i2c-mux-gpio 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. Kernel driver i2c-gpio-mux
  2. Author: Peter Korsgaard <[email protected]>
  3. Description
  4. -----------
  5. i2c-gpio-mux is an i2c mux driver providing access to I2C bus segments
  6. from a master I2C bus and a hardware MUX controlled through GPIO pins.
  7. E.G.:
  8. ---------- ---------- Bus segment 1 - - - - -
  9. | | SCL/SDA | |-------------- | |
  10. | |------------| |
  11. | | | | Bus segment 2 | |
  12. | Linux | GPIO 1..N | MUX |--------------- Devices
  13. | |------------| | | |
  14. | | | | Bus segment M
  15. | | | |---------------| |
  16. ---------- ---------- - - - - -
  17. SCL/SDA of the master I2C bus is multiplexed to bus segment 1..M
  18. according to the settings of the GPIO pins 1..N.
  19. Usage
  20. -----
  21. i2c-gpio-mux uses the platform bus, so you need to provide a struct
  22. platform_device with the platform_data pointing to a struct
  23. gpio_i2cmux_platform_data with the I2C adapter number of the master
  24. bus, the number of bus segments to create and the GPIO pins used
  25. to control it. See include/linux/i2c-gpio-mux.h for details.
  26. E.G. something like this for a MUX providing 4 bus segments
  27. controlled through 3 GPIO pins:
  28. #include <linux/i2c-gpio-mux.h>
  29. #include <linux/platform_device.h>
  30. static const unsigned myboard_gpiomux_gpios[] = {
  31. AT91_PIN_PC26, AT91_PIN_PC25, AT91_PIN_PC24
  32. };
  33. static const unsigned myboard_gpiomux_values[] = {
  34. 0, 1, 2, 3
  35. };
  36. static struct gpio_i2cmux_platform_data myboard_i2cmux_data = {
  37. .parent = 1,
  38. .base_nr = 2, /* optional */
  39. .values = myboard_gpiomux_values,
  40. .n_values = ARRAY_SIZE(myboard_gpiomux_values),
  41. .gpios = myboard_gpiomux_gpios,
  42. .n_gpios = ARRAY_SIZE(myboard_gpiomux_gpios),
  43. .idle = 4, /* optional */
  44. };
  45. static struct platform_device myboard_i2cmux = {
  46. .name = "i2c-gpio-mux",
  47. .id = 0,
  48. .dev = {
  49. .platform_data = &myboard_i2cmux_data,
  50. },
  51. };
  52. If you don't know the absolute GPIO pin numbers at registration time,
  53. you can instead provide a chip name (.chip_name) and relative GPIO pin
  54. numbers, and the i2c-gpio-mux driver will do the work for you,
  55. including deferred probing if the GPIO chip isn't immediately
  56. available.
  57. Device Registration
  58. -------------------
  59. When registering your i2c-gpio-mux device, you should pass the number
  60. of any GPIO pin it uses as the device ID. This guarantees that every
  61. instance has a different ID.
  62. Alternatively, if you don't need a stable device name, you can simply
  63. pass PLATFORM_DEVID_AUTO as the device ID, and the platform core will
  64. assign a dynamic ID to your device. If you do not know the absolute
  65. GPIO pin numbers at registration time, this is even the only option.