i2c-mux-gpio.rst 2.8 KB

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