Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7291e083 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou Committed by Andrea
Browse files

FROMLIST: Add Asus Gamepad descriptor fix

Asus Gamepad descriptor got broken by a recent kernel update. Fix it
here by overriding with a custom value.

(cherry-picked from https://www.spinics.net/lists/linux-input/msg63312.html

)

Bug: 140010996

Test: atest AsusGamepadTestCase
Signed-Off-By: default avatarSiarhei Vishniakou <svv@google.com>
Change-Id: I79bbb4a70c3b4be77397391de5e971a97d2ef831
(cherry picked from commit e123a917557177152b2fce6c55bf3524d1929f1e)
parent 0ea0782b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -134,6 +134,12 @@ config HID_APPLEIR

	Say Y here if you want support for Apple infrared remote control.

config HID_ASUS_GAMEPAD
	tristate "Asus Gamepad"
	depends on HID
	---help---
	Support for Asus Gamepad joystick.

config HID_AUREAL
	tristate "Aureal"
	depends on HID
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ obj-$(CONFIG_HID_A4TECH) += hid-a4tech.o
obj-$(CONFIG_HID_ACRUX)		+= hid-axff.o
obj-$(CONFIG_HID_APPLE)		+= hid-apple.o
obj-$(CONFIG_HID_APPLEIR)	+= hid-appleir.o
obj-$(CONFIG_HID_ASUS_GAMEPAD)	+= hid-asus-gamepad.o
obj-$(CONFIG_HID_AUREAL)	+= hid-aureal.o
obj-$(CONFIG_HID_BELKIN)	+= hid-belkin.o
obj-$(CONFIG_HID_BETOP_FF)	+= hid-betopff.o
+66 −0
Original line number Diff line number Diff line
/*
 *  HID driver for Asus Gamepad.
 *  Fix the descriptor due to tightening HID specifications.
 *  Copyright (c) 2019 Siarhei Vishniakou <svv@google.com>
 *
 *  Based on a patch contributed by JeiFeng Lee and Thunder Yu.
 */

/*
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 */

#include <linux/device.h>
#include <linux/hid.h>
#include <linux/module.h>

#include "hid-ids.h"

static __u8 GAMEPAD_DESCRIPTOR[] = {
	0x05, 0x01, 0x09, 0x05, 0xa1, 0x01, 0x85, 0x01, 0x05, 0x09, 0x0a,
	0x01, 0x00, 0x0a, 0x02, 0x00, 0x0a, 0x04, 0x00, 0x0a, 0x05, 0x00,
	0x0a, 0x07, 0x00, 0x0a, 0x08, 0x00, 0x0a, 0x0e, 0x00, 0x0a, 0x0f,
	0x00, 0x0a, 0x0d, 0x00, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95,
	0x09, 0x81, 0x02, 0x05, 0x0c, 0x0a, 0x24, 0x02, 0x0a, 0x23, 0x02,
	0x95, 0x02, 0x81, 0x02, 0x75, 0x01, 0x95, 0x01, 0x81, 0x03, 0x05,
	0x01, 0x75, 0x04, 0x95, 0x01, 0x25, 0x07, 0x46, 0x3b, 0x01, 0x66,
	0x14, 0x00, 0x09, 0x39, 0x81, 0x42, 0x66, 0x00, 0x00, 0x09, 0x01,
	0xa1, 0x00, 0x09, 0x30, 0x09, 0x31, 0x09, 0x32, 0x09, 0x35, 0x15,
	0x00, 0x26, 0xff, 0x00, 0x35, 0x00, 0x46, 0xff, 0x00, 0x75, 0x08,
	0x95, 0x04, 0x81, 0x02, 0x05, 0x02, 0x09, 0xc5, 0x09, 0xc4, 0x95,
	0x02, 0x81, 0x02, 0xc0, 0x85, 0x02, 0x05, 0x08, 0x0a, 0x01, 0x00,
	0x0a, 0x02, 0x00, 0x0a, 0x03, 0x00, 0x0a, 0x04, 0x00, 0x15, 0x00,
	0x25, 0x01, 0x75, 0x01, 0x95, 0x04, 0x91, 0x02, 0x75, 0x04, 0x95,
	0x01, 0x91, 0x03, 0xc0, 0x05, 0x0c, 0x09, 0x01, 0xa1, 0x01, 0x85,
	0x03, 0x05, 0x01, 0x09, 0x06, 0xa1, 0x02, 0x05, 0x06, 0x09, 0x20,
	0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x01, 0x81, 0x02,
	0x06, 0xbc, 0xff, 0x0a, 0xad, 0xbd, 0x75, 0x08, 0x95, 0x06, 0x81,
	0x02, 0xc0, 0xc0};

static __u8 *asus_gamepad_report_fixup(struct hid_device *hdev,
					__u8 *rdesc, unsigned int *rsize)
{
	if (hdev->product == USB_DEVICE_ID_ASUSTEK_GAMEPAD) {
		hid_info(hdev, "Fixing up Asus Gamepad report descriptor\n");
		*rsize = ARRAY_SIZE(GAMEPAD_DESCRIPTOR);
		return GAMEPAD_DESCRIPTOR;
	}
	return rdesc;
}

static const struct hid_device_id asus_devices[] = {
	{HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ASUSTEK,
					USB_DEVICE_ID_ASUSTEK_GAMEPAD)},
};
MODULE_DEVICE_TABLE(hid, asus_devices);

static struct hid_driver asus_driver = {
	.name = "asus-gamepad",
	.id_table = asus_devices,
	.report_fixup = asus_gamepad_report_fixup};
module_hid_driver(asus_driver);

MODULE_LICENSE("GPL");
+1 −0
Original line number Diff line number Diff line
@@ -1903,6 +1903,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS) },
	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_GAMEPAD) },
	{ HID_USB_DEVICE(USB_VENDOR_ID_AUREAL, USB_DEVICE_ID_AUREAL_W01RN) },
	{ HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
	{ HID_USB_DEVICE(USB_VENDOR_ID_BETOP_2185BFM, 0x2208) },
+1 −0
Original line number Diff line number Diff line
@@ -158,6 +158,7 @@
#define USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO	0x0186

#define USB_VENDOR_ID_ASUSTEK		0x0b05
#define USB_DEVICE_ID_ASUSTEK_GAMEPAD	0x4500
#define USB_DEVICE_ID_ASUSTEK_LCM	0x1726
#define USB_DEVICE_ID_ASUSTEK_LCM2	0x175b