aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/rc
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2010-11-25 16:36:27 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-12-29 05:16:58 -0500
commit801c73c04ad57689dc9b47baf62cbb23f954d987 (patch)
tree38ecfa2b548e4aa6bb881971e7f23e43ac4a30d1 /drivers/media/rc
parentdea8a39fb569c23084c857ccdbf70a95ea3bf7dc (diff)
[media] rc-core: add loopback driver
This patch adds a loopback driver to rc-core which I've found useful for running scripted tests of different parts of rc-core without having to fiddle with real hardware. Basically it emulates hardware with a learning and a non-learning receiver and two transmitters (which correspond to the two receivers). TX data that is sent is fed back as input on the corresponding receiver, which allows for debugging of IR decoders, keymaps, etc. Signed-off-by: David Härdeman <david@hardeman.nu> Acked-by: Jarod Wilson <jarod@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/rc')
-rw-r--r--drivers/media/rc/Kconfig13
-rw-r--r--drivers/media/rc/Makefile1
-rw-r--r--drivers/media/rc/rc-loopback.c260
3 files changed, 274 insertions, 0 deletions
diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 42b4feb0e7f9..3785162f928e 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -177,4 +177,17 @@ config IR_WINBOND_CIR
177 To compile this driver as a module, choose M here: the module will 177 To compile this driver as a module, choose M here: the module will
178 be called winbond_cir. 178 be called winbond_cir.
179 179
180config RC_LOOPBACK
181 tristate "Remote Control Loopback Driver"
182 depends on RC_CORE
183 ---help---
184 Say Y here if you want support for the remote control loopback
185 driver which allows TX data to be sent back as RX data.
186 This is mostly useful for debugging purposes.
187
188 If you're not sure, select N here.
189
190 To compile this driver as a module, choose M here: the module will
191 be called rc_loopback.
192
180endif #RC_CORE 193endif #RC_CORE
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index 78ac8c5c8adc..67b4f7fe2577 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -19,3 +19,4 @@ obj-$(CONFIG_IR_NUVOTON) += nuvoton-cir.o
19obj-$(CONFIG_IR_ENE) += ene_ir.o 19obj-$(CONFIG_IR_ENE) += ene_ir.o
20obj-$(CONFIG_IR_STREAMZAP) += streamzap.o 20obj-$(CONFIG_IR_STREAMZAP) += streamzap.o
21obj-$(CONFIG_IR_WINBOND_CIR) += winbond-cir.o 21obj-$(CONFIG_IR_WINBOND_CIR) += winbond-cir.o
22obj-$(CONFIG_RC_LOOPBACK) += rc-loopback.o
diff --git a/drivers/media/rc/rc-loopback.c b/drivers/media/rc/rc-loopback.c
new file mode 100644
index 000000000000..49cee61d79c6
--- /dev/null
+++ b/drivers/media/rc/rc-loopback.c
@@ -0,0 +1,260 @@
1/*
2 * Loopback driver for rc-core,
3 *
4 * Copyright (c) 2010 David Härdeman <david@hardeman.nu>
5 *
6 * This driver receives TX data and passes it back as RX data,
7 * which is useful for (scripted) debugging of rc-core without
8 * having to use actual hardware.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26#include <linux/device.h>
27#include <linux/module.h>
28#include <linux/sched.h>
29#include <media/rc-core.h>
30
31#define DRIVER_NAME "rc-loopback"
32#define dprintk(x...) if (debug) printk(KERN_INFO DRIVER_NAME ": " x)
33#define RXMASK_REGULAR 0x1
34#define RXMASK_LEARNING 0x2
35
36static bool debug;
37
38struct loopback_dev {
39 struct rc_dev *dev;
40 u32 txmask;
41 u32 txcarrier;
42 u32 txduty;
43 bool idle;
44 bool learning;
45 bool carrierreport;
46 u32 rxcarriermin;
47 u32 rxcarriermax;
48};
49
50static struct loopback_dev loopdev;
51
52static int loop_set_tx_mask(struct rc_dev *dev, u32 mask)
53{
54 struct loopback_dev *lodev = dev->priv;
55
56 if ((mask & (RXMASK_REGULAR | RXMASK_LEARNING)) != mask) {
57 dprintk("invalid tx mask: %u\n", mask);
58 return -EINVAL;
59 }
60
61 dprintk("setting tx mask: %u\n", mask);
62 lodev->txmask = mask;
63 return 0;
64}
65
66static int loop_set_tx_carrier(struct rc_dev *dev, u32 carrier)
67{
68 struct loopback_dev *lodev = dev->priv;
69
70 dprintk("setting tx carrier: %u\n", carrier);
71 lodev->txcarrier = carrier;
72 return 0;
73}
74
75static int loop_set_tx_duty_cycle(struct rc_dev *dev, u32 duty_cycle)
76{
77 struct loopback_dev *lodev = dev->priv;
78
79 if (duty_cycle < 1 || duty_cycle > 99) {
80 dprintk("invalid duty cycle: %u\n", duty_cycle);
81 return -EINVAL;
82 }
83
84 dprintk("setting duty cycle: %u\n", duty_cycle);
85 lodev->txduty = duty_cycle;
86 return 0;
87}
88
89static int loop_set_rx_carrier_range(struct rc_dev *dev, u32 min, u32 max)
90{
91 struct loopback_dev *lodev = dev->priv;
92
93 if (min < 1 || min > max) {
94 dprintk("invalid rx carrier range %u to %u\n", min, max);
95 return -EINVAL;
96 }
97
98 dprintk("setting rx carrier range %u to %u\n", min, max);
99 lodev->rxcarriermin = min;
100 lodev->rxcarriermax = max;
101 return 0;
102}
103
104static int loop_tx_ir(struct rc_dev *dev, int *txbuf, u32 n)
105{
106 struct loopback_dev *lodev = dev->priv;
107 u32 rxmask;
108 unsigned count;
109 unsigned total_duration = 0;
110 unsigned i;
111 DEFINE_IR_RAW_EVENT(rawir);
112
113 if (n == 0 || n % sizeof(int)) {
114 dprintk("invalid tx buffer size\n");
115 return -EINVAL;
116 }
117
118 count = n / sizeof(int);
119 for (i = 0; i < count; i++)
120 total_duration += abs(txbuf[i]);
121
122 if (total_duration == 0) {
123 dprintk("invalid tx data, total duration zero\n");
124 return -EINVAL;
125 }
126
127 if (lodev->txcarrier < lodev->rxcarriermin ||
128 lodev->txcarrier > lodev->rxcarriermax) {
129 dprintk("ignoring tx, carrier out of range\n");
130 goto out;
131 }
132
133 if (lodev->learning)
134 rxmask = RXMASK_LEARNING;
135 else
136 rxmask = RXMASK_REGULAR;
137
138 if (!(rxmask & lodev->txmask)) {
139 dprintk("ignoring tx, rx mask mismatch\n");
140 goto out;
141 }
142
143 for (i = 0; i < count; i++) {
144 rawir.pulse = i % 2 ? false : true;
145 rawir.duration = abs(txbuf[i]) * 1000;
146 if (rawir.duration)
147 ir_raw_event_store_with_filter(dev, &rawir);
148 }
149 ir_raw_event_handle(dev);
150
151out:
152 /* Lirc expects this function to take as long as the total duration */
153 set_current_state(TASK_INTERRUPTIBLE);
154 schedule_timeout(usecs_to_jiffies(total_duration));
155 return n;
156}
157
158static void loop_set_idle(struct rc_dev *dev, bool enable)
159{
160 struct loopback_dev *lodev = dev->priv;
161
162 if (lodev->idle != enable) {
163 dprintk("%sing idle mode\n", enable ? "enter" : "exit");
164 lodev->idle = enable;
165 }
166}
167
168static int loop_set_learning_mode(struct rc_dev *dev, int enable)
169{
170 struct loopback_dev *lodev = dev->priv;
171
172 if (lodev->learning != enable) {
173 dprintk("%sing learning mode\n", enable ? "enter" : "exit");
174 lodev->learning = !!enable;
175 }
176
177 return 0;
178}
179
180static int loop_set_carrier_report(struct rc_dev *dev, int enable)
181{
182 struct loopback_dev *lodev = dev->priv;
183
184 if (lodev->carrierreport != enable) {
185 dprintk("%sabling carrier reports\n", enable ? "en" : "dis");
186 lodev->carrierreport = !!enable;
187 }
188
189 return 0;
190}
191
192static int __init loop_init(void)
193{
194 struct rc_dev *rc;
195 int ret;
196
197 rc = rc_allocate_device();
198 if (!rc) {
199 printk(KERN_ERR DRIVER_NAME ": rc_dev allocation failed\n");
200 return -ENOMEM;
201 }
202
203 rc->input_name = "rc-core loopback device";
204 rc->input_phys = "rc-core/virtual";
205 rc->input_id.bustype = BUS_VIRTUAL;
206 rc->input_id.version = 1;
207 rc->driver_name = DRIVER_NAME;
208 rc->map_name = RC_MAP_EMPTY;
209 rc->priv = &loopdev;
210 rc->driver_type = RC_DRIVER_IR_RAW;
211 rc->allowed_protos = RC_TYPE_ALL;
212 rc->timeout = 100 * 1000 * 1000; /* 100 ms */
213 rc->min_timeout = 1;
214 rc->max_timeout = UINT_MAX;
215 rc->rx_resolution = 1000;
216 rc->tx_resolution = 1000;
217 rc->s_tx_mask = loop_set_tx_mask;
218 rc->s_tx_carrier = loop_set_tx_carrier;
219 rc->s_tx_duty_cycle = loop_set_tx_duty_cycle;
220 rc->s_rx_carrier_range = loop_set_rx_carrier_range;
221 rc->tx_ir = loop_tx_ir;
222 rc->s_idle = loop_set_idle;
223 rc->s_learning_mode = loop_set_learning_mode;
224 rc->s_carrier_report = loop_set_carrier_report;
225 rc->priv = &loopdev;
226
227 loopdev.txmask = RXMASK_REGULAR;
228 loopdev.txcarrier = 36000;
229 loopdev.txduty = 50;
230 loopdev.rxcarriermin = 1;
231 loopdev.rxcarriermax = ~0;
232 loopdev.idle = true;
233 loopdev.learning = false;
234 loopdev.carrierreport = false;
235
236 ret = rc_register_device(rc);
237 if (ret < 0) {
238 printk(KERN_ERR DRIVER_NAME ": rc_dev registration failed\n");
239 rc_free_device(rc);
240 return ret;
241 }
242
243 loopdev.dev = rc;
244 return 0;
245}
246
247static void __exit loop_exit(void)
248{
249 rc_unregister_device(loopdev.dev);
250}
251
252module_init(loop_init);
253module_exit(loop_exit);
254
255module_param(debug, bool, S_IRUGO | S_IWUSR);
256MODULE_PARM_DESC(debug, "Enable debug messages");
257
258MODULE_DESCRIPTION("Loopback device for rc-core debugging");
259MODULE_AUTHOR("David Härdeman <david@hardeman.nu>");
260MODULE_LICENSE("GPL");