Skip to content

Commit 8a4e8f8

Browse files
seanyoungmchehab
authored andcommitted
media: rc: new driver for early iMon device
These devices were supported by the lirc_imon.c driver which was removed from staging in commit f41003a ("[media] staging: lirc_imon: port remaining usb ids to imon and remove"). Signed-off-by: Sean Young <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 572eca0 commit 8a4e8f8

File tree

4 files changed

+219
-0
lines changed

4 files changed

+219
-0
lines changed

MAINTAINERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6903,6 +6903,13 @@ M: James Hogan <[email protected]>
69036903
S: Maintained
69046904
F: drivers/media/rc/img-ir/
69056905

6906+
IMON SOUNDGRAPH USB IR RECEIVER
6907+
M: Sean Young <[email protected]>
6908+
6909+
S: Maintained
6910+
F: drivers/media/rc/imon_raw.c
6911+
F: drivers/media/rc/imon.c
6912+
69066913
IMS TWINTURBO FRAMEBUFFER DRIVER
69076914
69086915
S: Orphan

drivers/media/rc/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ config IR_IMON
175175
To compile this driver as a module, choose M here: the
176176
module will be called imon.
177177

178+
config IR_IMON_RAW
179+
tristate "SoundGraph iMON Receiver (early raw IR models)"
180+
depends on USB_ARCH_HAS_HCD
181+
depends on RC_CORE
182+
select USB
183+
---help---
184+
Say Y here if you want to use a SoundGraph iMON IR Receiver,
185+
early raw models.
186+
187+
To compile this driver as a module, choose M here: the
188+
module will be called imon_raw.
189+
178190
config IR_MCEUSB
179191
tristate "Windows Media Center Ed. eHome Infrared Transceiver"
180192
depends on USB_ARCH_HAS_HCD

drivers/media/rc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ obj-$(CONFIG_IR_XMP_DECODER) += ir-xmp-decoder.o
1919
obj-$(CONFIG_RC_ATI_REMOTE) += ati_remote.o
2020
obj-$(CONFIG_IR_HIX5HD2) += ir-hix5hd2.o
2121
obj-$(CONFIG_IR_IMON) += imon.o
22+
obj-$(CONFIG_IR_IMON_RAW) += imon_raw.o
2223
obj-$(CONFIG_IR_ITE_CIR) += ite-cir.o
2324
obj-$(CONFIG_IR_MCEUSB) += mceusb.o
2425
obj-$(CONFIG_IR_FINTEK) += fintek-cir.o

