2010-10-23 16:28:33 +00:00
|
|
|
/*
|
|
|
|
* cx231xx IR glue driver
|
|
|
|
*
|
2014-02-07 10:03:07 +00:00
|
|
|
* Copyright (C) 2010 Mauro Carvalho Chehab
|
2010-10-23 16:28:33 +00:00
|
|
|
*
|
|
|
|
* Polaris (cx231xx) has its support for IR's with a design close to MCE.
|
|
|
|
* however, a few designs are using an external I2C chip for IR, instead
|
|
|
|
* of using the one provided by the chip.
|
|
|
|
* This driver provides support for those extra devices
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation version 2.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cx231xx.h"
|
|
|
|
#include <linux/slab.h>
|
2014-04-03 23:31:25 +00:00
|
|
|
#include <linux/bitrev.h>
|
2010-10-23 16:28:33 +00:00
|
|
|
|
|
|
|
#define MODULE_NAME "cx231xx-input"
|
|
|
|
|
2014-04-03 23:31:25 +00:00
|
|
|
static int get_key_isdbt(struct IR_i2c *ir, enum rc_type *protocol,
|
|
|
|
u32 *pscancode, u8 *toggle)
|
2010-10-23 16:28:33 +00:00
|
|
|
{
|
2012-01-10 00:28:13 +00:00
|
|
|
int rc;
|
2010-12-17 17:22:09 +00:00
|
|
|
u8 cmd, scancode;
|
2010-10-23 16:28:33 +00:00
|
|
|
|
2010-11-11 11:14:16 +00:00
|
|
|
dev_dbg(&ir->rc->input_dev->dev, "%s\n", __func__);
|
|
|
|
|
2010-10-23 16:28:33 +00:00
|
|
|
/* poll IR chip */
|
2012-01-10 00:28:13 +00:00
|
|
|
rc = i2c_master_recv(ir->c, &cmd, 1);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
if (rc != 1)
|
2010-10-23 16:28:33 +00:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
/* it seems that 0xFE indicates that a button is still hold
|
|
|
|
down, while 0xff indicates that no button is hold
|
|
|
|
down. 0xfe sequences are sometimes interrupted by 0xFF */
|
|
|
|
|
|
|
|
if (cmd == 0xff)
|
|
|
|
return 0;
|
|
|
|
|
2014-04-03 23:31:25 +00:00
|
|
|
scancode = bitrev8(cmd);
|
2010-10-23 16:28:33 +00:00
|
|
|
|
2010-12-17 17:22:09 +00:00
|
|
|
dev_dbg(&ir->rc->input_dev->dev, "cmd %02x, scan = %02x\n",
|
|
|
|
cmd, scancode);
|
|
|
|
|
2014-04-03 23:31:25 +00:00
|
|
|
*protocol = RC_TYPE_OTHER;
|
|
|
|
*pscancode = scancode;
|
|
|
|
*toggle = 0;
|
2010-10-23 16:28:33 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cx231xx_ir_init(struct cx231xx *dev)
|
|
|
|
{
|
|
|
|
struct i2c_board_info info;
|
|
|
|
u8 ir_i2c_bus;
|
|
|
|
|
2014-11-03 09:07:38 +00:00
|
|
|
dev_dbg(dev->dev, "%s\n", __func__);
|
2010-10-23 16:28:33 +00:00
|
|
|
|
|
|
|
/* Only initialize if a rc keycode map is defined */
|
2010-11-17 17:12:46 +00:00
|
|
|
if (!cx231xx_boards[dev->model].rc_map_name)
|
2010-10-23 16:28:33 +00:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
request_module("ir-kbd-i2c");
|
|
|
|
|
|
|
|
memset(&info, 0, sizeof(struct i2c_board_info));
|
2010-11-11 11:14:16 +00:00
|
|
|
memset(&dev->init_data, 0, sizeof(dev->init_data));
|
|
|
|
dev->init_data.rc_dev = rc_allocate_device();
|
|
|
|
if (!dev->init_data.rc_dev)
|
|
|
|
return -ENOMEM;
|
2010-10-23 16:28:33 +00:00
|
|
|
|
2010-11-11 11:14:16 +00:00
|
|
|
dev->init_data.name = cx231xx_boards[dev->model].name;
|
2010-10-23 16:28:33 +00:00
|
|
|
|
|
|
|
strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
|
2010-11-11 11:14:16 +00:00
|
|
|
info.platform_data = &dev->init_data;
|
2010-10-23 16:28:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Board-dependent values
|
|
|
|
*
|
|
|
|
* For now, there's just one type of hardware design using
|
|
|
|
* an i2c device.
|
|
|
|
*/
|
2010-11-11 11:14:16 +00:00
|
|
|
dev->init_data.get_key = get_key_isdbt;
|
2010-11-17 17:12:46 +00:00
|
|
|
dev->init_data.ir_codes = cx231xx_boards[dev->model].rc_map_name;
|
2010-10-23 16:28:33 +00:00
|
|
|
/* The i2c micro-controller only outputs the cmd part of NEC protocol */
|
2014-04-03 23:32:26 +00:00
|
|
|
dev->init_data.rc_dev->scancode_mask = 0xff;
|
2010-11-11 11:14:16 +00:00
|
|
|
dev->init_data.rc_dev->driver_name = "cx231xx";
|
2012-10-11 22:11:54 +00:00
|
|
|
dev->init_data.type = RC_BIT_NEC;
|
2010-10-23 16:28:33 +00:00
|
|
|
info.addr = 0x30;
|
|
|
|
|
|
|
|
/* Load and bind ir-kbd-i2c */
|
|
|
|
ir_i2c_bus = cx231xx_boards[dev->model].ir_i2c_master;
|
2014-11-03 09:07:38 +00:00
|
|
|
dev_dbg(dev->dev, "Trying to bind ir at bus %d, addr 0x%02x\n",
|
2010-11-11 11:14:16 +00:00
|
|
|
ir_i2c_bus, info.addr);
|
2014-10-02 05:20:59 +00:00
|
|
|
dev->ir_i2c_client = i2c_new_device(
|
|
|
|
cx231xx_get_i2c_adap(dev, ir_i2c_bus), &info);
|
2010-10-23 16:28:33 +00:00
|
|
|
|
2010-11-11 11:14:16 +00:00
|
|
|
return 0;
|
2010-10-23 16:28:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cx231xx_ir_exit(struct cx231xx *dev)
|
|
|
|
{
|
[media] cx231xx: Fix unregister logic
There are several weirdness at the unregister logic.
First of all, IR has a poll thread. This thread needs to be
removed, as it uses some resources associated to the main driver.
So, the driver needs to explicitly unregister the I2C client for
ir-kbd-i2c.
If, for some reason, the driver needs to wait for a close()
to happen, not all memories will be freed, because the free
logic were in the wrong place.
Also, v4l2_device_unregister() seems to be called too early,
as devices are still using it.
Finally, even with the device disconnected, there is one
USB function call that will still try to talk with it.
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2012-01-10 11:20:01 +00:00
|
|
|
if (dev->ir_i2c_client)
|
|
|
|
i2c_unregister_device(dev->ir_i2c_client);
|
|
|
|
dev->ir_i2c_client = NULL;
|
2010-10-23 16:28:33 +00:00
|
|
|
}
|