33 #include <linux/kernel.h>
34 #include <linux/module.h>
38 #include <linux/sched.h>
40 #include <linux/slab.h>
41 #include <linux/input.h>
42 #include <linux/bitops.h>
56 static int rx_low_carrier_freq;
58 MODULE_PARM_DESC(rx_low_carrier_freq,
"Override low RX carrier frequency, Hz, "
59 "0 for no RX demodulation");
62 static int rx_high_carrier_freq;
64 MODULE_PARM_DESC(rx_high_carrier_freq,
"Override high RX carrier frequency, "
65 "Hz, 0 for no RX demodulation");
68 static int tx_carrier_freq;
73 static int tx_duty_cycle;
78 static long sample_period;
83 static int model_number = -1;
91 static inline bool ite_is_high_carrier_freq(
unsigned int freq)
98 static u8 ite_get_carrier_freq_bits(
unsigned int freq)
100 if (ite_is_high_carrier_freq(freq)) {
104 else if (freq < 465000)
107 else if (freq < 490000)
129 static u8 ite_get_pulse_width_bits(
unsigned int freq,
int duty_cycle)
131 unsigned long period_ns, on_ns;
139 period_ns = 1000000000
UL /
freq;
140 on_ns = period_ns * duty_cycle / 100;
142 if (ite_is_high_carrier_freq(freq)) {
146 else if (on_ns < 850)
149 else if (on_ns < 950)
152 else if (on_ns < 1080)
161 else if (on_ns < 7850)
164 else if (on_ns < 9650)
167 else if (on_ns < 11950)
181 unsigned long *ldata;
182 unsigned int next_one, next_zero,
size;
188 sample_period = dev->
params.sample_period;
189 ldata = (
unsigned long *)data;
199 while (next_one < size) {
202 ev.duration =
ITE_BITS_TO_NS(next_zero - next_one, sample_period);
205 if (next_zero < size) {
227 static void ite_set_carrier_params(
struct ite_dev *dev)
229 unsigned int freq, low_freq, high_freq;
231 bool use_demodulator;
234 ite_dbg(
"%s called", __func__);
238 freq = dev->
params.tx_carrier_freq;
240 use_demodulator =
false;
242 low_freq = dev->
params.rx_low_carrier_freq;
243 high_freq = dev->
params.rx_high_carrier_freq;
250 use_demodulator =
false;
253 freq = (low_freq + high_freq) / 2;
259 * (high_freq + low_freq));
270 dev->
params.set_carrier_params(dev, ite_is_high_carrier_freq(freq),
271 use_demodulator, ite_get_carrier_freq_bits(freq), allowance,
272 ite_get_pulse_width_bits(freq, dev->
params.tx_duty_cycle));
276 static irqreturn_t ite_cir_isr(
int irq,
void *data)
291 iflags = dev->
params.get_irq_causes(dev);
297 dev->
params.get_rx_bytes(dev, rx_buf,
304 spin_unlock_irqrestore(&dev->
309 ite_decode_bytes(dev, rx_buf,
331 spin_unlock_irqrestore(&dev->
lock, flags);
339 static int ite_set_rx_carrier_range(
struct rc_dev *rcdev,
u32 carrier_low,
u32
346 dev->
params.rx_low_carrier_freq = carrier_low;
347 dev->
params.rx_high_carrier_freq = carrier_high;
348 ite_set_carrier_params(dev);
349 spin_unlock_irqrestore(&dev->
lock, flags);
355 static int ite_set_tx_carrier(
struct rc_dev *rcdev,
u32 carrier)
361 dev->
params.tx_carrier_freq = carrier;
362 ite_set_carrier_params(dev);
363 spin_unlock_irqrestore(&dev->
lock, flags);
369 static int ite_set_tx_duty_cycle(
struct rc_dev *rcdev,
u32 duty_cycle)
375 dev->
params.tx_duty_cycle = duty_cycle;
376 ite_set_carrier_params(dev);
377 spin_unlock_irqrestore(&dev->
lock, flags);
385 static int ite_tx_ir(
struct rc_dev *rcdev,
unsigned *txbuf,
unsigned n)
389 bool is_pulse =
false;
390 int remaining_us, fifo_avail, fifo_remaining, last_idx = 0;
391 int max_rle_us, next_rle_us;
396 ite_dbg(
"%s called", __func__);
407 ite_set_carrier_params(dev);
415 dev->
params.disable_rx(dev);
424 while (n > 0 && dev->
in_use) {
426 is_pulse = !is_pulse;
427 remaining_us = *(txbuf++);
431 ((is_pulse) ?
"pulse" :
"space"),
436 while (remaining_us > 0 && dev->
in_use) {
437 if (remaining_us > max_rle_us)
438 next_rle_us = max_rle_us;
441 next_rle_us = remaining_us;
443 remaining_us -= next_rle_us;
449 last_sent[last_idx++] =
val;
470 if (fifo_avail <= 0) {
473 enable_tx_interrupt(dev);
476 spin_unlock_irqrestore(&dev->
lock, flags);
486 disable_tx_interrupt(dev);
490 dev->
params.put_tx_byte(dev, val);
498 fifo_remaining = dev->
params.get_tx_used_slots(dev);
500 while (fifo_remaining > 0) {
504 remaining_us += last_sent[last_idx];
509 spin_unlock_irqrestore(&dev->
lock, flags);
521 ite_set_carrier_params(dev);
525 dev->
params.enable_rx(dev);
530 spin_unlock_irqrestore(&dev->
lock, flags);
536 static void ite_s_idle(
struct rc_dev *rcdev,
bool enable)
541 ite_dbg(
"%s called", __func__);
546 spin_unlock_irqrestore(&dev->
lock, flags);
556 static int it87_get_irq_causes(
struct ite_dev *dev)
561 ite_dbg(
"%s called", __func__);
582 static void it87_set_carrier_params(
struct ite_dev *dev,
bool high_freq,
583 bool use_demodulator,
584 u8 carrier_freq_bits,
u8 allowance_bits,
589 ite_dbg(
"%s called", __func__);
601 val |= allowance_bits;
616 ite_dbg(
"%s called", __func__);
621 while (fifo > 0 && buf_size > 0) {
634 static int it87_get_tx_used_slots(
struct ite_dev *dev)
636 ite_dbg(
"%s called", __func__);
649 static void it87_idle_rx(
struct ite_dev *dev)
651 ite_dbg(
"%s called", __func__);
663 static void it87_disable_rx(
struct ite_dev *dev)
665 ite_dbg(
"%s called", __func__);
681 static void it87_enable_rx(
struct ite_dev *dev)
683 ite_dbg(
"%s called", __func__);
699 static void it87_disable_tx_interrupt(
struct ite_dev *dev)
701 ite_dbg(
"%s called", __func__);
710 static void it87_enable_tx_interrupt(
struct ite_dev *dev)
712 ite_dbg(
"%s called", __func__);
720 static void it87_disable(
struct ite_dev *dev)
722 ite_dbg(
"%s called", __func__);
730 it87_disable_rx(dev);
738 static void it87_init_hardware(
struct ite_dev *dev)
740 ite_dbg(
"%s called", __func__);
765 ite_set_carrier_params(dev);
773 static int it8708_get_irq_causes(
struct ite_dev *dev)
778 ite_dbg(
"%s called", __func__);
794 static void it8708_set_carrier_params(
struct ite_dev *dev,
bool high_freq,
795 bool use_demodulator,
796 u8 carrier_freq_bits,
u8 allowance_bits,
801 ite_dbg(
"%s called", __func__);
825 val |= allowance_bits;
831 val |= pulse_width_bits;
837 static int it8708_get_rx_bytes(
struct ite_dev *dev,
u8 * buf,
int buf_size)
841 ite_dbg(
"%s called", __func__);
846 while (fifo > 0 && buf_size > 0) {
859 static int it8708_get_tx_used_slots(
struct ite_dev *dev)
861 ite_dbg(
"%s called", __func__);
874 static void it8708_idle_rx(
struct ite_dev *dev)
876 ite_dbg(
"%s called", __func__);
888 static void it8708_disable_rx(
struct ite_dev *dev)
890 ite_dbg(
"%s called", __func__);
907 static void it8708_enable_rx(
struct ite_dev *dev)
909 ite_dbg(
"%s called", __func__);
926 static void it8708_disable_tx_interrupt(
struct ite_dev *dev)
928 ite_dbg(
"%s called", __func__);
937 static void it8708_enable_tx_interrupt(
struct ite_dev *dev)
939 ite_dbg(
"%s called", __func__);
948 static void it8708_disable(
struct ite_dev *dev)
950 ite_dbg(
"%s called", __func__);
958 it8708_disable_rx(dev);
966 static void it8708_init_hardware(
struct ite_dev *dev)
968 ite_dbg(
"%s called", __func__);
1008 ite_set_carrier_params(dev);
1021 static inline void it8709_wm(
struct ite_dev *dev,
u8 val,
int index)
1027 static void it8709_wait(
struct ite_dev *dev)
1034 for (i = 0; i < 15000; i++) {
1070 static int it8709_get_irq_causes(
struct ite_dev *dev)
1075 ite_dbg(
"%s called", __func__);
1080 if (iflags & IT85_TLDLI)
1082 if (iflags & IT85_RDAI)
1091 static void it8709_set_carrier_params(
struct ite_dev *dev,
bool high_freq,
1092 bool use_demodulator,
1093 u8 carrier_freq_bits,
u8 allowance_bits,
1094 u8 pulse_width_bits)
1098 ite_dbg(
"%s called", __func__);
1113 if (use_demodulator)
1116 val |= allowance_bits;
1122 val |= pulse_width_bits;
1128 static int it8709_get_rx_bytes(
struct ite_dev *dev,
u8 * buf,
int buf_size)
1132 ite_dbg(
"%s called", __func__);
1137 while (fifo > 0 && buf_size > 0) {
1155 static int it8709_get_tx_used_slots(
struct ite_dev *dev)
1157 ite_dbg(
"%s called", __func__);
1170 static void it8709_idle_rx(
struct ite_dev *dev)
1172 ite_dbg(
"%s called", __func__);
1184 static void it8709_disable_rx(
struct ite_dev *dev)
1186 ite_dbg(
"%s called", __func__);
1199 it8709_idle_rx(dev);
1203 static void it8709_enable_rx(
struct ite_dev *dev)
1205 ite_dbg(
"%s called", __func__);
1212 it8709_idle_rx(dev);
1222 static void it8709_disable_tx_interrupt(
struct ite_dev *dev)
1224 ite_dbg(
"%s called", __func__);
1233 static void it8709_enable_tx_interrupt(
struct ite_dev *dev)
1235 ite_dbg(
"%s called", __func__);
1244 static void it8709_disable(
struct ite_dev *dev)
1246 ite_dbg(
"%s called", __func__);
1254 it8709_disable_rx(dev);
1262 static void it8709_init_hardware(
struct ite_dev *dev)
1264 ite_dbg(
"%s called", __func__);
1295 ite_set_carrier_params(dev);
1302 static int ite_open(
struct rc_dev *rcdev)
1305 unsigned long flags;
1307 ite_dbg(
"%s called", __func__);
1313 dev->
params.enable_rx(dev);
1315 spin_unlock_irqrestore(&dev->
lock, flags);
1321 static void ite_close(
struct rc_dev *rcdev)
1324 unsigned long flags;
1326 ite_dbg(
"%s called", __func__);
1332 spin_unlock_irqrestore(&dev->
lock, flags);
1336 dev->
params.disable(dev);
1338 spin_unlock_irqrestore(&dev->
lock, flags);
1344 .model =
"ITE8704 CIR transceiver",
1347 .hw_tx_capable =
true,
1348 .sample_period = (
u32) (1000000000ULL / 115200),
1349 .tx_carrier_freq = 38000,
1350 .tx_duty_cycle = 33,
1351 .rx_low_carrier_freq = 0,
1352 .rx_high_carrier_freq = 0,
1355 .get_irq_causes = it87_get_irq_causes,
1356 .enable_rx = it87_enable_rx,
1357 .idle_rx = it87_idle_rx,
1358 .disable_rx = it87_idle_rx,
1359 .get_rx_bytes = it87_get_rx_bytes,
1360 .enable_tx_interrupt = it87_enable_tx_interrupt,
1361 .disable_tx_interrupt = it87_disable_tx_interrupt,
1362 .get_tx_used_slots = it87_get_tx_used_slots,
1363 .put_tx_byte = it87_put_tx_byte,
1364 .disable = it87_disable,
1365 .init_hardware = it87_init_hardware,
1366 .set_carrier_params = it87_set_carrier_params,
1369 .model =
"ITE8713 CIR transceiver",
1372 .hw_tx_capable =
true,
1373 .sample_period = (
u32) (1000000000ULL / 115200),
1374 .tx_carrier_freq = 38000,
1375 .tx_duty_cycle = 33,
1376 .rx_low_carrier_freq = 0,
1377 .rx_high_carrier_freq = 0,
1380 .get_irq_causes = it87_get_irq_causes,
1381 .enable_rx = it87_enable_rx,
1382 .idle_rx = it87_idle_rx,
1383 .disable_rx = it87_idle_rx,
1384 .get_rx_bytes = it87_get_rx_bytes,
1385 .enable_tx_interrupt = it87_enable_tx_interrupt,
1386 .disable_tx_interrupt = it87_disable_tx_interrupt,
1387 .get_tx_used_slots = it87_get_tx_used_slots,
1388 .put_tx_byte = it87_put_tx_byte,
1389 .disable = it87_disable,
1390 .init_hardware = it87_init_hardware,
1391 .set_carrier_params = it87_set_carrier_params,
1394 .model =
"ITE8708 CIR transceiver",
1397 .hw_tx_capable =
true,
1398 .sample_period = (
u32) (1000000000ULL / 115200),
1399 .tx_carrier_freq = 38000,
1400 .tx_duty_cycle = 33,
1401 .rx_low_carrier_freq = 0,
1402 .rx_high_carrier_freq = 0,
1405 .get_irq_causes = it8708_get_irq_causes,
1406 .enable_rx = it8708_enable_rx,
1407 .idle_rx = it8708_idle_rx,
1408 .disable_rx = it8708_idle_rx,
1409 .get_rx_bytes = it8708_get_rx_bytes,
1410 .enable_tx_interrupt = it8708_enable_tx_interrupt,
1411 .disable_tx_interrupt =
1412 it8708_disable_tx_interrupt,
1413 .get_tx_used_slots = it8708_get_tx_used_slots,
1414 .put_tx_byte = it8708_put_tx_byte,
1415 .disable = it8708_disable,
1416 .init_hardware = it8708_init_hardware,
1417 .set_carrier_params = it8708_set_carrier_params,
1420 .model =
"ITE8709 CIR transceiver",
1423 .hw_tx_capable =
true,
1424 .sample_period = (
u32) (1000000000ULL / 115200),
1425 .tx_carrier_freq = 38000,
1426 .tx_duty_cycle = 33,
1427 .rx_low_carrier_freq = 0,
1428 .rx_high_carrier_freq = 0,
1431 .get_irq_causes = it8709_get_irq_causes,
1432 .enable_rx = it8709_enable_rx,
1433 .idle_rx = it8709_idle_rx,
1434 .disable_rx = it8709_idle_rx,
1435 .get_rx_bytes = it8709_get_rx_bytes,
1436 .enable_tx_interrupt = it8709_enable_tx_interrupt,
1437 .disable_tx_interrupt =
1438 it8709_disable_tx_interrupt,
1439 .get_tx_used_slots = it8709_get_tx_used_slots,
1440 .put_tx_byte = it8709_put_tx_byte,
1441 .disable = it8709_disable,
1442 .init_hardware = it8709_init_hardware,
1443 .set_carrier_params = it8709_set_carrier_params,
1466 ite_dbg(
"%s called", __func__);
1483 ite_dev_descs[model_no].model);
1485 if (model_number >= 0 && model_number <
ARRAY_SIZE(ite_dev_descs)) {
1486 model_no = model_number;
1494 dev_desc = &ite_dev_descs[model_no];
1498 if (!pnp_port_valid(pdev, io_rsrc_no) ||
1500 dev_err(&pdev->
dev,
"IR PNP Port not valid!\n");
1504 if (!pnp_irq_valid(pdev, 0)) {
1510 itdev->
cir_addr = pnp_port_start(pdev, io_rsrc_no);
1517 init_ir_raw_event(&itdev->
rawir);
1520 pnp_set_drvdata(pdev, itdev);
1531 if (sample_period > 0)
1532 itdev->
params.sample_period = sample_period;
1534 if (tx_carrier_freq > 0)
1535 itdev->
params.tx_carrier_freq = tx_carrier_freq;
1537 if (tx_duty_cycle > 0 && tx_duty_cycle <= 100)
1538 itdev->
params.tx_duty_cycle = tx_duty_cycle;
1540 if (rx_low_carrier_freq > 0)
1541 itdev->
params.rx_low_carrier_freq = rx_low_carrier_freq;
1543 if (rx_high_carrier_freq > 0)
1544 itdev->
params.rx_high_carrier_freq = rx_high_carrier_freq;
1548 itdev->
params.hw_tx_capable);
1550 itdev->
params.sample_period);
1552 itdev->
params.tx_carrier_freq);
1554 itdev->
params.tx_duty_cycle);
1556 itdev->
params.rx_low_carrier_freq);
1558 itdev->
params.rx_high_carrier_freq);
1561 itdev->
params.init_hardware(itdev);
1567 rdev->
open = ite_open;
1568 rdev->
close = ite_close;
1569 rdev->
s_idle = ite_s_idle;
1575 itdev->
params.sample_period;
1577 itdev->
params.sample_period;
1580 if (itdev->
params.hw_tx_capable) {
1581 rdev->
tx_ir = ite_tx_ir;
1625 struct ite_dev *dev = pnp_get_drvdata(pdev);
1626 unsigned long flags;
1628 ite_dbg(
"%s called", __func__);
1633 dev->
params.disable(dev);
1635 spin_unlock_irqrestore(&dev->
lock, flags);
1648 struct ite_dev *dev = pnp_get_drvdata(pdev);
1649 unsigned long flags;
1651 ite_dbg(
"%s called", __func__);
1659 dev->
params.disable(dev);
1661 spin_unlock_irqrestore(&dev->
lock, flags);
1666 static int ite_resume(
struct pnp_dev *pdev)
1669 struct ite_dev *dev = pnp_get_drvdata(pdev);
1670 unsigned long flags;
1672 ite_dbg(
"%s called", __func__);
1677 dev->
params.init_hardware(dev);
1679 dev->
params.enable_rx(dev);
1681 spin_unlock_irqrestore(&dev->
lock, flags);
1686 static void ite_shutdown(
struct pnp_dev *pdev)
1688 struct ite_dev *dev = pnp_get_drvdata(pdev);
1689 unsigned long flags;
1691 ite_dbg(
"%s called", __func__);
1696 dev->
params.disable(dev);
1698 spin_unlock_irqrestore(&dev->
lock, flags);
1703 .id_table = ite_ids,
1706 .suspend = ite_suspend,
1707 .resume = ite_resume,
1708 .shutdown = ite_shutdown,