Lines Matching +full:edge +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * serial_ir - Device driver that records pulse- and pause-lengths
6 * (space-lengths) between DDCD event on a serial port.
8 * Copyright (C) 1996,97 Ralph Metzler <rjkm@thp.uni-koeln.de>
13 * Copyright (C) 2016 Sean Young <sean@mess.org> (port to rc-core)
28 #include <media/rc-core.h>
37 void (*send_pulse)(unsigned int length, ktime_t edge);
56 static int sense = -1; /* -1 = auto, 0 = active high, 1 = active low */
60 static void send_pulse_irdeo(unsigned int length, ktime_t edge);
63 static void send_pulse_homebrew(unsigned int length, ktime_t edge);
141 /* fetch serial input packet (1 byte) from register offset */
142 static u8 sinp(int offset) in sinp() argument
145 /* the register is memory-mapped */ in sinp()
146 offset <<= ioshift; in sinp()
148 return inb(io + offset); in sinp()
151 /* write serial output packet (1 byte) of value to register offset */
152 static void soutp(int offset, u8 value) in soutp() argument
155 /* the register is memory-mapped */ in soutp()
156 offset <<= ioshift; in soutp()
158 outb(value, io + offset); in soutp()
190 for (i = 0, output = 0x7f; rawbits > 0; rawbits -= 3) { in send_pulse_irdeo()
215 static void send_pulse_homebrew_softcarrier(unsigned int length, ktime_t edge) in send_pulse_homebrew_softcarrier() argument
217 ktime_t now, target = ktime_add_us(edge, length); in send_pulse_homebrew_softcarrier()
228 space = DIV_ROUND_CLOSEST((100 - serial_ir.duty_cycle) * in send_pulse_homebrew_softcarrier()
236 edge = ktime_add_ns(edge, pulse); in send_pulse_homebrew_softcarrier()
237 delta = ktime_to_ns(ktime_sub(edge, now)); in send_pulse_homebrew_softcarrier()
244 edge = ktime_add_ns(edge, space); in send_pulse_homebrew_softcarrier()
245 delta = ktime_to_ns(ktime_sub(edge, now)); in send_pulse_homebrew_softcarrier()
251 static void send_pulse_homebrew(unsigned int length, ktime_t edge) in send_pulse_homebrew() argument
254 send_pulse_homebrew_softcarrier(length, edge); in send_pulse_homebrew()
327 static int last_dcd = -1; in serial_ir_irq_handler()
339 dev_err(&serial_ir.pdev->dev, "Trapped in interrupt"); in serial_ir_irq_handler()
343 sense != -1) { in serial_ir_irq_handler()
357 dev_dbg(&serial_ir.pdev->dev, in serial_ir_irq_handler()
369 dev_err(&serial_ir.pdev->dev, in serial_ir_irq_handler()
389 jiffies + usecs_to_jiffies(serial_ir.rcdev->timeout)); in serial_ir_irq_handler()
419 return -ENODEV; in hardware_init_port()
470 .duration = serial_ir.rcdev->timeout in serial_ir_timeout()
489 rcdev = devm_rc_allocate_device(&dev->dev, RC_DRIVER_IR_RAW); in serial_ir_probe()
491 return -ENOMEM; in serial_ir_probe()
494 rcdev->tx_ir = serial_ir_tx; in serial_ir_probe()
496 rcdev->s_tx_carrier = serial_ir_tx_carrier; in serial_ir_probe()
498 rcdev->s_tx_duty_cycle = serial_ir_tx_duty_cycle; in serial_ir_probe()
502 rcdev->device_name = "Serial IR type home-brew"; in serial_ir_probe()
505 rcdev->device_name = "Serial IR type IRdeo"; in serial_ir_probe()
508 rcdev->device_name = "Serial IR type IRdeo remote"; in serial_ir_probe()
511 rcdev->device_name = "Serial IR type AnimaX"; in serial_ir_probe()
514 rcdev->device_name = "Serial IR type IgorPlug"; in serial_ir_probe()
518 rcdev->input_phys = KBUILD_MODNAME "/input0"; in serial_ir_probe()
519 rcdev->input_id.bustype = BUS_HOST; in serial_ir_probe()
520 rcdev->input_id.vendor = 0x0001; in serial_ir_probe()
521 rcdev->input_id.product = 0x0001; in serial_ir_probe()
522 rcdev->input_id.version = 0x0100; in serial_ir_probe()
523 rcdev->open = serial_ir_open; in serial_ir_probe()
524 rcdev->close = serial_ir_close; in serial_ir_probe()
525 rcdev->dev.parent = &serial_ir.pdev->dev; in serial_ir_probe()
526 rcdev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER; in serial_ir_probe()
527 rcdev->driver_name = KBUILD_MODNAME; in serial_ir_probe()
528 rcdev->map_name = RC_MAP_RC6_MCE; in serial_ir_probe()
529 rcdev->min_timeout = 1; in serial_ir_probe()
530 rcdev->timeout = IR_DEFAULT_TIMEOUT; in serial_ir_probe()
531 rcdev->max_timeout = 10 * IR_DEFAULT_TIMEOUT; in serial_ir_probe()
532 rcdev->rx_resolution = 250; in serial_ir_probe()
538 result = devm_request_irq(&dev->dev, irq, serial_ir_irq_handler, in serial_ir_probe()
542 if (result == -EBUSY) in serial_ir_probe()
543 dev_err(&dev->dev, "IRQ %d busy\n", irq); in serial_ir_probe()
544 else if (result == -EINVAL) in serial_ir_probe()
545 dev_err(&dev->dev, "Bad irq number or handler\n"); in serial_ir_probe()
551 (devm_request_mem_region(&dev->dev, iommap, 8UL << ioshift, in serial_ir_probe()
553 (!iommap && (devm_request_region(&dev->dev, io, 8, in serial_ir_probe()
555 dev_err(&dev->dev, "port %04x already in use\n", io); in serial_ir_probe()
556 dev_warn(&dev->dev, "use 'setserial /dev/ttySX uart none'\n"); in serial_ir_probe()
557 dev_warn(&dev->dev, in serial_ir_probe()
559 dev_warn(&dev->dev, "make sure this module is loaded first\n"); in serial_ir_probe()
560 return -EBUSY; in serial_ir_probe()
572 if (sense == -1) { in serial_ir_probe()
590 dev_info(&dev->dev, "auto-detected active %s receiver\n", in serial_ir_probe()
593 dev_info(&dev->dev, "Manually using active %s receiver\n", in serial_ir_probe()
596 dev_dbg(&dev->dev, "Interrupt %d, port %04x obtained\n", irq, io); in serial_ir_probe()
598 return devm_rc_register_device(&dev->dev, rcdev); in serial_ir_probe()
639 ktime_t edge; in serial_ir_tx() local
649 edge = ktime_get(); in serial_ir_tx()
654 hardware[type].send_pulse(txbuf[i], edge); in serial_ir_tx()
656 edge = ktime_add_us(edge, txbuf[i]); in serial_ir_tx()
657 delta = ktime_us_delta(edge, ktime_get()); in serial_ir_tx()
660 usleep_range(delta - 25, delta + 25); in serial_ir_tx()
680 return -EINVAL; in serial_ir_tx_carrier()
744 result = -ENOMEM; in serial_ir_init()
780 return -EINVAL; in serial_ir_init_module()
792 /* make sure sense is either -1, 0, or 1 */ in serial_ir_init_module()
793 if (sense != -1) in serial_ir_init_module()
808 MODULE_DESCRIPTION("Infra-red receiver driver for serial ports.");
813 MODULE_PARM_DESC(type, "Hardware type (0 = home-brew, 1 = IRdeo, 2 = IRdeo Remote, 3 = AnimaX, 4 = …
825 * See linux-kernel/drivers/tty/serial/8250/8250.c serial_in()/out()
828 MODULE_PARM_DESC(ioshift, "shift I/O register offset (0 = no shift)");