Skip to contentSkip to conversation

dvb-usb-af9035: load HID table

PATCH In review Jaroslav Škarvada 3 participants 4 messages Jun 9, 2017 – Jun 14, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dvb-usb-af9035: load HID table

Automatically load sniffed HID table from Windows driver if USB_VID_ITETECH:USB_PID_ITETECH_IT9135_9006 device is present (e.g. Evolveo Mars) or if module parameter force_hid_tab_load is set.

---
 drivers/media/usb/dvb-usb-v2/af9035.c | 266 ++++++++++++++++++++++++++++++++++
 1 file changed, 266 insertions(+)
drivers/media/usb/dvb-usb-v2/af9035.c +266 -0
index 4df9486..5bbcc1e 100644
@@ -24,6 +24,10 @@
 /* Max transfer size done by I2C transfer functions */
 #define MAX_XFER_SIZE  64
 
+static bool force_hid_tab_load;
+module_param(force_hid_tab_load, bool, 0644);
+MODULE_PARM_DESC(force_hid_tab_load, "force HID table loading");
+
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
 static u16 af9035_checksum(const u8 *buf, size_t len)
@@ -1693,6 +1697,263 @@ static int af9035_tuner_detach(struct dvb_usb_adapter *adap)
 	return 0;
 }
 
