[media] media: rc: nuvoton: remove wake states
[deliverable/linux.git] / drivers / media / rc / nuvoton-cir.h
1 /*
2 * Driver for Nuvoton Technology Corporation w83667hg/w83677hg-i CIR
3 *
4 * Copyright (C) 2010 Jarod Wilson <jarod@redhat.com>
5 * Copyright (C) 2009 Nuvoton PS Team
6 *
7 * Special thanks to Nuvoton for providing hardware, spec sheets and
8 * sample code upon which portions of this driver are based. Indirect
9 * thanks also to Maxim Levitsky, whose ene_ir driver this driver is
10 * modeled after.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 * USA
26 */
27
28 #include <linux/spinlock.h>
29 #include <linux/ioctl.h>
30
31 /* platform driver name to register */
32 #define NVT_DRIVER_NAME "nuvoton-cir"
33
34 /* debugging module parameter */
35 static int debug;
36
37
38 #define nvt_dbg(text, ...) \
39 if (debug) \
40 printk(KERN_DEBUG \
41 KBUILD_MODNAME ": " text "\n" , ## __VA_ARGS__)
42
43 #define nvt_dbg_verbose(text, ...) \
44 if (debug > 1) \
45 printk(KERN_DEBUG \
46 KBUILD_MODNAME ": " text "\n" , ## __VA_ARGS__)
47
48 #define nvt_dbg_wake(text, ...) \
49 if (debug > 2) \
50 printk(KERN_DEBUG \
51 KBUILD_MODNAME ": " text "\n" , ## __VA_ARGS__)
52
53
54 /*
55 * Original lirc driver said min value of 76, and recommended value of 256
56 * for the buffer length, but then used 2048. Never mind that the size of the
57 * RX FIFO is 32 bytes... So I'm using 32 for RX and 256 for TX atm, but I'm
58 * not sure if maybe that TX value is off by a factor of 8 (bits vs. bytes),
59 * and I don't have TX-capable hardware to test/debug on...
60 */
61 #define TX_BUF_LEN 256
62 #define RX_BUF_LEN 32
63
64 #define SIO_ID_MASK 0xfff0
65
66 enum nvt_chip_ver {
67 NVT_UNKNOWN = 0,
68 NVT_W83667HG = 0xa510,
69 NVT_6775F = 0xb470,
70 NVT_6776F = 0xc330,
71 NVT_6779D = 0xc560,
72 NVT_INVALID = 0xffff,
73 };
74
75 struct nvt_chip {
76 const char *name;
77 enum nvt_chip_ver chip_ver;
78 };
79
80 struct nvt_dev {
81 struct pnp_dev *pdev;
82 struct rc_dev *rdev;
83
84 spinlock_t nvt_lock;
85
86 /* for rx */
87 u8 buf[RX_BUF_LEN];
88 unsigned int pkts;
89
90 struct {
91 spinlock_t lock;
92 u8 buf[TX_BUF_LEN];
93 unsigned int buf_count;
94 unsigned int cur_buf_num;
95 wait_queue_head_t queue;
96 u8 tx_state;
97 } tx;
98
99 /* EFER Config register index/data pair */
100 u32 cr_efir;
101 u32 cr_efdr;
102
103 /* hardware I/O settings */
104 unsigned long cir_addr;
105 unsigned long cir_wake_addr;
106 int cir_irq;
107
108 enum nvt_chip_ver chip_ver;
109 /* hardware id */
110 u8 chip_major;
111 u8 chip_minor;
112
113 /* hardware features */
114 bool hw_learning_capable;
115 bool hw_tx_capable;
116
117 /* rx settings */
118 bool learning_enabled;
119
120 /* for study */
121 u8 study_state;
122 /* carrier period = 1 / frequency */
123 u32 carrier;
124 };
125
126 /* study states */
127 #define ST_STUDY_NONE 0x0
128 #define ST_STUDY_START 0x1
129 #define ST_STUDY_CARRIER 0x2
130 #define ST_STUDY_ALL_RECV 0x4
131
132 /* receive states */
133 #define ST_RX_WAIT_7F 0x1
134 #define ST_RX_WAIT_HEAD 0x2
135 #define ST_RX_WAIT_SILENT_END 0x4
136
137 /* send states */
138 #define ST_TX_NONE 0x0
139 #define ST_TX_REQUEST 0x2
140 #define ST_TX_REPLY 0x4
141
142 /* buffer packet constants */
143 #define BUF_PULSE_BIT 0x80
144 #define BUF_LEN_MASK 0x7f
145 #define BUF_REPEAT_BYTE 0x70
146 #define BUF_REPEAT_MASK 0xf0
147
148 /* CIR settings */
149
150 /* total length of CIR and CIR WAKE */
151 #define CIR_IOREG_LENGTH 0x0f
152
153 /* RX limit length, 8 high bits for SLCH, 8 low bits for SLCL */
154 #define CIR_RX_LIMIT_COUNT (IR_DEFAULT_TIMEOUT / US_TO_NS(SAMPLE_PERIOD))
155
156 /* CIR Regs */
157 #define CIR_IRCON 0x00
158 #define CIR_IRSTS 0x01
159 #define CIR_IREN 0x02
160 #define CIR_RXFCONT 0x03
161 #define CIR_CP 0x04
162 #define CIR_CC 0x05
163 #define CIR_SLCH 0x06
164 #define CIR_SLCL 0x07
165 #define CIR_FIFOCON 0x08
166 #define CIR_IRFIFOSTS 0x09
167 #define CIR_SRXFIFO 0x0a
168 #define CIR_TXFCONT 0x0b
169 #define CIR_STXFIFO 0x0c
170 #define CIR_FCCH 0x0d
171 #define CIR_FCCL 0x0e
172 #define CIR_IRFSM 0x0f
173
174 /* CIR IRCON settings */
175 #define CIR_IRCON_RECV 0x80
176 #define CIR_IRCON_WIREN 0x40
177 #define CIR_IRCON_TXEN 0x20
178 #define CIR_IRCON_RXEN 0x10
179 #define CIR_IRCON_WRXINV 0x08
180 #define CIR_IRCON_RXINV 0x04
181
182 #define CIR_IRCON_SAMPLE_PERIOD_SEL_1 0x00
183 #define CIR_IRCON_SAMPLE_PERIOD_SEL_25 0x01
184 #define CIR_IRCON_SAMPLE_PERIOD_SEL_50 0x02
185 #define CIR_IRCON_SAMPLE_PERIOD_SEL_100 0x03
186
187 /* FIXME: make this a runtime option */
188 /* select sample period as 50us */
189 #define CIR_IRCON_SAMPLE_PERIOD_SEL CIR_IRCON_SAMPLE_PERIOD_SEL_50
190
191 /* CIR IRSTS settings */
192 #define CIR_IRSTS_RDR 0x80
193 #define CIR_IRSTS_RTR 0x40
194 #define CIR_IRSTS_PE 0x20
195 #define CIR_IRSTS_RFO 0x10
196 #define CIR_IRSTS_TE 0x08
197 #define CIR_IRSTS_TTR 0x04
198 #define CIR_IRSTS_TFU 0x02
199 #define CIR_IRSTS_GH 0x01
200
201 /* CIR IREN settings */
202 #define CIR_IREN_RDR 0x80
203 #define CIR_IREN_RTR 0x40
204 #define CIR_IREN_PE 0x20
205 #define CIR_IREN_RFO 0x10
206 #define CIR_IREN_TE 0x08
207 #define CIR_IREN_TTR 0x04
208 #define CIR_IREN_TFU 0x02
209 #define CIR_IREN_GH 0x01
210
211 /* CIR FIFOCON settings */
212 #define CIR_FIFOCON_TXFIFOCLR 0x80
213
214 #define CIR_FIFOCON_TX_TRIGGER_LEV_31 0x00
215 #define CIR_FIFOCON_TX_TRIGGER_LEV_24 0x10
216 #define CIR_FIFOCON_TX_TRIGGER_LEV_16 0x20
217 #define CIR_FIFOCON_TX_TRIGGER_LEV_8 0x30
218
219 /* FIXME: make this a runtime option */
220 /* select TX trigger level as 16 */
221 #define CIR_FIFOCON_TX_TRIGGER_LEV CIR_FIFOCON_TX_TRIGGER_LEV_16
222
223 #define CIR_FIFOCON_RXFIFOCLR 0x08
224
225 #define CIR_FIFOCON_RX_TRIGGER_LEV_1 0x00
226 #define CIR_FIFOCON_RX_TRIGGER_LEV_8 0x01
227 #define CIR_FIFOCON_RX_TRIGGER_LEV_16 0x02
228 #define CIR_FIFOCON_RX_TRIGGER_LEV_24 0x03
229
230 /* FIXME: make this a runtime option */
231 /* select RX trigger level as 24 */
232 #define CIR_FIFOCON_RX_TRIGGER_LEV CIR_FIFOCON_RX_TRIGGER_LEV_24
233
234 /* CIR IRFIFOSTS settings */
235 #define CIR_IRFIFOSTS_IR_PENDING 0x80
236 #define CIR_IRFIFOSTS_RX_GS 0x40
237 #define CIR_IRFIFOSTS_RX_FTA 0x20
238 #define CIR_IRFIFOSTS_RX_EMPTY 0x10
239 #define CIR_IRFIFOSTS_RX_FULL 0x08
240 #define CIR_IRFIFOSTS_TX_FTA 0x04
241 #define CIR_IRFIFOSTS_TX_EMPTY 0x02
242 #define CIR_IRFIFOSTS_TX_FULL 0x01
243
244
245 /* CIR WAKE UP Regs */
246 #define CIR_WAKE_IRCON 0x00
247 #define CIR_WAKE_IRSTS 0x01
248 #define CIR_WAKE_IREN 0x02
249 #define CIR_WAKE_FIFO_CMP_DEEP 0x03
250 #define CIR_WAKE_FIFO_CMP_TOL 0x04
251 #define CIR_WAKE_FIFO_COUNT 0x05
252 #define CIR_WAKE_SLCH 0x06
253 #define CIR_WAKE_SLCL 0x07
254 #define CIR_WAKE_FIFOCON 0x08
255 #define CIR_WAKE_SRXFSTS 0x09
256 #define CIR_WAKE_SAMPLE_RX_FIFO 0x0a
257 #define CIR_WAKE_WR_FIFO_DATA 0x0b
258 #define CIR_WAKE_RD_FIFO_ONLY 0x0c
259 #define CIR_WAKE_RD_FIFO_ONLY_IDX 0x0d
260 #define CIR_WAKE_FIFO_IGNORE 0x0e
261 #define CIR_WAKE_IRFSM 0x0f
262
263 /* CIR WAKE UP IRCON settings */
264 #define CIR_WAKE_IRCON_DEC_RST 0x80
265 #define CIR_WAKE_IRCON_MODE1 0x40
266 #define CIR_WAKE_IRCON_MODE0 0x20
267 #define CIR_WAKE_IRCON_RXEN 0x10
268 #define CIR_WAKE_IRCON_R 0x08
269 #define CIR_WAKE_IRCON_RXINV 0x04
270
271 /* FIXME/jarod: make this a runtime option */
272 /* select a same sample period like cir register */
273 #define CIR_WAKE_IRCON_SAMPLE_PERIOD_SEL CIR_IRCON_SAMPLE_PERIOD_SEL_50
274
275 /* CIR WAKE IRSTS Bits */
276 #define CIR_WAKE_IRSTS_RDR 0x80
277 #define CIR_WAKE_IRSTS_RTR 0x40
278 #define CIR_WAKE_IRSTS_PE 0x20
279 #define CIR_WAKE_IRSTS_RFO 0x10
280 #define CIR_WAKE_IRSTS_GH 0x08
281 #define CIR_WAKE_IRSTS_IR_PENDING 0x01
282
283 /* CIR WAKE UP IREN Bits */
284 #define CIR_WAKE_IREN_RDR 0x80
285 #define CIR_WAKE_IREN_RTR 0x40
286 #define CIR_WAKE_IREN_PE 0x20
287 #define CIR_WAKE_IREN_RFO 0x10
288 #define CIR_WAKE_IREN_GH 0x08
289
290 /* CIR WAKE FIFOCON settings */
291 #define CIR_WAKE_FIFOCON_RXFIFOCLR 0x08
292
293 #define CIR_WAKE_FIFOCON_RX_TRIGGER_LEV_67 0x00
294 #define CIR_WAKE_FIFOCON_RX_TRIGGER_LEV_66 0x01
295 #define CIR_WAKE_FIFOCON_RX_TRIGGER_LEV_65 0x02
296 #define CIR_WAKE_FIFOCON_RX_TRIGGER_LEV_64 0x03
297
298 /* FIXME: make this a runtime option */
299 /* select WAKE UP RX trigger level as 67 */
300 #define CIR_WAKE_FIFOCON_RX_TRIGGER_LEV CIR_WAKE_FIFOCON_RX_TRIGGER_LEV_67
301
302 /* CIR WAKE SRXFSTS settings */
303 #define CIR_WAKE_IRFIFOSTS_RX_GS 0x80
304 #define CIR_WAKE_IRFIFOSTS_RX_FTA 0x40
305 #define CIR_WAKE_IRFIFOSTS_RX_EMPTY 0x20
306 #define CIR_WAKE_IRFIFOSTS_RX_FULL 0x10
307
308 /*
309 * The CIR Wake FIFO buffer is 67 bytes long, but the stock remote wakes
310 * the system comparing only 65 bytes (fails with this set to 67)
311 */
312 #define CIR_WAKE_FIFO_CMP_BYTES 65
313 /* CIR Wake byte comparison tolerance */
314 #define CIR_WAKE_CMP_TOLERANCE 5
315
316 /*
317 * Extended Function Enable Registers:
318 * Extended Function Index Register
319 * Extended Function Data Register
320 */
321 #define CR_EFIR 0x2e
322 #define CR_EFDR 0x2f
323
324 /* Possible alternate EFER values, depends on how the chip is wired */
325 #define CR_EFIR2 0x4e
326 #define CR_EFDR2 0x4f
327
328 /* Extended Function Mode enable/disable magic values */
329 #define EFER_EFM_ENABLE 0x87
330 #define EFER_EFM_DISABLE 0xaa
331
332 /* Config regs we need to care about */
333 #define CR_SOFTWARE_RESET 0x02
334 #define CR_LOGICAL_DEV_SEL 0x07
335 #define CR_CHIP_ID_HI 0x20
336 #define CR_CHIP_ID_LO 0x21
337 #define CR_DEV_POWER_DOWN 0x22 /* bit 2 is CIR power, default power on */
338 #define CR_OUTPUT_PIN_SEL 0x27
339 #define CR_MULTIFUNC_PIN_SEL 0x2c
340 #define CR_LOGICAL_DEV_EN 0x30 /* valid for all logical devices */
341 /* next three regs valid for both the CIR and CIR_WAKE logical devices */
342 #define CR_CIR_BASE_ADDR_HI 0x60
343 #define CR_CIR_BASE_ADDR_LO 0x61
344 #define CR_CIR_IRQ_RSRC 0x70
345 /* next three regs valid only for ACPI logical dev */
346 #define CR_ACPI_CIR_WAKE 0xe0
347 #define CR_ACPI_IRQ_EVENTS 0xf6
348 #define CR_ACPI_IRQ_EVENTS2 0xf7
349
350 /* Logical devices that we need to care about */
351 #define LOGICAL_DEV_LPT 0x01
352 #define LOGICAL_DEV_CIR 0x06
353 #define LOGICAL_DEV_ACPI 0x0a
354 #define LOGICAL_DEV_CIR_WAKE 0x0e
355
356 #define LOGICAL_DEV_DISABLE 0x00
357 #define LOGICAL_DEV_ENABLE 0x01
358
359 #define CIR_WAKE_ENABLE_BIT 0x08
360 #define PME_INTR_CIR_PASS_BIT 0x08
361
362 /* w83677hg CIR pin config */
363 #define OUTPUT_PIN_SEL_MASK 0xbc
364 #define OUTPUT_ENABLE_CIR 0x01 /* Pin95=CIRRX, Pin96=CIRTX1 */
365 #define OUTPUT_ENABLE_CIRWB 0x40 /* enable wide-band sensor */
366
367 /* w83667hg CIR pin config */
368 #define MULTIFUNC_PIN_SEL_MASK 0x1f
369 #define MULTIFUNC_ENABLE_CIR 0x80 /* Pin75=CIRRX, Pin76=CIRTX1 */
370 #define MULTIFUNC_ENABLE_CIRWB 0x20 /* enable wide-band sensor */
371
372 /* MCE CIR signal length, related on sample period */
373
374 /* MCE CIR controller signal length: about 43ms
375 * 43ms / 50us (sample period) * 0.85 (inaccuracy)
376 */
377 #define CONTROLLER_BUF_LEN_MIN 830
378
379 /* MCE CIR keyboard signal length: about 26ms
380 * 26ms / 50us (sample period) * 0.85 (inaccuracy)
381 */
382 #define KEYBOARD_BUF_LEN_MAX 650
383 #define KEYBOARD_BUF_LEN_MIN 610
384
385 /* MCE CIR mouse signal length: about 24ms
386 * 24ms / 50us (sample period) * 0.85 (inaccuracy)
387 */
388 #define MOUSE_BUF_LEN_MIN 565
389
390 #define CIR_SAMPLE_PERIOD 50
391 #define CIR_SAMPLE_LOW_INACCURACY 0.85
392
393 /* MAX silence time that driver will sent to lirc */
394 #define MAX_SILENCE_TIME 60000
395
396 #if CIR_IRCON_SAMPLE_PERIOD_SEL == CIR_IRCON_SAMPLE_PERIOD_SEL_100
397 #define SAMPLE_PERIOD 100
398
399 #elif CIR_IRCON_SAMPLE_PERIOD_SEL == CIR_IRCON_SAMPLE_PERIOD_SEL_50
400 #define SAMPLE_PERIOD 50
401
402 #elif CIR_IRCON_SAMPLE_PERIOD_SEL == CIR_IRCON_SAMPLE_PERIOD_SEL_25
403 #define SAMPLE_PERIOD 25
404
405 #else
406 #define SAMPLE_PERIOD 1
407 #endif
408
409 /* as VISTA MCE definition, valid carrier value */
410 #define MAX_CARRIER 60000
411 #define MIN_CARRIER 30000
412
413 /* max wakeup sequence length */
414 #define WAKEUP_MAX_SIZE 65
This page took 0.052372 seconds and 6 git commands to generate.