Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 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 | { |
Mauro Carvalho Chehab | e330289 | 2010-12-17 14:22:09 -0300 | [diff] [blame] | 30 | u8 cmd, scancode; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 31 | |
Mauro Carvalho Chehab | 141bb0d | 2010-11-11 08:14:16 -0300 | [diff] [blame] | 32 | dev_dbg(&ir->rc->input_dev->dev, "%s\n", __func__); |
| 33 | |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 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 | |
Mauro Carvalho Chehab | e330289 | 2010-12-17 14:22:09 -0300 | [diff] [blame] | 45 | scancode = |
| 46 | ((cmd & 0x01) ? 0x80 : 0) | |
| 47 | ((cmd & 0x02) ? 0x40 : 0) | |
| 48 | ((cmd & 0x04) ? 0x20 : 0) | |
| 49 | ((cmd & 0x08) ? 0x10 : 0) | |
| 50 | ((cmd & 0x10) ? 0x08 : 0) | |
| 51 | ((cmd & 0x20) ? 0x04 : 0) | |
| 52 | ((cmd & 0x40) ? 0x02 : 0) | |
| 53 | ((cmd & 0x80) ? 0x01 : 0); |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 54 | |
Mauro Carvalho Chehab | e330289 | 2010-12-17 14:22:09 -0300 | [diff] [blame] | 55 | dev_dbg(&ir->rc->input_dev->dev, "cmd %02x, scan = %02x\n", |
| 56 | cmd, scancode); |
| 57 | |
| 58 | *ir_key = scancode; |
| 59 | *ir_raw = scancode; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 60 | return 1; |
| 61 | } |
| 62 | |
| 63 | int cx231xx_ir_init(struct cx231xx *dev) |
| 64 | { |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 65 | struct i2c_board_info info; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 66 | u8 ir_i2c_bus; |
| 67 | |
| 68 | dev_dbg(&dev->udev->dev, "%s\n", __func__); |
| 69 | |
| 70 | /* Only initialize if a rc keycode map is defined */ |
Mauro Carvalho Chehab | 29e3ec1 | 2010-11-17 14:12:46 -0300 | [diff] [blame] | 71 | if (!cx231xx_boards[dev->model].rc_map_name) |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 72 | return -ENODEV; |
| 73 | |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 74 | request_module("ir-kbd-i2c"); |
| 75 | |
| 76 | memset(&info, 0, sizeof(struct i2c_board_info)); |
Mauro Carvalho Chehab | 141bb0d | 2010-11-11 08:14:16 -0300 | [diff] [blame] | 77 | memset(&dev->init_data, 0, sizeof(dev->init_data)); |
| 78 | dev->init_data.rc_dev = rc_allocate_device(); |
| 79 | if (!dev->init_data.rc_dev) |
| 80 | return -ENOMEM; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 81 | |
Mauro Carvalho Chehab | 141bb0d | 2010-11-11 08:14:16 -0300 | [diff] [blame] | 82 | dev->init_data.name = cx231xx_boards[dev->model].name; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 83 | |
| 84 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); |
Mauro Carvalho Chehab | 141bb0d | 2010-11-11 08:14:16 -0300 | [diff] [blame] | 85 | info.platform_data = &dev->init_data; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 86 | |
| 87 | /* |
| 88 | * Board-dependent values |
| 89 | * |
| 90 | * For now, there's just one type of hardware design using |
| 91 | * an i2c device. |
| 92 | */ |
Mauro Carvalho Chehab | 141bb0d | 2010-11-11 08:14:16 -0300 | [diff] [blame] | 93 | dev->init_data.get_key = get_key_isdbt; |
Mauro Carvalho Chehab | 29e3ec1 | 2010-11-17 14:12:46 -0300 | [diff] [blame] | 94 | dev->init_data.ir_codes = cx231xx_boards[dev->model].rc_map_name; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 95 | /* The i2c micro-controller only outputs the cmd part of NEC protocol */ |
Mauro Carvalho Chehab | 141bb0d | 2010-11-11 08:14:16 -0300 | [diff] [blame] | 96 | dev->init_data.rc_dev->scanmask = 0xff; |
| 97 | dev->init_data.rc_dev->driver_name = "cx231xx"; |
Mauro Carvalho Chehab | 52b6614 | 2010-11-17 14:20:52 -0300 | [diff] [blame] | 98 | dev->init_data.type = RC_TYPE_NEC; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 99 | info.addr = 0x30; |
| 100 | |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 101 | /* Load and bind ir-kbd-i2c */ |
| 102 | ir_i2c_bus = cx231xx_boards[dev->model].ir_i2c_master; |
Mauro Carvalho Chehab | 141bb0d | 2010-11-11 08:14:16 -0300 | [diff] [blame] | 103 | dev_dbg(&dev->udev->dev, "Trying to bind ir at bus %d, addr 0x%02x\n", |
| 104 | ir_i2c_bus, info.addr); |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 105 | i2c_new_device(&dev->i2c_bus[ir_i2c_bus].i2c_adap, &info); |
| 106 | |
Mauro Carvalho Chehab | 141bb0d | 2010-11-11 08:14:16 -0300 | [diff] [blame] | 107 | return 0; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | void cx231xx_ir_exit(struct cx231xx *dev) |
| 111 | { |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 112 | } |