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