Lines Matching +full:ld +full:- +full:pulse +full:- +full:delay +full:- +full:us
1 // SPDX-License-Identifier: GPL-2.0-or-later
8 * skeleton provided by the nuvoton-cir driver.
10 * The lirc_it87 driver was originally written by Hans-Gunter Lutke Uphues
13 * <jimbo-lirc@edwardsclan.net>.
16 * <spmf2004-lirc@yahoo.fr> in 2008.
25 #include <linux/delay.h>
29 #include <media/rc-core.h>
32 #include "ite-cir.h"
59 MODULE_PARM_DESC(tx_duty_cycle, "Override TX duty cycle, 1-100");
64 MODULE_PARM_DESC(sample_period, "Override carrier sample period, us");
67 static int model_number = -1;
72 /* HW-independent code functions */
105 DIV_ROUND_CLOSEST(freq - ITE_LCF_MIN_CARRIER_FREQ, in ite_get_carrier_freq_bits()
112 /* get the bits required to program the pulse with in TXMPW */
159 /* decode raw bytes as received by the hardware, and push them to the ir-core
172 sample_period = dev->params.sample_period; in ite_decode_bytes()
177 ev.pulse = true; in ite_decode_bytes()
180 ir_raw_event_store_with_filter(dev->rdev, &ev); in ite_decode_bytes()
185 ev.pulse = false; in ite_decode_bytes()
186 ev.duration = ITE_BITS_TO_US(next_zero - next_one, sample_period); in ite_decode_bytes()
187 ir_raw_event_store_with_filter(dev->rdev, &ev); in ite_decode_bytes()
194 ev.pulse = true; in ite_decode_bytes()
196 ITE_BITS_TO_US(next_one - next_zero, in ite_decode_bytes()
199 (dev->rdev, &ev); in ite_decode_bytes()
204 ir_raw_event_handle(dev->rdev); in ite_decode_bytes()
216 bool for_tx = dev->transmitting; in ite_set_carrier_params()
222 freq = dev->params.tx_carrier_freq; in ite_set_carrier_params()
226 low_freq = dev->params.rx_low_carrier_freq; in ite_set_carrier_params()
227 high_freq = dev->params.rx_high_carrier_freq; in ite_set_carrier_params()
241 DIV_ROUND_CLOSEST(10000 * (high_freq - low_freq), in ite_set_carrier_params()
255 /* set the carrier parameters in a device-dependent way */ in ite_set_carrier_params()
256 dev->params.set_carrier_params(dev, ite_is_high_carrier_freq(freq), in ite_set_carrier_params()
258 ite_get_pulse_width_bits(freq, dev->params.tx_duty_cycle)); in ite_set_carrier_params()
274 spin_lock_irqsave(&dev->lock, flags); in ite_cir_isr()
277 iflags = dev->params.get_irq_causes(dev); in ite_cir_isr()
283 dev->params.get_rx_bytes(dev, rx_buf, in ite_cir_isr()
287 /* drop the spinlock, since the ir-core layer in ite_cir_isr()
288 * may call us back again through in ite_cir_isr()
290 spin_unlock_irqrestore(&dev-> in ite_cir_isr()
299 spin_lock_irqsave(&dev->lock, in ite_cir_isr()
310 wake_up_interruptible(&dev->tx_queue); in ite_cir_isr()
317 spin_unlock_irqrestore(&dev->lock, flags); in ite_cir_isr()
329 struct ite_dev *dev = rcdev->priv; in ite_set_rx_carrier_range()
331 spin_lock_irqsave(&dev->lock, flags); in ite_set_rx_carrier_range()
332 dev->params.rx_low_carrier_freq = carrier_low; in ite_set_rx_carrier_range()
333 dev->params.rx_high_carrier_freq = carrier_high; in ite_set_rx_carrier_range()
335 spin_unlock_irqrestore(&dev->lock, flags); in ite_set_rx_carrier_range()
344 struct ite_dev *dev = rcdev->priv; in ite_set_tx_carrier()
346 spin_lock_irqsave(&dev->lock, flags); in ite_set_tx_carrier()
347 dev->params.tx_carrier_freq = carrier; in ite_set_tx_carrier()
349 spin_unlock_irqrestore(&dev->lock, flags); in ite_set_tx_carrier()
354 /* set the tx duty cycle by controlling the pulse width */
358 struct ite_dev *dev = rcdev->priv; in ite_set_tx_duty_cycle()
360 spin_lock_irqsave(&dev->lock, flags); in ite_set_tx_duty_cycle()
361 dev->params.tx_duty_cycle = duty_cycle; in ite_set_tx_duty_cycle()
363 spin_unlock_irqrestore(&dev->lock, flags); in ite_set_tx_duty_cycle()
369 * pulse/space/pulse/space lengths that we should write out completely through
374 struct ite_dev *dev = rcdev->priv; in ite_tx_ir()
387 spin_lock_irqsave(&dev->lock, flags); in ite_tx_ir()
390 dev->transmitting = true; in ite_tx_ir()
397 (ITE_BAUDRATE_DIVISOR * dev->params.sample_period * in ite_tx_ir()
401 dev->params.disable_rx(dev); in ite_tx_ir()
404 * then we'll just activate the interrupt, wait for it to wake us up in ite_tx_ir()
408 ITE_TX_FIFO_LEN - dev->params.get_tx_used_slots(dev); in ite_tx_ir()
410 while (n > 0 && dev->in_use) { in ite_tx_ir()
414 n--; in ite_tx_ir()
416 ite_dbg("%s: %ld", in ite_tx_ir()
417 ((is_pulse) ? "pulse" : "space"), in ite_tx_ir()
421 /* repeat while the pulse is non-zero length */ in ite_tx_ir()
422 while (remaining_us > 0 && dev->in_use) { in ite_tx_ir()
429 remaining_us -= next_rle_us; in ite_tx_ir()
439 val = (val - 1) & ITE_TX_RLE_MASK; in ite_tx_ir()
441 /* take into account pulse/space prefix */ in ite_tx_ir()
453 fifo_avail = ITE_TX_FIFO_LEN - dev->params.get_tx_used_slots(dev); in ite_tx_ir()
458 dev->params. in ite_tx_ir()
462 spin_unlock_irqrestore(&dev->lock, flags); in ite_tx_ir()
465 …wait_event_interruptible(dev->tx_queue, (fifo_avail = ITE_TX_FIFO_LEN - dev->params.get_tx_used_sl… in ite_tx_ir()
468 spin_lock_irqsave(&dev->lock, flags); in ite_tx_ir()
471 dev->params. in ite_tx_ir()
476 dev->params.put_tx_byte(dev, val); in ite_tx_ir()
477 fifo_avail--; in ite_tx_ir()
484 fifo_remaining = dev->params.get_tx_used_slots(dev); in ite_tx_ir()
487 fifo_remaining--; in ite_tx_ir()
488 last_idx--; in ite_tx_ir()
489 last_idx &= (ITE_TX_FIFO_LEN - 1); in ite_tx_ir()
495 spin_unlock_irqrestore(&dev->lock, flags); in ite_tx_ir()
501 spin_lock_irqsave(&dev->lock, flags); in ite_tx_ir()
504 dev->transmitting = false; in ite_tx_ir()
509 /* re-enable the receiver */ in ite_tx_ir()
510 if (dev->in_use) in ite_tx_ir()
511 dev->params.enable_rx(dev); in ite_tx_ir()
514 wake_up_interruptible(&dev->tx_ended); in ite_tx_ir()
516 spin_unlock_irqrestore(&dev->lock, flags); in ite_tx_ir()
525 struct ite_dev *dev = rcdev->priv; in ite_s_idle()
530 spin_lock_irqsave(&dev->lock, flags); in ite_s_idle()
531 dev->params.idle_rx(dev); in ite_s_idle()
532 spin_unlock_irqrestore(&dev->lock, flags); in ite_s_idle()
537 /* IT8712F HW-specific functions */
550 iflags = inb(dev->cir_addr + IT87_IIR) & IT87_II; in it87_get_irq_causes()
578 val = inb(dev->cir_addr + IT87_RCR) in it87_set_carrier_params()
589 outb(val, dev->cir_addr + IT87_RCR); in it87_set_carrier_params()
593 dev->cir_addr + IT87_TCR2); in it87_set_carrier_params()
605 fifo = inb(dev->cir_addr + IT87_RSR) & IT87_RXFBC; in it87_get_rx_bytes()
608 *(buf++) = inb(dev->cir_addr + IT87_DR); in it87_get_rx_bytes()
609 fifo--; in it87_get_rx_bytes()
611 buf_size--; in it87_get_rx_bytes()
624 return inb(dev->cir_addr + IT87_TSR) & IT87_TXFBC; in it87_get_tx_used_slots()
630 outb(value, dev->cir_addr + IT87_DR); in it87_put_tx_byte()
634 pulse is detected; this must be called with the device spinlock held */
640 outb(inb(dev->cir_addr + IT87_RCR) | IT87_RXACT, in it87_idle_rx()
641 dev->cir_addr + IT87_RCR); in it87_idle_rx()
644 outb(inb(dev->cir_addr + IT87_TCR1) | IT87_FIFOCLR, in it87_idle_rx()
645 dev->cir_addr + IT87_TCR1); in it87_idle_rx()
654 outb(inb(dev->cir_addr + IT87_IER) & ~(IT87_RDAIE | IT87_RFOIE), in it87_disable_rx()
655 dev->cir_addr + IT87_IER); in it87_disable_rx()
658 outb(inb(dev->cir_addr + IT87_RCR) & ~IT87_RXEN, in it87_disable_rx()
659 dev->cir_addr + IT87_RCR); in it87_disable_rx()
672 outb(inb(dev->cir_addr + IT87_RCR) | IT87_RXEN, in it87_enable_rx()
673 dev->cir_addr + IT87_RCR); in it87_enable_rx()
679 outb(inb(dev->cir_addr + IT87_IER) | IT87_RDAIE | IT87_RFOIE | IT87_IEC, in it87_enable_rx()
680 dev->cir_addr + IT87_IER); in it87_enable_rx()
690 outb(inb(dev->cir_addr + IT87_IER) & ~IT87_TLDLIE, in it87_disable_tx_interrupt()
691 dev->cir_addr + IT87_IER); in it87_disable_tx_interrupt()
701 outb(inb(dev->cir_addr + IT87_IER) | IT87_TLDLIE | IT87_IEC, in it87_enable_tx_interrupt()
702 dev->cir_addr + IT87_IER); in it87_enable_tx_interrupt()
711 outb(inb(dev->cir_addr + IT87_IER) & in it87_disable()
713 dev->cir_addr + IT87_IER); in it87_disable()
719 outb(IT87_FIFOCLR | inb(dev->cir_addr + IT87_TCR1), in it87_disable()
720 dev->cir_addr + IT87_TCR1); in it87_disable()
730 outb((inb(dev->cir_addr + IT87_IER) & in it87_init_hardware()
732 dev->cir_addr + IT87_IER); in it87_init_hardware()
735 outb(ITE_BAUDRATE_DIVISOR & 0xff, dev->cir_addr + IT87_BDLR); in it87_init_hardware()
736 outb((ITE_BAUDRATE_DIVISOR >> 8) & 0xff, dev->cir_addr + IT87_BDHR); in it87_init_hardware()
739 outb(inb(dev->cir_addr + IT87_IER) & ~IT87_BR, in it87_init_hardware()
740 dev->cir_addr + IT87_IER); in it87_init_hardware()
743 outb(ITE_RXDCR_DEFAULT, dev->cir_addr + IT87_RCR); in it87_init_hardware()
748 dev->cir_addr + IT87_TCR1); in it87_init_hardware()
754 /* IT8512F on ITE8708 HW-specific functions */
767 iflags = inb(dev->cir_addr + IT8708_C0IIR); in it8708_get_irq_causes()
790 outb(inb(dev->cir_addr + IT8708_BANKSEL) | IT8708_HRAE, in it8708_set_carrier_params()
791 dev->cir_addr + IT8708_BANKSEL); in it8708_set_carrier_params()
793 val = (inb(dev->cir_addr + IT8708_C0CFR) in it8708_set_carrier_params()
799 outb(val, dev->cir_addr + IT8708_C0CFR); in it8708_set_carrier_params()
801 outb(inb(dev->cir_addr + IT8708_BANKSEL) & ~IT8708_HRAE, in it8708_set_carrier_params()
802 dev->cir_addr + IT8708_BANKSEL); in it8708_set_carrier_params()
805 val = inb(dev->cir_addr + IT8708_C0RCR) in it8708_set_carrier_params()
813 outb(val, dev->cir_addr + IT8708_C0RCR); in it8708_set_carrier_params()
816 val = inb(dev->cir_addr + IT8708_C0TCR) & ~IT85_TXMPW; in it8708_set_carrier_params()
818 outb(val, dev->cir_addr + IT8708_C0TCR); in it8708_set_carrier_params()
830 fifo = inb(dev->cir_addr + IT8708_C0RFSR) & IT85_RXFBC; in it8708_get_rx_bytes()
833 *(buf++) = inb(dev->cir_addr + IT8708_C0DR); in it8708_get_rx_bytes()
834 fifo--; in it8708_get_rx_bytes()
836 buf_size--; in it8708_get_rx_bytes()
849 return inb(dev->cir_addr + IT8708_C0TFSR) & IT85_TXFBC; in it8708_get_tx_used_slots()
855 outb(value, dev->cir_addr + IT8708_C0DR); in it8708_put_tx_byte()
859 pulse is detected; this must be called with the device spinlock held */
865 outb(inb(dev->cir_addr + IT8708_C0RCR) | IT85_RXACT, in it8708_idle_rx()
866 dev->cir_addr + IT8708_C0RCR); in it8708_idle_rx()
869 outb(inb(dev->cir_addr + IT8708_C0MSTCR) | IT85_FIFOCLR, in it8708_idle_rx()
870 dev->cir_addr + IT8708_C0MSTCR); in it8708_idle_rx()
879 outb(inb(dev->cir_addr + IT8708_C0IER) & in it8708_disable_rx()
881 dev->cir_addr + IT8708_C0IER); in it8708_disable_rx()
884 outb(inb(dev->cir_addr + IT8708_C0RCR) & ~IT85_RXEN, in it8708_disable_rx()
885 dev->cir_addr + IT8708_C0RCR); in it8708_disable_rx()
898 outb(inb(dev->cir_addr + IT8708_C0RCR) | IT85_RXEN, in it8708_enable_rx()
899 dev->cir_addr + IT8708_C0RCR); in it8708_enable_rx()
905 outb(inb(dev->cir_addr + IT8708_C0IER) in it8708_enable_rx()
907 dev->cir_addr + IT8708_C0IER); in it8708_enable_rx()
917 outb(inb(dev->cir_addr + IT8708_C0IER) & ~IT85_TLDLIE, in it8708_disable_tx_interrupt()
918 dev->cir_addr + IT8708_C0IER); in it8708_disable_tx_interrupt()
928 outb(inb(dev->cir_addr + IT8708_C0IER) in it8708_enable_tx_interrupt()
930 dev->cir_addr + IT8708_C0IER); in it8708_enable_tx_interrupt()
939 outb(inb(dev->cir_addr + IT8708_C0IER) & in it8708_disable()
941 dev->cir_addr + IT8708_C0IER); in it8708_disable()
947 outb(IT85_FIFOCLR | inb(dev->cir_addr + IT8708_C0MSTCR), in it8708_disable()
948 dev->cir_addr + IT8708_C0MSTCR); in it8708_disable()
957 outb(inb(dev->cir_addr + IT8708_C0IER) & in it8708_init_hardware()
959 dev->cir_addr + IT8708_C0IER); in it8708_init_hardware()
962 outb(inb(dev->cir_addr + IT8708_BANKSEL) | IT8708_HRAE, in it8708_init_hardware()
963 dev->cir_addr + IT8708_BANKSEL); in it8708_init_hardware()
965 outb(ITE_BAUDRATE_DIVISOR & 0xff, dev->cir_addr + IT8708_C0BDLR); in it8708_init_hardware()
967 dev->cir_addr + IT8708_C0BDHR); in it8708_init_hardware()
969 outb(inb(dev->cir_addr + IT8708_BANKSEL) & ~IT8708_HRAE, in it8708_init_hardware()
970 dev->cir_addr + IT8708_BANKSEL); in it8708_init_hardware()
973 outb((inb(dev->cir_addr + IT8708_C0MSTCR) & in it8708_init_hardware()
977 dev->cir_addr + IT8708_C0MSTCR); in it8708_init_hardware()
980 outb((inb(dev->cir_addr + IT8708_C0RCR) & in it8708_init_hardware()
984 dev->cir_addr + IT8708_C0RCR); in it8708_init_hardware()
987 outb((inb(dev->cir_addr + IT8708_C0TCR) & in it8708_init_hardware()
991 dev->cir_addr + IT8708_C0TCR); in it8708_init_hardware()
997 /* IT8512F on ITE8709 HW-specific functions */
1002 outb(index, dev->cir_addr + IT8709_RAM_IDX); in it8709_rm()
1003 return inb(dev->cir_addr + IT8709_RAM_VAL); in it8709_rm()
1009 outb(index, dev->cir_addr + IT8709_RAM_IDX); in it8709_wm()
1010 outb(val, dev->cir_addr + IT8709_RAM_VAL); in it8709_wm()
1045 /* we wait before writing, and not afterwards, since this allows us to in it8709_wr()
1125 fifo--; in it8709_get_rx_bytes()
1127 buf_size--; in it8709_get_rx_bytes()
1155 pulse is detected; this must be called with the device spinlock held */
1290 struct ite_dev *dev = rcdev->priv; in ite_open()
1295 spin_lock_irqsave(&dev->lock, flags); in ite_open()
1296 dev->in_use = true; in ite_open()
1299 dev->params.enable_rx(dev); in ite_open()
1301 spin_unlock_irqrestore(&dev->lock, flags); in ite_open()
1309 struct ite_dev *dev = rcdev->priv; in ite_close()
1314 spin_lock_irqsave(&dev->lock, flags); in ite_close()
1315 dev->in_use = false; in ite_close()
1318 spin_unlock_irqrestore(&dev->lock, flags); in ite_close()
1319 wait_event_interruptible(dev->tx_ended, !dev->transmitting); in ite_close()
1320 spin_lock_irqsave(&dev->lock, flags); in ite_close()
1322 dev->params.disable(dev); in ite_close()
1324 spin_unlock_irqrestore(&dev->lock, flags); in ite_close()
1437 {"ITE8709", 3}, /* SRAM-Bridged IT8512 */
1448 int ret = -ENOMEM; in ite_probe()
1462 itdev->rdev = rdev; in ite_probe()
1464 ret = -ENODEV; in ite_probe()
1467 model_no = (int)dev_id->driver_data; in ite_probe()
1468 ite_pr(KERN_NOTICE, "Auto-detected model: %s\n", in ite_probe()
1480 io_rsrc_no = dev_desc->io_rsrc_no; in ite_probe()
1484 pnp_port_len(pdev, io_rsrc_no) != dev_desc->io_region_size) { in ite_probe()
1485 dev_err(&pdev->dev, "IR PNP Port not valid!\n"); in ite_probe()
1490 dev_err(&pdev->dev, "PNP IRQ not valid!\n"); in ite_probe()
1495 itdev->cir_addr = pnp_port_start(pdev, io_rsrc_no); in ite_probe()
1496 itdev->cir_irq = pnp_irq(pdev, 0); in ite_probe()
1499 spin_lock_init(&itdev->lock); in ite_probe()
1503 itdev->pdev = pdev; in ite_probe()
1506 init_waitqueue_head(&itdev->tx_queue); in ite_probe()
1507 init_waitqueue_head(&itdev->tx_ended); in ite_probe()
1509 /* copy model-specific parameters */ in ite_probe()
1510 itdev->params = *dev_desc; in ite_probe()
1514 itdev->params.sample_period = sample_period; in ite_probe()
1517 itdev->params.tx_carrier_freq = tx_carrier_freq; in ite_probe()
1520 itdev->params.tx_duty_cycle = tx_duty_cycle; in ite_probe()
1523 itdev->params.rx_low_carrier_freq = rx_low_carrier_freq; in ite_probe()
1526 itdev->params.rx_high_carrier_freq = rx_high_carrier_freq; in ite_probe()
1529 ite_pr(KERN_NOTICE, "TX-capable: %d\n", (int) in ite_probe()
1530 itdev->params.hw_tx_capable); in ite_probe()
1531 ite_pr(KERN_NOTICE, "Sample period (ns): %ld\n", (long) in ite_probe()
1532 itdev->params.sample_period); in ite_probe()
1534 itdev->params.tx_carrier_freq); in ite_probe()
1536 itdev->params.tx_duty_cycle); in ite_probe()
1538 itdev->params.rx_low_carrier_freq); in ite_probe()
1540 itdev->params.rx_high_carrier_freq); in ite_probe()
1543 itdev->params.init_hardware(itdev); in ite_probe()
1545 /* set up ir-core props */ in ite_probe()
1546 rdev->priv = itdev; in ite_probe()
1547 rdev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER; in ite_probe()
1548 rdev->open = ite_open; in ite_probe()
1549 rdev->close = ite_close; in ite_probe()
1550 rdev->s_idle = ite_s_idle; in ite_probe()
1551 rdev->s_rx_carrier_range = ite_set_rx_carrier_range; in ite_probe()
1553 rdev->min_timeout = 17 * 8 * ITE_BAUDRATE_DIVISOR * in ite_probe()
1554 itdev->params.sample_period; in ite_probe()
1555 rdev->timeout = IR_DEFAULT_TIMEOUT; in ite_probe()
1556 rdev->max_timeout = 10 * IR_DEFAULT_TIMEOUT; in ite_probe()
1557 rdev->rx_resolution = ITE_BAUDRATE_DIVISOR * in ite_probe()
1558 itdev->params.sample_period / 1000; in ite_probe()
1559 rdev->tx_resolution = ITE_BAUDRATE_DIVISOR * in ite_probe()
1560 itdev->params.sample_period / 1000; in ite_probe()
1563 if (itdev->params.hw_tx_capable) { in ite_probe()
1564 rdev->tx_ir = ite_tx_ir; in ite_probe()
1565 rdev->s_tx_carrier = ite_set_tx_carrier; in ite_probe()
1566 rdev->s_tx_duty_cycle = ite_set_tx_duty_cycle; in ite_probe()
1569 rdev->device_name = dev_desc->model; in ite_probe()
1570 rdev->input_id.bustype = BUS_HOST; in ite_probe()
1571 rdev->input_id.vendor = PCI_VENDOR_ID_ITE; in ite_probe()
1572 rdev->input_id.product = 0; in ite_probe()
1573 rdev->input_id.version = 0; in ite_probe()
1574 rdev->driver_name = ITE_DRIVER_NAME; in ite_probe()
1575 rdev->map_name = RC_MAP_RC6_MCE; in ite_probe()
1581 ret = -EBUSY; in ite_probe()
1583 if (!request_region(itdev->cir_addr, in ite_probe()
1584 dev_desc->io_region_size, ITE_DRIVER_NAME)) in ite_probe()
1587 if (request_irq(itdev->cir_irq, ite_cir_isr, IRQF_SHARED, in ite_probe()
1596 release_region(itdev->cir_addr, itdev->params.io_region_size); in ite_probe()
1614 spin_lock_irqsave(&dev->lock, flags); in ite_remove()
1617 dev->params.disable(dev); in ite_remove()
1619 spin_unlock_irqrestore(&dev->lock, flags); in ite_remove()
1622 free_irq(dev->cir_irq, dev); in ite_remove()
1623 release_region(dev->cir_addr, dev->params.io_region_size); in ite_remove()
1625 rc_unregister_device(dev->rdev); in ite_remove()
1638 wait_event_interruptible(dev->tx_ended, !dev->transmitting); in ite_suspend()
1640 spin_lock_irqsave(&dev->lock, flags); in ite_suspend()
1643 dev->params.disable(dev); in ite_suspend()
1645 spin_unlock_irqrestore(&dev->lock, flags); in ite_suspend()
1657 spin_lock_irqsave(&dev->lock, flags); in ite_resume()
1660 dev->params.init_hardware(dev); in ite_resume()
1662 dev->params.enable_rx(dev); in ite_resume()
1664 spin_unlock_irqrestore(&dev->lock, flags); in ite_resume()
1676 spin_lock_irqsave(&dev->lock, flags); in ite_shutdown()
1679 dev->params.disable(dev); in ite_shutdown()
1681 spin_unlock_irqrestore(&dev->lock, flags); in ite_shutdown()