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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Driver for Phoenix RC Flight Controller Adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2018 Marcus Folkesson <marcus.folkesson@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/usb/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define PXRC_VENDOR_ID		0x1781
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define PXRC_PRODUCT_ID		0x0898
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) struct pxrc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	struct input_dev	*input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct usb_interface	*intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	struct urb		*urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct mutex		pm_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	bool			is_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	char			phys[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static void pxrc_usb_irq(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct pxrc *pxrc = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	u8 *data = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	switch (urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		/* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	case -ETIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		/* this urb is timing out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		dev_dbg(&pxrc->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 			"%s - urb timed out - was the device unplugged?\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	case -ECONNRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	case -EPIPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		/* this urb is terminated, clean up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		dev_dbg(&pxrc->intf->dev, "%s - urb shutting down with status: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			__func__, urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		dev_dbg(&pxrc->intf->dev, "%s - nonzero urb status received: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			__func__, urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (urb->actual_length == 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		input_report_abs(pxrc->input, ABS_X, data[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		input_report_abs(pxrc->input, ABS_Y, data[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		input_report_abs(pxrc->input, ABS_RX, data[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		input_report_abs(pxrc->input, ABS_RY, data[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		input_report_abs(pxrc->input, ABS_RUDDER, data[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		input_report_abs(pxrc->input, ABS_THROTTLE, data[6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		input_report_abs(pxrc->input, ABS_MISC, data[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		input_report_key(pxrc->input, BTN_A, data[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	/* Resubmit to fetch new fresh URBs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	error = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (error && error != -EPERM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		dev_err(&pxrc->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			"%s - usb_submit_urb failed with result: %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			__func__, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static int pxrc_open(struct input_dev *input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct pxrc *pxrc = input_get_drvdata(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	mutex_lock(&pxrc->pm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	retval = usb_submit_urb(pxrc->urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		dev_err(&pxrc->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			"%s - usb_submit_urb failed, error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			__func__, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		retval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	pxrc->is_open = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	mutex_unlock(&pxrc->pm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static void pxrc_close(struct input_dev *input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	struct pxrc *pxrc = input_get_drvdata(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	mutex_lock(&pxrc->pm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	usb_kill_urb(pxrc->urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	pxrc->is_open = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	mutex_unlock(&pxrc->pm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static void pxrc_free_urb(void *_pxrc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct pxrc *pxrc = _pxrc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	usb_free_urb(pxrc->urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static int pxrc_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		      const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	struct usb_device *udev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct pxrc *pxrc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct usb_endpoint_descriptor *epirq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	size_t xfer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	void *xfer_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	 * Locate the endpoint information. This device only has an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	 * interrupt endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	error = usb_find_common_endpoints(intf->cur_altsetting,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 					  NULL, NULL, &epirq, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		dev_err(&intf->dev, "Could not find endpoint\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	pxrc = devm_kzalloc(&intf->dev, sizeof(*pxrc), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (!pxrc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	mutex_init(&pxrc->pm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	pxrc->intf = intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	usb_set_intfdata(pxrc->intf, pxrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	xfer_size = usb_endpoint_maxp(epirq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	xfer_buf = devm_kmalloc(&intf->dev, xfer_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (!xfer_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	pxrc->urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (!pxrc->urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	error = devm_add_action_or_reset(&intf->dev, pxrc_free_urb, pxrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	usb_fill_int_urb(pxrc->urb, udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			 usb_rcvintpipe(udev, epirq->bEndpointAddress),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			 xfer_buf, xfer_size, pxrc_usb_irq, pxrc, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	pxrc->input = devm_input_allocate_device(&intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (!pxrc->input) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		dev_err(&intf->dev, "couldn't allocate input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	pxrc->input->name = "PXRC Flight Controller Adapter";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	usb_make_path(udev, pxrc->phys, sizeof(pxrc->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	strlcat(pxrc->phys, "/input0", sizeof(pxrc->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	pxrc->input->phys = pxrc->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	usb_to_input_id(udev, &pxrc->input->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	pxrc->input->open = pxrc_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	pxrc->input->close = pxrc_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	input_set_capability(pxrc->input, EV_KEY, BTN_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	input_set_abs_params(pxrc->input, ABS_X, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	input_set_abs_params(pxrc->input, ABS_Y, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	input_set_abs_params(pxrc->input, ABS_RX, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	input_set_abs_params(pxrc->input, ABS_RY, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	input_set_abs_params(pxrc->input, ABS_RUDDER, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	input_set_abs_params(pxrc->input, ABS_THROTTLE, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	input_set_abs_params(pxrc->input, ABS_MISC, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	input_set_drvdata(pxrc->input, pxrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	error = input_register_device(pxrc->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static void pxrc_disconnect(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	/* All driver resources are devm-managed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static int pxrc_suspend(struct usb_interface *intf, pm_message_t message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	struct pxrc *pxrc = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	mutex_lock(&pxrc->pm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (pxrc->is_open)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		usb_kill_urb(pxrc->urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	mutex_unlock(&pxrc->pm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static int pxrc_resume(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	struct pxrc *pxrc = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	mutex_lock(&pxrc->pm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (pxrc->is_open && usb_submit_urb(pxrc->urb, GFP_KERNEL) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		retval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	mutex_unlock(&pxrc->pm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static int pxrc_pre_reset(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	struct pxrc *pxrc = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	mutex_lock(&pxrc->pm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	usb_kill_urb(pxrc->urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	return 0;
^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 int pxrc_post_reset(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	struct pxrc *pxrc = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (pxrc->is_open && usb_submit_urb(pxrc->urb, GFP_KERNEL) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		retval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	mutex_unlock(&pxrc->pm_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static int pxrc_reset_resume(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	return pxrc_resume(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static const struct usb_device_id pxrc_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	{ USB_DEVICE(PXRC_VENDOR_ID, PXRC_PRODUCT_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) MODULE_DEVICE_TABLE(usb, pxrc_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static struct usb_driver pxrc_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	.name =		"pxrc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	.probe =	pxrc_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	.disconnect =	pxrc_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	.id_table =	pxrc_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	.suspend	= pxrc_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	.resume		= pxrc_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	.pre_reset	= pxrc_pre_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	.post_reset	= pxrc_post_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	.reset_resume	= pxrc_reset_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) module_usb_driver(pxrc_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) MODULE_AUTHOR("Marcus Folkesson <marcus.folkesson@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) MODULE_DESCRIPTION("PhoenixRC Flight Controller Adapter");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) MODULE_LICENSE("GPL v2");