Commit cc06393a authored by Sean Young's avatar Sean Young Committed by Mauro Carvalho Chehab

[media] staging: lirc_sir: port to rc-core

Before this driver can be moved out of staging, it should be ported
to rc-core. I've tried to make the minimum changes possible without
upsetting checkpatch.

Compile tested only.
Signed-off-by: default avatarSean Young <sean@mess.org>
Cc: Jarod Wilson <jarod@redhat.com>
Cc: Christoph Bartelmus <lirc@bartelmus.de>
Cc: Milan Pikula <www@fornax.sk>
Cc: Frank Przybylski <mail@frankprzybylski.de>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent a92def1b
...@@ -40,7 +40,7 @@ config LIRC_SASEM ...@@ -40,7 +40,7 @@ config LIRC_SASEM
config LIRC_SIR config LIRC_SIR
tristate "Built-in SIR IrDA port" tristate "Built-in SIR IrDA port"
depends on LIRC depends on RC_CORE
help help
Driver for the SIR IrDA port Driver for the SIR IrDA port
......
/* /*
* LIRC SIR driver, (C) 2000 Milan Pikula <www@fornax.sk> * LIRC SIR driver, (C) 2000 Milan Pikula <www@fornax.sk>
* *
* lirc_sir - Device driver for use with SIR (serial infra red) * sir_ir - Device driver for use with SIR (serial infra red)
* mode of IrDA on many notebooks. * mode of IrDA on many notebooks.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -58,8 +58,7 @@ ...@@ -58,8 +58,7 @@
#include <linux/timer.h> #include <linux/timer.h>
#include <media/lirc.h> #include <media/rc-core.h>
#include <media/lirc_dev.h>
/* SECTION: Definitions */ /* SECTION: Definitions */
...@@ -87,11 +86,6 @@ static void init_act200(void); ...@@ -87,11 +86,6 @@ static void init_act200(void);
static void init_act220(void); static void init_act220(void);
#endif #endif
#define RBUF_LEN 1024
#define WBUF_LEN 1024
#define LIRC_DRIVER_NAME "lirc_sir"
#define PULSE '[' #define PULSE '['
#ifndef LIRC_SIR_TEKRAM #ifndef LIRC_SIR_TEKRAM
...@@ -131,28 +125,19 @@ static ktime_t last; ...@@ -131,28 +125,19 @@ static ktime_t last;
/* time of last UART data ready interrupt */ /* time of last UART data ready interrupt */
static ktime_t last_intr_time; static ktime_t last_intr_time;
static int last_value; static int last_value;
static struct rc_dev *rcdev;
static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue); static struct platform_device *sir_ir_dev;
static DEFINE_SPINLOCK(hardware_lock); static DEFINE_SPINLOCK(hardware_lock);
static int rx_buf[RBUF_LEN];
static unsigned int rx_tail, rx_head;
static bool debug; static bool debug;
/* SECTION: Prototypes */ /* SECTION: Prototypes */
/* Communication with user-space */ /* Communication with user-space */
static unsigned int lirc_poll(struct file *file, poll_table *wait);
static ssize_t lirc_read(struct file *file, char __user *buf, size_t count,
loff_t *ppos);
static ssize_t lirc_write(struct file *file, const char __user *buf, size_t n,
loff_t *pos);
static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
static void add_read_queue(int flag, unsigned long val); static void add_read_queue(int flag, unsigned long val);
static int init_chrdev(void); static int init_chrdev(void);
static void drop_chrdev(void);
/* Hardware */ /* Hardware */
static irqreturn_t sir_interrupt(int irq, void *dev_id); static irqreturn_t sir_interrupt(int irq, void *dev_id);
static void send_space(unsigned long len); static void send_space(unsigned long len);
...@@ -189,72 +174,14 @@ static void safe_udelay(unsigned long usecs) ...@@ -189,72 +174,14 @@ static void safe_udelay(unsigned long usecs)
} }
/* SECTION: Communication with user-space */ /* SECTION: Communication with user-space */
static int sir_tx_ir(struct rc_dev *dev, unsigned int *tx_buf,
static unsigned int lirc_poll(struct file *file, poll_table *wait) unsigned int count)
{
poll_wait(file, &lirc_read_queue, wait);
if (rx_head != rx_tail)
return POLLIN | POLLRDNORM;
return 0;
}
static ssize_t lirc_read(struct file *file, char __user *buf, size_t count,
loff_t *ppos)
{
int n = 0;
int retval = 0;
DECLARE_WAITQUEUE(wait, current);
if (count % sizeof(int))
return -EINVAL;
add_wait_queue(&lirc_read_queue, &wait);
set_current_state(TASK_INTERRUPTIBLE);
while (n < count) {
if (rx_head != rx_tail) {
if (copy_to_user(buf + n,
rx_buf + rx_head,
sizeof(int))) {
retval = -EFAULT;
break;
}
rx_head = (rx_head + 1) & (RBUF_LEN - 1);
n += sizeof(int);
} else {
if (file->f_flags & O_NONBLOCK) {
retval = -EAGAIN;
break;
}
if (signal_pending(current)) {
retval = -ERESTARTSYS;
break;
}
schedule();
set_current_state(TASK_INTERRUPTIBLE);
}
}
remove_wait_queue(&lirc_read_queue, &wait);
set_current_state(TASK_RUNNING);
return n ? n : retval;
}
static ssize_t lirc_write(struct file *file, const char __user *buf, size_t n,
loff_t *pos)
{ {
unsigned long flags; unsigned long flags;
int i, count; int i;
int *tx_buf;
count = n / sizeof(int);
if (n % sizeof(int) || count % 2 == 0)
return -EINVAL;
tx_buf = memdup_user(buf, n);
if (IS_ERR(tx_buf))
return PTR_ERR(tx_buf);
i = 0;
local_irq_save(flags); local_irq_save(flags);
while (1) { for (i = 0; i < count;) {
if (i >= count)
break;
if (tx_buf[i]) if (tx_buf[i])
send_pulse(tx_buf[i]); send_pulse(tx_buf[i]);
i++; i++;
...@@ -265,138 +192,53 @@ static ssize_t lirc_write(struct file *file, const char __user *buf, size_t n, ...@@ -265,138 +192,53 @@ static ssize_t lirc_write(struct file *file, const char __user *buf, size_t n,
i++; i++;
} }
local_irq_restore(flags); local_irq_restore(flags);
kfree(tx_buf);
return count;
}
static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
{
u32 __user *uptr = (u32 __user *)arg;
int retval = 0;
u32 value = 0;
if (cmd == LIRC_GET_FEATURES)
value = LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2;
else if (cmd == LIRC_GET_SEND_MODE)
value = LIRC_MODE_PULSE;
else if (cmd == LIRC_GET_REC_MODE)
value = LIRC_MODE_MODE2;
switch (cmd) {
case LIRC_GET_FEATURES:
case LIRC_GET_SEND_MODE:
case LIRC_GET_REC_MODE:
retval = put_user(value, uptr);
break;
case LIRC_SET_SEND_MODE:
case LIRC_SET_REC_MODE:
retval = get_user(value, uptr);
break;
default:
retval = -ENOIOCTLCMD;
}
if (retval)
return retval;
if (cmd == LIRC_SET_REC_MODE) {
if (value != LIRC_MODE_MODE2)
retval = -ENOSYS;
} else if (cmd == LIRC_SET_SEND_MODE) {
if (value != LIRC_MODE_PULSE)
retval = -ENOSYS;
}
return retval; return count;
} }
static void add_read_queue(int flag, unsigned long val) static void add_read_queue(int flag, unsigned long val)
{ {
unsigned int new_rx_tail; DEFINE_IR_RAW_EVENT(ev);
int newval;
pr_debug("add flag %d with val %lu\n", flag, val); pr_debug("add flag %d with val %lu\n", flag, val);
newval = val & PULSE_MASK;
/* /*
* statistically, pulses are ~TIME_CONST/2 too long. we could * statistically, pulses are ~TIME_CONST/2 too long. we could
* maybe make this more exact, but this is good enough * maybe make this more exact, but this is good enough
*/ */
if (flag) { if (flag) {
/* pulse */ /* pulse */
if (newval > TIME_CONST/2) if (val > TIME_CONST / 2)
newval -= TIME_CONST/2; val -= TIME_CONST / 2;
else /* should not ever happen */ else /* should not ever happen */
newval = 1; val = 1;
newval |= PULSE_BIT; ev.pulse = true;
} else { } else {
newval += TIME_CONST/2; val += TIME_CONST / 2;
} }
new_rx_tail = (rx_tail + 1) & (RBUF_LEN - 1); ev.duration = US_TO_NS(val);
if (new_rx_tail == rx_head) {
pr_debug("Buffer overrun.\n");
return;
}
rx_buf[rx_tail] = newval;
rx_tail = new_rx_tail;
wake_up_interruptible(&lirc_read_queue);
}
static const struct file_operations lirc_fops = { ir_raw_event_store_with_filter(rcdev, &ev);
.owner = THIS_MODULE,
.read = lirc_read,
.write = lirc_write,
.poll = lirc_poll,
.unlocked_ioctl = lirc_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = lirc_ioctl,
#endif
.open = lirc_dev_fop_open,
.release = lirc_dev_fop_close,
.llseek = no_llseek,
};
static int set_use_inc(void *data)
{
return 0;
} }
static void set_use_dec(void *data)
{
}
static struct lirc_driver driver = {
.name = LIRC_DRIVER_NAME,
.minor = -1,
.code_length = 1,
.sample_rate = 0,
.data = NULL,
.add_to_buf = NULL,
.set_use_inc = set_use_inc,
.set_use_dec = set_use_dec,
.fops = &lirc_fops,
.dev = NULL,
.owner = THIS_MODULE,
};
static struct platform_device *lirc_sir_dev;
static int init_chrdev(void) static int init_chrdev(void)
{ {
driver.dev = &lirc_sir_dev->dev; rcdev = devm_rc_allocate_device(&sir_ir_dev->dev, RC_DRIVER_IR_RAW);
driver.minor = lirc_register_driver(&driver); if (!rcdev)
if (driver.minor < 0) { return -ENOMEM;
pr_err("init_chrdev() failed.\n");
return -EIO; rcdev->input_phys = KBUILD_MODNAME "/input0";
} rcdev->input_id.bustype = BUS_HOST;
return 0; rcdev->input_id.vendor = 0x0001;
} rcdev->input_id.product = 0x0001;
rcdev->input_id.version = 0x0100;
static void drop_chrdev(void) rcdev->tx_ir = sir_tx_ir;
{ rcdev->allowed_protocols = RC_BIT_ALL_IR_DECODER;
lirc_unregister_driver(driver.minor); rcdev->map_name = RC_MAP_RC6_MCE;
rcdev->timeout = IR_DEFAULT_TIMEOUT;
rcdev->dev.parent = &sir_ir_dev->dev;
return devm_rc_register_device(&sir_ir_dev->dev, rcdev);
} }
/* SECTION: Hardware */ /* SECTION: Hardware */
...@@ -420,14 +262,15 @@ static void sir_timeout(unsigned long data) ...@@ -420,14 +262,15 @@ static void sir_timeout(unsigned long data)
/* determine 'virtual' pulse end: */ /* determine 'virtual' pulse end: */
pulse_end = min_t(unsigned long, pulse_end = min_t(unsigned long,
ktime_us_delta(last, last_intr_time), ktime_us_delta(last, last_intr_time),
PULSE_MASK); IR_MAX_DURATION);
dev_dbg(driver.dev, "timeout add %d for %lu usec\n", dev_dbg(&sir_ir_dev->dev, "timeout add %d for %lu usec\n",
last_value, pulse_end); last_value, pulse_end);
add_read_queue(last_value, pulse_end); add_read_queue(last_value, pulse_end);
last_value = 0; last_value = 0;
last = last_intr_time; last = last_intr_time;
} }
spin_unlock_irqrestore(&timer_lock, flags); spin_unlock_irqrestore(&timer_lock, flags);
ir_raw_event_handle(rcdev);
} }
static irqreturn_t sir_interrupt(int irq, void *dev_id) static irqreturn_t sir_interrupt(int irq, void *dev_id)
...@@ -462,20 +305,20 @@ static irqreturn_t sir_interrupt(int irq, void *dev_id) ...@@ -462,20 +305,20 @@ static irqreturn_t sir_interrupt(int irq, void *dev_id)
curr_time = ktime_get(); curr_time = ktime_get();
delt = min_t(unsigned long, delt = min_t(unsigned long,
ktime_us_delta(last, curr_time), ktime_us_delta(last, curr_time),
PULSE_MASK); IR_MAX_DURATION);
deltintr = min_t(unsigned long, deltintr = min_t(unsigned long,
ktime_us_delta(last_intr_time, ktime_us_delta(last_intr_time,
curr_time), curr_time),
PULSE_MASK); IR_MAX_DURATION);
dev_dbg(driver.dev, "t %lu, d %d\n", dev_dbg(&sir_ir_dev->dev, "t %lu, d %d\n",
deltintr, (int)data); deltintr, (int)data);
/* /*
* if nothing came in last X cycles, * if nothing came in last X cycles,
* it was gap * it was gap
*/ */
if (deltintr > TIME_CONST * threshold) { if (deltintr > TIME_CONST * threshold) {
if (last_value) { if (last_value) {
dev_dbg(driver.dev, "GAP\n"); dev_dbg(&sir_ir_dev->dev, "GAP\n");
/* simulate signal change */ /* simulate signal change */
add_read_queue(last_value, add_read_queue(last_value,
delt - delt -
...@@ -517,6 +360,7 @@ static irqreturn_t sir_interrupt(int irq, void *dev_id) ...@@ -517,6 +360,7 @@ static irqreturn_t sir_interrupt(int irq, void *dev_id)
break; break;
} }
} }
ir_raw_event_handle(rcdev);
return IRQ_RETVAL(IRQ_HANDLED); return IRQ_RETVAL(IRQ_HANDLED);
} }
...@@ -655,12 +499,12 @@ static int init_port(void) ...@@ -655,12 +499,12 @@ static int init_port(void)
int retval; int retval;
/* get I/O port access and IRQ line */ /* get I/O port access and IRQ line */
if (request_region(io, 8, LIRC_DRIVER_NAME) == NULL) { if (!request_region(io, 8, KBUILD_MODNAME)) {
pr_err("i/o port 0x%.4x already in use.\n", io); pr_err("i/o port 0x%.4x already in use.\n", io);
return -EBUSY; return -EBUSY;
} }
retval = request_irq(irq, sir_interrupt, 0, retval = request_irq(irq, sir_interrupt, 0,
LIRC_DRIVER_NAME, NULL); KBUILD_MODNAME, NULL);
if (retval < 0) { if (retval < 0) {
release_region(io, 8); release_region(io, 8);
pr_err("IRQ %d already in use.\n", irq); pr_err("IRQ %d already in use.\n", irq);
...@@ -882,11 +726,10 @@ void init_act220(void) ...@@ -882,11 +726,10 @@ void init_act220(void)
} }
#endif #endif
static int init_lirc_sir(void) static int init_sir_ir(void)
{ {
int retval; int retval;
init_waitqueue_head(&lirc_read_queue);
retval = init_port(); retval = init_port();
if (retval < 0) if (retval < 0)
return retval; return retval;
...@@ -895,42 +738,42 @@ static int init_lirc_sir(void) ...@@ -895,42 +738,42 @@ static int init_lirc_sir(void)
return 0; return 0;
} }
static int lirc_sir_probe(struct platform_device *dev) static int sir_ir_probe(struct platform_device *dev)
{ {
return 0; return 0;
} }
static int lirc_sir_remove(struct platform_device *dev) static int sir_ir_remove(struct platform_device *dev)
{ {
return 0; return 0;
} }
static struct platform_driver lirc_sir_driver = { static struct platform_driver sir_ir_driver = {
.probe = lirc_sir_probe, .probe = sir_ir_probe,
.remove = lirc_sir_remove, .remove = sir_ir_remove,
.driver = { .driver = {
.name = "lirc_sir", .name = "sir_ir",
}, },
}; };
static int __init lirc_sir_init(void) static int __init sir_ir_init(void)
{ {
int retval; int retval;
retval = platform_driver_register(&lirc_sir_driver); retval = platform_driver_register(&sir_ir_driver);
if (retval) { if (retval) {
pr_err("Platform driver register failed!\n"); pr_err("Platform driver register failed!\n");
return -ENODEV; return -ENODEV;
} }
lirc_sir_dev = platform_device_alloc("lirc_dev", 0); sir_ir_dev = platform_device_alloc("sir_ir", 0);
if (!lirc_sir_dev) { if (!sir_ir_dev) {
pr_err("Platform device alloc failed!\n"); pr_err("Platform device alloc failed!\n");
retval = -ENOMEM; retval = -ENOMEM;
goto pdev_alloc_fail; goto pdev_alloc_fail;
} }
retval = platform_device_add(lirc_sir_dev); retval = platform_device_add(sir_ir_dev);
if (retval) { if (retval) {
pr_err("Platform device add failed!\n"); pr_err("Platform device add failed!\n");
retval = -ENODEV; retval = -ENODEV;
...@@ -941,35 +784,32 @@ static int __init lirc_sir_init(void) ...@@ -941,35 +784,32 @@ static int __init lirc_sir_init(void)
if (retval < 0) if (retval < 0)
goto fail; goto fail;
retval = init_lirc_sir(); retval = init_sir_ir();
if (retval) { if (retval)
drop_chrdev();
goto fail; goto fail;
}
return 0; return 0;
fail: fail:
platform_device_del(lirc_sir_dev); platform_device_del(sir_ir_dev);
pdev_add_fail: pdev_add_fail:
platform_device_put(lirc_sir_dev); platform_device_put(sir_ir_dev);
pdev_alloc_fail: pdev_alloc_fail:
platform_driver_unregister(&lirc_sir_driver); platform_driver_unregister(&sir_ir_driver);
return retval; return retval;
} }
static void __exit lirc_sir_exit(void) static void __exit sir_ir_exit(void)
{ {
drop_hardware(); drop_hardware();
drop_chrdev();
drop_port(); drop_port();
platform_device_unregister(lirc_sir_dev); platform_device_unregister(sir_ir_dev);
platform_driver_unregister(&lirc_sir_driver); platform_driver_unregister(&sir_ir_driver);
pr_info("Uninstalled.\n"); pr_info("Uninstalled.\n");
} }
module_init(lirc_sir_init); module_init(sir_ir_init);
module_exit(lirc_sir_exit); module_exit(sir_ir_exit);
#ifdef LIRC_SIR_TEKRAM #ifdef LIRC_SIR_TEKRAM
MODULE_DESCRIPTION("Infrared receiver driver for Tekram Irmate 210"); MODULE_DESCRIPTION("Infrared receiver driver for Tekram Irmate 210");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment