Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 1 | /* |
| 2 | * cx231xx IR glue driver |
| 3 | * |
Mauro Carvalho Chehab | 37e59f8 | 2014-02-07 08:03:07 -0200 | [diff] [blame] | 4 | * Copyright (C) 2010 Mauro Carvalho Chehab |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 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" |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 22 | #include <linux/slab.h> |
David Härdeman | 4dd9bb9 | 2014-04-03 20:31:25 -0300 | [diff] [blame] | 23 | #include <linux/bitrev.h> |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 24 | |
| 25 | #define MODULE_NAME "cx231xx-input" |
| 26 | |
David Härdeman | 4dd9bb9 | 2014-04-03 20:31:25 -0300 | [diff] [blame] | 27 | static int get_key_isdbt(struct IR_i2c *ir, enum rc_type *protocol, |
| 28 | u32 *pscancode, u8 *toggle) |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 29 | { |
Mauro Carvalho Chehab | 90bf3aa | 2012-01-09 22:28:13 -0200 | [diff] [blame] | 30 | int rc; |
Mauro Carvalho Chehab | e330289 | 2010-12-17 14:22:09 -0300 | [diff] [blame] | 31 | u8 cmd, scancode; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 32 | |
Mauro Carvalho Chehab | 141bb0d | 2010-11-11 08:14:16 -0300 | [diff] [blame] | 33 | dev_dbg(&ir->rc->input_dev->dev, "%s\n", __func__); |
| 34 | |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 35 | /* poll IR chip */ |
Mauro Carvalho Chehab | 90bf3aa | 2012-01-09 22:28:13 -0200 | [diff] [blame] | 36 | rc = i2c_master_recv(ir->c, &cmd, 1); |
| 37 | if (rc < 0) |
| 38 | return rc; |
| 39 | if (rc != 1) |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 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 | |
David Härdeman | 4dd9bb9 | 2014-04-03 20:31:25 -0300 | [diff] [blame] | 49 | scancode = bitrev8(cmd); |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 50 | |
Mauro Carvalho Chehab | e330289 | 2010-12-17 14:22:09 -0300 | [diff] [blame] | 51 | dev_dbg(&ir->rc->input_dev->dev, "cmd %02x, scan = %02x\n", |
| 52 | cmd, scancode); |
| 53 | |
David Härdeman | 4dd9bb9 | 2014-04-03 20:31:25 -0300 | [diff] [blame] | 54 | *protocol = RC_TYPE_OTHER; |
| 55 | *pscancode = scancode; |
| 56 | *toggle = 0; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 57 | return 1; |
| 58 | } |
| 59 | |
| 60 | int cx231xx_ir_init(struct cx231xx *dev) |
| 61 | { |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 62 | struct i2c_board_info info; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 63 | u8 ir_i2c_bus; |
| 64 | |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 65 | dev_dbg(dev->dev, "%s\n", __func__); |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 66 | |
| 67 | /* Only initialize if a rc keycode map is defined */ |
Mauro Carvalho Chehab | 29e3ec1 | 2010-11-17 14:12:46 -0300 | [diff] [blame] | 68 | if (!cx231xx_boards[dev->model].rc_map_name) |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 69 | return -ENODEV; |
| 70 | |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 71 | request_module("ir-kbd-i2c"); |
| 72 | |
| 73 | memset(&info, 0, sizeof(struct i2c_board_info)); |
Mauro Carvalho Chehab | 141bb0d | 2010-11-11 08:14:16 -0300 | [diff] [blame] | 74 | memset(&dev->init_data, 0, sizeof(dev->init_data)); |
| 75 | dev->init_data.rc_dev = rc_allocate_device(); |
| 76 | if (!dev->init_data.rc_dev) |
| 77 | return -ENOMEM; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 78 | |
Mauro Carvalho Chehab | 141bb0d | 2010-11-11 08:14:16 -0300 | [diff] [blame] | 79 | dev->init_data.name = cx231xx_boards[dev->model].name; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 80 | |
| 81 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); |
Mauro Carvalho Chehab | 141bb0d | 2010-11-11 08:14:16 -0300 | [diff] [blame] | 82 | info.platform_data = &dev->init_data; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 83 | |
| 84 | /* |
| 85 | * Board-dependent values |
| 86 | * |
| 87 | * For now, there's just one type of hardware design using |
| 88 | * an i2c device. |
| 89 | */ |
Mauro Carvalho Chehab | 141bb0d | 2010-11-11 08:14:16 -0300 | [diff] [blame] | 90 | dev->init_data.get_key = get_key_isdbt; |
Mauro Carvalho Chehab | 29e3ec1 | 2010-11-17 14:12:46 -0300 | [diff] [blame] | 91 | 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] | 92 | /* The i2c micro-controller only outputs the cmd part of NEC protocol */ |
David Härdeman | 9d2f1d3 | 2014-04-03 20:32:26 -0300 | [diff] [blame] | 93 | dev->init_data.rc_dev->scancode_mask = 0xff; |
Mauro Carvalho Chehab | 141bb0d | 2010-11-11 08:14:16 -0300 | [diff] [blame] | 94 | dev->init_data.rc_dev->driver_name = "cx231xx"; |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 95 | dev->init_data.type = RC_BIT_NEC; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 96 | info.addr = 0x30; |
| 97 | |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 98 | /* Load and bind ir-kbd-i2c */ |
| 99 | ir_i2c_bus = cx231xx_boards[dev->model].ir_i2c_master; |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 100 | dev_dbg(dev->dev, "Trying to bind ir at bus %d, addr 0x%02x\n", |
Mauro Carvalho Chehab | 141bb0d | 2010-11-11 08:14:16 -0300 | [diff] [blame] | 101 | ir_i2c_bus, info.addr); |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 102 | dev->ir_i2c_client = i2c_new_device( |
| 103 | cx231xx_get_i2c_adap(dev, ir_i2c_bus), &info); |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 104 | |
Mauro Carvalho Chehab | 141bb0d | 2010-11-11 08:14:16 -0300 | [diff] [blame] | 105 | return 0; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void cx231xx_ir_exit(struct cx231xx *dev) |
| 109 | { |
Mauro Carvalho Chehab | 7528cd2 | 2012-01-10 09:20:01 -0200 | [diff] [blame] | 110 | if (dev->ir_i2c_client) |
| 111 | i2c_unregister_device(dev->ir_i2c_client); |
| 112 | dev->ir_i2c_client = NULL; |
Mauro Carvalho Chehab | 9ab6691 | 2010-10-23 13:28:33 -0300 | [diff] [blame] | 113 | } |