ipq806x: add support for GL.iNet GL-B1300
[openwrt/openwrt.git] / target / linux / mediatek / patches-4.9 / 0024-media-rc-add-driver-for-IR-remote-receiver-on-MT7623.patch
1 From 6e0336d1660725c06b6ab4f5361873538dbaa9f9 Mon Sep 17 00:00:00 2001
2 From: Sean Wang <sean.wang@mediatek.com>
3 Date: Fri, 13 Jan 2017 15:35:39 +0800
4 Subject: [PATCH 24/57] media: rc: add driver for IR remote receiver on MT7623
5 SoC
6
7 This patch adds driver for IR controller on MT7623 SoC.
8 and should also work on similar Mediatek SoC. Currently
9 testing successfully on NEC and SONY remote controller
10 only but it should work on others (lirc, rc-5 and rc-6).
11
12 Signed-off-by: Sean Wang <sean.wang@mediatek.com>
13 Reviewed-by: Sean Young <sean@mess.org>
14 ---
15 drivers/media/rc/Kconfig | 11 ++
16 drivers/media/rc/mtk-cir.c | 329 +++++++++++++++++++++++++++++++++++++++++++++
17 2 files changed, 340 insertions(+)
18 create mode 100644 drivers/media/rc/mtk-cir.c
19
20 --- a/drivers/media/rc/Kconfig
21 +++ b/drivers/media/rc/Kconfig
22 @@ -235,6 +235,17 @@ config IR_MESON
23 To compile this driver as a module, choose M here: the
24 module will be called meson-ir.
25
26 +config IR_MTK
27 + tristate "Mediatek IR remote receiver"
28 + depends on RC_CORE
29 + depends on ARCH_MEDIATEK || COMPILE_TEST
30 + ---help---
31 + Say Y if you want to use the IR remote receiver available
32 + on Mediatek SoCs.
33 +
34 + To compile this driver as a module, choose M here: the
35 + module will be called mtk-cir.
36 +
37 config IR_NUVOTON
38 tristate "Nuvoton w836x7hg Consumer Infrared Transceiver"
39 depends on PNP
40 --- /dev/null
41 +++ b/drivers/media/rc/mtk-cir.c
42 @@ -0,0 +1,329 @@
43 +/*
44 + * Driver for Mediatek IR Receiver Controller
45 + *
46 + * Copyright (C) 2017 Sean Wang <sean.wang@mediatek.com>
47 + *
48 + * This program is free software; you can redistribute it and/or
49 + * modify it under the terms of the GNU General Public License as
50 + * published by the Free Software Foundation; either version 2 of
51 + * the License, or (at your option) any later version.
52 + *
53 + * This program is distributed in the hope that it will be useful,
54 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
55 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56 + * GNU General Public License for more details.
57 + */
58 +
59 +#include <linux/clk.h>
60 +#include <linux/interrupt.h>
61 +#include <linux/module.h>
62 +#include <linux/of_platform.h>
63 +#include <linux/reset.h>
64 +#include <media/rc-core.h>
65 +
66 +#define MTK_IR_DEV KBUILD_MODNAME
67 +
68 +/* Register to enable PWM and IR */
69 +#define MTK_CONFIG_HIGH_REG 0x0c
70 +/* Enable IR pulse width detection */
71 +#define MTK_PWM_EN BIT(13)
72 +/* Enable IR hardware function */
73 +#define MTK_IR_EN BIT(0)
74 +
75 +/* Register to setting sample period */
76 +#define MTK_CONFIG_LOW_REG 0x10
77 +/* Field to set sample period */
78 +#define CHK_PERIOD DIV_ROUND_CLOSEST(MTK_IR_SAMPLE, \
79 + MTK_IR_CLK_PERIOD)
80 +#define MTK_CHK_PERIOD (((CHK_PERIOD) << 8) & (GENMASK(20, 8)))
81 +#define MTK_CHK_PERIOD_MASK (GENMASK(20, 8))
82 +
83 +/* Register to clear state of state machine */
84 +#define MTK_IRCLR_REG 0x20
85 +/* Bit to restart IR receiving */
86 +#define MTK_IRCLR BIT(0)
87 +
88 +/* Register containing pulse width data */
89 +#define MTK_CHKDATA_REG(i) (0x88 + 4 * (i))
90 +#define MTK_WIDTH_MASK (GENMASK(7, 0))
91 +
92 +/* Register to enable IR interrupt */
93 +#define MTK_IRINT_EN_REG 0xcc
94 +/* Bit to enable interrupt */
95 +#define MTK_IRINT_EN BIT(0)
96 +
97 +/* Register to ack IR interrupt */
98 +#define MTK_IRINT_CLR_REG 0xd0
99 +/* Bit to clear interrupt status */
100 +#define MTK_IRINT_CLR BIT(0)
101 +
102 +/* Maximum count of samples */
103 +#define MTK_MAX_SAMPLES 0xff
104 +/* Indicate the end of IR message */
105 +#define MTK_IR_END(v, p) ((v) == MTK_MAX_SAMPLES && (p) == 0)
106 +/* Number of registers to record the pulse width */
107 +#define MTK_CHKDATA_SZ 17
108 +/* Source clock frequency */
109 +#define MTK_IR_BASE_CLK 273000000
110 +/* Frequency after IR internal divider */
111 +#define MTK_IR_CLK_FREQ (MTK_IR_BASE_CLK / 4)
112 +/* Period for MTK_IR_CLK in ns*/
113 +#define MTK_IR_CLK_PERIOD DIV_ROUND_CLOSEST(1000000000ul, \
114 + MTK_IR_CLK_FREQ)
115 +/* Sample period in ns */
116 +#define MTK_IR_SAMPLE (MTK_IR_CLK_PERIOD * 0xc00)
117 +
118 +/* struct mtk_ir - This is the main datasructure for holding the state
119 + * of the driver
120 + * @dev: The device pointer
121 + * @rc: The rc instrance
122 + * @irq: The IRQ that we are using
123 + * @base: The mapped register i/o base
124 + * @clk: The clock that we are using
125 + */
126 +struct mtk_ir {
127 + struct device *dev;
128 + struct rc_dev *rc;
129 + void __iomem *base;
130 + int irq;
131 + struct clk *clk;
132 +};
133 +
134 +static void mtk_w32_mask(struct mtk_ir *ir, u32 val, u32 mask, unsigned int reg)
135 +{
136 + u32 tmp;
137 +
138 + tmp = __raw_readl(ir->base + reg);
139 + tmp = (tmp & ~mask) | val;
140 + __raw_writel(tmp, ir->base + reg);
141 +}
142 +
143 +static void mtk_w32(struct mtk_ir *ir, u32 val, unsigned int reg)
144 +{
145 + __raw_writel(val, ir->base + reg);
146 +}
147 +
148 +static u32 mtk_r32(struct mtk_ir *ir, unsigned int reg)
149 +{
150 + return __raw_readl(ir->base + reg);
151 +}
152 +
153 +static inline void mtk_irq_disable(struct mtk_ir *ir, u32 mask)
154 +{
155 + u32 val;
156 +
157 + val = mtk_r32(ir, MTK_IRINT_EN_REG);
158 + mtk_w32(ir, val & ~mask, MTK_IRINT_EN_REG);
159 +}
160 +
161 +static inline void mtk_irq_enable(struct mtk_ir *ir, u32 mask)
162 +{
163 + u32 val;
164 +
165 + val = mtk_r32(ir, MTK_IRINT_EN_REG);
166 + mtk_w32(ir, val | mask, MTK_IRINT_EN_REG);
167 +}
168 +
169 +static irqreturn_t mtk_ir_irq(int irqno, void *dev_id)
170 +{
171 + struct mtk_ir *ir = dev_id;
172 + u8 wid = 0;
173 + u32 i, j, val;
174 + DEFINE_IR_RAW_EVENT(rawir);
175 +
176 + /* Reset decoder state machine explicitly is required
177 + * because 1) the longest duration for space MTK IR hardware
178 + * could record is not safely long. e.g 12ms if rx resolution
179 + * is 46us by default. There is still the risk to satisfying
180 + * every decoder to reset themselves through long enough
181 + * trailing spaces and 2) the IRQ handler guarantees that
182 + * start of IR message is always contained in and starting
183 + * from register MTK_CHKDATA_REG(0).
184 + */
185 + ir_raw_event_reset(ir->rc);
186 +
187 + /* First message must be pulse */
188 + rawir.pulse = false;
189 +
190 + /* Handle all pulse and space IR controller captures */
191 + for (i = 0 ; i < MTK_CHKDATA_SZ ; i++) {
192 + val = mtk_r32(ir, MTK_CHKDATA_REG(i));
193 + dev_dbg(ir->dev, "@reg%d=0x%08x\n", i, val);
194 +
195 + for (j = 0 ; j < 4 ; j++) {
196 + wid = (val & (MTK_WIDTH_MASK << j * 8)) >> j * 8;
197 + rawir.pulse = !rawir.pulse;
198 + rawir.duration = wid * (MTK_IR_SAMPLE + 1);
199 + ir_raw_event_store_with_filter(ir->rc, &rawir);
200 + }
201 + }
202 +
203 + /* The maximum number of edges the IR controller can
204 + * hold is MTK_CHKDATA_SZ * 4. So if received IR messages
205 + * is over the limit, the last incomplete IR message would
206 + * be appended trailing space and still would be sent into
207 + * ir-rc-raw to decode. That helps it is possible that it
208 + * has enough information to decode a scancode even if the
209 + * trailing end of the message is missing.
210 + */
211 + if (!MTK_IR_END(wid, rawir.pulse)) {
212 + rawir.pulse = false;
213 + rawir.duration = MTK_MAX_SAMPLES * (MTK_IR_SAMPLE + 1);
214 + ir_raw_event_store_with_filter(ir->rc, &rawir);
215 + }
216 +
217 + ir_raw_event_handle(ir->rc);
218 +
219 + /* Restart controller for the next receive that would
220 + * clear up all CHKDATA registers
221 + */
222 + mtk_w32_mask(ir, 0x1, MTK_IRCLR, MTK_IRCLR_REG);
223 +
224 + /* Clear interrupt status */
225 + mtk_w32_mask(ir, 0x1, MTK_IRINT_CLR, MTK_IRINT_CLR_REG);
226 +
227 + return IRQ_HANDLED;
228 +}
229 +
230 +static int mtk_ir_probe(struct platform_device *pdev)
231 +{
232 + struct device *dev = &pdev->dev;
233 + struct device_node *dn = dev->of_node;
234 + struct resource *res;
235 + struct mtk_ir *ir;
236 + u32 val;
237 + int ret = 0;
238 + const char *map_name;
239 +
240 + ir = devm_kzalloc(dev, sizeof(struct mtk_ir), GFP_KERNEL);
241 + if (!ir)
242 + return -ENOMEM;
243 +
244 + ir->dev = dev;
245 +
246 + if (!of_device_is_compatible(dn, "mediatek,mt7623-cir"))
247 + return -ENODEV;
248 +
249 + ir->clk = devm_clk_get(dev, "clk");
250 + if (IS_ERR(ir->clk)) {
251 + dev_err(dev, "failed to get a ir clock.\n");
252 + return PTR_ERR(ir->clk);
253 + }
254 +
255 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
256 + ir->base = devm_ioremap_resource(dev, res);
257 + if (IS_ERR(ir->base)) {
258 + dev_err(dev, "failed to map registers\n");
259 + return PTR_ERR(ir->base);
260 + }
261 +
262 + ir->rc = devm_rc_allocate_device(dev, RC_DRIVER_IR_RAW);
263 + if (!ir->rc) {
264 + dev_err(dev, "failed to allocate device\n");
265 + return -ENOMEM;
266 + }
267 +
268 + ir->rc->priv = ir;
269 + ir->rc->input_name = MTK_IR_DEV;
270 + ir->rc->input_phys = MTK_IR_DEV "/input0";
271 + ir->rc->input_id.bustype = BUS_HOST;
272 + ir->rc->input_id.vendor = 0x0001;
273 + ir->rc->input_id.product = 0x0001;
274 + ir->rc->input_id.version = 0x0001;
275 + map_name = of_get_property(dn, "linux,rc-map-name", NULL);
276 + ir->rc->map_name = map_name ?: RC_MAP_EMPTY;
277 + ir->rc->dev.parent = dev;
278 + ir->rc->driver_name = MTK_IR_DEV;
279 + ir->rc->allowed_protocols = RC_BIT_ALL;
280 + ir->rc->rx_resolution = MTK_IR_SAMPLE;
281 + ir->rc->timeout = MTK_MAX_SAMPLES * (MTK_IR_SAMPLE + 1);
282 +
283 + ret = devm_rc_register_device(dev, ir->rc);
284 + if (ret) {
285 + dev_err(dev, "failed to register rc device\n");
286 + return ret;
287 + }
288 +
289 + platform_set_drvdata(pdev, ir);
290 +
291 + ir->irq = platform_get_irq(pdev, 0);
292 + if (ir->irq < 0) {
293 + dev_err(dev, "no irq resource\n");
294 + return -ENODEV;
295 + }
296 +
297 + /* Enable interrupt after proper hardware
298 + * setup and IRQ handler registration
299 + */
300 + if (clk_prepare_enable(ir->clk)) {
301 + dev_err(dev, "try to enable ir_clk failed\n");
302 + ret = -EINVAL;
303 + goto exit_clkdisable_clk;
304 + }
305 +
306 + mtk_irq_disable(ir, MTK_IRINT_EN);
307 +
308 + ret = devm_request_irq(dev, ir->irq, mtk_ir_irq, 0, MTK_IR_DEV, ir);
309 + if (ret) {
310 + dev_err(dev, "failed request irq\n");
311 + goto exit_clkdisable_clk;
312 + }
313 +
314 + /* Enable IR and PWM */
315 + val = mtk_r32(ir, MTK_CONFIG_HIGH_REG);
316 + val |= MTK_PWM_EN | MTK_IR_EN;
317 + mtk_w32(ir, val, MTK_CONFIG_HIGH_REG);
318 +
319 + /* Setting sample period */
320 + mtk_w32_mask(ir, MTK_CHK_PERIOD, MTK_CHK_PERIOD_MASK,
321 + MTK_CONFIG_LOW_REG);
322 +
323 + mtk_irq_enable(ir, MTK_IRINT_EN);
324 +
325 + dev_info(dev, "Initialized MT7623 IR driver, sample period = %luus\n",
326 + DIV_ROUND_CLOSEST(MTK_IR_SAMPLE, 1000));
327 +
328 + return 0;
329 +
330 +exit_clkdisable_clk:
331 + clk_disable_unprepare(ir->clk);
332 +
333 + return ret;
334 +}
335 +
336 +static int mtk_ir_remove(struct platform_device *pdev)
337 +{
338 + struct mtk_ir *ir = platform_get_drvdata(pdev);
339 +
340 + /* Avoid contention between remove handler and
341 + * IRQ handler so that disabling IR interrupt and
342 + * waiting for pending IRQ handler to complete
343 + */
344 + mtk_irq_disable(ir, MTK_IRINT_EN);
345 + synchronize_irq(ir->irq);
346 +
347 + clk_disable_unprepare(ir->clk);
348 +
349 + return 0;
350 +}
351 +
352 +static const struct of_device_id mtk_ir_match[] = {
353 + { .compatible = "mediatek,mt7623-cir" },
354 + {},
355 +};
356 +MODULE_DEVICE_TABLE(of, mtk_ir_match);
357 +
358 +static struct platform_driver mtk_ir_driver = {
359 + .probe = mtk_ir_probe,
360 + .remove = mtk_ir_remove,
361 + .driver = {
362 + .name = MTK_IR_DEV,
363 + .of_match_table = mtk_ir_match,
364 + },
365 +};
366 +
367 +module_platform_driver(mtk_ir_driver);
368 +
369 +MODULE_DESCRIPTION("Mediatek IR Receiver Controller Driver");
370 +MODULE_AUTHOR("Sean Wang <sean.wang@mediatek.com>");
371 +MODULE_LICENSE("GPL");
372 --- a/drivers/media/rc/Makefile
373 +++ b/drivers/media/rc/Makefile
374 @@ -37,3 +37,4 @@ obj-$(CONFIG_IR_TTUSBIR) += ttusbir.o
375 obj-$(CONFIG_RC_ST) += st_rc.o
376 obj-$(CONFIG_IR_SUNXI) += sunxi-cir.o
377 obj-$(CONFIG_IR_IMG) += img-ir/
378 +obj-$(CONFIG_IR_MTK) += mtk-cir.o
379 --- a/drivers/media/rc/rc-main.c
380 +++ b/drivers/media/rc/rc-main.c
381 @@ -1355,7 +1355,7 @@ static struct device_type rc_dev_type =
382 .uevent = rc_dev_uevent,
383 };
384
385 -struct rc_dev *rc_allocate_device(void)
386 +struct rc_dev *rc_allocate_device(enum rc_driver_type type)
387 {
388 struct rc_dev *dev;
389
390 @@ -1382,6 +1382,8 @@ struct rc_dev *rc_allocate_device(void)
391 dev->dev.class = &rc_class;
392 device_initialize(&dev->dev);
393
394 + dev->driver_type = type;
395 +
396 __module_get(THIS_MODULE);
397 return dev;
398 }
399 @@ -1403,6 +1405,35 @@ void rc_free_device(struct rc_dev *dev)
400 }
401 EXPORT_SYMBOL_GPL(rc_free_device);
402
403 +static void devm_rc_alloc_release(struct device *dev, void *res)
404 +{
405 + rc_free_device(*(struct rc_dev **)res);
406 +}
407 +
408 +struct rc_dev *devm_rc_allocate_device(struct device *dev,
409 + enum rc_driver_type type)
410 +{
411 + struct rc_dev **dr, *rc;
412 +
413 + dr = devres_alloc(devm_rc_alloc_release, sizeof(*dr), GFP_KERNEL);
414 + if (!dr)
415 + return NULL;
416 +
417 + rc = rc_allocate_device(type);
418 + if (!rc) {
419 + devres_free(dr);
420 + return NULL;
421 + }
422 +
423 + rc->dev.parent = dev;
424 + rc->managed_alloc = true;
425 + *dr = rc;
426 + devres_add(dev, dr);
427 +
428 + return rc;
429 +}
430 +EXPORT_SYMBOL_GPL(devm_rc_allocate_device);
431 +
432 int rc_register_device(struct rc_dev *dev)
433 {
434 static bool raw_init = false; /* raw decoders loaded? */
435 @@ -1536,6 +1567,33 @@ out_unlock:
436 }
437 EXPORT_SYMBOL_GPL(rc_register_device);
438
439 +static void devm_rc_release(struct device *dev, void *res)
440 +{
441 + rc_unregister_device(*(struct rc_dev **)res);
442 +}
443 +
444 +int devm_rc_register_device(struct device *parent, struct rc_dev *dev)
445 +{
446 + struct rc_dev **dr;
447 + int ret;
448 +
449 + dr = devres_alloc(devm_rc_release, sizeof(*dr), GFP_KERNEL);
450 + if (!dr)
451 + return -ENOMEM;
452 +
453 + ret = rc_register_device(dev);
454 + if (ret) {
455 + devres_free(dr);
456 + return ret;
457 + }
458 +
459 + *dr = dev;
460 + devres_add(parent, dr);
461 +
462 + return 0;
463 +}
464 +EXPORT_SYMBOL_GPL(devm_rc_register_device);
465 +
466 void rc_unregister_device(struct rc_dev *dev)
467 {
468 if (!dev)
469 @@ -1557,7 +1615,8 @@ void rc_unregister_device(struct rc_dev
470
471 ida_simple_remove(&rc_ida, dev->minor);
472
473 - rc_free_device(dev);
474 + if (!dev->managed_alloc)
475 + rc_free_device(dev);
476 }
477
478 EXPORT_SYMBOL_GPL(rc_unregister_device);
479 --- a/include/media/rc-core.h
480 +++ b/include/media/rc-core.h
481 @@ -68,6 +68,7 @@ enum rc_filter_type {
482 * struct rc_dev - represents a remote control device
483 * @dev: driver model's view of this device
484 * @initialized: 1 if the device init has completed, 0 otherwise
485 + * @managed_alloc: devm_rc_allocate_device was used to create rc_dev
486 * @sysfs_groups: sysfs attribute groups
487 * @input_name: name of the input child device
488 * @input_phys: physical path to the input child device
489 @@ -131,6 +132,7 @@ enum rc_filter_type {
490 struct rc_dev {
491 struct device dev;
492 atomic_t initialized;
493 + bool managed_alloc;
494 const struct attribute_group *sysfs_groups[5];
495 const char *input_name;
496 const char *input_phys;
497 @@ -198,9 +200,19 @@ struct rc_dev {
498 /**
499 * rc_allocate_device - Allocates a RC device
500 *
501 + * @rc_driver_type: specifies the type of the RC output to be allocated
502 * returns a pointer to struct rc_dev.
503 */
504 -struct rc_dev *rc_allocate_device(void);
505 +struct rc_dev *rc_allocate_device(enum rc_driver_type);
506 +
507 +/**
508 + * devm_rc_allocate_device - Managed RC device allocation
509 + *
510 + * @dev: pointer to struct device
511 + * @rc_driver_type: specifies the type of the RC output to be allocated
512 + * returns a pointer to struct rc_dev.
513 + */
514 +struct rc_dev *devm_rc_allocate_device(struct device *dev, enum rc_driver_type);
515
516 /**
517 * rc_free_device - Frees a RC device
518 @@ -217,6 +229,14 @@ void rc_free_device(struct rc_dev *dev);
519 int rc_register_device(struct rc_dev *dev);
520
521 /**
522 + * devm_rc_register_device - Manageded registering of a RC device
523 + *
524 + * @parent: pointer to struct device.
525 + * @dev: pointer to struct rc_dev.
526 + */
527 +int devm_rc_register_device(struct device *parent, struct rc_dev *dev);
528 +
529 +/**
530 * rc_unregister_device - Unregisters a RC device
531 *
532 * @dev: pointer to struct rc_dev.
533 --- a/drivers/media/common/siano/smsir.c
534 +++ b/drivers/media/common/siano/smsir.c
535 @@ -58,7 +58,7 @@ int sms_ir_init(struct smscore_device_t
536 struct rc_dev *dev;
537
538 pr_debug("Allocating rc device\n");
539 - dev = rc_allocate_device();
540 + dev = rc_allocate_device(RC_DRIVER_IR_RAW);
541 if (!dev)
542 return -ENOMEM;
543
544 --- a/drivers/media/i2c/ir-kbd-i2c.c
545 +++ b/drivers/media/i2c/ir-kbd-i2c.c
546 @@ -428,7 +428,7 @@ static int ir_probe(struct i2c_client *c
547 * If platform_data doesn't specify rc_dev, initialize it
548 * internally
549 */
550 - rc = rc_allocate_device();
551 + rc = rc_allocate_device(RC_DRIVER_SCANCODE);
552 if (!rc)
553 return -ENOMEM;
554 }
555 --- a/drivers/media/pci/bt8xx/bttv-input.c
556 +++ b/drivers/media/pci/bt8xx/bttv-input.c
557 @@ -424,7 +424,7 @@ int bttv_input_init(struct bttv *btv)
558 return -ENODEV;
559
560 ir = kzalloc(sizeof(*ir),GFP_KERNEL);
561 - rc = rc_allocate_device();
562 + rc = rc_allocate_device(RC_DRIVER_SCANCODE);
563 if (!ir || !rc)
564 goto err_out_free;
565
566 --- a/drivers/media/pci/cx23885/cx23885-input.c
567 +++ b/drivers/media/pci/cx23885/cx23885-input.c
568 @@ -267,7 +267,6 @@ int cx23885_input_init(struct cx23885_de
569 struct cx23885_kernel_ir *kernel_ir;
570 struct rc_dev *rc;
571 char *rc_map;
572 - enum rc_driver_type driver_type;
573 u64 allowed_protos;
574
575 int ret;
576 @@ -352,7 +351,7 @@ int cx23885_input_init(struct cx23885_de
577 pci_name(dev->pci));
578
579 /* input device */
580 - rc = rc_allocate_device();
581 + rc = rc_allocate_device(RC_DRIVER_IR_RAW);
582 if (!rc) {
583 ret = -ENOMEM;
584 goto err_out_free;
585 @@ -371,7 +370,6 @@ int cx23885_input_init(struct cx23885_de
586 rc->input_id.product = dev->pci->device;
587 }
588 rc->dev.parent = &dev->pci->dev;
589 - rc->driver_type = driver_type;
590 rc->allowed_protocols = allowed_protos;
591 rc->priv = kernel_ir;
592 rc->open = cx23885_input_ir_open;
593 --- a/drivers/media/pci/cx88/cx88-input.c
594 +++ b/drivers/media/pci/cx88/cx88-input.c
595 @@ -272,7 +272,7 @@ int cx88_ir_init(struct cx88_core *core,
596 */
597
598 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
599 - dev = rc_allocate_device();
600 + dev = rc_allocate_device(RC_DRIVER_IR_RAW);
601 if (!ir || !dev)
602 goto err_out_free;
603
604 @@ -482,7 +482,6 @@ int cx88_ir_init(struct cx88_core *core,
605 dev->scancode_mask = hardware_mask;
606
607 if (ir->sampling) {
608 - dev->driver_type = RC_DRIVER_IR_RAW;
609 dev->timeout = 10 * 1000 * 1000; /* 10 ms */
610 } else {
611 dev->driver_type = RC_DRIVER_SCANCODE;
612 --- a/drivers/media/pci/dm1105/dm1105.c
613 +++ b/drivers/media/pci/dm1105/dm1105.c
614 @@ -744,7 +744,7 @@ static int dm1105_ir_init(struct dm1105_
615 struct rc_dev *dev;
616 int err = -ENOMEM;
617
618 - dev = rc_allocate_device();
619 + dev = rc_allocate_device(RC_DRIVER_SCANCODE);
620 if (!dev)
621 return -ENOMEM;
622
623 @@ -753,7 +753,6 @@ static int dm1105_ir_init(struct dm1105_
624
625 dev->driver_name = MODULE_NAME;
626 dev->map_name = RC_MAP_DM1105_NEC;
627 - dev->driver_type = RC_DRIVER_SCANCODE;
628 dev->input_name = "DVB on-card IR receiver";
629 dev->input_phys = dm1105->ir.input_phys;
630 dev->input_id.bustype = BUS_PCI;
631 --- a/drivers/media/pci/mantis/mantis_input.c
632 +++ b/drivers/media/pci/mantis/mantis_input.c
633 @@ -39,7 +39,7 @@ int mantis_input_init(struct mantis_pci
634 struct rc_dev *dev;
635 int err;
636
637 - dev = rc_allocate_device();
638 + dev = rc_allocate_device(RC_DRIVER_SCANCODE);
639 if (!dev) {
640 dprintk(MANTIS_ERROR, 1, "Remote device allocation failed");
641 err = -ENOMEM;
642 --- a/drivers/media/pci/saa7134/saa7134-input.c
643 +++ b/drivers/media/pci/saa7134/saa7134-input.c
644 @@ -849,7 +849,7 @@ int saa7134_input_init1(struct saa7134_d
645 }
646
647 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
648 - rc = rc_allocate_device();
649 + rc = rc_allocate_device(RC_DRIVER_SCANCODE);
650 if (!ir || !rc) {
651 err = -ENOMEM;
652 goto err_out_free;
653 --- a/drivers/media/pci/smipcie/smipcie-ir.c
654 +++ b/drivers/media/pci/smipcie/smipcie-ir.c
655 @@ -183,7 +183,7 @@ int smi_ir_init(struct smi_dev *dev)
656 struct rc_dev *rc_dev;
657 struct smi_rc *ir = &dev->ir;
658
659 - rc_dev = rc_allocate_device();
660 + rc_dev = rc_allocate_device(RC_DRIVER_SCANCODE);
661 if (!rc_dev)
662 return -ENOMEM;
663
664 @@ -202,7 +202,6 @@ int smi_ir_init(struct smi_dev *dev)
665 rc_dev->input_id.product = dev->pci_dev->subsystem_device;
666 rc_dev->dev.parent = &dev->pci_dev->dev;
667
668 - rc_dev->driver_type = RC_DRIVER_SCANCODE;
669 rc_dev->map_name = dev->info->rc_map;
670
671 ir->rc_dev = rc_dev;
672 --- a/drivers/media/pci/ttpci/budget-ci.c
673 +++ b/drivers/media/pci/ttpci/budget-ci.c
674 @@ -177,7 +177,7 @@ static int msp430_ir_init(struct budget_
675 struct rc_dev *dev;
676 int error;
677
678 - dev = rc_allocate_device();
679 + dev = rc_allocate_device(RC_DRIVER_SCANCODE);
680 if (!dev) {
681 printk(KERN_ERR "budget_ci: IR interface initialisation failed\n");
682 return -ENOMEM;
683 --- a/drivers/media/rc/ati_remote.c
684 +++ b/drivers/media/rc/ati_remote.c
685 @@ -765,7 +765,6 @@ static void ati_remote_rc_init(struct at
686 struct rc_dev *rdev = ati_remote->rdev;
687
688 rdev->priv = ati_remote;
689 - rdev->driver_type = RC_DRIVER_SCANCODE;
690 rdev->allowed_protocols = RC_BIT_OTHER;
691 rdev->driver_name = "ati_remote";
692
693 @@ -852,7 +851,7 @@ static int ati_remote_probe(struct usb_i
694 }
695
696 ati_remote = kzalloc(sizeof (struct ati_remote), GFP_KERNEL);
697 - rc_dev = rc_allocate_device();
698 + rc_dev = rc_allocate_device(RC_DRIVER_SCANCODE);
699 if (!ati_remote || !rc_dev)
700 goto exit_free_dev_rdev;
701
702 --- a/drivers/media/rc/ene_ir.c
703 +++ b/drivers/media/rc/ene_ir.c
704 @@ -1012,7 +1012,7 @@ static int ene_probe(struct pnp_dev *pnp
705
706 /* allocate memory */
707 dev = kzalloc(sizeof(struct ene_device), GFP_KERNEL);
708 - rdev = rc_allocate_device();
709 + rdev = rc_allocate_device(RC_DRIVER_IR_RAW);
710 if (!dev || !rdev)
711 goto exit_free_dev_rdev;
712
713 --- a/drivers/media/rc/fintek-cir.c
714 +++ b/drivers/media/rc/fintek-cir.c
715 @@ -496,7 +496,7 @@ static int fintek_probe(struct pnp_dev *
716 return ret;
717
718 /* input device for IR remote (and tx) */
719 - rdev = rc_allocate_device();
720 + rdev = rc_allocate_device(RC_DRIVER_IR_RAW);
721 if (!rdev)
722 goto exit_free_dev_rdev;
723
724 --- a/drivers/media/rc/gpio-ir-recv.c
725 +++ b/drivers/media/rc/gpio-ir-recv.c
726 @@ -143,14 +143,13 @@ static int gpio_ir_recv_probe(struct pla
727 if (!gpio_dev)
728 return -ENOMEM;
729
730 - rcdev = rc_allocate_device();
731 + rcdev = rc_allocate_device(RC_DRIVER_IR_RAW);
732 if (!rcdev) {
733 rc = -ENOMEM;
734 goto err_allocate_device;
735 }
736
737 rcdev->priv = gpio_dev;
738 - rcdev->driver_type = RC_DRIVER_IR_RAW;
739 rcdev->input_name = GPIO_IR_DEVICE_NAME;
740 rcdev->input_phys = GPIO_IR_DEVICE_NAME "/input0";
741 rcdev->input_id.bustype = BUS_HOST;
742 --- a/drivers/media/rc/igorplugusb.c
743 +++ b/drivers/media/rc/igorplugusb.c
744 @@ -190,7 +190,7 @@ static int igorplugusb_probe(struct usb_
745
746 usb_make_path(udev, ir->phys, sizeof(ir->phys));
747
748 - rc = rc_allocate_device();
749 + rc = rc_allocate_device(RC_DRIVER_IR_RAW);
750 if (!rc)
751 goto fail;
752
753 @@ -198,7 +198,6 @@ static int igorplugusb_probe(struct usb_
754 rc->input_phys = ir->phys;
755 usb_to_input_id(udev, &rc->input_id);
756 rc->dev.parent = &intf->dev;
757 - rc->driver_type = RC_DRIVER_IR_RAW;
758 /*
759 * This device can only store 36 pulses + spaces, which is not enough
760 * for the NEC protocol and many others.
761 --- a/drivers/media/rc/iguanair.c
762 +++ b/drivers/media/rc/iguanair.c
763 @@ -431,7 +431,7 @@ static int iguanair_probe(struct usb_int
764 struct usb_host_interface *idesc;
765
766 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
767 - rc = rc_allocate_device();
768 + rc = rc_allocate_device(RC_DRIVER_IR_RAW);
769 if (!ir || !rc) {
770 ret = -ENOMEM;
771 goto out;
772 --- a/drivers/media/rc/img-ir/img-ir-hw.c
773 +++ b/drivers/media/rc/img-ir/img-ir-hw.c
774 @@ -1071,7 +1071,7 @@ int img_ir_probe_hw(struct img_ir_priv *
775 }
776
777 /* Allocate hardware decoder */
778 - hw->rdev = rdev = rc_allocate_device();
779 + hw->rdev = rdev = rc_allocate_device(RC_DRIVER_SCANCODE);
780 if (!rdev) {
781 dev_err(priv->dev, "cannot allocate input device\n");
782 error = -ENOMEM;
783 --- a/drivers/media/rc/img-ir/img-ir-raw.c
784 +++ b/drivers/media/rc/img-ir/img-ir-raw.c
785 @@ -110,7 +110,7 @@ int img_ir_probe_raw(struct img_ir_priv
786 setup_timer(&raw->timer, img_ir_echo_timer, (unsigned long)priv);
787
788 /* Allocate raw decoder */
789 - raw->rdev = rdev = rc_allocate_device();
790 + raw->rdev = rdev = rc_allocate_device(RC_DRIVER_IR_RAW);
791 if (!rdev) {
792 dev_err(priv->dev, "cannot allocate raw input device\n");
793 return -ENOMEM;
794 @@ -118,7 +118,6 @@ int img_ir_probe_raw(struct img_ir_priv
795 rdev->priv = priv;
796 rdev->map_name = RC_MAP_EMPTY;
797 rdev->input_name = "IMG Infrared Decoder Raw";
798 - rdev->driver_type = RC_DRIVER_IR_RAW;
799
800 /* Register raw decoder */
801 error = rc_register_device(rdev);
802 --- a/drivers/media/rc/imon.c
803 +++ b/drivers/media/rc/imon.c
804 @@ -1951,7 +1951,7 @@ static struct rc_dev *imon_init_rdev(str
805 const unsigned char fp_packet[] = { 0x40, 0x00, 0x00, 0x00,
806 0x00, 0x00, 0x00, 0x88 };
807
808 - rdev = rc_allocate_device();
809 + rdev = rc_allocate_device(RC_DRIVER_SCANCODE);
810 if (!rdev) {
811 dev_err(ictx->dev, "remote control dev allocation failed\n");
812 goto out;
813 @@ -1969,7 +1969,6 @@ static struct rc_dev *imon_init_rdev(str
814 rdev->dev.parent = ictx->dev;
815
816 rdev->priv = ictx;
817 - rdev->driver_type = RC_DRIVER_SCANCODE;
818 rdev->allowed_protocols = RC_BIT_OTHER | RC_BIT_RC6_MCE; /* iMON PAD or MCE */
819 rdev->change_protocol = imon_ir_change_protocol;
820 rdev->driver_name = MOD_NAME;
821 --- a/drivers/media/rc/ir-hix5hd2.c
822 +++ b/drivers/media/rc/ir-hix5hd2.c
823 @@ -222,7 +222,7 @@ static int hix5hd2_ir_probe(struct platf
824 return priv->irq;
825 }
826
827 - rdev = rc_allocate_device();
828 + rdev = rc_allocate_device(RC_DRIVER_IR_RAW);
829 if (!rdev)
830 return -ENOMEM;
831
832 --- a/drivers/media/rc/ite-cir.c
833 +++ b/drivers/media/rc/ite-cir.c
834 @@ -1472,7 +1472,7 @@ static int ite_probe(struct pnp_dev *pde
835 return ret;
836
837 /* input device for IR remote (and tx) */
838 - rdev = rc_allocate_device();
839 + rdev = rc_allocate_device(RC_DRIVER_IR_RAW);
840 if (!rdev)
841 goto exit_free_dev_rdev;
842 itdev->rdev = rdev;
843 --- a/drivers/media/rc/mceusb.c
844 +++ b/drivers/media/rc/mceusb.c
845 @@ -1220,7 +1220,7 @@ static struct rc_dev *mceusb_init_rc_dev
846 struct rc_dev *rc;
847 int ret;
848
849 - rc = rc_allocate_device();
850 + rc = rc_allocate_device(RC_DRIVER_IR_RAW);
851 if (!rc) {
852 dev_err(dev, "remote dev allocation failed");
853 goto out;
854 --- a/drivers/media/rc/meson-ir.c
855 +++ b/drivers/media/rc/meson-ir.c
856 @@ -131,7 +131,7 @@ static int meson_ir_probe(struct platfor
857 return ir->irq;
858 }
859
860 - ir->rc = rc_allocate_device();
861 + ir->rc = rc_allocate_device(RC_DRIVER_IR_RAW);
862 if (!ir->rc) {
863 dev_err(dev, "failed to allocate rc device\n");
864 return -ENOMEM;
865 --- a/drivers/media/rc/rc-loopback.c
866 +++ b/drivers/media/rc/rc-loopback.c
867 @@ -181,7 +181,7 @@ static int __init loop_init(void)
868 struct rc_dev *rc;
869 int ret;
870
871 - rc = rc_allocate_device();
872 + rc = rc_allocate_device(RC_DRIVER_IR_RAW);
873 if (!rc) {
874 printk(KERN_ERR DRIVER_NAME ": rc_dev allocation failed\n");
875 return -ENOMEM;
876 --- a/drivers/media/rc/st_rc.c
877 +++ b/drivers/media/rc/st_rc.c
878 @@ -235,7 +235,7 @@ static int st_rc_probe(struct platform_d
879 if (!rc_dev)
880 return -ENOMEM;
881
882 - rdev = rc_allocate_device();
883 + rdev = rc_allocate_device(RC_DRIVER_IR_RAW);
884
885 if (!rdev)
886 return -ENOMEM;
887 --- a/drivers/media/rc/streamzap.c
888 +++ b/drivers/media/rc/streamzap.c
889 @@ -291,7 +291,7 @@ static struct rc_dev *streamzap_init_rc_
890 struct device *dev = sz->dev;
891 int ret;
892
893 - rdev = rc_allocate_device();
894 + rdev = rc_allocate_device(RC_DRIVER_IR_RAW);
895 if (!rdev) {
896 dev_err(dev, "remote dev allocation failed\n");
897 goto out;
898 --- a/drivers/media/rc/sunxi-cir.c
899 +++ b/drivers/media/rc/sunxi-cir.c
900 @@ -212,7 +212,7 @@ static int sunxi_ir_probe(struct platfor
901 goto exit_clkdisable_clk;
902 }
903
904 - ir->rc = rc_allocate_device();
905 + ir->rc = rc_allocate_device(RC_DRIVER_IR_RAW);
906 if (!ir->rc) {
907 dev_err(dev, "failed to allocate device\n");
908 ret = -ENOMEM;
909 --- a/drivers/media/rc/ttusbir.c
910 +++ b/drivers/media/rc/ttusbir.c
911 @@ -205,7 +205,7 @@ static int ttusbir_probe(struct usb_inte
912 int altsetting = -1;
913
914 tt = kzalloc(sizeof(*tt), GFP_KERNEL);
915 - rc = rc_allocate_device();
916 + rc = rc_allocate_device(RC_DRIVER_IR_RAW);
917 if (!tt || !rc) {
918 ret = -ENOMEM;
919 goto out;
920 --- a/drivers/media/rc/winbond-cir.c
921 +++ b/drivers/media/rc/winbond-cir.c
922 @@ -1062,13 +1062,12 @@ wbcir_probe(struct pnp_dev *device, cons
923 if (err)
924 goto exit_free_data;
925
926 - data->dev = rc_allocate_device();
927 + data->dev = rc_allocate_device(RC_DRIVER_IR_RAW);
928 if (!data->dev) {
929 err = -ENOMEM;
930 goto exit_unregister_led;
931 }
932
933 - data->dev->driver_type = RC_DRIVER_IR_RAW;
934 data->dev->driver_name = DRVNAME;
935 data->dev->input_name = WBCIR_NAME;
936 data->dev->input_phys = "wbcir/cir0";
937 --- a/drivers/media/usb/au0828/au0828-input.c
938 +++ b/drivers/media/usb/au0828/au0828-input.c
939 @@ -298,7 +298,7 @@ int au0828_rc_register(struct au0828_dev
940 return -ENODEV;
941
942 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
943 - rc = rc_allocate_device();
944 + rc = rc_allocate_device(RC_DRIVER_IR_RAW);
945 if (!ir || !rc)
946 goto error;
947
948 @@ -343,7 +343,6 @@ int au0828_rc_register(struct au0828_dev
949 rc->input_id.product = le16_to_cpu(dev->usbdev->descriptor.idProduct);
950 rc->dev.parent = &dev->usbdev->dev;
951 rc->driver_name = "au0828-input";
952 - rc->driver_type = RC_DRIVER_IR_RAW;
953 rc->allowed_protocols = RC_BIT_NEC | RC_BIT_NECX | RC_BIT_NEC32 |
954 RC_BIT_RC5;
955
956 --- a/drivers/media/usb/cx231xx/cx231xx-input.c
957 +++ b/drivers/media/usb/cx231xx/cx231xx-input.c
958 @@ -72,7 +72,7 @@ int cx231xx_ir_init(struct cx231xx *dev)
959
960 memset(&info, 0, sizeof(struct i2c_board_info));
961 memset(&dev->init_data, 0, sizeof(dev->init_data));
962 - dev->init_data.rc_dev = rc_allocate_device();
963 + dev->init_data.rc_dev = rc_allocate_device(RC_DRIVER_SCANCODE);
964 if (!dev->init_data.rc_dev)
965 return -ENOMEM;
966
967 --- a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
968 +++ b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
969 @@ -147,7 +147,7 @@ static int dvb_usbv2_remote_init(struct
970 if (!d->rc.map_name)
971 return 0;
972
973 - dev = rc_allocate_device();
974 + dev = rc_allocate_device(d->rc.driver_type);
975 if (!dev) {
976 ret = -ENOMEM;
977 goto err;
978 @@ -162,7 +162,6 @@ static int dvb_usbv2_remote_init(struct
979 /* TODO: likely RC-core should took const char * */
980 dev->driver_name = (char *) d->props->driver_name;
981 dev->map_name = d->rc.map_name;
982 - dev->driver_type = d->rc.driver_type;
983 dev->allowed_protocols = d->rc.allowed_protos;
984 dev->change_protocol = d->rc.change_protocol;
985 dev->priv = d;
986 --- a/drivers/media/usb/dvb-usb/dvb-usb-remote.c
987 +++ b/drivers/media/usb/dvb-usb/dvb-usb-remote.c
988 @@ -265,7 +265,7 @@ static int rc_core_dvb_usb_remote_init(s
989 int err, rc_interval;
990 struct rc_dev *dev;
991
992 - dev = rc_allocate_device();
993 + dev = rc_allocate_device(d->props.rc.core.driver_type);
994 if (!dev)
995 return -ENOMEM;
996
997 @@ -273,7 +273,6 @@ static int rc_core_dvb_usb_remote_init(s
998 dev->map_name = d->props.rc.core.rc_codes;
999 dev->change_protocol = d->props.rc.core.change_protocol;
1000 dev->allowed_protocols = d->props.rc.core.allowed_protos;
1001 - dev->driver_type = d->props.rc.core.driver_type;
1002 usb_to_input_id(d->udev, &dev->input_id);
1003 dev->input_name = "IR-receiver inside an USB DVB receiver";
1004 dev->input_phys = d->rc_phys;
1005 --- a/drivers/media/usb/em28xx/em28xx-input.c
1006 +++ b/drivers/media/usb/em28xx/em28xx-input.c
1007 @@ -713,7 +713,7 @@ static int em28xx_ir_init(struct em28xx
1008 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
1009 if (!ir)
1010 return -ENOMEM;
1011 - rc = rc_allocate_device();
1012 + rc = rc_allocate_device(RC_DRIVER_SCANCODE);
1013 if (!rc)
1014 goto error;
1015
1016 --- a/drivers/media/usb/tm6000/tm6000-input.c
1017 +++ b/drivers/media/usb/tm6000/tm6000-input.c
1018 @@ -429,7 +429,7 @@ int tm6000_ir_init(struct tm6000_core *d
1019 return 0;
1020
1021 ir = kzalloc(sizeof(*ir), GFP_ATOMIC);
1022 - rc = rc_allocate_device();
1023 + rc = rc_allocate_device(RC_DRIVER_SCANCODE);
1024 if (!ir || !rc)
1025 goto out;
1026
1027 @@ -456,7 +456,6 @@ int tm6000_ir_init(struct tm6000_core *d
1028 ir->polling = 50;
1029 INIT_DELAYED_WORK(&ir->work, tm6000_ir_handle_key);
1030 }
1031 - rc->driver_type = RC_DRIVER_SCANCODE;
1032
1033 snprintf(ir->name, sizeof(ir->name), "tm5600/60x0 IR (%s)",
1034 dev->name);