简体   繁体   中英

How to read from I2C EEPROM from Linux kernel - ARM TI AM3352

On my board I have an I2C EEPROM that stores configuration information. UBoot reads it using the read_eeprom function shown below. I would also like to access this information from inside the Linux kernel so that my /proc/cpuinfo output shows correctly. However I can't find the equivalent functions of i2c_probe and i2c_read in the Linux kernel. How do I do the below functions from inside the kernel? I'm using Linux 3.2.

static int read_eeprom(void)
{
        /* Check if baseboard eeprom is available */
        if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
                puts("Could not probe the EEPROM; something fundamentally "
                        "wrong on the I2C bus.\n");
                return -ENODEV;
        }

        /* read the eeprom using i2c */
        if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)&header,
                                                        sizeof(header))) {
                puts("Could not read the EEPROM; something fundamentally"
                        " wrong on the I2C bus.\n");
                return -EIO;
        }

        if (header.magic != 0xEE3355AA) {
                /*
                 * read the eeprom using i2c again,
                 * but use only a 1 byte address
                 */
                if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1,
                                        (uchar *)&header, sizeof(header))) {
                        puts("Could not read the EEPROM; something "
                                "fundamentally wrong on the I2C bus.\n");
                        return -EIO;
                }

                if (header.magic != 0xEE3355AA) {
                        printf("Incorrect magic number (0x%x) in EEPROM\n",
                                        header.magic);
                        return -EINVAL;
                }
        }

        return 0;
}

There are some questions to take into account in order to address your problem:

  • Do you build your kernel yourself? Is your board a custom one?

  • Do you really need to be in the kernel?

  • Do you really need to put your informations in procfs? especially in cpuinfo or a custom procfs file could be sufficiant ( procfs interface , guide to procfs )?

  • Get informations concerning your EEPROM using i2c-tools or checking sysfs (/sys/class/i2c*)

  • How is your EEPROM I2C device registrated ( many ways )?

  • Determine where you will introduce your code and be sure it is run after the device registration. Will you create your own kernel module for instance in staging? Will you patch your EEPROM driver?

  • See how to access and update the procfs's cpuinfo

Depending on your real needs and your configuration, the way to address your problem can change.

Did you try using eeprog utility, I have used it in past to read the content of eeprom .Its source is available on line which you can port into your application .

http://www.codesink.org/eeprog.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM