ite-cir.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. /*
  2. * Driver for ITE Tech Inc. IT8712F/IT8512F CIR
  3. *
  4. * Copyright (C) 2010 Juan Jesús García de Soria <skandalfo@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. */
  16. /* platform driver name to register */
  17. #define ITE_DRIVER_NAME "ite-cir"
  18. /* logging macros */
  19. #define ite_pr(level, text, ...) \
  20. printk(level KBUILD_MODNAME ": " text, ## __VA_ARGS__)
  21. #define ite_dbg(text, ...) do { \
  22. if (debug) \
  23. printk(KERN_DEBUG \
  24. KBUILD_MODNAME ": " text "\n" , ## __VA_ARGS__); \
  25. } while (0)
  26. #define ite_dbg_verbose(text, ...) do {\
  27. if (debug > 1) \
  28. printk(KERN_DEBUG \
  29. KBUILD_MODNAME ": " text "\n" , ## __VA_ARGS__); \
  30. } while (0)
  31. /* FIFO sizes */
  32. #define ITE_TX_FIFO_LEN 32
  33. #define ITE_RX_FIFO_LEN 32
  34. /* interrupt types */
  35. #define ITE_IRQ_TX_FIFO 1
  36. #define ITE_IRQ_RX_FIFO 2
  37. #define ITE_IRQ_RX_FIFO_OVERRUN 4
  38. /* forward declaration */
  39. struct ite_dev;
  40. /* struct for storing the parameters of different recognized devices */
  41. struct ite_dev_params {
  42. /* model of the device */
  43. const char *model;
  44. /* size of the I/O region */
  45. int io_region_size;
  46. /* IR pnp I/O resource number */
  47. int io_rsrc_no;
  48. /* true if the hardware supports transmission */
  49. bool hw_tx_capable;
  50. /* base sampling period, in ns */
  51. u32 sample_period;
  52. /* rx low carrier frequency, in Hz, 0 means no demodulation */
  53. unsigned int rx_low_carrier_freq;
  54. /* tx high carrier frequency, in Hz, 0 means no demodulation */
  55. unsigned int rx_high_carrier_freq;
  56. /* tx carrier frequency, in Hz */
  57. unsigned int tx_carrier_freq;
  58. /* duty cycle, 0-100 */
  59. int tx_duty_cycle;
  60. /* hw-specific operation function pointers; most of these must be
  61. * called while holding the spin lock, except for the TX FIFO length
  62. * one */
  63. /* get pending interrupt causes */
  64. int (*get_irq_causes) (struct ite_dev *dev);
  65. /* enable rx */
  66. void (*enable_rx) (struct ite_dev *dev);
  67. /* make rx enter the idle state; keep listening for a pulse, but stop
  68. * streaming space bytes */
  69. void (*idle_rx) (struct ite_dev *dev);
  70. /* disable rx completely */
  71. void (*disable_rx) (struct ite_dev *dev);
  72. /* read bytes from RX FIFO; return read count */
  73. int (*get_rx_bytes) (struct ite_dev *dev, u8 *buf, int buf_size);
  74. /* enable tx FIFO space available interrupt */
  75. void (*enable_tx_interrupt) (struct ite_dev *dev);
  76. /* disable tx FIFO space available interrupt */
  77. void (*disable_tx_interrupt) (struct ite_dev *dev);
  78. /* get number of full TX FIFO slots */
  79. int (*get_tx_used_slots) (struct ite_dev *dev);
  80. /* put a byte to the TX FIFO */
  81. void (*put_tx_byte) (struct ite_dev *dev, u8 value);
  82. /* disable hardware completely */
  83. void (*disable) (struct ite_dev *dev);
  84. /* initialize the hardware */
  85. void (*init_hardware) (struct ite_dev *dev);
  86. /* set the carrier parameters */
  87. void (*set_carrier_params) (struct ite_dev *dev, bool high_freq,
  88. bool use_demodulator, u8 carrier_freq_bits,
  89. u8 allowance_bits, u8 pulse_width_bits);
  90. };
  91. /* ITE CIR device structure */
  92. struct ite_dev {
  93. struct pnp_dev *pdev;
  94. struct rc_dev *rdev;
  95. struct ir_raw_event rawir;
  96. /* sync data */
  97. spinlock_t lock;
  98. bool in_use, transmitting;
  99. /* transmit support */
  100. int tx_fifo_allowance;
  101. wait_queue_head_t tx_queue, tx_ended;
  102. /* hardware I/O settings */
  103. unsigned long cir_addr;
  104. int cir_irq;
  105. /* overridable copy of model parameters */
  106. struct ite_dev_params params;
  107. };
  108. /* common values for all kinds of hardware */
  109. /* baud rate divisor default */
  110. #define ITE_BAUDRATE_DIVISOR 1
  111. /* low-speed carrier frequency limits (Hz) */
  112. #define ITE_LCF_MIN_CARRIER_FREQ 27000
  113. #define ITE_LCF_MAX_CARRIER_FREQ 58000
  114. /* high-speed carrier frequency limits (Hz) */
  115. #define ITE_HCF_MIN_CARRIER_FREQ 400000
  116. #define ITE_HCF_MAX_CARRIER_FREQ 500000
  117. /* default carrier freq for when demodulator is off (Hz) */
  118. #define ITE_DEFAULT_CARRIER_FREQ 38000
  119. /* convert bits to us */
  120. #define ITE_BITS_TO_NS(bits, sample_period) \
  121. ((u32) ((bits) * ITE_BAUDRATE_DIVISOR * sample_period))
  122. /*
  123. * n in RDCR produces a tolerance of +/- n * 6.25% around the center
  124. * carrier frequency...
  125. *
  126. * From two limit frequencies, L (low) and H (high), we can get both the
  127. * center frequency F = (L + H) / 2 and the variation from the center
  128. * frequency A = (H - L) / (H + L). We can use this in order to honor the
  129. * s_rx_carrier_range() call in ir-core. We'll suppose that any request
  130. * setting L=0 means we must shut down the demodulator.
  131. */
  132. #define ITE_RXDCR_PER_10000_STEP 625
  133. /* high speed carrier freq values */
  134. #define ITE_CFQ_400 0x03
  135. #define ITE_CFQ_450 0x08
  136. #define ITE_CFQ_480 0x0b
  137. #define ITE_CFQ_500 0x0d
  138. /* values for pulse widths */
  139. #define ITE_TXMPW_A 0x02
  140. #define ITE_TXMPW_B 0x03
  141. #define ITE_TXMPW_C 0x04
  142. #define ITE_TXMPW_D 0x05
  143. #define ITE_TXMPW_E 0x06
  144. /* values for demodulator carrier range allowance */
  145. #define ITE_RXDCR_DEFAULT 0x01 /* default carrier range */
  146. #define ITE_RXDCR_MAX 0x07 /* default carrier range */
  147. /* DR TX bits */
  148. #define ITE_TX_PULSE 0x00
  149. #define ITE_TX_SPACE 0x80
  150. #define ITE_TX_MAX_RLE 0x80
  151. #define ITE_TX_RLE_MASK 0x7f
  152. /*
  153. * IT8712F
  154. *
  155. * hardware data obtained from:
  156. *
  157. * IT8712F
  158. * Environment Control – Low Pin Count Input / Output
  159. * (EC - LPC I/O)
  160. * Preliminary Specification V0. 81
  161. */
  162. /* register offsets */
  163. #define IT87_DR 0x00 /* data register */
  164. #define IT87_IER 0x01 /* interrupt enable register */
  165. #define IT87_RCR 0x02 /* receiver control register */
  166. #define IT87_TCR1 0x03 /* transmitter control register 1 */
  167. #define IT87_TCR2 0x04 /* transmitter control register 2 */
  168. #define IT87_TSR 0x05 /* transmitter status register */
  169. #define IT87_RSR 0x06 /* receiver status register */
  170. #define IT87_BDLR 0x05 /* baud rate divisor low byte register */
  171. #define IT87_BDHR 0x06 /* baud rate divisor high byte register */
  172. #define IT87_IIR 0x07 /* interrupt identification register */
  173. #define IT87_IOREG_LENGTH 0x08 /* length of register file */
  174. /* IER bits */
  175. #define IT87_TLDLIE 0x01 /* transmitter low data interrupt enable */
  176. #define IT87_RDAIE 0x02 /* receiver data available interrupt enable */
  177. #define IT87_RFOIE 0x04 /* receiver FIFO overrun interrupt enable */
  178. #define IT87_IEC 0x08 /* interrupt enable control */
  179. #define IT87_BR 0x10 /* baud rate register enable */
  180. #define IT87_RESET 0x20 /* reset */
  181. /* RCR bits */
  182. #define IT87_RXDCR 0x07 /* receiver demodulation carrier range mask */
  183. #define IT87_RXACT 0x08 /* receiver active */
  184. #define IT87_RXEND 0x10 /* receiver demodulation enable */
  185. #define IT87_RXEN 0x20 /* receiver enable */
  186. #define IT87_HCFS 0x40 /* high-speed carrier frequency select */
  187. #define IT87_RDWOS 0x80 /* receiver data without sync */
  188. /* TCR1 bits */
  189. #define IT87_TXMPM 0x03 /* transmitter modulation pulse mode mask */
  190. #define IT87_TXMPM_DEFAULT 0x00 /* modulation pulse mode default */
  191. #define IT87_TXENDF 0x04 /* transmitter deferral */
  192. #define IT87_TXRLE 0x08 /* transmitter run length enable */
  193. #define IT87_FIFOTL 0x30 /* FIFO level threshold mask */
  194. #define IT87_FIFOTL_DEFAULT 0x20 /* FIFO level threshold default
  195. * 0x00 -> 1, 0x10 -> 7, 0x20 -> 17,
  196. * 0x30 -> 25 */
  197. #define IT87_ILE 0x40 /* internal loopback enable */
  198. #define IT87_FIFOCLR 0x80 /* FIFO clear bit */
  199. /* TCR2 bits */
  200. #define IT87_TXMPW 0x07 /* transmitter modulation pulse width mask */
  201. #define IT87_TXMPW_DEFAULT 0x04 /* default modulation pulse width */
  202. #define IT87_CFQ 0xf8 /* carrier frequency mask */
  203. #define IT87_CFQ_SHIFT 3 /* carrier frequency bit shift */
  204. /* TSR bits */
  205. #define IT87_TXFBC 0x3f /* transmitter FIFO byte count mask */
  206. /* RSR bits */
  207. #define IT87_RXFBC 0x3f /* receiver FIFO byte count mask */
  208. #define IT87_RXFTO 0x80 /* receiver FIFO time-out */
  209. /* IIR bits */
  210. #define IT87_IP 0x01 /* interrupt pending */
  211. #define IT87_II 0x06 /* interrupt identification mask */
  212. #define IT87_II_NOINT 0x00 /* no interrupt */
  213. #define IT87_II_TXLDL 0x02 /* transmitter low data level */
  214. #define IT87_II_RXDS 0x04 /* receiver data stored */
  215. #define IT87_II_RXFO 0x06 /* receiver FIFO overrun */
  216. /*
  217. * IT8512E/F
  218. *
  219. * Hardware data obtained from:
  220. *
  221. * IT8512E/F
  222. * Embedded Controller
  223. * Preliminary Specification V0.4.1
  224. *
  225. * Note that the CIR registers are not directly available to the host, because
  226. * they only are accessible to the integrated microcontroller. Thus, in order
  227. * use it, some kind of bridging is required. As the bridging may depend on
  228. * the controller firmware in use, we are going to use the PNP ID in order to
  229. * determine the strategy and ports available. See after these generic
  230. * IT8512E/F register definitions for register definitions for those
  231. * strategies.
  232. */
  233. /* register offsets */
  234. #define IT85_C0DR 0x00 /* data register */
  235. #define IT85_C0MSTCR 0x01 /* master control register */
  236. #define IT85_C0IER 0x02 /* interrupt enable register */
  237. #define IT85_C0IIR 0x03 /* interrupt identification register */
  238. #define IT85_C0CFR 0x04 /* carrier frequency register */
  239. #define IT85_C0RCR 0x05 /* receiver control register */
  240. #define IT85_C0TCR 0x06 /* transmitter control register */
  241. #define IT85_C0SCK 0x07 /* slow clock control register */
  242. #define IT85_C0BDLR 0x08 /* baud rate divisor low byte register */
  243. #define IT85_C0BDHR 0x09 /* baud rate divisor high byte register */
  244. #define IT85_C0TFSR 0x0a /* transmitter FIFO status register */
  245. #define IT85_C0RFSR 0x0b /* receiver FIFO status register */
  246. #define IT85_C0WCL 0x0d /* wakeup code length register */
  247. #define IT85_C0WCR 0x0e /* wakeup code read/write register */
  248. #define IT85_C0WPS 0x0f /* wakeup power control/status register */
  249. #define IT85_IOREG_LENGTH 0x10 /* length of register file */
  250. /* C0MSTCR bits */
  251. #define IT85_RESET 0x01 /* reset */
  252. #define IT85_FIFOCLR 0x02 /* FIFO clear bit */
  253. #define IT85_FIFOTL 0x0c /* FIFO level threshold mask */
  254. #define IT85_FIFOTL_DEFAULT 0x08 /* FIFO level threshold default
  255. * 0x00 -> 1, 0x04 -> 7, 0x08 -> 17,
  256. * 0x0c -> 25 */
  257. #define IT85_ILE 0x10 /* internal loopback enable */
  258. #define IT85_ILSEL 0x20 /* internal loopback select */
  259. /* C0IER bits */
  260. #define IT85_TLDLIE 0x01 /* TX low data level interrupt enable */
  261. #define IT85_RDAIE 0x02 /* RX data available interrupt enable */
  262. #define IT85_RFOIE 0x04 /* RX FIFO overrun interrupt enable */
  263. #define IT85_IEC 0x80 /* interrupt enable function control */
  264. /* C0IIR bits */
  265. #define IT85_TLDLI 0x01 /* transmitter low data level interrupt */
  266. #define IT85_RDAI 0x02 /* receiver data available interrupt */
  267. #define IT85_RFOI 0x04 /* receiver FIFO overrun interrupt */
  268. #define IT85_NIP 0x80 /* no interrupt pending */
  269. /* C0CFR bits */
  270. #define IT85_CFQ 0x1f /* carrier frequency mask */
  271. #define IT85_HCFS 0x20 /* high speed carrier frequency select */
  272. /* C0RCR bits */
  273. #define IT85_RXDCR 0x07 /* receiver demodulation carrier range mask */
  274. #define IT85_RXACT 0x08 /* receiver active */
  275. #define IT85_RXEND 0x10 /* receiver demodulation enable */
  276. #define IT85_RDWOS 0x20 /* receiver data without sync */
  277. #define IT85_RXEN 0x80 /* receiver enable */
  278. /* C0TCR bits */
  279. #define IT85_TXMPW 0x07 /* transmitter modulation pulse width mask */
  280. #define IT85_TXMPW_DEFAULT 0x04 /* default modulation pulse width */
  281. #define IT85_TXMPM 0x18 /* transmitter modulation pulse mode mask */
  282. #define IT85_TXMPM_DEFAULT 0x00 /* modulation pulse mode default */
  283. #define IT85_TXENDF 0x20 /* transmitter deferral */
  284. #define IT85_TXRLE 0x40 /* transmitter run length enable */
  285. /* C0SCK bits */
  286. #define IT85_SCKS 0x01 /* slow clock select */
  287. #define IT85_TXDCKG 0x02 /* TXD clock gating */
  288. #define IT85_DLL1P8E 0x04 /* DLL 1.8432M enable */
  289. #define IT85_DLLTE 0x08 /* DLL test enable */
  290. #define IT85_BRCM 0x70 /* baud rate count mode */
  291. #define IT85_DLLOCK 0x80 /* DLL lock */
  292. /* C0TFSR bits */
  293. #define IT85_TXFBC 0x3f /* transmitter FIFO count mask */
  294. /* C0RFSR bits */
  295. #define IT85_RXFBC 0x3f /* receiver FIFO count mask */
  296. #define IT85_RXFTO 0x80 /* receiver FIFO time-out */
  297. /* C0WCL bits */
  298. #define IT85_WCL 0x3f /* wakeup code length mask */
  299. /* C0WPS bits */
  300. #define IT85_CIRPOSIE 0x01 /* power on/off status interrupt enable */
  301. #define IT85_CIRPOIS 0x02 /* power on/off interrupt status */
  302. #define IT85_CIRPOII 0x04 /* power on/off interrupt identification */
  303. #define IT85_RCRST 0x10 /* wakeup code reading counter reset bit */
  304. #define IT85_WCRST 0x20 /* wakeup code writing counter reset bit */
  305. /*
  306. * ITE8708
  307. *
  308. * Hardware data obtained from hacked driver for IT8512 in this forum post:
  309. *
  310. * http://ubuntuforums.org/showthread.php?t=1028640
  311. *
  312. * Although there's no official documentation for that driver, analysis would
  313. * suggest that it maps the 16 registers of IT8512 onto two 8-register banks,
  314. * selectable by a single bank-select bit that's mapped onto both banks. The
  315. * IT8512 registers are mapped in a different order, so that the first bank
  316. * maps the ones that are used more often, and two registers that share a
  317. * reserved high-order bit are placed at the same offset in both banks in
  318. * order to reuse the reserved bit as the bank select bit.
  319. */
  320. /* register offsets */
  321. /* mapped onto both banks */
  322. #define IT8708_BANKSEL 0x07 /* bank select register */
  323. #define IT8708_HRAE 0x80 /* high registers access enable */
  324. /* mapped onto the low bank */
  325. #define IT8708_C0DR 0x00 /* data register */
  326. #define IT8708_C0MSTCR 0x01 /* master control register */
  327. #define IT8708_C0IER 0x02 /* interrupt enable register */
  328. #define IT8708_C0IIR 0x03 /* interrupt identification register */
  329. #define IT8708_C0RFSR 0x04 /* receiver FIFO status register */
  330. #define IT8708_C0RCR 0x05 /* receiver control register */
  331. #define IT8708_C0TFSR 0x06 /* transmitter FIFO status register */
  332. #define IT8708_C0TCR 0x07 /* transmitter control register */
  333. /* mapped onto the high bank */
  334. #define IT8708_C0BDLR 0x01 /* baud rate divisor low byte register */
  335. #define IT8708_C0BDHR 0x02 /* baud rate divisor high byte register */
  336. #define IT8708_C0CFR 0x04 /* carrier frequency register */
  337. /* registers whose bank mapping we don't know, since they weren't being used
  338. * in the hacked driver... most probably they belong to the high bank too,
  339. * since they fit in the holes the other registers leave */
  340. #define IT8708_C0SCK 0x03 /* slow clock control register */
  341. #define IT8708_C0WCL 0x05 /* wakeup code length register */
  342. #define IT8708_C0WCR 0x06 /* wakeup code read/write register */
  343. #define IT8708_C0WPS 0x07 /* wakeup power control/status register */
  344. #define IT8708_IOREG_LENGTH 0x08 /* length of register file */
  345. /* two more registers that are defined in the hacked driver, but can't be
  346. * found in the data sheets; no idea what they are or how they are accessed,
  347. * since the hacked driver doesn't seem to use them */
  348. #define IT8708_CSCRR 0x00
  349. #define IT8708_CGPINTR 0x01
  350. /* CSCRR bits */
  351. #define IT8708_CSCRR_SCRB 0x3f
  352. #define IT8708_CSCRR_PM 0x80
  353. /* CGPINTR bits */
  354. #define IT8708_CGPINT 0x01
  355. /*
  356. * ITE8709
  357. *
  358. * Hardware interfacing data obtained from the original lirc_ite8709 driver.
  359. * Verbatim from its sources:
  360. *
  361. * The ITE8709 device seems to be the combination of IT8512 superIO chip and
  362. * a specific firmware running on the IT8512's embedded micro-controller.
  363. * In addition of the embedded micro-controller, the IT8512 chip contains a
  364. * CIR module and several other modules. A few modules are directly accessible
  365. * by the host CPU, but most of them are only accessible by the
  366. * micro-controller. The CIR module is only accessible by the
  367. * micro-controller.
  368. *
  369. * The battery-backed SRAM module is accessible by the host CPU and the
  370. * micro-controller. So one of the MC's firmware role is to act as a bridge
  371. * between the host CPU and the CIR module. The firmware implements a kind of
  372. * communication protocol using the SRAM module as a shared memory. The IT8512
  373. * specification is publicly available on ITE's web site, but the
  374. * communication protocol is not, so it was reverse-engineered.
  375. */
  376. /* register offsets */
  377. #define IT8709_RAM_IDX 0x00 /* index into the SRAM module bytes */
  378. #define IT8709_RAM_VAL 0x01 /* read/write data to the indexed byte */
  379. #define IT8709_IOREG_LENGTH 0x02 /* length of register file */
  380. /* register offsets inside the SRAM module */
  381. #define IT8709_MODE 0x1a /* request/ack byte */
  382. #define IT8709_REG_IDX 0x1b /* index of the CIR register to access */
  383. #define IT8709_REG_VAL 0x1c /* value read/to be written */
  384. #define IT8709_IIR 0x1e /* interrupt identification register */
  385. #define IT8709_RFSR 0x1f /* receiver FIFO status register */
  386. #define IT8709_FIFO 0x20 /* start of in RAM RX FIFO copy */
  387. /* MODE values */
  388. #define IT8709_IDLE 0x00
  389. #define IT8709_WRITE 0x01
  390. #define IT8709_READ 0x02