fintek-cir.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * Driver for Feature Integration Technology Inc. (aka Fintek) LPC CIR
  3. *
  4. * Copyright (C) 2011 Jarod Wilson <jarod@redhat.com>
  5. *
  6. * Special thanks to Fintek for providing hardware and spec sheets.
  7. * This driver is based upon the nuvoton, ite and ene drivers for
  8. * similar hardware.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  23. * USA
  24. */
  25. #include <linux/spinlock.h>
  26. #include <linux/ioctl.h>
  27. /* platform driver name to register */
  28. #define FINTEK_DRIVER_NAME "fintek-cir"
  29. #define FINTEK_DESCRIPTION "Fintek LPC SuperIO Consumer IR Transceiver"
  30. #define VENDOR_ID_FINTEK 0x1934
  31. /* debugging module parameter */
  32. static int debug;
  33. #define fit_pr(level, text, ...) \
  34. printk(level KBUILD_MODNAME ": " text, ## __VA_ARGS__)
  35. #define fit_dbg(text, ...) \
  36. if (debug) \
  37. printk(KERN_DEBUG \
  38. KBUILD_MODNAME ": " text "\n" , ## __VA_ARGS__)
  39. #define fit_dbg_verbose(text, ...) \
  40. if (debug > 1) \
  41. printk(KERN_DEBUG \
  42. KBUILD_MODNAME ": " text "\n" , ## __VA_ARGS__)
  43. #define fit_dbg_wake(text, ...) \
  44. if (debug > 2) \
  45. printk(KERN_DEBUG \
  46. KBUILD_MODNAME ": " text "\n" , ## __VA_ARGS__)
  47. #define TX_BUF_LEN 256
  48. #define RX_BUF_LEN 32
  49. struct fintek_dev {
  50. struct pnp_dev *pdev;
  51. struct rc_dev *rdev;
  52. spinlock_t fintek_lock;
  53. /* for rx */
  54. u8 buf[RX_BUF_LEN];
  55. unsigned int pkts;
  56. struct {
  57. spinlock_t lock;
  58. u8 buf[TX_BUF_LEN];
  59. unsigned int buf_count;
  60. unsigned int cur_buf_num;
  61. wait_queue_head_t queue;
  62. } tx;
  63. /* Config register index/data port pair */
  64. u8 cr_ip;
  65. u8 cr_dp;
  66. /* hardware I/O settings */
  67. unsigned long cir_addr;
  68. int cir_irq;
  69. int cir_port_len;
  70. /* hardware id */
  71. u8 chip_major;
  72. u8 chip_minor;
  73. u16 chip_vendor;
  74. /* hardware features */
  75. bool hw_learning_capable;
  76. bool hw_tx_capable;
  77. /* rx settings */
  78. bool learning_enabled;
  79. bool carrier_detect_enabled;
  80. enum {
  81. CMD_HEADER = 0,
  82. SUBCMD,
  83. CMD_DATA,
  84. PARSE_IRDATA,
  85. } parser_state;
  86. u8 cmd, rem;
  87. /* carrier period = 1 / frequency */
  88. u32 carrier;
  89. };
  90. /* buffer packet constants, largely identical to mceusb.c */
  91. #define BUF_PULSE_BIT 0x80
  92. #define BUF_LEN_MASK 0x1f
  93. #define BUF_SAMPLE_MASK 0x7f
  94. #define BUF_COMMAND_HEADER 0x9f
  95. #define BUF_COMMAND_MASK 0xe0
  96. #define BUF_COMMAND_NULL 0x00
  97. #define BUF_HW_CMD_HEADER 0xff
  98. #define BUF_CMD_G_REVISION 0x0b
  99. #define BUF_CMD_S_CARRIER 0x06
  100. #define BUF_CMD_S_TIMEOUT 0x0c
  101. #define BUF_CMD_SIG_END 0x01
  102. #define BUF_CMD_S_TXMASK 0x08
  103. #define BUF_CMD_S_RXSENSOR 0x14
  104. #define BUF_RSP_PULSE_COUNT 0x15
  105. #define CIR_SAMPLE_PERIOD 50
  106. /*
  107. * Configuration Register:
  108. * Index Port
  109. * Data Port
  110. */
  111. #define CR_INDEX_PORT 0x2e
  112. #define CR_DATA_PORT 0x2f
  113. /* Possible alternate values, depends on how the chip is wired */
  114. #define CR_INDEX_PORT2 0x4e
  115. #define CR_DATA_PORT2 0x4f
  116. /*
  117. * GCR_CONFIG_PORT_SEL bit 4 specifies which Index Port value is
  118. * active. 1 = 0x4e, 0 = 0x2e
  119. */
  120. #define PORT_SEL_PORT_4E_EN 0x10
  121. /* Extended Function Mode enable/disable magic values */
  122. #define CONFIG_REG_ENABLE 0x87
  123. #define CONFIG_REG_DISABLE 0xaa
  124. /* Chip IDs found in CR_CHIP_ID_{HI,LO} */
  125. #define CHIP_ID_HIGH_F71809U 0x04
  126. #define CHIP_ID_LOW_F71809U 0x08
  127. /*
  128. * Global control regs we need to care about:
  129. * Global Control def.
  130. * Register name addr val. */
  131. #define GCR_SOFTWARE_RESET 0x02 /* 0x00 */
  132. #define GCR_LOGICAL_DEV_NO 0x07 /* 0x00 */
  133. #define GCR_CHIP_ID_HI 0x20 /* 0x04 */
  134. #define GCR_CHIP_ID_LO 0x21 /* 0x08 */
  135. #define GCR_VENDOR_ID_HI 0x23 /* 0x19 */
  136. #define GCR_VENDOR_ID_LO 0x24 /* 0x34 */
  137. #define GCR_CONFIG_PORT_SEL 0x25 /* 0x01 */
  138. #define GCR_KBMOUSE_WAKEUP 0x27
  139. #define LOGICAL_DEV_DISABLE 0x00
  140. #define LOGICAL_DEV_ENABLE 0x01
  141. /* Logical device number of the CIR function */
  142. #define LOGICAL_DEV_CIR 0x05
  143. /* CIR Logical Device (LDN 0x08) config registers */
  144. #define CIR_CR_COMMAND_INDEX 0x04
  145. #define CIR_CR_IRCS 0x05 /* Before host writes command to IR, host
  146. must set to 1. When host finshes write
  147. command to IR, host must clear to 0. */
  148. #define CIR_CR_COMMAND_DATA 0x06 /* Host read or write comand data */
  149. #define CIR_CR_CLASS 0x07 /* 0xff = rx-only, 0x66 = rx + 2 tx,
  150. 0x33 = rx + 1 tx */
  151. #define CIR_CR_DEV_EN 0x30 /* bit0 = 1 enables CIR */
  152. #define CIR_CR_BASE_ADDR_HI 0x60 /* MSB of CIR IO base addr */
  153. #define CIR_CR_BASE_ADDR_LO 0x61 /* LSB of CIR IO base addr */
  154. #define CIR_CR_IRQ_SEL 0x70 /* bits3-0 store CIR IRQ */
  155. #define CIR_CR_PSOUT_STATUS 0xf1
  156. #define CIR_CR_WAKE_KEY3_ADDR 0xf8
  157. #define CIR_CR_WAKE_KEY3_CODE 0xf9
  158. #define CIR_CR_WAKE_KEY3_DC 0xfa
  159. #define CIR_CR_WAKE_CONTROL 0xfb
  160. #define CIR_CR_WAKE_KEY12_ADDR 0xfc
  161. #define CIR_CR_WAKE_KEY4_ADDR 0xfd
  162. #define CIR_CR_WAKE_KEY5_ADDR 0xfe
  163. #define CLASS_RX_ONLY 0xff
  164. #define CLASS_RX_2TX 0x66
  165. #define CLASS_RX_1TX 0x33
  166. /* CIR device registers */
  167. #define CIR_STATUS 0x00
  168. #define CIR_RX_DATA 0x01
  169. #define CIR_TX_CONTROL 0x02
  170. #define CIR_TX_DATA 0x03
  171. #define CIR_CONTROL 0x04
  172. /* Bits to enable CIR wake */
  173. #define LOGICAL_DEV_ACPI 0x01
  174. #define LDEV_ACPI_WAKE_EN_REG 0xe8
  175. #define ACPI_WAKE_EN_CIR_BIT 0x04
  176. #define LDEV_ACPI_PME_EN_REG 0xf0
  177. #define LDEV_ACPI_PME_CLR_REG 0xf1
  178. #define ACPI_PME_CIR_BIT 0x02
  179. #define LDEV_ACPI_STATE_REG 0xf4
  180. #define ACPI_STATE_CIR_BIT 0x20
  181. /*
  182. * CIR status register (0x00):
  183. * 7 - CIR_IRQ_EN (1 = enable CIR IRQ, 0 = disable)
  184. * 3 - TX_FINISH (1 when TX finished, write 1 to clear)
  185. * 2 - TX_UNDERRUN (1 on TX underrun, write 1 to clear)
  186. * 1 - RX_TIMEOUT (1 on RX timeout, write 1 to clear)
  187. * 0 - RX_RECEIVE (1 on RX receive, write 1 to clear)
  188. */
  189. #define CIR_STATUS_IRQ_EN 0x80
  190. #define CIR_STATUS_TX_FINISH 0x08
  191. #define CIR_STATUS_TX_UNDERRUN 0x04
  192. #define CIR_STATUS_RX_TIMEOUT 0x02
  193. #define CIR_STATUS_RX_RECEIVE 0x01
  194. #define CIR_STATUS_IRQ_MASK 0x0f
  195. /*
  196. * CIR TX control register (0x02):
  197. * 7 - TX_START (1 to indicate TX start, auto-cleared when done)
  198. * 6 - TX_END (1 to indicate TX data written to TX fifo)
  199. */
  200. #define CIR_TX_CONTROL_TX_START 0x80
  201. #define CIR_TX_CONTROL_TX_END 0x40