+static int ite9135_load_hid_tab(struct dvb_usb_device *d)
+{
+	struct usb_interface *intf = d->intf;
+	int ret, i;
+	struct reg_val hid_tab[] = {
+		{ 0x4a97, 0x02 },
+		{ 0x4a98, 0xbd },
+		{ 0x4a99, 0x0c },
+		{ 0x4a9a, 0xf3 },
+		{ 0x4a9b, 0x3d },
+		{ 0x4a9c, 0x00 },
+		{ 0x4a9d, 0x00 },
+		{ 0x4a9e, 0x02 },
+		{ 0x4a9f, 0xbd },
+		{ 0x4aa0, 0x00 },
+		{ 0x4aa1, 0xff },
+		{ 0x4aa2, 0x1e },
+		{ 0x4aa3, 0x00 },
+		{ 0x4aa4, 0x00 },
+		{ 0x4aa5, 0x02 },
+		{ 0x4aa6, 0xbd },
+		{ 0x4aa7, 0x01 },
+		{ 0x4aa8, 0xfe },
+		{ 0x4aa9, 0x1f },
+		{ 0x4aaa, 0x00 },
+		{ 0x4aab, 0x00 },
+		{ 0x4aac, 0x02 },
+		{ 0x4aad, 0xbd },
+		{ 0x4aae, 0x02 },
+		{ 0x4aaf, 0xfd },
+		{ 0x4ab0, 0x20 },
+		{ 0x4ab1, 0x00 },
+		{ 0x4ab2, 0x00 },
+		{ 0x4ab3, 0x02 },
+		{ 0x4ab4, 0xbd },
+		{ 0x4ab5, 0x03 },
+		{ 0x4ab6, 0xfc },
+		{ 0x4ab7, 0x21 },
+		{ 0x4ab8, 0x00 },
+		{ 0x4ab9, 0x00 },
+		{ 0x4aba, 0x02 },
+		{ 0x4abb, 0xbd },
+		{ 0x4abc, 0x04 },
+		{ 0x4abd, 0xfb },
+		{ 0x4abe, 0x22 },
+		{ 0x4abf, 0x00 },
+		{ 0x4ac0, 0x00 },
+		{ 0x4ac1, 0x02 },
+		{ 0x4ac2, 0xbd },
+		{ 0x4ac3, 0x05 },
+		{ 0x4ac4, 0xfa },
+		{ 0x4ac5, 0x23 },
+		{ 0x4ac6, 0x00 },
+		{ 0x4ac7, 0x00 },
+		{ 0x4ac8, 0x02 },
+		{ 0x4ac9, 0xbd },
+		{ 0x4aca, 0x06 },
+		{ 0x4acb, 0xf9 },
+		{ 0x4acc, 0x24 },
+		{ 0x4acd, 0x00 },
+		{ 0x4ace, 0x00 },
+		{ 0x4acf, 0x02 },
+		{ 0x4ad0, 0xbd },
+		{ 0x4ad1, 0x07 },
+		{ 0x4ad2, 0xf8 },
+		{ 0x4ad3, 0x25 },
+		{ 0x4ad4, 0x00 },
+		{ 0x4ad5, 0x00 },
+		{ 0x4ad6, 0x02 },
+		{ 0x4ad7, 0xbd },
+		{ 0x4ad8, 0x08 },
+		{ 0x4ad9, 0xf7 },
+		{ 0x4ada, 0x26 },
+		{ 0x4adb, 0x00 },
+		{ 0x4adc, 0x00 },
+		{ 0x4add, 0x02 },
+		{ 0x4ade, 0xbd },
+		{ 0x4adf, 0x09 },
+		{ 0x4ae0, 0xf6 },
+		{ 0x4ae1, 0x27 },
+		{ 0x4ae2, 0x00 },
+		{ 0x4ae3, 0x00 },
+		{ 0x4ae4, 0x02 },
+		{ 0x4ae5, 0xbd },
+		{ 0x4ae6, 0x0a },
+		{ 0x4ae7, 0xf5 },
+		{ 0x4ae8, 0x41 },
+		{ 0x4ae9, 0x00 },
+		{ 0x4aea, 0x00 },
+		{ 0x4aeb, 0x02 },
+		{ 0x4aec, 0xbd },
+		{ 0x4aed, 0x1c },
+		{ 0x4aee, 0xe3 },
+		{ 0x4aef, 0x2a },
+		{ 0x4af0, 0x00 },
+		{ 0x4af1, 0x00 },
+		{ 0x4af2, 0x02 },
+		{ 0x4af3, 0xbd },
+		{ 0x4af4, 0x1f },
+		{ 0x4af5, 0xe0 },
+		{ 0x4af6, 0x43 },
+		{ 0x4af7, 0x00 },
+		{ 0x4af8, 0x00 },
+		{ 0x4af9, 0x02 },
+		{ 0x4afa, 0xbd },
+		{ 0x4afb, 0x12 },
+		{ 0x4afc, 0xed },
+		{ 0x4afd, 0x52 },
+		{ 0x4afe, 0x00 },
+		{ 0x4aff, 0x00 },
+		{ 0x4b00, 0x02 },
+		{ 0x4b01, 0xbd },
+		{ 0x4b02, 0x11 },
+		{ 0x4b03, 0xee },
+		{ 0x4b04, 0x50 },
+		{ 0x4b05, 0x00 },
+		{ 0x4b06, 0x00 },
+		{ 0x4b07, 0x02 },
+		{ 0x4b08, 0xbd },
+		{ 0x4b09, 0x15 },
+		{ 0x4b0a, 0xea },
+		{ 0x4b0b, 0x28 },
+		{ 0x4b0c, 0x00 },
+		{ 0x4b0d, 0x00 },
+		{ 0x4b0e, 0x02 },
+		{ 0x4b0f, 0xbd },
+		{ 0x4b10, 0x10 },
+		{ 0x4b11, 0xef },
+		{ 0x4b12, 0x4f },
+		{ 0x4b13, 0x00 },
+		{ 0x4b14, 0x00 },
+		{ 0x4b15, 0x02 },
+		{ 0x4b16, 0xbd },
+		{ 0x4b17, 0x13 },
+		{ 0x4b18, 0xec },
+		{ 0x4b19, 0x51 },
+		{ 0x4b1a, 0x00 },
+		{ 0x4b1b, 0x00 },
+		{ 0x4b1c, 0x02 },
+		{ 0x4b1d, 0xbd },
+		{ 0x4b1e, 0x0e },
+		{ 0x4b1f, 0xf1 },
+		{ 0x4b20, 0x42 },
+		{ 0x4b21, 0x00 },
+		{ 0x4b22, 0x00 },
+		{ 0x4b23, 0x02 },
+		{ 0x4b24, 0xbd },
+		{ 0x4b25, 0x19 },
+		{ 0x4b26, 0xe6 },
+		{ 0x4b27, 0x15 },
+		{ 0x4b28, 0x01 },
+		{ 0x4b29, 0x00 },
+		{ 0x4b2a, 0x02 },
+		{ 0x4b2b, 0xbd },
+		{ 0x4b2c, 0x1e },
+		{ 0x4b2d, 0xe1 },
+		{ 0x4b2e, 0x13 },
+		{ 0x4b2f, 0x03 },
+		{ 0x4b30, 0x00 },
+		{ 0x4b31, 0x02 },
+		{ 0x4b32, 0xbd },
+		{ 0x4b33, 0x16 },
+		{ 0x4b34, 0xe9 },
+		{ 0x4b35, 0x16 },
+		{ 0x4b36, 0x01 },
+		{ 0x4b37, 0x00 },
+		{ 0x4b38, 0x02 },
+		{ 0x4b39, 0xbd },
+		{ 0x4b3a, 0x0b },
+		{ 0x4b3b, 0xf4 },
+		{ 0x4b3c, 0x28 },
+		{ 0x4b3d, 0x04 },
+		{ 0x4b3e, 0x00 },
+		{ 0x4b3f, 0x02 },
+		{ 0x4b40, 0xbd },
+		{ 0x4b41, 0x0f },
+		{ 0x4b42, 0xf0 },
+		{ 0x4b43, 0x3b },
+		{ 0x4b44, 0x00 },
+		{ 0x4b45, 0x00 },
+		{ 0x4b46, 0x02 },
+		{ 0x4b47, 0xbd },
+		{ 0x4b48, 0x18 },
+		{ 0x4b49, 0xe7 },
+		{ 0x4b4a, 0x2e },
+		{ 0x4b4b, 0x00 },
+		{ 0x4b4c, 0x00 },
+		{ 0x4b4d, 0x02 },
+		{ 0x4b4e, 0xbd },
+		{ 0x4b4f, 0x1a },
+		{ 0x4b50, 0xe5 },
+		{ 0x4b51, 0x2d },
+		{ 0x4b52, 0x00 },
+		{ 0x4b53, 0x00 },
+		{ 0x4b54, 0x02 },
+		{ 0x4b55, 0xbd },
+		{ 0x4b56, 0x17 },
+		{ 0x4b57, 0xe8 },
+		{ 0x4b58, 0x3e },
+		{ 0x4b59, 0x00 },
+		{ 0x4b5a, 0x00 },
+		{ 0x4b5b, 0x02 },
+		{ 0x4b5c, 0xbd },
+		{ 0x4b5d, 0x40 },
+		{ 0x4b5e, 0xbf },
+		{ 0x4b5f, 0x13 },
+		{ 0x4b60, 0x01 },
+		{ 0x4b61, 0x00 },
+		{ 0x4b62, 0x02 },
+		{ 0x4b63, 0xbd },
+		{ 0x4b64, 0x41 },
+		{ 0x4b65, 0xbe },
+		{ 0x4b66, 0x09 },
+		{ 0x4b67, 0x03 },
+		{ 0x4b68, 0x00 },
+		{ 0x4b69, 0x02 },
+		{ 0x4b6a, 0xbd },
+		{ 0x4b6b, 0x42 },
+		{ 0x4b6c, 0xbd },
+		{ 0x4b6d, 0x07 },
+		{ 0x4b6e, 0x03 },
+		{ 0x4b6f, 0x00 },
+		{ 0x4b70, 0x02 },
+		{ 0x4b71, 0xbd },
+		{ 0x4b72, 0x44 },
+		{ 0x4b73, 0xbb },
+		{ 0x4b74, 0x16 },
+		{ 0x4b75, 0x03 },
+		{ 0x4b76, 0x00 },
+		{ 0x4b77, 0x02 },
+		{ 0x4b78, 0xbd },
+		{ 0x4b79, 0x45 },
+		{ 0x4b7a, 0xba },
+		{ 0x4b7b, 0x45 },
+		{ 0x4b7c, 0x05 },
+		{ 0x4b7d, 0x00 },
+		{ 0x4b7e, 0x02 },
+		{ 0x4b7f, 0xbd },
+		{ 0x4b80, 0x14 },
+		{ 0x4b81, 0xeb },
+		{ 0x4b82, 0x45 },
+		{ 0x4b83, 0x03 },
+		{ 0x4b84, 0x00 },
+	};
+
+	for (i = 0; i < ARRAY_SIZE(hid_tab); i++) {
+		ret = af9035_wr_reg(d, hid_tab[i].reg, hid_tab[i].val);
+		if (ret < 0)
+			goto err;
+	}
+	dev_info(&intf->dev, "HID table successfully loaded\n");
+	return 0;
+err:
+	dev_info(&intf->dev, "loading HID table failed, item=%d, ret=%d\n", i, ret);
+	return ret;
+}
+
 static int af9035_init(struct dvb_usb_device *d)
 {
 	struct state *state = d_to_priv(d);
@@ -1732,6 +1993,11 @@ static int af9035_init(struct dvb_usb_device *d)
 			goto err;
 	}
 
