1 Driver for tilt-switches connected via GPIOs
2 ============================================
4 Generic driver to read data from tilt switches connected via gpios.
5 Orientation can be provided by one or more than one tilt switches,
6 i.e. each tilt switch providing one axis, and the number of axes
13 The array of struct gpio in the gpios field is used to list the gpios
14 that represent the current tilt state.
16 The array of struct gpio_tilt_axis describes the axes that are reported
17 to the input system. The values set therein are used for the
18 input_set_abs_params calls needed to init the axes.
20 The array of struct gpio_tilt_state maps gpio states to the corresponding
21 values to report. The gpio state is represented as a bitfield where the
22 bit-index corresponds to the index of the gpio in the struct gpio array.
23 In the same manner the values stored in the axes array correspond to
24 the elements of the gpio_tilt_axis-array.
30 Example configuration for a single TS1003 tilt switch that rotates around
31 one axis in 4 steps and emits the current tilt via two GPIOs.
33 static int sg060_tilt_enable(struct device *dev) {
34 /* code to enable the sensors */
37 static void sg060_tilt_disable(struct device *dev) {
38 /* code to disable the sensors */
41 static struct gpio sg060_tilt_gpios[] = {
42 { SG060_TILT_GPIO_SENSOR1, GPIOF_IN, "tilt_sensor1" },
43 { SG060_TILT_GPIO_SENSOR2, GPIOF_IN, "tilt_sensor2" },
46 static struct gpio_tilt_state sg060_tilt_states[] = {
48 .gpios = (0 << 1) | (0 << 0),
53 .gpios = (0 << 1) | (1 << 0),
58 .gpios = (1 << 1) | (1 << 0),
63 .gpios = (1 << 1) | (0 << 0),
70 static struct gpio_tilt_axis sg060_tilt_axes[] = {
80 static struct gpio_tilt_platform_data sg060_tilt_pdata= {
81 .gpios = sg060_tilt_gpios,
82 .nr_gpios = ARRAY_SIZE(sg060_tilt_gpios),
84 .axes = sg060_tilt_axes,
85 .nr_axes = ARRAY_SIZE(sg060_tilt_axes),
87 .states = sg060_tilt_states,
88 .nr_states = ARRAY_SIZE(sg060_tilt_states),
90 .debounce_interval = 100,
92 .poll_interval = 1000,
93 .enable = sg060_tilt_enable,
94 .disable = sg060_tilt_disable,
97 static struct platform_device sg060_device_tilt = {
98 .name = "gpio-tilt-polled",
101 .platform_data = &sg060_tilt_pdata,