^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) * USB RedRat3 IR Transceiver rc-core driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2011 by Jarod Wilson <jarod@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * based heavily on the work of Stephen Cox, with additional
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * help from RedRat Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * This driver began life based an an old version of the first-generation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * lirc_mceusb driver from the lirc 0.7.2 distribution. It was then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * significantly rewritten by Stephen Cox with the aid of RedRat Ltd's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Chris Dodge.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * The driver was then ported to rc-core and significantly rewritten again,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * by Jarod, using the in-kernel mceusb driver as a guide, after an initial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * port effort was started by Stephen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * TODO LIST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * - fix lirc not showing repeats properly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * The RedRat3 is a USB transceiver with both send & receive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * with 2 separate sensors available for receive to enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * both good long range reception for general use, and good
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * short range reception when required for learning a signal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * http://www.redrat.co.uk/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * It uses its own little protocol to communicate, the required
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * parts of which are embedded within this driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/usb/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <media/rc-core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* Driver Information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define DRIVER_AUTHOR "Jarod Wilson <jarod@redhat.com>"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define DRIVER_AUTHOR2 "The Dweller, Stephen Cox"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define DRIVER_DESC "RedRat3 USB IR Transceiver Driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define DRIVER_NAME "redrat3"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* bulk data transfer types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define RR3_ERROR 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define RR3_MOD_SIGNAL_IN 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define RR3_MOD_SIGNAL_OUT 0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /* Get the RR firmware version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define RR3_FW_VERSION 0xb1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define RR3_FW_VERSION_LEN 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* Send encoded signal bulk-sent earlier*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define RR3_TX_SEND_SIGNAL 0xb3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define RR3_SET_IR_PARAM 0xb7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define RR3_GET_IR_PARAM 0xb8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /* Blink the red LED on the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define RR3_BLINK_LED 0xb9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* Read serial number of device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define RR3_READ_SER_NO 0xba
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define RR3_SER_NO_LEN 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /* Start capture with the RC receiver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define RR3_RC_DET_ENABLE 0xbb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* Stop capture with the RC receiver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define RR3_RC_DET_DISABLE 0xbc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* Start capture with the wideband receiver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define RR3_MODSIG_CAPTURE 0xb2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* Return the status of RC detector capture */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define RR3_RC_DET_STATUS 0xbd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* Reset redrat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define RR3_RESET 0xa0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* Max number of lengths in the signal. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define RR3_IR_IO_MAX_LENGTHS 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* Periods to measure mod. freq. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define RR3_IR_IO_PERIODS_MF 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /* Size of memory for main signal data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define RR3_IR_IO_SIG_MEM_SIZE 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* Delta value when measuring lengths */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define RR3_IR_IO_LENGTH_FUZZ 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* Timeout for end of signal detection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define RR3_IR_IO_SIG_TIMEOUT 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /* Minimum value for pause recognition. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define RR3_IR_IO_MIN_PAUSE 0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /* Clock freq. of EZ-USB chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define RR3_CLK 24000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /* Clock periods per timer count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define RR3_CLK_PER_COUNT 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* (RR3_CLK / RR3_CLK_PER_COUNT) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define RR3_CLK_CONV_FACTOR 2000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /* USB bulk-in wideband IR data endpoint address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define RR3_WIDE_IN_EP_ADDR 0x81
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /* USB bulk-in narrowband IR data endpoint address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define RR3_NARROW_IN_EP_ADDR 0x82
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /* Size of the fixed-length portion of the signal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define RR3_DRIVER_MAXLENS 255
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define RR3_MAX_SIG_SIZE 512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define RR3_TIME_UNIT 50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define RR3_END_OF_SIGNAL 0x7f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define RR3_TX_TRAILER_LEN 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define RR3_RX_MIN_TIMEOUT 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define RR3_RX_MAX_TIMEOUT 2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /* The 8051's CPUCS Register address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define RR3_CPUCS_REG_ADDR 0x7f92
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define USB_RR3USB_VENDOR_ID 0x112a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #define USB_RR3USB_PRODUCT_ID 0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define USB_RR3IIUSB_PRODUCT_ID 0x0005
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * The redrat3 encodes an IR signal as set of different lengths and a set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * of indices into those lengths. This sets how much two lengths must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * differ before they are considered distinct, the value is specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * in microseconds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * Default 5, value 0 to 127.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static int length_fuzz = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) module_param(length_fuzz, uint, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) MODULE_PARM_DESC(length_fuzz, "Length Fuzz (0-127)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * When receiving a continuous ir stream (for example when a user is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * holding a button down on a remote), this specifies the minimum size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * of a space when the redrat3 sends a irdata packet to the host. Specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * in milliseconds. Default value 18ms.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * The value can be between 2 and 30 inclusive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static int minimum_pause = 18;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) module_param(minimum_pause, uint, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) MODULE_PARM_DESC(minimum_pause, "Minimum Pause in ms (2-30)");
^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) * The carrier frequency is measured during the first pulse of the IR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * signal. The larger the number of periods used To measure, the more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * accurate the result is likely to be, however some signals have short
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * initial pulses, so in some case it may be necessary to reduce this value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * Default 8, value 1 to 255.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static int periods_measure_carrier = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) module_param(periods_measure_carrier, uint, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) MODULE_PARM_DESC(periods_measure_carrier, "Number of Periods to Measure Carrier (1-255)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct redrat3_header {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) __be16 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) __be16 transfer_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /* sending and receiving irdata */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct redrat3_irdata {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct redrat3_header header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) __be32 pause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) __be16 mod_freq_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) __be16 num_periods;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) __u8 max_lengths;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) __u8 no_lengths;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) __be16 max_sig_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) __be16 sig_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) __u8 no_repeats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) __be16 lens[RR3_DRIVER_MAXLENS]; /* not aligned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) __u8 sigdata[RR3_MAX_SIG_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /* firmware errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct redrat3_error {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct redrat3_header header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) __be16 fw_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /* table of devices that work with this driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static const struct usb_device_id redrat3_dev_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /* Original version of the RedRat3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {USB_DEVICE(USB_RR3USB_VENDOR_ID, USB_RR3USB_PRODUCT_ID)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* Second Version/release of the RedRat3 - RetRat3-II */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {USB_DEVICE(USB_RR3USB_VENDOR_ID, USB_RR3IIUSB_PRODUCT_ID)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {} /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /* Structure to hold all of our device specific stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct redrat3_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* core device bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct rc_dev *rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* led control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct led_classdev led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) atomic_t flash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct usb_ctrlrequest flash_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct urb *flash_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) u8 flash_in_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /* learning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) bool wideband;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct usb_ctrlrequest learn_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) struct urb *learn_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) u8 learn_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* save off the usb device pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* the receive endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct usb_endpoint_descriptor *ep_narrow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /* the buffer to receive data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) void *bulk_in_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /* urb used to read ir data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct urb *narrow_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct urb *wide_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* the send endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct usb_endpoint_descriptor *ep_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /* usb dma */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) dma_addr_t dma_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* Is the device currently transmitting?*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) bool transmitting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /* store for current packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct redrat3_irdata irdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) u16 bytes_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) u32 carrier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) char name[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) char phys[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static void redrat3_dump_fw_error(struct redrat3_dev *rr3, int code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (!rr3->transmitting && (code != 0x40))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) dev_info(rr3->dev, "fw error code 0x%02x: ", code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) switch (code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) case 0x00:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) pr_cont("No Error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /* Codes 0x20 through 0x2f are IR Firmware Errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) case 0x20:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) pr_cont("Initial signal pulse not long enough to measure carrier frequency\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) case 0x21:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) pr_cont("Not enough length values allocated for signal\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) case 0x22:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) pr_cont("Not enough memory allocated for signal data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) case 0x23:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) pr_cont("Too many signal repeats\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) case 0x28:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) pr_cont("Insufficient memory available for IR signal data memory allocation\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) case 0x29:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) pr_cont("Insufficient memory available for IrDa signal data memory allocation\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /* Codes 0x30 through 0x3f are USB Firmware Errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) case 0x30:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) pr_cont("Insufficient memory available for bulk transfer structure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * Other error codes... These are primarily errors that can occur in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * the control messages sent to the redrat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) case 0x40:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (!rr3->transmitting)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) pr_cont("Signal capture has been terminated\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) case 0x41:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) pr_cont("Attempt to set/get and unknown signal I/O algorithm parameter\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) case 0x42:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) pr_cont("Signal capture already started\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) pr_cont("Unknown Error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static u32 redrat3_val_to_mod_freq(struct redrat3_irdata *irdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) u32 mod_freq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) u16 mod_freq_count = be16_to_cpu(irdata->mod_freq_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (mod_freq_count != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) mod_freq = (RR3_CLK * be16_to_cpu(irdata->num_periods)) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) (mod_freq_count * RR3_CLK_PER_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return mod_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /* this function scales down the figures for the same result... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static u32 redrat3_len_to_us(u32 length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) u32 biglen = length * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) u32 divisor = (RR3_CLK_CONV_FACTOR) / 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) u32 result = (u32) (biglen / divisor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) /* don't allow zero lengths to go back, breaks lirc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return result ? result : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) * convert us back into redrat3 lengths
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * length * 1000 length * 1000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * ------------- = ---------------- = micro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * rr3clk / 1000 rr3clk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) * 6 * 2 4 * 3 micro * rr3clk micro * rr3clk / 1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * ----- = 4 ----- = 6 -------------- = len ---------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * 3 2 1000000 1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static u32 redrat3_us_to_len(u32 microsec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) u32 result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) u32 divisor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) microsec = (microsec > IR_MAX_DURATION) ? IR_MAX_DURATION : microsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) divisor = (RR3_CLK_CONV_FACTOR / 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) result = (u32)(microsec * divisor) / 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /* don't allow zero lengths to go back, breaks lirc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) return result ? result : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static void redrat3_process_ir_data(struct redrat3_dev *rr3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) struct ir_raw_event rawir = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) unsigned int i, sig_size, offset, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) u32 mod_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) dev = rr3->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) mod_freq = redrat3_val_to_mod_freq(&rr3->irdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) dev_dbg(dev, "Got mod_freq of %u\n", mod_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if (mod_freq && rr3->wideband) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct ir_raw_event ev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) .carrier_report = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) .carrier = mod_freq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) ir_raw_event_store(rr3->rc, &ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) /* process each rr3 encoded byte into an int */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) sig_size = be16_to_cpu(rr3->irdata.sig_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) for (i = 0; i < sig_size; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) offset = rr3->irdata.sigdata[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) val = get_unaligned_be16(&rr3->irdata.lens[offset]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /* we should always get pulse/space/pulse/space samples */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (i % 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) rawir.pulse = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) rawir.pulse = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) rawir.duration = redrat3_len_to_us(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /* cap the value to IR_MAX_DURATION */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) rawir.duration = (rawir.duration > IR_MAX_DURATION) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) IR_MAX_DURATION : rawir.duration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) dev_dbg(dev, "storing %s with duration %d (i: %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) rawir.pulse ? "pulse" : "space", rawir.duration, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) ir_raw_event_store_with_filter(rr3->rc, &rawir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) /* add a trailing space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) rawir.pulse = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) rawir.timeout = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) rawir.duration = rr3->rc->timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) dev_dbg(dev, "storing trailing timeout with duration %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) rawir.duration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) ir_raw_event_store_with_filter(rr3->rc, &rawir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) dev_dbg(dev, "calling ir_raw_event_handle\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) ir_raw_event_handle(rr3->rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) /* Util fn to send rr3 cmds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static int redrat3_send_cmd(int cmd, struct redrat3_dev *rr3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) u8 *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) data = kzalloc(sizeof(u8), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) udev = rr3->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 0x0000, 0x0000, data, sizeof(u8), 10000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (res < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) dev_err(rr3->dev, "%s: Error sending rr3 cmd res %d, data %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) __func__, res, *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) res = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) res = data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) /* Enables the long range detector and starts async receive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static int redrat3_enable_detector(struct redrat3_dev *rr3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) struct device *dev = rr3->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) u8 ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) ret = redrat3_send_cmd(RR3_RC_DET_ENABLE, rr3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) dev_dbg(dev, "%s: unexpected ret of %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) ret = redrat3_send_cmd(RR3_RC_DET_STATUS, rr3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (ret != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) dev_err(dev, "%s: detector status: %d, should be 1\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) ret = usb_submit_urb(rr3->narrow_urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) dev_err(rr3->dev, "narrow band urb failed: %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) ret = usb_submit_urb(rr3->wide_urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) dev_err(rr3->dev, "wide band urb failed: %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static inline void redrat3_delete(struct redrat3_dev *rr3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) struct usb_device *udev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) usb_kill_urb(rr3->narrow_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) usb_kill_urb(rr3->wide_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) usb_kill_urb(rr3->flash_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) usb_kill_urb(rr3->learn_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) usb_free_urb(rr3->narrow_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) usb_free_urb(rr3->wide_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) usb_free_urb(rr3->flash_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) usb_free_urb(rr3->learn_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) usb_free_coherent(udev, le16_to_cpu(rr3->ep_narrow->wMaxPacketSize),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) rr3->bulk_in_buf, rr3->dma_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) kfree(rr3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static u32 redrat3_get_timeout(struct redrat3_dev *rr3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) __be32 *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) u32 timeout = MS_TO_US(150); /* a sane default, if things go haywire */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) int len, ret, pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) len = sizeof(*tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) tmp = kzalloc(len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (!tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) pipe = usb_rcvctrlpipe(rr3->udev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) ret = usb_control_msg(rr3->udev, pipe, RR3_GET_IR_PARAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) RR3_IR_IO_SIG_TIMEOUT, 0, tmp, len, 5000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (ret != len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) dev_warn(rr3->dev, "Failed to read timeout from hardware\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) timeout = redrat3_len_to_us(be32_to_cpup(tmp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) dev_dbg(rr3->dev, "Got timeout of %d ms\n", timeout / 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) kfree(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) return timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) static int redrat3_set_timeout(struct rc_dev *rc_dev, unsigned int timeoutus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) struct redrat3_dev *rr3 = rc_dev->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) struct usb_device *udev = rr3->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) struct device *dev = rr3->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) __be32 *timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) timeout = kmalloc(sizeof(*timeout), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) if (!timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) *timeout = cpu_to_be32(redrat3_us_to_len(timeoutus));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), RR3_SET_IR_PARAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) RR3_IR_IO_SIG_TIMEOUT, 0, timeout, sizeof(*timeout),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 25000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) dev_dbg(dev, "set ir parm timeout %d ret 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) be32_to_cpu(*timeout), ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) if (ret == sizeof(*timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) else if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) kfree(timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) static void redrat3_reset(struct redrat3_dev *rr3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) struct usb_device *udev = rr3->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) struct device *dev = rr3->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) int rc, rxpipe, txpipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) u8 *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) size_t const len = sizeof(*val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) rxpipe = usb_rcvctrlpipe(udev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) txpipe = usb_sndctrlpipe(udev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) val = kmalloc(len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) if (!val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) *val = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) rc = usb_control_msg(udev, rxpipe, RR3_RESET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) RR3_CPUCS_REG_ADDR, 0, val, len, 25000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) dev_dbg(dev, "reset returned 0x%02x\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) *val = length_fuzz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) rc = usb_control_msg(udev, txpipe, RR3_SET_IR_PARAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) RR3_IR_IO_LENGTH_FUZZ, 0, val, len, 25000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) dev_dbg(dev, "set ir parm len fuzz %d rc 0x%02x\n", *val, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) *val = (65536 - (minimum_pause * 2000)) / 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) rc = usb_control_msg(udev, txpipe, RR3_SET_IR_PARAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) RR3_IR_IO_MIN_PAUSE, 0, val, len, 25000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) dev_dbg(dev, "set ir parm min pause %d rc 0x%02x\n", *val, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) *val = periods_measure_carrier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) rc = usb_control_msg(udev, txpipe, RR3_SET_IR_PARAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) RR3_IR_IO_PERIODS_MF, 0, val, len, 25000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) dev_dbg(dev, "set ir parm periods measure carrier %d rc 0x%02x", *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) *val = RR3_DRIVER_MAXLENS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) rc = usb_control_msg(udev, txpipe, RR3_SET_IR_PARAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) RR3_IR_IO_MAX_LENGTHS, 0, val, len, 25000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) dev_dbg(dev, "set ir parm max lens %d rc 0x%02x\n", *val, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) kfree(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) static void redrat3_get_firmware_rev(struct redrat3_dev *rr3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) buffer = kcalloc(RR3_FW_VERSION_LEN + 1, sizeof(*buffer), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) if (!buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) rc = usb_control_msg(rr3->udev, usb_rcvctrlpipe(rr3->udev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) RR3_FW_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 0, 0, buffer, RR3_FW_VERSION_LEN, 5000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) if (rc >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) dev_info(rr3->dev, "Firmware rev: %s", buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) dev_err(rr3->dev, "Problem fetching firmware ID\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) static void redrat3_read_packet_start(struct redrat3_dev *rr3, unsigned len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) struct redrat3_header *header = rr3->bulk_in_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) unsigned pktlen, pkttype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) /* grab the Length and type of transfer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) pktlen = be16_to_cpu(header->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) pkttype = be16_to_cpu(header->transfer_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) if (pktlen > sizeof(rr3->irdata)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) dev_warn(rr3->dev, "packet length %u too large\n", pktlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) switch (pkttype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) case RR3_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) if (len >= sizeof(struct redrat3_error)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) struct redrat3_error *error = rr3->bulk_in_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) unsigned fw_error = be16_to_cpu(error->fw_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) redrat3_dump_fw_error(rr3, fw_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) case RR3_MOD_SIGNAL_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) memcpy(&rr3->irdata, rr3->bulk_in_buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) rr3->bytes_read = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) dev_dbg(rr3->dev, "bytes_read %d, pktlen %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) rr3->bytes_read, pktlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) dev_dbg(rr3->dev, "ignoring packet with type 0x%02x, len of %d, 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) pkttype, len, pktlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) static void redrat3_read_packet_continue(struct redrat3_dev *rr3, unsigned len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) void *irdata = &rr3->irdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) if (len + rr3->bytes_read > sizeof(rr3->irdata)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) dev_warn(rr3->dev, "too much data for packet\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) rr3->bytes_read = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) memcpy(irdata + rr3->bytes_read, rr3->bulk_in_buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) rr3->bytes_read += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) dev_dbg(rr3->dev, "bytes_read %d, pktlen %d\n", rr3->bytes_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) be16_to_cpu(rr3->irdata.header.length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) /* gather IR data from incoming urb, process it when we have enough */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) static int redrat3_get_ir_data(struct redrat3_dev *rr3, unsigned len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) struct device *dev = rr3->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) unsigned pkttype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) if (rr3->bytes_read == 0 && len >= sizeof(struct redrat3_header)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) redrat3_read_packet_start(rr3, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) } else if (rr3->bytes_read != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) redrat3_read_packet_continue(rr3, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) } else if (rr3->bytes_read == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) dev_err(dev, "error: no packet data read\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) ret = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) if (rr3->bytes_read < be16_to_cpu(rr3->irdata.header.length) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) sizeof(struct redrat3_header))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) /* we're still accumulating data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) /* if we get here, we've got IR data to decode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) pkttype = be16_to_cpu(rr3->irdata.header.transfer_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if (pkttype == RR3_MOD_SIGNAL_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) redrat3_process_ir_data(rr3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) dev_dbg(dev, "discarding non-signal data packet (type 0x%02x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) pkttype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) rr3->bytes_read = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) /* callback function from USB when async USB request has completed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) static void redrat3_handle_async(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) struct redrat3_dev *rr3 = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) switch (urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) ret = redrat3_get_ir_data(rr3, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) if (!ret && rr3->wideband && !rr3->learn_urb->hcpriv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) ret = usb_submit_urb(rr3->learn_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) dev_err(rr3->dev, "Failed to submit learning urb: %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) /* no error, prepare to read more */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) ret = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) dev_err(rr3->dev, "Failed to resubmit urb: %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) case -ECONNRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) usb_unlink_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) case -EPIPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) dev_warn(rr3->dev, "Error: urb status = %d\n", urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) rr3->bytes_read = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) static u16 mod_freq_to_val(unsigned int mod_freq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) int mult = 6000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) /* Clk used in mod. freq. generation is CLK24/4. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) return 65536 - (mult / mod_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) static int redrat3_set_tx_carrier(struct rc_dev *rcdev, u32 carrier)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) struct redrat3_dev *rr3 = rcdev->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) struct device *dev = rr3->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) dev_dbg(dev, "Setting modulation frequency to %u", carrier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) if (carrier == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) rr3->carrier = carrier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) unsigned count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) struct redrat3_dev *rr3 = rcdev->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) struct device *dev = rr3->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) struct redrat3_irdata *irdata = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) int ret, ret_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) int lencheck, cur_sample_len, pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) int *sample_lens = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) u8 curlencheck = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) unsigned i, sendbuf_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) if (rr3->transmitting) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) dev_warn(dev, "%s: transmitter already in use\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) if (count > RR3_MAX_SIG_SIZE - RR3_TX_TRAILER_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) /* rr3 will disable rc detector on transmit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) rr3->transmitting = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) sample_lens = kcalloc(RR3_DRIVER_MAXLENS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) sizeof(*sample_lens),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) if (!sample_lens)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) irdata = kzalloc(sizeof(*irdata), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) if (!irdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) cur_sample_len = redrat3_us_to_len(txbuf[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) if (cur_sample_len > 0xffff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) dev_warn(dev, "transmit period of %uus truncated to %uus\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) txbuf[i], redrat3_len_to_us(0xffff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) cur_sample_len = 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) for (lencheck = 0; lencheck < curlencheck; lencheck++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) if (sample_lens[lencheck] == cur_sample_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) if (lencheck == curlencheck) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) dev_dbg(dev, "txbuf[%d]=%u, pos %d, enc %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) i, txbuf[i], curlencheck, cur_sample_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) if (curlencheck < RR3_DRIVER_MAXLENS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) /* now convert the value to a proper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) * rr3 value.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) sample_lens[curlencheck] = cur_sample_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) put_unaligned_be16(cur_sample_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) &irdata->lens[curlencheck]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) curlencheck++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) irdata->sigdata[i] = lencheck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) irdata->sigdata[count] = RR3_END_OF_SIGNAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) irdata->sigdata[count + 1] = RR3_END_OF_SIGNAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) sendbuf_len = offsetof(struct redrat3_irdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) sigdata[count + RR3_TX_TRAILER_LEN]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) /* fill in our packet header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) irdata->header.length = cpu_to_be16(sendbuf_len -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) sizeof(struct redrat3_header));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) irdata->header.transfer_type = cpu_to_be16(RR3_MOD_SIGNAL_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) irdata->pause = cpu_to_be32(redrat3_len_to_us(100));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) irdata->mod_freq_count = cpu_to_be16(mod_freq_to_val(rr3->carrier));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) irdata->no_lengths = curlencheck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) irdata->sig_size = cpu_to_be16(count + RR3_TX_TRAILER_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) pipe = usb_sndbulkpipe(rr3->udev, rr3->ep_out->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) ret = usb_bulk_msg(rr3->udev, pipe, irdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) sendbuf_len, &ret_len, 10000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) dev_dbg(dev, "sent %d bytes, (ret %d)\n", ret_len, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) /* now tell the hardware to transmit what we sent it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) pipe = usb_rcvctrlpipe(rr3->udev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) ret = usb_control_msg(rr3->udev, pipe, RR3_TX_SEND_SIGNAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 0, 0, irdata, 2, 10000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) dev_err(dev, "Error: control msg send failed, rc %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) ret = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) kfree(irdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) kfree(sample_lens);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) rr3->transmitting = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) /* rr3 re-enables rc detector because it was enabled before */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) static void redrat3_brightness_set(struct led_classdev *led_dev, enum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) led_brightness brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) struct redrat3_dev *rr3 = container_of(led_dev, struct redrat3_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if (brightness != LED_OFF && atomic_cmpxchg(&rr3->flash, 0, 1) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) int ret = usb_submit_urb(rr3->flash_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) dev_dbg(rr3->dev, "%s: unexpected ret of %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) atomic_set(&rr3->flash, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) static int redrat3_wideband_receiver(struct rc_dev *rcdev, int enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) struct redrat3_dev *rr3 = rcdev->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) rr3->wideband = enable != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) if (enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) ret = usb_submit_urb(rr3->learn_urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) dev_err(rr3->dev, "Failed to submit learning urb: %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) static void redrat3_learn_complete(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) struct redrat3_dev *rr3 = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) switch (urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) case -ECONNRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) usb_unlink_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) case -EPIPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) dev_err(rr3->dev, "Error: learn urb status = %d", urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) static void redrat3_led_complete(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) struct redrat3_dev *rr3 = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) switch (urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) case -ECONNRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) usb_unlink_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) case -EPIPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) dev_dbg(rr3->dev, "Error: urb status = %d\n", urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) rr3->led.brightness = LED_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) atomic_dec(&rr3->flash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) struct device *dev = rr3->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) struct rc_dev *rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) u16 prod = le16_to_cpu(rr3->udev->descriptor.idProduct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) rc = rc_allocate_device(RC_DRIVER_IR_RAW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) snprintf(rr3->name, sizeof(rr3->name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) "RedRat3%s Infrared Remote Transceiver",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) prod == USB_RR3IIUSB_PRODUCT_ID ? "-II" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) usb_make_path(rr3->udev, rr3->phys, sizeof(rr3->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) rc->device_name = rr3->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) rc->input_phys = rr3->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) usb_to_input_id(rr3->udev, &rc->input_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) rc->dev.parent = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) rc->priv = rr3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) rc->min_timeout = MS_TO_US(RR3_RX_MIN_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) rc->max_timeout = MS_TO_US(RR3_RX_MAX_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) rc->timeout = redrat3_get_timeout(rr3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) rc->s_timeout = redrat3_set_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) rc->tx_ir = redrat3_transmit_ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) rc->s_tx_carrier = redrat3_set_tx_carrier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) rc->s_carrier_report = redrat3_wideband_receiver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) rc->driver_name = DRIVER_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) rc->rx_resolution = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) rc->map_name = RC_MAP_HAUPPAUGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) ret = rc_register_device(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) dev_err(dev, "remote dev registration failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) rc_free_device(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) static int redrat3_dev_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) struct usb_device *udev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) struct device *dev = &intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) struct usb_host_interface *uhi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) struct redrat3_dev *rr3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) struct usb_endpoint_descriptor *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) struct usb_endpoint_descriptor *ep_narrow = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) struct usb_endpoint_descriptor *ep_wide = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) struct usb_endpoint_descriptor *ep_out = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) u8 addr, attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) int pipe, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) int retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) uhi = intf->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) /* find our bulk-in and bulk-out endpoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) for (i = 0; i < uhi->desc.bNumEndpoints; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) ep = &uhi->endpoint[i].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) addr = ep->bEndpointAddress;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) attrs = ep->bmAttributes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) if (((addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) ((attrs & USB_ENDPOINT_XFERTYPE_MASK) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) USB_ENDPOINT_XFER_BULK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) dev_dbg(dev, "found bulk-in endpoint at 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) ep->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) /* data comes in on 0x82, 0x81 is for learning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) if (ep->bEndpointAddress == RR3_NARROW_IN_EP_ADDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) ep_narrow = ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) if (ep->bEndpointAddress == RR3_WIDE_IN_EP_ADDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) ep_wide = ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) if ((ep_out == NULL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) ((addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) ((attrs & USB_ENDPOINT_XFERTYPE_MASK) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) USB_ENDPOINT_XFER_BULK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) dev_dbg(dev, "found bulk-out endpoint at 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) ep->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) ep_out = ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) if (!ep_narrow || !ep_out || !ep_wide) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) dev_err(dev, "Couldn't find all endpoints\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) retval = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) goto no_endpoints;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) /* allocate memory for our device state and initialize it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) rr3 = kzalloc(sizeof(*rr3), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) if (!rr3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) goto no_endpoints;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) rr3->dev = &intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) rr3->ep_narrow = ep_narrow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) rr3->ep_out = ep_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) rr3->udev = udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) /* set up bulk-in endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) rr3->narrow_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) if (!rr3->narrow_urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) goto redrat_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) rr3->wide_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) if (!rr3->wide_urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) goto redrat_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) rr3->bulk_in_buf = usb_alloc_coherent(udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) le16_to_cpu(ep_narrow->wMaxPacketSize),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) GFP_KERNEL, &rr3->dma_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) if (!rr3->bulk_in_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) goto redrat_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) pipe = usb_rcvbulkpipe(udev, ep_narrow->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) usb_fill_bulk_urb(rr3->narrow_urb, udev, pipe, rr3->bulk_in_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) le16_to_cpu(ep_narrow->wMaxPacketSize),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) redrat3_handle_async, rr3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) rr3->narrow_urb->transfer_dma = rr3->dma_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) rr3->narrow_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) pipe = usb_rcvbulkpipe(udev, ep_wide->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) usb_fill_bulk_urb(rr3->wide_urb, udev, pipe, rr3->bulk_in_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) le16_to_cpu(ep_narrow->wMaxPacketSize),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) redrat3_handle_async, rr3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) rr3->wide_urb->transfer_dma = rr3->dma_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) rr3->wide_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) redrat3_reset(rr3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) redrat3_get_firmware_rev(rr3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) /* default.. will get overridden by any sends with a freq defined */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) rr3->carrier = 38000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) atomic_set(&rr3->flash, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) rr3->flash_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) if (!rr3->flash_urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) goto redrat_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) /* learn urb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) rr3->learn_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) if (!rr3->learn_urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) goto redrat_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) /* setup packet is 'c0 b2 0000 0000 0001' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) rr3->learn_control.bRequestType = 0xc0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) rr3->learn_control.bRequest = RR3_MODSIG_CAPTURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) rr3->learn_control.wLength = cpu_to_le16(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) usb_fill_control_urb(rr3->learn_urb, udev, usb_rcvctrlpipe(udev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) (unsigned char *)&rr3->learn_control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) &rr3->learn_buf, sizeof(rr3->learn_buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) redrat3_learn_complete, rr3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) /* setup packet is 'c0 b9 0000 0000 0001' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) rr3->flash_control.bRequestType = 0xc0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) rr3->flash_control.bRequest = RR3_BLINK_LED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) rr3->flash_control.wLength = cpu_to_le16(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) usb_fill_control_urb(rr3->flash_urb, udev, usb_rcvctrlpipe(udev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) (unsigned char *)&rr3->flash_control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) &rr3->flash_in_buf, sizeof(rr3->flash_in_buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) redrat3_led_complete, rr3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) /* led control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) rr3->led.name = "redrat3:red:feedback";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) rr3->led.default_trigger = "rc-feedback";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) rr3->led.brightness_set = redrat3_brightness_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) retval = led_classdev_register(&intf->dev, &rr3->led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) goto redrat_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) rr3->rc = redrat3_init_rc_dev(rr3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) if (!rr3->rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) goto led_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) /* might be all we need to do? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) retval = redrat3_enable_detector(rr3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) goto led_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) /* we can register the device now, as it is ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) usb_set_intfdata(intf, rr3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) led_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) led_classdev_unregister(&rr3->led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) redrat_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) redrat3_delete(rr3, rr3->udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) no_endpoints:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) static void redrat3_dev_disconnect(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) struct usb_device *udev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) struct redrat3_dev *rr3 = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) usb_set_intfdata(intf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) rc_unregister_device(rr3->rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) led_classdev_unregister(&rr3->led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) redrat3_delete(rr3, udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) static int redrat3_dev_suspend(struct usb_interface *intf, pm_message_t message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) struct redrat3_dev *rr3 = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) led_classdev_suspend(&rr3->led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) usb_kill_urb(rr3->narrow_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) usb_kill_urb(rr3->wide_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) usb_kill_urb(rr3->flash_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) static int redrat3_dev_resume(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) struct redrat3_dev *rr3 = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) if (usb_submit_urb(rr3->narrow_urb, GFP_ATOMIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) if (usb_submit_urb(rr3->wide_urb, GFP_ATOMIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) led_classdev_resume(&rr3->led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) static struct usb_driver redrat3_dev_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) .name = DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) .probe = redrat3_dev_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) .disconnect = redrat3_dev_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) .suspend = redrat3_dev_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) .resume = redrat3_dev_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) .reset_resume = redrat3_dev_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) .id_table = redrat3_dev_table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) module_usb_driver(redrat3_dev_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) MODULE_AUTHOR(DRIVER_AUTHOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) MODULE_AUTHOR(DRIVER_AUTHOR2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) MODULE_DEVICE_TABLE(usb, redrat3_dev_table);