+	if (force_hid_tab_load || \
+		(le16_to_cpu(d->udev->descriptor.idVendor) == USB_VID_ITETECH && \
+		le16_to_cpu(d->udev->descriptor.idProduct) == USB_PID_ITETECH_IT9135_9006))
+			ite9135_load_hid_tab(d);
+
 	return 0;
 
 err:
Signature · 1 line
2.9.4
#1 lore raw

Hello

Jaroslav Škarvada kirjoitti 2017-06-09 20:46:

Quoted 3 lines

Automatically load sniffed HID table from Windows driver if USB_VID_ITETECH:USB_PID_ITETECH_IT9135_9006 device is present (e.g. Evolveo Mars) or if module parameter force_hid_tab_load is set.

There is few issues I don't like this approach. Mostly that module parameter to select HID table. There is existing solution to select remote controller, it is ir-keytable and it should be used rather than defining device specific module parameter.

If you look that HID table you could see there is 4 bytes NEC code and 3 bytes HID code. Remote controller seems to have 34 keys. Remote controller address bytes are 0x02bd, grepping existing remote controller keytables it could be Total Media In Hand remote controller (rc-total-media-in-hand.c). If not, then defining new keytable is needed.

I did some research about issue and found 2 better solutions.
1) Configure HID table dynamically. Remote controller keytable has some needed information, but those KEY_* events needed to be translated to HID codes somehow.
2) Kill HID and then use CMD_IR_GET to get remote controller scancodes by polling.

