gpio-tilt.txt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. Driver for tilt-switches connected via GPIOs
  2. ============================================
  3. Generic driver to read data from tilt switches connected via gpios.
  4. Orientation can be provided by one or more than one tilt switches,
  5. i.e. each tilt switch providing one axis, and the number of axes
  6. is also not limited.
  7. Data structures:
  8. ----------------
  9. The array of struct gpio in the gpios field is used to list the gpios
  10. that represent the current tilt state.
  11. The array of struct gpio_tilt_axis describes the axes that are reported
  12. to the input system. The values set therein are used for the
  13. input_set_abs_params calls needed to init the axes.
  14. The array of struct gpio_tilt_state maps gpio states to the corresponding
  15. values to report. The gpio state is represented as a bitfield where the
  16. bit-index corresponds to the index of the gpio in the struct gpio array.
  17. In the same manner the values stored in the axes array correspond to
  18. the elements of the gpio_tilt_axis-array.
  19. Example:
  20. --------
  21. Example configuration for a single TS1003 tilt switch that rotates around
  22. one axis in 4 steps and emits the current tilt via two GPIOs.
  23. static int sg060_tilt_enable(struct device *dev) {
  24. /* code to enable the sensors */
  25. };
  26. static void sg060_tilt_disable(struct device *dev) {
  27. /* code to disable the sensors */
  28. };
  29. static struct gpio sg060_tilt_gpios[] = {
  30. { SG060_TILT_GPIO_SENSOR1, GPIOF_IN, "tilt_sensor1" },
  31. { SG060_TILT_GPIO_SENSOR2, GPIOF_IN, "tilt_sensor2" },
  32. };
  33. static struct gpio_tilt_state sg060_tilt_states[] = {
  34. {
  35. .gpios = (0 << 1) | (0 << 0),
  36. .axes = (int[]) {
  37. 0,
  38. },
  39. }, {
  40. .gpios = (0 << 1) | (1 << 0),
  41. .axes = (int[]) {
  42. 1, /* 90 degrees */
  43. },
  44. }, {
  45. .gpios = (1 << 1) | (1 << 0),
  46. .axes = (int[]) {
  47. 2, /* 180 degrees */
  48. },
  49. }, {
  50. .gpios = (1 << 1) | (0 << 0),
  51. .axes = (int[]) {
  52. 3, /* 270 degrees */
  53. },
  54. },
  55. };
  56. static struct gpio_tilt_axis sg060_tilt_axes[] = {
  57. {
  58. .axis = ABS_RY,
  59. .min = 0,
  60. .max = 3,
  61. .fuzz = 0,
  62. .flat = 0,
  63. },
  64. };
  65. static struct gpio_tilt_platform_data sg060_tilt_pdata= {
  66. .gpios = sg060_tilt_gpios,
  67. .nr_gpios = ARRAY_SIZE(sg060_tilt_gpios),
  68. .axes = sg060_tilt_axes,
  69. .nr_axes = ARRAY_SIZE(sg060_tilt_axes),
  70. .states = sg060_tilt_states,
  71. .nr_states = ARRAY_SIZE(sg060_tilt_states),
  72. .debounce_interval = 100,
  73. .poll_interval = 1000,
  74. .enable = sg060_tilt_enable,
  75. .disable = sg060_tilt_disable,
  76. };
  77. static struct platform_device sg060_device_tilt = {
  78. .name = "gpio-tilt-polled",
  79. .id = -1,
  80. .dev = {
  81. .platform_data = &sg060_tilt_pdata,
  82. },
  83. };