diff options
Diffstat (limited to 'Documentation/input/gpio-tilt.txt')
-rw-r--r-- | Documentation/input/gpio-tilt.txt | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/Documentation/input/gpio-tilt.txt b/Documentation/input/gpio-tilt.txt new file mode 100644 index 000000000000..06d60c3ff5e7 --- /dev/null +++ b/Documentation/input/gpio-tilt.txt | |||
@@ -0,0 +1,103 @@ | |||
1 | Driver for tilt-switches connected via GPIOs | ||
2 | ============================================ | ||
3 | |||
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 | ||
7 | is also not limited. | ||
8 | |||
9 | |||
10 | Data structures: | ||
11 | ---------------- | ||
12 | |||
13 | The array of struct gpio in the gpios field is used to list the gpios | ||
14 | that represent the current tilt state. | ||
15 | |||
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. | ||
19 | |||
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. | ||
25 | |||
26 | |||
27 | Example: | ||
28 | -------- | ||
29 | |||
30 | Example configuration for a single TS1003 tilt switch that rotates around | ||
31 | one axis in 4 steps and emitts the current tilt via two GPIOs. | ||
32 | |||
33 | static int sg060_tilt_enable(struct device *dev) { | ||
34 | /* code to enable the sensors */ | ||
35 | }; | ||
36 | |||
37 | static void sg060_tilt_disable(struct device *dev) { | ||
38 | /* code to disable the sensors */ | ||
39 | }; | ||
40 | |||
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" }, | ||
44 | }; | ||
45 | |||
46 | static struct gpio_tilt_state sg060_tilt_states[] = { | ||
47 | { | ||
48 | .gpios = (0 << 1) | (0 << 0), | ||
49 | .axes = (int[]) { | ||
50 | 0, | ||
51 | }, | ||
52 | }, { | ||
53 | .gpios = (0 << 1) | (1 << 0), | ||
54 | .axes = (int[]) { | ||
55 | 1, /* 90 degrees */ | ||
56 | }, | ||
57 | }, { | ||
58 | .gpios = (1 << 1) | (1 << 0), | ||
59 | .axes = (int[]) { | ||
60 | 2, /* 180 degrees */ | ||
61 | }, | ||
62 | }, { | ||
63 | .gpios = (1 << 1) | (0 << 0), | ||
64 | .axes = (int[]) { | ||
65 | 3, /* 270 degrees */ | ||
66 | }, | ||
67 | }, | ||
68 | }; | ||
69 | |||
70 | static struct gpio_tilt_axis sg060_tilt_axes[] = { | ||
71 | { | ||
72 | .axis = ABS_RY, | ||
73 | .min = 0, | ||
74 | .max = 3, | ||
75 | .fuzz = 0, | ||
76 | .flat = 0, | ||
77 | }, | ||
78 | }; | ||
79 | |||
80 | static struct gpio_tilt_platform_data sg060_tilt_pdata= { | ||
81 | .gpios = sg060_tilt_gpios, | ||
82 | .nr_gpios = ARRAY_SIZE(sg060_tilt_gpios), | ||
83 | |||
84 | .axes = sg060_tilt_axes, | ||
85 | .nr_axes = ARRAY_SIZE(sg060_tilt_axes), | ||
86 | |||
87 | .states = sg060_tilt_states, | ||
88 | .nr_states = ARRAY_SIZE(sg060_tilt_states), | ||
89 | |||
90 | .debounce_interval = 100, | ||
91 | |||
92 | .poll_interval = 1000, | ||
93 | .enable = sg060_tilt_enable, | ||
94 | .disable = sg060_tilt_disable, | ||
95 | }; | ||
96 | |||
97 | static struct platform_device sg060_device_tilt = { | ||
98 | .name = "gpio-tilt-polled", | ||
99 | .id = -1, | ||
100 | .dev = { | ||
101 | .platform_data = &sg060_tilt_pdata, | ||
102 | }, | ||
103 | }; | ||