0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/spinlock.h>
0013 #include <linux/ioctl.h>
0014
0015
0016 #define FINTEK_DRIVER_NAME "fintek-cir"
0017 #define FINTEK_DESCRIPTION "Fintek LPC SuperIO Consumer IR Transceiver"
0018 #define VENDOR_ID_FINTEK 0x1934
0019
0020
0021
0022 static int debug;
0023
0024 #define fit_pr(level, text, ...) \
0025 printk(level KBUILD_MODNAME ": " text, ## __VA_ARGS__)
0026
0027 #define fit_dbg(text, ...) \
0028 if (debug) \
0029 printk(KERN_DEBUG \
0030 KBUILD_MODNAME ": " text "\n" , ## __VA_ARGS__)
0031
0032 #define fit_dbg_verbose(text, ...) \
0033 if (debug > 1) \
0034 printk(KERN_DEBUG \
0035 KBUILD_MODNAME ": " text "\n" , ## __VA_ARGS__)
0036
0037 #define fit_dbg_wake(text, ...) \
0038 if (debug > 2) \
0039 printk(KERN_DEBUG \
0040 KBUILD_MODNAME ": " text "\n" , ## __VA_ARGS__)
0041
0042
0043 #define TX_BUF_LEN 256
0044 #define RX_BUF_LEN 32
0045
0046 struct fintek_dev {
0047 struct pnp_dev *pdev;
0048 struct rc_dev *rdev;
0049
0050 spinlock_t fintek_lock;
0051
0052
0053 u8 buf[RX_BUF_LEN];
0054 unsigned int pkts;
0055
0056 struct {
0057 spinlock_t lock;
0058 u8 buf[TX_BUF_LEN];
0059 unsigned int buf_count;
0060 unsigned int cur_buf_num;
0061 wait_queue_head_t queue;
0062 } tx;
0063
0064
0065 u32 cr_ip;
0066 u32 cr_dp;
0067
0068
0069 unsigned long cir_addr;
0070 int cir_irq;
0071 int cir_port_len;
0072
0073
0074 u8 chip_major;
0075 u8 chip_minor;
0076 u16 chip_vendor;
0077 u8 logical_dev_cir;
0078
0079
0080 bool hw_learning_capable;
0081 bool hw_tx_capable;
0082
0083
0084 bool learning_enabled;
0085 bool carrier_detect_enabled;
0086
0087 enum {
0088 CMD_HEADER = 0,
0089 SUBCMD,
0090 CMD_DATA,
0091 PARSE_IRDATA,
0092 } parser_state;
0093
0094 u8 cmd, rem;
0095
0096
0097 u32 carrier;
0098 };
0099
0100
0101 #define BUF_PULSE_BIT 0x80
0102 #define BUF_LEN_MASK 0x1f
0103 #define BUF_SAMPLE_MASK 0x7f
0104
0105 #define BUF_COMMAND_HEADER 0x9f
0106 #define BUF_COMMAND_MASK 0xe0
0107 #define BUF_COMMAND_NULL 0x00
0108 #define BUF_HW_CMD_HEADER 0xff
0109 #define BUF_CMD_G_REVISION 0x0b
0110 #define BUF_CMD_S_CARRIER 0x06
0111 #define BUF_CMD_S_TIMEOUT 0x0c
0112 #define BUF_CMD_SIG_END 0x01
0113 #define BUF_CMD_S_TXMASK 0x08
0114 #define BUF_CMD_S_RXSENSOR 0x14
0115 #define BUF_RSP_PULSE_COUNT 0x15
0116
0117 #define CIR_SAMPLE_PERIOD 50
0118
0119
0120
0121
0122
0123
0124 #define CR_INDEX_PORT 0x2e
0125 #define CR_DATA_PORT 0x2f
0126
0127
0128 #define CR_INDEX_PORT2 0x4e
0129 #define CR_DATA_PORT2 0x4f
0130
0131
0132
0133
0134
0135 #define PORT_SEL_PORT_4E_EN 0x10
0136
0137
0138 #define CONFIG_REG_ENABLE 0x87
0139 #define CONFIG_REG_DISABLE 0xaa
0140
0141
0142 #define CHIP_ID_HIGH_F71809U 0x04
0143 #define CHIP_ID_LOW_F71809U 0x08
0144
0145
0146
0147
0148
0149 #define GCR_SOFTWARE_RESET 0x02
0150 #define GCR_LOGICAL_DEV_NO 0x07
0151 #define GCR_CHIP_ID_HI 0x20
0152 #define GCR_CHIP_ID_LO 0x21
0153 #define GCR_VENDOR_ID_HI 0x23
0154 #define GCR_VENDOR_ID_LO 0x24
0155 #define GCR_CONFIG_PORT_SEL 0x25
0156 #define GCR_KBMOUSE_WAKEUP 0x27
0157
0158 #define LOGICAL_DEV_DISABLE 0x00
0159 #define LOGICAL_DEV_ENABLE 0x01
0160
0161
0162 #define LOGICAL_DEV_CIR_REV1 0x05
0163 #define LOGICAL_DEV_CIR_REV2 0x08
0164
0165
0166 #define CIR_CR_COMMAND_INDEX 0x04
0167 #define CIR_CR_IRCS 0x05
0168
0169
0170 #define CIR_CR_COMMAND_DATA 0x06
0171 #define CIR_CR_CLASS 0x07
0172
0173 #define CIR_CR_DEV_EN 0x30
0174 #define CIR_CR_BASE_ADDR_HI 0x60
0175 #define CIR_CR_BASE_ADDR_LO 0x61
0176 #define CIR_CR_IRQ_SEL 0x70
0177 #define CIR_CR_PSOUT_STATUS 0xf1
0178 #define CIR_CR_WAKE_KEY3_ADDR 0xf8
0179 #define CIR_CR_WAKE_KEY3_CODE 0xf9
0180 #define CIR_CR_WAKE_KEY3_DC 0xfa
0181 #define CIR_CR_WAKE_CONTROL 0xfb
0182 #define CIR_CR_WAKE_KEY12_ADDR 0xfc
0183 #define CIR_CR_WAKE_KEY4_ADDR 0xfd
0184 #define CIR_CR_WAKE_KEY5_ADDR 0xfe
0185
0186 #define CLASS_RX_ONLY 0xff
0187 #define CLASS_RX_2TX 0x66
0188 #define CLASS_RX_1TX 0x33
0189
0190
0191 #define CIR_STATUS 0x00
0192 #define CIR_RX_DATA 0x01
0193 #define CIR_TX_CONTROL 0x02
0194 #define CIR_TX_DATA 0x03
0195 #define CIR_CONTROL 0x04
0196
0197
0198 #define LOGICAL_DEV_ACPI 0x01
0199 #define LDEV_ACPI_WAKE_EN_REG 0xe8
0200 #define ACPI_WAKE_EN_CIR_BIT 0x04
0201
0202 #define LDEV_ACPI_PME_EN_REG 0xf0
0203 #define LDEV_ACPI_PME_CLR_REG 0xf1
0204 #define ACPI_PME_CIR_BIT 0x02
0205
0206 #define LDEV_ACPI_STATE_REG 0xf4
0207 #define ACPI_STATE_CIR_BIT 0x20
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217 #define CIR_STATUS_IRQ_EN 0x80
0218 #define CIR_STATUS_TX_FINISH 0x08
0219 #define CIR_STATUS_TX_UNDERRUN 0x04
0220 #define CIR_STATUS_RX_TIMEOUT 0x02
0221 #define CIR_STATUS_RX_RECEIVE 0x01
0222 #define CIR_STATUS_IRQ_MASK 0x0f
0223
0224
0225
0226
0227
0228
0229 #define CIR_TX_CONTROL_TX_START 0x80
0230 #define CIR_TX_CONTROL_TX_END 0x40
0231