Solution 1 sounds most correct. No need to poll and decode by sw as hw does all the job. But it is most hardest to implement, I am not aware if anyone has done it yet.

regards
Antti

Signature · 1 line
http://palosaari.fi/
#3 lore raw
In reply to Jaroslav Škarvada
reproduce: wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross…

Hi Jaroslav,

[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on v4.12-rc4 next-20170609]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Jaroslav-karvada/dvb-usb-af9035-load-HID-table/20170611-142004
base:   git://linuxtv.org/media_tree.git master
config: xtensa-allmodconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 4.9.0

reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=xtensa

All warnings (new ones prefixed by >>):

drivers/media/usb/dvb-usb-v2/af9035.c: In function 'ite9135_load_hid_tab':

>> drivers/media/usb/dvb-usb-v2/af9035.c:1955:1: warning: the frame size of 1936 bytes is larger than 1024 bytes [-Wframe-larger-than=]
    }
    ^

vim +1955 drivers/media/usb/dvb-usb-v2/af9035.c

1939 { 0x4b81, 0xeb },
1940 { 0x4b82, 0x45 },
1941 { 0x4b83, 0x03 },
1942 { 0x4b84, 0x00 },
1943 };
1944
1945 for (i = 0; i < ARRAY_SIZE(hid_tab); i++) {
1946 ret = af9035_wr_reg(d, hid_tab[i].reg, hid_tab[i].val);
1947 if (ret < 0)
1948 goto err;
1949 }
1950 dev_info(&intf->dev, "HID table successfully loaded\n");
1951 return 0;
1952 err:
1953 dev_info(&intf->dev, "loading HID table failed, item=%d, ret=%d\n", i, ret);
1954 return ret;

> 1955	}

1956
1957 static int af9035_init(struct dvb_usb_device *d)
1958 {
1959 struct state *state = d_to_priv(d);
1960 struct usb_interface *intf = d->intf;
1961 int ret, i;
1962 u16 frame_size = (d->udev->speed == USB_SPEED_FULL ? 5 : 87) * 188 / 4;
1963 u8 packet_size = (d->udev->speed == USB_SPEED_FULL ? 64 : 512) / 4;

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#2 lore raw
In reply to Antti Palosaari

----- Original Message -----

Quoted 31 lines

Hello

Jaroslav Škarvada kirjoitti 2017-06-09 20:46:

Quoted 4 lines

Automatically load sniffed HID table from Windows driver if USB_VID_ITETECH:USB_PID_ITETECH_IT9135_9006 device is present (e.g. Evolveo
Mars) or if module parameter force_hid_tab_load is set.

There is few issues I don't like this approach. Mostly that module parameter to select HID table. There is existing solution to select remote controller, it is ir-keytable and it should be used rather than defining device specific module parameter.

If you look that HID table you could see there is 4 bytes NEC code and 3 bytes HID code. Remote controller seems to have 34 keys. Remote controller address bytes are 0x02bd, grepping existing remote controller keytables it could be Total Media In Hand remote controller (rc-total-media-in-hand.c). If not, then defining new keytable is needed.

I did some research about issue and found 2 better solutions.
1) Configure HID table dynamically. Remote controller keytable has some needed information, but those KEY_* events needed to be translated to HID codes somehow.
2) Kill HID and then use CMD_IR_GET to get remote controller scancodes by polling.

Solution 1 sounds most correct. No need to poll and decode by sw as hw does all the job. But it is most hardest to implement, I am not aware if anyone has done it yet.

Quoted 7 lines

regards
Antti

--
http://palosaari.fi/

Hi,

thanks for info. General approach is usually better than device specific hacks, but it looks like longer run. Unfortunately I returned the device to the original owner, so I will be probably unable to help with it more. But the problem needs to be addressed, the state when the remote isn't working isn't good

thanks & regards

Jaroslav