]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/media/usb/cx231xx/cx231xx-input.c
[media] rc-core: remove protocol arrays
[mirror_ubuntu-artful-kernel.git] / drivers / media / usb / cx231xx / cx231xx-input.c
CommitLineData
9ab66912
MCC
1/*
2 * cx231xx IR glue driver
3 *
37e59f87 4 * Copyright (C) 2010 Mauro Carvalho Chehab
9ab66912
MCC
5 *
6 * Polaris (cx231xx) has its support for IR's with a design close to MCE.
7 * however, a few designs are using an external I2C chip for IR, instead
8 * of using the one provided by the chip.
9 * This driver provides support for those extra devices
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation version 2.
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 GNU
18 * General Public License for more details.
19 */
20
21#include "cx231xx.h"
22#include <linux/usb.h>
23#include <linux/slab.h>
4dd9bb91 24#include <linux/bitrev.h>
9ab66912
MCC
25
26#define MODULE_NAME "cx231xx-input"
27
4dd9bb91
DH
28static int get_key_isdbt(struct IR_i2c *ir, enum rc_type *protocol,
29 u32 *pscancode, u8 *toggle)
9ab66912 30{
90bf3aab 31 int rc;
e330289e 32 u8 cmd, scancode;
9ab66912 33
141bb0dc
MCC
34 dev_dbg(&ir->rc->input_dev->dev, "%s\n", __func__);
35
9ab66912 36 /* poll IR chip */
90bf3aab
MCC
37 rc = i2c_master_recv(ir->c, &cmd, 1);
38 if (rc < 0)
39 return rc;
40 if (rc != 1)
9ab66912
MCC
41 return -EIO;
42
43 /* it seems that 0xFE indicates that a button is still hold
44 down, while 0xff indicates that no button is hold
45 down. 0xfe sequences are sometimes interrupted by 0xFF */
46
47 if (cmd == 0xff)
48 return 0;
49
4dd9bb91 50 scancode = bitrev8(cmd);
9ab66912 51
e330289e
MCC
52 dev_dbg(&ir->rc->input_dev->dev, "cmd %02x, scan = %02x\n",
53 cmd, scancode);
54
4dd9bb91
DH
55 *protocol = RC_TYPE_OTHER;
56 *pscancode = scancode;
57 *toggle = 0;
9ab66912
MCC
58 return 1;
59}
60
61int cx231xx_ir_init(struct cx231xx *dev)
62{
9ab66912 63 struct i2c_board_info info;
9ab66912
MCC
64 u8 ir_i2c_bus;
65
66 dev_dbg(&dev->udev->dev, "%s\n", __func__);
67
68 /* Only initialize if a rc keycode map is defined */
29e3ec19 69 if (!cx231xx_boards[dev->model].rc_map_name)
9ab66912
MCC
70 return -ENODEV;
71
9ab66912
MCC
72 request_module("ir-kbd-i2c");
73
74 memset(&info, 0, sizeof(struct i2c_board_info));
141bb0dc
MCC
75 memset(&dev->init_data, 0, sizeof(dev->init_data));
76 dev->init_data.rc_dev = rc_allocate_device();
77 if (!dev->init_data.rc_dev)
78 return -ENOMEM;
9ab66912 79
141bb0dc 80 dev->init_data.name = cx231xx_boards[dev->model].name;
9ab66912
MCC
81
82 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
141bb0dc 83 info.platform_data = &dev->init_data;
9ab66912
MCC
84
85 /*
86 * Board-dependent values
87 *
88 * For now, there's just one type of hardware design using
89 * an i2c device.
90 */
141bb0dc 91 dev->init_data.get_key = get_key_isdbt;
29e3ec19 92 dev->init_data.ir_codes = cx231xx_boards[dev->model].rc_map_name;
9ab66912 93 /* The i2c micro-controller only outputs the cmd part of NEC protocol */
141bb0dc
MCC
94 dev->init_data.rc_dev->scanmask = 0xff;
95 dev->init_data.rc_dev->driver_name = "cx231xx";
c003ab1b 96 dev->init_data.type = RC_BIT_NEC;
9ab66912
MCC
97 info.addr = 0x30;
98
9ab66912
MCC
99 /* Load and bind ir-kbd-i2c */
100 ir_i2c_bus = cx231xx_boards[dev->model].ir_i2c_master;
141bb0dc
MCC
101 dev_dbg(&dev->udev->dev, "Trying to bind ir at bus %d, addr 0x%02x\n",
102 ir_i2c_bus, info.addr);
7528cd27 103 dev->ir_i2c_client = i2c_new_device(&dev->i2c_bus[ir_i2c_bus].i2c_adap, &info);
9ab66912 104
141bb0dc 105 return 0;
9ab66912
MCC
106}
107
108void cx231xx_ir_exit(struct cx231xx *dev)
109{
7528cd27
MCC
110 if (dev->ir_i2c_client)
111 i2c_unregister_device(dev->ir_i2c_client);
112 dev->ir_i2c_client = NULL;
9ab66912 113}