diff options
Diffstat (limited to 'drivers/media/IR')
-rw-r--r-- | drivers/media/IR/Kconfig | 35 | ||||
-rw-r--r-- | drivers/media/IR/Makefile | 3 | ||||
-rw-r--r-- | drivers/media/IR/imon.c | 11 | ||||
-rw-r--r-- | drivers/media/IR/ir-core-priv.h | 54 | ||||
-rw-r--r-- | drivers/media/IR/ir-jvc-decoder.c | 152 | ||||
-rw-r--r-- | drivers/media/IR/ir-keytable.c | 5 | ||||
-rw-r--r-- | drivers/media/IR/ir-lirc-codec.c | 278 | ||||
-rw-r--r-- | drivers/media/IR/ir-nec-decoder.c | 151 | ||||
-rw-r--r-- | drivers/media/IR/ir-raw-event.c | 167 | ||||
-rw-r--r-- | drivers/media/IR/ir-rc5-decoder.c | 167 | ||||
-rw-r--r-- | drivers/media/IR/ir-rc6-decoder.c | 153 | ||||
-rw-r--r-- | drivers/media/IR/ir-sony-decoder.c | 155 | ||||
-rw-r--r-- | drivers/media/IR/ir-sysfs.c | 251 | ||||
-rw-r--r-- | drivers/media/IR/keymaps/Makefile | 4 | ||||
-rw-r--r-- | drivers/media/IR/keymaps/rc-dib0700-nec.c | 124 | ||||
-rw-r--r-- | drivers/media/IR/keymaps/rc-dib0700-rc5.c | 235 | ||||
-rw-r--r-- | drivers/media/IR/keymaps/rc-lirc.c | 41 | ||||
-rw-r--r-- | drivers/media/IR/keymaps/rc-rc6-mce.c | 105 | ||||
-rw-r--r-- | drivers/media/IR/lirc_dev.c | 764 | ||||
-rw-r--r-- | drivers/media/IR/mceusb.c | 1143 |
20 files changed, 3085 insertions, 913 deletions
diff --git a/drivers/media/IR/Kconfig b/drivers/media/IR/Kconfig index d22a8ec523fc..999a8250b3ce 100644 --- a/drivers/media/IR/Kconfig +++ b/drivers/media/IR/Kconfig | |||
@@ -8,6 +8,17 @@ config VIDEO_IR | |||
8 | depends on IR_CORE | 8 | depends on IR_CORE |
9 | default IR_CORE | 9 | default IR_CORE |
10 | 10 | ||
11 | config LIRC | ||
12 | tristate | ||
13 | default y | ||
14 | |||
15 | ---help--- | ||
16 | Enable this option to build the Linux Infrared Remote | ||
17 | Control (LIRC) core device interface driver. The LIRC | ||
18 | interface passes raw IR to and from userspace, where the | ||
19 | LIRC daemon handles protocol decoding for IR reception ann | ||
20 | encoding for IR transmitting (aka "blasting"). | ||
21 | |||
11 | source "drivers/media/IR/keymaps/Kconfig" | 22 | source "drivers/media/IR/keymaps/Kconfig" |
12 | 23 | ||
13 | config IR_NEC_DECODER | 24 | config IR_NEC_DECODER |
@@ -33,6 +44,7 @@ config IR_RC5_DECODER | |||
33 | config IR_RC6_DECODER | 44 | config IR_RC6_DECODER |
34 | tristate "Enable IR raw decoder for the RC6 protocol" | 45 | tristate "Enable IR raw decoder for the RC6 protocol" |
35 | depends on IR_CORE | 46 | depends on IR_CORE |
47 | select BITREVERSE | ||
36 | default y | 48 | default y |
37 | 49 | ||
38 | ---help--- | 50 | ---help--- |
@@ -42,6 +54,7 @@ config IR_RC6_DECODER | |||
42 | config IR_JVC_DECODER | 54 | config IR_JVC_DECODER |
43 | tristate "Enable IR raw decoder for the JVC protocol" | 55 | tristate "Enable IR raw decoder for the JVC protocol" |
44 | depends on IR_CORE | 56 | depends on IR_CORE |
57 | select BITREVERSE | ||
45 | default y | 58 | default y |
46 | 59 | ||
47 | ---help--- | 60 | ---help--- |
@@ -57,6 +70,16 @@ config IR_SONY_DECODER | |||
57 | Enable this option if you have an infrared remote control which | 70 | Enable this option if you have an infrared remote control which |
58 | uses the Sony protocol, and you need software decoding support. | 71 | uses the Sony protocol, and you need software decoding support. |
59 | 72 | ||
73 | config IR_LIRC_CODEC | ||
74 | tristate "Enable IR to LIRC bridge" | ||
75 | depends on IR_CORE | ||
76 | depends on LIRC | ||
77 | default y | ||
78 | |||
79 | ---help--- | ||
80 | Enable this option to pass raw IR to and from userspace via | ||
81 | the LIRC interface. | ||
82 | |||
60 | config IR_IMON | 83 | config IR_IMON |
61 | tristate "SoundGraph iMON Receiver and Display" | 84 | tristate "SoundGraph iMON Receiver and Display" |
62 | depends on USB_ARCH_HAS_HCD | 85 | depends on USB_ARCH_HAS_HCD |
@@ -68,3 +91,15 @@ config IR_IMON | |||
68 | 91 | ||
69 | To compile this driver as a module, choose M here: the | 92 | To compile this driver as a module, choose M here: the |
70 | module will be called imon. | 93 | module will be called imon. |
94 | |||
95 | config IR_MCEUSB | ||
96 | tristate "Windows Media Center Ed. eHome Infrared Transceiver" | ||
97 | depends on USB_ARCH_HAS_HCD | ||
98 | depends on IR_CORE | ||
99 | select USB | ||
100 | ---help--- | ||
101 | Say Y here if you want to use a Windows Media Center Edition | ||
102 | eHome Infrared Transceiver. | ||
103 | |||
104 | To compile this driver as a module, choose M here: the | ||
105 | module will be called mceusb. | ||
diff --git a/drivers/media/IR/Makefile b/drivers/media/IR/Makefile index b998fcced2e4..2ae4f3abfdbd 100644 --- a/drivers/media/IR/Makefile +++ b/drivers/media/IR/Makefile | |||
@@ -5,11 +5,14 @@ obj-y += keymaps/ | |||
5 | 5 | ||
6 | obj-$(CONFIG_IR_CORE) += ir-core.o | 6 | obj-$(CONFIG_IR_CORE) += ir-core.o |
7 | obj-$(CONFIG_VIDEO_IR) += ir-common.o | 7 | obj-$(CONFIG_VIDEO_IR) += ir-common.o |
8 | obj-$(CONFIG_LIRC) += lirc_dev.o | ||
8 | obj-$(CONFIG_IR_NEC_DECODER) += ir-nec-decoder.o | 9 | obj-$(CONFIG_IR_NEC_DECODER) += ir-nec-decoder.o |
9 | obj-$(CONFIG_IR_RC5_DECODER) += ir-rc5-decoder.o | 10 | obj-$(CONFIG_IR_RC5_DECODER) += ir-rc5-decoder.o |
10 | obj-$(CONFIG_IR_RC6_DECODER) += ir-rc6-decoder.o | 11 | obj-$(CONFIG_IR_RC6_DECODER) += ir-rc6-decoder.o |
11 | obj-$(CONFIG_IR_JVC_DECODER) += ir-jvc-decoder.o | 12 | obj-$(CONFIG_IR_JVC_DECODER) += ir-jvc-decoder.o |
12 | obj-$(CONFIG_IR_SONY_DECODER) += ir-sony-decoder.o | 13 | obj-$(CONFIG_IR_SONY_DECODER) += ir-sony-decoder.o |
14 | obj-$(CONFIG_IR_LIRC_CODEC) += ir-lirc-codec.o | ||
13 | 15 | ||
14 | # stand-alone IR receivers/transmitters | 16 | # stand-alone IR receivers/transmitters |
15 | obj-$(CONFIG_IR_IMON) += imon.o | 17 | obj-$(CONFIG_IR_IMON) += imon.o |
18 | obj-$(CONFIG_IR_MCEUSB) += mceusb.o | ||
diff --git a/drivers/media/IR/imon.c b/drivers/media/IR/imon.c index 4bbd45f4284c..65c125e44e96 100644 --- a/drivers/media/IR/imon.c +++ b/drivers/media/IR/imon.c | |||
@@ -407,7 +407,7 @@ static int display_close(struct inode *inode, struct file *file) | |||
407 | struct imon_context *ictx = NULL; | 407 | struct imon_context *ictx = NULL; |
408 | int retval = 0; | 408 | int retval = 0; |
409 | 409 | ||
410 | ictx = (struct imon_context *)file->private_data; | 410 | ictx = file->private_data; |
411 | 411 | ||
412 | if (!ictx) { | 412 | if (!ictx) { |
413 | err("%s: no context for device", __func__); | 413 | err("%s: no context for device", __func__); |
@@ -812,7 +812,7 @@ static ssize_t vfd_write(struct file *file, const char *buf, | |||
812 | const unsigned char vfd_packet6[] = { | 812 | const unsigned char vfd_packet6[] = { |
813 | 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF }; | 813 | 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF }; |
814 | 814 | ||
815 | ictx = (struct imon_context *)file->private_data; | 815 | ictx = file->private_data; |
816 | if (!ictx) { | 816 | if (!ictx) { |
817 | err("%s: no context for device", __func__); | 817 | err("%s: no context for device", __func__); |
818 | return -ENODEV; | 818 | return -ENODEV; |
@@ -896,7 +896,7 @@ static ssize_t lcd_write(struct file *file, const char *buf, | |||
896 | int retval = 0; | 896 | int retval = 0; |
897 | struct imon_context *ictx; | 897 | struct imon_context *ictx; |
898 | 898 | ||
899 | ictx = (struct imon_context *)file->private_data; | 899 | ictx = file->private_data; |
900 | if (!ictx) { | 900 | if (!ictx) { |
901 | err("%s: no context for device", __func__); | 901 | err("%s: no context for device", __func__); |
902 | return -ENODEV; | 902 | return -ENODEV; |
@@ -1943,7 +1943,7 @@ static struct imon_context *imon_init_intf0(struct usb_interface *intf) | |||
1943 | return ictx; | 1943 | return ictx; |
1944 | 1944 | ||
1945 | urb_submit_failed: | 1945 | urb_submit_failed: |
1946 | input_unregister_device(ictx->idev); | 1946 | ir_input_unregister(ictx->idev); |
1947 | input_free_device(ictx->idev); | 1947 | input_free_device(ictx->idev); |
1948 | idev_setup_failed: | 1948 | idev_setup_failed: |
1949 | find_endpoint_failed: | 1949 | find_endpoint_failed: |
@@ -2067,6 +2067,7 @@ static void imon_get_ffdc_type(struct imon_context *ictx) | |||
2067 | detected_display_type = IMON_DISPLAY_TYPE_VFD; | 2067 | detected_display_type = IMON_DISPLAY_TYPE_VFD; |
2068 | break; | 2068 | break; |
2069 | /* iMON LCD, MCE IR */ | 2069 | /* iMON LCD, MCE IR */ |
2070 | case 0x9e: | ||
2070 | case 0x9f: | 2071 | case 0x9f: |
2071 | dev_info(ictx->dev, "0xffdc iMON LCD, MCE IR"); | 2072 | dev_info(ictx->dev, "0xffdc iMON LCD, MCE IR"); |
2072 | detected_display_type = IMON_DISPLAY_TYPE_LCD; | 2073 | detected_display_type = IMON_DISPLAY_TYPE_LCD; |
@@ -2306,7 +2307,7 @@ static void __devexit imon_disconnect(struct usb_interface *interface) | |||
2306 | if (ifnum == 0) { | 2307 | if (ifnum == 0) { |
2307 | ictx->dev_present_intf0 = false; | 2308 | ictx->dev_present_intf0 = false; |
2308 | usb_kill_urb(ictx->rx_urb_intf0); | 2309 | usb_kill_urb(ictx->rx_urb_intf0); |
2309 | input_unregister_device(ictx->idev); | 2310 | ir_input_unregister(ictx->idev); |
2310 | if (ictx->display_supported) { | 2311 | if (ictx->display_supported) { |
2311 | if (ictx->display_type == IMON_DISPLAY_TYPE_LCD) | 2312 | if (ictx->display_type == IMON_DISPLAY_TYPE_LCD) |
2312 | usb_deregister_dev(interface, &imon_lcd_class); | 2313 | usb_deregister_dev(interface, &imon_lcd_class); |
diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h index 9a5e65a471a5..babd52061bc3 100644 --- a/drivers/media/IR/ir-core-priv.h +++ b/drivers/media/IR/ir-core-priv.h | |||
@@ -22,17 +22,62 @@ | |||
22 | struct ir_raw_handler { | 22 | struct ir_raw_handler { |
23 | struct list_head list; | 23 | struct list_head list; |
24 | 24 | ||
25 | u64 protocols; /* which are handled by this handler */ | ||
25 | int (*decode)(struct input_dev *input_dev, struct ir_raw_event event); | 26 | int (*decode)(struct input_dev *input_dev, struct ir_raw_event event); |
27 | |||
28 | /* These two should only be used by the lirc decoder */ | ||
26 | int (*raw_register)(struct input_dev *input_dev); | 29 | int (*raw_register)(struct input_dev *input_dev); |
27 | int (*raw_unregister)(struct input_dev *input_dev); | 30 | int (*raw_unregister)(struct input_dev *input_dev); |
28 | }; | 31 | }; |
29 | 32 | ||
30 | struct ir_raw_event_ctrl { | 33 | struct ir_raw_event_ctrl { |
34 | struct list_head list; /* to keep track of raw clients */ | ||
31 | struct work_struct rx_work; /* for the rx decoding workqueue */ | 35 | struct work_struct rx_work; /* for the rx decoding workqueue */ |
32 | struct kfifo kfifo; /* fifo for the pulse/space durations */ | 36 | struct kfifo kfifo; /* fifo for the pulse/space durations */ |
33 | ktime_t last_event; /* when last event occurred */ | 37 | ktime_t last_event; /* when last event occurred */ |
34 | enum raw_event_type last_type; /* last event type */ | 38 | enum raw_event_type last_type; /* last event type */ |
35 | struct input_dev *input_dev; /* pointer to the parent input_dev */ | 39 | struct input_dev *input_dev; /* pointer to the parent input_dev */ |
40 | u64 enabled_protocols; /* enabled raw protocol decoders */ | ||
41 | |||
42 | /* raw decoder state follows */ | ||
43 | struct ir_raw_event prev_ev; | ||
44 | struct nec_dec { | ||
45 | int state; | ||
46 | unsigned count; | ||
47 | u32 bits; | ||
48 | } nec; | ||
49 | struct rc5_dec { | ||
50 | int state; | ||
51 | u32 bits; | ||
52 | unsigned count; | ||
53 | unsigned wanted_bits; | ||
54 | } rc5; | ||
55 | struct rc6_dec { | ||
56 | int state; | ||
57 | u8 header; | ||
58 | u32 body; | ||
59 | bool toggle; | ||
60 | unsigned count; | ||
61 | unsigned wanted_bits; | ||
62 | } rc6; | ||
63 | struct sony_dec { | ||
64 | int state; | ||
65 | u32 bits; | ||
66 | unsigned count; | ||
67 | } sony; | ||
68 | struct jvc_dec { | ||
69 | int state; | ||
70 | u16 bits; | ||
71 | u16 old_bits; | ||
72 | unsigned count; | ||
73 | bool first; | ||
74 | bool toggle; | ||
75 | } jvc; | ||
76 | struct lirc_codec { | ||
77 | struct ir_input_dev *ir_dev; | ||
78 | struct lirc_driver *drv; | ||
79 | int lircdata; | ||
80 | } lirc; | ||
36 | }; | 81 | }; |
37 | 82 | ||
38 | /* macros for IR decoders */ | 83 | /* macros for IR decoders */ |
@@ -74,6 +119,7 @@ void ir_unregister_class(struct input_dev *input_dev); | |||
74 | /* | 119 | /* |
75 | * Routines from ir-raw-event.c to be used internally and by decoders | 120 | * Routines from ir-raw-event.c to be used internally and by decoders |
76 | */ | 121 | */ |
122 | u64 ir_raw_get_allowed_protocols(void); | ||
77 | int ir_raw_event_register(struct input_dev *input_dev); | 123 | int ir_raw_event_register(struct input_dev *input_dev); |
78 | void ir_raw_event_unregister(struct input_dev *input_dev); | 124 | void ir_raw_event_unregister(struct input_dev *input_dev); |
79 | int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler); | 125 | int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler); |
@@ -123,4 +169,12 @@ void ir_raw_init(void); | |||
123 | #define load_sony_decode() 0 | 169 | #define load_sony_decode() 0 |
124 | #endif | 170 | #endif |
125 | 171 | ||
172 | /* from ir-lirc-codec.c */ | ||
173 | #ifdef CONFIG_IR_LIRC_CODEC_MODULE | ||
174 | #define load_lirc_codec() request_module("ir-lirc-codec") | ||
175 | #else | ||
176 | #define load_lirc_codec() 0 | ||
177 | #endif | ||
178 | |||
179 | |||
126 | #endif /* _IR_RAW_EVENT */ | 180 | #endif /* _IR_RAW_EVENT */ |
diff --git a/drivers/media/IR/ir-jvc-decoder.c b/drivers/media/IR/ir-jvc-decoder.c index 0b804944cbb0..8894d8b36048 100644 --- a/drivers/media/IR/ir-jvc-decoder.c +++ b/drivers/media/IR/ir-jvc-decoder.c | |||
@@ -25,10 +25,6 @@ | |||
25 | #define JVC_TRAILER_PULSE (1 * JVC_UNIT) | 25 | #define JVC_TRAILER_PULSE (1 * JVC_UNIT) |
26 | #define JVC_TRAILER_SPACE (35 * JVC_UNIT) | 26 | #define JVC_TRAILER_SPACE (35 * JVC_UNIT) |
27 | 27 | ||
28 | /* Used to register jvc_decoder clients */ | ||
29 | static LIST_HEAD(decoder_list); | ||
30 | DEFINE_SPINLOCK(decoder_lock); | ||
31 | |||
32 | enum jvc_state { | 28 | enum jvc_state { |
33 | STATE_INACTIVE, | 29 | STATE_INACTIVE, |
34 | STATE_HEADER_SPACE, | 30 | STATE_HEADER_SPACE, |
@@ -38,87 +34,6 @@ enum jvc_state { | |||
38 | STATE_TRAILER_SPACE, | 34 | STATE_TRAILER_SPACE, |
39 | }; | 35 | }; |
40 | 36 | ||
41 | struct decoder_data { | ||
42 | struct list_head list; | ||
43 | struct ir_input_dev *ir_dev; | ||
44 | int enabled:1; | ||
45 | |||
46 | /* State machine control */ | ||
47 | enum jvc_state state; | ||
48 | u16 jvc_bits; | ||
49 | u16 jvc_old_bits; | ||
50 | unsigned count; | ||
51 | bool first; | ||
52 | bool toggle; | ||
53 | }; | ||
54 | |||
55 | |||
56 | /** | ||
57 | * get_decoder_data() - gets decoder data | ||
58 | * @input_dev: input device | ||
59 | * | ||
60 | * Returns the struct decoder_data that corresponds to a device | ||
61 | */ | ||
62 | static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev) | ||
63 | { | ||
64 | struct decoder_data *data = NULL; | ||
65 | |||
66 | spin_lock(&decoder_lock); | ||
67 | list_for_each_entry(data, &decoder_list, list) { | ||
68 | if (data->ir_dev == ir_dev) | ||
69 | break; | ||
70 | } | ||
71 | spin_unlock(&decoder_lock); | ||
72 | return data; | ||
73 | } | ||
74 | |||
75 | static ssize_t store_enabled(struct device *d, | ||
76 | struct device_attribute *mattr, | ||
77 | const char *buf, | ||
78 | size_t len) | ||
79 | { | ||
80 | unsigned long value; | ||
81 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | ||
82 | struct decoder_data *data = get_decoder_data(ir_dev); | ||
83 | |||
84 | if (!data) | ||
85 | return -EINVAL; | ||
86 | |||
87 | if (strict_strtoul(buf, 10, &value) || value > 1) | ||
88 | return -EINVAL; | ||
89 | |||
90 | data->enabled = value; | ||
91 | |||
92 | return len; | ||
93 | } | ||
94 | |||
95 | static ssize_t show_enabled(struct device *d, | ||
96 | struct device_attribute *mattr, char *buf) | ||
97 | { | ||
98 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | ||
99 | struct decoder_data *data = get_decoder_data(ir_dev); | ||
100 | |||
101 | if (!data) | ||
102 | return -EINVAL; | ||
103 | |||
104 | if (data->enabled) | ||
105 | return sprintf(buf, "1\n"); | ||
106 | else | ||
107 | return sprintf(buf, "0\n"); | ||
108 | } | ||
109 | |||
110 | static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled); | ||
111 | |||
112 | static struct attribute *decoder_attributes[] = { | ||
113 | &dev_attr_enabled.attr, | ||
114 | NULL | ||
115 | }; | ||
116 | |||
117 | static struct attribute_group decoder_attribute_group = { | ||
118 | .name = "jvc_decoder", | ||
119 | .attrs = decoder_attributes, | ||
120 | }; | ||
121 | |||
122 | /** | 37 | /** |
123 | * ir_jvc_decode() - Decode one JVC pulse or space | 38 | * ir_jvc_decode() - Decode one JVC pulse or space |
124 | * @input_dev: the struct input_dev descriptor of the device | 39 | * @input_dev: the struct input_dev descriptor of the device |
@@ -128,14 +43,10 @@ static struct attribute_group decoder_attribute_group = { | |||
128 | */ | 43 | */ |
129 | static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev) | 44 | static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev) |
130 | { | 45 | { |
131 | struct decoder_data *data; | ||
132 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | 46 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); |
47 | struct jvc_dec *data = &ir_dev->raw->jvc; | ||
133 | 48 | ||
134 | data = get_decoder_data(ir_dev); | 49 | if (!(ir_dev->raw->enabled_protocols & IR_TYPE_JVC)) |
135 | if (!data) | ||
136 | return -EINVAL; | ||
137 | |||
138 | if (!data->enabled) | ||
139 | return 0; | 50 | return 0; |
140 | 51 | ||
141 | if (IS_RESET(ev)) { | 52 | if (IS_RESET(ev)) { |
@@ -188,9 +99,9 @@ static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev) | |||
188 | if (ev.pulse) | 99 | if (ev.pulse) |
189 | break; | 100 | break; |
190 | 101 | ||
191 | data->jvc_bits <<= 1; | 102 | data->bits <<= 1; |
192 | if (eq_margin(ev.duration, JVC_BIT_1_SPACE, JVC_UNIT / 2)) { | 103 | if (eq_margin(ev.duration, JVC_BIT_1_SPACE, JVC_UNIT / 2)) { |
193 | data->jvc_bits |= 1; | 104 | data->bits |= 1; |
194 | decrease_duration(&ev, JVC_BIT_1_SPACE); | 105 | decrease_duration(&ev, JVC_BIT_1_SPACE); |
195 | } else if (eq_margin(ev.duration, JVC_BIT_0_SPACE, JVC_UNIT / 2)) | 106 | } else if (eq_margin(ev.duration, JVC_BIT_0_SPACE, JVC_UNIT / 2)) |
196 | decrease_duration(&ev, JVC_BIT_0_SPACE); | 107 | decrease_duration(&ev, JVC_BIT_0_SPACE); |
@@ -223,13 +134,13 @@ static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev) | |||
223 | 134 | ||
224 | if (data->first) { | 135 | if (data->first) { |
225 | u32 scancode; | 136 | u32 scancode; |
226 | scancode = (bitrev8((data->jvc_bits >> 8) & 0xff) << 8) | | 137 | scancode = (bitrev8((data->bits >> 8) & 0xff) << 8) | |
227 | (bitrev8((data->jvc_bits >> 0) & 0xff) << 0); | 138 | (bitrev8((data->bits >> 0) & 0xff) << 0); |
228 | IR_dprintk(1, "JVC scancode 0x%04x\n", scancode); | 139 | IR_dprintk(1, "JVC scancode 0x%04x\n", scancode); |
229 | ir_keydown(input_dev, scancode, data->toggle); | 140 | ir_keydown(input_dev, scancode, data->toggle); |
230 | data->first = false; | 141 | data->first = false; |
231 | data->jvc_old_bits = data->jvc_bits; | 142 | data->old_bits = data->bits; |
232 | } else if (data->jvc_bits == data->jvc_old_bits) { | 143 | } else if (data->bits == data->old_bits) { |
233 | IR_dprintk(1, "JVC repeat\n"); | 144 | IR_dprintk(1, "JVC repeat\n"); |
234 | ir_repeat(input_dev); | 145 | ir_repeat(input_dev); |
235 | } else { | 146 | } else { |
@@ -249,54 +160,9 @@ out: | |||
249 | return -EINVAL; | 160 | return -EINVAL; |
250 | } | 161 | } |
251 | 162 | ||
252 | static int ir_jvc_register(struct input_dev *input_dev) | ||
253 | { | ||
254 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
255 | struct decoder_data *data; | ||
256 | int rc; | ||
257 | |||
258 | rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group); | ||
259 | if (rc < 0) | ||
260 | return rc; | ||
261 | |||
262 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
263 | if (!data) { | ||
264 | sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group); | ||
265 | return -ENOMEM; | ||
266 | } | ||
267 | |||
268 | data->ir_dev = ir_dev; | ||
269 | data->enabled = 1; | ||
270 | |||
271 | spin_lock(&decoder_lock); | ||
272 | list_add_tail(&data->list, &decoder_list); | ||
273 | spin_unlock(&decoder_lock); | ||
274 | |||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | static int ir_jvc_unregister(struct input_dev *input_dev) | ||
279 | { | ||
280 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
281 | static struct decoder_data *data; | ||
282 | |||
283 | data = get_decoder_data(ir_dev); | ||
284 | if (!data) | ||
285 | return 0; | ||
286 | |||
287 | sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group); | ||
288 | |||
289 | spin_lock(&decoder_lock); | ||
290 | list_del(&data->list); | ||
291 | spin_unlock(&decoder_lock); | ||
292 | |||
293 | return 0; | ||
294 | } | ||
295 | |||
296 | static struct ir_raw_handler jvc_handler = { | 163 | static struct ir_raw_handler jvc_handler = { |
164 | .protocols = IR_TYPE_JVC, | ||
297 | .decode = ir_jvc_decode, | 165 | .decode = ir_jvc_decode, |
298 | .raw_register = ir_jvc_register, | ||
299 | .raw_unregister = ir_jvc_unregister, | ||
300 | }; | 166 | }; |
301 | 167 | ||
302 | static int __init ir_jvc_decode_init(void) | 168 | static int __init ir_jvc_decode_init(void) |
diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c index 94a8577e72eb..15a0f192d413 100644 --- a/drivers/media/IR/ir-keytable.c +++ b/drivers/media/IR/ir-keytable.c | |||
@@ -497,8 +497,9 @@ int __ir_input_register(struct input_dev *input_dev, | |||
497 | goto out_event; | 497 | goto out_event; |
498 | } | 498 | } |
499 | 499 | ||
500 | IR_dprintk(1, "Registered input device on %s for %s remote.\n", | 500 | IR_dprintk(1, "Registered input device on %s for %s remote%s.\n", |
501 | driver_name, rc_tab->name); | 501 | driver_name, rc_tab->name, |
502 | ir_dev->props->driver_type == RC_DRIVER_IR_RAW ? " in raw mode" : ""); | ||
502 | 503 | ||
503 | return 0; | 504 | return 0; |
504 | 505 | ||
diff --git a/drivers/media/IR/ir-lirc-codec.c b/drivers/media/IR/ir-lirc-codec.c new file mode 100644 index 000000000000..3ba482d96c4b --- /dev/null +++ b/drivers/media/IR/ir-lirc-codec.c | |||
@@ -0,0 +1,278 @@ | |||
1 | /* ir-lirc-codec.c - ir-core to classic lirc interface bridge | ||
2 | * | ||
3 | * Copyright (C) 2010 by Jarod Wilson <jarod@redhat.com> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation version 2 of the License. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | */ | ||
14 | |||
15 | #include <linux/sched.h> | ||
16 | #include <linux/wait.h> | ||
17 | #include <media/lirc.h> | ||
18 | #include <media/lirc_dev.h> | ||
19 | #include <media/ir-core.h> | ||
20 | #include "ir-core-priv.h" | ||
21 | |||
22 | #define LIRCBUF_SIZE 256 | ||
23 | |||
24 | /** | ||
25 | * ir_lirc_decode() - Send raw IR data to lirc_dev to be relayed to the | ||
26 | * lircd userspace daemon for decoding. | ||
27 | * @input_dev: the struct input_dev descriptor of the device | ||
28 | * @duration: the struct ir_raw_event descriptor of the pulse/space | ||
29 | * | ||
30 | * This function returns -EINVAL if the lirc interfaces aren't wired up. | ||
31 | */ | ||
32 | static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event ev) | ||
33 | { | ||
34 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
35 | |||
36 | if (!(ir_dev->raw->enabled_protocols & IR_TYPE_LIRC)) | ||
37 | return 0; | ||
38 | |||
39 | if (!ir_dev->raw->lirc.drv || !ir_dev->raw->lirc.drv->rbuf) | ||
40 | return -EINVAL; | ||
41 | |||
42 | IR_dprintk(2, "LIRC data transfer started (%uus %s)\n", | ||
43 | TO_US(ev.duration), TO_STR(ev.pulse)); | ||
44 | |||
45 | ir_dev->raw->lirc.lircdata += ev.duration / 1000; | ||
46 | if (ev.pulse) | ||
47 | ir_dev->raw->lirc.lircdata |= PULSE_BIT; | ||
48 | |||
49 | lirc_buffer_write(ir_dev->raw->lirc.drv->rbuf, | ||
50 | (unsigned char *) &ir_dev->raw->lirc.lircdata); | ||
51 | wake_up(&ir_dev->raw->lirc.drv->rbuf->wait_poll); | ||
52 | |||
53 | ir_dev->raw->lirc.lircdata = 0; | ||
54 | |||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | static ssize_t ir_lirc_transmit_ir(struct file *file, const char *buf, | ||
59 | size_t n, loff_t *ppos) | ||
60 | { | ||
61 | struct lirc_codec *lirc; | ||
62 | struct ir_input_dev *ir_dev; | ||
63 | int *txbuf; /* buffer with values to transmit */ | ||
64 | int ret = 0, count; | ||
65 | |||
66 | lirc = lirc_get_pdata(file); | ||
67 | if (!lirc) | ||
68 | return -EFAULT; | ||
69 | |||
70 | if (n % sizeof(int)) | ||
71 | return -EINVAL; | ||
72 | |||
73 | count = n / sizeof(int); | ||
74 | if (count > LIRCBUF_SIZE || count % 2 == 0) | ||
75 | return -EINVAL; | ||
76 | |||
77 | txbuf = memdup_user(buf, n); | ||
78 | if (IS_ERR(txbuf)) | ||
79 | return PTR_ERR(txbuf); | ||
80 | |||
81 | ir_dev = lirc->ir_dev; | ||
82 | if (!ir_dev) { | ||
83 | ret = -EFAULT; | ||
84 | goto out; | ||
85 | } | ||
86 | |||
87 | if (ir_dev->props && ir_dev->props->tx_ir) | ||
88 | ret = ir_dev->props->tx_ir(ir_dev->props->priv, txbuf, (u32)n); | ||
89 | |||
90 | out: | ||
91 | kfree(txbuf); | ||
92 | return ret; | ||
93 | } | ||
94 | |||
95 | static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) | ||
96 | { | ||
97 | struct lirc_codec *lirc; | ||
98 | struct ir_input_dev *ir_dev; | ||
99 | int ret = 0; | ||
100 | void *drv_data; | ||
101 | unsigned long val; | ||
102 | |||
103 | lirc = lirc_get_pdata(filep); | ||
104 | if (!lirc) | ||
105 | return -EFAULT; | ||
106 | |||
107 | ir_dev = lirc->ir_dev; | ||
108 | if (!ir_dev || !ir_dev->props || !ir_dev->props->priv) | ||
109 | return -EFAULT; | ||
110 | |||
111 | drv_data = ir_dev->props->priv; | ||
112 | |||
113 | switch (cmd) { | ||
114 | case LIRC_SET_TRANSMITTER_MASK: | ||
115 | ret = get_user(val, (unsigned long *)arg); | ||
116 | if (ret) | ||
117 | return ret; | ||
118 | |||
119 | if (ir_dev->props && ir_dev->props->s_tx_mask) | ||
120 | ret = ir_dev->props->s_tx_mask(drv_data, (u32)val); | ||
121 | else | ||
122 | return -EINVAL; | ||
123 | break; | ||
124 | |||
125 | case LIRC_SET_SEND_CARRIER: | ||
126 | ret = get_user(val, (unsigned long *)arg); | ||
127 | if (ret) | ||
128 | return ret; | ||
129 | |||
130 | if (ir_dev->props && ir_dev->props->s_tx_carrier) | ||
131 | ir_dev->props->s_tx_carrier(drv_data, (u32)val); | ||
132 | else | ||
133 | return -EINVAL; | ||
134 | break; | ||
135 | |||
136 | case LIRC_GET_SEND_MODE: | ||
137 | val = LIRC_CAN_SEND_PULSE & LIRC_CAN_SEND_MASK; | ||
138 | ret = put_user(val, (unsigned long *)arg); | ||
139 | break; | ||
140 | |||
141 | case LIRC_SET_SEND_MODE: | ||
142 | ret = get_user(val, (unsigned long *)arg); | ||
143 | if (ret) | ||
144 | return ret; | ||
145 | |||
146 | if (val != (LIRC_MODE_PULSE & LIRC_CAN_SEND_MASK)) | ||
147 | return -EINVAL; | ||
148 | break; | ||
149 | |||
150 | default: | ||
151 | return lirc_dev_fop_ioctl(filep, cmd, arg); | ||
152 | } | ||
153 | |||
154 | return ret; | ||
155 | } | ||
156 | |||
157 | static int ir_lirc_open(void *data) | ||
158 | { | ||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | static void ir_lirc_close(void *data) | ||
163 | { | ||
164 | return; | ||
165 | } | ||
166 | |||
167 | static struct file_operations lirc_fops = { | ||
168 | .owner = THIS_MODULE, | ||
169 | .write = ir_lirc_transmit_ir, | ||
170 | .unlocked_ioctl = ir_lirc_ioctl, | ||
171 | .read = lirc_dev_fop_read, | ||
172 | .poll = lirc_dev_fop_poll, | ||
173 | .open = lirc_dev_fop_open, | ||
174 | .release = lirc_dev_fop_close, | ||
175 | }; | ||
176 | |||
177 | static int ir_lirc_register(struct input_dev *input_dev) | ||
178 | { | ||
179 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
180 | struct lirc_driver *drv; | ||
181 | struct lirc_buffer *rbuf; | ||
182 | int rc = -ENOMEM; | ||
183 | unsigned long features; | ||
184 | |||
185 | drv = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL); | ||
186 | if (!drv) | ||
187 | return rc; | ||
188 | |||
189 | rbuf = kzalloc(sizeof(struct lirc_buffer), GFP_KERNEL); | ||
190 | if (!rbuf) | ||
191 | goto rbuf_alloc_failed; | ||
192 | |||
193 | rc = lirc_buffer_init(rbuf, sizeof(int), LIRCBUF_SIZE); | ||
194 | if (rc) | ||
195 | goto rbuf_init_failed; | ||
196 | |||
197 | features = LIRC_CAN_REC_MODE2; | ||
198 | if (ir_dev->props->tx_ir) { | ||
199 | features |= LIRC_CAN_SEND_PULSE; | ||
200 | if (ir_dev->props->s_tx_mask) | ||
201 | features |= LIRC_CAN_SET_TRANSMITTER_MASK; | ||
202 | if (ir_dev->props->s_tx_carrier) | ||
203 | features |= LIRC_CAN_SET_SEND_CARRIER; | ||
204 | } | ||
205 | |||
206 | snprintf(drv->name, sizeof(drv->name), "ir-lirc-codec (%s)", | ||
207 | ir_dev->driver_name); | ||
208 | drv->minor = -1; | ||
209 | drv->features = features; | ||
210 | drv->data = &ir_dev->raw->lirc; | ||
211 | drv->rbuf = rbuf; | ||
212 | drv->set_use_inc = &ir_lirc_open; | ||
213 | drv->set_use_dec = &ir_lirc_close; | ||
214 | drv->code_length = sizeof(struct ir_raw_event) * 8; | ||
215 | drv->fops = &lirc_fops; | ||
216 | drv->dev = &ir_dev->dev; | ||
217 | drv->owner = THIS_MODULE; | ||
218 | |||
219 | drv->minor = lirc_register_driver(drv); | ||
220 | if (drv->minor < 0) { | ||
221 | rc = -ENODEV; | ||
222 | goto lirc_register_failed; | ||
223 | } | ||
224 | |||
225 | ir_dev->raw->lirc.drv = drv; | ||
226 | ir_dev->raw->lirc.ir_dev = ir_dev; | ||
227 | ir_dev->raw->lirc.lircdata = PULSE_MASK; | ||
228 | |||
229 | return 0; | ||
230 | |||
231 | lirc_register_failed: | ||
232 | rbuf_init_failed: | ||
233 | kfree(rbuf); | ||
234 | rbuf_alloc_failed: | ||
235 | kfree(drv); | ||
236 | |||
237 | return rc; | ||
238 | } | ||
239 | |||
240 | static int ir_lirc_unregister(struct input_dev *input_dev) | ||
241 | { | ||
242 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
243 | struct lirc_codec *lirc = &ir_dev->raw->lirc; | ||
244 | |||
245 | lirc_unregister_driver(lirc->drv->minor); | ||
246 | lirc_buffer_free(lirc->drv->rbuf); | ||
247 | kfree(lirc->drv); | ||
248 | |||
249 | return 0; | ||
250 | } | ||
251 | |||
252 | static struct ir_raw_handler lirc_handler = { | ||
253 | .protocols = IR_TYPE_LIRC, | ||
254 | .decode = ir_lirc_decode, | ||
255 | .raw_register = ir_lirc_register, | ||
256 | .raw_unregister = ir_lirc_unregister, | ||
257 | }; | ||
258 | |||
259 | static int __init ir_lirc_codec_init(void) | ||
260 | { | ||
261 | ir_raw_handler_register(&lirc_handler); | ||
262 | |||
263 | printk(KERN_INFO "IR LIRC bridge handler initialized\n"); | ||
264 | return 0; | ||
265 | } | ||
266 | |||
267 | static void __exit ir_lirc_codec_exit(void) | ||
268 | { | ||
269 | ir_raw_handler_unregister(&lirc_handler); | ||
270 | } | ||
271 | |||
272 | module_init(ir_lirc_codec_init); | ||
273 | module_exit(ir_lirc_codec_exit); | ||
274 | |||
275 | MODULE_LICENSE("GPL"); | ||
276 | MODULE_AUTHOR("Jarod Wilson <jarod@redhat.com>"); | ||
277 | MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)"); | ||
278 | MODULE_DESCRIPTION("LIRC IR handler bridge"); | ||
diff --git a/drivers/media/IR/ir-nec-decoder.c b/drivers/media/IR/ir-nec-decoder.c index ba79233112ef..52e0f378ae3d 100644 --- a/drivers/media/IR/ir-nec-decoder.c +++ b/drivers/media/IR/ir-nec-decoder.c | |||
@@ -27,10 +27,6 @@ | |||
27 | #define NEC_TRAILER_PULSE (1 * NEC_UNIT) | 27 | #define NEC_TRAILER_PULSE (1 * NEC_UNIT) |
28 | #define NEC_TRAILER_SPACE (10 * NEC_UNIT) /* even longer in reality */ | 28 | #define NEC_TRAILER_SPACE (10 * NEC_UNIT) /* even longer in reality */ |
29 | 29 | ||
30 | /* Used to register nec_decoder clients */ | ||
31 | static LIST_HEAD(decoder_list); | ||
32 | static DEFINE_SPINLOCK(decoder_lock); | ||
33 | |||
34 | enum nec_state { | 30 | enum nec_state { |
35 | STATE_INACTIVE, | 31 | STATE_INACTIVE, |
36 | STATE_HEADER_SPACE, | 32 | STATE_HEADER_SPACE, |
@@ -40,84 +36,6 @@ enum nec_state { | |||
40 | STATE_TRAILER_SPACE, | 36 | STATE_TRAILER_SPACE, |
41 | }; | 37 | }; |
42 | 38 | ||
43 | struct decoder_data { | ||
44 | struct list_head list; | ||
45 | struct ir_input_dev *ir_dev; | ||
46 | int enabled:1; | ||
47 | |||
48 | /* State machine control */ | ||
49 | enum nec_state state; | ||
50 | u32 nec_bits; | ||
51 | unsigned count; | ||
52 | }; | ||
53 | |||
54 | |||
55 | /** | ||
56 | * get_decoder_data() - gets decoder data | ||
57 | * @input_dev: input device | ||
58 | * | ||
59 | * Returns the struct decoder_data that corresponds to a device | ||
60 | */ | ||
61 | static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev) | ||
62 | { | ||
63 | struct decoder_data *data = NULL; | ||
64 | |||
65 | spin_lock(&decoder_lock); | ||
66 | list_for_each_entry(data, &decoder_list, list) { | ||
67 | if (data->ir_dev == ir_dev) | ||
68 | break; | ||
69 | } | ||
70 | spin_unlock(&decoder_lock); | ||
71 | return data; | ||
72 | } | ||
73 | |||
74 | static ssize_t store_enabled(struct device *d, | ||
75 | struct device_attribute *mattr, | ||
76 | const char *buf, | ||
77 | size_t len) | ||
78 | { | ||
79 | unsigned long value; | ||
80 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | ||
81 | struct decoder_data *data = get_decoder_data(ir_dev); | ||
82 | |||
83 | if (!data) | ||
84 | return -EINVAL; | ||
85 | |||
86 | if (strict_strtoul(buf, 10, &value) || value > 1) | ||
87 | return -EINVAL; | ||
88 | |||
89 | data->enabled = value; | ||
90 | |||
91 | return len; | ||
92 | } | ||
93 | |||
94 | static ssize_t show_enabled(struct device *d, | ||
95 | struct device_attribute *mattr, char *buf) | ||
96 | { | ||
97 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | ||
98 | struct decoder_data *data = get_decoder_data(ir_dev); | ||
99 | |||
100 | if (!data) | ||
101 | return -EINVAL; | ||
102 | |||
103 | if (data->enabled) | ||
104 | return sprintf(buf, "1\n"); | ||
105 | else | ||
106 | return sprintf(buf, "0\n"); | ||
107 | } | ||
108 | |||
109 | static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled); | ||
110 | |||
111 | static struct attribute *decoder_attributes[] = { | ||
112 | &dev_attr_enabled.attr, | ||
113 | NULL | ||
114 | }; | ||
115 | |||
116 | static struct attribute_group decoder_attribute_group = { | ||
117 | .name = "nec_decoder", | ||
118 | .attrs = decoder_attributes, | ||
119 | }; | ||
120 | |||
121 | /** | 39 | /** |
122 | * ir_nec_decode() - Decode one NEC pulse or space | 40 | * ir_nec_decode() - Decode one NEC pulse or space |
123 | * @input_dev: the struct input_dev descriptor of the device | 41 | * @input_dev: the struct input_dev descriptor of the device |
@@ -127,16 +45,12 @@ static struct attribute_group decoder_attribute_group = { | |||
127 | */ | 45 | */ |
128 | static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev) | 46 | static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev) |
129 | { | 47 | { |
130 | struct decoder_data *data; | ||
131 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | 48 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); |
49 | struct nec_dec *data = &ir_dev->raw->nec; | ||
132 | u32 scancode; | 50 | u32 scancode; |
133 | u8 address, not_address, command, not_command; | 51 | u8 address, not_address, command, not_command; |
134 | 52 | ||
135 | data = get_decoder_data(ir_dev); | 53 | if (!(ir_dev->raw->enabled_protocols & IR_TYPE_NEC)) |
136 | if (!data) | ||
137 | return -EINVAL; | ||
138 | |||
139 | if (!data->enabled) | ||
140 | return 0; | 54 | return 0; |
141 | 55 | ||
142 | if (IS_RESET(ev)) { | 56 | if (IS_RESET(ev)) { |
@@ -191,9 +105,9 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev) | |||
191 | if (ev.pulse) | 105 | if (ev.pulse) |
192 | break; | 106 | break; |
193 | 107 | ||
194 | data->nec_bits <<= 1; | 108 | data->bits <<= 1; |
195 | if (eq_margin(ev.duration, NEC_BIT_1_SPACE, NEC_UNIT / 2)) | 109 | if (eq_margin(ev.duration, NEC_BIT_1_SPACE, NEC_UNIT / 2)) |
196 | data->nec_bits |= 1; | 110 | data->bits |= 1; |
197 | else if (!eq_margin(ev.duration, NEC_BIT_0_SPACE, NEC_UNIT / 2)) | 111 | else if (!eq_margin(ev.duration, NEC_BIT_0_SPACE, NEC_UNIT / 2)) |
198 | break; | 112 | break; |
199 | data->count++; | 113 | data->count++; |
@@ -222,14 +136,14 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev) | |||
222 | if (!geq_margin(ev.duration, NEC_TRAILER_SPACE, NEC_UNIT / 2)) | 136 | if (!geq_margin(ev.duration, NEC_TRAILER_SPACE, NEC_UNIT / 2)) |
223 | break; | 137 | break; |
224 | 138 | ||
225 | address = bitrev8((data->nec_bits >> 24) & 0xff); | 139 | address = bitrev8((data->bits >> 24) & 0xff); |
226 | not_address = bitrev8((data->nec_bits >> 16) & 0xff); | 140 | not_address = bitrev8((data->bits >> 16) & 0xff); |
227 | command = bitrev8((data->nec_bits >> 8) & 0xff); | 141 | command = bitrev8((data->bits >> 8) & 0xff); |
228 | not_command = bitrev8((data->nec_bits >> 0) & 0xff); | 142 | not_command = bitrev8((data->bits >> 0) & 0xff); |
229 | 143 | ||
230 | if ((command ^ not_command) != 0xff) { | 144 | if ((command ^ not_command) != 0xff) { |
231 | IR_dprintk(1, "NEC checksum error: received 0x%08x\n", | 145 | IR_dprintk(1, "NEC checksum error: received 0x%08x\n", |
232 | data->nec_bits); | 146 | data->bits); |
233 | break; | 147 | break; |
234 | } | 148 | } |
235 | 149 | ||
@@ -256,54 +170,9 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev) | |||
256 | return -EINVAL; | 170 | return -EINVAL; |
257 | } | 171 | } |
258 | 172 | ||
259 | static int ir_nec_register(struct input_dev *input_dev) | ||
260 | { | ||
261 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
262 | struct decoder_data *data; | ||
263 | int rc; | ||
264 | |||
265 | rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group); | ||
266 | if (rc < 0) | ||
267 | return rc; | ||
268 | |||
269 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
270 | if (!data) { | ||
271 | sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group); | ||
272 | return -ENOMEM; | ||
273 | } | ||
274 | |||
275 | data->ir_dev = ir_dev; | ||
276 | data->enabled = 1; | ||
277 | |||
278 | spin_lock(&decoder_lock); | ||
279 | list_add_tail(&data->list, &decoder_list); | ||
280 | spin_unlock(&decoder_lock); | ||
281 | |||
282 | return 0; | ||
283 | } | ||
284 | |||
285 | static int ir_nec_unregister(struct input_dev *input_dev) | ||
286 | { | ||
287 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
288 | static struct decoder_data *data; | ||
289 | |||
290 | data = get_decoder_data(ir_dev); | ||
291 | if (!data) | ||
292 | return 0; | ||
293 | |||
294 | sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group); | ||
295 | |||
296 | spin_lock(&decoder_lock); | ||
297 | list_del(&data->list); | ||
298 | spin_unlock(&decoder_lock); | ||
299 | |||
300 | return 0; | ||
301 | } | ||
302 | |||
303 | static struct ir_raw_handler nec_handler = { | 173 | static struct ir_raw_handler nec_handler = { |
174 | .protocols = IR_TYPE_NEC, | ||
304 | .decode = ir_nec_decode, | 175 | .decode = ir_nec_decode, |
305 | .raw_register = ir_nec_register, | ||
306 | .raw_unregister = ir_nec_unregister, | ||
307 | }; | 176 | }; |
308 | 177 | ||
309 | static int __init ir_nec_decode_init(void) | 178 | static int __init ir_nec_decode_init(void) |
diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c index ea68a3f2effa..6f192ef31db1 100644 --- a/drivers/media/IR/ir-raw-event.c +++ b/drivers/media/IR/ir-raw-event.c | |||
@@ -20,35 +20,13 @@ | |||
20 | /* Define the max number of pulse/space transitions to buffer */ | 20 | /* Define the max number of pulse/space transitions to buffer */ |
21 | #define MAX_IR_EVENT_SIZE 512 | 21 | #define MAX_IR_EVENT_SIZE 512 |
22 | 22 | ||
23 | /* Used to keep track of IR raw clients, protected by ir_raw_handler_lock */ | ||
24 | static LIST_HEAD(ir_raw_client_list); | ||
25 | |||
23 | /* Used to handle IR raw handler extensions */ | 26 | /* Used to handle IR raw handler extensions */ |
24 | static LIST_HEAD(ir_raw_handler_list); | ||
25 | static DEFINE_SPINLOCK(ir_raw_handler_lock); | 27 | static DEFINE_SPINLOCK(ir_raw_handler_lock); |
26 | 28 | static LIST_HEAD(ir_raw_handler_list); | |
27 | /** | 29 | static u64 available_protocols; |
28 | * RUN_DECODER() - runs an operation on all IR decoders | ||
29 | * @ops: IR raw handler operation to be called | ||
30 | * @arg: arguments to be passed to the callback | ||
31 | * | ||
32 | * Calls ir_raw_handler::ops for all registered IR handlers. It prevents | ||
33 | * new decode addition/removal while running, by locking ir_raw_handler_lock | ||
34 | * mutex. If an error occurs, it stops the ops. Otherwise, it returns a sum | ||
35 | * of the return codes. | ||
36 | */ | ||
37 | #define RUN_DECODER(ops, ...) ({ \ | ||
38 | struct ir_raw_handler *_ir_raw_handler; \ | ||
39 | int _sumrc = 0, _rc; \ | ||
40 | spin_lock(&ir_raw_handler_lock); \ | ||
41 | list_for_each_entry(_ir_raw_handler, &ir_raw_handler_list, list) { \ | ||
42 | if (_ir_raw_handler->ops) { \ | ||
43 | _rc = _ir_raw_handler->ops(__VA_ARGS__); \ | ||
44 | if (_rc < 0) \ | ||
45 | break; \ | ||
46 | _sumrc += _rc; \ | ||
47 | } \ | ||
48 | } \ | ||
49 | spin_unlock(&ir_raw_handler_lock); \ | ||
50 | _sumrc; \ | ||
51 | }) | ||
52 | 30 | ||
53 | #ifdef MODULE | 31 | #ifdef MODULE |
54 | /* Used to load the decoders */ | 32 | /* Used to load the decoders */ |
@@ -58,57 +36,17 @@ static struct work_struct wq_load; | |||
58 | static void ir_raw_event_work(struct work_struct *work) | 36 | static void ir_raw_event_work(struct work_struct *work) |
59 | { | 37 | { |
60 | struct ir_raw_event ev; | 38 | struct ir_raw_event ev; |
39 | struct ir_raw_handler *handler; | ||
61 | struct ir_raw_event_ctrl *raw = | 40 | struct ir_raw_event_ctrl *raw = |
62 | container_of(work, struct ir_raw_event_ctrl, rx_work); | 41 | container_of(work, struct ir_raw_event_ctrl, rx_work); |
63 | 42 | ||
64 | while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) | 43 | while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) { |
65 | RUN_DECODER(decode, raw->input_dev, ev); | 44 | spin_lock(&ir_raw_handler_lock); |
66 | } | 45 | list_for_each_entry(handler, &ir_raw_handler_list, list) |
67 | 46 | handler->decode(raw->input_dev, ev); | |
68 | int ir_raw_event_register(struct input_dev *input_dev) | 47 | spin_unlock(&ir_raw_handler_lock); |
69 | { | 48 | raw->prev_ev = ev; |
70 | struct ir_input_dev *ir = input_get_drvdata(input_dev); | ||
71 | int rc; | ||
72 | |||
73 | ir->raw = kzalloc(sizeof(*ir->raw), GFP_KERNEL); | ||
74 | if (!ir->raw) | ||
75 | return -ENOMEM; | ||
76 | |||
77 | ir->raw->input_dev = input_dev; | ||
78 | INIT_WORK(&ir->raw->rx_work, ir_raw_event_work); | ||
79 | |||
80 | rc = kfifo_alloc(&ir->raw->kfifo, sizeof(s64) * MAX_IR_EVENT_SIZE, | ||
81 | GFP_KERNEL); | ||
82 | if (rc < 0) { | ||
83 | kfree(ir->raw); | ||
84 | ir->raw = NULL; | ||
85 | return rc; | ||
86 | } | ||
87 | |||
88 | rc = RUN_DECODER(raw_register, input_dev); | ||
89 | if (rc < 0) { | ||
90 | kfifo_free(&ir->raw->kfifo); | ||
91 | kfree(ir->raw); | ||
92 | ir->raw = NULL; | ||
93 | return rc; | ||
94 | } | 49 | } |
95 | |||
96 | return rc; | ||
97 | } | ||
98 | |||
99 | void ir_raw_event_unregister(struct input_dev *input_dev) | ||
100 | { | ||
101 | struct ir_input_dev *ir = input_get_drvdata(input_dev); | ||
102 | |||
103 | if (!ir->raw) | ||
104 | return; | ||
105 | |||
106 | cancel_work_sync(&ir->raw->rx_work); | ||
107 | RUN_DECODER(raw_unregister, input_dev); | ||
108 | |||
109 | kfifo_free(&ir->raw->kfifo); | ||
110 | kfree(ir->raw); | ||
111 | ir->raw = NULL; | ||
112 | } | 50 | } |
113 | 51 | ||
114 | /** | 52 | /** |
@@ -204,23 +142,103 @@ void ir_raw_event_handle(struct input_dev *input_dev) | |||
204 | } | 142 | } |
205 | EXPORT_SYMBOL_GPL(ir_raw_event_handle); | 143 | EXPORT_SYMBOL_GPL(ir_raw_event_handle); |
206 | 144 | ||
145 | /* used internally by the sysfs interface */ | ||
146 | u64 | ||
147 | ir_raw_get_allowed_protocols() | ||
148 | { | ||
149 | u64 protocols; | ||
150 | spin_lock(&ir_raw_handler_lock); | ||
151 | protocols = available_protocols; | ||
152 | spin_unlock(&ir_raw_handler_lock); | ||
153 | return protocols; | ||
154 | } | ||
155 | |||
156 | /* | ||
157 | * Used to (un)register raw event clients | ||
158 | */ | ||
159 | int ir_raw_event_register(struct input_dev *input_dev) | ||
160 | { | ||
161 | struct ir_input_dev *ir = input_get_drvdata(input_dev); | ||
162 | int rc; | ||
163 | struct ir_raw_handler *handler; | ||
164 | |||
165 | ir->raw = kzalloc(sizeof(*ir->raw), GFP_KERNEL); | ||
166 | if (!ir->raw) | ||
167 | return -ENOMEM; | ||
168 | |||
169 | ir->raw->input_dev = input_dev; | ||
170 | INIT_WORK(&ir->raw->rx_work, ir_raw_event_work); | ||
171 | ir->raw->enabled_protocols = ~0; | ||
172 | rc = kfifo_alloc(&ir->raw->kfifo, sizeof(s64) * MAX_IR_EVENT_SIZE, | ||
173 | GFP_KERNEL); | ||
174 | if (rc < 0) { | ||
175 | kfree(ir->raw); | ||
176 | ir->raw = NULL; | ||
177 | return rc; | ||
178 | } | ||
179 | |||
180 | spin_lock(&ir_raw_handler_lock); | ||
181 | list_add_tail(&ir->raw->list, &ir_raw_client_list); | ||
182 | list_for_each_entry(handler, &ir_raw_handler_list, list) | ||
183 | if (handler->raw_register) | ||
184 | handler->raw_register(ir->raw->input_dev); | ||
185 | spin_unlock(&ir_raw_handler_lock); | ||
186 | |||
187 | return 0; | ||
188 | } | ||
189 | |||
190 | void ir_raw_event_unregister(struct input_dev *input_dev) | ||
191 | { | ||
192 | struct ir_input_dev *ir = input_get_drvdata(input_dev); | ||
193 | struct ir_raw_handler *handler; | ||
194 | |||
195 | if (!ir->raw) | ||
196 | return; | ||
197 | |||
198 | cancel_work_sync(&ir->raw->rx_work); | ||
199 | |||
200 | spin_lock(&ir_raw_handler_lock); | ||
201 | list_del(&ir->raw->list); | ||
202 | list_for_each_entry(handler, &ir_raw_handler_list, list) | ||
203 | if (handler->raw_unregister) | ||
204 | handler->raw_unregister(ir->raw->input_dev); | ||
205 | spin_unlock(&ir_raw_handler_lock); | ||
206 | |||
207 | kfifo_free(&ir->raw->kfifo); | ||
208 | kfree(ir->raw); | ||
209 | ir->raw = NULL; | ||
210 | } | ||
211 | |||
207 | /* | 212 | /* |
208 | * Extension interface - used to register the IR decoders | 213 | * Extension interface - used to register the IR decoders |
209 | */ | 214 | */ |
210 | 215 | ||
211 | int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler) | 216 | int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler) |
212 | { | 217 | { |
218 | struct ir_raw_event_ctrl *raw; | ||
219 | |||
213 | spin_lock(&ir_raw_handler_lock); | 220 | spin_lock(&ir_raw_handler_lock); |
214 | list_add_tail(&ir_raw_handler->list, &ir_raw_handler_list); | 221 | list_add_tail(&ir_raw_handler->list, &ir_raw_handler_list); |
222 | if (ir_raw_handler->raw_register) | ||
223 | list_for_each_entry(raw, &ir_raw_client_list, list) | ||
224 | ir_raw_handler->raw_register(raw->input_dev); | ||
225 | available_protocols |= ir_raw_handler->protocols; | ||
215 | spin_unlock(&ir_raw_handler_lock); | 226 | spin_unlock(&ir_raw_handler_lock); |
227 | |||
216 | return 0; | 228 | return 0; |
217 | } | 229 | } |
218 | EXPORT_SYMBOL(ir_raw_handler_register); | 230 | EXPORT_SYMBOL(ir_raw_handler_register); |
219 | 231 | ||
220 | void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler) | 232 | void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler) |
221 | { | 233 | { |
234 | struct ir_raw_event_ctrl *raw; | ||
235 | |||
222 | spin_lock(&ir_raw_handler_lock); | 236 | spin_lock(&ir_raw_handler_lock); |
223 | list_del(&ir_raw_handler->list); | 237 | list_del(&ir_raw_handler->list); |
238 | if (ir_raw_handler->raw_unregister) | ||
239 | list_for_each_entry(raw, &ir_raw_client_list, list) | ||
240 | ir_raw_handler->raw_unregister(raw->input_dev); | ||
241 | available_protocols &= ~ir_raw_handler->protocols; | ||
224 | spin_unlock(&ir_raw_handler_lock); | 242 | spin_unlock(&ir_raw_handler_lock); |
225 | } | 243 | } |
226 | EXPORT_SYMBOL(ir_raw_handler_unregister); | 244 | EXPORT_SYMBOL(ir_raw_handler_unregister); |
@@ -235,6 +253,7 @@ static void init_decoders(struct work_struct *work) | |||
235 | load_rc6_decode(); | 253 | load_rc6_decode(); |
236 | load_jvc_decode(); | 254 | load_jvc_decode(); |
237 | load_sony_decode(); | 255 | load_sony_decode(); |
256 | load_lirc_codec(); | ||
238 | 257 | ||
239 | /* If needed, we may later add some init code. In this case, | 258 | /* If needed, we may later add some init code. In this case, |
240 | it is needed to change the CONFIG_MODULE test at ir-core.h | 259 | it is needed to change the CONFIG_MODULE test at ir-core.h |
diff --git a/drivers/media/IR/ir-rc5-decoder.c b/drivers/media/IR/ir-rc5-decoder.c index 23cdb1b1a3bc..df4770d978ad 100644 --- a/drivers/media/IR/ir-rc5-decoder.c +++ b/drivers/media/IR/ir-rc5-decoder.c | |||
@@ -30,10 +30,6 @@ | |||
30 | #define RC5_BIT_END (1 * RC5_UNIT) | 30 | #define RC5_BIT_END (1 * RC5_UNIT) |
31 | #define RC5X_SPACE (4 * RC5_UNIT) | 31 | #define RC5X_SPACE (4 * RC5_UNIT) |
32 | 32 | ||
33 | /* Used to register rc5_decoder clients */ | ||
34 | static LIST_HEAD(decoder_list); | ||
35 | static DEFINE_SPINLOCK(decoder_lock); | ||
36 | |||
37 | enum rc5_state { | 33 | enum rc5_state { |
38 | STATE_INACTIVE, | 34 | STATE_INACTIVE, |
39 | STATE_BIT_START, | 35 | STATE_BIT_START, |
@@ -42,87 +38,6 @@ enum rc5_state { | |||
42 | STATE_FINISHED, | 38 | STATE_FINISHED, |
43 | }; | 39 | }; |
44 | 40 | ||
45 | struct decoder_data { | ||
46 | struct list_head list; | ||
47 | struct ir_input_dev *ir_dev; | ||
48 | int enabled:1; | ||
49 | |||
50 | /* State machine control */ | ||
51 | enum rc5_state state; | ||
52 | u32 rc5_bits; | ||
53 | struct ir_raw_event prev_ev; | ||
54 | unsigned count; | ||
55 | unsigned wanted_bits; | ||
56 | }; | ||
57 | |||
58 | |||
59 | /** | ||
60 | * get_decoder_data() - gets decoder data | ||
61 | * @input_dev: input device | ||
62 | * | ||
63 | * Returns the struct decoder_data that corresponds to a device | ||
64 | */ | ||
65 | |||
66 | static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev) | ||
67 | { | ||
68 | struct decoder_data *data = NULL; | ||
69 | |||
70 | spin_lock(&decoder_lock); | ||
71 | list_for_each_entry(data, &decoder_list, list) { | ||
72 | if (data->ir_dev == ir_dev) | ||
73 | break; | ||
74 | } | ||
75 | spin_unlock(&decoder_lock); | ||
76 | return data; | ||
77 | } | ||
78 | |||
79 | static ssize_t store_enabled(struct device *d, | ||
80 | struct device_attribute *mattr, | ||
81 | const char *buf, | ||
82 | size_t len) | ||
83 | { | ||
84 | unsigned long value; | ||
85 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | ||
86 | struct decoder_data *data = get_decoder_data(ir_dev); | ||
87 | |||
88 | if (!data) | ||
89 | return -EINVAL; | ||
90 | |||
91 | if (strict_strtoul(buf, 10, &value) || value > 1) | ||
92 | return -EINVAL; | ||
93 | |||
94 | data->enabled = value; | ||
95 | |||
96 | return len; | ||
97 | } | ||
98 | |||
99 | static ssize_t show_enabled(struct device *d, | ||
100 | struct device_attribute *mattr, char *buf) | ||
101 | { | ||
102 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | ||
103 | struct decoder_data *data = get_decoder_data(ir_dev); | ||
104 | |||
105 | if (!data) | ||
106 | return -EINVAL; | ||
107 | |||
108 | if (data->enabled) | ||
109 | return sprintf(buf, "1\n"); | ||
110 | else | ||
111 | return sprintf(buf, "0\n"); | ||
112 | } | ||
113 | |||
114 | static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled); | ||
115 | |||
116 | static struct attribute *decoder_attributes[] = { | ||
117 | &dev_attr_enabled.attr, | ||
118 | NULL | ||
119 | }; | ||
120 | |||
121 | static struct attribute_group decoder_attribute_group = { | ||
122 | .name = "rc5_decoder", | ||
123 | .attrs = decoder_attributes, | ||
124 | }; | ||
125 | |||
126 | /** | 41 | /** |
127 | * ir_rc5_decode() - Decode one RC-5 pulse or space | 42 | * ir_rc5_decode() - Decode one RC-5 pulse or space |
128 | * @input_dev: the struct input_dev descriptor of the device | 43 | * @input_dev: the struct input_dev descriptor of the device |
@@ -132,17 +47,13 @@ static struct attribute_group decoder_attribute_group = { | |||
132 | */ | 47 | */ |
133 | static int ir_rc5_decode(struct input_dev *input_dev, struct ir_raw_event ev) | 48 | static int ir_rc5_decode(struct input_dev *input_dev, struct ir_raw_event ev) |
134 | { | 49 | { |
135 | struct decoder_data *data; | ||
136 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | 50 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); |
51 | struct rc5_dec *data = &ir_dev->raw->rc5; | ||
137 | u8 toggle; | 52 | u8 toggle; |
138 | u32 scancode; | 53 | u32 scancode; |
139 | 54 | ||
140 | data = get_decoder_data(ir_dev); | 55 | if (!(ir_dev->raw->enabled_protocols & IR_TYPE_RC5)) |
141 | if (!data) | 56 | return 0; |
142 | return -EINVAL; | ||
143 | |||
144 | if (!data->enabled) | ||
145 | return 0; | ||
146 | 57 | ||
147 | if (IS_RESET(ev)) { | 58 | if (IS_RESET(ev)) { |
148 | data->state = STATE_INACTIVE; | 59 | data->state = STATE_INACTIVE; |
@@ -176,16 +87,15 @@ again: | |||
176 | if (!eq_margin(ev.duration, RC5_BIT_START, RC5_UNIT / 2)) | 87 | if (!eq_margin(ev.duration, RC5_BIT_START, RC5_UNIT / 2)) |
177 | break; | 88 | break; |
178 | 89 | ||
179 | data->rc5_bits <<= 1; | 90 | data->bits <<= 1; |
180 | if (!ev.pulse) | 91 | if (!ev.pulse) |
181 | data->rc5_bits |= 1; | 92 | data->bits |= 1; |
182 | data->count++; | 93 | data->count++; |
183 | data->prev_ev = ev; | ||
184 | data->state = STATE_BIT_END; | 94 | data->state = STATE_BIT_END; |
185 | return 0; | 95 | return 0; |
186 | 96 | ||
187 | case STATE_BIT_END: | 97 | case STATE_BIT_END: |
188 | if (!is_transition(&ev, &data->prev_ev)) | 98 | if (!is_transition(&ev, &ir_dev->raw->prev_ev)) |
189 | break; | 99 | break; |
190 | 100 | ||
191 | if (data->count == data->wanted_bits) | 101 | if (data->count == data->wanted_bits) |
@@ -217,11 +127,11 @@ again: | |||
217 | if (data->wanted_bits == RC5X_NBITS) { | 127 | if (data->wanted_bits == RC5X_NBITS) { |
218 | /* RC5X */ | 128 | /* RC5X */ |
219 | u8 xdata, command, system; | 129 | u8 xdata, command, system; |
220 | xdata = (data->rc5_bits & 0x0003F) >> 0; | 130 | xdata = (data->bits & 0x0003F) >> 0; |
221 | command = (data->rc5_bits & 0x00FC0) >> 6; | 131 | command = (data->bits & 0x00FC0) >> 6; |
222 | system = (data->rc5_bits & 0x1F000) >> 12; | 132 | system = (data->bits & 0x1F000) >> 12; |
223 | toggle = (data->rc5_bits & 0x20000) ? 1 : 0; | 133 | toggle = (data->bits & 0x20000) ? 1 : 0; |
224 | command += (data->rc5_bits & 0x01000) ? 0 : 0x40; | 134 | command += (data->bits & 0x01000) ? 0 : 0x40; |
225 | scancode = system << 16 | command << 8 | xdata; | 135 | scancode = system << 16 | command << 8 | xdata; |
226 | 136 | ||
227 | IR_dprintk(1, "RC5X scancode 0x%06x (toggle: %u)\n", | 137 | IR_dprintk(1, "RC5X scancode 0x%06x (toggle: %u)\n", |
@@ -230,10 +140,10 @@ again: | |||
230 | } else { | 140 | } else { |
231 | /* RC5 */ | 141 | /* RC5 */ |
232 | u8 command, system; | 142 | u8 command, system; |
233 | command = (data->rc5_bits & 0x0003F) >> 0; | 143 | command = (data->bits & 0x0003F) >> 0; |
234 | system = (data->rc5_bits & 0x007C0) >> 6; | 144 | system = (data->bits & 0x007C0) >> 6; |
235 | toggle = (data->rc5_bits & 0x00800) ? 1 : 0; | 145 | toggle = (data->bits & 0x00800) ? 1 : 0; |
236 | command += (data->rc5_bits & 0x01000) ? 0 : 0x40; | 146 | command += (data->bits & 0x01000) ? 0 : 0x40; |
237 | scancode = system << 8 | command; | 147 | scancode = system << 8 | command; |
238 | 148 | ||
239 | IR_dprintk(1, "RC5 scancode 0x%04x (toggle: %u)\n", | 149 | IR_dprintk(1, "RC5 scancode 0x%04x (toggle: %u)\n", |
@@ -252,54 +162,9 @@ out: | |||
252 | return -EINVAL; | 162 | return -EINVAL; |
253 | } | 163 | } |
254 | 164 | ||
255 | static int ir_rc5_register(struct input_dev *input_dev) | ||
256 | { | ||
257 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
258 | struct decoder_data *data; | ||
259 | int rc; | ||
260 | |||
261 | rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group); | ||
262 | if (rc < 0) | ||
263 | return rc; | ||
264 | |||
265 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
266 | if (!data) { | ||
267 | sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group); | ||
268 | return -ENOMEM; | ||
269 | } | ||
270 | |||
271 | data->ir_dev = ir_dev; | ||
272 | data->enabled = 1; | ||
273 | |||
274 | spin_lock(&decoder_lock); | ||
275 | list_add_tail(&data->list, &decoder_list); | ||
276 | spin_unlock(&decoder_lock); | ||
277 | |||
278 | return 0; | ||
279 | } | ||
280 | |||
281 | static int ir_rc5_unregister(struct input_dev *input_dev) | ||
282 | { | ||
283 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
284 | static struct decoder_data *data; | ||
285 | |||
286 | data = get_decoder_data(ir_dev); | ||
287 | if (!data) | ||
288 | return 0; | ||
289 | |||
290 | sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group); | ||
291 | |||
292 | spin_lock(&decoder_lock); | ||
293 | list_del(&data->list); | ||
294 | spin_unlock(&decoder_lock); | ||
295 | |||
296 | return 0; | ||
297 | } | ||
298 | |||
299 | static struct ir_raw_handler rc5_handler = { | 165 | static struct ir_raw_handler rc5_handler = { |
166 | .protocols = IR_TYPE_RC5, | ||
300 | .decode = ir_rc5_decode, | 167 | .decode = ir_rc5_decode, |
301 | .raw_register = ir_rc5_register, | ||
302 | .raw_unregister = ir_rc5_unregister, | ||
303 | }; | 168 | }; |
304 | 169 | ||
305 | static int __init ir_rc5_decode_init(void) | 170 | static int __init ir_rc5_decode_init(void) |
diff --git a/drivers/media/IR/ir-rc6-decoder.c b/drivers/media/IR/ir-rc6-decoder.c index 2bf479f4f1bc..f1624b8279bc 100644 --- a/drivers/media/IR/ir-rc6-decoder.c +++ b/drivers/media/IR/ir-rc6-decoder.c | |||
@@ -36,10 +36,6 @@ | |||
36 | #define RC6_STARTBIT_MASK 0x08 /* for the header bits */ | 36 | #define RC6_STARTBIT_MASK 0x08 /* for the header bits */ |
37 | #define RC6_6A_MCE_TOGGLE_MASK 0x8000 /* for the body bits */ | 37 | #define RC6_6A_MCE_TOGGLE_MASK 0x8000 /* for the body bits */ |
38 | 38 | ||
39 | /* Used to register rc6_decoder clients */ | ||
40 | static LIST_HEAD(decoder_list); | ||
41 | static DEFINE_SPINLOCK(decoder_lock); | ||
42 | |||
43 | enum rc6_mode { | 39 | enum rc6_mode { |
44 | RC6_MODE_0, | 40 | RC6_MODE_0, |
45 | RC6_MODE_6A, | 41 | RC6_MODE_6A, |
@@ -58,89 +54,8 @@ enum rc6_state { | |||
58 | STATE_FINISHED, | 54 | STATE_FINISHED, |
59 | }; | 55 | }; |
60 | 56 | ||
61 | struct decoder_data { | 57 | static enum rc6_mode rc6_mode(struct rc6_dec *data) |
62 | struct list_head list; | ||
63 | struct ir_input_dev *ir_dev; | ||
64 | int enabled:1; | ||
65 | |||
66 | /* State machine control */ | ||
67 | enum rc6_state state; | ||
68 | u8 header; | ||
69 | u32 body; | ||
70 | struct ir_raw_event prev_ev; | ||
71 | bool toggle; | ||
72 | unsigned count; | ||
73 | unsigned wanted_bits; | ||
74 | }; | ||
75 | |||
76 | |||
77 | /** | ||
78 | * get_decoder_data() - gets decoder data | ||
79 | * @input_dev: input device | ||
80 | * | ||
81 | * Returns the struct decoder_data that corresponds to a device | ||
82 | */ | ||
83 | static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev) | ||
84 | { | ||
85 | struct decoder_data *data = NULL; | ||
86 | |||
87 | spin_lock(&decoder_lock); | ||
88 | list_for_each_entry(data, &decoder_list, list) { | ||
89 | if (data->ir_dev == ir_dev) | ||
90 | break; | ||
91 | } | ||
92 | spin_unlock(&decoder_lock); | ||
93 | return data; | ||
94 | } | ||
95 | |||
96 | static ssize_t store_enabled(struct device *d, | ||
97 | struct device_attribute *mattr, | ||
98 | const char *buf, | ||
99 | size_t len) | ||
100 | { | 58 | { |
101 | unsigned long value; | ||
102 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | ||
103 | struct decoder_data *data = get_decoder_data(ir_dev); | ||
104 | |||
105 | if (!data) | ||
106 | return -EINVAL; | ||
107 | |||
108 | if (strict_strtoul(buf, 10, &value) || value > 1) | ||
109 | return -EINVAL; | ||
110 | |||
111 | data->enabled = value; | ||
112 | |||
113 | return len; | ||
114 | } | ||
115 | |||
116 | static ssize_t show_enabled(struct device *d, | ||
117 | struct device_attribute *mattr, char *buf) | ||
118 | { | ||
119 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | ||
120 | struct decoder_data *data = get_decoder_data(ir_dev); | ||
121 | |||
122 | if (!data) | ||
123 | return -EINVAL; | ||
124 | |||
125 | if (data->enabled) | ||
126 | return sprintf(buf, "1\n"); | ||
127 | else | ||
128 | return sprintf(buf, "0\n"); | ||
129 | } | ||
130 | |||
131 | static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled); | ||
132 | |||
133 | static struct attribute *decoder_attributes[] = { | ||
134 | &dev_attr_enabled.attr, | ||
135 | NULL | ||
136 | }; | ||
137 | |||
138 | static struct attribute_group decoder_attribute_group = { | ||
139 | .name = "rc6_decoder", | ||
140 | .attrs = decoder_attributes, | ||
141 | }; | ||
142 | |||
143 | static enum rc6_mode rc6_mode(struct decoder_data *data) { | ||
144 | switch (data->header & RC6_MODE_MASK) { | 59 | switch (data->header & RC6_MODE_MASK) { |
145 | case 0: | 60 | case 0: |
146 | return RC6_MODE_0; | 61 | return RC6_MODE_0; |
@@ -162,16 +77,12 @@ static enum rc6_mode rc6_mode(struct decoder_data *data) { | |||
162 | */ | 77 | */ |
163 | static int ir_rc6_decode(struct input_dev *input_dev, struct ir_raw_event ev) | 78 | static int ir_rc6_decode(struct input_dev *input_dev, struct ir_raw_event ev) |
164 | { | 79 | { |
165 | struct decoder_data *data; | ||
166 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | 80 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); |
81 | struct rc6_dec *data = &ir_dev->raw->rc6; | ||
167 | u32 scancode; | 82 | u32 scancode; |
168 | u8 toggle; | 83 | u8 toggle; |
169 | 84 | ||
170 | data = get_decoder_data(ir_dev); | 85 | if (!(ir_dev->raw->enabled_protocols & IR_TYPE_RC6)) |
171 | if (!data) | ||
172 | return -EINVAL; | ||
173 | |||
174 | if (!data->enabled) | ||
175 | return 0; | 86 | return 0; |
176 | 87 | ||
177 | if (IS_RESET(ev)) { | 88 | if (IS_RESET(ev)) { |
@@ -223,12 +134,11 @@ again: | |||
223 | if (ev.pulse) | 134 | if (ev.pulse) |
224 | data->header |= 1; | 135 | data->header |= 1; |
225 | data->count++; | 136 | data->count++; |
226 | data->prev_ev = ev; | ||
227 | data->state = STATE_HEADER_BIT_END; | 137 | data->state = STATE_HEADER_BIT_END; |
228 | return 0; | 138 | return 0; |
229 | 139 | ||
230 | case STATE_HEADER_BIT_END: | 140 | case STATE_HEADER_BIT_END: |
231 | if (!is_transition(&ev, &data->prev_ev)) | 141 | if (!is_transition(&ev, &ir_dev->raw->prev_ev)) |
232 | break; | 142 | break; |
233 | 143 | ||
234 | if (data->count == RC6_HEADER_NBITS) | 144 | if (data->count == RC6_HEADER_NBITS) |
@@ -244,12 +154,11 @@ again: | |||
244 | break; | 154 | break; |
245 | 155 | ||
246 | data->toggle = ev.pulse; | 156 | data->toggle = ev.pulse; |
247 | data->prev_ev = ev; | ||
248 | data->state = STATE_TOGGLE_END; | 157 | data->state = STATE_TOGGLE_END; |
249 | return 0; | 158 | return 0; |
250 | 159 | ||
251 | case STATE_TOGGLE_END: | 160 | case STATE_TOGGLE_END: |
252 | if (!is_transition(&ev, &data->prev_ev) || | 161 | if (!is_transition(&ev, &ir_dev->raw->prev_ev) || |
253 | !geq_margin(ev.duration, RC6_TOGGLE_END, RC6_UNIT / 2)) | 162 | !geq_margin(ev.duration, RC6_TOGGLE_END, RC6_UNIT / 2)) |
254 | break; | 163 | break; |
255 | 164 | ||
@@ -259,7 +168,6 @@ again: | |||
259 | } | 168 | } |
260 | 169 | ||
261 | data->state = STATE_BODY_BIT_START; | 170 | data->state = STATE_BODY_BIT_START; |
262 | data->prev_ev = ev; | ||
263 | decrease_duration(&ev, RC6_TOGGLE_END); | 171 | decrease_duration(&ev, RC6_TOGGLE_END); |
264 | data->count = 0; | 172 | data->count = 0; |
265 | 173 | ||
@@ -291,13 +199,11 @@ again: | |||
291 | if (ev.pulse) | 199 | if (ev.pulse) |
292 | data->body |= 1; | 200 | data->body |= 1; |
293 | data->count++; | 201 | data->count++; |
294 | data->prev_ev = ev; | ||
295 | |||
296 | data->state = STATE_BODY_BIT_END; | 202 | data->state = STATE_BODY_BIT_END; |
297 | return 0; | 203 | return 0; |
298 | 204 | ||
299 | case STATE_BODY_BIT_END: | 205 | case STATE_BODY_BIT_END: |
300 | if (!is_transition(&ev, &data->prev_ev)) | 206 | if (!is_transition(&ev, &ir_dev->raw->prev_ev)) |
301 | break; | 207 | break; |
302 | 208 | ||
303 | if (data->count == data->wanted_bits) | 209 | if (data->count == data->wanted_bits) |
@@ -348,54 +254,9 @@ out: | |||
348 | return -EINVAL; | 254 | return -EINVAL; |
349 | } | 255 | } |
350 | 256 | ||
351 | static int ir_rc6_register(struct input_dev *input_dev) | ||
352 | { | ||
353 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
354 | struct decoder_data *data; | ||
355 | int rc; | ||
356 | |||
357 | rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group); | ||
358 | if (rc < 0) | ||
359 | return rc; | ||
360 | |||
361 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
362 | if (!data) { | ||
363 | sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group); | ||
364 | return -ENOMEM; | ||
365 | } | ||
366 | |||
367 | data->ir_dev = ir_dev; | ||
368 | data->enabled = 1; | ||
369 | |||
370 | spin_lock(&decoder_lock); | ||
371 | list_add_tail(&data->list, &decoder_list); | ||
372 | spin_unlock(&decoder_lock); | ||
373 | |||
374 | return 0; | ||
375 | } | ||
376 | |||
377 | static int ir_rc6_unregister(struct input_dev *input_dev) | ||
378 | { | ||
379 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
380 | static struct decoder_data *data; | ||
381 | |||
382 | data = get_decoder_data(ir_dev); | ||
383 | if (!data) | ||
384 | return 0; | ||
385 | |||
386 | sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group); | ||
387 | |||
388 | spin_lock(&decoder_lock); | ||
389 | list_del(&data->list); | ||
390 | spin_unlock(&decoder_lock); | ||
391 | |||
392 | return 0; | ||
393 | } | ||
394 | |||
395 | static struct ir_raw_handler rc6_handler = { | 257 | static struct ir_raw_handler rc6_handler = { |
258 | .protocols = IR_TYPE_RC6, | ||
396 | .decode = ir_rc6_decode, | 259 | .decode = ir_rc6_decode, |
397 | .raw_register = ir_rc6_register, | ||
398 | .raw_unregister = ir_rc6_unregister, | ||
399 | }; | 260 | }; |
400 | 261 | ||
401 | static int __init ir_rc6_decode_init(void) | 262 | static int __init ir_rc6_decode_init(void) |
diff --git a/drivers/media/IR/ir-sony-decoder.c b/drivers/media/IR/ir-sony-decoder.c index 9f440c5c060d..b9074f07c7a0 100644 --- a/drivers/media/IR/ir-sony-decoder.c +++ b/drivers/media/IR/ir-sony-decoder.c | |||
@@ -23,10 +23,6 @@ | |||
23 | #define SONY_BIT_SPACE (1 * SONY_UNIT) | 23 | #define SONY_BIT_SPACE (1 * SONY_UNIT) |
24 | #define SONY_TRAILER_SPACE (10 * SONY_UNIT) /* minimum */ | 24 | #define SONY_TRAILER_SPACE (10 * SONY_UNIT) /* minimum */ |
25 | 25 | ||
26 | /* Used to register sony_decoder clients */ | ||
27 | static LIST_HEAD(decoder_list); | ||
28 | static DEFINE_SPINLOCK(decoder_lock); | ||
29 | |||
30 | enum sony_state { | 26 | enum sony_state { |
31 | STATE_INACTIVE, | 27 | STATE_INACTIVE, |
32 | STATE_HEADER_SPACE, | 28 | STATE_HEADER_SPACE, |
@@ -35,84 +31,6 @@ enum sony_state { | |||
35 | STATE_FINISHED, | 31 | STATE_FINISHED, |
36 | }; | 32 | }; |
37 | 33 | ||
38 | struct decoder_data { | ||
39 | struct list_head list; | ||
40 | struct ir_input_dev *ir_dev; | ||
41 | int enabled:1; | ||
42 | |||
43 | /* State machine control */ | ||
44 | enum sony_state state; | ||
45 | u32 sony_bits; | ||
46 | unsigned count; | ||
47 | }; | ||
48 | |||
49 | |||
50 | /** | ||
51 | * get_decoder_data() - gets decoder data | ||
52 | * @input_dev: input device | ||
53 | * | ||
54 | * Returns the struct decoder_data that corresponds to a device | ||
55 | */ | ||
56 | static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev) | ||
57 | { | ||
58 | struct decoder_data *data = NULL; | ||
59 | |||
60 | spin_lock(&decoder_lock); | ||
61 | list_for_each_entry(data, &decoder_list, list) { | ||
62 | if (data->ir_dev == ir_dev) | ||
63 | break; | ||
64 | } | ||
65 | spin_unlock(&decoder_lock); | ||
66 | return data; | ||
67 | } | ||
68 | |||
69 | static ssize_t store_enabled(struct device *d, | ||
70 | struct device_attribute *mattr, | ||
71 | const char *buf, | ||
72 | size_t len) | ||
73 | { | ||
74 | unsigned long value; | ||
75 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | ||
76 | struct decoder_data *data = get_decoder_data(ir_dev); | ||
77 | |||
78 | if (!data) | ||
79 | return -EINVAL; | ||
80 | |||
81 | if (strict_strtoul(buf, 10, &value) || value > 1) | ||
82 | return -EINVAL; | ||
83 | |||
84 | data->enabled = value; | ||
85 | |||
86 | return len; | ||
87 | } | ||
88 | |||
89 | static ssize_t show_enabled(struct device *d, | ||
90 | struct device_attribute *mattr, char *buf) | ||
91 | { | ||
92 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | ||
93 | struct decoder_data *data = get_decoder_data(ir_dev); | ||
94 | |||
95 | if (!data) | ||
96 | return -EINVAL; | ||
97 | |||
98 | if (data->enabled) | ||
99 | return sprintf(buf, "1\n"); | ||
100 | else | ||
101 | return sprintf(buf, "0\n"); | ||
102 | } | ||
103 | |||
104 | static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled); | ||
105 | |||
106 | static struct attribute *decoder_attributes[] = { | ||
107 | &dev_attr_enabled.attr, | ||
108 | NULL | ||
109 | }; | ||
110 | |||
111 | static struct attribute_group decoder_attribute_group = { | ||
112 | .name = "sony_decoder", | ||
113 | .attrs = decoder_attributes, | ||
114 | }; | ||
115 | |||
116 | /** | 34 | /** |
117 | * ir_sony_decode() - Decode one Sony pulse or space | 35 | * ir_sony_decode() - Decode one Sony pulse or space |
118 | * @input_dev: the struct input_dev descriptor of the device | 36 | * @input_dev: the struct input_dev descriptor of the device |
@@ -122,16 +40,12 @@ static struct attribute_group decoder_attribute_group = { | |||
122 | */ | 40 | */ |
123 | static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev) | 41 | static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev) |
124 | { | 42 | { |
125 | struct decoder_data *data; | ||
126 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | 43 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); |
44 | struct sony_dec *data = &ir_dev->raw->sony; | ||
127 | u32 scancode; | 45 | u32 scancode; |
128 | u8 device, subdevice, function; | 46 | u8 device, subdevice, function; |
129 | 47 | ||
130 | data = get_decoder_data(ir_dev); | 48 | if (!(ir_dev->raw->enabled_protocols & IR_TYPE_SONY)) |
131 | if (!data) | ||
132 | return -EINVAL; | ||
133 | |||
134 | if (!data->enabled) | ||
135 | return 0; | 49 | return 0; |
136 | 50 | ||
137 | if (IS_RESET(ev)) { | 51 | if (IS_RESET(ev)) { |
@@ -172,9 +86,9 @@ static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev) | |||
172 | if (!ev.pulse) | 86 | if (!ev.pulse) |
173 | break; | 87 | break; |
174 | 88 | ||
175 | data->sony_bits <<= 1; | 89 | data->bits <<= 1; |
176 | if (eq_margin(ev.duration, SONY_BIT_1_PULSE, SONY_UNIT / 2)) | 90 | if (eq_margin(ev.duration, SONY_BIT_1_PULSE, SONY_UNIT / 2)) |
177 | data->sony_bits |= 1; | 91 | data->bits |= 1; |
178 | else if (!eq_margin(ev.duration, SONY_BIT_0_PULSE, SONY_UNIT / 2)) | 92 | else if (!eq_margin(ev.duration, SONY_BIT_0_PULSE, SONY_UNIT / 2)) |
179 | break; | 93 | break; |
180 | 94 | ||
@@ -208,19 +122,19 @@ static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev) | |||
208 | 122 | ||
209 | switch (data->count) { | 123 | switch (data->count) { |
210 | case 12: | 124 | case 12: |
211 | device = bitrev8((data->sony_bits << 3) & 0xF8); | 125 | device = bitrev8((data->bits << 3) & 0xF8); |
212 | subdevice = 0; | 126 | subdevice = 0; |
213 | function = bitrev8((data->sony_bits >> 4) & 0xFE); | 127 | function = bitrev8((data->bits >> 4) & 0xFE); |
214 | break; | 128 | break; |
215 | case 15: | 129 | case 15: |
216 | device = bitrev8((data->sony_bits >> 0) & 0xFF); | 130 | device = bitrev8((data->bits >> 0) & 0xFF); |
217 | subdevice = 0; | 131 | subdevice = 0; |
218 | function = bitrev8((data->sony_bits >> 7) & 0xFD); | 132 | function = bitrev8((data->bits >> 7) & 0xFD); |
219 | break; | 133 | break; |
220 | case 20: | 134 | case 20: |
221 | device = bitrev8((data->sony_bits >> 5) & 0xF8); | 135 | device = bitrev8((data->bits >> 5) & 0xF8); |
222 | subdevice = bitrev8((data->sony_bits >> 0) & 0xFF); | 136 | subdevice = bitrev8((data->bits >> 0) & 0xFF); |
223 | function = bitrev8((data->sony_bits >> 12) & 0xFE); | 137 | function = bitrev8((data->bits >> 12) & 0xFE); |
224 | break; | 138 | break; |
225 | default: | 139 | default: |
226 | IR_dprintk(1, "Sony invalid bitcount %u\n", data->count); | 140 | IR_dprintk(1, "Sony invalid bitcount %u\n", data->count); |
@@ -241,54 +155,9 @@ out: | |||
241 | return -EINVAL; | 155 | return -EINVAL; |
242 | } | 156 | } |
243 | 157 | ||
244 | static int ir_sony_register(struct input_dev *input_dev) | ||
245 | { | ||
246 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
247 | struct decoder_data *data; | ||
248 | int rc; | ||
249 | |||
250 | rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group); | ||
251 | if (rc < 0) | ||
252 | return rc; | ||
253 | |||
254 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
255 | if (!data) { | ||
256 | sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group); | ||
257 | return -ENOMEM; | ||
258 | } | ||
259 | |||
260 | data->ir_dev = ir_dev; | ||
261 | data->enabled = 1; | ||
262 | |||
263 | spin_lock(&decoder_lock); | ||
264 | list_add_tail(&data->list, &decoder_list); | ||
265 | spin_unlock(&decoder_lock); | ||
266 | |||
267 | return 0; | ||
268 | } | ||
269 | |||
270 | static int ir_sony_unregister(struct input_dev *input_dev) | ||
271 | { | ||
272 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
273 | static struct decoder_data *data; | ||
274 | |||
275 | data = get_decoder_data(ir_dev); | ||
276 | if (!data) | ||
277 | return 0; | ||
278 | |||
279 | sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group); | ||
280 | |||
281 | spin_lock(&decoder_lock); | ||
282 | list_del(&data->list); | ||
283 | spin_unlock(&decoder_lock); | ||
284 | |||
285 | return 0; | ||
286 | } | ||
287 | |||
288 | static struct ir_raw_handler sony_handler = { | 158 | static struct ir_raw_handler sony_handler = { |
159 | .protocols = IR_TYPE_SONY, | ||
289 | .decode = ir_sony_decode, | 160 | .decode = ir_sony_decode, |
290 | .raw_register = ir_sony_register, | ||
291 | .raw_unregister = ir_sony_unregister, | ||
292 | }; | 161 | }; |
293 | 162 | ||
294 | static int __init ir_sony_decode_init(void) | 163 | static int __init ir_sony_decode_init(void) |
diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c index 2098dd1488e0..6273047e915b 100644 --- a/drivers/media/IR/ir-sysfs.c +++ b/drivers/media/IR/ir-sysfs.c | |||
@@ -33,125 +33,172 @@ static struct class ir_input_class = { | |||
33 | .devnode = ir_devnode, | 33 | .devnode = ir_devnode, |
34 | }; | 34 | }; |
35 | 35 | ||
36 | static struct { | ||
37 | u64 type; | ||
38 | char *name; | ||
39 | } proto_names[] = { | ||
40 | { IR_TYPE_UNKNOWN, "unknown" }, | ||
41 | { IR_TYPE_RC5, "rc-5" }, | ||
42 | { IR_TYPE_NEC, "nec" }, | ||
43 | { IR_TYPE_RC6, "rc-6" }, | ||
44 | { IR_TYPE_JVC, "jvc" }, | ||
45 | { IR_TYPE_SONY, "sony" }, | ||
46 | { IR_TYPE_LIRC, "lirc" }, | ||
47 | }; | ||
48 | |||
49 | #define PROTO_NONE "none" | ||
50 | |||
36 | /** | 51 | /** |
37 | * show_protocol() - shows the current IR protocol | 52 | * show_protocols() - shows the current IR protocol(s) |
38 | * @d: the device descriptor | 53 | * @d: the device descriptor |
39 | * @mattr: the device attribute struct (unused) | 54 | * @mattr: the device attribute struct (unused) |
40 | * @buf: a pointer to the output buffer | 55 | * @buf: a pointer to the output buffer |
41 | * | 56 | * |
42 | * This routine is a callback routine for input read the IR protocol type. | 57 | * This routine is a callback routine for input read the IR protocol type(s). |
43 | * it is trigged by reading /sys/class/rc/rc?/current_protocol. | 58 | * it is trigged by reading /sys/class/rc/rc?/protocols. |
44 | * It returns the protocol name, as understood by the driver. | 59 | * It returns the protocol names of supported protocols. |
60 | * Enabled protocols are printed in brackets. | ||
45 | */ | 61 | */ |
46 | static ssize_t show_protocol(struct device *d, | 62 | static ssize_t show_protocols(struct device *d, |
47 | struct device_attribute *mattr, char *buf) | 63 | struct device_attribute *mattr, char *buf) |
48 | { | 64 | { |
49 | char *s; | ||
50 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | 65 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); |
51 | u64 ir_type = ir_dev->rc_tab.ir_type; | 66 | u64 allowed, enabled; |
52 | 67 | char *tmp = buf; | |
53 | IR_dprintk(1, "Current protocol is %lld\n", (long long)ir_type); | 68 | int i; |
54 | 69 | ||
55 | /* FIXME: doesn't support multiple protocols at the same time */ | 70 | if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE) { |
56 | if (ir_type == IR_TYPE_UNKNOWN) | 71 | enabled = ir_dev->rc_tab.ir_type; |
57 | s = "Unknown"; | 72 | allowed = ir_dev->props->allowed_protos; |
58 | else if (ir_type == IR_TYPE_RC5) | 73 | } else { |
59 | s = "rc-5"; | 74 | enabled = ir_dev->raw->enabled_protocols; |
60 | else if (ir_type == IR_TYPE_NEC) | 75 | allowed = ir_raw_get_allowed_protocols(); |
61 | s = "nec"; | 76 | } |
62 | else if (ir_type == IR_TYPE_RC6) | 77 | |
63 | s = "rc6"; | 78 | IR_dprintk(1, "allowed - 0x%llx, enabled - 0x%llx\n", |
64 | else if (ir_type == IR_TYPE_JVC) | 79 | (long long)allowed, |
65 | s = "jvc"; | 80 | (long long)enabled); |
66 | else if (ir_type == IR_TYPE_SONY) | ||
67 | s = "sony"; | ||
68 | else | ||
69 | s = "other"; | ||
70 | 81 | ||
71 | return sprintf(buf, "%s\n", s); | 82 | for (i = 0; i < ARRAY_SIZE(proto_names); i++) { |
83 | if (allowed & enabled & proto_names[i].type) | ||
84 | tmp += sprintf(tmp, "[%s] ", proto_names[i].name); | ||
85 | else if (allowed & proto_names[i].type) | ||
86 | tmp += sprintf(tmp, "%s ", proto_names[i].name); | ||
87 | } | ||
88 | |||
89 | if (tmp != buf) | ||
90 | tmp--; | ||
91 | *tmp = '\n'; | ||
92 | return tmp + 1 - buf; | ||
72 | } | 93 | } |
73 | 94 | ||
74 | /** | 95 | /** |
75 | * store_protocol() - shows the current IR protocol | 96 | * store_protocols() - changes the current IR protocol(s) |
76 | * @d: the device descriptor | 97 | * @d: the device descriptor |
77 | * @mattr: the device attribute struct (unused) | 98 | * @mattr: the device attribute struct (unused) |
78 | * @buf: a pointer to the input buffer | 99 | * @buf: a pointer to the input buffer |
79 | * @len: length of the input buffer | 100 | * @len: length of the input buffer |
80 | * | 101 | * |
81 | * This routine is a callback routine for changing the IR protocol type. | 102 | * This routine is a callback routine for changing the IR protocol type. |
82 | * it is trigged by reading /sys/class/rc/rc?/current_protocol. | 103 | * It is trigged by writing to /sys/class/rc/rc?/protocols. |
83 | * It changes the IR the protocol name, if the IR type is recognized | 104 | * Writing "+proto" will add a protocol to the list of enabled protocols. |
84 | * by the driver. | 105 | * Writing "-proto" will remove a protocol from the list of enabled protocols. |
85 | * If an unknown protocol name is used, returns -EINVAL. | 106 | * Writing "proto" will enable only "proto". |
107 | * Writing "none" will disable all protocols. | ||
108 | * Returns -EINVAL if an invalid protocol combination or unknown protocol name | ||
109 | * is used, otherwise @len. | ||
86 | */ | 110 | */ |
87 | static ssize_t store_protocol(struct device *d, | 111 | static ssize_t store_protocols(struct device *d, |
88 | struct device_attribute *mattr, | 112 | struct device_attribute *mattr, |
89 | const char *data, | 113 | const char *data, |
90 | size_t len) | 114 | size_t len) |
91 | { | 115 | { |
92 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | 116 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); |
93 | u64 ir_type = 0; | 117 | bool enable, disable; |
94 | int rc = -EINVAL; | 118 | const char *tmp; |
119 | u64 type; | ||
120 | u64 mask; | ||
121 | int rc, i, count = 0; | ||
95 | unsigned long flags; | 122 | unsigned long flags; |
96 | char *buf; | 123 | |
97 | 124 | if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE) | |
98 | while ((buf = strsep((char **) &data, " \n")) != NULL) { | 125 | type = ir_dev->rc_tab.ir_type; |
99 | if (!strcasecmp(buf, "rc-5") || !strcasecmp(buf, "rc5")) | 126 | else |
100 | ir_type |= IR_TYPE_RC5; | 127 | type = ir_dev->raw->enabled_protocols; |
101 | if (!strcasecmp(buf, "nec")) | 128 | |
102 | ir_type |= IR_TYPE_NEC; | 129 | while ((tmp = strsep((char **) &data, " \n")) != NULL) { |
103 | if (!strcasecmp(buf, "jvc")) | 130 | if (!*tmp) |
104 | ir_type |= IR_TYPE_JVC; | 131 | break; |
105 | if (!strcasecmp(buf, "sony")) | 132 | |
106 | ir_type |= IR_TYPE_SONY; | 133 | if (*tmp == '+') { |
134 | enable = true; | ||
135 | disable = false; | ||
136 | tmp++; | ||
137 | } else if (*tmp == '-') { | ||
138 | enable = false; | ||
139 | disable = true; | ||
140 | tmp++; | ||
141 | } else { | ||
142 | enable = false; | ||
143 | disable = false; | ||
144 | } | ||
145 | |||
146 | if (!enable && !disable && !strncasecmp(tmp, PROTO_NONE, sizeof(PROTO_NONE))) { | ||
147 | tmp += sizeof(PROTO_NONE); | ||
148 | mask = 0; | ||
149 | count++; | ||
150 | } else { | ||
151 | for (i = 0; i < ARRAY_SIZE(proto_names); i++) { | ||
152 | if (!strncasecmp(tmp, proto_names[i].name, strlen(proto_names[i].name))) { | ||
153 | tmp += strlen(proto_names[i].name); | ||
154 | mask = proto_names[i].type; | ||
155 | break; | ||
156 | } | ||
157 | } | ||
158 | if (i == ARRAY_SIZE(proto_names)) { | ||
159 | IR_dprintk(1, "Unknown protocol: '%s'\n", tmp); | ||
160 | return -EINVAL; | ||
161 | } | ||
162 | count++; | ||
163 | } | ||
164 | |||
165 | if (enable) | ||
166 | type |= mask; | ||
167 | else if (disable) | ||
168 | type &= ~mask; | ||
169 | else | ||
170 | type = mask; | ||
107 | } | 171 | } |
108 | 172 | ||
109 | if (!ir_type) { | 173 | if (!count) { |
110 | IR_dprintk(1, "Unknown protocol\n"); | 174 | IR_dprintk(1, "Protocol not specified\n"); |
111 | return -EINVAL; | 175 | return -EINVAL; |
112 | } | 176 | } |
113 | 177 | ||
114 | if (ir_dev->props && ir_dev->props->change_protocol) | 178 | if (ir_dev->props && ir_dev->props->change_protocol) { |
115 | rc = ir_dev->props->change_protocol(ir_dev->props->priv, | 179 | rc = ir_dev->props->change_protocol(ir_dev->props->priv, |
116 | ir_type); | 180 | type); |
117 | 181 | if (rc < 0) { | |
118 | if (rc < 0) { | 182 | IR_dprintk(1, "Error setting protocols to 0x%llx\n", |
119 | IR_dprintk(1, "Error setting protocol to %lld\n", | 183 | (long long)type); |
120 | (long long)ir_type); | 184 | return -EINVAL; |
121 | return -EINVAL; | 185 | } |
122 | } | 186 | } |
123 | 187 | ||
124 | spin_lock_irqsave(&ir_dev->rc_tab.lock, flags); | 188 | if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE) { |
125 | ir_dev->rc_tab.ir_type = ir_type; | 189 | spin_lock_irqsave(&ir_dev->rc_tab.lock, flags); |
126 | spin_unlock_irqrestore(&ir_dev->rc_tab.lock, flags); | 190 | ir_dev->rc_tab.ir_type = type; |
191 | spin_unlock_irqrestore(&ir_dev->rc_tab.lock, flags); | ||
192 | } else { | ||
193 | ir_dev->raw->enabled_protocols = type; | ||
194 | } | ||
127 | 195 | ||
128 | IR_dprintk(1, "Current protocol(s) is(are) %lld\n", | 196 | IR_dprintk(1, "Current protocol(s): 0x%llx\n", |
129 | (long long)ir_type); | 197 | (long long)type); |
130 | 198 | ||
131 | return len; | 199 | return len; |
132 | } | 200 | } |
133 | 201 | ||
134 | static ssize_t show_supported_protocols(struct device *d, | ||
135 | struct device_attribute *mattr, char *buf) | ||
136 | { | ||
137 | char *orgbuf = buf; | ||
138 | struct ir_input_dev *ir_dev = dev_get_drvdata(d); | ||
139 | |||
140 | /* FIXME: doesn't support multiple protocols at the same time */ | ||
141 | if (ir_dev->props->allowed_protos == IR_TYPE_UNKNOWN) | ||
142 | buf += sprintf(buf, "unknown "); | ||
143 | if (ir_dev->props->allowed_protos & IR_TYPE_RC5) | ||
144 | buf += sprintf(buf, "rc-5 "); | ||
145 | if (ir_dev->props->allowed_protos & IR_TYPE_NEC) | ||
146 | buf += sprintf(buf, "nec "); | ||
147 | if (buf == orgbuf) | ||
148 | buf += sprintf(buf, "other "); | ||
149 | |||
150 | buf += sprintf(buf - 1, "\n"); | ||
151 | |||
152 | return buf - orgbuf; | ||
153 | } | ||
154 | |||
155 | #define ADD_HOTPLUG_VAR(fmt, val...) \ | 202 | #define ADD_HOTPLUG_VAR(fmt, val...) \ |
156 | do { \ | 203 | do { \ |
157 | int err = add_uevent_var(env, fmt, val); \ | 204 | int err = add_uevent_var(env, fmt, val); \ |
@@ -159,7 +206,7 @@ static ssize_t show_supported_protocols(struct device *d, | |||
159 | return err; \ | 206 | return err; \ |
160 | } while (0) | 207 | } while (0) |
161 | 208 | ||
162 | static int ir_dev_uevent(struct device *device, struct kobj_uevent_env *env) | 209 | static int rc_dev_uevent(struct device *device, struct kobj_uevent_env *env) |
163 | { | 210 | { |
164 | struct ir_input_dev *ir_dev = dev_get_drvdata(device); | 211 | struct ir_input_dev *ir_dev = dev_get_drvdata(device); |
165 | 212 | ||
@@ -174,34 +221,26 @@ static int ir_dev_uevent(struct device *device, struct kobj_uevent_env *env) | |||
174 | /* | 221 | /* |
175 | * Static device attribute struct with the sysfs attributes for IR's | 222 | * Static device attribute struct with the sysfs attributes for IR's |
176 | */ | 223 | */ |
177 | static DEVICE_ATTR(protocol, S_IRUGO | S_IWUSR, | 224 | static DEVICE_ATTR(protocols, S_IRUGO | S_IWUSR, |
178 | show_protocol, store_protocol); | 225 | show_protocols, store_protocols); |
179 | 226 | ||
180 | static DEVICE_ATTR(supported_protocols, S_IRUGO | S_IWUSR, | 227 | static struct attribute *rc_dev_attrs[] = { |
181 | show_supported_protocols, NULL); | 228 | &dev_attr_protocols.attr, |
182 | |||
183 | static struct attribute *ir_hw_dev_attrs[] = { | ||
184 | &dev_attr_protocol.attr, | ||
185 | &dev_attr_supported_protocols.attr, | ||
186 | NULL, | 229 | NULL, |
187 | }; | 230 | }; |
188 | 231 | ||
189 | static struct attribute_group ir_hw_dev_attr_grp = { | 232 | static struct attribute_group rc_dev_attr_grp = { |
190 | .attrs = ir_hw_dev_attrs, | 233 | .attrs = rc_dev_attrs, |
191 | }; | 234 | }; |
192 | 235 | ||
193 | static const struct attribute_group *ir_hw_dev_attr_groups[] = { | 236 | static const struct attribute_group *rc_dev_attr_groups[] = { |
194 | &ir_hw_dev_attr_grp, | 237 | &rc_dev_attr_grp, |
195 | NULL | 238 | NULL |
196 | }; | 239 | }; |
197 | 240 | ||
198 | static struct device_type rc_dev_type = { | 241 | static struct device_type rc_dev_type = { |
199 | .groups = ir_hw_dev_attr_groups, | 242 | .groups = rc_dev_attr_groups, |
200 | .uevent = ir_dev_uevent, | 243 | .uevent = rc_dev_uevent, |
201 | }; | ||
202 | |||
203 | static struct device_type ir_raw_dev_type = { | ||
204 | .uevent = ir_dev_uevent, | ||
205 | }; | 244 | }; |
206 | 245 | ||
207 | /** | 246 | /** |
@@ -221,11 +260,7 @@ int ir_register_class(struct input_dev *input_dev) | |||
221 | if (unlikely(devno < 0)) | 260 | if (unlikely(devno < 0)) |
222 | return devno; | 261 | return devno; |
223 | 262 | ||
224 | if (ir_dev->props) { | 263 | ir_dev->dev.type = &rc_dev_type; |
225 | if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE) | ||
226 | ir_dev->dev.type = &rc_dev_type; | ||
227 | } else | ||
228 | ir_dev->dev.type = &ir_raw_dev_type; | ||
229 | 264 | ||
230 | ir_dev->dev.class = &ir_input_class; | 265 | ir_dev->dev.class = &ir_input_class; |
231 | ir_dev->dev.parent = input_dev->dev.parent; | 266 | ir_dev->dev.parent = input_dev->dev.parent; |
diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile index aea649fbcf5a..cbee06243b51 100644 --- a/drivers/media/IR/keymaps/Makefile +++ b/drivers/media/IR/keymaps/Makefile | |||
@@ -14,6 +14,8 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ | |||
14 | rc-budget-ci-old.o \ | 14 | rc-budget-ci-old.o \ |
15 | rc-cinergy-1400.o \ | 15 | rc-cinergy-1400.o \ |
16 | rc-cinergy.o \ | 16 | rc-cinergy.o \ |
17 | rc-dib0700-nec.o \ | ||
18 | rc-dib0700-rc5.o \ | ||
17 | rc-dm1105-nec.o \ | 19 | rc-dm1105-nec.o \ |
18 | rc-dntv-live-dvb-t.o \ | 20 | rc-dntv-live-dvb-t.o \ |
19 | rc-dntv-live-dvbt-pro.o \ | 21 | rc-dntv-live-dvbt-pro.o \ |
@@ -37,6 +39,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ | |||
37 | rc-kaiomy.o \ | 39 | rc-kaiomy.o \ |
38 | rc-kworld-315u.o \ | 40 | rc-kworld-315u.o \ |
39 | rc-kworld-plus-tv-analog.o \ | 41 | rc-kworld-plus-tv-analog.o \ |
42 | rc-lirc.o \ | ||
40 | rc-manli.o \ | 43 | rc-manli.o \ |
41 | rc-msi-tvanywhere.o \ | 44 | rc-msi-tvanywhere.o \ |
42 | rc-msi-tvanywhere-plus.o \ | 45 | rc-msi-tvanywhere-plus.o \ |
@@ -57,6 +60,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ | |||
57 | rc-pv951.o \ | 60 | rc-pv951.o \ |
58 | rc-rc5-hauppauge-new.o \ | 61 | rc-rc5-hauppauge-new.o \ |
59 | rc-rc5-tv.o \ | 62 | rc-rc5-tv.o \ |
63 | rc-rc6-mce.o \ | ||
60 | rc-real-audio-220-32-keys.o \ | 64 | rc-real-audio-220-32-keys.o \ |
61 | rc-tbs-nec.o \ | 65 | rc-tbs-nec.o \ |
62 | rc-terratec-cinergy-xs.o \ | 66 | rc-terratec-cinergy-xs.o \ |
diff --git a/drivers/media/IR/keymaps/rc-dib0700-nec.c b/drivers/media/IR/keymaps/rc-dib0700-nec.c new file mode 100644 index 000000000000..ae1832038fbe --- /dev/null +++ b/drivers/media/IR/keymaps/rc-dib0700-nec.c | |||
@@ -0,0 +1,124 @@ | |||
1 | /* rc-dvb0700-big.c - Keytable for devices in dvb0700 | ||
2 | * | ||
3 | * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.com> | ||
4 | * | ||
5 | * TODO: This table is a real mess, as it merges RC codes from several | ||
6 | * devices into a big table. It also has both RC-5 and NEC codes inside. | ||
7 | * It should be broken into small tables, and the protocols should properly | ||
8 | * be indentificated. | ||
9 | * | ||
10 | * The table were imported from dib0700_devices.c. | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU General Public License as published by | ||
14 | * the Free Software Foundation; either version 2 of the License, or | ||
15 | * (at your option) any later version. | ||
16 | */ | ||
17 | |||
18 | #include <media/rc-map.h> | ||
19 | |||
20 | static struct ir_scancode dib0700_nec_table[] = { | ||
21 | /* Key codes for the Pixelview SBTVD remote */ | ||
22 | { 0x8613, KEY_MUTE }, | ||
23 | { 0x8612, KEY_POWER }, | ||
24 | { 0x8601, KEY_1 }, | ||
25 | { 0x8602, KEY_2 }, | ||
26 | { 0x8603, KEY_3 }, | ||
27 | { 0x8604, KEY_4 }, | ||
28 | { 0x8605, KEY_5 }, | ||
29 | { 0x8606, KEY_6 }, | ||
30 | { 0x8607, KEY_7 }, | ||
31 | { 0x8608, KEY_8 }, | ||
32 | { 0x8609, KEY_9 }, | ||
33 | { 0x8600, KEY_0 }, | ||
34 | { 0x860d, KEY_CHANNELUP }, | ||
35 | { 0x8619, KEY_CHANNELDOWN }, | ||
36 | { 0x8610, KEY_VOLUMEUP }, | ||
37 | { 0x860c, KEY_VOLUMEDOWN }, | ||
38 | |||
39 | { 0x860a, KEY_CAMERA }, | ||
40 | { 0x860b, KEY_ZOOM }, | ||
41 | { 0x861b, KEY_BACKSPACE }, | ||
42 | { 0x8615, KEY_ENTER }, | ||
43 | |||
44 | { 0x861d, KEY_UP }, | ||
45 | { 0x861e, KEY_DOWN }, | ||
46 | { 0x860e, KEY_LEFT }, | ||
47 | { 0x860f, KEY_RIGHT }, | ||
48 | |||
49 | { 0x8618, KEY_RECORD }, | ||
50 | { 0x861a, KEY_STOP }, | ||
51 | |||
52 | /* Key codes for the EvolutePC TVWay+ remote */ | ||
53 | { 0x7a00, KEY_MENU }, | ||
54 | { 0x7a01, KEY_RECORD }, | ||
55 | { 0x7a02, KEY_PLAY }, | ||
56 | { 0x7a03, KEY_STOP }, | ||
57 | { 0x7a10, KEY_CHANNELUP }, | ||
58 | { 0x7a11, KEY_CHANNELDOWN }, | ||
59 | { 0x7a12, KEY_VOLUMEUP }, | ||
60 | { 0x7a13, KEY_VOLUMEDOWN }, | ||
61 | { 0x7a40, KEY_POWER }, | ||
62 | { 0x7a41, KEY_MUTE }, | ||
63 | |||
64 | /* Key codes for the Elgato EyeTV Diversity silver remote */ | ||
65 | { 0x4501, KEY_POWER }, | ||
66 | { 0x4502, KEY_MUTE }, | ||
67 | { 0x4503, KEY_1 }, | ||
68 | { 0x4504, KEY_2 }, | ||
69 | { 0x4505, KEY_3 }, | ||
70 | { 0x4506, KEY_4 }, | ||
71 | { 0x4507, KEY_5 }, | ||
72 | { 0x4508, KEY_6 }, | ||
73 | { 0x4509, KEY_7 }, | ||
74 | { 0x450a, KEY_8 }, | ||
75 | { 0x450b, KEY_9 }, | ||
76 | { 0x450c, KEY_LAST }, | ||
77 | { 0x450d, KEY_0 }, | ||
78 | { 0x450e, KEY_ENTER }, | ||
79 | { 0x450f, KEY_RED }, | ||
80 | { 0x4510, KEY_CHANNELUP }, | ||
81 | { 0x4511, KEY_GREEN }, | ||
82 | { 0x4512, KEY_VOLUMEDOWN }, | ||
83 | { 0x4513, KEY_OK }, | ||
84 | { 0x4514, KEY_VOLUMEUP }, | ||
85 | { 0x4515, KEY_YELLOW }, | ||
86 | { 0x4516, KEY_CHANNELDOWN }, | ||
87 | { 0x4517, KEY_BLUE }, | ||
88 | { 0x4518, KEY_LEFT }, /* Skip backwards */ | ||
89 | { 0x4519, KEY_PLAYPAUSE }, | ||
90 | { 0x451a, KEY_RIGHT }, /* Skip forward */ | ||
91 | { 0x451b, KEY_REWIND }, | ||
92 | { 0x451c, KEY_L }, /* Live */ | ||
93 | { 0x451d, KEY_FASTFORWARD }, | ||
94 | { 0x451e, KEY_STOP }, /* 'Reveal' for Teletext */ | ||
95 | { 0x451f, KEY_MENU }, /* KEY_TEXT for Teletext */ | ||
96 | { 0x4540, KEY_RECORD }, /* Font 'Size' for Teletext */ | ||
97 | { 0x4541, KEY_SCREEN }, /* Full screen toggle, 'Hold' for Teletext */ | ||
98 | { 0x4542, KEY_SELECT }, /* Select video input, 'Select' for Teletext */ | ||
99 | }; | ||
100 | |||
101 | static struct rc_keymap dib0700_nec_map = { | ||
102 | .map = { | ||
103 | .scan = dib0700_nec_table, | ||
104 | .size = ARRAY_SIZE(dib0700_nec_table), | ||
105 | .ir_type = IR_TYPE_NEC, | ||
106 | .name = RC_MAP_DIB0700_NEC_TABLE, | ||
107 | } | ||
108 | }; | ||
109 | |||
110 | static int __init init_rc_map(void) | ||
111 | { | ||
112 | return ir_register_map(&dib0700_nec_map); | ||
113 | } | ||
114 | |||
115 | static void __exit exit_rc_map(void) | ||
116 | { | ||
117 | ir_unregister_map(&dib0700_nec_map); | ||
118 | } | ||
119 | |||
120 | module_init(init_rc_map) | ||
121 | module_exit(exit_rc_map) | ||
122 | |||
123 | MODULE_LICENSE("GPL"); | ||
124 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>"); | ||
diff --git a/drivers/media/IR/keymaps/rc-dib0700-rc5.c b/drivers/media/IR/keymaps/rc-dib0700-rc5.c new file mode 100644 index 000000000000..4a4797cfd77d --- /dev/null +++ b/drivers/media/IR/keymaps/rc-dib0700-rc5.c | |||
@@ -0,0 +1,235 @@ | |||
1 | /* rc-dvb0700-big.c - Keytable for devices in dvb0700 | ||
2 | * | ||
3 | * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.com> | ||
4 | * | ||
5 | * TODO: This table is a real mess, as it merges RC codes from several | ||
6 | * devices into a big table. It also has both RC-5 and NEC codes inside. | ||
7 | * It should be broken into small tables, and the protocols should properly | ||
8 | * be indentificated. | ||
9 | * | ||
10 | * The table were imported from dib0700_devices.c. | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU General Public License as published by | ||
14 | * the Free Software Foundation; either version 2 of the License, or | ||
15 | * (at your option) any later version. | ||
16 | */ | ||
17 | |||
18 | #include <media/rc-map.h> | ||
19 | |||
20 | static struct ir_scancode dib0700_rc5_table[] = { | ||
21 | /* Key codes for the tiny Pinnacle remote*/ | ||
22 | { 0x0700, KEY_MUTE }, | ||
23 | { 0x0701, KEY_MENU }, /* Pinnacle logo */ | ||
24 | { 0x0739, KEY_POWER }, | ||
25 | { 0x0703, KEY_VOLUMEUP }, | ||
26 | { 0x0709, KEY_VOLUMEDOWN }, | ||
27 | { 0x0706, KEY_CHANNELUP }, | ||
28 | { 0x070c, KEY_CHANNELDOWN }, | ||
29 | { 0x070f, KEY_1 }, | ||
30 | { 0x0715, KEY_2 }, | ||
31 | { 0x0710, KEY_3 }, | ||
32 | { 0x0718, KEY_4 }, | ||
33 | { 0x071b, KEY_5 }, | ||
34 | { 0x071e, KEY_6 }, | ||
35 | { 0x0711, KEY_7 }, | ||
36 | { 0x0721, KEY_8 }, | ||
37 | { 0x0712, KEY_9 }, | ||
38 | { 0x0727, KEY_0 }, | ||
39 | { 0x0724, KEY_SCREEN }, /* 'Square' key */ | ||
40 | { 0x072a, KEY_TEXT }, /* 'T' key */ | ||
41 | { 0x072d, KEY_REWIND }, | ||
42 | { 0x0730, KEY_PLAY }, | ||
43 | { 0x0733, KEY_FASTFORWARD }, | ||
44 | { 0x0736, KEY_RECORD }, | ||
45 | { 0x073c, KEY_STOP }, | ||
46 | { 0x073f, KEY_CANCEL }, /* '?' key */ | ||
47 | |||
48 | /* Key codes for the Terratec Cinergy DT XS Diversity, similar to cinergyT2.c */ | ||
49 | { 0xeb01, KEY_POWER }, | ||
50 | { 0xeb02, KEY_1 }, | ||
51 | { 0xeb03, KEY_2 }, | ||
52 | { 0xeb04, KEY_3 }, | ||
53 | { 0xeb05, KEY_4 }, | ||
54 | { 0xeb06, KEY_5 }, | ||
55 | { 0xeb07, KEY_6 }, | ||
56 | { 0xeb08, KEY_7 }, | ||
57 | { 0xeb09, KEY_8 }, | ||
58 | { 0xeb0a, KEY_9 }, | ||
59 | { 0xeb0b, KEY_VIDEO }, | ||
60 | { 0xeb0c, KEY_0 }, | ||
61 | { 0xeb0d, KEY_REFRESH }, | ||
62 | { 0xeb0f, KEY_EPG }, | ||
63 | { 0xeb10, KEY_UP }, | ||
64 | { 0xeb11, KEY_LEFT }, | ||
65 | { 0xeb12, KEY_OK }, | ||
66 | { 0xeb13, KEY_RIGHT }, | ||
67 | { 0xeb14, KEY_DOWN }, | ||
68 | { 0xeb16, KEY_INFO }, | ||
69 | { 0xeb17, KEY_RED }, | ||
70 | { 0xeb18, KEY_GREEN }, | ||
71 | { 0xeb19, KEY_YELLOW }, | ||
72 | { 0xeb1a, KEY_BLUE }, | ||
73 | { 0xeb1b, KEY_CHANNELUP }, | ||
74 | { 0xeb1c, KEY_VOLUMEUP }, | ||
75 | { 0xeb1d, KEY_MUTE }, | ||
76 | { 0xeb1e, KEY_VOLUMEDOWN }, | ||
77 | { 0xeb1f, KEY_CHANNELDOWN }, | ||
78 | { 0xeb40, KEY_PAUSE }, | ||
79 | { 0xeb41, KEY_HOME }, | ||
80 | { 0xeb42, KEY_MENU }, /* DVD Menu */ | ||
81 | { 0xeb43, KEY_SUBTITLE }, | ||
82 | { 0xeb44, KEY_TEXT }, /* Teletext */ | ||
83 | { 0xeb45, KEY_DELETE }, | ||
84 | { 0xeb46, KEY_TV }, | ||
85 | { 0xeb47, KEY_DVD }, | ||
86 | { 0xeb48, KEY_STOP }, | ||
87 | { 0xeb49, KEY_VIDEO }, | ||
88 | { 0xeb4a, KEY_AUDIO }, /* Music */ | ||
89 | { 0xeb4b, KEY_SCREEN }, /* Pic */ | ||
90 | { 0xeb4c, KEY_PLAY }, | ||
91 | { 0xeb4d, KEY_BACK }, | ||
92 | { 0xeb4e, KEY_REWIND }, | ||
93 | { 0xeb4f, KEY_FASTFORWARD }, | ||
94 | { 0xeb54, KEY_PREVIOUS }, | ||
95 | { 0xeb58, KEY_RECORD }, | ||
96 | { 0xeb5c, KEY_NEXT }, | ||
97 | |||
98 | /* Key codes for the Haupauge WinTV Nova-TD, copied from nova-t-usb2.c (Nova-T USB2) */ | ||
99 | { 0x1e00, KEY_0 }, | ||
100 | { 0x1e01, KEY_1 }, | ||
101 | { 0x1e02, KEY_2 }, | ||
102 | { 0x1e03, KEY_3 }, | ||
103 | { 0x1e04, KEY_4 }, | ||
104 | { 0x1e05, KEY_5 }, | ||
105 | { 0x1e06, KEY_6 }, | ||
106 | { 0x1e07, KEY_7 }, | ||
107 | { 0x1e08, KEY_8 }, | ||
108 | { 0x1e09, KEY_9 }, | ||
109 | { 0x1e0a, KEY_KPASTERISK }, | ||
110 | { 0x1e0b, KEY_RED }, | ||
111 | { 0x1e0c, KEY_RADIO }, | ||
112 | { 0x1e0d, KEY_MENU }, | ||
113 | { 0x1e0e, KEY_GRAVE }, /* # */ | ||
114 | { 0x1e0f, KEY_MUTE }, | ||
115 | { 0x1e10, KEY_VOLUMEUP }, | ||
116 | { 0x1e11, KEY_VOLUMEDOWN }, | ||
117 | { 0x1e12, KEY_CHANNEL }, | ||
118 | { 0x1e14, KEY_UP }, | ||
119 | { 0x1e15, KEY_DOWN }, | ||
120 | { 0x1e16, KEY_LEFT }, | ||
121 | { 0x1e17, KEY_RIGHT }, | ||
122 | { 0x1e18, KEY_VIDEO }, | ||
123 | { 0x1e19, KEY_AUDIO }, | ||
124 | { 0x1e1a, KEY_MEDIA }, | ||
125 | { 0x1e1b, KEY_EPG }, | ||
126 | { 0x1e1c, KEY_TV }, | ||
127 | { 0x1e1e, KEY_NEXT }, | ||
128 | { 0x1e1f, KEY_BACK }, | ||
129 | { 0x1e20, KEY_CHANNELUP }, | ||
130 | { 0x1e21, KEY_CHANNELDOWN }, | ||
131 | { 0x1e24, KEY_LAST }, /* Skip backwards */ | ||
132 | { 0x1e25, KEY_OK }, | ||
133 | { 0x1e29, KEY_BLUE}, | ||
134 | { 0x1e2e, KEY_GREEN }, | ||
135 | { 0x1e30, KEY_PAUSE }, | ||
136 | { 0x1e32, KEY_REWIND }, | ||
137 | { 0x1e34, KEY_FASTFORWARD }, | ||
138 | { 0x1e35, KEY_PLAY }, | ||
139 | { 0x1e36, KEY_STOP }, | ||
140 | { 0x1e37, KEY_RECORD }, | ||
141 | { 0x1e38, KEY_YELLOW }, | ||
142 | { 0x1e3b, KEY_GOTO }, | ||
143 | { 0x1e3d, KEY_POWER }, | ||
144 | |||
145 | /* Key codes for the Leadtek Winfast DTV Dongle */ | ||
146 | { 0x0042, KEY_POWER }, | ||
147 | { 0x077c, KEY_TUNER }, | ||
148 | { 0x0f4e, KEY_PRINT }, /* PREVIEW */ | ||
149 | { 0x0840, KEY_SCREEN }, /* full screen toggle*/ | ||
150 | { 0x0f71, KEY_DOT }, /* frequency */ | ||
151 | { 0x0743, KEY_0 }, | ||
152 | { 0x0c41, KEY_1 }, | ||
153 | { 0x0443, KEY_2 }, | ||
154 | { 0x0b7f, KEY_3 }, | ||
155 | { 0x0e41, KEY_4 }, | ||
156 | { 0x0643, KEY_5 }, | ||
157 | { 0x097f, KEY_6 }, | ||
158 | { 0x0d7e, KEY_7 }, | ||
159 | { 0x057c, KEY_8 }, | ||
160 | { 0x0a40, KEY_9 }, | ||
161 | { 0x0e4e, KEY_CLEAR }, | ||
162 | { 0x047c, KEY_CHANNEL }, /* show channel number */ | ||
163 | { 0x0f41, KEY_LAST }, /* recall */ | ||
164 | { 0x0342, KEY_MUTE }, | ||
165 | { 0x064c, KEY_RESERVED }, /* PIP button*/ | ||
166 | { 0x0172, KEY_SHUFFLE }, /* SNAPSHOT */ | ||
167 | { 0x0c4e, KEY_PLAYPAUSE }, /* TIMESHIFT */ | ||
168 | { 0x0b70, KEY_RECORD }, | ||
169 | { 0x037d, KEY_VOLUMEUP }, | ||
170 | { 0x017d, KEY_VOLUMEDOWN }, | ||
171 | { 0x0242, KEY_CHANNELUP }, | ||
172 | { 0x007d, KEY_CHANNELDOWN }, | ||
173 | |||
174 | /* Key codes for Nova-TD "credit card" remote control. */ | ||
175 | { 0x1d00, KEY_0 }, | ||
176 | { 0x1d01, KEY_1 }, | ||
177 | { 0x1d02, KEY_2 }, | ||
178 | { 0x1d03, KEY_3 }, | ||
179 | { 0x1d04, KEY_4 }, | ||
180 | { 0x1d05, KEY_5 }, | ||
181 | { 0x1d06, KEY_6 }, | ||
182 | { 0x1d07, KEY_7 }, | ||
183 | { 0x1d08, KEY_8 }, | ||
184 | { 0x1d09, KEY_9 }, | ||
185 | { 0x1d0a, KEY_TEXT }, | ||
186 | { 0x1d0d, KEY_MENU }, | ||
187 | { 0x1d0f, KEY_MUTE }, | ||
188 | { 0x1d10, KEY_VOLUMEUP }, | ||
189 | { 0x1d11, KEY_VOLUMEDOWN }, | ||
190 | { 0x1d12, KEY_CHANNEL }, | ||
191 | { 0x1d14, KEY_UP }, | ||
192 | { 0x1d15, KEY_DOWN }, | ||
193 | { 0x1d16, KEY_LEFT }, | ||
194 | { 0x1d17, KEY_RIGHT }, | ||
195 | { 0x1d1c, KEY_TV }, | ||
196 | { 0x1d1e, KEY_NEXT }, | ||
197 | { 0x1d1f, KEY_BACK }, | ||
198 | { 0x1d20, KEY_CHANNELUP }, | ||
199 | { 0x1d21, KEY_CHANNELDOWN }, | ||
200 | { 0x1d24, KEY_LAST }, | ||
201 | { 0x1d25, KEY_OK }, | ||
202 | { 0x1d30, KEY_PAUSE }, | ||
203 | { 0x1d32, KEY_REWIND }, | ||
204 | { 0x1d34, KEY_FASTFORWARD }, | ||
205 | { 0x1d35, KEY_PLAY }, | ||
206 | { 0x1d36, KEY_STOP }, | ||
207 | { 0x1d37, KEY_RECORD }, | ||
208 | { 0x1d3b, KEY_GOTO }, | ||
209 | { 0x1d3d, KEY_POWER }, | ||
210 | }; | ||
211 | |||
212 | static struct rc_keymap dib0700_rc5_map = { | ||
213 | .map = { | ||
214 | .scan = dib0700_rc5_table, | ||
215 | .size = ARRAY_SIZE(dib0700_rc5_table), | ||
216 | .ir_type = IR_TYPE_RC5, | ||
217 | .name = RC_MAP_DIB0700_RC5_TABLE, | ||
218 | } | ||
219 | }; | ||
220 | |||
221 | static int __init init_rc_map(void) | ||
222 | { | ||
223 | return ir_register_map(&dib0700_rc5_map); | ||
224 | } | ||
225 | |||
226 | static void __exit exit_rc_map(void) | ||
227 | { | ||
228 | ir_unregister_map(&dib0700_rc5_map); | ||
229 | } | ||
230 | |||
231 | module_init(init_rc_map) | ||
232 | module_exit(exit_rc_map) | ||
233 | |||
234 | MODULE_LICENSE("GPL"); | ||
235 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>"); | ||
diff --git a/drivers/media/IR/keymaps/rc-lirc.c b/drivers/media/IR/keymaps/rc-lirc.c new file mode 100644 index 000000000000..43fcf9035082 --- /dev/null +++ b/drivers/media/IR/keymaps/rc-lirc.c | |||
@@ -0,0 +1,41 @@ | |||
1 | /* rc-lirc.c - Empty dummy keytable, for use when its preferred to pass | ||
2 | * all raw IR data to the lirc userspace decoder. | ||
3 | * | ||
4 | * Copyright (c) 2010 by Jarod Wilson <jarod@redhat.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <media/ir-core.h> | ||
13 | |||
14 | static struct ir_scancode lirc[] = { | ||
15 | { }, | ||
16 | }; | ||
17 | |||
18 | static struct rc_keymap lirc_map = { | ||
19 | .map = { | ||
20 | .scan = lirc, | ||
21 | .size = ARRAY_SIZE(lirc), | ||
22 | .ir_type = IR_TYPE_LIRC, | ||
23 | .name = RC_MAP_LIRC, | ||
24 | } | ||
25 | }; | ||
26 | |||
27 | static int __init init_rc_map_lirc(void) | ||
28 | { | ||
29 | return ir_register_map(&lirc_map); | ||
30 | } | ||
31 | |||
32 | static void __exit exit_rc_map_lirc(void) | ||
33 | { | ||
34 | ir_unregister_map(&lirc_map); | ||
35 | } | ||
36 | |||
37 | module_init(init_rc_map_lirc) | ||
38 | module_exit(exit_rc_map_lirc) | ||
39 | |||
40 | MODULE_LICENSE("GPL"); | ||
41 | MODULE_AUTHOR("Jarod Wilson <jarod@redhat.com>"); | ||
diff --git a/drivers/media/IR/keymaps/rc-rc6-mce.c b/drivers/media/IR/keymaps/rc-rc6-mce.c new file mode 100644 index 000000000000..c6726a8039be --- /dev/null +++ b/drivers/media/IR/keymaps/rc-rc6-mce.c | |||
@@ -0,0 +1,105 @@ | |||
1 | /* rc-rc6-mce.c - Keytable for Windows Media Center RC-6 remotes for use | ||
2 | * with the Media Center Edition eHome Infrared Transceiver. | ||
3 | * | ||
4 | * Copyright (c) 2010 by Jarod Wilson <jarod@redhat.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <media/rc-map.h> | ||
13 | |||
14 | static struct ir_scancode rc6_mce[] = { | ||
15 | { 0x800f0415, KEY_REWIND }, | ||
16 | { 0x800f0414, KEY_FASTFORWARD }, | ||
17 | { 0x800f041b, KEY_PREVIOUS }, | ||
18 | { 0x800f041a, KEY_NEXT }, | ||
19 | |||
20 | { 0x800f0416, KEY_PLAY }, | ||
21 | { 0x800f0418, KEY_PAUSE }, | ||
22 | { 0x800f0419, KEY_STOP }, | ||
23 | { 0x800f0417, KEY_RECORD }, | ||
24 | |||
25 | { 0x800f041e, KEY_UP }, | ||
26 | { 0x800f041f, KEY_DOWN }, | ||
27 | { 0x800f0420, KEY_LEFT }, | ||
28 | { 0x800f0421, KEY_RIGHT }, | ||
29 | |||
30 | { 0x800f040b, KEY_ENTER }, | ||
31 | { 0x800f0422, KEY_OK }, | ||
32 | { 0x800f0423, KEY_EXIT }, | ||
33 | { 0x800f040a, KEY_DELETE }, | ||
34 | |||
35 | { 0x800f040e, KEY_MUTE }, | ||
36 | { 0x800f0410, KEY_VOLUMEUP }, | ||
37 | { 0x800f0411, KEY_VOLUMEDOWN }, | ||
38 | { 0x800f0412, KEY_CHANNELUP }, | ||
39 | { 0x800f0413, KEY_CHANNELDOWN }, | ||
40 | |||
41 | { 0x800f0401, KEY_NUMERIC_1 }, | ||
42 | { 0x800f0402, KEY_NUMERIC_2 }, | ||
43 | { 0x800f0403, KEY_NUMERIC_3 }, | ||
44 | { 0x800f0404, KEY_NUMERIC_4 }, | ||
45 | { 0x800f0405, KEY_NUMERIC_5 }, | ||
46 | { 0x800f0406, KEY_NUMERIC_6 }, | ||
47 | { 0x800f0407, KEY_NUMERIC_7 }, | ||
48 | { 0x800f0408, KEY_NUMERIC_8 }, | ||
49 | { 0x800f0409, KEY_NUMERIC_9 }, | ||
50 | { 0x800f0400, KEY_NUMERIC_0 }, | ||
51 | |||
52 | { 0x800f041d, KEY_NUMERIC_STAR }, | ||
53 | { 0x800f041c, KEY_NUMERIC_POUND }, | ||
54 | |||
55 | { 0x800f0446, KEY_TV }, | ||
56 | { 0x800f0447, KEY_AUDIO }, /* My Music */ | ||
57 | { 0x800f0448, KEY_PVR }, /* RecordedTV */ | ||
58 | { 0x800f0449, KEY_CAMERA }, | ||
59 | { 0x800f044a, KEY_VIDEO }, | ||
60 | { 0x800f0424, KEY_DVD }, | ||
61 | { 0x800f0425, KEY_TUNER }, /* LiveTV */ | ||
62 | { 0x800f0450, KEY_RADIO }, | ||
63 | |||
64 | { 0x800f044c, KEY_LANGUAGE }, | ||
65 | { 0x800f0427, KEY_ZOOM }, /* Aspect */ | ||
66 | |||
67 | { 0x800f045b, KEY_RED }, | ||
68 | { 0x800f045c, KEY_GREEN }, | ||
69 | { 0x800f045d, KEY_YELLOW }, | ||
70 | { 0x800f045e, KEY_BLUE }, | ||
71 | |||
72 | { 0x800f040f, KEY_INFO }, | ||
73 | { 0x800f0426, KEY_EPG }, /* Guide */ | ||
74 | { 0x800f045a, KEY_SUBTITLE }, /* Caption/Teletext */ | ||
75 | { 0x800f044d, KEY_TITLE }, | ||
76 | |||
77 | { 0x800f040c, KEY_POWER }, | ||
78 | { 0x800f040d, KEY_PROG1 }, /* Windows MCE button */ | ||
79 | |||
80 | }; | ||
81 | |||
82 | static struct rc_keymap rc6_mce_map = { | ||
83 | .map = { | ||
84 | .scan = rc6_mce, | ||
85 | .size = ARRAY_SIZE(rc6_mce), | ||
86 | .ir_type = IR_TYPE_RC6, | ||
87 | .name = RC_MAP_RC6_MCE, | ||
88 | } | ||
89 | }; | ||
90 | |||
91 | static int __init init_rc_map_rc6_mce(void) | ||
92 | { | ||
93 | return ir_register_map(&rc6_mce_map); | ||
94 | } | ||
95 | |||
96 | static void __exit exit_rc_map_rc6_mce(void) | ||
97 | { | ||
98 | ir_unregister_map(&rc6_mce_map); | ||
99 | } | ||
100 | |||
101 | module_init(init_rc_map_rc6_mce) | ||
102 | module_exit(exit_rc_map_rc6_mce) | ||
103 | |||
104 | MODULE_LICENSE("GPL"); | ||
105 | MODULE_AUTHOR("Jarod Wilson <jarod@redhat.com>"); | ||
diff --git a/drivers/media/IR/lirc_dev.c b/drivers/media/IR/lirc_dev.c new file mode 100644 index 000000000000..899891bec352 --- /dev/null +++ b/drivers/media/IR/lirc_dev.c | |||
@@ -0,0 +1,764 @@ | |||
1 | /* | ||
2 | * LIRC base driver | ||
3 | * | ||
4 | * by Artur Lipowski <alipowski@interia.pl> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | * | ||
20 | */ | ||
21 | |||
22 | #include <linux/module.h> | ||
23 | #include <linux/kernel.h> | ||
24 | #include <linux/sched.h> | ||
25 | #include <linux/errno.h> | ||
26 | #include <linux/ioctl.h> | ||
27 | #include <linux/fs.h> | ||
28 | #include <linux/poll.h> | ||
29 | #include <linux/completion.h> | ||
30 | #include <linux/errno.h> | ||
31 | #include <linux/mutex.h> | ||
32 | #include <linux/wait.h> | ||
33 | #include <linux/unistd.h> | ||
34 | #include <linux/kthread.h> | ||
35 | #include <linux/bitops.h> | ||
36 | #include <linux/device.h> | ||
37 | #include <linux/cdev.h> | ||
38 | |||
39 | #include <media/lirc.h> | ||
40 | #include <media/lirc_dev.h> | ||
41 | |||
42 | static int debug; | ||
43 | |||
44 | #define IRCTL_DEV_NAME "BaseRemoteCtl" | ||
45 | #define NOPLUG -1 | ||
46 | #define LOGHEAD "lirc_dev (%s[%d]): " | ||
47 | |||
48 | static dev_t lirc_base_dev; | ||
49 | |||
50 | struct irctl { | ||
51 | struct lirc_driver d; | ||
52 | int attached; | ||
53 | int open; | ||
54 | |||
55 | struct mutex irctl_lock; | ||
56 | struct lirc_buffer *buf; | ||
57 | unsigned int chunk_size; | ||
58 | |||
59 | struct task_struct *task; | ||
60 | long jiffies_to_wait; | ||
61 | |||
62 | struct cdev cdev; | ||
63 | }; | ||
64 | |||
65 | static DEFINE_MUTEX(lirc_dev_lock); | ||
66 | |||
67 | static struct irctl *irctls[MAX_IRCTL_DEVICES]; | ||
68 | |||
69 | /* Only used for sysfs but defined to void otherwise */ | ||
70 | static struct class *lirc_class; | ||
71 | |||
72 | /* helper function | ||
73 | * initializes the irctl structure | ||
74 | */ | ||
75 | static void init_irctl(struct irctl *ir) | ||
76 | { | ||
77 | dev_dbg(ir->d.dev, LOGHEAD "initializing irctl\n", | ||
78 | ir->d.name, ir->d.minor); | ||
79 | mutex_init(&ir->irctl_lock); | ||
80 | ir->d.minor = NOPLUG; | ||
81 | } | ||
82 | |||
83 | static void cleanup(struct irctl *ir) | ||
84 | { | ||
85 | dev_dbg(ir->d.dev, LOGHEAD "cleaning up\n", ir->d.name, ir->d.minor); | ||
86 | |||
87 | device_destroy(lirc_class, MKDEV(MAJOR(lirc_base_dev), ir->d.minor)); | ||
88 | |||
89 | if (ir->buf != ir->d.rbuf) { | ||
90 | lirc_buffer_free(ir->buf); | ||
91 | kfree(ir->buf); | ||
92 | } | ||
93 | ir->buf = NULL; | ||
94 | } | ||
95 | |||
96 | /* helper function | ||
97 | * reads key codes from driver and puts them into buffer | ||
98 | * returns 0 on success | ||
99 | */ | ||
100 | static int add_to_buf(struct irctl *ir) | ||
101 | { | ||
102 | if (ir->d.add_to_buf) { | ||
103 | int res = -ENODATA; | ||
104 | int got_data = 0; | ||
105 | |||
106 | /* | ||
107 | * service the device as long as it is returning | ||
108 | * data and we have space | ||
109 | */ | ||
110 | get_data: | ||
111 | res = ir->d.add_to_buf(ir->d.data, ir->buf); | ||
112 | if (res == 0) { | ||
113 | got_data++; | ||
114 | goto get_data; | ||
115 | } | ||
116 | |||
117 | if (res == -ENODEV) | ||
118 | kthread_stop(ir->task); | ||
119 | |||
120 | return got_data ? 0 : res; | ||
121 | } | ||
122 | |||
123 | return 0; | ||
124 | } | ||
125 | |||
126 | /* main function of the polling thread | ||
127 | */ | ||
128 | static int lirc_thread(void *irctl) | ||
129 | { | ||
130 | struct irctl *ir = irctl; | ||
131 | |||
132 | dev_dbg(ir->d.dev, LOGHEAD "poll thread started\n", | ||
133 | ir->d.name, ir->d.minor); | ||
134 | |||
135 | do { | ||
136 | if (ir->open) { | ||
137 | if (ir->jiffies_to_wait) { | ||
138 | set_current_state(TASK_INTERRUPTIBLE); | ||
139 | schedule_timeout(ir->jiffies_to_wait); | ||
140 | } | ||
141 | if (kthread_should_stop()) | ||
142 | break; | ||
143 | if (!add_to_buf(ir)) | ||
144 | wake_up_interruptible(&ir->buf->wait_poll); | ||
145 | } else { | ||
146 | set_current_state(TASK_INTERRUPTIBLE); | ||
147 | schedule(); | ||
148 | } | ||
149 | } while (!kthread_should_stop()); | ||
150 | |||
151 | dev_dbg(ir->d.dev, LOGHEAD "poll thread ended\n", | ||
152 | ir->d.name, ir->d.minor); | ||
153 | |||
154 | return 0; | ||
155 | } | ||
156 | |||
157 | |||
158 | static struct file_operations fops = { | ||
159 | .owner = THIS_MODULE, | ||
160 | .read = lirc_dev_fop_read, | ||
161 | .write = lirc_dev_fop_write, | ||
162 | .poll = lirc_dev_fop_poll, | ||
163 | .unlocked_ioctl = lirc_dev_fop_ioctl, | ||
164 | .open = lirc_dev_fop_open, | ||
165 | .release = lirc_dev_fop_close, | ||
166 | }; | ||
167 | |||
168 | static int lirc_cdev_add(struct irctl *ir) | ||
169 | { | ||
170 | int retval; | ||
171 | struct lirc_driver *d = &ir->d; | ||
172 | |||
173 | if (d->fops) { | ||
174 | cdev_init(&ir->cdev, d->fops); | ||
175 | ir->cdev.owner = d->owner; | ||
176 | } else { | ||
177 | cdev_init(&ir->cdev, &fops); | ||
178 | ir->cdev.owner = THIS_MODULE; | ||
179 | } | ||
180 | kobject_set_name(&ir->cdev.kobj, "lirc%d", d->minor); | ||
181 | |||
182 | retval = cdev_add(&ir->cdev, MKDEV(MAJOR(lirc_base_dev), d->minor), 1); | ||
183 | if (retval) | ||
184 | kobject_put(&ir->cdev.kobj); | ||
185 | |||
186 | return retval; | ||
187 | } | ||
188 | |||
189 | int lirc_register_driver(struct lirc_driver *d) | ||
190 | { | ||
191 | struct irctl *ir; | ||
192 | int minor; | ||
193 | int bytes_in_key; | ||
194 | unsigned int chunk_size; | ||
195 | unsigned int buffer_size; | ||
196 | int err; | ||
197 | |||
198 | if (!d) { | ||
199 | printk(KERN_ERR "lirc_dev: lirc_register_driver: " | ||
200 | "driver pointer must be not NULL!\n"); | ||
201 | err = -EBADRQC; | ||
202 | goto out; | ||
203 | } | ||
204 | |||
205 | if (MAX_IRCTL_DEVICES <= d->minor) { | ||
206 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | ||
207 | "\"minor\" must be between 0 and %d (%d)!\n", | ||
208 | MAX_IRCTL_DEVICES-1, d->minor); | ||
209 | err = -EBADRQC; | ||
210 | goto out; | ||
211 | } | ||
212 | |||
213 | if (1 > d->code_length || (BUFLEN * 8) < d->code_length) { | ||
214 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | ||
215 | "code length in bits for minor (%d) " | ||
216 | "must be less than %d!\n", | ||
217 | d->minor, BUFLEN * 8); | ||
218 | err = -EBADRQC; | ||
219 | goto out; | ||
220 | } | ||
221 | |||
222 | dev_dbg(d->dev, "lirc_dev: lirc_register_driver: sample_rate: %d\n", | ||
223 | d->sample_rate); | ||
224 | if (d->sample_rate) { | ||
225 | if (2 > d->sample_rate || HZ < d->sample_rate) { | ||
226 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | ||
227 | "sample_rate must be between 2 and %d!\n", HZ); | ||
228 | err = -EBADRQC; | ||
229 | goto out; | ||
230 | } | ||
231 | if (!d->add_to_buf) { | ||
232 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | ||
233 | "add_to_buf cannot be NULL when " | ||
234 | "sample_rate is set\n"); | ||
235 | err = -EBADRQC; | ||
236 | goto out; | ||
237 | } | ||
238 | } else if (!(d->fops && d->fops->read) && !d->rbuf) { | ||
239 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | ||
240 | "fops->read and rbuf cannot all be NULL!\n"); | ||
241 | err = -EBADRQC; | ||
242 | goto out; | ||
243 | } else if (!d->rbuf) { | ||
244 | if (!(d->fops && d->fops->read && d->fops->poll && | ||
245 | d->fops->unlocked_ioctl)) { | ||
246 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | ||
247 | "neither read, poll nor unlocked_ioctl can be NULL!\n"); | ||
248 | err = -EBADRQC; | ||
249 | goto out; | ||
250 | } | ||
251 | } | ||
252 | |||
253 | mutex_lock(&lirc_dev_lock); | ||
254 | |||
255 | minor = d->minor; | ||
256 | |||
257 | if (minor < 0) { | ||
258 | /* find first free slot for driver */ | ||
259 | for (minor = 0; minor < MAX_IRCTL_DEVICES; minor++) | ||
260 | if (!irctls[minor]) | ||
261 | break; | ||
262 | if (MAX_IRCTL_DEVICES == minor) { | ||
263 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | ||
264 | "no free slots for drivers!\n"); | ||
265 | err = -ENOMEM; | ||
266 | goto out_lock; | ||
267 | } | ||
268 | } else if (irctls[minor]) { | ||
269 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | ||
270 | "minor (%d) just registered!\n", minor); | ||
271 | err = -EBUSY; | ||
272 | goto out_lock; | ||
273 | } | ||
274 | |||
275 | ir = kzalloc(sizeof(struct irctl), GFP_KERNEL); | ||
276 | if (!ir) { | ||
277 | err = -ENOMEM; | ||
278 | goto out_lock; | ||
279 | } | ||
280 | init_irctl(ir); | ||
281 | irctls[minor] = ir; | ||
282 | d->minor = minor; | ||
283 | |||
284 | if (d->sample_rate) { | ||
285 | ir->jiffies_to_wait = HZ / d->sample_rate; | ||
286 | } else { | ||
287 | /* it means - wait for external event in task queue */ | ||
288 | ir->jiffies_to_wait = 0; | ||
289 | } | ||
290 | |||
291 | /* some safety check 8-) */ | ||
292 | d->name[sizeof(d->name)-1] = '\0'; | ||
293 | |||
294 | bytes_in_key = BITS_TO_LONGS(d->code_length) + | ||
295 | (d->code_length % 8 ? 1 : 0); | ||
296 | buffer_size = d->buffer_size ? d->buffer_size : BUFLEN / bytes_in_key; | ||
297 | chunk_size = d->chunk_size ? d->chunk_size : bytes_in_key; | ||
298 | |||
299 | if (d->rbuf) { | ||
300 | ir->buf = d->rbuf; | ||
301 | } else { | ||
302 | ir->buf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL); | ||
303 | if (!ir->buf) { | ||
304 | err = -ENOMEM; | ||
305 | goto out_lock; | ||
306 | } | ||
307 | err = lirc_buffer_init(ir->buf, chunk_size, buffer_size); | ||
308 | if (err) { | ||
309 | kfree(ir->buf); | ||
310 | goto out_lock; | ||
311 | } | ||
312 | } | ||
313 | ir->chunk_size = ir->buf->chunk_size; | ||
314 | |||
315 | if (d->features == 0) | ||
316 | d->features = LIRC_CAN_REC_LIRCCODE; | ||
317 | |||
318 | ir->d = *d; | ||
319 | ir->d.minor = minor; | ||
320 | |||
321 | device_create(lirc_class, ir->d.dev, | ||
322 | MKDEV(MAJOR(lirc_base_dev), ir->d.minor), NULL, | ||
323 | "lirc%u", ir->d.minor); | ||
324 | |||
325 | if (d->sample_rate) { | ||
326 | /* try to fire up polling thread */ | ||
327 | ir->task = kthread_run(lirc_thread, (void *)ir, "lirc_dev"); | ||
328 | if (IS_ERR(ir->task)) { | ||
329 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | ||
330 | "cannot run poll thread for minor = %d\n", | ||
331 | d->minor); | ||
332 | err = -ECHILD; | ||
333 | goto out_sysfs; | ||
334 | } | ||
335 | } | ||
336 | |||
337 | err = lirc_cdev_add(ir); | ||
338 | if (err) | ||
339 | goto out_sysfs; | ||
340 | |||
341 | ir->attached = 1; | ||
342 | mutex_unlock(&lirc_dev_lock); | ||
343 | |||
344 | dev_info(ir->d.dev, "lirc_dev: driver %s registered at minor = %d\n", | ||
345 | ir->d.name, ir->d.minor); | ||
346 | return minor; | ||
347 | |||
348 | out_sysfs: | ||
349 | device_destroy(lirc_class, MKDEV(MAJOR(lirc_base_dev), ir->d.minor)); | ||
350 | out_lock: | ||
351 | mutex_unlock(&lirc_dev_lock); | ||
352 | out: | ||
353 | return err; | ||
354 | } | ||
355 | EXPORT_SYMBOL(lirc_register_driver); | ||
356 | |||
357 | int lirc_unregister_driver(int minor) | ||
358 | { | ||
359 | struct irctl *ir; | ||
360 | |||
361 | if (minor < 0 || minor >= MAX_IRCTL_DEVICES) { | ||
362 | printk(KERN_ERR "lirc_dev: lirc_unregister_driver: " | ||
363 | "\"minor (%d)\" must be between 0 and %d!\n", | ||
364 | minor, MAX_IRCTL_DEVICES-1); | ||
365 | return -EBADRQC; | ||
366 | } | ||
367 | |||
368 | ir = irctls[minor]; | ||
369 | |||
370 | mutex_lock(&lirc_dev_lock); | ||
371 | |||
372 | if (ir->d.minor != minor) { | ||
373 | printk(KERN_ERR "lirc_dev: lirc_unregister_driver: " | ||
374 | "minor (%d) device not registered!", minor); | ||
375 | mutex_unlock(&lirc_dev_lock); | ||
376 | return -ENOENT; | ||
377 | } | ||
378 | |||
379 | /* end up polling thread */ | ||
380 | if (ir->task) | ||
381 | kthread_stop(ir->task); | ||
382 | |||
383 | dev_dbg(ir->d.dev, "lirc_dev: driver %s unregistered from minor = %d\n", | ||
384 | ir->d.name, ir->d.minor); | ||
385 | |||
386 | ir->attached = 0; | ||
387 | if (ir->open) { | ||
388 | dev_dbg(ir->d.dev, LOGHEAD "releasing opened driver\n", | ||
389 | ir->d.name, ir->d.minor); | ||
390 | wake_up_interruptible(&ir->buf->wait_poll); | ||
391 | mutex_lock(&ir->irctl_lock); | ||
392 | ir->d.set_use_dec(ir->d.data); | ||
393 | module_put(ir->d.owner); | ||
394 | mutex_unlock(&ir->irctl_lock); | ||
395 | cdev_del(&ir->cdev); | ||
396 | } else { | ||
397 | cleanup(ir); | ||
398 | cdev_del(&ir->cdev); | ||
399 | kfree(ir); | ||
400 | irctls[minor] = NULL; | ||
401 | } | ||
402 | |||
403 | mutex_unlock(&lirc_dev_lock); | ||
404 | |||
405 | return 0; | ||
406 | } | ||
407 | EXPORT_SYMBOL(lirc_unregister_driver); | ||
408 | |||
409 | int lirc_dev_fop_open(struct inode *inode, struct file *file) | ||
410 | { | ||
411 | struct irctl *ir; | ||
412 | int retval = 0; | ||
413 | |||
414 | if (iminor(inode) >= MAX_IRCTL_DEVICES) { | ||
415 | printk(KERN_WARNING "lirc_dev [%d]: open result = -ENODEV\n", | ||
416 | iminor(inode)); | ||
417 | return -ENODEV; | ||
418 | } | ||
419 | |||
420 | if (mutex_lock_interruptible(&lirc_dev_lock)) | ||
421 | return -ERESTARTSYS; | ||
422 | |||
423 | ir = irctls[iminor(inode)]; | ||
424 | if (!ir) { | ||
425 | retval = -ENODEV; | ||
426 | goto error; | ||
427 | } | ||
428 | file->private_data = ir; | ||
429 | |||
430 | dev_dbg(ir->d.dev, LOGHEAD "open called\n", ir->d.name, ir->d.minor); | ||
431 | |||
432 | if (ir->d.minor == NOPLUG) { | ||
433 | retval = -ENODEV; | ||
434 | goto error; | ||
435 | } | ||
436 | |||
437 | if (ir->open) { | ||
438 | retval = -EBUSY; | ||
439 | goto error; | ||
440 | } | ||
441 | |||
442 | if (try_module_get(ir->d.owner)) { | ||
443 | ++ir->open; | ||
444 | retval = ir->d.set_use_inc(ir->d.data); | ||
445 | |||
446 | if (retval) { | ||
447 | module_put(ir->d.owner); | ||
448 | --ir->open; | ||
449 | } else { | ||
450 | lirc_buffer_clear(ir->buf); | ||
451 | } | ||
452 | if (ir->task) | ||
453 | wake_up_process(ir->task); | ||
454 | } | ||
455 | |||
456 | error: | ||
457 | if (ir) | ||
458 | dev_dbg(ir->d.dev, LOGHEAD "open result = %d\n", | ||
459 | ir->d.name, ir->d.minor, retval); | ||
460 | |||
461 | mutex_unlock(&lirc_dev_lock); | ||
462 | |||
463 | return retval; | ||
464 | } | ||
465 | EXPORT_SYMBOL(lirc_dev_fop_open); | ||
466 | |||
467 | int lirc_dev_fop_close(struct inode *inode, struct file *file) | ||
468 | { | ||
469 | struct irctl *ir = irctls[iminor(inode)]; | ||
470 | |||
471 | dev_dbg(ir->d.dev, LOGHEAD "close called\n", ir->d.name, ir->d.minor); | ||
472 | |||
473 | WARN_ON(mutex_lock_killable(&lirc_dev_lock)); | ||
474 | |||
475 | --ir->open; | ||
476 | if (ir->attached) { | ||
477 | ir->d.set_use_dec(ir->d.data); | ||
478 | module_put(ir->d.owner); | ||
479 | } else { | ||
480 | cleanup(ir); | ||
481 | irctls[ir->d.minor] = NULL; | ||
482 | kfree(ir); | ||
483 | } | ||
484 | |||
485 | mutex_unlock(&lirc_dev_lock); | ||
486 | |||
487 | return 0; | ||
488 | } | ||
489 | EXPORT_SYMBOL(lirc_dev_fop_close); | ||
490 | |||
491 | unsigned int lirc_dev_fop_poll(struct file *file, poll_table *wait) | ||
492 | { | ||
493 | struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)]; | ||
494 | unsigned int ret; | ||
495 | |||
496 | dev_dbg(ir->d.dev, LOGHEAD "poll called\n", ir->d.name, ir->d.minor); | ||
497 | |||
498 | if (!ir->attached) { | ||
499 | mutex_unlock(&ir->irctl_lock); | ||
500 | return POLLERR; | ||
501 | } | ||
502 | |||
503 | poll_wait(file, &ir->buf->wait_poll, wait); | ||
504 | |||
505 | if (ir->buf) | ||
506 | if (lirc_buffer_empty(ir->buf)) | ||
507 | ret = 0; | ||
508 | else | ||
509 | ret = POLLIN | POLLRDNORM; | ||
510 | else | ||
511 | ret = POLLERR; | ||
512 | |||
513 | dev_dbg(ir->d.dev, LOGHEAD "poll result = %d\n", | ||
514 | ir->d.name, ir->d.minor, ret); | ||
515 | |||
516 | return ret; | ||
517 | } | ||
518 | EXPORT_SYMBOL(lirc_dev_fop_poll); | ||
519 | |||
520 | long lirc_dev_fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | ||
521 | { | ||
522 | unsigned long mode; | ||
523 | int result = 0; | ||
524 | struct irctl *ir = file->private_data; | ||
525 | |||
526 | dev_dbg(ir->d.dev, LOGHEAD "ioctl called (0x%x)\n", | ||
527 | ir->d.name, ir->d.minor, cmd); | ||
528 | |||
529 | if (ir->d.minor == NOPLUG || !ir->attached) { | ||
530 | dev_dbg(ir->d.dev, LOGHEAD "ioctl result = -ENODEV\n", | ||
531 | ir->d.name, ir->d.minor); | ||
532 | return -ENODEV; | ||
533 | } | ||
534 | |||
535 | mutex_lock(&ir->irctl_lock); | ||
536 | |||
537 | switch (cmd) { | ||
538 | case LIRC_GET_FEATURES: | ||
539 | result = put_user(ir->d.features, (unsigned long *)arg); | ||
540 | break; | ||
541 | case LIRC_GET_REC_MODE: | ||
542 | if (!(ir->d.features & LIRC_CAN_REC_MASK)) { | ||
543 | result = -ENOSYS; | ||
544 | break; | ||
545 | } | ||
546 | |||
547 | result = put_user(LIRC_REC2MODE | ||
548 | (ir->d.features & LIRC_CAN_REC_MASK), | ||
549 | (unsigned long *)arg); | ||
550 | break; | ||
551 | case LIRC_SET_REC_MODE: | ||
552 | if (!(ir->d.features & LIRC_CAN_REC_MASK)) { | ||
553 | result = -ENOSYS; | ||
554 | break; | ||
555 | } | ||
556 | |||
557 | result = get_user(mode, (unsigned long *)arg); | ||
558 | if (!result && !(LIRC_MODE2REC(mode) & ir->d.features)) | ||
559 | result = -EINVAL; | ||
560 | /* | ||
561 | * FIXME: We should actually set the mode somehow but | ||
562 | * for now, lirc_serial doesn't support mode changing either | ||
563 | */ | ||
564 | break; | ||
565 | case LIRC_GET_LENGTH: | ||
566 | result = put_user(ir->d.code_length, (unsigned long *)arg); | ||
567 | break; | ||
568 | case LIRC_GET_MIN_TIMEOUT: | ||
569 | if (!(ir->d.features & LIRC_CAN_SET_REC_TIMEOUT) || | ||
570 | ir->d.min_timeout == 0) { | ||
571 | result = -ENOSYS; | ||
572 | break; | ||
573 | } | ||
574 | |||
575 | result = put_user(ir->d.min_timeout, (unsigned long *)arg); | ||
576 | break; | ||
577 | case LIRC_GET_MAX_TIMEOUT: | ||
578 | if (!(ir->d.features & LIRC_CAN_SET_REC_TIMEOUT) || | ||
579 | ir->d.max_timeout == 0) { | ||
580 | result = -ENOSYS; | ||
581 | break; | ||
582 | } | ||
583 | |||
584 | result = put_user(ir->d.max_timeout, (unsigned long *)arg); | ||
585 | break; | ||
586 | default: | ||
587 | result = -EINVAL; | ||
588 | } | ||
589 | |||
590 | dev_dbg(ir->d.dev, LOGHEAD "ioctl result = %d\n", | ||
591 | ir->d.name, ir->d.minor, result); | ||
592 | |||
593 | mutex_unlock(&ir->irctl_lock); | ||
594 | |||
595 | return result; | ||
596 | } | ||
597 | EXPORT_SYMBOL(lirc_dev_fop_ioctl); | ||
598 | |||
599 | ssize_t lirc_dev_fop_read(struct file *file, | ||
600 | char *buffer, | ||
601 | size_t length, | ||
602 | loff_t *ppos) | ||
603 | { | ||
604 | struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)]; | ||
605 | unsigned char buf[ir->chunk_size]; | ||
606 | int ret = 0, written = 0; | ||
607 | DECLARE_WAITQUEUE(wait, current); | ||
608 | |||
609 | dev_dbg(ir->d.dev, LOGHEAD "read called\n", ir->d.name, ir->d.minor); | ||
610 | |||
611 | if (mutex_lock_interruptible(&ir->irctl_lock)) | ||
612 | return -ERESTARTSYS; | ||
613 | if (!ir->attached) { | ||
614 | mutex_unlock(&ir->irctl_lock); | ||
615 | return -ENODEV; | ||
616 | } | ||
617 | |||
618 | if (length % ir->chunk_size) { | ||
619 | dev_dbg(ir->d.dev, LOGHEAD "read result = -EINVAL\n", | ||
620 | ir->d.name, ir->d.minor); | ||
621 | mutex_unlock(&ir->irctl_lock); | ||
622 | return -EINVAL; | ||
623 | } | ||
624 | |||
625 | /* | ||
626 | * we add ourselves to the task queue before buffer check | ||
627 | * to avoid losing scan code (in case when queue is awaken somewhere | ||
628 | * between while condition checking and scheduling) | ||
629 | */ | ||
630 | add_wait_queue(&ir->buf->wait_poll, &wait); | ||
631 | set_current_state(TASK_INTERRUPTIBLE); | ||
632 | |||
633 | /* | ||
634 | * while we didn't provide 'length' bytes, device is opened in blocking | ||
635 | * mode and 'copy_to_user' is happy, wait for data. | ||
636 | */ | ||
637 | while (written < length && ret == 0) { | ||
638 | if (lirc_buffer_empty(ir->buf)) { | ||
639 | /* According to the read(2) man page, 'written' can be | ||
640 | * returned as less than 'length', instead of blocking | ||
641 | * again, returning -EWOULDBLOCK, or returning | ||
642 | * -ERESTARTSYS */ | ||
643 | if (written) | ||
644 | break; | ||
645 | if (file->f_flags & O_NONBLOCK) { | ||
646 | ret = -EWOULDBLOCK; | ||
647 | break; | ||
648 | } | ||
649 | if (signal_pending(current)) { | ||
650 | ret = -ERESTARTSYS; | ||
651 | break; | ||
652 | } | ||
653 | |||
654 | mutex_unlock(&ir->irctl_lock); | ||
655 | schedule(); | ||
656 | set_current_state(TASK_INTERRUPTIBLE); | ||
657 | |||
658 | if (mutex_lock_interruptible(&ir->irctl_lock)) { | ||
659 | ret = -ERESTARTSYS; | ||
660 | remove_wait_queue(&ir->buf->wait_poll, &wait); | ||
661 | set_current_state(TASK_RUNNING); | ||
662 | goto out_unlocked; | ||
663 | } | ||
664 | |||
665 | if (!ir->attached) { | ||
666 | ret = -ENODEV; | ||
667 | break; | ||
668 | } | ||
669 | } else { | ||
670 | lirc_buffer_read(ir->buf, buf); | ||
671 | ret = copy_to_user((void *)buffer+written, buf, | ||
672 | ir->buf->chunk_size); | ||
673 | written += ir->buf->chunk_size; | ||
674 | } | ||
675 | } | ||
676 | |||
677 | remove_wait_queue(&ir->buf->wait_poll, &wait); | ||
678 | set_current_state(TASK_RUNNING); | ||
679 | mutex_unlock(&ir->irctl_lock); | ||
680 | |||
681 | out_unlocked: | ||
682 | dev_dbg(ir->d.dev, LOGHEAD "read result = %s (%d)\n", | ||
683 | ir->d.name, ir->d.minor, ret ? "-EFAULT" : "OK", ret); | ||
684 | |||
685 | return ret ? ret : written; | ||
686 | } | ||
687 | EXPORT_SYMBOL(lirc_dev_fop_read); | ||
688 | |||
689 | void *lirc_get_pdata(struct file *file) | ||
690 | { | ||
691 | void *data = NULL; | ||
692 | |||
693 | if (file && file->f_dentry && file->f_dentry->d_inode && | ||
694 | file->f_dentry->d_inode->i_rdev) { | ||
695 | struct irctl *ir; | ||
696 | ir = irctls[iminor(file->f_dentry->d_inode)]; | ||
697 | data = ir->d.data; | ||
698 | } | ||
699 | |||
700 | return data; | ||
701 | } | ||
702 | EXPORT_SYMBOL(lirc_get_pdata); | ||
703 | |||
704 | |||
705 | ssize_t lirc_dev_fop_write(struct file *file, const char *buffer, | ||
706 | size_t length, loff_t *ppos) | ||
707 | { | ||
708 | struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)]; | ||
709 | |||
710 | dev_dbg(ir->d.dev, LOGHEAD "write called\n", ir->d.name, ir->d.minor); | ||
711 | |||
712 | if (!ir->attached) | ||
713 | return -ENODEV; | ||
714 | |||
715 | return -EINVAL; | ||
716 | } | ||
717 | EXPORT_SYMBOL(lirc_dev_fop_write); | ||
718 | |||
719 | |||
720 | static int __init lirc_dev_init(void) | ||
721 | { | ||
722 | int retval; | ||
723 | |||
724 | lirc_class = class_create(THIS_MODULE, "lirc"); | ||
725 | if (IS_ERR(lirc_class)) { | ||
726 | retval = PTR_ERR(lirc_class); | ||
727 | printk(KERN_ERR "lirc_dev: class_create failed\n"); | ||
728 | goto error; | ||
729 | } | ||
730 | |||
731 | retval = alloc_chrdev_region(&lirc_base_dev, 0, MAX_IRCTL_DEVICES, | ||
732 | IRCTL_DEV_NAME); | ||
733 | if (retval) { | ||
734 | class_destroy(lirc_class); | ||
735 | printk(KERN_ERR "lirc_dev: alloc_chrdev_region failed\n"); | ||
736 | goto error; | ||
737 | } | ||
738 | |||
739 | |||
740 | printk(KERN_INFO "lirc_dev: IR Remote Control driver registered, " | ||
741 | "major %d \n", MAJOR(lirc_base_dev)); | ||
742 | |||
743 | error: | ||
744 | return retval; | ||
745 | } | ||
746 | |||
747 | |||
748 | |||
749 | static void __exit lirc_dev_exit(void) | ||
750 | { | ||
751 | class_destroy(lirc_class); | ||
752 | unregister_chrdev_region(lirc_base_dev, MAX_IRCTL_DEVICES); | ||
753 | printk(KERN_INFO "lirc_dev: module unloaded\n"); | ||
754 | } | ||
755 | |||
756 | module_init(lirc_dev_init); | ||
757 | module_exit(lirc_dev_exit); | ||
758 | |||
759 | MODULE_DESCRIPTION("LIRC base driver module"); | ||
760 | MODULE_AUTHOR("Artur Lipowski"); | ||
761 | MODULE_LICENSE("GPL"); | ||
762 | |||
763 | module_param(debug, bool, S_IRUGO | S_IWUSR); | ||
764 | MODULE_PARM_DESC(debug, "Enable debugging messages"); | ||
diff --git a/drivers/media/IR/mceusb.c b/drivers/media/IR/mceusb.c new file mode 100644 index 000000000000..78bf7f77a1a0 --- /dev/null +++ b/drivers/media/IR/mceusb.c | |||
@@ -0,0 +1,1143 @@ | |||
1 | /* | ||
2 | * Driver for USB Windows Media Center Ed. eHome Infrared Transceivers | ||
3 | * | ||
4 | * Copyright (c) 2010 by Jarod Wilson <jarod@redhat.com> | ||
5 | * | ||
6 | * Based on the original lirc_mceusb and lirc_mceusb2 drivers, by Dan | ||
7 | * Conti, Martin Blatter and Daniel Melander, the latter of which was | ||
8 | * in turn also based on the lirc_atiusb driver by Paul Miller. The | ||
9 | * two mce drivers were merged into one by Jarod Wilson, with transmit | ||
10 | * support for the 1st-gen device added primarily by Patrick Calhoun, | ||
11 | * with a bit of tweaks by Jarod. Debugging improvements and proper | ||
12 | * support for what appears to be 3rd-gen hardware added by Jarod. | ||
13 | * Initial port from lirc driver to ir-core drivery by Jarod, based | ||
14 | * partially on a port to an earlier proposed IR infrastructure by | ||
15 | * Jon Smirl, which included enhancements and simplifications to the | ||
16 | * incoming IR buffer parsing routines. | ||
17 | * | ||
18 | * | ||
19 | * This program is free software; you can redistribute it and/or modify | ||
20 | * it under the terms of the GNU General Public License as published by | ||
21 | * the Free Software Foundation; either version 2 of the License, or | ||
22 | * (at your option) any later version. | ||
23 | * | ||
24 | * This program is distributed in the hope that it will be useful, | ||
25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
27 | * GNU General Public License for more details. | ||
28 | * | ||
29 | * You should have received a copy of the GNU General Public License | ||
30 | * along with this program; if not, write to the Free Software | ||
31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
32 | * | ||
33 | */ | ||
34 | |||
35 | #include <linux/device.h> | ||
36 | #include <linux/module.h> | ||
37 | #include <linux/slab.h> | ||
38 | #include <linux/usb.h> | ||
39 | #include <linux/input.h> | ||
40 | #include <media/ir-core.h> | ||
41 | #include <media/ir-common.h> | ||
42 | |||
43 | #define DRIVER_VERSION "1.91" | ||
44 | #define DRIVER_AUTHOR "Jarod Wilson <jarod@wilsonet.com>" | ||
45 | #define DRIVER_DESC "Windows Media Center Ed. eHome Infrared Transceiver " \ | ||
46 | "device driver" | ||
47 | #define DRIVER_NAME "mceusb" | ||
48 | |||
49 | #define USB_BUFLEN 32 /* USB reception buffer length */ | ||
50 | #define USB_CTRL_MSG_SZ 2 /* Size of usb ctrl msg on gen1 hw */ | ||
51 | #define MCE_G1_INIT_MSGS 40 /* Init messages on gen1 hw to throw out */ | ||
52 | |||
53 | /* MCE constants */ | ||
54 | #define MCE_CMDBUF_SIZE 384 /* MCE Command buffer length */ | ||
55 | #define MCE_TIME_UNIT 50 /* Approx 50us resolution */ | ||
56 | #define MCE_CODE_LENGTH 5 /* Normal length of packet (with header) */ | ||
57 | #define MCE_PACKET_SIZE 4 /* Normal length of packet (without header) */ | ||
58 | #define MCE_PACKET_HEADER 0x84 /* Actual header format is 0x80 + num_bytes */ | ||
59 | #define MCE_CONTROL_HEADER 0x9F /* MCE status header */ | ||
60 | #define MCE_TX_HEADER_LENGTH 3 /* # of bytes in the initializing tx header */ | ||
61 | #define MCE_MAX_CHANNELS 2 /* Two transmitters, hardware dependent? */ | ||
62 | #define MCE_DEFAULT_TX_MASK 0x03 /* Val opts: TX1=0x01, TX2=0x02, ALL=0x03 */ | ||
63 | #define MCE_PULSE_BIT 0x80 /* Pulse bit, MSB set == PULSE else SPACE */ | ||
64 | #define MCE_PULSE_MASK 0x7F /* Pulse mask */ | ||
65 | #define MCE_MAX_PULSE_LENGTH 0x7F /* Longest transmittable pulse symbol */ | ||
66 | #define MCE_PACKET_LENGTH_MASK 0x1F /* Packet length mask */ | ||
67 | |||
68 | |||
69 | /* module parameters */ | ||
70 | #ifdef CONFIG_USB_DEBUG | ||
71 | static int debug = 1; | ||
72 | #else | ||
73 | static int debug; | ||
74 | #endif | ||
75 | |||
76 | /* general constants */ | ||
77 | #define SEND_FLAG_IN_PROGRESS 1 | ||
78 | #define SEND_FLAG_COMPLETE 2 | ||
79 | #define RECV_FLAG_IN_PROGRESS 3 | ||
80 | #define RECV_FLAG_COMPLETE 4 | ||
81 | |||
82 | #define MCEUSB_RX 1 | ||
83 | #define MCEUSB_TX 2 | ||
84 | |||
85 | #define VENDOR_PHILIPS 0x0471 | ||
86 | #define VENDOR_SMK 0x0609 | ||
87 | #define VENDOR_TATUNG 0x1460 | ||
88 | #define VENDOR_GATEWAY 0x107b | ||
89 | #define VENDOR_SHUTTLE 0x1308 | ||
90 | #define VENDOR_SHUTTLE2 0x051c | ||
91 | #define VENDOR_MITSUMI 0x03ee | ||
92 | #define VENDOR_TOPSEED 0x1784 | ||
93 | #define VENDOR_RICAVISION 0x179d | ||
94 | #define VENDOR_ITRON 0x195d | ||
95 | #define VENDOR_FIC 0x1509 | ||
96 | #define VENDOR_LG 0x043e | ||
97 | #define VENDOR_MICROSOFT 0x045e | ||
98 | #define VENDOR_FORMOSA 0x147a | ||
99 | #define VENDOR_FINTEK 0x1934 | ||
100 | #define VENDOR_PINNACLE 0x2304 | ||
101 | #define VENDOR_ECS 0x1019 | ||
102 | #define VENDOR_WISTRON 0x0fb8 | ||
103 | #define VENDOR_COMPRO 0x185b | ||
104 | #define VENDOR_NORTHSTAR 0x04eb | ||
105 | #define VENDOR_REALTEK 0x0bda | ||
106 | #define VENDOR_TIVO 0x105a | ||
107 | |||
108 | static struct usb_device_id mceusb_dev_table[] = { | ||
109 | /* Original Microsoft MCE IR Transceiver (often HP-branded) */ | ||
110 | { USB_DEVICE(VENDOR_MICROSOFT, 0x006d) }, | ||
111 | /* Philips Infrared Transceiver - Sahara branded */ | ||
112 | { USB_DEVICE(VENDOR_PHILIPS, 0x0608) }, | ||
113 | /* Philips Infrared Transceiver - HP branded */ | ||
114 | { USB_DEVICE(VENDOR_PHILIPS, 0x060c) }, | ||
115 | /* Philips SRM5100 */ | ||
116 | { USB_DEVICE(VENDOR_PHILIPS, 0x060d) }, | ||
117 | /* Philips Infrared Transceiver - Omaura */ | ||
118 | { USB_DEVICE(VENDOR_PHILIPS, 0x060f) }, | ||
119 | /* Philips Infrared Transceiver - Spinel plus */ | ||
120 | { USB_DEVICE(VENDOR_PHILIPS, 0x0613) }, | ||
121 | /* Philips eHome Infrared Transceiver */ | ||
122 | { USB_DEVICE(VENDOR_PHILIPS, 0x0815) }, | ||
123 | /* Realtek MCE IR Receiver */ | ||
124 | { USB_DEVICE(VENDOR_REALTEK, 0x0161) }, | ||
125 | /* SMK/Toshiba G83C0004D410 */ | ||
126 | { USB_DEVICE(VENDOR_SMK, 0x031d) }, | ||
127 | /* SMK eHome Infrared Transceiver (Sony VAIO) */ | ||
128 | { USB_DEVICE(VENDOR_SMK, 0x0322) }, | ||
129 | /* bundled with Hauppauge PVR-150 */ | ||
130 | { USB_DEVICE(VENDOR_SMK, 0x0334) }, | ||
131 | /* SMK eHome Infrared Transceiver */ | ||
132 | { USB_DEVICE(VENDOR_SMK, 0x0338) }, | ||
133 | /* Tatung eHome Infrared Transceiver */ | ||
134 | { USB_DEVICE(VENDOR_TATUNG, 0x9150) }, | ||
135 | /* Shuttle eHome Infrared Transceiver */ | ||
136 | { USB_DEVICE(VENDOR_SHUTTLE, 0xc001) }, | ||
137 | /* Shuttle eHome Infrared Transceiver */ | ||
138 | { USB_DEVICE(VENDOR_SHUTTLE2, 0xc001) }, | ||
139 | /* Gateway eHome Infrared Transceiver */ | ||
140 | { USB_DEVICE(VENDOR_GATEWAY, 0x3009) }, | ||
141 | /* Mitsumi */ | ||
142 | { USB_DEVICE(VENDOR_MITSUMI, 0x2501) }, | ||
143 | /* Topseed eHome Infrared Transceiver */ | ||
144 | { USB_DEVICE(VENDOR_TOPSEED, 0x0001) }, | ||
145 | /* Topseed HP eHome Infrared Transceiver */ | ||
146 | { USB_DEVICE(VENDOR_TOPSEED, 0x0006) }, | ||
147 | /* Topseed eHome Infrared Transceiver */ | ||
148 | { USB_DEVICE(VENDOR_TOPSEED, 0x0007) }, | ||
149 | /* Topseed eHome Infrared Transceiver */ | ||
150 | { USB_DEVICE(VENDOR_TOPSEED, 0x0008) }, | ||
151 | /* Topseed eHome Infrared Transceiver */ | ||
152 | { USB_DEVICE(VENDOR_TOPSEED, 0x000a) }, | ||
153 | /* Topseed eHome Infrared Transceiver */ | ||
154 | { USB_DEVICE(VENDOR_TOPSEED, 0x0011) }, | ||
155 | /* Ricavision internal Infrared Transceiver */ | ||
156 | { USB_DEVICE(VENDOR_RICAVISION, 0x0010) }, | ||
157 | /* Itron ione Libra Q-11 */ | ||
158 | { USB_DEVICE(VENDOR_ITRON, 0x7002) }, | ||
159 | /* FIC eHome Infrared Transceiver */ | ||
160 | { USB_DEVICE(VENDOR_FIC, 0x9242) }, | ||
161 | /* LG eHome Infrared Transceiver */ | ||
162 | { USB_DEVICE(VENDOR_LG, 0x9803) }, | ||
163 | /* Microsoft MCE Infrared Transceiver */ | ||
164 | { USB_DEVICE(VENDOR_MICROSOFT, 0x00a0) }, | ||
165 | /* Formosa eHome Infrared Transceiver */ | ||
166 | { USB_DEVICE(VENDOR_FORMOSA, 0xe015) }, | ||
167 | /* Formosa21 / eHome Infrared Receiver */ | ||
168 | { USB_DEVICE(VENDOR_FORMOSA, 0xe016) }, | ||
169 | /* Formosa aim / Trust MCE Infrared Receiver */ | ||
170 | { USB_DEVICE(VENDOR_FORMOSA, 0xe017) }, | ||
171 | /* Formosa Industrial Computing / Beanbag Emulation Device */ | ||
172 | { USB_DEVICE(VENDOR_FORMOSA, 0xe018) }, | ||
173 | /* Formosa21 / eHome Infrared Receiver */ | ||
174 | { USB_DEVICE(VENDOR_FORMOSA, 0xe03a) }, | ||
175 | /* Formosa Industrial Computing AIM IR605/A */ | ||
176 | { USB_DEVICE(VENDOR_FORMOSA, 0xe03c) }, | ||
177 | /* Formosa Industrial Computing */ | ||
178 | { USB_DEVICE(VENDOR_FORMOSA, 0xe03e) }, | ||
179 | /* Fintek eHome Infrared Transceiver */ | ||
180 | { USB_DEVICE(VENDOR_FINTEK, 0x0602) }, | ||
181 | /* Fintek eHome Infrared Transceiver (in the AOpen MP45) */ | ||
182 | { USB_DEVICE(VENDOR_FINTEK, 0x0702) }, | ||
183 | /* Pinnacle Remote Kit */ | ||
184 | { USB_DEVICE(VENDOR_PINNACLE, 0x0225) }, | ||
185 | /* Elitegroup Computer Systems IR */ | ||
186 | { USB_DEVICE(VENDOR_ECS, 0x0f38) }, | ||
187 | /* Wistron Corp. eHome Infrared Receiver */ | ||
188 | { USB_DEVICE(VENDOR_WISTRON, 0x0002) }, | ||
189 | /* Compro K100 */ | ||
190 | { USB_DEVICE(VENDOR_COMPRO, 0x3020) }, | ||
191 | /* Compro K100 v2 */ | ||
192 | { USB_DEVICE(VENDOR_COMPRO, 0x3082) }, | ||
193 | /* Northstar Systems, Inc. eHome Infrared Transceiver */ | ||
194 | { USB_DEVICE(VENDOR_NORTHSTAR, 0xe004) }, | ||
195 | /* TiVo PC IR Receiver */ | ||
196 | { USB_DEVICE(VENDOR_TIVO, 0x2000) }, | ||
197 | /* Terminating entry */ | ||
198 | { } | ||
199 | }; | ||
200 | |||
201 | static struct usb_device_id gen3_list[] = { | ||
202 | { USB_DEVICE(VENDOR_PINNACLE, 0x0225) }, | ||
203 | { USB_DEVICE(VENDOR_TOPSEED, 0x0008) }, | ||
204 | {} | ||
205 | }; | ||
206 | |||
207 | static struct usb_device_id microsoft_gen1_list[] = { | ||
208 | { USB_DEVICE(VENDOR_MICROSOFT, 0x006d) }, | ||
209 | {} | ||
210 | }; | ||
211 | |||
212 | static struct usb_device_id std_tx_mask_list[] = { | ||
213 | { USB_DEVICE(VENDOR_MICROSOFT, 0x006d) }, | ||
214 | { USB_DEVICE(VENDOR_PHILIPS, 0x060c) }, | ||
215 | { USB_DEVICE(VENDOR_SMK, 0x031d) }, | ||
216 | { USB_DEVICE(VENDOR_SMK, 0x0322) }, | ||
217 | { USB_DEVICE(VENDOR_SMK, 0x0334) }, | ||
218 | { USB_DEVICE(VENDOR_TOPSEED, 0x0001) }, | ||
219 | { USB_DEVICE(VENDOR_TOPSEED, 0x0006) }, | ||
220 | { USB_DEVICE(VENDOR_TOPSEED, 0x0007) }, | ||
221 | { USB_DEVICE(VENDOR_TOPSEED, 0x0008) }, | ||
222 | { USB_DEVICE(VENDOR_TOPSEED, 0x000a) }, | ||
223 | { USB_DEVICE(VENDOR_TOPSEED, 0x0011) }, | ||
224 | { USB_DEVICE(VENDOR_PINNACLE, 0x0225) }, | ||
225 | {} | ||
226 | }; | ||
227 | |||
228 | /* data structure for each usb transceiver */ | ||
229 | struct mceusb_dev { | ||
230 | /* ir-core bits */ | ||
231 | struct ir_input_dev *irdev; | ||
232 | struct ir_dev_props *props; | ||
233 | struct ir_raw_event rawir; | ||
234 | |||
235 | /* core device bits */ | ||
236 | struct device *dev; | ||
237 | struct input_dev *idev; | ||
238 | |||
239 | /* usb */ | ||
240 | struct usb_device *usbdev; | ||
241 | struct urb *urb_in; | ||
242 | struct usb_endpoint_descriptor *usb_ep_in; | ||
243 | struct usb_endpoint_descriptor *usb_ep_out; | ||
244 | |||
245 | /* buffers and dma */ | ||
246 | unsigned char *buf_in; | ||
247 | unsigned int len_in; | ||
248 | u8 cmd; /* MCE command type */ | ||
249 | u8 rem; /* Remaining IR data bytes in packet */ | ||
250 | dma_addr_t dma_in; | ||
251 | dma_addr_t dma_out; | ||
252 | |||
253 | struct { | ||
254 | u32 connected:1; | ||
255 | u32 tx_mask_inverted:1; | ||
256 | u32 microsoft_gen1:1; | ||
257 | u32 reserved:29; | ||
258 | } flags; | ||
259 | |||
260 | /* transmit support */ | ||
261 | int send_flags; | ||
262 | u32 carrier; | ||
263 | unsigned char tx_mask; | ||
264 | |||
265 | char name[128]; | ||
266 | char phys[64]; | ||
267 | }; | ||
268 | |||
269 | /* | ||
270 | * MCE Device Command Strings | ||
271 | * Device command responses vary from device to device... | ||
272 | * - DEVICE_RESET resets the hardware to its default state | ||
273 | * - GET_REVISION fetches the hardware/software revision, common | ||
274 | * replies are ff 0b 45 ff 1b 08 and ff 0b 50 ff 1b 42 | ||
275 | * - GET_CARRIER_FREQ gets the carrier mode and frequency of the | ||
276 | * device, with replies in the form of 9f 06 MM FF, where MM is 0-3, | ||
277 | * meaning clk of 10000000, 2500000, 625000 or 156250, and FF is | ||
278 | * ((clk / frequency) - 1) | ||
279 | * - GET_RX_TIMEOUT fetches the receiver timeout in units of 50us, | ||
280 | * response in the form of 9f 0c msb lsb | ||
281 | * - GET_TX_BITMASK fetches the transmitter bitmask, replies in | ||
282 | * the form of 9f 08 bm, where bm is the bitmask | ||
283 | * - GET_RX_SENSOR fetches the RX sensor setting -- long-range | ||
284 | * general use one or short-range learning one, in the form of | ||
285 | * 9f 14 ss, where ss is either 01 for long-range or 02 for short | ||
286 | * - SET_CARRIER_FREQ sets a new carrier mode and frequency | ||
287 | * - SET_TX_BITMASK sets the transmitter bitmask | ||
288 | * - SET_RX_TIMEOUT sets the receiver timeout | ||
289 | * - SET_RX_SENSOR sets which receiver sensor to use | ||
290 | */ | ||
291 | static char DEVICE_RESET[] = {0x00, 0xff, 0xaa}; | ||
292 | static char GET_REVISION[] = {0xff, 0x0b}; | ||
293 | static char GET_UNKNOWN[] = {0xff, 0x18}; | ||
294 | static char GET_UNKNOWN2[] = {0x9f, 0x05}; | ||
295 | static char GET_CARRIER_FREQ[] = {0x9f, 0x07}; | ||
296 | static char GET_RX_TIMEOUT[] = {0x9f, 0x0d}; | ||
297 | static char GET_TX_BITMASK[] = {0x9f, 0x13}; | ||
298 | static char GET_RX_SENSOR[] = {0x9f, 0x15}; | ||
299 | /* sub in desired values in lower byte or bytes for full command */ | ||
300 | /* FIXME: make use of these for transmit. | ||
301 | static char SET_CARRIER_FREQ[] = {0x9f, 0x06, 0x00, 0x00}; | ||
302 | static char SET_TX_BITMASK[] = {0x9f, 0x08, 0x00}; | ||
303 | static char SET_RX_TIMEOUT[] = {0x9f, 0x0c, 0x00, 0x00}; | ||
304 | static char SET_RX_SENSOR[] = {0x9f, 0x14, 0x00}; | ||
305 | */ | ||
306 | |||
307 | static void mceusb_dev_printdata(struct mceusb_dev *ir, char *buf, | ||
308 | int len, bool out) | ||
309 | { | ||
310 | char codes[USB_BUFLEN * 3 + 1]; | ||
311 | char inout[9]; | ||
312 | int i; | ||
313 | u8 cmd, subcmd, data1, data2; | ||
314 | struct device *dev = ir->dev; | ||
315 | int idx = 0; | ||
316 | |||
317 | /* skip meaningless 0xb1 0x60 header bytes on orig receiver */ | ||
318 | if (ir->flags.microsoft_gen1 && !out) | ||
319 | idx = 2; | ||
320 | |||
321 | if (len <= idx) | ||
322 | return; | ||
323 | |||
324 | for (i = 0; i < len && i < USB_BUFLEN; i++) | ||
325 | snprintf(codes + i * 3, 4, "%02x ", buf[i] & 0xFF); | ||
326 | |||
327 | dev_info(dev, "%sx data: %s (length=%d)\n", | ||
328 | (out ? "t" : "r"), codes, len); | ||
329 | |||
330 | if (out) | ||
331 | strcpy(inout, "Request\0"); | ||
332 | else | ||
333 | strcpy(inout, "Got\0"); | ||
334 | |||
335 | cmd = buf[idx] & 0xff; | ||
336 | subcmd = buf[idx + 1] & 0xff; | ||
337 | data1 = buf[idx + 2] & 0xff; | ||
338 | data2 = buf[idx + 3] & 0xff; | ||
339 | |||
340 | switch (cmd) { | ||
341 | case 0x00: | ||
342 | if (subcmd == 0xff && data1 == 0xaa) | ||
343 | dev_info(dev, "Device reset requested\n"); | ||
344 | else | ||
345 | dev_info(dev, "Unknown command 0x%02x 0x%02x\n", | ||
346 | cmd, subcmd); | ||
347 | break; | ||
348 | case 0xff: | ||
349 | switch (subcmd) { | ||
350 | case 0x0b: | ||
351 | if (len == 2) | ||
352 | dev_info(dev, "Get hw/sw rev?\n"); | ||
353 | else | ||
354 | dev_info(dev, "hw/sw rev 0x%02x 0x%02x " | ||
355 | "0x%02x 0x%02x\n", data1, data2, | ||
356 | buf[idx + 4], buf[idx + 5]); | ||
357 | break; | ||
358 | case 0xaa: | ||
359 | dev_info(dev, "Device reset requested\n"); | ||
360 | break; | ||
361 | case 0xfe: | ||
362 | dev_info(dev, "Previous command not supported\n"); | ||
363 | break; | ||
364 | case 0x18: | ||
365 | case 0x1b: | ||
366 | default: | ||
367 | dev_info(dev, "Unknown command 0x%02x 0x%02x\n", | ||
368 | cmd, subcmd); | ||
369 | break; | ||
370 | } | ||
371 | break; | ||
372 | case 0x9f: | ||
373 | switch (subcmd) { | ||
374 | case 0x03: | ||
375 | dev_info(dev, "Ping\n"); | ||
376 | break; | ||
377 | case 0x04: | ||
378 | dev_info(dev, "Resp to 9f 05 of 0x%02x 0x%02x\n", | ||
379 | data1, data2); | ||
380 | break; | ||
381 | case 0x06: | ||
382 | dev_info(dev, "%s carrier mode and freq of " | ||
383 | "0x%02x 0x%02x\n", inout, data1, data2); | ||
384 | break; | ||
385 | case 0x07: | ||
386 | dev_info(dev, "Get carrier mode and freq\n"); | ||
387 | break; | ||
388 | case 0x08: | ||
389 | dev_info(dev, "%s transmit blaster mask of 0x%02x\n", | ||
390 | inout, data1); | ||
391 | break; | ||
392 | case 0x0c: | ||
393 | /* value is in units of 50us, so x*50/100 or x/2 ms */ | ||
394 | dev_info(dev, "%s receive timeout of %d ms\n", | ||
395 | inout, ((data1 << 8) | data2) / 2); | ||
396 | break; | ||
397 | case 0x0d: | ||
398 | dev_info(dev, "Get receive timeout\n"); | ||
399 | break; | ||
400 | case 0x13: | ||
401 | dev_info(dev, "Get transmit blaster mask\n"); | ||
402 | break; | ||
403 | case 0x14: | ||
404 | dev_info(dev, "%s %s-range receive sensor in use\n", | ||
405 | inout, data1 == 0x02 ? "short" : "long"); | ||
406 | break; | ||
407 | case 0x15: | ||
408 | if (len == 2) | ||
409 | dev_info(dev, "Get receive sensor\n"); | ||
410 | else | ||
411 | dev_info(dev, "Received pulse count is %d\n", | ||
412 | ((data1 << 8) | data2)); | ||
413 | break; | ||
414 | case 0xfe: | ||
415 | dev_info(dev, "Error! Hardware is likely wedged...\n"); | ||
416 | break; | ||
417 | case 0x05: | ||
418 | case 0x09: | ||
419 | case 0x0f: | ||
420 | default: | ||
421 | dev_info(dev, "Unknown command 0x%02x 0x%02x\n", | ||
422 | cmd, subcmd); | ||
423 | break; | ||
424 | } | ||
425 | break; | ||
426 | default: | ||
427 | break; | ||
428 | } | ||
429 | } | ||
430 | |||
431 | static void usb_async_callback(struct urb *urb, struct pt_regs *regs) | ||
432 | { | ||
433 | struct mceusb_dev *ir; | ||
434 | int len; | ||
435 | |||
436 | if (!urb) | ||
437 | return; | ||
438 | |||
439 | ir = urb->context; | ||
440 | if (ir) { | ||
441 | len = urb->actual_length; | ||
442 | |||
443 | dev_dbg(ir->dev, "callback called (status=%d len=%d)\n", | ||
444 | urb->status, len); | ||
445 | |||
446 | if (debug) | ||
447 | mceusb_dev_printdata(ir, urb->transfer_buffer, | ||
448 | len, true); | ||
449 | } | ||
450 | |||
451 | } | ||
452 | |||
453 | /* request incoming or send outgoing usb packet - used to initialize remote */ | ||
454 | static void mce_request_packet(struct mceusb_dev *ir, | ||
455 | struct usb_endpoint_descriptor *ep, | ||
456 | unsigned char *data, int size, int urb_type) | ||
457 | { | ||
458 | int res; | ||
459 | struct urb *async_urb; | ||
460 | struct device *dev = ir->dev; | ||
461 | unsigned char *async_buf; | ||
462 | |||
463 | if (urb_type == MCEUSB_TX) { | ||
464 | async_urb = usb_alloc_urb(0, GFP_KERNEL); | ||
465 | if (unlikely(!async_urb)) { | ||
466 | dev_err(dev, "Error, couldn't allocate urb!\n"); | ||
467 | return; | ||
468 | } | ||
469 | |||
470 | async_buf = kzalloc(size, GFP_KERNEL); | ||
471 | if (!async_buf) { | ||
472 | dev_err(dev, "Error, couldn't allocate buf!\n"); | ||
473 | usb_free_urb(async_urb); | ||
474 | return; | ||
475 | } | ||
476 | |||
477 | /* outbound data */ | ||
478 | usb_fill_int_urb(async_urb, ir->usbdev, | ||
479 | usb_sndintpipe(ir->usbdev, ep->bEndpointAddress), | ||
480 | async_buf, size, (usb_complete_t) usb_async_callback, | ||
481 | ir, ep->bInterval); | ||
482 | memcpy(async_buf, data, size); | ||
483 | |||
484 | } else if (urb_type == MCEUSB_RX) { | ||
485 | /* standard request */ | ||
486 | async_urb = ir->urb_in; | ||
487 | ir->send_flags = RECV_FLAG_IN_PROGRESS; | ||
488 | |||
489 | } else { | ||
490 | dev_err(dev, "Error! Unknown urb type %d\n", urb_type); | ||
491 | return; | ||
492 | } | ||
493 | |||
494 | dev_dbg(dev, "receive request called (size=%#x)\n", size); | ||
495 | |||
496 | async_urb->transfer_buffer_length = size; | ||
497 | async_urb->dev = ir->usbdev; | ||
498 | |||
499 | res = usb_submit_urb(async_urb, GFP_ATOMIC); | ||
500 | if (res) { | ||
501 | dev_dbg(dev, "receive request FAILED! (res=%d)\n", res); | ||
502 | return; | ||
503 | } | ||
504 | dev_dbg(dev, "receive request complete (res=%d)\n", res); | ||
505 | } | ||
506 | |||
507 | static void mce_async_out(struct mceusb_dev *ir, unsigned char *data, int size) | ||
508 | { | ||
509 | mce_request_packet(ir, ir->usb_ep_out, data, size, MCEUSB_TX); | ||
510 | } | ||
511 | |||
512 | static void mce_sync_in(struct mceusb_dev *ir, unsigned char *data, int size) | ||
513 | { | ||
514 | mce_request_packet(ir, ir->usb_ep_in, data, size, MCEUSB_RX); | ||
515 | } | ||
516 | |||
517 | /* Send data out the IR blaster port(s) */ | ||
518 | static int mceusb_tx_ir(void *priv, int *txbuf, u32 n) | ||
519 | { | ||
520 | struct mceusb_dev *ir = priv; | ||
521 | int i, ret = 0; | ||
522 | int count, cmdcount = 0; | ||
523 | unsigned char *cmdbuf; /* MCE command buffer */ | ||
524 | long signal_duration = 0; /* Singnal length in us */ | ||
525 | struct timeval start_time, end_time; | ||
526 | |||
527 | do_gettimeofday(&start_time); | ||
528 | |||
529 | count = n / sizeof(int); | ||
530 | |||
531 | cmdbuf = kzalloc(sizeof(int) * MCE_CMDBUF_SIZE, GFP_KERNEL); | ||
532 | if (!cmdbuf) | ||
533 | return -ENOMEM; | ||
534 | |||
535 | /* MCE tx init header */ | ||
536 | cmdbuf[cmdcount++] = MCE_CONTROL_HEADER; | ||
537 | cmdbuf[cmdcount++] = 0x08; | ||
538 | cmdbuf[cmdcount++] = ir->tx_mask; | ||
539 | |||
540 | /* Generate mce packet data */ | ||
541 | for (i = 0; (i < count) && (cmdcount < MCE_CMDBUF_SIZE); i++) { | ||
542 | signal_duration += txbuf[i]; | ||
543 | txbuf[i] = txbuf[i] / MCE_TIME_UNIT; | ||
544 | |||
545 | do { /* loop to support long pulses/spaces > 127*50us=6.35ms */ | ||
546 | |||
547 | /* Insert mce packet header every 4th entry */ | ||
548 | if ((cmdcount < MCE_CMDBUF_SIZE) && | ||
549 | (cmdcount - MCE_TX_HEADER_LENGTH) % | ||
550 | MCE_CODE_LENGTH == 0) | ||
551 | cmdbuf[cmdcount++] = MCE_PACKET_HEADER; | ||
552 | |||
553 | /* Insert mce packet data */ | ||
554 | if (cmdcount < MCE_CMDBUF_SIZE) | ||
555 | cmdbuf[cmdcount++] = | ||
556 | (txbuf[i] < MCE_PULSE_BIT ? | ||
557 | txbuf[i] : MCE_MAX_PULSE_LENGTH) | | ||
558 | (i & 1 ? 0x00 : MCE_PULSE_BIT); | ||
559 | else { | ||
560 | ret = -EINVAL; | ||
561 | goto out; | ||
562 | } | ||
563 | |||
564 | } while ((txbuf[i] > MCE_MAX_PULSE_LENGTH) && | ||
565 | (txbuf[i] -= MCE_MAX_PULSE_LENGTH)); | ||
566 | } | ||
567 | |||
568 | /* Fix packet length in last header */ | ||
569 | cmdbuf[cmdcount - (cmdcount - MCE_TX_HEADER_LENGTH) % MCE_CODE_LENGTH] = | ||
570 | 0x80 + (cmdcount - MCE_TX_HEADER_LENGTH) % MCE_CODE_LENGTH - 1; | ||
571 | |||
572 | /* Check if we have room for the empty packet at the end */ | ||
573 | if (cmdcount >= MCE_CMDBUF_SIZE) { | ||
574 | ret = -EINVAL; | ||
575 | goto out; | ||
576 | } | ||
577 | |||
578 | /* All mce commands end with an empty packet (0x80) */ | ||
579 | cmdbuf[cmdcount++] = 0x80; | ||
580 | |||
581 | /* Transmit the command to the mce device */ | ||
582 | mce_async_out(ir, cmdbuf, cmdcount); | ||
583 | |||
584 | /* | ||
585 | * The lircd gap calculation expects the write function to | ||
586 | * wait the time it takes for the ircommand to be sent before | ||
587 | * it returns. | ||
588 | */ | ||
589 | do_gettimeofday(&end_time); | ||
590 | signal_duration -= (end_time.tv_usec - start_time.tv_usec) + | ||
591 | (end_time.tv_sec - start_time.tv_sec) * 1000000; | ||
592 | |||
593 | /* delay with the closest number of ticks */ | ||
594 | set_current_state(TASK_INTERRUPTIBLE); | ||
595 | schedule_timeout(usecs_to_jiffies(signal_duration)); | ||
596 | |||
597 | out: | ||
598 | kfree(cmdbuf); | ||
599 | return ret ? ret : n; | ||
600 | } | ||
601 | |||
602 | /* Sets active IR outputs -- mce devices typically (all?) have two */ | ||
603 | static int mceusb_set_tx_mask(void *priv, u32 mask) | ||
604 | { | ||
605 | struct mceusb_dev *ir = priv; | ||
606 | |||
607 | if (ir->flags.tx_mask_inverted) | ||
608 | ir->tx_mask = (mask != 0x03 ? mask ^ 0x03 : mask) << 1; | ||
609 | else | ||
610 | ir->tx_mask = mask; | ||
611 | |||
612 | return 0; | ||
613 | } | ||
614 | |||
615 | /* Sets the send carrier frequency and mode */ | ||
616 | static int mceusb_set_tx_carrier(void *priv, u32 carrier) | ||
617 | { | ||
618 | struct mceusb_dev *ir = priv; | ||
619 | int clk = 10000000; | ||
620 | int prescaler = 0, divisor = 0; | ||
621 | unsigned char cmdbuf[4] = { 0x9f, 0x06, 0x00, 0x00 }; | ||
622 | |||
623 | /* Carrier has changed */ | ||
624 | if (ir->carrier != carrier) { | ||
625 | |||
626 | if (carrier == 0) { | ||
627 | ir->carrier = carrier; | ||
628 | cmdbuf[2] = 0x01; | ||
629 | cmdbuf[3] = 0x80; | ||
630 | dev_dbg(ir->dev, "%s: disabling carrier " | ||
631 | "modulation\n", __func__); | ||
632 | mce_async_out(ir, cmdbuf, sizeof(cmdbuf)); | ||
633 | return carrier; | ||
634 | } | ||
635 | |||
636 | for (prescaler = 0; prescaler < 4; ++prescaler) { | ||
637 | divisor = (clk >> (2 * prescaler)) / carrier; | ||
638 | if (divisor <= 0xFF) { | ||
639 | ir->carrier = carrier; | ||
640 | cmdbuf[2] = prescaler; | ||
641 | cmdbuf[3] = divisor; | ||
642 | dev_dbg(ir->dev, "%s: requesting %u HZ " | ||
643 | "carrier\n", __func__, carrier); | ||
644 | |||
645 | /* Transmit new carrier to mce device */ | ||
646 | mce_async_out(ir, cmdbuf, sizeof(cmdbuf)); | ||
647 | return carrier; | ||
648 | } | ||
649 | } | ||
650 | |||
651 | return -EINVAL; | ||
652 | |||
653 | } | ||
654 | |||
655 | return carrier; | ||
656 | } | ||
657 | |||
658 | static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len) | ||
659 | { | ||
660 | struct ir_raw_event rawir = { .pulse = false, .duration = 0 }; | ||
661 | int i, start_index = 0; | ||
662 | u8 hdr = MCE_CONTROL_HEADER; | ||
663 | |||
664 | /* skip meaningless 0xb1 0x60 header bytes on orig receiver */ | ||
665 | if (ir->flags.microsoft_gen1) | ||
666 | start_index = 2; | ||
667 | |||
668 | for (i = start_index; i < buf_len;) { | ||
669 | if (ir->rem == 0) { | ||
670 | /* decode mce packets of the form (84),AA,BB,CC,DD */ | ||
671 | /* IR data packets can span USB messages - rem */ | ||
672 | hdr = ir->buf_in[i]; | ||
673 | ir->rem = (hdr & MCE_PACKET_LENGTH_MASK); | ||
674 | ir->cmd = (hdr & ~MCE_PACKET_LENGTH_MASK); | ||
675 | dev_dbg(ir->dev, "New data. rem: 0x%02x, cmd: 0x%02x\n", | ||
676 | ir->rem, ir->cmd); | ||
677 | i++; | ||
678 | } | ||
679 | |||
680 | /* don't process MCE commands */ | ||
681 | if (hdr == MCE_CONTROL_HEADER || hdr == 0xff) { | ||
682 | ir->rem = 0; | ||
683 | return; | ||
684 | } | ||
685 | |||
686 | for (; (ir->rem > 0) && (i < buf_len); i++) { | ||
687 | ir->rem--; | ||
688 | |||
689 | rawir.pulse = ((ir->buf_in[i] & MCE_PULSE_BIT) != 0); | ||
690 | rawir.duration = (ir->buf_in[i] & MCE_PULSE_MASK) | ||
691 | * MCE_TIME_UNIT * 1000; | ||
692 | |||
693 | if ((ir->buf_in[i] & MCE_PULSE_MASK) == 0x7f) { | ||
694 | if (ir->rawir.pulse == rawir.pulse) | ||
695 | ir->rawir.duration += rawir.duration; | ||
696 | else { | ||
697 | ir->rawir.duration = rawir.duration; | ||
698 | ir->rawir.pulse = rawir.pulse; | ||
699 | } | ||
700 | continue; | ||
701 | } | ||
702 | rawir.duration += ir->rawir.duration; | ||
703 | ir->rawir.duration = 0; | ||
704 | ir->rawir.pulse = rawir.pulse; | ||
705 | |||
706 | dev_dbg(ir->dev, "Storing %s with duration %d\n", | ||
707 | rawir.pulse ? "pulse" : "space", | ||
708 | rawir.duration); | ||
709 | |||
710 | ir_raw_event_store(ir->idev, &rawir); | ||
711 | } | ||
712 | |||
713 | if (ir->buf_in[i] == 0x80 || ir->buf_in[i] == 0x9f) | ||
714 | ir->rem = 0; | ||
715 | |||
716 | dev_dbg(ir->dev, "calling ir_raw_event_handle\n"); | ||
717 | ir_raw_event_handle(ir->idev); | ||
718 | } | ||
719 | } | ||
720 | |||
721 | static void mceusb_dev_recv(struct urb *urb, struct pt_regs *regs) | ||
722 | { | ||
723 | struct mceusb_dev *ir; | ||
724 | int buf_len; | ||
725 | |||
726 | if (!urb) | ||
727 | return; | ||
728 | |||
729 | ir = urb->context; | ||
730 | if (!ir) { | ||
731 | usb_unlink_urb(urb); | ||
732 | return; | ||
733 | } | ||
734 | |||
735 | buf_len = urb->actual_length; | ||
736 | |||
737 | if (debug) | ||
738 | mceusb_dev_printdata(ir, urb->transfer_buffer, buf_len, false); | ||
739 | |||
740 | if (ir->send_flags == RECV_FLAG_IN_PROGRESS) { | ||
741 | ir->send_flags = SEND_FLAG_COMPLETE; | ||
742 | dev_dbg(&ir->irdev->dev, "setup answer received %d bytes\n", | ||
743 | buf_len); | ||
744 | } | ||
745 | |||
746 | switch (urb->status) { | ||
747 | /* success */ | ||
748 | case 0: | ||
749 | mceusb_process_ir_data(ir, buf_len); | ||
750 | break; | ||
751 | |||
752 | case -ECONNRESET: | ||
753 | case -ENOENT: | ||
754 | case -ESHUTDOWN: | ||
755 | usb_unlink_urb(urb); | ||
756 | return; | ||
757 | |||
758 | case -EPIPE: | ||
759 | default: | ||
760 | break; | ||
761 | } | ||
762 | |||
763 | usb_submit_urb(urb, GFP_ATOMIC); | ||
764 | } | ||
765 | |||
766 | static void mceusb_gen1_init(struct mceusb_dev *ir) | ||
767 | { | ||
768 | int ret; | ||
769 | int maxp = ir->len_in; | ||
770 | struct device *dev = ir->dev; | ||
771 | char *data; | ||
772 | |||
773 | data = kzalloc(USB_CTRL_MSG_SZ, GFP_KERNEL); | ||
774 | if (!data) { | ||
775 | dev_err(dev, "%s: memory allocation failed!\n", __func__); | ||
776 | return; | ||
777 | } | ||
778 | |||
779 | /* | ||
780 | * This is a strange one. Windows issues a set address to the device | ||
781 | * on the receive control pipe and expect a certain value pair back | ||
782 | */ | ||
783 | ret = usb_control_msg(ir->usbdev, usb_rcvctrlpipe(ir->usbdev, 0), | ||
784 | USB_REQ_SET_ADDRESS, USB_TYPE_VENDOR, 0, 0, | ||
785 | data, USB_CTRL_MSG_SZ, HZ * 3); | ||
786 | dev_dbg(dev, "%s - ret = %d\n", __func__, ret); | ||
787 | dev_dbg(dev, "%s - data[0] = %d, data[1] = %d\n", | ||
788 | __func__, data[0], data[1]); | ||
789 | |||
790 | /* set feature: bit rate 38400 bps */ | ||
791 | ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0), | ||
792 | USB_REQ_SET_FEATURE, USB_TYPE_VENDOR, | ||
793 | 0xc04e, 0x0000, NULL, 0, HZ * 3); | ||
794 | |||
795 | dev_dbg(dev, "%s - ret = %d\n", __func__, ret); | ||
796 | |||
797 | /* bRequest 4: set char length to 8 bits */ | ||
798 | ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0), | ||
799 | 4, USB_TYPE_VENDOR, | ||
800 | 0x0808, 0x0000, NULL, 0, HZ * 3); | ||
801 | dev_dbg(dev, "%s - retB = %d\n", __func__, ret); | ||
802 | |||
803 | /* bRequest 2: set handshaking to use DTR/DSR */ | ||
804 | ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0), | ||
805 | 2, USB_TYPE_VENDOR, | ||
806 | 0x0000, 0x0100, NULL, 0, HZ * 3); | ||
807 | dev_dbg(dev, "%s - retC = %d\n", __func__, ret); | ||
808 | |||
809 | /* device reset */ | ||
810 | mce_async_out(ir, DEVICE_RESET, sizeof(DEVICE_RESET)); | ||
811 | mce_sync_in(ir, NULL, maxp); | ||
812 | |||
813 | /* get hw/sw revision? */ | ||
814 | mce_async_out(ir, GET_REVISION, sizeof(GET_REVISION)); | ||
815 | mce_sync_in(ir, NULL, maxp); | ||
816 | |||
817 | kfree(data); | ||
818 | }; | ||
819 | |||
820 | static void mceusb_gen2_init(struct mceusb_dev *ir) | ||
821 | { | ||
822 | int maxp = ir->len_in; | ||
823 | |||
824 | /* device reset */ | ||
825 | mce_async_out(ir, DEVICE_RESET, sizeof(DEVICE_RESET)); | ||
826 | mce_sync_in(ir, NULL, maxp); | ||
827 | |||
828 | /* get hw/sw revision? */ | ||
829 | mce_async_out(ir, GET_REVISION, sizeof(GET_REVISION)); | ||
830 | mce_sync_in(ir, NULL, maxp); | ||
831 | |||
832 | /* unknown what the next two actually return... */ | ||
833 | mce_async_out(ir, GET_UNKNOWN, sizeof(GET_UNKNOWN)); | ||
834 | mce_sync_in(ir, NULL, maxp); | ||
835 | mce_async_out(ir, GET_UNKNOWN2, sizeof(GET_UNKNOWN2)); | ||
836 | mce_sync_in(ir, NULL, maxp); | ||
837 | } | ||
838 | |||
839 | static void mceusb_get_parameters(struct mceusb_dev *ir) | ||
840 | { | ||
841 | int maxp = ir->len_in; | ||
842 | |||
843 | /* get the carrier and frequency */ | ||
844 | mce_async_out(ir, GET_CARRIER_FREQ, sizeof(GET_CARRIER_FREQ)); | ||
845 | mce_sync_in(ir, NULL, maxp); | ||
846 | |||
847 | /* get the transmitter bitmask */ | ||
848 | mce_async_out(ir, GET_TX_BITMASK, sizeof(GET_TX_BITMASK)); | ||
849 | mce_sync_in(ir, NULL, maxp); | ||
850 | |||
851 | /* get receiver timeout value */ | ||
852 | mce_async_out(ir, GET_RX_TIMEOUT, sizeof(GET_RX_TIMEOUT)); | ||
853 | mce_sync_in(ir, NULL, maxp); | ||
854 | |||
855 | /* get receiver sensor setting */ | ||
856 | mce_async_out(ir, GET_RX_SENSOR, sizeof(GET_RX_SENSOR)); | ||
857 | mce_sync_in(ir, NULL, maxp); | ||
858 | } | ||
859 | |||
860 | static struct input_dev *mceusb_init_input_dev(struct mceusb_dev *ir) | ||
861 | { | ||
862 | struct input_dev *idev; | ||
863 | struct ir_dev_props *props; | ||
864 | struct ir_input_dev *irdev; | ||
865 | struct device *dev = ir->dev; | ||
866 | int ret = -ENODEV; | ||
867 | |||
868 | idev = input_allocate_device(); | ||
869 | if (!idev) { | ||
870 | dev_err(dev, "remote input dev allocation failed\n"); | ||
871 | goto idev_alloc_failed; | ||
872 | } | ||
873 | |||
874 | ret = -ENOMEM; | ||
875 | props = kzalloc(sizeof(struct ir_dev_props), GFP_KERNEL); | ||
876 | if (!props) { | ||
877 | dev_err(dev, "remote ir dev props allocation failed\n"); | ||
878 | goto props_alloc_failed; | ||
879 | } | ||
880 | |||
881 | irdev = kzalloc(sizeof(struct ir_input_dev), GFP_KERNEL); | ||
882 | if (!irdev) { | ||
883 | dev_err(dev, "remote ir input dev allocation failed\n"); | ||
884 | goto ir_dev_alloc_failed; | ||
885 | } | ||
886 | |||
887 | snprintf(ir->name, sizeof(ir->name), "Media Center Ed. eHome " | ||
888 | "Infrared Remote Transceiver (%04x:%04x)", | ||
889 | le16_to_cpu(ir->usbdev->descriptor.idVendor), | ||
890 | le16_to_cpu(ir->usbdev->descriptor.idProduct)); | ||
891 | |||
892 | idev->name = ir->name; | ||
893 | usb_make_path(ir->usbdev, ir->phys, sizeof(ir->phys)); | ||
894 | strlcat(ir->phys, "/input0", sizeof(ir->phys)); | ||
895 | idev->phys = ir->phys; | ||
896 | |||
897 | props->priv = ir; | ||
898 | props->driver_type = RC_DRIVER_IR_RAW; | ||
899 | props->allowed_protos = IR_TYPE_ALL; | ||
900 | props->s_tx_mask = mceusb_set_tx_mask; | ||
901 | props->s_tx_carrier = mceusb_set_tx_carrier; | ||
902 | props->tx_ir = mceusb_tx_ir; | ||
903 | |||
904 | ir->props = props; | ||
905 | ir->irdev = irdev; | ||
906 | |||
907 | input_set_drvdata(idev, irdev); | ||
908 | |||
909 | ret = ir_input_register(idev, RC_MAP_RC6_MCE, props, DRIVER_NAME); | ||
910 | if (ret < 0) { | ||
911 | dev_err(dev, "remote input device register failed\n"); | ||
912 | goto irdev_failed; | ||
913 | } | ||
914 | |||
915 | return idev; | ||
916 | |||
917 | irdev_failed: | ||
918 | kfree(irdev); | ||
919 | ir_dev_alloc_failed: | ||
920 | kfree(props); | ||
921 | props_alloc_failed: | ||
922 | input_free_device(idev); | ||
923 | idev_alloc_failed: | ||
924 | return NULL; | ||
925 | } | ||
926 | |||
927 | static int __devinit mceusb_dev_probe(struct usb_interface *intf, | ||
928 | const struct usb_device_id *id) | ||
929 | { | ||
930 | struct usb_device *dev = interface_to_usbdev(intf); | ||
931 | struct usb_host_interface *idesc; | ||
932 | struct usb_endpoint_descriptor *ep = NULL; | ||
933 | struct usb_endpoint_descriptor *ep_in = NULL; | ||
934 | struct usb_endpoint_descriptor *ep_out = NULL; | ||
935 | struct usb_host_config *config; | ||
936 | struct mceusb_dev *ir = NULL; | ||
937 | int pipe, maxp, i; | ||
938 | char buf[63], name[128] = ""; | ||
939 | bool is_gen3; | ||
940 | bool is_microsoft_gen1; | ||
941 | bool tx_mask_inverted; | ||
942 | |||
943 | dev_dbg(&intf->dev, ": %s called\n", __func__); | ||
944 | |||
945 | config = dev->actconfig; | ||
946 | idesc = intf->cur_altsetting; | ||
947 | |||
948 | is_gen3 = usb_match_id(intf, gen3_list) ? 1 : 0; | ||
949 | is_microsoft_gen1 = usb_match_id(intf, microsoft_gen1_list) ? 1 : 0; | ||
950 | tx_mask_inverted = usb_match_id(intf, std_tx_mask_list) ? 0 : 1; | ||
951 | |||
952 | /* step through the endpoints to find first bulk in and out endpoint */ | ||
953 | for (i = 0; i < idesc->desc.bNumEndpoints; ++i) { | ||
954 | ep = &idesc->endpoint[i].desc; | ||
955 | |||
956 | if ((ep_in == NULL) | ||
957 | && ((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) | ||
958 | == USB_DIR_IN) | ||
959 | && (((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) | ||
960 | == USB_ENDPOINT_XFER_BULK) | ||
961 | || ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) | ||
962 | == USB_ENDPOINT_XFER_INT))) { | ||
963 | |||
964 | ep_in = ep; | ||
965 | ep_in->bmAttributes = USB_ENDPOINT_XFER_INT; | ||
966 | ep_in->bInterval = 1; | ||
967 | dev_dbg(&intf->dev, ": acceptable inbound endpoint " | ||
968 | "found\n"); | ||
969 | } | ||
970 | |||
971 | if ((ep_out == NULL) | ||
972 | && ((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) | ||
973 | == USB_DIR_OUT) | ||
974 | && (((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) | ||
975 | == USB_ENDPOINT_XFER_BULK) | ||
976 | || ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) | ||
977 | == USB_ENDPOINT_XFER_INT))) { | ||
978 | |||
979 | ep_out = ep; | ||
980 | ep_out->bmAttributes = USB_ENDPOINT_XFER_INT; | ||
981 | ep_out->bInterval = 1; | ||
982 | dev_dbg(&intf->dev, ": acceptable outbound endpoint " | ||
983 | "found\n"); | ||
984 | } | ||
985 | } | ||
986 | if (ep_in == NULL) { | ||
987 | dev_dbg(&intf->dev, ": inbound and/or endpoint not found\n"); | ||
988 | return -ENODEV; | ||
989 | } | ||
990 | |||
991 | pipe = usb_rcvintpipe(dev, ep_in->bEndpointAddress); | ||
992 | maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); | ||
993 | |||
994 | ir = kzalloc(sizeof(struct mceusb_dev), GFP_KERNEL); | ||
995 | if (!ir) | ||
996 | goto mem_alloc_fail; | ||
997 | |||
998 | ir->buf_in = usb_alloc_coherent(dev, maxp, GFP_ATOMIC, &ir->dma_in); | ||
999 | if (!ir->buf_in) | ||
1000 | goto buf_in_alloc_fail; | ||
1001 | |||
1002 | ir->urb_in = usb_alloc_urb(0, GFP_KERNEL); | ||
1003 | if (!ir->urb_in) | ||
1004 | goto urb_in_alloc_fail; | ||
1005 | |||
1006 | ir->usbdev = dev; | ||
1007 | ir->dev = &intf->dev; | ||
1008 | ir->len_in = maxp; | ||
1009 | ir->flags.microsoft_gen1 = is_microsoft_gen1; | ||
1010 | ir->flags.tx_mask_inverted = tx_mask_inverted; | ||
1011 | |||
1012 | /* Saving usb interface data for use by the transmitter routine */ | ||
1013 | ir->usb_ep_in = ep_in; | ||
1014 | ir->usb_ep_out = ep_out; | ||
1015 | |||
1016 | if (dev->descriptor.iManufacturer | ||
1017 | && usb_string(dev, dev->descriptor.iManufacturer, | ||
1018 | buf, sizeof(buf)) > 0) | ||
1019 | strlcpy(name, buf, sizeof(name)); | ||
1020 | if (dev->descriptor.iProduct | ||
1021 | && usb_string(dev, dev->descriptor.iProduct, | ||
1022 | buf, sizeof(buf)) > 0) | ||
1023 | snprintf(name + strlen(name), sizeof(name) - strlen(name), | ||
1024 | " %s", buf); | ||
1025 | |||
1026 | ir->idev = mceusb_init_input_dev(ir); | ||
1027 | if (!ir->idev) | ||
1028 | goto input_dev_fail; | ||
1029 | |||
1030 | /* flush buffers on the device */ | ||
1031 | mce_sync_in(ir, NULL, maxp); | ||
1032 | mce_sync_in(ir, NULL, maxp); | ||
1033 | |||
1034 | /* wire up inbound data handler */ | ||
1035 | usb_fill_int_urb(ir->urb_in, dev, pipe, ir->buf_in, | ||
1036 | maxp, (usb_complete_t) mceusb_dev_recv, ir, ep_in->bInterval); | ||
1037 | ir->urb_in->transfer_dma = ir->dma_in; | ||
1038 | ir->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | ||
1039 | |||
1040 | /* initialize device */ | ||
1041 | if (ir->flags.microsoft_gen1) | ||
1042 | mceusb_gen1_init(ir); | ||
1043 | else if (!is_gen3) | ||
1044 | mceusb_gen2_init(ir); | ||
1045 | |||
1046 | mceusb_get_parameters(ir); | ||
1047 | |||
1048 | mceusb_set_tx_mask(ir, MCE_DEFAULT_TX_MASK); | ||
1049 | |||
1050 | usb_set_intfdata(intf, ir); | ||
1051 | |||
1052 | dev_info(&intf->dev, "Registered %s on usb%d:%d\n", name, | ||
1053 | dev->bus->busnum, dev->devnum); | ||
1054 | |||
1055 | return 0; | ||
1056 | |||
1057 | /* Error-handling path */ | ||
1058 | input_dev_fail: | ||
1059 | usb_free_urb(ir->urb_in); | ||
1060 | urb_in_alloc_fail: | ||
1061 | usb_free_coherent(dev, maxp, ir->buf_in, ir->dma_in); | ||
1062 | buf_in_alloc_fail: | ||
1063 | kfree(ir); | ||
1064 | mem_alloc_fail: | ||
1065 | dev_err(&intf->dev, "%s: device setup failed!\n", __func__); | ||
1066 | |||
1067 | return -ENOMEM; | ||
1068 | } | ||
1069 | |||
1070 | |||
1071 | static void __devexit mceusb_dev_disconnect(struct usb_interface *intf) | ||
1072 | { | ||
1073 | struct usb_device *dev = interface_to_usbdev(intf); | ||
1074 | struct mceusb_dev *ir = usb_get_intfdata(intf); | ||
1075 | |||
1076 | usb_set_intfdata(intf, NULL); | ||
1077 | |||
1078 | if (!ir) | ||
1079 | return; | ||
1080 | |||
1081 | ir->usbdev = NULL; | ||
1082 | ir_input_unregister(ir->idev); | ||
1083 | usb_kill_urb(ir->urb_in); | ||
1084 | usb_free_urb(ir->urb_in); | ||
1085 | usb_free_coherent(dev, ir->len_in, ir->buf_in, ir->dma_in); | ||
1086 | |||
1087 | kfree(ir); | ||
1088 | } | ||
1089 | |||
1090 | static int mceusb_dev_suspend(struct usb_interface *intf, pm_message_t message) | ||
1091 | { | ||
1092 | struct mceusb_dev *ir = usb_get_intfdata(intf); | ||
1093 | dev_info(ir->dev, "suspend\n"); | ||
1094 | usb_kill_urb(ir->urb_in); | ||
1095 | return 0; | ||
1096 | } | ||
1097 | |||
1098 | static int mceusb_dev_resume(struct usb_interface *intf) | ||
1099 | { | ||
1100 | struct mceusb_dev *ir = usb_get_intfdata(intf); | ||
1101 | dev_info(ir->dev, "resume\n"); | ||
1102 | if (usb_submit_urb(ir->urb_in, GFP_ATOMIC)) | ||
1103 | return -EIO; | ||
1104 | return 0; | ||
1105 | } | ||
1106 | |||
1107 | static struct usb_driver mceusb_dev_driver = { | ||
1108 | .name = DRIVER_NAME, | ||
1109 | .probe = mceusb_dev_probe, | ||
1110 | .disconnect = mceusb_dev_disconnect, | ||
1111 | .suspend = mceusb_dev_suspend, | ||
1112 | .resume = mceusb_dev_resume, | ||
1113 | .reset_resume = mceusb_dev_resume, | ||
1114 | .id_table = mceusb_dev_table | ||
1115 | }; | ||
1116 | |||
1117 | static int __init mceusb_dev_init(void) | ||
1118 | { | ||
1119 | int ret; | ||
1120 | |||
1121 | ret = usb_register(&mceusb_dev_driver); | ||
1122 | if (ret < 0) | ||
1123 | printk(KERN_ERR DRIVER_NAME | ||
1124 | ": usb register failed, result = %d\n", ret); | ||
1125 | |||
1126 | return ret; | ||
1127 | } | ||
1128 | |||
1129 | static void __exit mceusb_dev_exit(void) | ||
1130 | { | ||
1131 | usb_deregister(&mceusb_dev_driver); | ||
1132 | } | ||
1133 | |||
1134 | module_init(mceusb_dev_init); | ||
1135 | module_exit(mceusb_dev_exit); | ||
1136 | |||
1137 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
1138 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
1139 | MODULE_LICENSE("GPL"); | ||
1140 | MODULE_DEVICE_TABLE(usb, mceusb_dev_table); | ||
1141 | |||
1142 | module_param(debug, bool, S_IRUGO | S_IWUSR); | ||
1143 | MODULE_PARM_DESC(debug, "Debug enabled or not"); | ||