winbond-cir.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  1. /*
  2. * winbond-cir.c - Driver for the Consumer IR functionality of Winbond
  3. * SuperI/O chips.
  4. *
  5. * Currently supports the Winbond WPCD376i chip (PNP id WEC1022), but
  6. * could probably support others (Winbond WEC102X, NatSemi, etc)
  7. * with minor modifications.
  8. *
  9. * Original Author: David Härdeman <david@hardeman.nu>
  10. * Copyright (C) 2009 - 2011 David Härdeman <david@hardeman.nu>
  11. *
  12. * Dedicated to my daughter Matilda, without whose loving attention this
  13. * driver would have been finished in half the time and with a fraction
  14. * of the bugs.
  15. *
  16. * Written using:
  17. * o Winbond WPCD376I datasheet helpfully provided by Jesse Barnes at Intel
  18. * o NatSemi PC87338/PC97338 datasheet (for the serial port stuff)
  19. * o DSDT dumps
  20. *
  21. * Supported features:
  22. * o IR Receive
  23. * o IR Transmit
  24. * o Wake-On-CIR functionality
  25. *
  26. * To do:
  27. * o Learning
  28. *
  29. * This program is free software; you can redistribute it and/or modify
  30. * it under the terms of the GNU General Public License as published by
  31. * the Free Software Foundation; either version 2 of the License, or
  32. * (at your option) any later version.
  33. *
  34. * This program is distributed in the hope that it will be useful,
  35. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  36. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  37. * GNU General Public License for more details.
  38. *
  39. * You should have received a copy of the GNU General Public License
  40. * along with this program; if not, write to the Free Software
  41. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  42. */
  43. #include <linux/module.h>
  44. #include <linux/pnp.h>
  45. #include <linux/interrupt.h>
  46. #include <linux/timer.h>
  47. #include <linux/leds.h>
  48. #include <linux/spinlock.h>
  49. #include <linux/pci_ids.h>
  50. #include <linux/io.h>
  51. #include <linux/bitrev.h>
  52. #include <linux/slab.h>
  53. #include <linux/wait.h>
  54. #include <linux/sched.h>
  55. #include <media/rc-core.h>
  56. #define DRVNAME "winbond-cir"
  57. /* CEIR Wake-Up Registers, relative to data->wbase */
  58. #define WBCIR_REG_WCEIR_CTL 0x03 /* CEIR Receiver Control */
  59. #define WBCIR_REG_WCEIR_STS 0x04 /* CEIR Receiver Status */
  60. #define WBCIR_REG_WCEIR_EV_EN 0x05 /* CEIR Receiver Event Enable */
  61. #define WBCIR_REG_WCEIR_CNTL 0x06 /* CEIR Receiver Counter Low */
  62. #define WBCIR_REG_WCEIR_CNTH 0x07 /* CEIR Receiver Counter High */
  63. #define WBCIR_REG_WCEIR_INDEX 0x08 /* CEIR Receiver Index */
  64. #define WBCIR_REG_WCEIR_DATA 0x09 /* CEIR Receiver Data */
  65. #define WBCIR_REG_WCEIR_CSL 0x0A /* CEIR Re. Compare Strlen */
  66. #define WBCIR_REG_WCEIR_CFG1 0x0B /* CEIR Re. Configuration 1 */
  67. #define WBCIR_REG_WCEIR_CFG2 0x0C /* CEIR Re. Configuration 2 */
  68. /* CEIR Enhanced Functionality Registers, relative to data->ebase */
  69. #define WBCIR_REG_ECEIR_CTS 0x00 /* Enhanced IR Control Status */
  70. #define WBCIR_REG_ECEIR_CCTL 0x01 /* Infrared Counter Control */
  71. #define WBCIR_REG_ECEIR_CNT_LO 0x02 /* Infrared Counter LSB */
  72. #define WBCIR_REG_ECEIR_CNT_HI 0x03 /* Infrared Counter MSB */
  73. #define WBCIR_REG_ECEIR_IREM 0x04 /* Infrared Emitter Status */
  74. /* SP3 Banked Registers, relative to data->sbase */
  75. #define WBCIR_REG_SP3_BSR 0x03 /* Bank Select, all banks */
  76. /* Bank 0 */
  77. #define WBCIR_REG_SP3_RXDATA 0x00 /* FIFO RX data (r) */
  78. #define WBCIR_REG_SP3_TXDATA 0x00 /* FIFO TX data (w) */
  79. #define WBCIR_REG_SP3_IER 0x01 /* Interrupt Enable */
  80. #define WBCIR_REG_SP3_EIR 0x02 /* Event Identification (r) */
  81. #define WBCIR_REG_SP3_FCR 0x02 /* FIFO Control (w) */
  82. #define WBCIR_REG_SP3_MCR 0x04 /* Mode Control */
  83. #define WBCIR_REG_SP3_LSR 0x05 /* Link Status */
  84. #define WBCIR_REG_SP3_MSR 0x06 /* Modem Status */
  85. #define WBCIR_REG_SP3_ASCR 0x07 /* Aux Status and Control */
  86. /* Bank 2 */
  87. #define WBCIR_REG_SP3_BGDL 0x00 /* Baud Divisor LSB */
  88. #define WBCIR_REG_SP3_BGDH 0x01 /* Baud Divisor MSB */
  89. #define WBCIR_REG_SP3_EXCR1 0x02 /* Extended Control 1 */
  90. #define WBCIR_REG_SP3_EXCR2 0x04 /* Extended Control 2 */
  91. #define WBCIR_REG_SP3_TXFLV 0x06 /* TX FIFO Level */
  92. #define WBCIR_REG_SP3_RXFLV 0x07 /* RX FIFO Level */
  93. /* Bank 3 */
  94. #define WBCIR_REG_SP3_MRID 0x00 /* Module Identification */
  95. #define WBCIR_REG_SP3_SH_LCR 0x01 /* LCR Shadow */
  96. #define WBCIR_REG_SP3_SH_FCR 0x02 /* FCR Shadow */
  97. /* Bank 4 */
  98. #define WBCIR_REG_SP3_IRCR1 0x02 /* Infrared Control 1 */
  99. /* Bank 5 */
  100. #define WBCIR_REG_SP3_IRCR2 0x04 /* Infrared Control 2 */
  101. /* Bank 6 */
  102. #define WBCIR_REG_SP3_IRCR3 0x00 /* Infrared Control 3 */
  103. #define WBCIR_REG_SP3_SIR_PW 0x02 /* SIR Pulse Width */
  104. /* Bank 7 */
  105. #define WBCIR_REG_SP3_IRRXDC 0x00 /* IR RX Demod Control */
  106. #define WBCIR_REG_SP3_IRTXMC 0x01 /* IR TX Mod Control */
  107. #define WBCIR_REG_SP3_RCCFG 0x02 /* CEIR Config */
  108. #define WBCIR_REG_SP3_IRCFG1 0x04 /* Infrared Config 1 */
  109. #define WBCIR_REG_SP3_IRCFG4 0x07 /* Infrared Config 4 */
  110. /*
  111. * Magic values follow
  112. */
  113. /* No interrupts for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */
  114. #define WBCIR_IRQ_NONE 0x00
  115. /* RX data bit for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */
  116. #define WBCIR_IRQ_RX 0x01
  117. /* TX data low bit for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */
  118. #define WBCIR_IRQ_TX_LOW 0x02
  119. /* Over/Under-flow bit for WBCIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */
  120. #define WBCIR_IRQ_ERR 0x04
  121. /* TX data empty bit for WBCEIR_REG_SP3_IER and WBCIR_REG_SP3_EIR */
  122. #define WBCIR_IRQ_TX_EMPTY 0x20
  123. /* Led enable/disable bit for WBCIR_REG_ECEIR_CTS */
  124. #define WBCIR_LED_ENABLE 0x80
  125. /* RX data available bit for WBCIR_REG_SP3_LSR */
  126. #define WBCIR_RX_AVAIL 0x01
  127. /* RX data overrun error bit for WBCIR_REG_SP3_LSR */
  128. #define WBCIR_RX_OVERRUN 0x02
  129. /* TX End-Of-Transmission bit for WBCIR_REG_SP3_ASCR */
  130. #define WBCIR_TX_EOT 0x04
  131. /* RX disable bit for WBCIR_REG_SP3_ASCR */
  132. #define WBCIR_RX_DISABLE 0x20
  133. /* TX data underrun error bit for WBCIR_REG_SP3_ASCR */
  134. #define WBCIR_TX_UNDERRUN 0x40
  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
  143. /* Valid banks for the SP3 UART */
  144. enum wbcir_bank {
  145. WBCIR_BANK_0 = 0x00,
  146. WBCIR_BANK_1 = 0x80,
  147. WBCIR_BANK_2 = 0xE0,
  148. WBCIR_BANK_3 = 0xE4,
  149. WBCIR_BANK_4 = 0xE8,
  150. WBCIR_BANK_5 = 0xEC,
  151. WBCIR_BANK_6 = 0xF0,
  152. WBCIR_BANK_7 = 0xF4,
  153. };
  154. /* Supported power-on IR Protocols */
  155. enum wbcir_protocol {
  156. IR_PROTOCOL_RC5 = 0x0,
  157. IR_PROTOCOL_NEC = 0x1,
  158. IR_PROTOCOL_RC6 = 0x2,
  159. };
  160. /* Possible states for IR reception */
  161. enum wbcir_rxstate {
  162. WBCIR_RXSTATE_INACTIVE = 0,
  163. WBCIR_RXSTATE_ACTIVE,
  164. WBCIR_RXSTATE_ERROR
  165. };
  166. /* Possible states for IR transmission */
  167. enum wbcir_txstate {
  168. WBCIR_TXSTATE_INACTIVE = 0,
  169. WBCIR_TXSTATE_ACTIVE,
  170. WBCIR_TXSTATE_DONE,
  171. WBCIR_TXSTATE_ERROR
  172. };
  173. /* Misc */
  174. #define WBCIR_NAME "Winbond CIR"
  175. #define WBCIR_ID_FAMILY 0xF1 /* Family ID for the WPCD376I */
  176. #define WBCIR_ID_CHIP 0x04 /* Chip ID for the WPCD376I */
  177. #define INVALID_SCANCODE 0x7FFFFFFF /* Invalid with all protos */
  178. #define WAKEUP_IOMEM_LEN 0x10 /* Wake-Up I/O Reg Len */
  179. #define EHFUNC_IOMEM_LEN 0x10 /* Enhanced Func I/O Reg Len */
  180. #define SP_IOMEM_LEN 0x08 /* Serial Port 3 (IR) Reg Len */
  181. /* Per-device data */
  182. struct wbcir_data {
  183. spinlock_t spinlock;
  184. struct rc_dev *dev;
  185. struct led_classdev led;
  186. unsigned long wbase; /* Wake-Up Baseaddr */
  187. unsigned long ebase; /* Enhanced Func. Baseaddr */
  188. unsigned long sbase; /* Serial Port Baseaddr */
  189. unsigned int irq; /* Serial Port IRQ */
  190. u8 irqmask;
  191. /* RX state */
  192. enum wbcir_rxstate rxstate;
  193. struct led_trigger *rxtrigger;
  194. struct ir_raw_event rxev;
  195. /* TX state */
  196. enum wbcir_txstate txstate;
  197. struct led_trigger *txtrigger;
  198. u32 txlen;
  199. u32 txoff;
  200. u32 *txbuf;
  201. wait_queue_head_t txwaitq;
  202. u8 txmask;
  203. u32 txcarrier;
  204. };
  205. static enum wbcir_protocol protocol = IR_PROTOCOL_RC6;
  206. module_param(protocol, uint, 0444);
  207. MODULE_PARM_DESC(protocol, "IR protocol to use for the power-on command "
  208. "(0 = RC5, 1 = NEC, 2 = RC6A, default)");
  209. static int invert; /* default = 0 */
  210. module_param(invert, bool, 0444);
  211. MODULE_PARM_DESC(invert, "Invert the signal from the IR receiver");
  212. static int txandrx; /* default = 0 */
  213. module_param(txandrx, bool, 0444);
  214. MODULE_PARM_DESC(invert, "Allow simultaneous TX and RX");
  215. static unsigned int wake_sc = 0x800F040C;
  216. module_param(wake_sc, uint, 0644);
  217. MODULE_PARM_DESC(wake_sc, "Scancode of the power-on IR command");
  218. static unsigned int wake_rc6mode = 6;
  219. module_param(wake_rc6mode, uint, 0644);
  220. MODULE_PARM_DESC(wake_rc6mode, "RC6 mode for the power-on command "
  221. "(0 = 0, 6 = 6A, default)");
  222. /*****************************************************************************
  223. *
  224. * UTILITY FUNCTIONS
  225. *
  226. *****************************************************************************/
  227. /* Caller needs to hold wbcir_lock */
  228. static void
  229. wbcir_set_bits(unsigned long addr, u8 bits, u8 mask)
  230. {
  231. u8 val;
  232. val = inb(addr);
  233. val = ((val & ~mask) | (bits & mask));
  234. outb(val, addr);
  235. }
  236. /* Selects the register bank for the serial port */
  237. static inline void
  238. wbcir_select_bank(struct wbcir_data *data, enum wbcir_bank bank)
  239. {
  240. outb(bank, data->sbase + WBCIR_REG_SP3_BSR);
  241. }
  242. static inline void
  243. wbcir_set_irqmask(struct wbcir_data *data, u8 irqmask)
  244. {
  245. if (data->irqmask == irqmask)
  246. return;
  247. wbcir_select_bank(data, WBCIR_BANK_0);
  248. outb(irqmask, data->sbase + WBCIR_REG_SP3_IER);
  249. data->irqmask = irqmask;
  250. }
  251. static enum led_brightness
  252. wbcir_led_brightness_get(struct led_classdev *led_cdev)
  253. {
  254. struct wbcir_data *data = container_of(led_cdev,
  255. struct wbcir_data,
  256. led);
  257. if (inb(data->ebase + WBCIR_REG_ECEIR_CTS) & WBCIR_LED_ENABLE)
  258. return LED_FULL;
  259. else
  260. return LED_OFF;
  261. }
  262. static void
  263. wbcir_led_brightness_set(struct led_classdev *led_cdev,
  264. enum led_brightness brightness)
  265. {
  266. struct wbcir_data *data = container_of(led_cdev,
  267. struct wbcir_data,
  268. led);
  269. wbcir_set_bits(data->ebase + WBCIR_REG_ECEIR_CTS,
  270. brightness == LED_OFF ? 0x00 : WBCIR_LED_ENABLE,
  271. WBCIR_LED_ENABLE);
  272. }
  273. /* Manchester encodes bits to RC6 message cells (see wbcir_shutdown) */
  274. static u8
  275. wbcir_to_rc6cells(u8 val)
  276. {
  277. u8 coded = 0x00;
  278. int i;
  279. val &= 0x0F;
  280. for (i = 0; i < 4; i++) {
  281. if (val & 0x01)
  282. coded |= 0x02 << (i * 2);
  283. else
  284. coded |= 0x01 << (i * 2);
  285. val >>= 1;
  286. }
  287. return coded;
  288. }
  289. /*****************************************************************************
  290. *
  291. * INTERRUPT FUNCTIONS
  292. *
  293. *****************************************************************************/
  294. static void
  295. wbcir_idle_rx(struct rc_dev *dev, bool idle)
  296. {
  297. struct wbcir_data *data = dev->priv;
  298. if (!idle && data->rxstate == WBCIR_RXSTATE_INACTIVE) {
  299. data->rxstate = WBCIR_RXSTATE_ACTIVE;
  300. led_trigger_event(data->rxtrigger, LED_FULL);
  301. }
  302. if (idle && data->rxstate != WBCIR_RXSTATE_INACTIVE)
  303. /* Tell hardware to go idle by setting RXINACTIVE */
  304. outb(WBCIR_RX_DISABLE, data->sbase + WBCIR_REG_SP3_ASCR);
  305. }
  306. static void
  307. wbcir_irq_rx(struct wbcir_data *data, struct pnp_dev *device)
  308. {
  309. u8 irdata;
  310. DEFINE_IR_RAW_EVENT(rawir);
  311. /* Since RXHDLEV is set, at least 8 bytes are in the FIFO */
  312. while (inb(data->sbase + WBCIR_REG_SP3_LSR) & WBCIR_RX_AVAIL) {
  313. irdata = inb(data->sbase + WBCIR_REG_SP3_RXDATA);
  314. if (data->rxstate == WBCIR_RXSTATE_ERROR)
  315. continue;
  316. rawir.pulse = irdata & 0x80 ? false : true;
  317. rawir.duration = US_TO_NS((irdata & 0x7F) * 10);
  318. ir_raw_event_store_with_filter(data->dev, &rawir);
  319. }
  320. /* Check if we should go idle */
  321. if (data->dev->idle) {
  322. led_trigger_event(data->rxtrigger, LED_OFF);
  323. data->rxstate = WBCIR_RXSTATE_INACTIVE;
  324. }
  325. ir_raw_event_handle(data->dev);
  326. }
  327. static void
  328. wbcir_irq_tx(struct wbcir_data *data)
  329. {
  330. unsigned int space;
  331. unsigned int used;
  332. u8 bytes[16];
  333. u8 byte;
  334. if (!data->txbuf)
  335. return;
  336. switch (data->txstate) {
  337. case WBCIR_TXSTATE_INACTIVE:
  338. /* TX FIFO empty */
  339. space = 16;
  340. led_trigger_event(data->txtrigger, LED_FULL);
  341. break;
  342. case WBCIR_TXSTATE_ACTIVE:
  343. /* TX FIFO low (3 bytes or less) */
  344. space = 13;
  345. break;
  346. case WBCIR_TXSTATE_ERROR:
  347. space = 0;
  348. break;
  349. default:
  350. return;
  351. }
  352. /*
  353. * TX data is run-length coded in bytes: YXXXXXXX
  354. * Y = space (1) or pulse (0)
  355. * X = duration, encoded as (X + 1) * 10us (i.e 10 to 1280 us)
  356. */
  357. for (used = 0; used < space && data->txoff != data->txlen; used++) {
  358. if (data->txbuf[data->txoff] == 0) {
  359. data->txoff++;
  360. continue;
  361. }
  362. byte = min((u32)0x80, data->txbuf[data->txoff]);
  363. data->txbuf[data->txoff] -= byte;
  364. byte--;
  365. byte |= (data->txoff % 2 ? 0x80 : 0x00); /* pulse/space */
  366. bytes[used] = byte;
  367. }
  368. while (data->txbuf[data->txoff] == 0 && data->txoff != data->txlen)
  369. data->txoff++;
  370. if (used == 0) {
  371. /* Finished */
  372. if (data->txstate == WBCIR_TXSTATE_ERROR)
  373. /* Clear TX underrun bit */
  374. outb(WBCIR_TX_UNDERRUN, data->sbase + WBCIR_REG_SP3_ASCR);
  375. else
  376. data->txstate = WBCIR_TXSTATE_DONE;
  377. wbcir_set_irqmask(data, WBCIR_IRQ_RX | WBCIR_IRQ_ERR);
  378. led_trigger_event(data->txtrigger, LED_OFF);
  379. wake_up(&data->txwaitq);
  380. } else if (data->txoff == data->txlen) {
  381. /* At the end of transmission, tell the hw before last byte */
  382. outsb(data->sbase + WBCIR_REG_SP3_TXDATA, bytes, used - 1);
  383. outb(WBCIR_TX_EOT, data->sbase + WBCIR_REG_SP3_ASCR);
  384. outb(bytes[used - 1], data->sbase + WBCIR_REG_SP3_TXDATA);
  385. wbcir_set_irqmask(data, WBCIR_IRQ_RX | WBCIR_IRQ_ERR |
  386. WBCIR_IRQ_TX_EMPTY);
  387. } else {
  388. /* More data to follow... */
  389. outsb(data->sbase + WBCIR_REG_SP3_RXDATA, bytes, used);
  390. if (data->txstate == WBCIR_TXSTATE_INACTIVE) {
  391. wbcir_set_irqmask(data, WBCIR_IRQ_RX | WBCIR_IRQ_ERR |
  392. WBCIR_IRQ_TX_LOW);
  393. data->txstate = WBCIR_TXSTATE_ACTIVE;
  394. }
  395. }
  396. }
  397. static irqreturn_t
  398. wbcir_irq_handler(int irqno, void *cookie)
  399. {
  400. struct pnp_dev *device = cookie;
  401. struct wbcir_data *data = pnp_get_drvdata(device);
  402. unsigned long flags;
  403. u8 status;
  404. spin_lock_irqsave(&data->spinlock, flags);
  405. wbcir_select_bank(data, WBCIR_BANK_0);
  406. status = inb(data->sbase + WBCIR_REG_SP3_EIR);
  407. status &= data->irqmask;
  408. if (!status) {
  409. spin_unlock_irqrestore(&data->spinlock, flags);
  410. return IRQ_NONE;
  411. }
  412. if (status & WBCIR_IRQ_ERR) {
  413. /* RX overflow? (read clears bit) */
  414. if (inb(data->sbase + WBCIR_REG_SP3_LSR) & WBCIR_RX_OVERRUN) {
  415. data->rxstate = WBCIR_RXSTATE_ERROR;
  416. ir_raw_event_reset(data->dev);
  417. }
  418. /* TX underflow? */
  419. if (inb(data->sbase + WBCIR_REG_SP3_ASCR) & WBCIR_TX_UNDERRUN)
  420. data->txstate = WBCIR_TXSTATE_ERROR;
  421. }
  422. if (status & WBCIR_IRQ_RX)
  423. wbcir_irq_rx(data, device);
  424. if (status & (WBCIR_IRQ_TX_LOW | WBCIR_IRQ_TX_EMPTY))
  425. wbcir_irq_tx(data);
  426. spin_unlock_irqrestore(&data->spinlock, flags);
  427. return IRQ_HANDLED;
  428. }
  429. /*****************************************************************************
  430. *
  431. * RC-CORE INTERFACE FUNCTIONS
  432. *
  433. *****************************************************************************/
  434. static int
  435. wbcir_txcarrier(struct rc_dev *dev, u32 carrier)
  436. {
  437. struct wbcir_data *data = dev->priv;
  438. unsigned long flags;
  439. u8 val;
  440. u32 freq;
  441. freq = DIV_ROUND_CLOSEST(carrier, 1000);
  442. if (freq < 30 || freq > 60)
  443. return -EINVAL;
  444. switch (freq) {
  445. case 58:
  446. case 59:
  447. case 60:
  448. val = freq - 58;
  449. freq *= 1000;
  450. break;
  451. case 57:
  452. val = freq - 27;
  453. freq = 56900;
  454. break;
  455. default:
  456. val = freq - 27;
  457. freq *= 1000;
  458. break;
  459. }
  460. spin_lock_irqsave(&data->spinlock, flags);
  461. if (data->txstate != WBCIR_TXSTATE_INACTIVE) {
  462. spin_unlock_irqrestore(&data->spinlock, flags);
  463. return -EBUSY;
  464. }
  465. if (data->txcarrier != freq) {
  466. wbcir_select_bank(data, WBCIR_BANK_7);
  467. wbcir_set_bits(data->sbase + WBCIR_REG_SP3_IRTXMC, val, 0x1F);
  468. data->txcarrier = freq;
  469. }
  470. spin_unlock_irqrestore(&data->spinlock, flags);
  471. return 0;
  472. }
  473. static int
  474. wbcir_txmask(struct rc_dev *dev, u32 mask)
  475. {
  476. struct wbcir_data *data = dev->priv;
  477. unsigned long flags;
  478. u8 val;
  479. /* Four outputs, only one output can be enabled at a time */
  480. switch (mask) {
  481. case 0x1:
  482. val = 0x0;
  483. break;
  484. case 0x2:
  485. val = 0x1;
  486. break;
  487. case 0x4:
  488. val = 0x2;
  489. break;
  490. case 0x8:
  491. val = 0x3;
  492. break;
  493. default:
  494. return -EINVAL;
  495. }
  496. spin_lock_irqsave(&data->spinlock, flags);
  497. if (data->txstate != WBCIR_TXSTATE_INACTIVE) {
  498. spin_unlock_irqrestore(&data->spinlock, flags);
  499. return -EBUSY;
  500. }
  501. if (data->txmask != mask) {
  502. wbcir_set_bits(data->ebase + WBCIR_REG_ECEIR_CTS, val, 0x0c);
  503. data->txmask = mask;
  504. }
  505. spin_unlock_irqrestore(&data->spinlock, flags);
  506. return 0;
  507. }
  508. static int
  509. wbcir_tx(struct rc_dev *dev, unsigned *buf, unsigned count)
  510. {
  511. struct wbcir_data *data = dev->priv;
  512. unsigned i;
  513. unsigned long flags;
  514. /* Not sure if this is possible, but better safe than sorry */
  515. spin_lock_irqsave(&data->spinlock, flags);
  516. if (data->txstate != WBCIR_TXSTATE_INACTIVE) {
  517. spin_unlock_irqrestore(&data->spinlock, flags);
  518. return -EBUSY;
  519. }
  520. /* Convert values to multiples of 10us */
  521. for (i = 0; i < count; i++)
  522. buf[i] = DIV_ROUND_CLOSEST(buf[i], 10);
  523. /* Fill the TX fifo once, the irq handler will do the rest */
  524. data->txbuf = buf;
  525. data->txlen = count;
  526. data->txoff = 0;
  527. wbcir_irq_tx(data);
  528. /* Wait for the TX to complete */
  529. while (data->txstate == WBCIR_TXSTATE_ACTIVE) {
  530. spin_unlock_irqrestore(&data->spinlock, flags);
  531. wait_event(data->txwaitq, data->txstate != WBCIR_TXSTATE_ACTIVE);
  532. spin_lock_irqsave(&data->spinlock, flags);
  533. }
  534. /* We're done */
  535. if (data->txstate == WBCIR_TXSTATE_ERROR)
  536. count = -EAGAIN;
  537. data->txstate = WBCIR_TXSTATE_INACTIVE;
  538. data->txbuf = NULL;
  539. spin_unlock_irqrestore(&data->spinlock, flags);
  540. return count;
  541. }
  542. /*****************************************************************************
  543. *
  544. * SETUP/INIT/SUSPEND/RESUME FUNCTIONS
  545. *
  546. *****************************************************************************/
  547. static void
  548. wbcir_shutdown(struct pnp_dev *device)
  549. {
  550. struct device *dev = &device->dev;
  551. struct wbcir_data *data = pnp_get_drvdata(device);
  552. bool do_wake = true;
  553. u8 match[11];
  554. u8 mask[11];
  555. u8 rc6_csl = 0;
  556. int i;
  557. memset(match, 0, sizeof(match));
  558. memset(mask, 0, sizeof(mask));
  559. if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev)) {
  560. do_wake = false;
  561. goto finish;
  562. }
  563. switch (protocol) {
  564. case IR_PROTOCOL_RC5:
  565. if (wake_sc > 0xFFF) {
  566. do_wake = false;
  567. dev_err(dev, "RC5 - Invalid wake scancode\n");
  568. break;
  569. }
  570. /* Mask = 13 bits, ex toggle */
  571. mask[0] = 0xFF;
  572. mask[1] = 0x17;
  573. match[0] = (wake_sc & 0x003F); /* 6 command bits */
  574. match[0] |= (wake_sc & 0x0180) >> 1; /* 2 address bits */
  575. match[1] = (wake_sc & 0x0E00) >> 9; /* 3 address bits */
  576. if (!(wake_sc & 0x0040)) /* 2nd start bit */
  577. match[1] |= 0x10;
  578. break;
  579. case IR_PROTOCOL_NEC:
  580. if (wake_sc > 0xFFFFFF) {
  581. do_wake = false;
  582. dev_err(dev, "NEC - Invalid wake scancode\n");
  583. break;
  584. }
  585. mask[0] = mask[1] = mask[2] = mask[3] = 0xFF;
  586. match[1] = bitrev8((wake_sc & 0xFF));
  587. match[0] = ~match[1];
  588. match[3] = bitrev8((wake_sc & 0xFF00) >> 8);
  589. if (wake_sc > 0xFFFF)
  590. match[2] = bitrev8((wake_sc & 0xFF0000) >> 16);
  591. else
  592. match[2] = ~match[3];
  593. break;
  594. case IR_PROTOCOL_RC6:
  595. if (wake_rc6mode == 0) {
  596. if (wake_sc > 0xFFFF) {
  597. do_wake = false;
  598. dev_err(dev, "RC6 - Invalid wake scancode\n");
  599. break;
  600. }
  601. /* Command */
  602. match[0] = wbcir_to_rc6cells(wake_sc >> 0);
  603. mask[0] = 0xFF;
  604. match[1] = wbcir_to_rc6cells(wake_sc >> 4);
  605. mask[1] = 0xFF;
  606. /* Address */
  607. match[2] = wbcir_to_rc6cells(wake_sc >> 8);
  608. mask[2] = 0xFF;
  609. match[3] = wbcir_to_rc6cells(wake_sc >> 12);
  610. mask[3] = 0xFF;
  611. /* Header */
  612. match[4] = 0x50; /* mode1 = mode0 = 0, ignore toggle */
  613. mask[4] = 0xF0;
  614. match[5] = 0x09; /* start bit = 1, mode2 = 0 */
  615. mask[5] = 0x0F;
  616. rc6_csl = 44;
  617. } else if (wake_rc6mode == 6) {
  618. i = 0;
  619. /* Command */
  620. match[i] = wbcir_to_rc6cells(wake_sc >> 0);
  621. mask[i++] = 0xFF;
  622. match[i] = wbcir_to_rc6cells(wake_sc >> 4);
  623. mask[i++] = 0xFF;
  624. /* Address + Toggle */
  625. match[i] = wbcir_to_rc6cells(wake_sc >> 8);
  626. mask[i++] = 0xFF;
  627. match[i] = wbcir_to_rc6cells(wake_sc >> 12);
  628. mask[i++] = 0x3F;
  629. /* Customer bits 7 - 0 */
  630. match[i] = wbcir_to_rc6cells(wake_sc >> 16);
  631. mask[i++] = 0xFF;
  632. match[i] = wbcir_to_rc6cells(wake_sc >> 20);
  633. mask[i++] = 0xFF;
  634. if (wake_sc & 0x80000000) {
  635. /* Customer range bit and bits 15 - 8 */
  636. match[i] = wbcir_to_rc6cells(wake_sc >> 24);
  637. mask[i++] = 0xFF;
  638. match[i] = wbcir_to_rc6cells(wake_sc >> 28);
  639. mask[i++] = 0xFF;
  640. rc6_csl = 76;
  641. } else if (wake_sc <= 0x007FFFFF) {
  642. rc6_csl = 60;
  643. } else {
  644. do_wake = false;
  645. dev_err(dev, "RC6 - Invalid wake scancode\n");
  646. break;
  647. }
  648. /* Header */
  649. match[i] = 0x93; /* mode1 = mode0 = 1, submode = 0 */
  650. mask[i++] = 0xFF;
  651. match[i] = 0x0A; /* start bit = 1, mode2 = 1 */
  652. mask[i++] = 0x0F;
  653. } else {
  654. do_wake = false;
  655. dev_err(dev, "RC6 - Invalid wake mode\n");
  656. }
  657. break;
  658. default:
  659. do_wake = false;
  660. break;
  661. }
  662. finish:
  663. if (do_wake) {
  664. /* Set compare and compare mask */
  665. wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
  666. WBCIR_REGSEL_COMPARE | WBCIR_REG_ADDR0,
  667. 0x3F);
  668. outsb(data->wbase + WBCIR_REG_WCEIR_DATA, match, 11);
  669. wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
  670. WBCIR_REGSEL_MASK | WBCIR_REG_ADDR0,
  671. 0x3F);
  672. outsb(data->wbase + WBCIR_REG_WCEIR_DATA, mask, 11);
  673. /* RC6 Compare String Len */
  674. outb(rc6_csl, data->wbase + WBCIR_REG_WCEIR_CSL);
  675. /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
  676. wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17);
  677. /* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */
  678. wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x01, 0x07);
  679. /* Set CEIR_EN */
  680. wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
  681. } else {
  682. /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
  683. wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
  684. /* Clear CEIR_EN */
  685. wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
  686. }
  687. /*
  688. * ACPI will set the HW disable bit for SP3 which means that the
  689. * output signals are left in an undefined state which may cause
  690. * spurious interrupts which we need to ignore until the hardware
  691. * is reinitialized.
  692. */
  693. wbcir_set_irqmask(data, WBCIR_IRQ_NONE);
  694. disable_irq(data->irq);
  695. /* Disable LED */
  696. led_trigger_event(data->rxtrigger, LED_OFF);
  697. led_trigger_event(data->txtrigger, LED_OFF);
  698. }
  699. static int
  700. wbcir_suspend(struct pnp_dev *device, pm_message_t state)
  701. {
  702. wbcir_shutdown(device);
  703. return 0;
  704. }
  705. static void
  706. wbcir_init_hw(struct wbcir_data *data)
  707. {
  708. u8 tmp;
  709. /* Disable interrupts */
  710. wbcir_set_irqmask(data, WBCIR_IRQ_NONE);
  711. /* Set PROT_SEL, RX_INV, Clear CEIR_EN (needed for the led) */
  712. tmp = protocol << 4;
  713. if (invert)
  714. tmp |= 0x08;
  715. outb(tmp, data->wbase + WBCIR_REG_WCEIR_CTL);
  716. /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
  717. wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17);
  718. /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
  719. wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
  720. /* Set RC5 cell time to correspond to 36 kHz */
  721. wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CFG1, 0x4A, 0x7F);
  722. /* Set IRTX_INV */
  723. if (invert)
  724. outb(0x04, data->ebase + WBCIR_REG_ECEIR_CCTL);
  725. else
  726. outb(0x00, data->ebase + WBCIR_REG_ECEIR_CCTL);
  727. /*
  728. * Clear IR LED, set SP3 clock to 24Mhz, set TX mask to IRTX1,
  729. * set SP3_IRRX_SW to binary 01, helpfully not documented
  730. */
  731. outb(0x10, data->ebase + WBCIR_REG_ECEIR_CTS);
  732. data->txmask = 0x1;
  733. /* Enable extended mode */
  734. wbcir_select_bank(data, WBCIR_BANK_2);
  735. outb(WBCIR_EXT_ENABLE, data->sbase + WBCIR_REG_SP3_EXCR1);
  736. /*
  737. * Configure baud generator, IR data will be sampled at
  738. * a bitrate of: (24Mhz * prescaler) / (divisor * 16).
  739. *
  740. * The ECIR registers include a flag to change the
  741. * 24Mhz clock freq to 48Mhz.
  742. *
  743. * It's not documented in the specs, but fifo levels
  744. * other than 16 seems to be unsupported.
  745. */
  746. /* prescaler 1.0, tx/rx fifo lvl 16 */
  747. outb(0x30, data->sbase + WBCIR_REG_SP3_EXCR2);
  748. /* Set baud divisor to sample every 10 us */
  749. outb(0x0F, data->sbase + WBCIR_REG_SP3_BGDL);
  750. outb(0x00, data->sbase + WBCIR_REG_SP3_BGDH);
  751. /* Set CEIR mode */
  752. wbcir_select_bank(data, WBCIR_BANK_0);
  753. outb(0xC0, data->sbase + WBCIR_REG_SP3_MCR);
  754. inb(data->sbase + WBCIR_REG_SP3_LSR); /* Clear LSR */
  755. inb(data->sbase + WBCIR_REG_SP3_MSR); /* Clear MSR */
  756. /* Disable RX demod, enable run-length enc/dec, set freq span */
  757. wbcir_select_bank(data, WBCIR_BANK_7);
  758. outb(0x90, data->sbase + WBCIR_REG_SP3_RCCFG);
  759. /* Disable timer */
  760. wbcir_select_bank(data, WBCIR_BANK_4);
  761. outb(0x00, data->sbase + WBCIR_REG_SP3_IRCR1);
  762. /* Disable MSR interrupt, clear AUX_IRX, mask RX during TX? */
  763. wbcir_select_bank(data, WBCIR_BANK_5);
  764. outb(txandrx ? 0x03 : 0x02, data->sbase + WBCIR_REG_SP3_IRCR2);
  765. /* Disable CRC */
  766. wbcir_select_bank(data, WBCIR_BANK_6);
  767. outb(0x20, data->sbase + WBCIR_REG_SP3_IRCR3);
  768. /* Set RX demodulation freq, not really used */
  769. wbcir_select_bank(data, WBCIR_BANK_7);
  770. outb(0xF2, data->sbase + WBCIR_REG_SP3_IRRXDC);
  771. /* Set TX modulation, 36kHz, 7us pulse width */
  772. outb(0x69, data->sbase + WBCIR_REG_SP3_IRTXMC);
  773. data->txcarrier = 36000;
  774. /* Set invert and pin direction */
  775. if (invert)
  776. outb(0x10, data->sbase + WBCIR_REG_SP3_IRCFG4);
  777. else
  778. outb(0x00, data->sbase + WBCIR_REG_SP3_IRCFG4);
  779. /* Set FIFO thresholds (RX = 8, TX = 3), reset RX/TX */
  780. wbcir_select_bank(data, WBCIR_BANK_0);
  781. outb(0x97, data->sbase + WBCIR_REG_SP3_FCR);
  782. /* Clear AUX status bits */
  783. outb(0xE0, data->sbase + WBCIR_REG_SP3_ASCR);
  784. /* Clear RX state */
  785. data->rxstate = WBCIR_RXSTATE_INACTIVE;
  786. data->rxev.duration = 0;
  787. ir_raw_event_reset(data->dev);
  788. ir_raw_event_handle(data->dev);
  789. /*
  790. * Check TX state, if we did a suspend/resume cycle while TX was
  791. * active, we will have a process waiting in txwaitq.
  792. */
  793. if (data->txstate == WBCIR_TXSTATE_ACTIVE) {
  794. data->txstate = WBCIR_TXSTATE_ERROR;
  795. wake_up(&data->txwaitq);
  796. }
  797. /* Enable interrupts */
  798. wbcir_set_irqmask(data, WBCIR_IRQ_RX | WBCIR_IRQ_ERR);
  799. }
  800. static int
  801. wbcir_resume(struct pnp_dev *device)
  802. {
  803. struct wbcir_data *data = pnp_get_drvdata(device);
  804. wbcir_init_hw(data);
  805. enable_irq(data->irq);
  806. return 0;
  807. }
  808. static int __devinit
  809. wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id)
  810. {
  811. struct device *dev = &device->dev;
  812. struct wbcir_data *data;
  813. int err;
  814. if (!(pnp_port_len(device, 0) == EHFUNC_IOMEM_LEN &&
  815. pnp_port_len(device, 1) == WAKEUP_IOMEM_LEN &&
  816. pnp_port_len(device, 2) == SP_IOMEM_LEN)) {
  817. dev_err(dev, "Invalid resources\n");
  818. return -ENODEV;
  819. }
  820. data = kzalloc(sizeof(*data), GFP_KERNEL);
  821. if (!data) {
  822. err = -ENOMEM;
  823. goto exit;
  824. }
  825. pnp_set_drvdata(device, data);
  826. spin_lock_init(&data->spinlock);
  827. init_waitqueue_head(&data->txwaitq);
  828. data->ebase = pnp_port_start(device, 0);
  829. data->wbase = pnp_port_start(device, 1);
  830. data->sbase = pnp_port_start(device, 2);
  831. data->irq = pnp_irq(device, 0);
  832. if (data->wbase == 0 || data->ebase == 0 ||
  833. data->sbase == 0 || data->irq == 0) {
  834. err = -ENODEV;
  835. dev_err(dev, "Invalid resources\n");
  836. goto exit_free_data;
  837. }
  838. dev_dbg(&device->dev, "Found device "
  839. "(w: 0x%lX, e: 0x%lX, s: 0x%lX, i: %u)\n",
  840. data->wbase, data->ebase, data->sbase, data->irq);
  841. if (!request_region(data->wbase, WAKEUP_IOMEM_LEN, DRVNAME)) {
  842. dev_err(dev, "Region 0x%lx-0x%lx already in use!\n",
  843. data->wbase, data->wbase + WAKEUP_IOMEM_LEN - 1);
  844. err = -EBUSY;
  845. goto exit_free_data;
  846. }
  847. if (!request_region(data->ebase, EHFUNC_IOMEM_LEN, DRVNAME)) {
  848. dev_err(dev, "Region 0x%lx-0x%lx already in use!\n",
  849. data->ebase, data->ebase + EHFUNC_IOMEM_LEN - 1);
  850. err = -EBUSY;
  851. goto exit_release_wbase;
  852. }
  853. if (!request_region(data->sbase, SP_IOMEM_LEN, DRVNAME)) {
  854. dev_err(dev, "Region 0x%lx-0x%lx already in use!\n",
  855. data->sbase, data->sbase + SP_IOMEM_LEN - 1);
  856. err = -EBUSY;
  857. goto exit_release_ebase;
  858. }
  859. err = request_irq(data->irq, wbcir_irq_handler,
  860. IRQF_DISABLED, DRVNAME, device);
  861. if (err) {
  862. dev_err(dev, "Failed to claim IRQ %u\n", data->irq);
  863. err = -EBUSY;
  864. goto exit_release_sbase;
  865. }
  866. led_trigger_register_simple("cir-tx", &data->txtrigger);
  867. if (!data->txtrigger) {
  868. err = -ENOMEM;
  869. goto exit_free_irq;
  870. }
  871. led_trigger_register_simple("cir-rx", &data->rxtrigger);
  872. if (!data->rxtrigger) {
  873. err = -ENOMEM;
  874. goto exit_unregister_txtrigger;
  875. }
  876. data->led.name = "cir::activity";
  877. data->led.default_trigger = "cir-rx";
  878. data->led.brightness_set = wbcir_led_brightness_set;
  879. data->led.brightness_get = wbcir_led_brightness_get;
  880. err = led_classdev_register(&device->dev, &data->led);
  881. if (err)
  882. goto exit_unregister_rxtrigger;
  883. data->dev = rc_allocate_device();
  884. if (!data->dev) {
  885. err = -ENOMEM;
  886. goto exit_unregister_led;
  887. }
  888. data->dev->driver_name = WBCIR_NAME;
  889. data->dev->input_name = WBCIR_NAME;
  890. data->dev->input_phys = "wbcir/cir0";
  891. data->dev->input_id.bustype = BUS_HOST;
  892. data->dev->input_id.vendor = PCI_VENDOR_ID_WINBOND;
  893. data->dev->input_id.product = WBCIR_ID_FAMILY;
  894. data->dev->input_id.version = WBCIR_ID_CHIP;
  895. data->dev->map_name = RC_MAP_RC6_MCE;
  896. data->dev->s_idle = wbcir_idle_rx;
  897. data->dev->s_tx_mask = wbcir_txmask;
  898. data->dev->s_tx_carrier = wbcir_txcarrier;
  899. data->dev->tx_ir = wbcir_tx;
  900. data->dev->priv = data;
  901. data->dev->dev.parent = &device->dev;
  902. err = rc_register_device(data->dev);
  903. if (err)
  904. goto exit_free_rc;
  905. device_init_wakeup(&device->dev, 1);
  906. wbcir_init_hw(data);
  907. return 0;
  908. exit_free_rc:
  909. rc_free_device(data->dev);
  910. exit_unregister_led:
  911. led_classdev_unregister(&data->led);
  912. exit_unregister_rxtrigger:
  913. led_trigger_unregister_simple(data->rxtrigger);
  914. exit_unregister_txtrigger:
  915. led_trigger_unregister_simple(data->txtrigger);
  916. exit_free_irq:
  917. free_irq(data->irq, device);
  918. exit_release_sbase:
  919. release_region(data->sbase, SP_IOMEM_LEN);
  920. exit_release_ebase:
  921. release_region(data->ebase, EHFUNC_IOMEM_LEN);
  922. exit_release_wbase:
  923. release_region(data->wbase, WAKEUP_IOMEM_LEN);
  924. exit_free_data:
  925. kfree(data);
  926. pnp_set_drvdata(device, NULL);
  927. exit:
  928. return err;
  929. }
  930. static void __devexit
  931. wbcir_remove(struct pnp_dev *device)
  932. {
  933. struct wbcir_data *data = pnp_get_drvdata(device);
  934. /* Disable interrupts */
  935. wbcir_set_irqmask(data, WBCIR_IRQ_NONE);
  936. free_irq(data->irq, device);
  937. /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
  938. wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17);
  939. /* Clear CEIR_EN */
  940. wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
  941. /* Clear BUFF_EN, END_EN, MATCH_EN */
  942. wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
  943. rc_unregister_device(data->dev);
  944. led_trigger_unregister_simple(data->rxtrigger);
  945. led_trigger_unregister_simple(data->txtrigger);
  946. led_classdev_unregister(&data->led);
  947. /* This is ok since &data->led isn't actually used */
  948. wbcir_led_brightness_set(&data->led, LED_OFF);
  949. release_region(data->wbase, WAKEUP_IOMEM_LEN);
  950. release_region(data->ebase, EHFUNC_IOMEM_LEN);
  951. release_region(data->sbase, SP_IOMEM_LEN);
  952. kfree(data);
  953. pnp_set_drvdata(device, NULL);
  954. }
  955. static const struct pnp_device_id wbcir_ids[] = {
  956. { "WEC1022", 0 },
  957. { "", 0 }
  958. };
  959. MODULE_DEVICE_TABLE(pnp, wbcir_ids);
  960. static struct pnp_driver wbcir_driver = {
  961. .name = WBCIR_NAME,
  962. .id_table = wbcir_ids,
  963. .probe = wbcir_probe,
  964. .remove = __devexit_p(wbcir_remove),
  965. .suspend = wbcir_suspend,
  966. .resume = wbcir_resume,
  967. .shutdown = wbcir_shutdown
  968. };
  969. static int __init
  970. wbcir_init(void)
  971. {
  972. int ret;
  973. switch (protocol) {
  974. case IR_PROTOCOL_RC5:
  975. case IR_PROTOCOL_NEC:
  976. case IR_PROTOCOL_RC6:
  977. break;
  978. default:
  979. printk(KERN_ERR DRVNAME ": Invalid power-on protocol\n");
  980. }
  981. ret = pnp_register_driver(&wbcir_driver);
  982. if (ret)
  983. printk(KERN_ERR DRVNAME ": Unable to register driver\n");
  984. return ret;
  985. }
  986. static void __exit
  987. wbcir_exit(void)
  988. {
  989. pnp_unregister_driver(&wbcir_driver);
  990. }
  991. module_init(wbcir_init);
  992. module_exit(wbcir_exit);
  993. MODULE_AUTHOR("David Härdeman <david@hardeman.nu>");
  994. MODULE_DESCRIPTION("Winbond SuperI/O Consumer IR Driver");
  995. MODULE_LICENSE("GPL");