fintek-cir.h 6.3 KB

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