Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags   |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * IgorPlug-USB IR Receiver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2014 Sean Young <sean@mess.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Supports the standard homebrew IgorPlugUSB receiver with Igor's firmware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * See http://www.cesko.host.sk/IgorPlugUSB/IgorPlug-USB%20(AVR)_eng.htm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Based on the lirc_igorplugusb.c driver:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *	Copyright (C) 2004 Jan M. Hochstein
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *	<hochstein@algo.informatik.tu-darmstadt.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/usb/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <media/rc-core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define DRIVER_DESC		"IgorPlug-USB IR Receiver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define DRIVER_NAME		"igorplugusb"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define HEADERLEN		3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define BUFLEN			36
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define MAX_PACKET		(HEADERLEN + BUFLEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define SET_INFRABUFFER_EMPTY	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define GET_INFRACODE		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) struct igorplugusb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct rc_dev *rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct usb_ctrlrequest request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct timer_list timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	uint8_t buf_in[MAX_PACKET];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	char phys[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static void igorplugusb_cmd(struct igorplugusb *ir, int cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static void igorplugusb_irdata(struct igorplugusb *ir, unsigned len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct ir_raw_event rawir = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	unsigned i, start, overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	dev_dbg(ir->dev, "irdata: %*ph (len=%u)", len, ir->buf_in, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	 * If more than 36 pulses and spaces follow each other, the igorplugusb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	 * overwrites its buffer from the beginning. The overflow value is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	 * last offset which was not overwritten. Everything from this offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	 * onwards occurred before everything until this offset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	overflow = ir->buf_in[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	i = start = overflow + HEADERLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (start >= len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		dev_err(ir->dev, "receive overflow invalid: %u", overflow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		if (overflow > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			dev_warn(ir->dev, "receive overflow, at least %u lost",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 								overflow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			ir_raw_event_reset(ir->rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			rawir.duration = ir->buf_in[i] * 85;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			rawir.pulse = i & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			ir_raw_event_store_with_filter(ir->rc, &rawir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			if (++i == len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 				i = HEADERLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		} while (i != start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		/* add a trailing space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		rawir.duration = ir->rc->timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		rawir.pulse = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		ir_raw_event_store_with_filter(ir->rc, &rawir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		ir_raw_event_handle(ir->rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	igorplugusb_cmd(ir, SET_INFRABUFFER_EMPTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static void igorplugusb_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct usb_ctrlrequest *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	struct igorplugusb *ir = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	req = (struct usb_ctrlrequest *)urb->setup_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	switch (urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		if (req->bRequest == GET_INFRACODE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 					urb->actual_length > HEADERLEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			igorplugusb_irdata(ir, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		else /* request IR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			mod_timer(&ir->timer, jiffies + msecs_to_jiffies(50));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	case -EPROTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	case -ECONNRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		usb_unlink_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		dev_warn(ir->dev, "Error: urb status = %d\n", urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		igorplugusb_cmd(ir, SET_INFRABUFFER_EMPTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static void igorplugusb_cmd(struct igorplugusb *ir, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	ir->request.bRequest = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	ir->urb->transfer_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	ret = usb_submit_urb(ir->urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		dev_err(ir->dev, "submit urb failed: %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static void igorplugusb_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct igorplugusb *ir = from_timer(ir, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	igorplugusb_cmd(ir, GET_INFRACODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static int igorplugusb_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 					const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct usb_host_interface *idesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	struct usb_endpoint_descriptor *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct igorplugusb *ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	struct rc_dev *rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	udev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	idesc = intf->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if (idesc->desc.bNumEndpoints != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		dev_err(&intf->dev, "incorrect number of endpoints");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	ep = &idesc->endpoint[0].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (!usb_endpoint_dir_in(ep) || !usb_endpoint_xfer_control(ep)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		dev_err(&intf->dev, "endpoint incorrect");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	ir = devm_kzalloc(&intf->dev, sizeof(*ir), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	if (!ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	ir->dev = &intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	timer_setup(&ir->timer, igorplugusb_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	ir->request.bRequest = GET_INFRACODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	ir->request.bRequestType = USB_TYPE_VENDOR | USB_DIR_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	ir->request.wLength = cpu_to_le16(sizeof(ir->buf_in));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	ir->urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	if (!ir->urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	usb_fill_control_urb(ir->urb, udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		usb_rcvctrlpipe(udev, 0), (uint8_t *)&ir->request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		ir->buf_in, sizeof(ir->buf_in), igorplugusb_callback, ir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	usb_make_path(udev, ir->phys, sizeof(ir->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	rc = rc_allocate_device(RC_DRIVER_IR_RAW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	rc->device_name = DRIVER_DESC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	rc->input_phys = ir->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	usb_to_input_id(udev, &rc->input_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	rc->dev.parent = &intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	 * This device can only store 36 pulses + spaces, which is not enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	 * for the NEC protocol and many others.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		~(RC_PROTO_BIT_NEC | RC_PROTO_BIT_NECX | RC_PROTO_BIT_NEC32 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		  RC_PROTO_BIT_RC6_6A_20 | RC_PROTO_BIT_RC6_6A_24 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		  RC_PROTO_BIT_RC6_6A_32 | RC_PROTO_BIT_RC6_MCE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		  RC_PROTO_BIT_SONY20 | RC_PROTO_BIT_SANYO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	rc->priv = ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	rc->driver_name = DRIVER_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	rc->map_name = RC_MAP_HAUPPAUGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	rc->timeout = MS_TO_US(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	rc->rx_resolution = 85;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	ir->rc = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	ret = rc_register_device(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		dev_err(&intf->dev, "failed to register rc device: %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	usb_set_intfdata(intf, ir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	igorplugusb_cmd(ir, SET_INFRABUFFER_EMPTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	rc_free_device(ir->rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	usb_free_urb(ir->urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	del_timer(&ir->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static void igorplugusb_disconnect(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	struct igorplugusb *ir = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	rc_unregister_device(ir->rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	del_timer_sync(&ir->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	usb_set_intfdata(intf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	usb_kill_urb(ir->urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	usb_free_urb(ir->urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static const struct usb_device_id igorplugusb_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	/* Igor Plug USB (Atmel's Manufact. ID) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	{ USB_DEVICE(0x03eb, 0x0002) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	/* Fit PC2 Infrared Adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	{ USB_DEVICE(0x03eb, 0x21fe) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	/* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static struct usb_driver igorplugusb_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	.name =	DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	.probe = igorplugusb_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	.disconnect = igorplugusb_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	.id_table = igorplugusb_table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) module_usb_driver(igorplugusb_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) MODULE_AUTHOR("Sean Young <sean@mess.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) MODULE_DEVICE_TABLE(usb, igorplugusb_table);