i.mx6 at24cxx EEPROM Linux I2c-gpio

Source: Internet
Author: User

/************************************************************************** * i.mx6 AT24Cxx EEPROM Linu X I2c-gpio * Disclaimer: * Many times when we use the Linux system management hardware, more is through the chip controller, * but sometimes, we will also encounter the chip in the control is not enough, or in the design of the process of accidents, such as no * have thought controller exists, the content of this article is because For the fourth controller in the I²c does not exist, but on the hardware * think it exists, in order to solve this problem, found the I2c-gpio device driver, and so on, the other one * some relatively simple controller will also have this IO device driver. * 2015-12-20 Shenzhen Nanshan Ping Shan village Zengjianfeng ******************************************************** *****************/                    \\\\\\\\\\\\\-*-Directory-*-////////////|A. Reference Documentation:|two. The type of I²C bus supported by the Linux kernel:| Three Open Kernel i2c-Gpio Features:|Four. Turn on the AT24CXX series EEPROM driver:|Five. GPIO IO configuration:|Six. Board-level file porting code:|Seven. EEPROM write protection problem:------------------------------------A. Reference Documentation:1. Linux Gpio analog i²c use/GPIO analog I²c Bus-1: http://blog.163.com/ac952_hmz/blog/static/94791513201281133230840/    2s3c2440-based embedded Linux driver--at24c02 (EEPROM-i²c Interface) driver interpretation: http://blog.csdn.net/yj4231/article/details/18182775two. The type of I²C bus supported by the Linux kernel:1using an I²C bus controller on the chip: the I²C device can be mounted directly on the corresponding bus. 2do not use the on-chip I²C bus controller, through the analog I²c bus timing: By using a common Gpio port, to control the GPIO pin level, the time lag length, to simulate the i²c timing, in order to communicate with the I²C device. 3Without using the on-chip I²C bus controller, the Linux kernel comes with i2c-Gpio driver: Only need to specify the Gpio port to use, the length of the delay, by the I²c-Gpio driver to manage how to communicate with the I²C device, is quite an i²c controller, which is provided by the Linux kernel. Because of the hardware design requirement in current work, this article mainly elaborates the 3rd kind of realization way. Three Turn on kernel i²c-Gpio Features: If the I2c_gpio function is turned on in the kernel configuration: ────────────────────────────────────────────────────────────────────────────── ┌─────────────────────────I2C Hardware Bus support─────────────────────────┐│arrow keys navigate the Me  Nu. <Enter> selects submenus--->.  ││highlighted Letters is hotkeys. Pressing<Y> includes, <N>excludes,││<M> modularizes features. Press <Esc><Esc> to exit, <?> forHelp, </>││ forSearch. Legend: [*] built-inch[] excluded <M> module < >module││┌────^(-) ────────────────────────────────────────────────────────────────┐│││< >SiS 96x││││< >VIA vt82c586b││││< > VIA vt82c596/82c686/82xx and Cx700/vx8xx││││I²c system bus drivers (mostly embedded/system-on-chip) * *││││< >Synopsys designware││││<*> gpio-based bitbanging i2c││││<*> IMX I²cInterface││││< > Intel moorestown/Medfield Platform i²c controller││││< >opencores i²c controller││││< > pca9564/pca9665 asPlatform Device││││< > Simtec Generic i²cInterface││││< >Xilinx i²c controller│││└────v (+) ────────────────────────────────────────────────────────────────┘│├────────────────────────────────────── ──────────────────────────────────────┤│<Select> < Exit > < Help >│└────────────────────────────────────────────────────────────────────────────┘ Four. Turn on the AT24CXX series EEPROM driver:1because the Linux kernel already contains the drivers for the At24cxx series, we do not need to do this, such as opening the AT24CXX series driver in the kernel configuration. ──────────────────────────────────────────────────────────────────────────────┌──────────────────────────────  EEPROM support──────────────────────────────┐│arrow Keys navigate the menu. <Enter> selects submenus--->.  ││highlighted Letters is hotkeys. Pressing<Y> includes, <N>excludes,││<M> modularizes features. Press <Esc><Esc> to exit, <?> forHelp, </>││ forSearch. Legend: [*] built-inch[] excluded <M> module < >module││┌────────────────────────────────────────────────────────────────────────┐│││
    <*> I²c EEPROMs fromMost vendors││││< > SPI EEPROMs fromMost vendors││││< >Old i²c EEPROM reader││││< > Maxim max6874/5power supply supervisor││││< >EEPROM 93cx6 support││││                                                                        ││││                                                                        ││││││││                                                                        ││││          ││││││ │││││└─────────────────────────────── ─────────────────────────────────────────┘│├────────────────────────────────────────────────────────────────── ──────────┤│<Select> < Exit > < Help >│└────────────────────────────────────────────────────────────────────────────┘< /c0>2. AT24CXX Series Drive Core source code: drivers/misc/eeprom/at24.c Five. GPIO IO configuration: .../*IMX6DL No i2c4*/    /** *MX6DL_PAD_ENET_TX_EN__I2C4_SCL, *MX6DL_PAD_ENET_TXD1__I2C4_SDA,*/mx6dl_pad_enet_tx_en__gpio_1_28, mx6dl_pad_enet_txd1__gpio_1_29, ... Six Board-level file porting code: ... #include<linux/i2c-gpio.h>//Add I2c-gpio header file#include <linux/i2c/at24.h>//Add header file    ......    /** * Specify 2 Gpio for the SDA, SCL line for I²c bus*/    #defineSabresd_i2c4_sda_gpio IMX_GPIO_NR (1, 29)#defineSabresd_i2c4_scl_gpio IMX_GPIO_NR (1, 28)    ......    Static structI2c_gpio_platform_data I2c_bus_gpio_data ={. Sda_pin=Sabresd_i2c4_sda_gpio,. Scl_pin=Sabresd_i2c4_scl_gpio,. Udelay=5,//100Khz. Timeout = -,          //. Sda_is_open_drain = 1,//cannot be added on the current board//. Scl_is_open_drain = 1,//cannot be added on the current board    }; Static structPlatform_device I2c_bus_gpio_device = {          //This name is required, mainly for the I2c-gpio driver.. Name ="I2c-gpio",          //since the motherboard has already used the 0,1,2 number, here 3. ID =3,/*Bus has 0,1,2, so-start at 3*/. Dev={. Platform_data= &I2c_bus_gpio_data,}}; Static structI2c_board_info __initdata gpio_i2c_devices[] = {          {              /** 24C02: Corresponds to the AT24C02 driver name in the at24.c driver * 0x50: The address of the corresponding I²c device, also the address of our AT24C02 device*/I2c_board_info ("24C02",0x50),          },      }; ......    Static void__init Mx6_sabresd_board_init (void)    {        ......            /** Register Gpio i²c Bus write by ZENGJF * Register I2c-gpio device, equivalent to register an I²C controller */Platform_device_register (&I2c_bus_gpio_device); ......        /** Register Gpio device Write by ZENGJF * on the I²C Controller 3, the Controller 3 is the front registered I²C Controller, * mainly because the ID of the previously registered I²c controller is 3*/I2c_register_board_info (3, Gpio_i2c_devices, Array_size (gpio_i2c_devices));    ......    } ...... Seven EEPROM write protection problem: When you find that you can read data from the EEPROM, but cannot write data to the EEPROM, please check the EEPROM chip's WP (write protect) pin is pulled up. 

i.mx6 at24cxx EEPROM Linux I2c-gpio

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.