diff options
author | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-10-23 12:28:33 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-12-29 05:16:28 -0500 |
commit | 9ab66912e0cd671fbea1b99e8a37d11b14d50baf (patch) | |
tree | 01fbcb21c8d3f7d90360d7c410c07152aba7ecd6 /drivers/media/video/cx231xx | |
parent | f0551efc77b0f34a93a14d2bf96051612e352a39 (diff) |
[media] cx231xx: Add a driver for I2C-based IR
Although cx231xx has a very good IR support, already supported by
mceusb driver, some designs decided to add a separate I2C
microcontroller chip in order to handle IR.
Due to that, add a glue to ir-kbd-i2c is needed, in order to support
those devices.
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/cx231xx')
-rw-r--r-- | drivers/media/video/cx231xx/Kconfig | 13 | ||||
-rw-r--r-- | drivers/media/video/cx231xx/Makefile | 5 | ||||
-rw-r--r-- | drivers/media/video/cx231xx/cx231xx-cards.c | 5 | ||||
-rw-r--r-- | drivers/media/video/cx231xx/cx231xx-core.c | 2 | ||||
-rw-r--r-- | drivers/media/video/cx231xx/cx231xx-input.c | 122 | ||||
-rw-r--r-- | drivers/media/video/cx231xx/cx231xx.h | 32 |
6 files changed, 174 insertions, 5 deletions
diff --git a/drivers/media/video/cx231xx/Kconfig b/drivers/media/video/cx231xx/Kconfig index bad836f77758..c37eac114024 100644 --- a/drivers/media/video/cx231xx/Kconfig +++ b/drivers/media/video/cx231xx/Kconfig | |||
@@ -14,6 +14,19 @@ config VIDEO_CX231XX | |||
14 | To compile this driver as a module, choose M here: the | 14 | To compile this driver as a module, choose M here: the |
15 | module will be called cx231xx | 15 | module will be called cx231xx |
16 | 16 | ||
17 | config VIDEO_CX231XX_RC | ||
18 | bool "Conexant cx231xx Remote Controller additional support" | ||
19 | depends on VIDEO_IR | ||
20 | depends on VIDEO_CX231XX | ||
21 | default y | ||
22 | ---help--- | ||
23 | cx231xx hardware has a builtin RX/TX support. However, a few | ||
24 | designs opted to not use it, but, instead, some other hardware. | ||
25 | This module enables the usage of those other hardware, like the | ||
26 | ones used with ISDB-T boards. | ||
27 | |||
28 | On most cases, all you need for IR is mceusb module. | ||
29 | |||
17 | config VIDEO_CX231XX_ALSA | 30 | config VIDEO_CX231XX_ALSA |
18 | tristate "Conexant Cx231xx ALSA audio module" | 31 | tristate "Conexant Cx231xx ALSA audio module" |
19 | depends on VIDEO_CX231XX && SND | 32 | depends on VIDEO_CX231XX && SND |
diff --git a/drivers/media/video/cx231xx/Makefile b/drivers/media/video/cx231xx/Makefile index a6bc4cc54677..2c2484355449 100644 --- a/drivers/media/video/cx231xx/Makefile +++ b/drivers/media/video/cx231xx/Makefile | |||
@@ -1,5 +1,6 @@ | |||
1 | cx231xx-objs := cx231xx-video.o cx231xx-i2c.o cx231xx-cards.o cx231xx-core.o \ | 1 | cx231xx-y += cx231xx-video.o cx231xx-i2c.o cx231xx-cards.o cx231xx-core.o |
2 | cx231xx-avcore.o cx231xx-417.o cx231xx-pcb-cfg.o cx231xx-vbi.o | 2 | cx231xx-y += cx231xx-avcore.o cx231xx-417.o cx231xx-pcb-cfg.o cx231xx-vbi.o |
3 | cx231xx-$(CONFIG_VIDEO_CX231XX_RC) += cx231xx-input.o | ||
3 | 4 | ||
4 | cx231xx-alsa-objs := cx231xx-audio.o | 5 | cx231xx-alsa-objs := cx231xx-audio.o |
5 | 6 | ||
diff --git a/drivers/media/video/cx231xx/cx231xx-cards.c b/drivers/media/video/cx231xx/cx231xx-cards.c index 400447fbf7fb..0a06fcac9db9 100644 --- a/drivers/media/video/cx231xx/cx231xx-cards.c +++ b/drivers/media/video/cx231xx/cx231xx-cards.c | |||
@@ -663,8 +663,11 @@ void cx231xx_release_resources(struct cx231xx *dev) | |||
663 | 663 | ||
664 | cx231xx_remove_from_devlist(dev); | 664 | cx231xx_remove_from_devlist(dev); |
665 | 665 | ||
666 | /* Release I2C buses */ | ||
666 | cx231xx_dev_uninit(dev); | 667 | cx231xx_dev_uninit(dev); |
667 | 668 | ||
669 | cx231xx_ir_exit(dev); | ||
670 | |||
668 | usb_put_dev(dev->udev); | 671 | usb_put_dev(dev->udev); |
669 | 672 | ||
670 | /* Mark device as unused */ | 673 | /* Mark device as unused */ |
@@ -782,6 +785,8 @@ static int cx231xx_init_dev(struct cx231xx **devhandle, struct usb_device *udev, | |||
782 | goto fail_reg_devices; | 785 | goto fail_reg_devices; |
783 | } | 786 | } |
784 | 787 | ||
788 | cx231xx_ir_init(dev); | ||
789 | |||
785 | cx231xx_init_extension(dev); | 790 | cx231xx_init_extension(dev); |
786 | 791 | ||
787 | return 0; | 792 | return 0; |
diff --git a/drivers/media/video/cx231xx/cx231xx-core.c b/drivers/media/video/cx231xx/cx231xx-core.c index d6028c92b6f2..44d124c2fc35 100644 --- a/drivers/media/video/cx231xx/cx231xx-core.c +++ b/drivers/media/video/cx231xx/cx231xx-core.c | |||
@@ -1289,7 +1289,7 @@ int cx231xx_dev_init(struct cx231xx *dev) | |||
1289 | /* Internal Master 3 Bus */ | 1289 | /* Internal Master 3 Bus */ |
1290 | dev->i2c_bus[2].nr = 2; | 1290 | dev->i2c_bus[2].nr = 2; |
1291 | dev->i2c_bus[2].dev = dev; | 1291 | dev->i2c_bus[2].dev = dev; |
1292 | dev->i2c_bus[2].i2c_period = I2C_SPEED_400K; /* 400kHz */ | 1292 | dev->i2c_bus[2].i2c_period = I2C_SPEED_100K; /* 100kHz */ |
1293 | dev->i2c_bus[2].i2c_nostop = 0; | 1293 | dev->i2c_bus[2].i2c_nostop = 0; |
1294 | dev->i2c_bus[2].i2c_reserve = 0; | 1294 | dev->i2c_bus[2].i2c_reserve = 0; |
1295 | 1295 | ||
diff --git a/drivers/media/video/cx231xx/cx231xx-input.c b/drivers/media/video/cx231xx/cx231xx-input.c new file mode 100644 index 000000000000..6725244c400c --- /dev/null +++ b/drivers/media/video/cx231xx/cx231xx-input.c | |||
@@ -0,0 +1,122 @@ | |||
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 | /* poll IR chip */ | ||
33 | if (1 != i2c_master_recv(ir->c, &cmd, 1)) | ||
34 | return -EIO; | ||
35 | |||
36 | /* it seems that 0xFE indicates that a button is still hold | ||
37 | down, while 0xff indicates that no button is hold | ||
38 | down. 0xfe sequences are sometimes interrupted by 0xFF */ | ||
39 | |||
40 | if (cmd == 0xff) | ||
41 | return 0; | ||
42 | |||
43 | dev_dbg(&ir->input->dev, "scancode = %02x\n", cmd); | ||
44 | |||
45 | *ir_key = cmd; | ||
46 | *ir_raw = cmd; | ||
47 | return 1; | ||
48 | } | ||
49 | |||
50 | int cx231xx_ir_init(struct cx231xx *dev) | ||
51 | { | ||
52 | struct input_dev *input_dev; | ||
53 | struct i2c_board_info info; | ||
54 | int rc; | ||
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 | input_dev = input_allocate_device(); | ||
64 | if (!input_dev) | ||
65 | return -ENOMEM; | ||
66 | |||
67 | request_module("ir-kbd-i2c"); | ||
68 | |||
69 | memset(&info, 0, sizeof(struct i2c_board_info)); | ||
70 | memset(&dev->ir.init_data, 0, sizeof(dev->ir.init_data)); | ||
71 | |||
72 | dev->ir.input_dev = input_dev; | ||
73 | dev->ir.init_data.name = cx231xx_boards[dev->model].name; | ||
74 | dev->ir.props.priv = dev; | ||
75 | dev->ir.props.allowed_protos = IR_TYPE_NEC; | ||
76 | snprintf(dev->ir.name, sizeof(dev->ir.name), | ||
77 | "cx231xx IR (%s)", cx231xx_boards[dev->model].name); | ||
78 | usb_make_path(dev->udev, dev->ir.phys, sizeof(dev->ir.phys)); | ||
79 | strlcat(dev->ir.phys, "/input0", sizeof(dev->ir.phys)); | ||
80 | |||
81 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); | ||
82 | info.platform_data = &dev->ir.init_data; | ||
83 | |||
84 | input_dev->name = dev->ir.name; | ||
85 | input_dev->phys = dev->ir.phys; | ||
86 | input_dev->dev.parent = &dev->udev->dev; | ||
87 | input_dev->id.bustype = BUS_USB; | ||
88 | input_dev->id.version = 1; | ||
89 | input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); | ||
90 | input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct); | ||
91 | |||
92 | /* | ||
93 | * Board-dependent values | ||
94 | * | ||
95 | * For now, there's just one type of hardware design using | ||
96 | * an i2c device. | ||
97 | */ | ||
98 | dev->ir.init_data.get_key = get_key_isdbt; | ||
99 | dev->ir.init_data.ir_codes = cx231xx_boards[dev->model].rc_map; | ||
100 | /* The i2c micro-controller only outputs the cmd part of NEC protocol */ | ||
101 | dev->ir.props.scanmask = 0xff; | ||
102 | info.addr = 0x30; | ||
103 | |||
104 | rc = ir_input_register(input_dev, cx231xx_boards[dev->model].rc_map, | ||
105 | &dev->ir.props, MODULE_NAME); | ||
106 | if (rc < 0) | ||
107 | return rc; | ||
108 | |||
109 | /* Load and bind ir-kbd-i2c */ | ||
110 | ir_i2c_bus = cx231xx_boards[dev->model].ir_i2c_master; | ||
111 | i2c_new_device(&dev->i2c_bus[ir_i2c_bus].i2c_adap, &info); | ||
112 | |||
113 | return rc; | ||
114 | } | ||
115 | |||
116 | void cx231xx_ir_exit(struct cx231xx *dev) | ||
117 | { | ||
118 | if (dev->ir.input_dev) { | ||
119 | ir_input_unregister(dev->ir.input_dev); | ||
120 | dev->ir.input_dev = NULL; | ||
121 | } | ||
122 | } | ||
diff --git a/drivers/media/video/cx231xx/cx231xx.h b/drivers/media/video/cx231xx/cx231xx.h index 8a7d0a4aaab6..a09cef43d98d 100644 --- a/drivers/media/video/cx231xx/cx231xx.h +++ b/drivers/media/video/cx231xx/cx231xx.h | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <media/videobuf-vmalloc.h> | 35 | #include <media/videobuf-vmalloc.h> |
36 | #include <media/v4l2-device.h> | 36 | #include <media/v4l2-device.h> |
37 | #include <media/ir-core.h> | 37 | #include <media/ir-core.h> |
38 | #include <media/ir-kbd-i2c.h> | ||
38 | #include <media/videobuf-dvb.h> | 39 | #include <media/videobuf-dvb.h> |
39 | 40 | ||
40 | #include "cx231xx-reg.h" | 41 | #include "cx231xx-reg.h" |
@@ -345,6 +346,10 @@ struct cx231xx_board { | |||
345 | /* i2c masters */ | 346 | /* i2c masters */ |
346 | u8 tuner_i2c_master; | 347 | u8 tuner_i2c_master; |
347 | u8 demod_i2c_master; | 348 | u8 demod_i2c_master; |
349 | u8 ir_i2c_master; | ||
350 | |||
351 | /* for devices with I2C chips for IR */ | ||
352 | char *rc_map; | ||
348 | 353 | ||
349 | unsigned int max_range_640_480:1; | 354 | unsigned int max_range_640_480:1; |
350 | unsigned int has_dvb:1; | 355 | unsigned int has_dvb:1; |
@@ -597,6 +602,17 @@ struct cx231xx_tsport { | |||
597 | void *port_priv; | 602 | void *port_priv; |
598 | }; | 603 | }; |
599 | 604 | ||
605 | struct cx231xx_ir_t { | ||
606 | struct input_dev *input_dev; | ||
607 | char name[40]; | ||
608 | char phys[32]; | ||
609 | |||
610 | struct ir_dev_props props; | ||
611 | |||
612 | /* I2C keyboard data */ | ||
613 | struct IR_i2c_init_data init_data; | ||
614 | }; | ||
615 | |||
600 | /* main device struct */ | 616 | /* main device struct */ |
601 | struct cx231xx { | 617 | struct cx231xx { |
602 | /* generic device properties */ | 618 | /* generic device properties */ |
@@ -606,6 +622,9 @@ struct cx231xx { | |||
606 | 622 | ||
607 | struct cx231xx_board board; | 623 | struct cx231xx_board board; |
608 | 624 | ||
625 | /* For I2C IR support */ | ||
626 | struct cx231xx_ir_t ir; | ||
627 | |||
609 | unsigned int stream_on:1; /* Locks streams */ | 628 | unsigned int stream_on:1; /* Locks streams */ |
610 | unsigned int vbi_stream_on:1; /* Locks streams for VBI */ | 629 | unsigned int vbi_stream_on:1; /* Locks streams for VBI */ |
611 | unsigned int has_audio_class:1; | 630 | unsigned int has_audio_class:1; |
@@ -617,8 +636,6 @@ struct cx231xx { | |||
617 | struct v4l2_subdev *sd_cx25840; | 636 | struct v4l2_subdev *sd_cx25840; |
618 | struct v4l2_subdev *sd_tuner; | 637 | struct v4l2_subdev *sd_tuner; |
619 | 638 | ||
620 | struct cx231xx_IR *ir; | ||
621 | |||
622 | struct work_struct wq_trigger; /* Trigger to start/stop audio for alsa module */ | 639 | struct work_struct wq_trigger; /* Trigger to start/stop audio for alsa module */ |
623 | atomic_t stream_started; /* stream should be running if true */ | 640 | atomic_t stream_started; /* stream should be running if true */ |
624 | 641 | ||
@@ -955,6 +972,17 @@ int cx231xx_tuner_callback(void *ptr, int component, int command, int arg); | |||
955 | extern int cx231xx_417_register(struct cx231xx *dev); | 972 | extern int cx231xx_417_register(struct cx231xx *dev); |
956 | extern void cx231xx_417_unregister(struct cx231xx *dev); | 973 | extern void cx231xx_417_unregister(struct cx231xx *dev); |
957 | 974 | ||
975 | /* cx23885-input.c */ | ||
976 | |||
977 | #if defined(CONFIG_VIDEO_CX231XX_RC) | ||
978 | int cx231xx_ir_init(struct cx231xx *dev); | ||
979 | void cx231xx_ir_exit(struct cx231xx *dev); | ||
980 | #else | ||
981 | #define cx231xx_ir_init(dev) (0) | ||
982 | #define cx231xx_ir_exit(dev) (0) | ||
983 | #endif | ||
984 | |||
985 | |||
958 | /* printk macros */ | 986 | /* printk macros */ |
959 | 987 | ||
960 | #define cx231xx_err(fmt, arg...) do {\ | 988 | #define cx231xx_err(fmt, arg...) do {\ |