gpio-i2cmux 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. Kernel driver gpio-i2cmux
  2. Author: Peter Korsgaard <peter.korsgaard@barco.com>
  3. Description
  4. -----------
  5. gpio-i2cmux 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. gpio-i2cmux 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/gpio-i2cmux.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/gpio-i2cmux.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 = "gpio-i2cmux",
  47. .id = 0,
  48. .dev = {
  49. .platform_data = &myboard_i2cmux_data,
  50. },
  51. };