1
2
3
4
5
6
7
8
9
10
11#include "cx231xx.h"
12#include <linux/slab.h>
13#include <linux/bitrev.h>
14
15#define MODULE_NAME "cx231xx-input"
16
17static int get_key_isdbt(struct IR_i2c *ir, enum rc_proto *protocol,
18 u32 *pscancode, u8 *toggle)
19{
20 int rc;
21 u8 cmd, scancode;
22
23 dev_dbg(&ir->rc->dev, "%s\n", __func__);
24
25
26 rc = i2c_master_recv(ir->c, &cmd, 1);
27 if (rc < 0)
28 return rc;
29 if (rc != 1)
30 return -EIO;
31
32
33
34
35
36 if (cmd == 0xff)
37 return 0;
38
39 scancode = bitrev8(cmd);
40
41 dev_dbg(&ir->rc->dev, "cmd %02x, scan = %02x\n", cmd, scancode);
42
43 *protocol = RC_PROTO_OTHER;
44 *pscancode = scancode;
45 *toggle = 0;
46 return 1;
47}
48
49int cx231xx_ir_init(struct cx231xx *dev)
50{
51 struct i2c_board_info info;
52 u8 ir_i2c_bus;
53
54 dev_dbg(dev->dev, "%s\n", __func__);
55
56
57 if (!cx231xx_boards[dev->model].rc_map_name)
58 return -ENODEV;
59
60 request_module("ir-kbd-i2c");
61
62 memset(&info, 0, sizeof(struct i2c_board_info));
63 memset(&dev->init_data, 0, sizeof(dev->init_data));
64 dev->init_data.rc_dev = rc_allocate_device(RC_DRIVER_SCANCODE);
65 if (!dev->init_data.rc_dev)
66 return -ENOMEM;
67
68 dev->init_data.name = cx231xx_boards[dev->model].name;
69
70 strscpy(info.type, "ir_video", I2C_NAME_SIZE);
71 info.platform_data = &dev->init_data;
72
73
74
75
76
77
78
79 dev->init_data.get_key = get_key_isdbt;
80 dev->init_data.ir_codes = cx231xx_boards[dev->model].rc_map_name;
81
82 dev->init_data.rc_dev->scancode_mask = 0xff;
83 dev->init_data.rc_dev->driver_name = "cx231xx";
84 dev->init_data.type = RC_PROTO_BIT_NEC;
85 info.addr = 0x30;
86
87
88 ir_i2c_bus = cx231xx_boards[dev->model].ir_i2c_master;
89 dev_dbg(dev->dev, "Trying to bind ir at bus %d, addr 0x%02x\n",
90 ir_i2c_bus, info.addr);
91 dev->ir_i2c_client = i2c_new_device(
92 cx231xx_get_i2c_adap(dev, ir_i2c_bus), &info);
93
94 return 0;
95}
96
97void cx231xx_ir_exit(struct cx231xx *dev)
98{
99 if (dev->ir_i2c_client)
100 i2c_unregister_device(dev->ir_i2c_client);
101 dev->ir_i2c_client = NULL;
102}
103