]> git.karo-electronics.de Git - linux-beck.git/blob - drivers/media/video/cx231xx/cx231xx-input.c
[media] cx231xx: Fix i2c support at cx231xx-input
[linux-beck.git] / drivers / media / video / cx231xx / cx231xx-input.c
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         dev_dbg(&ir->rc->input_dev->dev, "%s\n", __func__);
33
34                 /* poll IR chip */
35         if (1 != i2c_master_recv(ir->c, &cmd, 1))
36                 return -EIO;
37
38         /* it seems that 0xFE indicates that a button is still hold
39            down, while 0xff indicates that no button is hold
40            down. 0xfe sequences are sometimes interrupted by 0xFF */
41
42         if (cmd == 0xff)
43                 return 0;
44
45         dev_dbg(&ir->rc->input_dev->dev, "scancode = %02x\n", cmd);
46
47         *ir_key = cmd;
48         *ir_raw = cmd;
49         return 1;
50 }
51
52 int cx231xx_ir_init(struct cx231xx *dev)
53 {
54         struct i2c_board_info info;
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         request_module("ir-kbd-i2c");
64
65         memset(&info, 0, sizeof(struct i2c_board_info));
66         memset(&dev->init_data, 0, sizeof(dev->init_data));
67         dev->init_data.rc_dev = rc_allocate_device();
68         if (!dev->init_data.rc_dev)
69                 return -ENOMEM;
70
71         dev->init_data.name = cx231xx_boards[dev->model].name;
72
73         strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
74         info.platform_data = &dev->init_data;
75
76         /*
77          * Board-dependent values
78          *
79          * For now, there's just one type of hardware design using
80          * an i2c device.
81          */
82         dev->init_data.get_key = get_key_isdbt;
83         dev->init_data.ir_codes = cx231xx_boards[dev->model].rc_map;
84         /* The i2c micro-controller only outputs the cmd part of NEC protocol */
85         dev->init_data.rc_dev->scanmask = 0xff;
86         dev->init_data.rc_dev->driver_name = "cx231xx";
87         dev->init_data.type = IR_TYPE_NEC;
88         info.addr = 0x30;
89
90         /* Load and bind ir-kbd-i2c */
91         ir_i2c_bus = cx231xx_boards[dev->model].ir_i2c_master;
92         dev_dbg(&dev->udev->dev, "Trying to bind ir at bus %d, addr 0x%02x\n",
93                 ir_i2c_bus, info.addr);
94         i2c_new_device(&dev->i2c_bus[ir_i2c_bus].i2c_adap, &info);
95
96         return 0;
97 }
98
99 void cx231xx_ir_exit(struct cx231xx *dev)
100 {
101 }