1Driver for tilt-switches connected via GPIOs
2============================================
3
4Generic driver to read data from tilt switches connected via gpios.
5Orientation can be provided by one or more than one tilt switches,
6i.e. each tilt switch providing one axis, and the number of axes
7is also not limited.
8
9
10Data structures:
11----------------
12
13The array of struct gpio in the gpios field is used to list the gpios
14that represent the current tilt state.
15
16The array of struct gpio_tilt_axis describes the axes that are reported
17to the input system. The values set therein are used for the
18input_set_abs_params calls needed to init the axes.
19
20The array of struct gpio_tilt_state maps gpio states to the corresponding
21values to report. The gpio state is represented as a bitfield where the
22bit-index corresponds to the index of the gpio in the struct gpio array.
23In the same manner the values stored in the axes array correspond to
24the elements of the gpio_tilt_axis-array.
25
26
27Example:
28--------
29
30Example configuration for a single TS1003 tilt switch that rotates around
31one axis in 4 steps and emits the current tilt via two GPIOs.
32
33static int sg060_tilt_enable(struct device *dev) {
34	/* code to enable the sensors */
35};
36
37static void sg060_tilt_disable(struct device *dev) {
38	/* code to disable the sensors */
39};
40
41static 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
46static 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
70static 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
80static 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
97static struct platform_device sg060_device_tilt = {
98	.name = "gpio-tilt-polled",
99	.id = -1,
100	.dev = {
101		.platform_data = &sg060_tilt_pdata,
102	},
103};
104