简体   繁体   English

如何从Linux内核中读取I2C EEPROM-ARM TI AM3352

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

On my board I have an I2C EEPROM that stores configuration information. 在我的板上,我有一个I2C EEPROM,用于存储配置信息。 UBoot reads it using the read_eeprom function shown below. UBoot使用下面显示的read_eeprom函数读取它。 I would also like to access this information from inside the Linux kernel so that my /proc/cpuinfo output shows correctly. 我还想从Linux内核内部访问此信息,以便/ proc / cpuinfo输出正确显示。 However I can't find the equivalent functions of i2c_probe and i2c_read in the Linux kernel. 但是我在Linux内核中找不到i2c_probe和i2c_read的等效功能。 How do I do the below functions from inside the kernel? 如何从内核内部执行以下功能? I'm using Linux 3.2. 我正在使用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 )? 特别是在cpuinfo或自定义procfs文件中就足够了( procfs接口procfs指南 )?

  • Get informations concerning your EEPROM using i2c-tools or checking sysfs (/sys/class/i2c*) 使用i2c工具或检查sysfs(/ sys / class / i2c *)获取有关EEPROM的信息

  • How is your EEPROM I2C device registrated ( many ways )? EEPROM I2C设备如何注册( 许多方式 )?

  • 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? 您会修补EEPROM驱动程序吗?

  • See how to access and update the procfs's cpuinfo 了解如何访问和更新procfs的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 . 您是否尝试过使用eeprog实用程序,但我过去曾使用它来阅读eeprom的内容。它的源代码在线可用,您可以将其移植到应用程序中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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