aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/wm97xx.h
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2008-04-02 00:51:09 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2008-04-02 00:51:09 -0400
commitfebf1dff119ef27ee22a54d40f284d2454f00d8d (patch)
tree8369e232456e3ba52bfdc873d561ddcbea7d0baa /include/linux/wm97xx.h
parent3797fec17193e05dee9666b990d6c84e16b188b3 (diff)
Input: add support for WM97xx familty touchscreens
Add support for the touchscreen controllers provided by Wolfson Microelectronics WM97xx series chips in both polled and streaming modes. These drivers have been maintained out of tree since 2003. During that time the driver the primary maintainer was Liam Girdwood and a number of people have made contributions including Dmitry Baryshkov, Stanley Cai, Rodolfo Giometti, Russell King, Marc Kleine-Budde, Ian Molton, Vincent Sanders, Andrew Zabolotny, Graeme Gregory, Mike Arthur and myself. Apologies to anyone I have omitted. Signed-off-by: Liam Girdwood <liam.girdwood@wolfsonmicro.com> Signed-off-by: Graeme Gregory <gg@opensource.wolfsonmicro.com> Signed-off-by: Mike Arthur <mike.arthur@wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'include/linux/wm97xx.h')
-rw-r--r--include/linux/wm97xx.h311
1 files changed, 311 insertions, 0 deletions
diff --git a/include/linux/wm97xx.h b/include/linux/wm97xx.h
new file mode 100644
index 000000000000..ed01c7df54a3
--- /dev/null
+++ b/include/linux/wm97xx.h
@@ -0,0 +1,311 @@
1
2/*
3 * Register bits and API for Wolfson WM97xx series of codecs
4 */
5
6#ifndef _LINUX_WM97XX_H
7#define _LINUX_WM97XX_H
8
9#include <sound/core.h>
10#include <sound/pcm.h>
11#include <sound/ac97_codec.h>
12#include <sound/initval.h>
13#include <linux/types.h>
14#include <linux/list.h>
15#include <linux/input.h> /* Input device layer */
16#include <linux/platform_device.h>
17
18/*
19 * WM97xx AC97 Touchscreen registers
20 */
21#define AC97_WM97XX_DIGITISER1 0x76
22#define AC97_WM97XX_DIGITISER2 0x78
23#define AC97_WM97XX_DIGITISER_RD 0x7a
24#define AC97_WM9713_DIG1 0x74
25#define AC97_WM9713_DIG2 AC97_WM97XX_DIGITISER1
26#define AC97_WM9713_DIG3 AC97_WM97XX_DIGITISER2
27
28/*
29 * WM97xx register bits
30 */
31#define WM97XX_POLL 0x8000 /* initiate a polling measurement */
32#define WM97XX_ADCSEL_X 0x1000 /* x coord measurement */
33#define WM97XX_ADCSEL_Y 0x2000 /* y coord measurement */
34#define WM97XX_ADCSEL_PRES 0x3000 /* pressure measurement */
35#define WM97XX_ADCSEL_MASK 0x7000
36#define WM97XX_COO 0x0800 /* enable coordinate mode */
37#define WM97XX_CTC 0x0400 /* enable continuous mode */
38#define WM97XX_CM_RATE_93 0x0000 /* 93.75Hz continuous rate */
39#define WM97XX_CM_RATE_187 0x0100 /* 187.5Hz continuous rate */
40#define WM97XX_CM_RATE_375 0x0200 /* 375Hz continuous rate */
41#define WM97XX_CM_RATE_750 0x0300 /* 750Hz continuous rate */
42#define WM97XX_CM_RATE_8K 0x00f0 /* 8kHz continuous rate */
43#define WM97XX_CM_RATE_12K 0x01f0 /* 12kHz continuous rate */
44#define WM97XX_CM_RATE_24K 0x02f0 /* 24kHz continuous rate */
45#define WM97XX_CM_RATE_48K 0x03f0 /* 48kHz continuous rate */
46#define WM97XX_CM_RATE_MASK 0x03f0
47#define WM97XX_RATE(i) (((i & 3) << 8) | ((i & 4) ? 0xf0 : 0))
48#define WM97XX_DELAY(i) ((i << 4) & 0x00f0) /* sample delay times */
49#define WM97XX_DELAY_MASK 0x00f0
50#define WM97XX_SLEN 0x0008 /* slot read back enable */
51#define WM97XX_SLT(i) ((i - 5) & 0x7) /* panel slot (5-11) */
52#define WM97XX_SLT_MASK 0x0007
53#define WM97XX_PRP_DETW 0x4000 /* detect on, digitise off, wake */
54#define WM97XX_PRP_DET 0x8000 /* detect on, digitise off, no wake */
55#define WM97XX_PRP_DET_DIG 0xc000 /* setect on, digitise on */
56#define WM97XX_RPR 0x2000 /* wake up on pen down */
57#define WM97XX_PEN_DOWN 0x8000 /* pen is down */
58#define WM97XX_ADCSRC_MASK 0x7000 /* ADC source mask */
59
60#define WM97XX_AUX_ID1 0x8001
61#define WM97XX_AUX_ID2 0x8002
62#define WM97XX_AUX_ID3 0x8003
63#define WM97XX_AUX_ID4 0x8004
64
65
66/* WM9712 Bits */
67#define WM9712_45W 0x1000 /* set for 5-wire touchscreen */
68#define WM9712_PDEN 0x0800 /* measure only when pen down */
69#define WM9712_WAIT 0x0200 /* wait until adc is read before next sample */
70#define WM9712_PIL 0x0100 /* current used for pressure measurement. set 400uA else 200uA */
71#define WM9712_MASK_HI 0x0040 /* hi on mask pin (47) stops conversions */
72#define WM9712_MASK_EDGE 0x0080 /* rising/falling edge on pin delays sample */
73#define WM9712_MASK_SYNC 0x00c0 /* rising/falling edge on mask initiates sample */
74#define WM9712_RPU(i) (i&0x3f) /* internal pull up on pen detect (64k / rpu) */
75#define WM9712_PD(i) (0x1 << i) /* power management */
76
77/* WM9712 Registers */
78#define AC97_WM9712_POWER 0x24
79#define AC97_WM9712_REV 0x58
80
81/* WM9705 Bits */
82#define WM9705_PDEN 0x1000 /* measure only when pen is down */
83#define WM9705_PINV 0x0800 /* inverts sense of pen down output */
84#define WM9705_BSEN 0x0400 /* BUSY flag enable, pin47 is 1 when busy */
85#define WM9705_BINV 0x0200 /* invert BUSY (pin47) output */
86#define WM9705_WAIT 0x0100 /* wait until adc is read before next sample */
87#define WM9705_PIL 0x0080 /* current used for pressure measurement. set 400uA else 200uA */
88#define WM9705_PHIZ 0x0040 /* set PHONE and PCBEEP inputs to high impedance */
89#define WM9705_MASK_HI 0x0010 /* hi on mask stops conversions */
90#define WM9705_MASK_EDGE 0x0020 /* rising/falling edge on pin delays sample */
91#define WM9705_MASK_SYNC 0x0030 /* rising/falling edge on mask initiates sample */
92#define WM9705_PDD(i) (i & 0x000f) /* pen detect comparator threshold */
93
94
95/* WM9713 Bits */
96#define WM9713_PDPOL 0x0400 /* Pen down polarity */
97#define WM9713_POLL 0x0200 /* initiate a polling measurement */
98#define WM9713_CTC 0x0100 /* enable continuous mode */
99#define WM9713_ADCSEL_X 0x0002 /* X measurement */
100#define WM9713_ADCSEL_Y 0x0004 /* Y measurement */
101#define WM9713_ADCSEL_PRES 0x0008 /* Pressure measurement */
102#define WM9713_COO 0x0001 /* enable coordinate mode */
103#define WM9713_PDEN 0x0800 /* measure only when pen down */
104#define WM9713_ADCSEL_MASK 0x00fe /* ADC selection mask */
105#define WM9713_WAIT 0x0200 /* coordinate wait */
106
107/* AUX ADC ID's */
108#define TS_COMP1 0x0
109#define TS_COMP2 0x1
110#define TS_BMON 0x2
111#define TS_WIPER 0x3
112
113/* ID numbers */
114#define WM97XX_ID1 0x574d
115#define WM9712_ID2 0x4c12
116#define WM9705_ID2 0x4c05
117#define WM9713_ID2 0x4c13
118
119/* Codec GPIO's */
120#define WM97XX_MAX_GPIO 16
121#define WM97XX_GPIO_1 (1 << 1)
122#define WM97XX_GPIO_2 (1 << 2)
123#define WM97XX_GPIO_3 (1 << 3)
124#define WM97XX_GPIO_4 (1 << 4)
125#define WM97XX_GPIO_5 (1 << 5)
126#define WM97XX_GPIO_6 (1 << 6)
127#define WM97XX_GPIO_7 (1 << 7)
128#define WM97XX_GPIO_8 (1 << 8)
129#define WM97XX_GPIO_9 (1 << 9)
130#define WM97XX_GPIO_10 (1 << 10)
131#define WM97XX_GPIO_11 (1 << 11)
132#define WM97XX_GPIO_12 (1 << 12)
133#define WM97XX_GPIO_13 (1 << 13)
134#define WM97XX_GPIO_14 (1 << 14)
135#define WM97XX_GPIO_15 (1 << 15)
136
137
138#define AC97_LINK_FRAME 21 /* time in uS for AC97 link frame */
139
140
141/*---------------- Return codes from sample reading functions ---------------*/
142
143/* More data is available; call the sample gathering function again */
144#define RC_AGAIN 0x00000001
145/* The returned sample is valid */
146#define RC_VALID 0x00000002
147/* The pen is up (the first RC_VALID without RC_PENUP means pen is down) */
148#define RC_PENUP 0x00000004
149/* The pen is down (RC_VALID implies RC_PENDOWN, but sometimes it is helpful
150 to tell the handler that the pen is down but we don't know yet his coords,
151 so the handler should not sleep or wait for pendown irq) */
152#define RC_PENDOWN 0x00000008
153
154/*
155 * The wm97xx driver provides a private API for writing platform-specific
156 * drivers.
157 */
158
159/* The structure used to return arch specific sampled data into */
160struct wm97xx_data {
161 int x;
162 int y;
163 int p;
164};
165
166/*
167 * Codec GPIO status
168 */
169enum wm97xx_gpio_status {
170 WM97XX_GPIO_HIGH,
171 WM97XX_GPIO_LOW
172};
173
174/*
175 * Codec GPIO direction
176 */
177enum wm97xx_gpio_dir {
178 WM97XX_GPIO_IN,
179 WM97XX_GPIO_OUT
180};
181
182/*
183 * Codec GPIO polarity
184 */
185enum wm97xx_gpio_pol {
186 WM97XX_GPIO_POL_HIGH,
187 WM97XX_GPIO_POL_LOW
188};
189
190/*
191 * Codec GPIO sticky
192 */
193enum wm97xx_gpio_sticky {
194 WM97XX_GPIO_STICKY,
195 WM97XX_GPIO_NOTSTICKY
196};
197
198/*
199 * Codec GPIO wake
200 */
201enum wm97xx_gpio_wake {
202 WM97XX_GPIO_WAKE,
203 WM97XX_GPIO_NOWAKE
204};
205
206/*
207 * Digitiser ioctl commands
208 */
209#define WM97XX_DIG_START 0x1
210#define WM97XX_DIG_STOP 0x2
211#define WM97XX_PHY_INIT 0x3
212#define WM97XX_AUX_PREPARE 0x4
213#define WM97XX_DIG_RESTORE 0x5
214
215struct wm97xx;
216
217extern struct wm97xx_codec_drv wm9705_codec;
218extern struct wm97xx_codec_drv wm9712_codec;
219extern struct wm97xx_codec_drv wm9713_codec;
220
221/*
222 * Codec driver interface - allows mapping to WM9705/12/13 and newer codecs
223 */
224struct wm97xx_codec_drv {
225 u16 id;
226 char *name;
227
228 /* read 1 sample */
229 int (*poll_sample) (struct wm97xx *, int adcsel, int *sample);
230
231 /* read X,Y,[P] in poll */
232 int (*poll_touch) (struct wm97xx *, struct wm97xx_data *);
233
234 int (*acc_enable) (struct wm97xx *, int enable);
235 void (*phy_init) (struct wm97xx *);
236 void (*dig_enable) (struct wm97xx *, int enable);
237 void (*dig_restore) (struct wm97xx *);
238 void (*aux_prepare) (struct wm97xx *);
239};
240
241
242/* Machine specific and accelerated touch operations */
243struct wm97xx_mach_ops {
244
245 /* accelerated touch readback - coords are transmited on AC97 link */
246 int acc_enabled;
247 void (*acc_pen_up) (struct wm97xx *);
248 int (*acc_pen_down) (struct wm97xx *);
249 int (*acc_startup) (struct wm97xx *);
250 void (*acc_shutdown) (struct wm97xx *);
251
252 /* interrupt mask control - required for accelerated operation */
253 void (*irq_enable) (struct wm97xx *, int enable);
254
255 /* GPIO pin used for accelerated operation */
256 int irq_gpio;
257
258 /* pre and post sample - can be used to minimise any analog noise */
259 void (*pre_sample) (int); /* function to run before sampling */
260 void (*post_sample) (int); /* function to run after sampling */
261};
262
263struct wm97xx {
264 u16 dig[3], id, gpio[6], misc; /* Cached codec registers */
265 u16 dig_save[3]; /* saved during aux reading */
266 struct wm97xx_codec_drv *codec; /* attached codec driver*/
267 struct input_dev *input_dev; /* touchscreen input device */
268 struct snd_ac97 *ac97; /* ALSA codec access */
269 struct device *dev; /* ALSA device */
270 struct platform_device *battery_dev;
271 struct platform_device *touch_dev;
272 struct wm97xx_mach_ops *mach_ops;
273 struct mutex codec_mutex;
274 struct delayed_work ts_reader; /* Used to poll touchscreen */
275 unsigned long ts_reader_interval; /* Current interval for timer */
276 unsigned long ts_reader_min_interval; /* Minimum interval */
277 unsigned int pen_irq; /* Pen IRQ number in use */
278 struct workqueue_struct *ts_workq;
279 struct work_struct pen_event_work;
280 u16 acc_slot; /* AC97 slot used for acc touch data */
281 u16 acc_rate; /* acc touch data rate */
282 unsigned pen_is_down:1; /* Pen is down */
283 unsigned aux_waiting:1; /* aux measurement waiting */
284 unsigned pen_probably_down:1; /* used in polling mode */
285};
286
287/*
288 * Codec GPIO access (not supported on WM9705)
289 * This can be used to set/get codec GPIO and Virtual GPIO status.
290 */
291enum wm97xx_gpio_status wm97xx_get_gpio(struct wm97xx *wm, u32 gpio);
292void wm97xx_set_gpio(struct wm97xx *wm, u32 gpio,
293 enum wm97xx_gpio_status status);
294void wm97xx_config_gpio(struct wm97xx *wm, u32 gpio,
295 enum wm97xx_gpio_dir dir,
296 enum wm97xx_gpio_pol pol,
297 enum wm97xx_gpio_sticky sticky,
298 enum wm97xx_gpio_wake wake);
299
300/* codec AC97 IO access */
301int wm97xx_reg_read(struct wm97xx *wm, u16 reg);
302void wm97xx_reg_write(struct wm97xx *wm, u16 reg, u16 val);
303
304/* aux adc readback */
305int wm97xx_read_aux_adc(struct wm97xx *wm, u16 adcsel);
306
307/* machine ops */
308int wm97xx_register_mach_ops(struct wm97xx *, struct wm97xx_mach_ops *);
309void wm97xx_unregister_mach_ops(struct wm97xx *);
310
311#endif