Last active
January 1, 2016 07:39
-
-
Save Embedded-linux/8113305 to your computer and use it in GitHub Desktop.
I2C Platform Driver ,Bus Driver and Client Driver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Writing I2C Platform Driver and Code Flow: | |
| File Name: arch/arm/mach-versatile/versatile-pb.c | |
| Function Name: versatile_init(); -----------> arch/arm/mach-versatile/core.c --------------> | |
| platform_device_register(&versatile_i2c_device); | |
| Machine File is registering i2c device with function name platform_device_register() | |
| static struct platform_device versatile_i2c_device = { | |
| .name = "versatile-i2c", | |
| .id = 0, | |
| .num_resources = 1, | |
| .resource = &versatile_i2c_resource, | |
| }; | |
| i2c device is having above structer parameters of Name of Master i2c Device, id of i2c device | |
| [cat /sys/devices/platform/versatile-i2c/uevent], no.of resources [No. of Master devices] and | |
| Resources of I2C Device. | |
| static struct resource versatile_i2c_resource = { | |
| .start = VERSATILE_I2C_BASE, | |
| .end = VERSATILE_I2C_BASE + SZ_4K - 1, | |
| .flags = IORESOURCE_MEM, | |
| }; | |
| i2c Resources provided by Machine to I2C Master is defined as above structure parameters. | |
| Machine is providing Base address of I2C Device and client device can accessed/transfer | |
| the data based on the offset address of client registers from this Base address. | |
| static int __init versatile_i2c_init(void) | |
| { | |
| return i2c_register_board_info(0, versatile_i2c_board_info, | |
| ARRAY_SIZE(versatile_i2c_board_info)); | |
| } | |
| arch_initcall(versatile_i2c_init); | |
| Initilization of I2C Platform driver is done through above function call | |
| with registered I2C Board Information. | |
| static struct i2c_board_info versatile_i2c_board_info[] = { | |
| { | |
| I2C_BOARD_INFO("ds1338", 0xd0 >> 1), | |
| }, | |
| }; | |
| I2C board info is having name of I2C Controller [Client Device] and address of | |
| Controller provided in memory map of System. | |
| -------------------------------------------------------------------------------------------------------------------- | |
| Writing Master Controller of Versatile-Pb Board for I2C Protocol: | |
| #define VERSATILE_I2C_BASE 0x10002000 /* kernel 3.2 version*/ | |
| #define IORESOURCE_MEM 0x00000200 | |
| File Name:drivers/i2c/buses/i2c-versatile.c | |
| Module init Function: i2c_versatile_init() and | |
| Module init Function: i2c_versatile_exit() | |
| i2c_versatile_init() calls platform_driver_register() registers i2c_versatile_driver , | |
| which calls probe and remove Functions. | |
| Probe function calls i2c_algorithm which gets and sets SCL and SDA Values of Master Controller. | |
| [Based On Master Controller Data/Register Manual]. | |
| ------------------------------------------------------------------------------------------------------------ | |
| I2C Client Driver: | |
| i2c_board_info is giving name of Client controller which is added to I2C bus using | |
| i2c alogirioth driver and versatile adaptor. | |
| Here it is RTC and name oc controller is DS1388. | |
| File Name: drivers/rtc/rtc-ds1307.c | |
| This file describes functionality of RTC DS1307/1338 and adding as client device to I2C, | |
| Sending/Receving information through SMBUS of I2C protocol | |
| [I2C supported Protocol: reference: Essential Linux Device Drivers]. | |
| ------------------------------------------------------------------------------------------------ | |
| Explore the flow of Data from Client Device to Platform Device by manipulating code and verifying the same in Qemu. | |
| Qemu supports Versatile Board. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment