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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * ati_remote2 - ATI/Philips USB RF remote driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (C) 2005-2008 Ville Syrjala <syrjala@sci.fi>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright (C) 2007-2008 Peter Stokes <linux@dadeos.co.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include <linux/usb/input.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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #define DRIVER_DESC    "ATI/Philips USB RF remote driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  * ATI Remote Wonder II Channel Configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  * The remote control can be assigned one of sixteen "channels" in order to facilitate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  * the use of multiple remote controls within range of each other.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  * A remote's "channel" may be altered by pressing and holding the "PC" button for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  * approximately 3 seconds, after which the button will slowly flash the count of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  * currently configured "channel", using the numeric keypad enter a number between 1 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  * 16 and then press the "PC" button again, the button will slowly flash the count of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  * newly configured "channel".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 	ATI_REMOTE2_MAX_CHANNEL_MASK = 0xFFFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 	ATI_REMOTE2_MAX_MODE_MASK = 0x1F,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) static int ati_remote2_set_mask(const char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 				const struct kernel_param *kp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 				unsigned int max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 	unsigned int mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 	if (!val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 	ret = kstrtouint(val, 0, &mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 	if (mask & ~max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 	*(unsigned int *)kp->arg = mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) static int ati_remote2_set_channel_mask(const char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 					const struct kernel_param *kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 	pr_debug("%s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_CHANNEL_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) static int ati_remote2_get_channel_mask(char *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 					const struct kernel_param *kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	pr_debug("%s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 	return sprintf(buffer, "0x%04x\n", *(unsigned int *)kp->arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) static int ati_remote2_set_mode_mask(const char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 				     const struct kernel_param *kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	pr_debug("%s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_MODE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) static int ati_remote2_get_mode_mask(char *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 				     const struct kernel_param *kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	pr_debug("%s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	return sprintf(buffer, "0x%02x\n", *(unsigned int *)kp->arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) #define param_check_channel_mask(name, p) __param_check(name, p, unsigned int)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) static const struct kernel_param_ops param_ops_channel_mask = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	.set = ati_remote2_set_channel_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	.get = ati_remote2_get_channel_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) module_param(channel_mask, channel_mask, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) #define param_check_mode_mask(name, p) __param_check(name, p, unsigned int)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) static const struct kernel_param_ops param_ops_mode_mask = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	.set = ati_remote2_set_mode_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	.get = ati_remote2_get_mode_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) module_param(mode_mask, mode_mask, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) static const struct usb_device_id ati_remote2_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	{ USB_DEVICE(0x0471, 0x0602) },	/* ATI Remote Wonder II */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) MODULE_DEVICE_TABLE(usb, ati_remote2_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) static DEFINE_MUTEX(ati_remote2_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	ATI_REMOTE2_OPENED = 0x1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	ATI_REMOTE2_SUSPENDED = 0x2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	ATI_REMOTE2_AUX1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	ATI_REMOTE2_AUX2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	ATI_REMOTE2_AUX3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	ATI_REMOTE2_AUX4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	ATI_REMOTE2_PC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	ATI_REMOTE2_MODES,
^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) static const struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	u8  hw_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	u16 keycode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) } ati_remote2_key_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	{ 0x00, KEY_0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	{ 0x01, KEY_1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	{ 0x02, KEY_2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	{ 0x03, KEY_3 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	{ 0x04, KEY_4 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	{ 0x05, KEY_5 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	{ 0x06, KEY_6 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	{ 0x07, KEY_7 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	{ 0x08, KEY_8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	{ 0x09, KEY_9 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	{ 0x0c, KEY_POWER },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	{ 0x0d, KEY_MUTE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	{ 0x10, KEY_VOLUMEUP },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	{ 0x11, KEY_VOLUMEDOWN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	{ 0x20, KEY_CHANNELUP },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	{ 0x21, KEY_CHANNELDOWN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	{ 0x28, KEY_FORWARD },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	{ 0x29, KEY_REWIND },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	{ 0x2c, KEY_PLAY },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	{ 0x30, KEY_PAUSE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	{ 0x31, KEY_STOP },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	{ 0x37, KEY_RECORD },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	{ 0x38, KEY_DVD },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	{ 0x39, KEY_TV },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	{ 0x3f, KEY_PROG1 }, /* AUX1-AUX4 and PC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	{ 0x54, KEY_MENU },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	{ 0x58, KEY_UP },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	{ 0x59, KEY_DOWN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	{ 0x5a, KEY_LEFT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	{ 0x5b, KEY_RIGHT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	{ 0x5c, KEY_OK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	{ 0x78, KEY_A },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	{ 0x79, KEY_B },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	{ 0x7a, KEY_C },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	{ 0x7b, KEY_D },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	{ 0x7c, KEY_E },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	{ 0x7d, KEY_F },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	{ 0x82, KEY_ENTER },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	{ 0x8e, KEY_VENDOR },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	{ 0x96, KEY_COFFEE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	{ 0xa9, BTN_LEFT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	{ 0xaa, BTN_RIGHT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	{ 0xbe, KEY_QUESTION },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	{ 0xd0, KEY_EDIT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	{ 0xd5, KEY_FRONT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	{ 0xf9, KEY_INFO },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) struct ati_remote2 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	struct input_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	struct usb_interface *intf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	struct usb_endpoint_descriptor *ep[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	struct urb *urb[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	void *buf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	dma_addr_t buf_dma[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	unsigned long jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	int mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	char name[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	char phys[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	/* Each mode (AUX1-AUX4 and PC) can have an independent keymap. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	u16 keycode[ATI_REMOTE2_MODES][ARRAY_SIZE(ati_remote2_key_table)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	unsigned int channel_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	unsigned int mode_mask;
^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 ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) static void ati_remote2_disconnect(struct usb_interface *interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) static int ati_remote2_suspend(struct usb_interface *interface, pm_message_t message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) static int ati_remote2_resume(struct usb_interface *interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) static int ati_remote2_reset_resume(struct usb_interface *interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) static int ati_remote2_pre_reset(struct usb_interface *interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) static int ati_remote2_post_reset(struct usb_interface *interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) static struct usb_driver ati_remote2_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	.name       = "ati_remote2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	.probe      = ati_remote2_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	.disconnect = ati_remote2_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	.id_table   = ati_remote2_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	.suspend    = ati_remote2_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	.resume     = ati_remote2_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	.reset_resume = ati_remote2_reset_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	.pre_reset  = ati_remote2_pre_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	.post_reset = ati_remote2_post_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	.supports_autosuspend = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) static int ati_remote2_submit_urbs(struct ati_remote2 *ar2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	r = usb_submit_urb(ar2->urb[0], GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		dev_err(&ar2->intf[0]->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 			"%s(): usb_submit_urb() = %d\n", __func__, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	r = usb_submit_urb(ar2->urb[1], GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 		usb_kill_urb(ar2->urb[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 		dev_err(&ar2->intf[1]->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 			"%s(): usb_submit_urb() = %d\n", __func__, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 		return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) static void ati_remote2_kill_urbs(struct ati_remote2 *ar2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	usb_kill_urb(ar2->urb[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	usb_kill_urb(ar2->urb[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) static int ati_remote2_open(struct input_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	struct ati_remote2 *ar2 = input_get_drvdata(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	r = usb_autopm_get_interface(ar2->intf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 		dev_err(&ar2->intf[0]->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 			"%s(): usb_autopm_get_interface() = %d\n", __func__, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 		goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	mutex_lock(&ati_remote2_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 		r = ati_remote2_submit_urbs(ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 		if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 			goto fail2;
^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) 	ar2->flags |= ATI_REMOTE2_OPENED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	mutex_unlock(&ati_remote2_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	usb_autopm_put_interface(ar2->intf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285)  fail2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	mutex_unlock(&ati_remote2_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	usb_autopm_put_interface(ar2->intf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288)  fail1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	return r;
^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 void ati_remote2_close(struct input_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	struct ati_remote2 *ar2 = input_get_drvdata(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	mutex_lock(&ati_remote2_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	if (!(ar2->flags & ATI_REMOTE2_SUSPENDED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 		ati_remote2_kill_urbs(ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	ar2->flags &= ~ATI_REMOTE2_OPENED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	mutex_unlock(&ati_remote2_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) static void ati_remote2_input_mouse(struct ati_remote2 *ar2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	struct input_dev *idev = ar2->idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	u8 *data = ar2->buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	int channel, mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	channel = data[0] >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	if (!((1 << channel) & ar2->channel_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	mode = data[0] & 0x0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	if (mode > ATI_REMOTE2_PC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 		dev_err(&ar2->intf[0]->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 			"Unknown mode byte (%02x %02x %02x %02x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 			data[3], data[2], data[1], data[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	if (!((1 << mode) & ar2->mode_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	input_event(idev, EV_REL, REL_X, (s8) data[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	input_event(idev, EV_REL, REL_Y, (s8) data[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	input_sync(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) static int ati_remote2_lookup(unsigned int hw_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	for (i = 0; i < ARRAY_SIZE(ati_remote2_key_table); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		if (ati_remote2_key_table[i].hw_code == hw_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 			return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) static void ati_remote2_input_key(struct ati_remote2 *ar2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	struct input_dev *idev = ar2->idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	u8 *data = ar2->buf[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	int channel, mode, hw_code, index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	channel = data[0] >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	if (!((1 << channel) & ar2->channel_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	mode = data[0] & 0x0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	if (mode > ATI_REMOTE2_PC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		dev_err(&ar2->intf[1]->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 			"Unknown mode byte (%02x %02x %02x %02x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 			data[3], data[2], data[1], data[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	hw_code = data[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	if (hw_code == 0x3f) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 		 * For some incomprehensible reason the mouse pad generates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 		 * events which look identical to the events from the last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		 * pressed mode key. Naturally we don't want to generate key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 		 * events for the mouse pad so we filter out any subsequent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 		 * events from the same mode key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 		if (ar2->mode == mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 		if (data[1] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 			ar2->mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	if (!((1 << mode) & ar2->mode_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	index = ati_remote2_lookup(hw_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	if (index < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 		dev_err(&ar2->intf[1]->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 			"Unknown code byte (%02x %02x %02x %02x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 			data[3], data[2], data[1], data[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	switch (data[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	case 0:	/* release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	case 1:	/* press */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_DELAY]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	case 2:	/* repeat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 		/* No repeat for mouse buttons. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		if (ar2->keycode[mode][index] == BTN_LEFT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 		    ar2->keycode[mode][index] == BTN_RIGHT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		if (!time_after_eq(jiffies, ar2->jiffies))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_PERIOD]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		dev_err(&ar2->intf[1]->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 			"Unknown state byte (%02x %02x %02x %02x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 			data[3], data[2], data[1], data[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	input_event(idev, EV_KEY, ar2->keycode[mode][index], data[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	input_sync(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) static void ati_remote2_complete_mouse(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	struct ati_remote2 *ar2 = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	switch (urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 		usb_mark_last_busy(ar2->udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 		ati_remote2_input_mouse(ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	case -EILSEQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	case -ECONNRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 		dev_dbg(&ar2->intf[0]->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 			"%s(): urb status = %d\n", __func__, urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 		usb_mark_last_busy(ar2->udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		dev_err(&ar2->intf[0]->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 			"%s(): urb status = %d\n", __func__, urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	r = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		dev_err(&ar2->intf[0]->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 			"%s(): usb_submit_urb() = %d\n", __func__, r);
^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 void ati_remote2_complete_key(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	struct ati_remote2 *ar2 = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	switch (urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		usb_mark_last_busy(ar2->udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		ati_remote2_input_key(ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	case -EILSEQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	case -ECONNRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		dev_dbg(&ar2->intf[1]->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 			"%s(): urb status = %d\n", __func__, urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		usb_mark_last_busy(ar2->udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 		dev_err(&ar2->intf[1]->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 			"%s(): urb status = %d\n", __func__, urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	r = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		dev_err(&ar2->intf[1]->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 			"%s(): usb_submit_urb() = %d\n", __func__, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) static int ati_remote2_getkeycode(struct input_dev *idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 				  struct input_keymap_entry *ke)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	struct ati_remote2 *ar2 = input_get_drvdata(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	unsigned int mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	unsigned int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	unsigned int scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		index = ke->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 		if (index >= ATI_REMOTE2_MODES *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 				ARRAY_SIZE(ati_remote2_key_table))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 		scancode = (mode << 8) + ati_remote2_key_table[offset].hw_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		if (input_scancode_to_scalar(ke, &scancode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		mode = scancode >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		if (mode > ATI_REMOTE2_PC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 		offset = ati_remote2_lookup(scancode & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 		if (offset < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		index = mode * ARRAY_SIZE(ati_remote2_key_table) + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	ke->keycode = ar2->keycode[mode][offset];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	ke->len = sizeof(scancode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	memcpy(&ke->scancode, &scancode, sizeof(scancode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	ke->index = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) static int ati_remote2_setkeycode(struct input_dev *idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 				  const struct input_keymap_entry *ke,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 				  unsigned int *old_keycode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	struct ati_remote2 *ar2 = input_get_drvdata(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	unsigned int mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	unsigned int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	unsigned int scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 		if (ke->index >= ATI_REMOTE2_MODES *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 				ARRAY_SIZE(ati_remote2_key_table))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 		if (input_scancode_to_scalar(ke, &scancode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		mode = scancode >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 		if (mode > ATI_REMOTE2_PC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 		offset = ati_remote2_lookup(scancode & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 		if (offset < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	*old_keycode = ar2->keycode[mode][offset];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	ar2->keycode[mode][offset] = ke->keycode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	__set_bit(ke->keycode, idev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 		for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 			if (ar2->keycode[mode][index] == *old_keycode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	__clear_bit(*old_keycode, idev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) static int ati_remote2_input_init(struct ati_remote2 *ar2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	struct input_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	int index, mode, retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	idev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	ar2->idev = idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	input_set_drvdata(idev, ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		BIT_MASK(BTN_RIGHT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 			ar2->keycode[mode][index] = ati_remote2_key_table[index].keycode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 			__set_bit(ar2->keycode[mode][index], idev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	/* AUX1-AUX4 and PC generate the same scancode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	index = ati_remote2_lookup(0x3f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	ar2->keycode[ATI_REMOTE2_AUX1][index] = KEY_PROG1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	ar2->keycode[ATI_REMOTE2_AUX2][index] = KEY_PROG2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	ar2->keycode[ATI_REMOTE2_AUX3][index] = KEY_PROG3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	ar2->keycode[ATI_REMOTE2_AUX4][index] = KEY_PROG4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	ar2->keycode[ATI_REMOTE2_PC][index] = KEY_PC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	__set_bit(KEY_PROG1, idev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	__set_bit(KEY_PROG2, idev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	__set_bit(KEY_PROG3, idev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	__set_bit(KEY_PROG4, idev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	__set_bit(KEY_PC, idev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	idev->rep[REP_DELAY]  = 250;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	idev->rep[REP_PERIOD] = 33;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	idev->open = ati_remote2_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	idev->close = ati_remote2_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	idev->getkeycode = ati_remote2_getkeycode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	idev->setkeycode = ati_remote2_setkeycode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	idev->name = ar2->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	idev->phys = ar2->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	usb_to_input_id(ar2->udev, &idev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	idev->dev.parent = &ar2->udev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	retval = input_register_device(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		input_free_device(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) static int ati_remote2_urb_init(struct ati_remote2 *ar2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	struct usb_device *udev = ar2->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	int i, pipe, maxp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		ar2->buf[i] = usb_alloc_coherent(udev, 4, GFP_KERNEL, &ar2->buf_dma[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		if (!ar2->buf[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 		ar2->urb[i] = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 		if (!ar2->urb[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		pipe = usb_rcvintpipe(udev, ar2->ep[i]->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		maxp = maxp > 4 ? 4 : maxp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		usb_fill_int_urb(ar2->urb[i], udev, pipe, ar2->buf[i], maxp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 				 i ? ati_remote2_complete_key : ati_remote2_complete_mouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 				 ar2, ar2->ep[i]->bInterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		ar2->urb[i]->transfer_dma = ar2->buf_dma[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		ar2->urb[i]->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
^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) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) static void ati_remote2_urb_cleanup(struct ati_remote2 *ar2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		usb_free_urb(ar2->urb[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		usb_free_coherent(ar2->udev, 4, ar2->buf[i], ar2->buf_dma[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) static int ati_remote2_setup(struct ati_remote2 *ar2, unsigned int ch_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	int r, i, channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	 * Configure receiver to only accept input from remote "channel"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	 *  channel == 0  -> Accept input from any remote channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	 *  channel == 1  -> Only accept input from remote channel 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	 *  channel == 2  -> Only accept input from remote channel 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	 *  ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	 *  channel == 16 -> Only accept input from remote channel 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	channel = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	for (i = 0; i < 16; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		if ((1 << i) & ch_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 			if (!(~(1 << i) & ch_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 				channel = i + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		}
^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) 	r = usb_control_msg(ar2->udev, usb_sndctrlpipe(ar2->udev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 			    0x20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 			    USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 			    channel, 0x0, NULL, 0, USB_CTRL_SET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		dev_err(&ar2->udev->dev, "%s - failed to set channel due to error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 			__func__, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) static ssize_t ati_remote2_show_channel_mask(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 					     struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 					     char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	struct usb_device *udev = to_usb_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	struct ati_remote2 *ar2 = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	return sprintf(buf, "0x%04x\n", ar2->channel_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) static ssize_t ati_remote2_store_channel_mask(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 					      struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 					      const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	struct usb_device *udev = to_usb_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	struct ati_remote2 *ar2 = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	unsigned int mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	r = kstrtouint(buf, 0, &mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	if (mask & ~ATI_REMOTE2_MAX_CHANNEL_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	r = usb_autopm_get_interface(ar2->intf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 		dev_err(&ar2->intf[0]->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 			"%s(): usb_autopm_get_interface() = %d\n", __func__, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	mutex_lock(&ati_remote2_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	if (mask != ar2->channel_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 		r = ati_remote2_setup(ar2, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		if (!r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 			ar2->channel_mask = mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	mutex_unlock(&ati_remote2_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	usb_autopm_put_interface(ar2->intf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	return r ? r : count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) static ssize_t ati_remote2_show_mode_mask(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 					  struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 					  char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	struct usb_device *udev = to_usb_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	struct ati_remote2 *ar2 = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	return sprintf(buf, "0x%02x\n", ar2->mode_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) static ssize_t ati_remote2_store_mode_mask(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 					   struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 					   const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	struct usb_device *udev = to_usb_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	struct ati_remote2 *ar2 = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	unsigned int mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	err = kstrtouint(buf, 0, &mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	if (mask & ~ATI_REMOTE2_MAX_MODE_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	ar2->mode_mask = mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	return count;
^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) static DEVICE_ATTR(channel_mask, 0644, ati_remote2_show_channel_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		   ati_remote2_store_channel_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) static DEVICE_ATTR(mode_mask, 0644, ati_remote2_show_mode_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		   ati_remote2_store_mode_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) static struct attribute *ati_remote2_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	&dev_attr_channel_mask.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	&dev_attr_mode_mask.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) static struct attribute_group ati_remote2_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	.attrs = ati_remote2_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	struct usb_device *udev = interface_to_usbdev(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	struct usb_host_interface *alt = interface->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	struct ati_remote2 *ar2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	if (alt->desc.bInterfaceNumber)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	ar2 = kzalloc(sizeof (struct ati_remote2), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	if (!ar2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	ar2->udev = udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	/* Sanity check, first interface must have an endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	if (alt->desc.bNumEndpoints < 1 || !alt->endpoint) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		dev_err(&interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 			"%s(): interface 0 must have an endpoint\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 		r = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	ar2->intf[0] = interface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	ar2->ep[0] = &alt->endpoint[0].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	/* Sanity check, the device must have two interfaces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	ar2->intf[1] = usb_ifnum_to_if(udev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	if ((udev->actconfig->desc.bNumInterfaces < 2) || !ar2->intf[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 		dev_err(&interface->dev, "%s(): need 2 interfaces, found %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 			__func__, udev->actconfig->desc.bNumInterfaces);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		r = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	r = usb_driver_claim_interface(&ati_remote2_driver, ar2->intf[1], ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	/* Sanity check, second interface must have an endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	alt = ar2->intf[1]->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	if (alt->desc.bNumEndpoints < 1 || !alt->endpoint) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 		dev_err(&interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 			"%s(): interface 1 must have an endpoint\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 		r = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	ar2->ep[1] = &alt->endpoint[0].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	r = ati_remote2_urb_init(ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		goto fail3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	ar2->channel_mask = channel_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	ar2->mode_mask = mode_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	r = ati_remote2_setup(ar2, ar2->channel_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		goto fail3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	usb_make_path(udev, ar2->phys, sizeof(ar2->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	strlcat(ar2->phys, "/input0", sizeof(ar2->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	strlcat(ar2->name, "ATI Remote Wonder II", sizeof(ar2->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	r = sysfs_create_group(&udev->dev.kobj, &ati_remote2_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 		goto fail3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	r = ati_remote2_input_init(ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 		goto fail4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	usb_set_intfdata(interface, ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	interface->needs_remote_wakeup = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878)  fail4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	sysfs_remove_group(&udev->dev.kobj, &ati_remote2_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880)  fail3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	ati_remote2_urb_cleanup(ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882)  fail2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884)  fail1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	kfree(ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) static void ati_remote2_disconnect(struct usb_interface *interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	struct ati_remote2 *ar2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	struct usb_host_interface *alt = interface->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	if (alt->desc.bInterfaceNumber)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	ar2 = usb_get_intfdata(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	usb_set_intfdata(interface, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	input_unregister_device(ar2->idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	sysfs_remove_group(&ar2->udev->dev.kobj, &ati_remote2_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	ati_remote2_urb_cleanup(ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	kfree(ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) static int ati_remote2_suspend(struct usb_interface *interface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 			       pm_message_t message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	struct ati_remote2 *ar2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	struct usb_host_interface *alt = interface->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	if (alt->desc.bInterfaceNumber)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	ar2 = usb_get_intfdata(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	mutex_lock(&ati_remote2_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	if (ar2->flags & ATI_REMOTE2_OPENED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		ati_remote2_kill_urbs(ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	ar2->flags |= ATI_REMOTE2_SUSPENDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	mutex_unlock(&ati_remote2_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) static int ati_remote2_resume(struct usb_interface *interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	struct ati_remote2 *ar2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	struct usb_host_interface *alt = interface->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	int r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	if (alt->desc.bInterfaceNumber)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	ar2 = usb_get_intfdata(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	mutex_lock(&ati_remote2_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	if (ar2->flags & ATI_REMOTE2_OPENED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		r = ati_remote2_submit_urbs(ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	if (!r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	mutex_unlock(&ati_remote2_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) static int ati_remote2_reset_resume(struct usb_interface *interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	struct ati_remote2 *ar2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	struct usb_host_interface *alt = interface->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	int r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	if (alt->desc.bInterfaceNumber)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	ar2 = usb_get_intfdata(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	mutex_lock(&ati_remote2_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	r = ati_remote2_setup(ar2, ar2->channel_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	if (ar2->flags & ATI_REMOTE2_OPENED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 		r = ati_remote2_submit_urbs(ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	if (!r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	mutex_unlock(&ati_remote2_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) static int ati_remote2_pre_reset(struct usb_interface *interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	struct ati_remote2 *ar2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	struct usb_host_interface *alt = interface->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	if (alt->desc.bInterfaceNumber)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	ar2 = usb_get_intfdata(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	mutex_lock(&ati_remote2_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	if (ar2->flags == ATI_REMOTE2_OPENED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 		ati_remote2_kill_urbs(ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) static int ati_remote2_post_reset(struct usb_interface *interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	struct ati_remote2 *ar2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	struct usb_host_interface *alt = interface->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	int r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	if (alt->desc.bInterfaceNumber)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	ar2 = usb_get_intfdata(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	if (ar2->flags == ATI_REMOTE2_OPENED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 		r = ati_remote2_submit_urbs(ar2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	mutex_unlock(&ati_remote2_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) module_usb_driver(ati_remote2_driver);