]>
Commit | Line | Data |
---|---|---|
9ab66912 MCC |
1 | /* |
2 | * cx231xx IR glue driver | |
3 | * | |
4 | * Copyright (C) 2010 Mauro Carvalho Chehab <mchehab@redhat.com> | |
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> | |
24 | ||
25 | #define MODULE_NAME "cx231xx-input" | |
26 | ||
27 | static int get_key_isdbt(struct IR_i2c *ir, u32 *ir_key, | |
28 | u32 *ir_raw) | |
29 | { | |
90bf3aab | 30 | int rc; |
e330289e | 31 | u8 cmd, scancode; |
9ab66912 | 32 | |
141bb0dc MCC |
33 | dev_dbg(&ir->rc->input_dev->dev, "%s\n", __func__); |
34 | ||
9ab66912 | 35 | /* poll IR chip */ |
90bf3aab MCC |
36 | rc = i2c_master_recv(ir->c, &cmd, 1); |
37 | if (rc < 0) | |
38 | return rc; | |
39 | if (rc != 1) | |
9ab66912 MCC |
40 | return -EIO; |
41 | ||
42 | /* it seems that 0xFE indicates that a button is still hold | |
43 | down, while 0xff indicates that no button is hold | |
44 | down. 0xfe sequences are sometimes interrupted by 0xFF */ | |
45 | ||
46 | if (cmd == 0xff) | |
47 | return 0; | |
48 | ||
e330289e MCC |
49 | scancode = |
50 | ((cmd & 0x01) ? 0x80 : 0) | | |
51 | ((cmd & 0x02) ? 0x40 : 0) | | |
52 | ((cmd & 0x04) ? 0x20 : 0) | | |
53 | ((cmd & 0x08) ? 0x10 : 0) | | |
54 | ((cmd & 0x10) ? 0x08 : 0) | | |
55 | ((cmd & 0x20) ? 0x04 : 0) | | |
56 | ((cmd & 0x40) ? 0x02 : 0) | | |
57 | ((cmd & 0x80) ? 0x01 : 0); | |
9ab66912 | 58 | |
e330289e MCC |
59 | dev_dbg(&ir->rc->input_dev->dev, "cmd %02x, scan = %02x\n", |
60 | cmd, scancode); | |
61 | ||
62 | *ir_key = scancode; | |
63 | *ir_raw = scancode; | |
9ab66912 MCC |
64 | return 1; |
65 | } | |
66 | ||
67 | int cx231xx_ir_init(struct cx231xx *dev) | |
68 | { | |
9ab66912 | 69 | struct i2c_board_info info; |
9ab66912 MCC |
70 | u8 ir_i2c_bus; |
71 | ||
72 | dev_dbg(&dev->udev->dev, "%s\n", __func__); | |
73 | ||
74 | /* Only initialize if a rc keycode map is defined */ | |
29e3ec19 | 75 | if (!cx231xx_boards[dev->model].rc_map_name) |
9ab66912 MCC |
76 | return -ENODEV; |
77 | ||
9ab66912 MCC |
78 | request_module("ir-kbd-i2c"); |
79 | ||
80 | memset(&info, 0, sizeof(struct i2c_board_info)); | |
141bb0dc MCC |
81 | memset(&dev->init_data, 0, sizeof(dev->init_data)); |
82 | dev->init_data.rc_dev = rc_allocate_device(); | |
83 | if (!dev->init_data.rc_dev) | |
84 | return -ENOMEM; | |
9ab66912 | 85 | |
141bb0dc | 86 | dev->init_data.name = cx231xx_boards[dev->model].name; |
9ab66912 MCC |
87 | |
88 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); | |
141bb0dc | 89 | info.platform_data = &dev->init_data; |
9ab66912 MCC |
90 | |
91 | /* | |
92 | * Board-dependent values | |
93 | * | |
94 | * For now, there's just one type of hardware design using | |
95 | * an i2c device. | |
96 | */ | |
141bb0dc | 97 | dev->init_data.get_key = get_key_isdbt; |
29e3ec19 | 98 | dev->init_data.ir_codes = cx231xx_boards[dev->model].rc_map_name; |
9ab66912 | 99 | /* The i2c micro-controller only outputs the cmd part of NEC protocol */ |
141bb0dc MCC |
100 | dev->init_data.rc_dev->scanmask = 0xff; |
101 | dev->init_data.rc_dev->driver_name = "cx231xx"; | |
c003ab1b | 102 | dev->init_data.type = RC_BIT_NEC; |
9ab66912 MCC |
103 | info.addr = 0x30; |
104 | ||
9ab66912 MCC |
105 | /* Load and bind ir-kbd-i2c */ |
106 | ir_i2c_bus = cx231xx_boards[dev->model].ir_i2c_master; | |
141bb0dc MCC |
107 | dev_dbg(&dev->udev->dev, "Trying to bind ir at bus %d, addr 0x%02x\n", |
108 | ir_i2c_bus, info.addr); | |
7528cd27 | 109 | dev->ir_i2c_client = i2c_new_device(&dev->i2c_bus[ir_i2c_bus].i2c_adap, &info); |
9ab66912 | 110 | |
141bb0dc | 111 | return 0; |
9ab66912 MCC |
112 | } |
113 | ||
114 | void cx231xx_ir_exit(struct cx231xx *dev) | |
115 | { | |
7528cd27 MCC |
116 | if (dev->ir_i2c_client) |
117 | i2c_unregister_device(dev->ir_i2c_client); | |
118 | dev->ir_i2c_client = NULL; | |
9ab66912 | 119 | } |