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 | { | |
30 | u8 cmd; | |
31 | ||
32 | /* poll IR chip */ | |
33 | if (1 != i2c_master_recv(ir->c, &cmd, 1)) | |
34 | return -EIO; | |
35 | ||
36 | /* it seems that 0xFE indicates that a button is still hold | |
37 | down, while 0xff indicates that no button is hold | |
38 | down. 0xfe sequences are sometimes interrupted by 0xFF */ | |
39 | ||
40 | if (cmd == 0xff) | |
41 | return 0; | |
42 | ||
43 | dev_dbg(&ir->input->dev, "scancode = %02x\n", cmd); | |
44 | ||
45 | *ir_key = cmd; | |
46 | *ir_raw = cmd; | |
47 | return 1; | |
48 | } | |
49 | ||
50 | int cx231xx_ir_init(struct cx231xx *dev) | |
51 | { | |
52 | struct input_dev *input_dev; | |
53 | struct i2c_board_info info; | |
54 | int rc; | |
55 | u8 ir_i2c_bus; | |
56 | ||
57 | dev_dbg(&dev->udev->dev, "%s\n", __func__); | |
58 | ||
59 | /* Only initialize if a rc keycode map is defined */ | |
60 | if (!cx231xx_boards[dev->model].rc_map) | |
61 | return -ENODEV; | |
62 | ||
63 | input_dev = input_allocate_device(); | |
64 | if (!input_dev) | |
65 | return -ENOMEM; | |
66 | ||
67 | request_module("ir-kbd-i2c"); | |
68 | ||
69 | memset(&info, 0, sizeof(struct i2c_board_info)); | |
70 | memset(&dev->ir.init_data, 0, sizeof(dev->ir.init_data)); | |
71 | ||
72 | dev->ir.input_dev = input_dev; | |
73 | dev->ir.init_data.name = cx231xx_boards[dev->model].name; | |
74 | dev->ir.props.priv = dev; | |
75 | dev->ir.props.allowed_protos = IR_TYPE_NEC; | |
76 | snprintf(dev->ir.name, sizeof(dev->ir.name), | |
77 | "cx231xx IR (%s)", cx231xx_boards[dev->model].name); | |
78 | usb_make_path(dev->udev, dev->ir.phys, sizeof(dev->ir.phys)); | |
79 | strlcat(dev->ir.phys, "/input0", sizeof(dev->ir.phys)); | |
80 | ||
81 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); | |
82 | info.platform_data = &dev->ir.init_data; | |
83 | ||
84 | input_dev->name = dev->ir.name; | |
85 | input_dev->phys = dev->ir.phys; | |
86 | input_dev->dev.parent = &dev->udev->dev; | |
87 | input_dev->id.bustype = BUS_USB; | |
88 | input_dev->id.version = 1; | |
89 | input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); | |
90 | input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct); | |
91 | ||
92 | /* | |
93 | * Board-dependent values | |
94 | * | |
95 | * For now, there's just one type of hardware design using | |
96 | * an i2c device. | |
97 | */ | |
98 | dev->ir.init_data.get_key = get_key_isdbt; | |
99 | dev->ir.init_data.ir_codes = cx231xx_boards[dev->model].rc_map; | |
100 | /* The i2c micro-controller only outputs the cmd part of NEC protocol */ | |
101 | dev->ir.props.scanmask = 0xff; | |
102 | info.addr = 0x30; | |
103 | ||
104 | rc = ir_input_register(input_dev, cx231xx_boards[dev->model].rc_map, | |
105 | &dev->ir.props, MODULE_NAME); | |
106 | if (rc < 0) | |
107 | return rc; | |
108 | ||
109 | /* Load and bind ir-kbd-i2c */ | |
110 | ir_i2c_bus = cx231xx_boards[dev->model].ir_i2c_master; | |
111 | i2c_new_device(&dev->i2c_bus[ir_i2c_bus].i2c_adap, &info); | |
112 | ||
113 | return rc; | |
114 | } | |
115 | ||
116 | void cx231xx_ir_exit(struct cx231xx *dev) | |
117 | { | |
118 | if (dev->ir.input_dev) { | |
119 | ir_input_unregister(dev->ir.input_dev); | |
120 | dev->ir.input_dev = NULL; | |
121 | } | |
122 | } |