drivers/media/rc/imon_raw.c

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
//
3+
// Copyright (C) 2018 Sean Young <[email protected]>
4+
5+
#include <linux/module.h>
6+
#include <linux/usb.h>
7+
#include <linux/usb/input.h>
8+
#include <media/rc-core.h>
9+
10+
/* Each bit is 250us */
11+
#define BIT_DURATION 250000
12+
13+
struct imon {
14+
struct device *dev;
15+
struct urb *ir_urb;
16+
struct rc_dev *rcdev;
17+
u8 ir_buf[8];
18+
char phys[64];
19+
};
20+
21+
/*
22+
* ffs/find_next_bit() searches in the wrong direction, so open-code our own.
23+
*/
24+
static inline int is_bit_set(const u8 *buf, int bit)
25+
{
26+
return buf[bit / 8] & (0x80 >> (bit & 7));
27+
}
28+
29+
static void imon_ir_data(struct imon *imon)
30+
{
31+
DEFINE_IR_RAW_EVENT(rawir);
32+
int offset = 0, size = 5 * 8;
33+
int bit;
34+
35+
dev_dbg(imon->dev, "data: %*ph", 8, imon->ir_buf);
36+
37+
while (offset < size) {
38+
bit = offset;
39+
while (!is_bit_set(imon->ir_buf, bit) && bit < size)
40+
bit++;
41+
dev_dbg(imon->dev, "pulse: %d bits", bit - offset);
42+
if (bit > offset) {
43+
rawir.pulse = true;
44+
rawir.duration = (bit - offset) * BIT_DURATION;
45+
ir_raw_event_store_with_filter(imon->rcdev, &rawir);
46+
}
47+
48+
if (bit >= size)
49+
break;
50+
51+
offset = bit;
52+
while (is_bit_set(imon->ir_buf, bit) && bit < size)
53+
bit++;
54+
dev_dbg(imon->dev, "space: %d bits", bit - offset);
55+
56+
rawir.pulse = false;
57+
rawir.duration = (bit - offset) * BIT_DURATION;
58+
ir_raw_event_store_with_filter(imon->rcdev, &rawir);
59+
60+
offset = bit;
61+
}
62+
63+
if (imon->ir_buf[7] == 0x0a) {
64+
ir_raw_event_set_idle(imon->rcdev, true);
65+
ir_raw_event_handle(imon->rcdev);
66+
}
67+
}
68+
69+
static void imon_ir_rx(struct urb *urb)
70+
{
71+
struct imon *imon = urb->context;
72+
int ret;
73+
74+
switch (urb->status) {
75+
case 0:
76+
if (imon->ir_buf[7] != 0xff)
77+
imon_ir_data(imon);
78+
break;
79+
case -ECONNRESET:
80+
case -ENOENT:
81+
case -ESHUTDOWN:
82+
usb_unlink_urb(urb);
83+
return;
84+
case -EPIPE:
85+
default:
86+
dev_dbg(imon->dev, "error: urb status = %d", urb->status);
87+
break;
88+
}
89+
90+
ret = usb_submit_urb(urb, GFP_ATOMIC);
91+
if (ret && ret != -ENODEV)
92+
dev_warn(imon->dev, "failed to resubmit urb: %d", ret);
93+
}
94+
95+
static int imon_probe(struct usb_interface *intf,
96+
const struct usb_device_id *id)
97+
{
98+
struct usb_endpoint_descriptor *ir_ep = NULL;
99+
struct usb_host_interface *idesc;
100+
struct usb_device *udev;
101+
struct rc_dev *rcdev;
102+
struct imon *imon;
103+
int i, ret;
104+
105+
udev = interface_to_usbdev(intf);
106+
idesc = intf->cur_altsetting;
107+
108+
for (i = 0; i < idesc->desc.bNumEndpoints; i++) {
109+
struct usb_endpoint_descriptor *ep = &idesc->endpoint[i].desc;
110+
111+
if (usb_endpoint_is_int_in(ep)) {
112+
ir_ep = ep;
113+
break;
114+
}
115+
}
116+
117+
if (!ir_ep) {
118+
dev_err(&intf->dev, "IR endpoint missing");
119+
return -ENODEV;
120+
}
121+
122+
imon = devm_kmalloc(&intf->dev, sizeof(*imon), GFP_KERNEL);
123+
if (!imon)
124+
return -ENOMEM;
125+
126+
imon->ir_urb = usb_alloc_urb(0, GFP_KERNEL);
127+
if (!imon->ir_urb)
128+
return -ENOMEM;
129+
130+
imon->dev = &intf->dev;
131+
usb_fill_int_urb(imon->ir_urb, udev,
132+
usb_rcvintpipe(udev, ir_ep->bEndpointAddress),
133+
imon->ir_buf, sizeof(imon->ir_buf),
134+
imon_ir_rx, imon, ir_ep->bInterval);
135+
136+
rcdev = devm_rc_allocate_device(&intf->dev, RC_DRIVER_IR_RAW);
137+
if (!rcdev) {
138+
ret = -ENOMEM;
139+
goto free_urb;
140+
}
141+
142+
usb_make_path(udev, imon->phys, sizeof(imon->phys));
143+
144+
rcdev->device_name = "iMON Station";
145+
rcdev->driver_name = KBUILD_MODNAME;
146+
rcdev->input_phys = imon->phys;
147+
usb_to_input_id(udev, &rcdev->input_id);
148+
rcdev->dev.parent = &intf->dev;
149+
rcdev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
150+
rcdev->map_name = RC_MAP_IMON_RSC;
151+
rcdev->rx_resolution = BIT_DURATION;
152+
rcdev->priv = imon;
153+
154+
ret = devm_rc_register_device(&intf->dev, rcdev);
155+
if (ret)
156+
goto free_urb;
157+
158+
imon->rcdev = rcdev;
159+
160+
ret = usb_submit_urb(imon->ir_urb, GFP_KERNEL);
161+
if (ret)
162+
goto free_urb;
163+
164+
usb_set_intfdata(intf, imon);
165+
166+
return 0;
167+
168+
free_urb:
169+
usb_free_urb(imon->ir_urb);
170+
return ret;
171+
}
172+
173+
static void imon_disconnect(struct usb_interface *intf)
174+
{
175+
struct imon *imon = usb_get_intfdata(intf);
176+
177+
usb_kill_urb(imon->ir_urb);
178+
usb_free_urb(imon->ir_urb);
179+
}
180+
181+
static const struct usb_device_id imon_table[] = {
182+
/* SoundGraph iMON (IR only) -- sg_imon.inf */
183+
{ USB_DEVICE(0x04e8, 0xff30) },
184+
{}
185+
};
186+
187+
static struct usb_driver imon_driver = {
188+
.name = KBUILD_MODNAME,
189+
.probe = imon_probe,
190+
.disconnect = imon_disconnect,
191+
.id_table = imon_table
192+
};
193+
194+
module_usb_driver(imon_driver);
195+
196+
MODULE_DESCRIPTION("Early raw iMON IR devices");
197+
MODULE_AUTHOR("Sean Young <[email protected]>");
198+
MODULE_LICENSE("GPL");
199+
MODULE_DEVICE_TABLE(usb, imon_table);

0 commit comments

Comments
 (0)