2 * winbond-cir.c - Driver for the Consumer IR functionality of Winbond
5 * Currently supports the Winbond WPCD376i chip (PNP id WEC1022), but
6 * could probably support others (Winbond WEC102X, NatSemi, etc)
7 * with minor modifications.
9 * Original Author: David Härdeman <david@hardeman.nu>
10 * Copyright (C) 2009 David Härdeman <david@hardeman.nu>
12 * Dedicated to Matilda, my newborn daughter, without whose loving attention
13 * this driver would have been finished in half the time and with a fraction
17 * o Winbond WPCD376I datasheet helpfully provided by Jesse Barnes at Intel
18 * o NatSemi PC87338/PC97338 datasheet (for the serial port stuff)
23 * o Wake-On-CIR functionality
28 * Left as an exercise for the reader:
29 * o Learning (I have neither the hardware, nor the need)
30 * o IR Transmit (ibid)
32 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation; either version 2 of the License, or
35 * (at your option) any later version.
37 * This program is distributed in the hope that it will be useful,
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 * GNU General Public License for more details.
42 * You should have received a copy of the GNU General Public License
43 * along with this program; if not, write to the Free Software
44 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
47 #include <linux/module.h>
48 #include <linux/pnp.h>
49 #include <linux/interrupt.h>
50 #include <linux/timer.h>
51 #include <linux/input.h>
52 #include <linux/leds.h>
53 #include <linux/list.h>
54 #include <linux/spinlock.h>
55 #include <linux/pci_ids.h>
57 #include <linux/bitrev.h>
58 #include <linux/bitops.h>
59 #include <linux/slab.h>
61 #define DRVNAME "winbond-cir"
63 /* CEIR Wake-Up Registers, relative to data->wbase */
64 #define WBCIR_REG_WCEIR_CTL 0x03 /* CEIR Receiver Control */
65 #define WBCIR_REG_WCEIR_STS 0x04 /* CEIR Receiver Status */
66 #define WBCIR_REG_WCEIR_EV_EN 0x05 /* CEIR Receiver Event Enable */
67 #define WBCIR_REG_WCEIR_CNTL 0x06 /* CEIR Receiver Counter Low */
68 #define WBCIR_REG_WCEIR_CNTH 0x07 /* CEIR Receiver Counter High */
69 #define WBCIR_REG_WCEIR_INDEX 0x08 /* CEIR Receiver Index */
70 #define WBCIR_REG_WCEIR_DATA 0x09 /* CEIR Receiver Data */
71 #define WBCIR_REG_WCEIR_CSL 0x0A /* CEIR Re. Compare Strlen */
72 #define WBCIR_REG_WCEIR_CFG1 0x0B /* CEIR Re. Configuration 1 */
73 #define WBCIR_REG_WCEIR_CFG2 0x0C /* CEIR Re. Configuration 2 */
75 /* CEIR Enhanced Functionality Registers, relative to data->ebase */
76 #define WBCIR_REG_ECEIR_CTS 0x00 /* Enhanced IR Control Status */
77 #define WBCIR_REG_ECEIR_CCTL 0x01 /* Infrared Counter Control */
78 #define WBCIR_REG_ECEIR_CNT_LO 0x02 /* Infrared Counter LSB */
79 #define WBCIR_REG_ECEIR_CNT_HI 0x03 /* Infrared Counter MSB */
80 #define WBCIR_REG_ECEIR_IREM 0x04 /* Infrared Emitter Status */
82 /* SP3 Banked Registers, relative to data->sbase */
83 #define WBCIR_REG_SP3_BSR 0x03 /* Bank Select, all banks */
85 #define WBCIR_REG_SP3_RXDATA 0x00 /* FIFO RX data (r) */
86 #define WBCIR_REG_SP3_TXDATA 0x00 /* FIFO TX data (w) */
87 #define WBCIR_REG_SP3_IER 0x01 /* Interrupt Enable */
88 #define WBCIR_REG_SP3_EIR 0x02 /* Event Identification (r) */
89 #define WBCIR_REG_SP3_FCR 0x02 /* FIFO Control (w) */
90 #define WBCIR_REG_SP3_MCR 0x04 /* Mode Control */
91 #define WBCIR_REG_SP3_LSR 0x05 /* Link Status */
92 #define WBCIR_REG_SP3_MSR 0x06 /* Modem Status */
93 #define WBCIR_REG_SP3_ASCR 0x07 /* Aux Status and Control */
95 #define WBCIR_REG_SP3_BGDL 0x00 /* Baud Divisor LSB */
96 #define WBCIR_REG_SP3_BGDH 0x01 /* Baud Divisor MSB */
97 #define WBCIR_REG_SP3_EXCR1 0x02 /* Extended Control 1 */
98 #define WBCIR_REG_SP3_EXCR2 0x04 /* Extended Control 2 */
99 #define WBCIR_REG_SP3_TXFLV 0x06 /* TX FIFO Level */
100 #define WBCIR_REG_SP3_RXFLV 0x07 /* RX FIFO Level */
102 #define WBCIR_REG_SP3_MRID 0x00 /* Module Identification */
103 #define WBCIR_REG_SP3_SH_LCR 0x01 /* LCR Shadow */
104 #define WBCIR_REG_SP3_SH_FCR 0x02 /* FCR Shadow */
106 #define WBCIR_REG_SP3_IRCR1 0x02 /* Infrared Control 1 */
108 #define WBCIR_REG_SP3_IRCR2 0x04 /* Infrared Control 2 */
110 #define WBCIR_REG_SP3_IRCR3 0x00 /* Infrared Control 3 */
111 #define WBCIR_REG_SP3_SIR_PW 0x02 /* SIR Pulse Width */
113 #define WBCIR_REG_SP3_IRRXDC 0x00 /* IR RX Demod Control */
114 #define WBCIR_REG_SP3_IRTXMC 0x01 /* IR TX Mod Control */
115 #define WBCIR_REG_SP3_RCCFG 0x02 /* CEIR Config */
116 #define WBCIR_REG_SP3_IRCFG1 0x04 /* Infrared Config 1 */
117 #define WBCIR_REG_SP3_IRCFG4 0x07 /* Infrared Config 4 */
120 * Magic values follow
123 /* No interrupts for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */
124 #define WBCIR_IRQ_NONE 0x00
125 /* RX data bit for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */
126 #define WBCIR_IRQ_RX 0x01
127 /* Over/Under-flow bit for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */
128 #define WBCIR_IRQ_ERR 0x04
129 /* Led enable/disable bit for WBCIR_REG_ECEIR_CTS */
130 #define WBCIR_LED_ENABLE 0x80
131 /* RX data available bit for WBCIR_REG_SP3_LSR */
132 #define WBCIR_RX_AVAIL 0x01
133 /* RX disable bit for WBCIR_REG_SP3_ASCR */
134 #define WBCIR_RX_DISABLE 0x20
135 /* Extended mode enable bit for WBCIR_REG_SP3_EXCR1 */
136 #define WBCIR_EXT_ENABLE 0x01
137 /* Select compare register in WBCIR_REG_WCEIR_INDEX (bits 5 & 6) */
138 #define WBCIR_REGSEL_COMPARE 0x10
139 /* Select mask register in WBCIR_REG_WCEIR_INDEX (bits 5 & 6) */
140 #define WBCIR_REGSEL_MASK 0x20
141 /* Starting address of selected register in WBCIR_REG_WCEIR_INDEX */
142 #define WBCIR_REG_ADDR0 0x00
144 /* Valid banks for the SP3 UART */
156 /* Supported IR Protocols */
157 enum wbcir_protocol
{
158 IR_PROTOCOL_RC5
= 0x0,
159 IR_PROTOCOL_NEC
= 0x1,
160 IR_PROTOCOL_RC6
= 0x2,
164 #define WBCIR_NAME "Winbond CIR"
165 #define WBCIR_ID_FAMILY 0xF1 /* Family ID for the WPCD376I */
166 #define WBCIR_ID_CHIP 0x04 /* Chip ID for the WPCD376I */
167 #define IR_KEYPRESS_TIMEOUT 250 /* FIXME: should be per-protocol? */
168 #define INVALID_SCANCODE 0x7FFFFFFF /* Invalid with all protos */
169 #define WAKEUP_IOMEM_LEN 0x10 /* Wake-Up I/O Reg Len */
170 #define EHFUNC_IOMEM_LEN 0x10 /* Enhanced Func I/O Reg Len */
171 #define SP_IOMEM_LEN 0x08 /* Serial Port 3 (IR) Reg Len */
172 #define WBCIR_MAX_IDLE_BYTES 10
174 static DEFINE_SPINLOCK(wbcir_lock
);
175 static DEFINE_RWLOCK(keytable_lock
);
179 unsigned int keycode
;
182 struct wbcir_keyentry
{
183 struct wbcir_key key
;
184 struct list_head list
;
187 static struct wbcir_key rc6_def_keymap
[] = {
188 { 0x800F0400, KEY_NUMERIC_0
},
189 { 0x800F0401, KEY_NUMERIC_1
},
190 { 0x800F0402, KEY_NUMERIC_2
},
191 { 0x800F0403, KEY_NUMERIC_3
},
192 { 0x800F0404, KEY_NUMERIC_4
},
193 { 0x800F0405, KEY_NUMERIC_5
},
194 { 0x800F0406, KEY_NUMERIC_6
},
195 { 0x800F0407, KEY_NUMERIC_7
},
196 { 0x800F0408, KEY_NUMERIC_8
},
197 { 0x800F0409, KEY_NUMERIC_9
},
198 { 0x800F041D, KEY_NUMERIC_STAR
},
199 { 0x800F041C, KEY_NUMERIC_POUND
},
200 { 0x800F0410, KEY_VOLUMEUP
},
201 { 0x800F0411, KEY_VOLUMEDOWN
},
202 { 0x800F0412, KEY_CHANNELUP
},
203 { 0x800F0413, KEY_CHANNELDOWN
},
204 { 0x800F040E, KEY_MUTE
},
205 { 0x800F040D, KEY_VENDOR
}, /* Vista Logo Key */
206 { 0x800F041E, KEY_UP
},
207 { 0x800F041F, KEY_DOWN
},
208 { 0x800F0420, KEY_LEFT
},
209 { 0x800F0421, KEY_RIGHT
},
210 { 0x800F0422, KEY_OK
},
211 { 0x800F0423, KEY_ESC
},
212 { 0x800F040F, KEY_INFO
},
213 { 0x800F040A, KEY_CLEAR
},
214 { 0x800F040B, KEY_ENTER
},
215 { 0x800F045B, KEY_RED
},
216 { 0x800F045C, KEY_GREEN
},
217 { 0x800F045D, KEY_YELLOW
},
218 { 0x800F045E, KEY_BLUE
},
219 { 0x800F045A, KEY_TEXT
},
220 { 0x800F0427, KEY_SWITCHVIDEOMODE
},
221 { 0x800F040C, KEY_POWER
},
222 { 0x800F0450, KEY_RADIO
},
223 { 0x800F0448, KEY_PVR
},
224 { 0x800F0447, KEY_AUDIO
},
225 { 0x800F0426, KEY_EPG
},
226 { 0x800F0449, KEY_CAMERA
},
227 { 0x800F0425, KEY_TV
},
228 { 0x800F044A, KEY_VIDEO
},
229 { 0x800F0424, KEY_DVD
},
230 { 0x800F0416, KEY_PLAY
},
231 { 0x800F0418, KEY_PAUSE
},
232 { 0x800F0419, KEY_STOP
},
233 { 0x800F0414, KEY_FASTFORWARD
},
234 { 0x800F041A, KEY_NEXT
},
235 { 0x800F041B, KEY_PREVIOUS
},
236 { 0x800F0415, KEY_REWIND
},
237 { 0x800F0417, KEY_RECORD
},
240 /* Registers and other state is protected by wbcir_lock */
242 unsigned long wbase
; /* Wake-Up Baseaddr */
243 unsigned long ebase
; /* Enhanced Func. Baseaddr */
244 unsigned long sbase
; /* Serial Port Baseaddr */
245 unsigned int irq
; /* Serial Port IRQ */
247 struct input_dev
*input_dev
;
248 struct timer_list timer_keyup
;
249 struct led_trigger
*rxtrigger
;
250 struct led_trigger
*txtrigger
;
251 struct led_classdev led
;
254 unsigned int last_keycode
;
257 unsigned long keyup_jiffies
;
258 unsigned int idle_count
;
260 /* RX irdata and parsing state */
261 unsigned long irdata
[30];
262 unsigned int irdata_count
;
263 unsigned int irdata_idle
;
264 unsigned int irdata_off
;
265 unsigned int irdata_error
;
267 /* Protected by keytable_lock */
268 struct list_head keytable
;
271 static enum wbcir_protocol protocol
= IR_PROTOCOL_RC6
;
272 module_param(protocol
, uint
, 0444);
273 MODULE_PARM_DESC(protocol
, "IR protocol to use "
274 "(0 = RC5, 1 = NEC, 2 = RC6A, default)");
276 static int invert
; /* default = 0 */
277 module_param(invert
, bool, 0444);
278 MODULE_PARM_DESC(invert
, "Invert the signal from the IR receiver");
280 static unsigned int wake_sc
= 0x800F040C;
281 module_param(wake_sc
, uint
, 0644);
282 MODULE_PARM_DESC(wake_sc
, "Scancode of the power-on IR command");
284 static unsigned int wake_rc6mode
= 6;
285 module_param(wake_rc6mode
, uint
, 0644);
286 MODULE_PARM_DESC(wake_rc6mode
, "RC6 mode for the power-on command "
287 "(0 = 0, 6 = 6A, default)");
291 /*****************************************************************************
295 *****************************************************************************/
297 /* Caller needs to hold wbcir_lock */
299 wbcir_set_bits(unsigned long addr
, u8 bits
, u8 mask
)
304 val
= ((val
& ~mask
) | (bits
& mask
));
308 /* Selects the register bank for the serial port */
310 wbcir_select_bank(struct wbcir_data
*data
, enum wbcir_bank bank
)
312 outb(bank
, data
->sbase
+ WBCIR_REG_SP3_BSR
);
315 static enum led_brightness
316 wbcir_led_brightness_get(struct led_classdev
*led_cdev
)
318 struct wbcir_data
*data
= container_of(led_cdev
,
322 if (inb(data
->ebase
+ WBCIR_REG_ECEIR_CTS
) & WBCIR_LED_ENABLE
)
329 wbcir_led_brightness_set(struct led_classdev
*led_cdev
,
330 enum led_brightness brightness
)
332 struct wbcir_data
*data
= container_of(led_cdev
,
336 wbcir_set_bits(data
->ebase
+ WBCIR_REG_ECEIR_CTS
,
337 brightness
== LED_OFF
? 0x00 : WBCIR_LED_ENABLE
,
341 /* Manchester encodes bits to RC6 message cells (see wbcir_parse_rc6) */
343 wbcir_to_rc6cells(u8 val
)
349 for (i
= 0; i
< 4; i
++) {
351 coded
|= 0x02 << (i
* 2);
353 coded
|= 0x01 << (i
* 2);
362 /*****************************************************************************
366 *****************************************************************************/
369 wbcir_do_getkeycode(struct wbcir_data
*data
, u32 scancode
)
371 struct wbcir_keyentry
*keyentry
;
372 unsigned int keycode
= KEY_RESERVED
;
375 read_lock_irqsave(&keytable_lock
, flags
);
377 list_for_each_entry(keyentry
, &data
->keytable
, list
) {
378 if (keyentry
->key
.scancode
== scancode
) {
379 keycode
= keyentry
->key
.keycode
;
384 read_unlock_irqrestore(&keytable_lock
, flags
);
389 wbcir_getkeycode(struct input_dev
*dev
,
390 unsigned int scancode
, unsigned int *keycode
)
392 struct wbcir_data
*data
= input_get_drvdata(dev
);
394 *keycode
= wbcir_do_getkeycode(data
, scancode
);
399 wbcir_setkeycode(struct input_dev
*dev
,
400 unsigned int scancode
, unsigned int keycode
)
402 struct wbcir_data
*data
= input_get_drvdata(dev
);
403 struct wbcir_keyentry
*keyentry
;
404 struct wbcir_keyentry
*new_keyentry
;
406 unsigned int old_keycode
= KEY_RESERVED
;
408 new_keyentry
= kmalloc(sizeof(*new_keyentry
), GFP_KERNEL
);
412 write_lock_irqsave(&keytable_lock
, flags
);
414 list_for_each_entry(keyentry
, &data
->keytable
, list
) {
415 if (keyentry
->key
.scancode
!= scancode
)
418 old_keycode
= keyentry
->key
.keycode
;
419 keyentry
->key
.keycode
= keycode
;
421 if (keyentry
->key
.keycode
== KEY_RESERVED
) {
422 list_del(&keyentry
->list
);
429 set_bit(keycode
, dev
->keybit
);
431 if (old_keycode
== KEY_RESERVED
) {
432 new_keyentry
->key
.scancode
= scancode
;
433 new_keyentry
->key
.keycode
= keycode
;
434 list_add(&new_keyentry
->list
, &data
->keytable
);
437 clear_bit(old_keycode
, dev
->keybit
);
438 list_for_each_entry(keyentry
, &data
->keytable
, list
) {
439 if (keyentry
->key
.keycode
== old_keycode
) {
440 set_bit(old_keycode
, dev
->keybit
);
446 write_unlock_irqrestore(&keytable_lock
, flags
);
451 * Timer function to report keyup event some time after keydown is
452 * reported by the ISR.
455 wbcir_keyup(unsigned long cookie
)
457 struct wbcir_data
*data
= (struct wbcir_data
*)cookie
;
461 * data->keyup_jiffies is used to prevent a race condition if a
462 * hardware interrupt occurs at this point and the keyup timer
463 * event is moved further into the future as a result.
465 * The timer will then be reactivated and this function called
466 * again in the future. We need to exit gracefully in that case
467 * to allow the input subsystem to do its auto-repeat magic or
468 * a keyup event might follow immediately after the keydown.
471 spin_lock_irqsave(&wbcir_lock
, flags
);
473 if (time_is_after_eq_jiffies(data
->keyup_jiffies
) && data
->keypressed
) {
474 data
->keypressed
= 0;
475 led_trigger_event(data
->rxtrigger
, LED_OFF
);
476 input_report_key(data
->input_dev
, data
->last_keycode
, 0);
477 input_sync(data
->input_dev
);
480 spin_unlock_irqrestore(&wbcir_lock
, flags
);
484 wbcir_keydown(struct wbcir_data
*data
, u32 scancode
, u8 toggle
)
486 unsigned int keycode
;
489 if (data
->last_scancode
== scancode
&&
490 data
->last_toggle
== toggle
&&
493 data
->last_scancode
= scancode
;
495 /* Do we need to release an old keypress? */
496 if (data
->keypressed
) {
497 input_report_key(data
->input_dev
, data
->last_keycode
, 0);
498 input_sync(data
->input_dev
);
499 data
->keypressed
= 0;
502 /* Report scancode */
503 input_event(data
->input_dev
, EV_MSC
, MSC_SCAN
, (int)scancode
);
505 /* Do we know this scancode? */
506 keycode
= wbcir_do_getkeycode(data
, scancode
);
507 if (keycode
== KEY_RESERVED
)
510 /* Register a keypress */
511 input_report_key(data
->input_dev
, keycode
, 1);
512 data
->keypressed
= 1;
513 data
->last_keycode
= keycode
;
514 data
->last_toggle
= toggle
;
517 input_sync(data
->input_dev
);
518 led_trigger_event(data
->rxtrigger
,
519 data
->keypressed
? LED_FULL
: LED_OFF
);
520 data
->keyup_jiffies
= jiffies
+ msecs_to_jiffies(IR_KEYPRESS_TIMEOUT
);
521 mod_timer(&data
->timer_keyup
, data
->keyup_jiffies
);
526 /*****************************************************************************
528 * IR PARSING FUNCTIONS
530 *****************************************************************************/
532 /* Resets all irdata */
534 wbcir_reset_irdata(struct wbcir_data
*data
)
536 memset(data
->irdata
, 0, sizeof(data
->irdata
));
537 data
->irdata_count
= 0;
538 data
->irdata_off
= 0;
539 data
->irdata_error
= 0;
540 data
->idle_count
= 0;
543 /* Adds one bit of irdata */
545 add_irdata_bit(struct wbcir_data
*data
, int set
)
547 if (data
->irdata_count
>= sizeof(data
->irdata
) * 8) {
548 data
->irdata_error
= 1;
553 __set_bit(data
->irdata_count
, data
->irdata
);
554 data
->irdata_count
++;
557 /* Gets count bits of irdata */
559 get_bits(struct wbcir_data
*data
, int count
)
563 if (data
->irdata_count
- data
->irdata_off
< count
) {
564 data
->irdata_error
= 1;
570 if (test_bit(data
->irdata_off
, data
->irdata
))
579 /* Reads 16 cells and converts them to a byte */
581 wbcir_rc6cells_to_byte(struct wbcir_data
*data
)
583 u16 raw
= get_bits(data
, 16);
587 for (bit
= 0; bit
< 8; bit
++) {
588 switch (raw
& 0x03) {
592 val
|= (0x01 << bit
);
595 data
->irdata_error
= 1;
604 /* Decodes a number of bits from raw RC5 data */
606 wbcir_get_rc5bits(struct wbcir_data
*data
, unsigned int count
)
608 u16 raw
= get_bits(data
, count
* 2);
612 for (bit
= 0; bit
< count
; bit
++) {
613 switch (raw
& 0x03) {
615 val
|= (0x01 << bit
);
620 data
->irdata_error
= 1;
630 wbcir_parse_rc6(struct device
*dev
, struct wbcir_data
*data
)
633 * Normal bits are manchester coded as follows:
634 * cell0 + cell1 = logic "0"
635 * cell1 + cell0 = logic "1"
637 * The IR pulse has the following components:
639 * Leader - 6 * cell1 - discarded
640 * Gap - 2 * cell0 - discarded
641 * Start bit - Normal Coding - always "1"
642 * Mode Bit 2 - 0 - Normal Coding
643 * Toggle bit - Normal Coding with double bit time,
644 * e.g. cell0 + cell0 + cell1 + cell1
647 * The rest depends on the mode, the following modes are known:
650 * Address Bit 7 - 0 - Normal Coding
651 * Command Bit 7 - 0 - Normal Coding
654 * The above Toggle Bit is used as a submode bit, 0 = A, 1 = B.
655 * Submode B is for pointing devices, only remotes using submode A
658 * Customer range bit - 0 => Customer = 7 bits, 0...127
659 * 1 => Customer = 15 bits, 32768...65535
660 * Customer Bits - Normal Coding
662 * Customer codes are allocated by Philips. The rest of the bits
663 * are customer dependent. The following is commonly used (and the
664 * only supported config):
666 * Toggle Bit - Normal Coding
667 * Address Bit 6 - 0 - Normal Coding
668 * Command Bit 7 - 0 - Normal Coding
670 * All modes are followed by at least 6 * cell0.
673 * 1 * 2 (start bit) + 3 * 2 (mode) + 2 * 2 (toggle) +
674 * 8 * 2 (address) + 8 * 2 (command) =
678 * 1 * 2 (start bit) + 3 * 2 (mode) + 2 * 2 (submode) +
679 * 1 * 2 (customer range bit) + 7/15 * 2 (customer bits) +
680 * 1 * 2 (toggle bit) + 7 * 2 (address) + 8 * 2 (command) =
691 while (get_bits(data
, 1) && !data
->irdata_error
)
695 if (get_bits(data
, 1)) {
696 dev_dbg(dev
, "RC6 - Invalid leader space\n");
701 if (get_bits(data
, 2) != 0x02) {
702 dev_dbg(dev
, "RC6 - Invalid start bit\n");
707 mode
= get_bits(data
, 6);
709 case 0x15: /* 010101 = b000 */
712 case 0x29: /* 101001 = b110 */
716 dev_dbg(dev
, "RC6 - Invalid mode\n");
720 /* Toggle bit / Submode bit */
721 toggle
= get_bits(data
, 4);
730 dev_dbg(dev
, "RC6 - Toggle bit error\n");
737 dev_dbg(dev
, "RC6B - Not Supported\n");
741 customer
= wbcir_rc6cells_to_byte(data
);
743 if (customer
& 0x80) {
744 /* 15 bit customer value */
746 customer
|= wbcir_rc6cells_to_byte(data
);
751 address
= wbcir_rc6cells_to_byte(data
);
753 toggle
= address
>> 7;
758 command
= wbcir_rc6cells_to_byte(data
);
760 /* Create scancode */
762 scancode
|= address
<< 8;
763 scancode
|= customer
<< 16;
765 /* Last sanity check */
766 if (data
->irdata_error
) {
767 dev_dbg(dev
, "RC6 - Cell error(s)\n");
771 dev_dbg(dev
, "IR-RC6 ad 0x%02X cm 0x%02X cu 0x%04X "
772 "toggle %u mode %u scan 0x%08X\n",
776 (unsigned int)toggle
,
780 wbcir_keydown(data
, scancode
, toggle
);
784 wbcir_parse_rc5(struct device
*dev
, struct wbcir_data
*data
)
787 * Bits are manchester coded as follows:
788 * cell1 + cell0 = logic "0"
789 * cell0 + cell1 = logic "1"
790 * (i.e. the reverse of RC6)
792 * Start bit 1 - "1" - discarded
793 * Start bit 2 - Must be inverted to get command bit 6
804 if (!get_bits(data
, 1)) {
805 dev_dbg(dev
, "RC5 - Invalid start bit\n");
810 if (!wbcir_get_rc5bits(data
, 1))
815 toggle
= wbcir_get_rc5bits(data
, 1);
816 address
= wbcir_get_rc5bits(data
, 5);
817 command
|= wbcir_get_rc5bits(data
, 6);
818 scancode
= address
<< 7 | command
;
820 /* Last sanity check */
821 if (data
->irdata_error
) {
822 dev_dbg(dev
, "RC5 - Invalid message\n");
826 dev_dbg(dev
, "IR-RC5 ad %u cm %u t %u s %u\n",
827 (unsigned int)address
,
828 (unsigned int)command
,
829 (unsigned int)toggle
,
830 (unsigned int)scancode
);
832 wbcir_keydown(data
, scancode
, toggle
);
836 wbcir_parse_nec(struct device
*dev
, struct wbcir_data
*data
)
839 * Each bit represents 560 us.
841 * Leader - 9 ms burst
842 * Gap - 4.5 ms silence
843 * Address1 bit 0 - 7 - Address 1
844 * Address2 bit 0 - 7 - Address 2
845 * Command1 bit 0 - 7 - Command 1
846 * Command2 bit 0 - 7 - Command 2
848 * Note the bit order!
850 * With the old NEC protocol, Address2 was the inverse of Address1
851 * and Command2 was the inverse of Command1 and were used as
854 * With NEC extended, Address1 is the LSB of the Address and
855 * Address2 is the MSB, Command parsing remains unchanged.
857 * A repeat message is coded as:
858 * Leader - 9 ms burst
859 * Gap - 2.25 ms silence
860 * Repeat - 560 us active
870 while (get_bits(data
, 1) && !data
->irdata_error
)
874 if (get_bits(data
, 4)) {
875 dev_dbg(dev
, "NEC - Invalid leader space\n");
880 if (get_bits(data
, 1)) {
881 if (!data
->keypressed
) {
882 dev_dbg(dev
, "NEC - Stray repeat message\n");
886 dev_dbg(dev
, "IR-NEC repeat s %u\n",
887 (unsigned int)data
->last_scancode
);
889 wbcir_keydown(data
, data
->last_scancode
, data
->last_toggle
);
893 /* Remaining leader space */
894 if (get_bits(data
, 3)) {
895 dev_dbg(dev
, "NEC - Invalid leader space\n");
899 address1
= bitrev8(get_bits(data
, 8));
900 address2
= bitrev8(get_bits(data
, 8));
901 command1
= bitrev8(get_bits(data
, 8));
902 command2
= bitrev8(get_bits(data
, 8));
905 if (data
->irdata_error
) {
906 dev_dbg(dev
, "NEC - Invalid message\n");
910 /* Check command validity */
911 if (command1
!= ~command2
) {
912 dev_dbg(dev
, "NEC - Command bytes mismatch\n");
916 /* Check for extended NEC protocol */
918 if (address1
!= ~address2
)
919 address
|= address2
<< 8;
921 scancode
= address
<< 8 | command1
;
923 dev_dbg(dev
, "IR-NEC ad %u cm %u s %u\n",
924 (unsigned int)address
,
925 (unsigned int)command1
,
926 (unsigned int)scancode
);
928 wbcir_keydown(data
, scancode
, !data
->last_toggle
);
933 /*****************************************************************************
935 * INTERRUPT FUNCTIONS
937 *****************************************************************************/
940 wbcir_irq_handler(int irqno
, void *cookie
)
942 struct pnp_dev
*device
= cookie
;
943 struct wbcir_data
*data
= pnp_get_drvdata(device
);
944 struct device
*dev
= &device
->dev
;
951 spin_lock_irqsave(&wbcir_lock
, flags
);
953 wbcir_select_bank(data
, WBCIR_BANK_0
);
955 status
= inb(data
->sbase
+ WBCIR_REG_SP3_EIR
);
957 if (!(status
& (WBCIR_IRQ_RX
| WBCIR_IRQ_ERR
))) {
958 spin_unlock_irqrestore(&wbcir_lock
, flags
);
962 if (status
& WBCIR_IRQ_ERR
)
963 data
->irdata_error
= 1;
965 if (!(status
& WBCIR_IRQ_RX
))
968 /* Since RXHDLEV is set, at least 8 bytes are in the FIFO */
969 insb(data
->sbase
+ WBCIR_REG_SP3_RXDATA
, &irdata
[0], 8);
971 for (i
= 0; i
< sizeof(irdata
); i
++) {
972 hw
= hweight8(irdata
[i
]);
974 add_irdata_bit(data
, 0);
976 add_irdata_bit(data
, 1);
981 data
->idle_count
= 0;
984 if (data
->idle_count
> WBCIR_MAX_IDLE_BYTES
) {
985 /* Set RXINACTIVE... */
986 outb(WBCIR_RX_DISABLE
, data
->sbase
+ WBCIR_REG_SP3_ASCR
);
988 /* ...and drain the FIFO */
989 while (inb(data
->sbase
+ WBCIR_REG_SP3_LSR
) & WBCIR_RX_AVAIL
)
990 inb(data
->sbase
+ WBCIR_REG_SP3_RXDATA
);
992 dev_dbg(dev
, "IRDATA:\n");
993 for (i
= 0; i
< data
->irdata_count
; i
+= BITS_PER_LONG
)
994 dev_dbg(dev
, "0x%08lX\n", data
->irdata
[i
/BITS_PER_LONG
]);
997 case IR_PROTOCOL_RC5
:
998 wbcir_parse_rc5(dev
, data
);
1000 case IR_PROTOCOL_RC6
:
1001 wbcir_parse_rc6(dev
, data
);
1003 case IR_PROTOCOL_NEC
:
1004 wbcir_parse_nec(dev
, data
);
1008 wbcir_reset_irdata(data
);
1012 spin_unlock_irqrestore(&wbcir_lock
, flags
);
1018 /*****************************************************************************
1020 * SETUP/INIT/SUSPEND/RESUME FUNCTIONS
1022 *****************************************************************************/
1025 wbcir_shutdown(struct pnp_dev
*device
)
1027 struct device
*dev
= &device
->dev
;
1028 struct wbcir_data
*data
= pnp_get_drvdata(device
);
1035 memset(match
, 0, sizeof(match
));
1036 memset(mask
, 0, sizeof(mask
));
1038 if (wake_sc
== INVALID_SCANCODE
|| !device_may_wakeup(dev
)) {
1044 case IR_PROTOCOL_RC5
:
1045 if (wake_sc
> 0xFFF) {
1047 dev_err(dev
, "RC5 - Invalid wake scancode\n");
1051 /* Mask = 13 bits, ex toggle */
1055 match
[0] = (wake_sc
& 0x003F); /* 6 command bits */
1056 match
[0] |= (wake_sc
& 0x0180) >> 1; /* 2 address bits */
1057 match
[1] = (wake_sc
& 0x0E00) >> 9; /* 3 address bits */
1058 if (!(wake_sc
& 0x0040)) /* 2nd start bit */
1063 case IR_PROTOCOL_NEC
:
1064 if (wake_sc
> 0xFFFFFF) {
1066 dev_err(dev
, "NEC - Invalid wake scancode\n");
1070 mask
[0] = mask
[1] = mask
[2] = mask
[3] = 0xFF;
1072 match
[1] = bitrev8((wake_sc
& 0xFF));
1073 match
[0] = ~match
[1];
1075 match
[3] = bitrev8((wake_sc
& 0xFF00) >> 8);
1076 if (wake_sc
> 0xFFFF)
1077 match
[2] = bitrev8((wake_sc
& 0xFF0000) >> 16);
1079 match
[2] = ~match
[3];
1083 case IR_PROTOCOL_RC6
:
1085 if (wake_rc6mode
== 0) {
1086 if (wake_sc
> 0xFFFF) {
1088 dev_err(dev
, "RC6 - Invalid wake scancode\n");
1093 match
[0] = wbcir_to_rc6cells(wake_sc
>> 0);
1095 match
[1] = wbcir_to_rc6cells(wake_sc
>> 4);
1099 match
[2] = wbcir_to_rc6cells(wake_sc
>> 8);
1101 match
[3] = wbcir_to_rc6cells(wake_sc
>> 12);
1105 match
[4] = 0x50; /* mode1 = mode0 = 0, ignore toggle */
1107 match
[5] = 0x09; /* start bit = 1, mode2 = 0 */
1112 } else if (wake_rc6mode
== 6) {
1116 match
[i
] = wbcir_to_rc6cells(wake_sc
>> 0);
1118 match
[i
] = wbcir_to_rc6cells(wake_sc
>> 4);
1121 /* Address + Toggle */
1122 match
[i
] = wbcir_to_rc6cells(wake_sc
>> 8);
1124 match
[i
] = wbcir_to_rc6cells(wake_sc
>> 12);
1127 /* Customer bits 7 - 0 */
1128 match
[i
] = wbcir_to_rc6cells(wake_sc
>> 16);
1130 match
[i
] = wbcir_to_rc6cells(wake_sc
>> 20);
1133 if (wake_sc
& 0x80000000) {
1134 /* Customer range bit and bits 15 - 8 */
1135 match
[i
] = wbcir_to_rc6cells(wake_sc
>> 24);
1137 match
[i
] = wbcir_to_rc6cells(wake_sc
>> 28);
1140 } else if (wake_sc
<= 0x007FFFFF) {
1144 dev_err(dev
, "RC6 - Invalid wake scancode\n");
1149 match
[i
] = 0x93; /* mode1 = mode0 = 1, submode = 0 */
1151 match
[i
] = 0x0A; /* start bit = 1, mode2 = 1 */
1156 dev_err(dev
, "RC6 - Invalid wake mode\n");
1168 /* Set compare and compare mask */
1169 wbcir_set_bits(data
->wbase
+ WBCIR_REG_WCEIR_INDEX
,
1170 WBCIR_REGSEL_COMPARE
| WBCIR_REG_ADDR0
,
1172 outsb(data
->wbase
+ WBCIR_REG_WCEIR_DATA
, match
, 11);
1173 wbcir_set_bits(data
->wbase
+ WBCIR_REG_WCEIR_INDEX
,
1174 WBCIR_REGSEL_MASK
| WBCIR_REG_ADDR0
,
1176 outsb(data
->wbase
+ WBCIR_REG_WCEIR_DATA
, mask
, 11);
1178 /* RC6 Compare String Len */
1179 outb(rc6_csl
, data
->wbase
+ WBCIR_REG_WCEIR_CSL
);
1181 /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
1182 wbcir_set_bits(data
->wbase
+ WBCIR_REG_WCEIR_STS
, 0x17, 0x17);
1184 /* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */
1185 wbcir_set_bits(data
->wbase
+ WBCIR_REG_WCEIR_EV_EN
, 0x01, 0x07);
1188 wbcir_set_bits(data
->wbase
+ WBCIR_REG_WCEIR_CTL
, 0x01, 0x01);
1191 /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
1192 wbcir_set_bits(data
->wbase
+ WBCIR_REG_WCEIR_EV_EN
, 0x00, 0x07);
1195 wbcir_set_bits(data
->wbase
+ WBCIR_REG_WCEIR_CTL
, 0x00, 0x01);
1198 /* Disable interrupts */
1199 wbcir_select_bank(data
, WBCIR_BANK_0
);
1200 outb(WBCIR_IRQ_NONE
, data
->sbase
+ WBCIR_REG_SP3_IER
);
1203 * ACPI will set the HW disable bit for SP3 which means that the
1204 * output signals are left in an undefined state which may cause
1205 * spurious interrupts which we need to ignore until the hardware
1208 disable_irq(data
->irq
);
1212 wbcir_suspend(struct pnp_dev
*device
, pm_message_t state
)
1214 wbcir_shutdown(device
);
1219 wbcir_init_hw(struct wbcir_data
*data
)
1223 /* Disable interrupts */
1224 wbcir_select_bank(data
, WBCIR_BANK_0
);
1225 outb(WBCIR_IRQ_NONE
, data
->sbase
+ WBCIR_REG_SP3_IER
);
1227 /* Set PROT_SEL, RX_INV, Clear CEIR_EN (needed for the led) */
1228 tmp
= protocol
<< 4;
1231 outb(tmp
, data
->wbase
+ WBCIR_REG_WCEIR_CTL
);
1233 /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
1234 wbcir_set_bits(data
->wbase
+ WBCIR_REG_WCEIR_STS
, 0x17, 0x17);
1236 /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
1237 wbcir_set_bits(data
->wbase
+ WBCIR_REG_WCEIR_EV_EN
, 0x00, 0x07);
1239 /* Set RC5 cell time to correspond to 36 kHz */
1240 wbcir_set_bits(data
->wbase
+ WBCIR_REG_WCEIR_CFG1
, 0x4A, 0x7F);
1244 outb(0x04, data
->ebase
+ WBCIR_REG_ECEIR_CCTL
);
1246 outb(0x00, data
->ebase
+ WBCIR_REG_ECEIR_CCTL
);
1249 * Clear IR LED, set SP3 clock to 24Mhz
1250 * set SP3_IRRX_SW to binary 01, helpfully not documented
1252 outb(0x10, data
->ebase
+ WBCIR_REG_ECEIR_CTS
);
1254 /* Enable extended mode */
1255 wbcir_select_bank(data
, WBCIR_BANK_2
);
1256 outb(WBCIR_EXT_ENABLE
, data
->sbase
+ WBCIR_REG_SP3_EXCR1
);
1259 * Configure baud generator, IR data will be sampled at
1260 * a bitrate of: (24Mhz * prescaler) / (divisor * 16).
1262 * The ECIR registers include a flag to change the
1263 * 24Mhz clock freq to 48Mhz.
1265 * It's not documented in the specs, but fifo levels
1266 * other than 16 seems to be unsupported.
1269 /* prescaler 1.0, tx/rx fifo lvl 16 */
1270 outb(0x30, data
->sbase
+ WBCIR_REG_SP3_EXCR2
);
1272 /* Set baud divisor to generate one byte per bit/cell */
1274 case IR_PROTOCOL_RC5
:
1275 outb(0xA7, data
->sbase
+ WBCIR_REG_SP3_BGDL
);
1277 case IR_PROTOCOL_RC6
:
1278 outb(0x53, data
->sbase
+ WBCIR_REG_SP3_BGDL
);
1280 case IR_PROTOCOL_NEC
:
1281 outb(0x69, data
->sbase
+ WBCIR_REG_SP3_BGDL
);
1284 outb(0x00, data
->sbase
+ WBCIR_REG_SP3_BGDH
);
1287 wbcir_select_bank(data
, WBCIR_BANK_0
);
1288 outb(0xC0, data
->sbase
+ WBCIR_REG_SP3_MCR
);
1289 inb(data
->sbase
+ WBCIR_REG_SP3_LSR
); /* Clear LSR */
1290 inb(data
->sbase
+ WBCIR_REG_SP3_MSR
); /* Clear MSR */
1292 /* Disable RX demod, run-length encoding/decoding, set freq span */
1293 wbcir_select_bank(data
, WBCIR_BANK_7
);
1294 outb(0x10, data
->sbase
+ WBCIR_REG_SP3_RCCFG
);
1297 wbcir_select_bank(data
, WBCIR_BANK_4
);
1298 outb(0x00, data
->sbase
+ WBCIR_REG_SP3_IRCR1
);
1300 /* Enable MSR interrupt, Clear AUX_IRX */
1301 wbcir_select_bank(data
, WBCIR_BANK_5
);
1302 outb(0x00, data
->sbase
+ WBCIR_REG_SP3_IRCR2
);
1305 wbcir_select_bank(data
, WBCIR_BANK_6
);
1306 outb(0x20, data
->sbase
+ WBCIR_REG_SP3_IRCR3
);
1308 /* Set RX/TX (de)modulation freq, not really used */
1309 wbcir_select_bank(data
, WBCIR_BANK_7
);
1310 outb(0xF2, data
->sbase
+ WBCIR_REG_SP3_IRRXDC
);
1311 outb(0x69, data
->sbase
+ WBCIR_REG_SP3_IRTXMC
);
1313 /* Set invert and pin direction */
1315 outb(0x10, data
->sbase
+ WBCIR_REG_SP3_IRCFG4
);
1317 outb(0x00, data
->sbase
+ WBCIR_REG_SP3_IRCFG4
);
1319 /* Set FIFO thresholds (RX = 8, TX = 3), reset RX/TX */
1320 wbcir_select_bank(data
, WBCIR_BANK_0
);
1321 outb(0x97, data
->sbase
+ WBCIR_REG_SP3_FCR
);
1323 /* Clear AUX status bits */
1324 outb(0xE0, data
->sbase
+ WBCIR_REG_SP3_ASCR
);
1326 /* Enable interrupts */
1327 wbcir_reset_irdata(data
);
1328 outb(WBCIR_IRQ_RX
| WBCIR_IRQ_ERR
, data
->sbase
+ WBCIR_REG_SP3_IER
);
1332 wbcir_resume(struct pnp_dev
*device
)
1334 struct wbcir_data
*data
= pnp_get_drvdata(device
);
1336 wbcir_init_hw(data
);
1337 enable_irq(data
->irq
);
1342 static int __devinit
1343 wbcir_probe(struct pnp_dev
*device
, const struct pnp_device_id
*dev_id
)
1345 struct device
*dev
= &device
->dev
;
1346 struct wbcir_data
*data
;
1349 if (!(pnp_port_len(device
, 0) == EHFUNC_IOMEM_LEN
&&
1350 pnp_port_len(device
, 1) == WAKEUP_IOMEM_LEN
&&
1351 pnp_port_len(device
, 2) == SP_IOMEM_LEN
)) {
1352 dev_err(dev
, "Invalid resources\n");
1356 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
1362 pnp_set_drvdata(device
, data
);
1364 data
->ebase
= pnp_port_start(device
, 0);
1365 data
->wbase
= pnp_port_start(device
, 1);
1366 data
->sbase
= pnp_port_start(device
, 2);
1367 data
->irq
= pnp_irq(device
, 0);
1369 if (data
->wbase
== 0 || data
->ebase
== 0 ||
1370 data
->sbase
== 0 || data
->irq
== 0) {
1372 dev_err(dev
, "Invalid resources\n");
1373 goto exit_free_data
;
1376 dev_dbg(&device
->dev
, "Found device "
1377 "(w: 0x%lX, e: 0x%lX, s: 0x%lX, i: %u)\n",
1378 data
->wbase
, data
->ebase
, data
->sbase
, data
->irq
);
1380 if (!request_region(data
->wbase
, WAKEUP_IOMEM_LEN
, DRVNAME
)) {
1381 dev_err(dev
, "Region 0x%lx-0x%lx already in use!\n",
1382 data
->wbase
, data
->wbase
+ WAKEUP_IOMEM_LEN
- 1);
1384 goto exit_free_data
;
1387 if (!request_region(data
->ebase
, EHFUNC_IOMEM_LEN
, DRVNAME
)) {
1388 dev_err(dev
, "Region 0x%lx-0x%lx already in use!\n",
1389 data
->ebase
, data
->ebase
+ EHFUNC_IOMEM_LEN
- 1);
1391 goto exit_release_wbase
;
1394 if (!request_region(data
->sbase
, SP_IOMEM_LEN
, DRVNAME
)) {
1395 dev_err(dev
, "Region 0x%lx-0x%lx already in use!\n",
1396 data
->sbase
, data
->sbase
+ SP_IOMEM_LEN
- 1);
1398 goto exit_release_ebase
;
1401 err
= request_irq(data
->irq
, wbcir_irq_handler
,
1402 IRQF_DISABLED
, DRVNAME
, device
);
1404 dev_err(dev
, "Failed to claim IRQ %u\n", data
->irq
);
1406 goto exit_release_sbase
;
1409 led_trigger_register_simple("cir-tx", &data
->txtrigger
);
1410 if (!data
->txtrigger
) {
1415 led_trigger_register_simple("cir-rx", &data
->rxtrigger
);
1416 if (!data
->rxtrigger
) {
1418 goto exit_unregister_txtrigger
;
1421 data
->led
.name
= "cir::activity";
1422 data
->led
.default_trigger
= "cir-rx";
1423 data
->led
.brightness_set
= wbcir_led_brightness_set
;
1424 data
->led
.brightness_get
= wbcir_led_brightness_get
;
1425 err
= led_classdev_register(&device
->dev
, &data
->led
);
1427 goto exit_unregister_rxtrigger
;
1429 data
->input_dev
= input_allocate_device();
1430 if (!data
->input_dev
) {
1432 goto exit_unregister_led
;
1435 data
->input_dev
->evbit
[0] = BIT(EV_KEY
);
1436 data
->input_dev
->name
= WBCIR_NAME
;
1437 data
->input_dev
->phys
= "wbcir/cir0";
1438 data
->input_dev
->id
.bustype
= BUS_HOST
;
1439 data
->input_dev
->id
.vendor
= PCI_VENDOR_ID_WINBOND
;
1440 data
->input_dev
->id
.product
= WBCIR_ID_FAMILY
;
1441 data
->input_dev
->id
.version
= WBCIR_ID_CHIP
;
1442 data
->input_dev
->getkeycode
= wbcir_getkeycode
;
1443 data
->input_dev
->setkeycode
= wbcir_setkeycode
;
1444 input_set_capability(data
->input_dev
, EV_MSC
, MSC_SCAN
);
1445 input_set_drvdata(data
->input_dev
, data
);
1447 err
= input_register_device(data
->input_dev
);
1449 goto exit_free_input
;
1451 data
->last_scancode
= INVALID_SCANCODE
;
1452 INIT_LIST_HEAD(&data
->keytable
);
1453 setup_timer(&data
->timer_keyup
, wbcir_keyup
, (unsigned long)data
);
1455 /* Load default keymaps */
1456 if (protocol
== IR_PROTOCOL_RC6
) {
1458 for (i
= 0; i
< ARRAY_SIZE(rc6_def_keymap
); i
++) {
1459 err
= wbcir_setkeycode(data
->input_dev
,
1460 (int)rc6_def_keymap
[i
].scancode
,
1461 (int)rc6_def_keymap
[i
].keycode
);
1463 goto exit_unregister_keys
;
1467 device_init_wakeup(&device
->dev
, 1);
1469 wbcir_init_hw(data
);
1473 exit_unregister_keys
:
1474 if (!list_empty(&data
->keytable
)) {
1475 struct wbcir_keyentry
*key
;
1476 struct wbcir_keyentry
*keytmp
;
1478 list_for_each_entry_safe(key
, keytmp
, &data
->keytable
, list
) {
1479 list_del(&key
->list
);
1483 input_unregister_device(data
->input_dev
);
1484 /* Can't call input_free_device on an unregistered device */
1485 data
->input_dev
= NULL
;
1487 input_free_device(data
->input_dev
);
1488 exit_unregister_led
:
1489 led_classdev_unregister(&data
->led
);
1490 exit_unregister_rxtrigger
:
1491 led_trigger_unregister_simple(data
->rxtrigger
);
1492 exit_unregister_txtrigger
:
1493 led_trigger_unregister_simple(data
->txtrigger
);
1495 free_irq(data
->irq
, device
);
1497 release_region(data
->sbase
, SP_IOMEM_LEN
);
1499 release_region(data
->ebase
, EHFUNC_IOMEM_LEN
);
1501 release_region(data
->wbase
, WAKEUP_IOMEM_LEN
);
1504 pnp_set_drvdata(device
, NULL
);
1509 static void __devexit
1510 wbcir_remove(struct pnp_dev
*device
)
1512 struct wbcir_data
*data
= pnp_get_drvdata(device
);
1513 struct wbcir_keyentry
*key
;
1514 struct wbcir_keyentry
*keytmp
;
1516 /* Disable interrupts */
1517 wbcir_select_bank(data
, WBCIR_BANK_0
);
1518 outb(WBCIR_IRQ_NONE
, data
->sbase
+ WBCIR_REG_SP3_IER
);
1520 del_timer_sync(&data
->timer_keyup
);
1522 free_irq(data
->irq
, device
);
1524 /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
1525 wbcir_set_bits(data
->wbase
+ WBCIR_REG_WCEIR_STS
, 0x17, 0x17);
1528 wbcir_set_bits(data
->wbase
+ WBCIR_REG_WCEIR_CTL
, 0x00, 0x01);
1530 /* Clear BUFF_EN, END_EN, MATCH_EN */
1531 wbcir_set_bits(data
->wbase
+ WBCIR_REG_WCEIR_EV_EN
, 0x00, 0x07);
1533 /* This will generate a keyup event if necessary */
1534 input_unregister_device(data
->input_dev
);
1536 led_trigger_unregister_simple(data
->rxtrigger
);
1537 led_trigger_unregister_simple(data
->txtrigger
);
1538 led_classdev_unregister(&data
->led
);
1540 /* This is ok since &data->led isn't actually used */
1541 wbcir_led_brightness_set(&data
->led
, LED_OFF
);
1543 release_region(data
->wbase
, WAKEUP_IOMEM_LEN
);
1544 release_region(data
->ebase
, EHFUNC_IOMEM_LEN
);
1545 release_region(data
->sbase
, SP_IOMEM_LEN
);
1547 list_for_each_entry_safe(key
, keytmp
, &data
->keytable
, list
) {
1548 list_del(&key
->list
);
1554 pnp_set_drvdata(device
, NULL
);
1557 static const struct pnp_device_id wbcir_ids
[] = {
1561 MODULE_DEVICE_TABLE(pnp
, wbcir_ids
);
1563 static struct pnp_driver wbcir_driver
= {
1565 .id_table
= wbcir_ids
,
1566 .probe
= wbcir_probe
,
1567 .remove
= __devexit_p(wbcir_remove
),
1568 .suspend
= wbcir_suspend
,
1569 .resume
= wbcir_resume
,
1570 .shutdown
= wbcir_shutdown
1579 case IR_PROTOCOL_RC5
:
1580 case IR_PROTOCOL_NEC
:
1581 case IR_PROTOCOL_RC6
:
1584 printk(KERN_ERR DRVNAME
": Invalid protocol argument\n");
1588 ret
= pnp_register_driver(&wbcir_driver
);
1590 printk(KERN_ERR DRVNAME
": Unable to register driver\n");
1598 pnp_unregister_driver(&wbcir_driver
);
1601 MODULE_AUTHOR("David Härdeman <david@hardeman.nu>");
1602 MODULE_DESCRIPTION("Winbond SuperI/O Consumer IR Driver");
1603 MODULE_LICENSE("GPL");
1605 module_init(wbcir_init
);
1606 module_exit(wbcir_exit
);