44 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
46 #include <linux/module.h>
55 #include <linux/slab.h>
56 #include <linux/wait.h>
57 #include <linux/sched.h>
60 #define DRVNAME "winbond-cir"
63 #define WBCIR_REG_WCEIR_CTL 0x03
64 #define WBCIR_REG_WCEIR_STS 0x04
65 #define WBCIR_REG_WCEIR_EV_EN 0x05
66 #define WBCIR_REG_WCEIR_CNTL 0x06
67 #define WBCIR_REG_WCEIR_CNTH 0x07
68 #define WBCIR_REG_WCEIR_INDEX 0x08
69 #define WBCIR_REG_WCEIR_DATA 0x09
70 #define WBCIR_REG_WCEIR_CSL 0x0A
71 #define WBCIR_REG_WCEIR_CFG1 0x0B
72 #define WBCIR_REG_WCEIR_CFG2 0x0C
75 #define WBCIR_REG_ECEIR_CTS 0x00
76 #define WBCIR_REG_ECEIR_CCTL 0x01
77 #define WBCIR_REG_ECEIR_CNT_LO 0x02
78 #define WBCIR_REG_ECEIR_CNT_HI 0x03
79 #define WBCIR_REG_ECEIR_IREM 0x04
82 #define WBCIR_REG_SP3_BSR 0x03
84 #define WBCIR_REG_SP3_RXDATA 0x00
85 #define WBCIR_REG_SP3_TXDATA 0x00
86 #define WBCIR_REG_SP3_IER 0x01
87 #define WBCIR_REG_SP3_EIR 0x02
88 #define WBCIR_REG_SP3_FCR 0x02
89 #define WBCIR_REG_SP3_MCR 0x04
90 #define WBCIR_REG_SP3_LSR 0x05
91 #define WBCIR_REG_SP3_MSR 0x06
92 #define WBCIR_REG_SP3_ASCR 0x07
94 #define WBCIR_REG_SP3_BGDL 0x00
95 #define WBCIR_REG_SP3_BGDH 0x01
96 #define WBCIR_REG_SP3_EXCR1 0x02
97 #define WBCIR_REG_SP3_EXCR2 0x04
98 #define WBCIR_REG_SP3_TXFLV 0x06
99 #define WBCIR_REG_SP3_RXFLV 0x07
101 #define WBCIR_REG_SP3_MRID 0x00
102 #define WBCIR_REG_SP3_SH_LCR 0x01
103 #define WBCIR_REG_SP3_SH_FCR 0x02
105 #define WBCIR_REG_SP3_IRCR1 0x02
107 #define WBCIR_REG_SP3_IRCR2 0x04
109 #define WBCIR_REG_SP3_IRCR3 0x00
110 #define WBCIR_REG_SP3_SIR_PW 0x02
112 #define WBCIR_REG_SP3_IRRXDC 0x00
113 #define WBCIR_REG_SP3_IRTXMC 0x01
114 #define WBCIR_REG_SP3_RCCFG 0x02
115 #define WBCIR_REG_SP3_IRCFG1 0x04
116 #define WBCIR_REG_SP3_IRCFG4 0x07
123 #define WBCIR_IRQ_NONE 0x00
125 #define WBCIR_IRQ_RX 0x01
127 #define WBCIR_IRQ_TX_LOW 0x02
129 #define WBCIR_IRQ_ERR 0x04
131 #define WBCIR_IRQ_TX_EMPTY 0x20
133 #define WBCIR_LED_ENABLE 0x80
135 #define WBCIR_RX_AVAIL 0x01
137 #define WBCIR_RX_OVERRUN 0x02
139 #define WBCIR_TX_EOT 0x04
141 #define WBCIR_RX_DISABLE 0x20
143 #define WBCIR_TX_UNDERRUN 0x40
145 #define WBCIR_EXT_ENABLE 0x01
147 #define WBCIR_REGSEL_COMPARE 0x10
149 #define WBCIR_REGSEL_MASK 0x20
151 #define WBCIR_REG_ADDR0 0x00
187 #define WBCIR_NAME "winbond-cir"
188 #define WBCIR_ID_FAMILY 0xF1
189 #define WBCIR_ID_CHIP 0x04
190 #define INVALID_SCANCODE 0x7FFFFFFF
191 #define WAKEUP_IOMEM_LEN 0x10
192 #define EHFUNC_IOMEM_LEN 0x10
193 #define SP_IOMEM_LEN 0x08
225 "(0 = RC5, 1 = NEC, 2 = RC6A, default)");
235 static unsigned int wake_sc = 0x800F040C;
239 static unsigned int wake_rc6mode = 6;
242 "(0 = 0, 6 = 6A, default)");
259 val = ((val & ~mask) | (bits & mask));
309 wbcir_to_rc6cells(
u8 val)
315 for (i = 0; i < 4; i++) {
317 coded |= 0x02 << (i * 2);
319 coded |= 0x01 << (i * 2);
358 rawir.pulse = irdata & 0x80 ?
false :
true;
359 rawir.duration =
US_TO_NS(((irdata & 0x7F) + 1) * 10);
364 if (data->
dev->idle) {
405 for (used = 0; used < space && data->
txoff != data->
txlen; used++) {
413 byte |= (data->
txoff % 2 ? 0x80 : 0x00);
449 wbcir_irq_handler(
int irqno,
void *
cookie)
452 struct wbcir_data *data = pnp_get_drvdata(device);
462 spin_unlock_irqrestore(&data->
spinlock, flags);
470 ir_raw_event_reset(data->
dev);
479 wbcir_irq_rx(data, device);
484 spin_unlock_irqrestore(&data->
spinlock, flags);
495 wbcir_txcarrier(
struct rc_dev *dev,
u32 carrier)
503 if (freq < 30 || freq > 60)
525 spin_unlock_irqrestore(&data->
spinlock, flags);
535 spin_unlock_irqrestore(&data->
spinlock, flags);
540 wbcir_txmask(
struct rc_dev *dev,
u32 mask)
566 spin_unlock_irqrestore(&data->
spinlock, flags);
570 if (data->
txmask != mask) {
575 spin_unlock_irqrestore(&data->
spinlock, flags);
580 wbcir_tx(
struct rc_dev *dev,
unsigned *
b,
unsigned count)
592 for (i = 0; i <
count; i++)
598 spin_unlock_irqrestore(&data->
spinlock, flags);
610 spin_unlock_irqrestore(&data->
spinlock, flags);
621 wbcir_shutdown(
struct pnp_dev *device)
623 struct device *dev = &device->
dev;
624 struct wbcir_data *data = pnp_get_drvdata(device);
631 memset(match, 0,
sizeof(match));
632 memset(mask, 0,
sizeof(mask));
641 if (wake_sc > 0xFFF) {
643 dev_err(dev,
"RC5 - Invalid wake scancode\n");
651 match[0] = (wake_sc & 0x003F);
652 match[0] |= (wake_sc & 0x0180) >> 1;
653 match[1] = (wake_sc & 0x0E00) >> 9;
654 if (!(wake_sc & 0x0040))
660 if (wake_sc > 0xFFFFFF) {
662 dev_err(dev,
"NEC - Invalid wake scancode\n");
666 mask[0] = mask[1] = mask[2] = mask[3] = 0xFF;
668 match[1] = bitrev8((wake_sc & 0xFF));
669 match[0] = ~match[1];
671 match[3] = bitrev8((wake_sc & 0xFF00) >> 8);
672 if (wake_sc > 0xFFFF)
673 match[2] = bitrev8((wake_sc & 0xFF0000) >> 16);
675 match[2] = ~match[3];
681 if (wake_rc6mode == 0) {
682 if (wake_sc > 0xFFFF) {
684 dev_err(dev,
"RC6 - Invalid wake scancode\n");
689 match[0] = wbcir_to_rc6cells(wake_sc >> 0);
691 match[1] = wbcir_to_rc6cells(wake_sc >> 4);
695 match[2] = wbcir_to_rc6cells(wake_sc >> 8);
697 match[3] = wbcir_to_rc6cells(wake_sc >> 12);
708 }
else if (wake_rc6mode == 6) {
712 match[
i] = wbcir_to_rc6cells(wake_sc >> 0);
714 match[
i] = wbcir_to_rc6cells(wake_sc >> 4);
718 match[
i] = wbcir_to_rc6cells(wake_sc >> 8);
720 match[
i] = wbcir_to_rc6cells(wake_sc >> 12);
724 match[
i] = wbcir_to_rc6cells(wake_sc >> 16);
726 match[
i] = wbcir_to_rc6cells(wake_sc >> 20);
729 if (wake_sc & 0x80000000) {
731 match[
i] = wbcir_to_rc6cells(wake_sc >> 24);
733 match[
i] = wbcir_to_rc6cells(wake_sc >> 28);
736 }
else if (wake_sc <= 0x007FFFFF) {
740 dev_err(dev,
"RC6 - Invalid wake scancode\n");
752 dev_err(dev,
"RC6 - Invalid wake mode\n");
811 wbcir_shutdown(device);
918 data->
rxev.duration = 0;
919 ir_raw_event_reset(data->
dev);
930 wbcir_set_irqmask(data, WBCIR_IRQ_RX | WBCIR_IRQ_ERR);
934 wbcir_resume(
struct pnp_dev *device)
936 struct wbcir_data *data = pnp_get_drvdata(device);
947 struct device *dev = &device->
dev;
954 dev_err(dev,
"Invalid resources\n");
964 pnp_set_drvdata(device, data);
967 data->
ebase = pnp_port_start(device, 0);
968 data->
wbase = pnp_port_start(device, 1);
969 data->
sbase = pnp_port_start(device, 2);
973 data->
sbase == 0 || data->
irq == 0) {
975 dev_err(dev,
"Invalid resources\n");
980 "(w: 0x%lX, e: 0x%lX, s: 0x%lX, i: %u)\n",
992 goto exit_unregister_txtrigger;
995 data->
led.name =
"cir::activity";
996 data->
led.default_trigger =
"cir-rx";
997 data->
led.brightness_set = wbcir_led_brightness_set;
998 data->
led.brightness_get = wbcir_led_brightness_get;
1001 goto exit_unregister_rxtrigger;
1006 goto exit_unregister_led;
1012 data->
dev->input_phys =
"wbcir/cir0";
1018 data->
dev->s_idle = wbcir_idle_rx;
1019 data->
dev->s_tx_mask = wbcir_txmask;
1020 data->
dev->s_tx_carrier = wbcir_txcarrier;
1021 data->
dev->tx_ir = wbcir_tx;
1023 data->
dev->dev.parent = &device->
dev;
1028 dev_err(dev,
"Region 0x%lx-0x%lx already in use!\n",
1035 dev_err(dev,
"Region 0x%lx-0x%lx already in use!\n",
1038 goto exit_release_wbase;
1042 dev_err(dev,
"Region 0x%lx-0x%lx already in use!\n",
1045 goto exit_release_ebase;
1051 dev_err(dev,
"Failed to claim IRQ %u\n", data->
irq);
1053 goto exit_release_sbase;
1062 wbcir_init_hw(data);
1076 exit_unregister_led:
1078 exit_unregister_rxtrigger:
1080 exit_unregister_txtrigger:
1084 pnp_set_drvdata(device,
NULL);
1090 wbcir_remove(
struct pnp_dev *device)
1092 struct wbcir_data *data = pnp_get_drvdata(device);
1114 wbcir_led_brightness_set(&data->
led,
LED_OFF);
1122 pnp_set_drvdata(device,
NULL);
1133 .id_table = wbcir_ids,
1134 .probe = wbcir_probe,
1136 .suspend = wbcir_suspend,
1137 .resume = wbcir_resume,
1138 .shutdown = wbcir_shutdown
1152 pr_err(
"Invalid power-on protocol\n");
1157 pr_err(
"Unable to register driver\n");