Skip to contentSkip to conversation

reading i2c eeprom early in boot

DISCUSSION Karl Hiramoto 2 participants 2 messages Jun 24, 2010 – Jun 25, 2010 1 message not in the archive I2C subsystem host drivers

lore
Share & tools
lore
#0 lore raw

Hi,

My goal is to assign a MAC address stored in a I2C EEPROM to a ethernet device on an ARM SOC so I can boot via NFS. Reading and writing this address works with the at24 driver after its loaded.

Currently the i2c __init call is after the ethernet devices __init, so this makes using the I2C drivers not possible, as nothing is instantiated.

So to me it looks like i have two options.

1. Reorder the init calls. I'd prefer not doing this for fear of breaking something else.

2. The I2C bus on my board is just using GPIO pins. I could bit bang these pins before the i2c drivers are loaded, in the arch initcalls. Are there any functions in the kernel to do this easily? Like optimally some libary function in the kernel to do something like:

i2c_gpio_read(int sda_pin, int scl_pin, int i2c_address, int len, void *data)

This library function may need to have to have a spinlock or mutex to avoid conflicts on these pins.

Is there a better solution?

--
karl

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Hi Karl,

Quoted 6 lines · Karl Hiramoto

My goal is to assign a MAC address stored in a I2C EEPROM to a ethernet device on an ARM SOC so I can boot via NFS. Reading and writing this address works with the at24 driver after its loaded.

Currently the i2c __init call is after the ethernet devices __init, so this makes using the I2C drivers not possible, as nothing is instantiated.

So to me it looks like i have two options.

Quoted 7 lines

1. Reorder the init calls. I'd prefer not doing this for fear of breaking something else.

2. The I2C bus on my board is just using GPIO pins. I could bit bang these pins before the i2c drivers are loaded, in the arch initcalls. Are there any functions in the kernel to do this easily? Like optimally some libary function in the kernel to do something like:

i2c_gpio_read(int sda_pin, int scl_pin, int i2c_address, int len, void *data)

This library function may need to have to have a spinlock or mutex to avoid conflicts on these pins.

I don't think anything like this exists, and I sincerely hope it will never exist. It would inevitably duplicate code that already exists, and add confusion all around, and bugs.

Quoted 1 line

Is there a better solution?

If parts of i2c need to be initialized earlier, then let's just do this. That being said, i2c core initialization happens at postcore_initcall() level since kernel 2.6.28, and many i2c bus drivers for embedded platforms use subsys_initcall(). i2c-gpio has just need changed to do exactly this:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=b8680784875b26a2876df5959673a496d56af673
Isn't it enough to solve your problem?

Signature · 1 line
Jean Delvare