Back to home page

OSCL-LXR

 
 

    


0001 ==========================
0002 Kernel driver i2c-mux-gpio
0003 ==========================
0004 
0005 Author: Peter Korsgaard <peter.korsgaard@barco.com>
0006 
0007 Description
0008 -----------
0009 
0010 i2c-mux-gpio is an i2c mux driver providing access to I2C bus segments
0011 from a master I2C bus and a hardware MUX controlled through GPIO pins.
0012 
0013 E.G.::
0014 
0015   ----------              ----------  Bus segment 1   - - - - -
0016  |          | SCL/SDA    |          |-------------- |           |
0017  |          |------------|          |
0018  |          |            |          | Bus segment 2 |           |
0019  |  Linux   | GPIO 1..N  |   MUX    |---------------   Devices
0020  |          |------------|          |               |           |
0021  |          |            |          | Bus segment M
0022  |          |            |          |---------------|           |
0023   ----------              ----------                  - - - - -
0024 
0025 SCL/SDA of the master I2C bus is multiplexed to bus segment 1..M
0026 according to the settings of the GPIO pins 1..N.
0027 
0028 Usage
0029 -----
0030 
0031 i2c-mux-gpio uses the platform bus, so you need to provide a struct
0032 platform_device with the platform_data pointing to a struct
0033 i2c_mux_gpio_platform_data with the I2C adapter number of the master
0034 bus, the number of bus segments to create and the GPIO pins used
0035 to control it. See include/linux/platform_data/i2c-mux-gpio.h for details.
0036 
0037 E.G. something like this for a MUX providing 4 bus segments
0038 controlled through 3 GPIO pins::
0039 
0040   #include <linux/platform_data/i2c-mux-gpio.h>
0041   #include <linux/platform_device.h>
0042 
0043   static const unsigned myboard_gpiomux_gpios[] = {
0044         AT91_PIN_PC26, AT91_PIN_PC25, AT91_PIN_PC24
0045   };
0046 
0047   static const unsigned myboard_gpiomux_values[] = {
0048         0, 1, 2, 3
0049   };
0050 
0051   static struct i2c_mux_gpio_platform_data myboard_i2cmux_data = {
0052         .parent         = 1,
0053         .base_nr        = 2, /* optional */
0054         .values         = myboard_gpiomux_values,
0055         .n_values       = ARRAY_SIZE(myboard_gpiomux_values),
0056         .gpios          = myboard_gpiomux_gpios,
0057         .n_gpios        = ARRAY_SIZE(myboard_gpiomux_gpios),
0058         .idle           = 4, /* optional */
0059   };
0060 
0061   static struct platform_device myboard_i2cmux = {
0062         .name           = "i2c-mux-gpio",
0063         .id             = 0,
0064         .dev            = {
0065                 .platform_data  = &myboard_i2cmux_data,
0066         },
0067   };
0068 
0069 If you don't know the absolute GPIO pin numbers at registration time,
0070 you can instead provide a chip name (.chip_name) and relative GPIO pin
0071 numbers, and the i2c-mux-gpio driver will do the work for you,
0072 including deferred probing if the GPIO chip isn't immediately
0073 available.
0074 
0075 Device Registration
0076 -------------------
0077 
0078 When registering your i2c-mux-gpio device, you should pass the number
0079 of any GPIO pin it uses as the device ID. This guarantees that every
0080 instance has a different ID.
0081 
0082 Alternatively, if you don't need a stable device name, you can simply
0083 pass PLATFORM_DEVID_AUTO as the device ID, and the platform core will
0084 assign a dynamic ID to your device. If you do not know the absolute
0085 GPIO pin numbers at registration time, this is even the only option.