Path: blob/master/drivers/media/video/cx231xx/cx231xx-input.c
17751 views
/*1* cx231xx IR glue driver2*3* Copyright (C) 2010 Mauro Carvalho Chehab <[email protected]>4*5* Polaris (cx231xx) has its support for IR's with a design close to MCE.6* however, a few designs are using an external I2C chip for IR, instead7* of using the one provided by the chip.8* This driver provides support for those extra devices9*10* This program is free software; you can redistribute it and/or11* modify it under the terms of the GNU General Public License as12* published by the Free Software Foundation version 2.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU17* General Public License for more details.18*/1920#include "cx231xx.h"21#include <linux/usb.h>22#include <linux/slab.h>2324#define MODULE_NAME "cx231xx-input"2526static int get_key_isdbt(struct IR_i2c *ir, u32 *ir_key,27u32 *ir_raw)28{29u8 cmd, scancode;3031dev_dbg(&ir->rc->input_dev->dev, "%s\n", __func__);3233/* poll IR chip */34if (1 != i2c_master_recv(ir->c, &cmd, 1))35return -EIO;3637/* it seems that 0xFE indicates that a button is still hold38down, while 0xff indicates that no button is hold39down. 0xfe sequences are sometimes interrupted by 0xFF */4041if (cmd == 0xff)42return 0;4344scancode =45((cmd & 0x01) ? 0x80 : 0) |46((cmd & 0x02) ? 0x40 : 0) |47((cmd & 0x04) ? 0x20 : 0) |48((cmd & 0x08) ? 0x10 : 0) |49((cmd & 0x10) ? 0x08 : 0) |50((cmd & 0x20) ? 0x04 : 0) |51((cmd & 0x40) ? 0x02 : 0) |52((cmd & 0x80) ? 0x01 : 0);5354dev_dbg(&ir->rc->input_dev->dev, "cmd %02x, scan = %02x\n",55cmd, scancode);5657*ir_key = scancode;58*ir_raw = scancode;59return 1;60}6162int cx231xx_ir_init(struct cx231xx *dev)63{64struct i2c_board_info info;65u8 ir_i2c_bus;6667dev_dbg(&dev->udev->dev, "%s\n", __func__);6869/* Only initialize if a rc keycode map is defined */70if (!cx231xx_boards[dev->model].rc_map_name)71return -ENODEV;7273request_module("ir-kbd-i2c");7475memset(&info, 0, sizeof(struct i2c_board_info));76memset(&dev->init_data, 0, sizeof(dev->init_data));77dev->init_data.rc_dev = rc_allocate_device();78if (!dev->init_data.rc_dev)79return -ENOMEM;8081dev->init_data.name = cx231xx_boards[dev->model].name;8283strlcpy(info.type, "ir_video", I2C_NAME_SIZE);84info.platform_data = &dev->init_data;8586/*87* Board-dependent values88*89* For now, there's just one type of hardware design using90* an i2c device.91*/92dev->init_data.get_key = get_key_isdbt;93dev->init_data.ir_codes = cx231xx_boards[dev->model].rc_map_name;94/* The i2c micro-controller only outputs the cmd part of NEC protocol */95dev->init_data.rc_dev->scanmask = 0xff;96dev->init_data.rc_dev->driver_name = "cx231xx";97dev->init_data.type = RC_TYPE_NEC;98info.addr = 0x30;99100/* Load and bind ir-kbd-i2c */101ir_i2c_bus = cx231xx_boards[dev->model].ir_i2c_master;102dev_dbg(&dev->udev->dev, "Trying to bind ir at bus %d, addr 0x%02x\n",103ir_i2c_bus, info.addr);104i2c_new_device(&dev->i2c_bus[ir_i2c_bus].i2c_adap, &info);105106return 0;107}108109void cx231xx_ir_exit(struct cx231xx *dev)110{111}112113114