* Re: [PATCH v3 RESEND RESEND 2/3] rust: core abstractions for HID drivers
From: Benjamin Tissoires @ 2025-09-17 10:04 UTC (permalink / raw)
To: Rahul Rameshbabu
Cc: linux-input, linux-kernel, rust-for-linux, Jiri Kosina,
a.hindborg, alex.gaynor, aliceryhl, benno.lossin,
Benjamin Tissoires, bjorn3_gh, boqun.feng, dakr, db48x, gary,
ojeda, tmgross, peter.hutterer
In-Reply-To: <20250913161222.3889-3-sergeantsagara@protonmail.com>
On Sep 13 2025, Rahul Rameshbabu wrote:
> These abstractions enable the development of HID drivers in Rust by binding
> with the HID core C API. They provide Rust types that map to the
> equivalents in C. In this initial draft, only hid_device and hid_device_id
> are provided direct Rust type equivalents. hid_driver is specially wrapped
> with a custom Driver type. The module_hid_driver! macro provides analogous
> functionality to its C equivalent. Only the .report_fixup callback is
> binded to Rust so far.
>
> Future work for these abstractions would include more bindings for common
> HID-related types, such as hid_field, hid_report_enum, and hid_report as
> well as more bus callbacks. Providing Rust equivalents to useful core HID
> functions will also be necessary for HID driver development in Rust.
>
> Signed-off-by: Rahul Rameshbabu <sergeantsagara@protonmail.com>
> ---
>
> Notes:
> Some points I did not address from the last review cycle:
>
> * I did not look into autogenerating all the getter functions for various
> fields exported from the binded C structures.
> - I would be interested in hearing opinions from folks actively involved
> with Rust for Linux on this topic.
>
> Changelog:
>
> v2->v3:
> * Implemented AlwaysRefCounted trait using embedded struct device's
> reference counts instead of the separate reference counter in struct
> hid_device
> * Used &raw mut as appropriate
> * Binded include/linux/device.h for get_device and put_device
> * Cleaned up various comment related formatting
> * Minified dev_err! format string
> * Updated Group enum to be repr(u16)
> * Implemented From<u16> trait for Group
> * Added TODO comment when const_trait_impl stabilizes
> * Made group getter functions return a Group variant instead of a raw
> number
> * Made sure example code builds
> v1->v2:
> * Binded drivers/hid/hid-ids.h for use in Rust drivers
> * Remove pre-emptive referencing of a C HID driver instance before
> it is fully initialized in the driver registration path
> * Moved static getters to generic Device trait implementation, so
> they can be used by all device::DeviceContext
> * Use core macros for supporting DeviceContext transitions
> * Implemented the AlwaysRefCounted and AsRef traits
> * Make use for dev_err! as appropriate
> RFC->v1:
> * Use Danilo's core infrastructure
> * Account for HID device groups
> * Remove probe and remove callbacks
> * Implement report_fixup support
> * Properly comment code including SAFETY comments
>
> MAINTAINERS | 9 +
> drivers/hid/Kconfig | 8 +
> rust/bindings/bindings_helper.h | 3 +
> rust/kernel/hid.rs | 503 ++++++++++++++++++++++++++++++++
> rust/kernel/lib.rs | 2 +
> 5 files changed, 525 insertions(+)
> create mode 100644 rust/kernel/hid.rs
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index dd810da5261b..6c60765f2aaa 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -10686,6 +10686,15 @@ F: include/uapi/linux/hid*
> F: samples/hid/
> F: tools/testing/selftests/hid/
>
> +HID CORE LAYER [RUST]
> +M: Rahul Rameshbabu <sergeantsagara@protonmail.com>
> +R: Benjamin Tissoires <bentiss@kernel.org>
> +L: linux-input@vger.kernel.org
> +S: Maintained
> +T: git git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid.git rust
FWIW, we (HID maintainers) are still undecided on how to handle that,
and so it's a little bit postponed for now
> +F: drivers/hid/*.rs
Could you instead make it really independant by relying on
drivers/hid/rust instead?
We already have drivers/hid/bpf for HID-BPF related stuff, so it doesn't
seem to be that much of an issue to have a separate rust dir.
This should allow for a cleaner separation without tinkering in Makefile
or Kconfig if the HID rust tree is handled separately.
Cheers,
Benjamin
> +F: rust/kernel/hid.rs
> +
> HID LOGITECH DRIVERS
> R: Filipe Laíns <lains@riseup.net>
> L: linux-input@vger.kernel.org
> diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
> index 43859fc75747..922e76e18af2 100644
> --- a/drivers/hid/Kconfig
> +++ b/drivers/hid/Kconfig
> @@ -744,6 +744,14 @@ config HID_MEGAWORLD_FF
> Say Y here if you have a Mega World based game controller and want
> to have force feedback support for it.
>
> +config RUST_HID_ABSTRACTIONS
> + bool "Rust HID abstractions support"
> + depends on RUST
> + depends on HID=y
> + help
> + Adds support needed for HID drivers written in Rust. It provides a
> + wrapper around the C hid core.
> +
> config HID_REDRAGON
> tristate "Redragon keyboards"
> default !EXPERT
> diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
> index 8cbb660e2ec2..7145fb1cdff1 100644
> --- a/rust/bindings/bindings_helper.h
> +++ b/rust/bindings/bindings_helper.h
> @@ -45,6 +45,7 @@
> #include <linux/cpufreq.h>
> #include <linux/cpumask.h>
> #include <linux/cred.h>
> +#include <linux/device.h>
> #include <linux/device/faux.h>
> #include <linux/dma-mapping.h>
> #include <linux/errname.h>
> @@ -52,6 +53,8 @@
> #include <linux/file.h>
> #include <linux/firmware.h>
> #include <linux/fs.h>
> +#include <linux/hid.h>
> +#include "../../drivers/hid/hid-ids.h"
> #include <linux/jiffies.h>
> #include <linux/jump_label.h>
> #include <linux/mdio.h>
> diff --git a/rust/kernel/hid.rs b/rust/kernel/hid.rs
> new file mode 100644
> index 000000000000..a93804af8b78
> --- /dev/null
> +++ b/rust/kernel/hid.rs
> @@ -0,0 +1,503 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +// Copyright (C) 2025 Rahul Rameshbabu <sergeantsagara@protonmail.com>
> +
> +//! Abstractions for the HID interface.
> +//!
> +//! C header: [`include/linux/hid.h`](srctree/include/linux/hid.h)
> +
> +use crate::{device, device_id::RawDeviceId, driver, error::*, prelude::*, types::Opaque};
> +use core::{
> + marker::PhantomData,
> + ptr::{addr_of_mut, NonNull},
> +};
> +
> +/// Indicates the item is static read-only.
> +///
> +/// Refer to [Device Class Definition for HID 1.11]
> +/// Section 6.2.2.5 Input, Output, and Feature Items.
> +///
> +/// [Device Class Definition for HID 1.11]: https://www.usb.org/sites/default/files/hid1_11.pdf
> +pub const MAIN_ITEM_CONSTANT: u8 = bindings::HID_MAIN_ITEM_CONSTANT as u8;
> +
> +/// Indicates the item represents data from a physical control.
> +///
> +/// Refer to [Device Class Definition for HID 1.11]
> +/// Section 6.2.2.5 Input, Output, and Feature Items.
> +///
> +/// [Device Class Definition for HID 1.11]: https://www.usb.org/sites/default/files/hid1_11.pdf
> +pub const MAIN_ITEM_VARIABLE: u8 = bindings::HID_MAIN_ITEM_VARIABLE as u8;
> +
> +/// Indicates the item should be treated as a relative change from the previous
> +/// report.
> +///
> +/// Refer to [Device Class Definition for HID 1.11]
> +/// Section 6.2.2.5 Input, Output, and Feature Items.
> +///
> +/// [Device Class Definition for HID 1.11]: https://www.usb.org/sites/default/files/hid1_11.pdf
> +pub const MAIN_ITEM_RELATIVE: u8 = bindings::HID_MAIN_ITEM_RELATIVE as u8;
> +
> +/// Indicates the item should wrap around when reaching the extreme high or
> +/// extreme low values.
> +///
> +/// Refer to [Device Class Definition for HID 1.11]
> +/// Section 6.2.2.5 Input, Output, and Feature Items.
> +///
> +/// [Device Class Definition for HID 1.11]: https://www.usb.org/sites/default/files/hid1_11.pdf
> +pub const MAIN_ITEM_WRAP: u8 = bindings::HID_MAIN_ITEM_WRAP as u8;
> +
> +/// Indicates the item should wrap around when reaching the extreme high or
> +/// extreme low values.
> +///
> +/// Refer to [Device Class Definition for HID 1.11]
> +/// Section 6.2.2.5 Input, Output, and Feature Items.
> +///
> +/// [Device Class Definition for HID 1.11]: https://www.usb.org/sites/default/files/hid1_11.pdf
> +pub const MAIN_ITEM_NONLINEAR: u8 = bindings::HID_MAIN_ITEM_NONLINEAR as u8;
> +
> +/// Indicates whether the control has a preferred state it will physically
> +/// return to without user intervention.
> +///
> +/// Refer to [Device Class Definition for HID 1.11]
> +/// Section 6.2.2.5 Input, Output, and Feature Items.
> +///
> +/// [Device Class Definition for HID 1.11]: https://www.usb.org/sites/default/files/hid1_11.pdf
> +pub const MAIN_ITEM_NO_PREFERRED: u8 = bindings::HID_MAIN_ITEM_NO_PREFERRED as u8;
> +
> +/// Indicates whether the control has a physical state where it will not send
> +/// any reports.
> +///
> +/// Refer to [Device Class Definition for HID 1.11]
> +/// Section 6.2.2.5 Input, Output, and Feature Items.
> +///
> +/// [Device Class Definition for HID 1.11]: https://www.usb.org/sites/default/files/hid1_11.pdf
> +pub const MAIN_ITEM_NULL_STATE: u8 = bindings::HID_MAIN_ITEM_NULL_STATE as u8;
> +
> +/// Indicates whether the control requires host system logic to change state.
> +///
> +/// Refer to [Device Class Definition for HID 1.11]
> +/// Section 6.2.2.5 Input, Output, and Feature Items.
> +///
> +/// [Device Class Definition for HID 1.11]: https://www.usb.org/sites/default/files/hid1_11.pdf
> +pub const MAIN_ITEM_VOLATILE: u8 = bindings::HID_MAIN_ITEM_VOLATILE as u8;
> +
> +/// Indicates whether the item is fixed size or a variable buffer of bytes.
> +///
> +/// Refer to [Device Class Definition for HID 1.11]
> +/// Section 6.2.2.5 Input, Output, and Feature Items.
> +///
> +/// [Device Class Definition for HID 1.11]: https://www.usb.org/sites/default/files/hid1_11.pdf
> +pub const MAIN_ITEM_BUFFERED_BYTE: u8 = bindings::HID_MAIN_ITEM_BUFFERED_BYTE as u8;
> +
> +/// HID device groups are intended to help categories HID devices based on a set
> +/// of common quirks and logic that they will require to function correctly.
> +#[repr(u16)]
> +pub enum Group {
> + /// Used to match a device against any group when probing.
> + Any = bindings::HID_GROUP_ANY as u16,
> +
> + /// Indicates a generic device that should need no custom logic from the
> + /// core HID stack.
> + Generic = bindings::HID_GROUP_GENERIC as u16,
> +
> + /// Maps multitouch devices to hid-multitouch instead of hid-generic.
> + Multitouch = bindings::HID_GROUP_MULTITOUCH as u16,
> +
> + /// Used for autodetecing and mapping of HID sensor hubs to
> + /// hid-sensor-hub.
> + SensorHub = bindings::HID_GROUP_SENSOR_HUB as u16,
> +
> + /// Used for autodetecing and mapping Win 8 multitouch devices to set the
> + /// needed quirks.
> + MultitouchWin8 = bindings::HID_GROUP_MULTITOUCH_WIN_8 as u16,
> +
> + // Vendor-specific device groups.
> + /// Used to distinguish Synpatics touchscreens from other products. The
> + /// touchscreens will be handled by hid-multitouch instead, while everything
> + /// else will be managed by hid-rmi.
> + RMI = bindings::HID_GROUP_RMI as u16,
> +
> + /// Used for hid-core handling to automatically identify Wacom devices and
> + /// have them probed by hid-wacom.
> + Wacom = bindings::HID_GROUP_WACOM as u16,
> +
> + /// Used by logitech-djreceiver and logitech-djdevice to autodetect if
> + /// devices paied to the DJ receivers are DJ devices and handle them with
> + /// the device driver.
> + LogitechDJDevice = bindings::HID_GROUP_LOGITECH_DJ_DEVICE as u16,
> +
> + /// Since the Valve Steam Controller only has vendor-specific usages,
> + /// prevent hid-generic from parsing its reports since there would be
> + /// nothing hid-generic could do for the device.
> + Steam = bindings::HID_GROUP_STEAM as u16,
> +
> + /// Used to differentiate 27 Mhz frequency Logitech DJ devices from other
> + /// Logitech DJ devices.
> + Logitech27MHzDevice = bindings::HID_GROUP_LOGITECH_27MHZ_DEVICE as u16,
> +
> + /// Used for autodetecting and mapping Vivaldi devices to hid-vivaldi.
> + Vivaldi = bindings::HID_GROUP_VIVALDI as u16,
> +}
> +
> +// TODO: use `const_trait_impl` once stabilized:
> +//
> +// ```
> +// impl const From<Group> for u16 {
> +// /// [`Group`] variants are represented by [`u16`] values.
> +// fn from(value: Group) -> Self {
> +// value as Self
> +// }
> +// }
> +// ```
> +impl Group {
> + /// Internal function used to convert [`Group`] variants into [`u16`].
> + const fn into(self) -> u16 {
> + self as u16
> + }
> +}
> +
> +impl From<u16> for Group {
> + /// [`u16`] values can be safely converted to [`Group`] variants.
> + fn from(value: u16) -> Self {
> + match value.into() {
> + bindings::HID_GROUP_GENERIC => Group::Generic,
> + bindings::HID_GROUP_MULTITOUCH => Group::Multitouch,
> + bindings::HID_GROUP_SENSOR_HUB => Group::SensorHub,
> + bindings::HID_GROUP_MULTITOUCH_WIN_8 => Group::MultitouchWin8,
> + bindings::HID_GROUP_RMI => Group::RMI,
> + bindings::HID_GROUP_WACOM => Group::Wacom,
> + bindings::HID_GROUP_LOGITECH_DJ_DEVICE => Group::LogitechDJDevice,
> + bindings::HID_GROUP_STEAM => Group::Steam,
> + bindings::HID_GROUP_LOGITECH_27MHZ_DEVICE => Group::Logitech27MHzDevice,
> + bindings::HID_GROUP_VIVALDI => Group::Vivaldi,
> + _ => Group::Any,
> + }
> + }
> +}
> +
> +/// The HID device representation.
> +///
> +/// This structure represents the Rust abstraction for a C `struct hid_device`.
> +/// The implementation abstracts the usage of an already existing C `struct
> +/// hid_device` within Rust code that we get passed from the C side.
> +///
> +/// # Invariants
> +///
> +/// A [`Device`] instance represents a valid `struct hid_device` created by the
> +/// C portion of the kernel.
> +#[repr(transparent)]
> +pub struct Device<Ctx: device::DeviceContext = device::Normal>(
> + Opaque<bindings::hid_device>,
> + PhantomData<Ctx>,
> +);
> +
> +impl<Ctx: device::DeviceContext> Device<Ctx> {
> + fn as_raw(&self) -> *mut bindings::hid_device {
> + self.0.get()
> + }
> +
> + /// Returns the HID transport bus ID.
> + pub fn bus(&self) -> u16 {
> + // SAFETY: `self.as_raw` is a valid pointer to a `struct hid_device`
> + unsafe { *self.as_raw() }.bus
> + }
> +
> + /// Returns the HID report group.
> + pub fn group(&self) -> Group {
> + // SAFETY: `self.as_raw` is a valid pointer to a `struct hid_device`
> + unsafe { *self.as_raw() }.group.into()
> + }
> +
> + /// Returns the HID vendor ID.
> + pub fn vendor(&self) -> u32 {
> + // SAFETY: `self.as_raw` is a valid pointer to a `struct hid_device`
> + unsafe { *self.as_raw() }.vendor
> + }
> +
> + /// Returns the HID product ID.
> + pub fn product(&self) -> u32 {
> + // SAFETY: `self.as_raw` is a valid pointer to a `struct hid_device`
> + unsafe { *self.as_raw() }.product
> + }
> +}
> +
> +// SAFETY: `Device` is a transparent wrapper of a type that doesn't depend on `Device`'s generic
> +// argument.
> +kernel::impl_device_context_deref!(unsafe { Device });
> +kernel::impl_device_context_into_aref!(Device);
> +
> +// SAFETY: Instances of `Device` are always reference-counted.
> +unsafe impl crate::types::AlwaysRefCounted for Device {
> + fn inc_ref(&self) {
> + // SAFETY: The existence of a shared reference guarantees that the refcount is non-zero.
> + unsafe { bindings::get_device(&raw mut (*self.as_raw()).dev) };
> + }
> +
> + unsafe fn dec_ref(obj: NonNull<Self>) {
> + // SAFETY: The safety requirements guarantee that the refcount is non-zero.
> + unsafe { bindings::put_device(&raw mut (*obj.cast::<bindings::hid_device>().as_ptr()).dev) }
> + }
> +}
> +
> +impl<Ctx: device::DeviceContext> AsRef<device::Device<Ctx>> for Device<Ctx> {
> + fn as_ref(&self) -> &device::Device<Ctx> {
> + // SAFETY: By the type invariant of `Self`, `self.as_raw()` is a pointer to a valid
> + // `struct hid_device`.
> + let dev = unsafe { addr_of_mut!((*self.as_raw()).dev) };
> +
> + // SAFETY: `dev` points to a valid `struct device`.
> + unsafe { device::Device::as_ref(dev) }
> + }
> +}
> +
> +/// Abstraction for the HID device ID structure `struct hid_device_id`.
> +#[repr(transparent)]
> +#[derive(Clone, Copy)]
> +pub struct DeviceId(bindings::hid_device_id);
> +
> +impl DeviceId {
> + /// Equivalent to C's `HID_USB_DEVICE` macro.
> + ///
> + /// Create a new `hid::DeviceId` from a group, vendor ID, and device ID
> + /// number.
> + pub const fn new_usb(group: Group, vendor: u32, product: u32) -> Self {
> + Self(bindings::hid_device_id {
> + bus: 0x3, // BUS_USB
> + group: group.into(),
> + vendor,
> + product,
> + driver_data: 0,
> + })
> + }
> +
> + /// Returns the HID transport bus ID.
> + pub fn bus(&self) -> u16 {
> + self.0.bus
> + }
> +
> + /// Returns the HID report group.
> + pub fn group(&self) -> Group {
> + self.0.group.into()
> + }
> +
> + /// Returns the HID vendor ID.
> + pub fn vendor(&self) -> u32 {
> + self.0.vendor
> + }
> +
> + /// Returns the HID product ID.
> + pub fn product(&self) -> u32 {
> + self.0.product
> + }
> +}
> +
> +// SAFETY:
> +// * `DeviceId` is a `#[repr(transparent)` wrapper of `hid_device_id` and does not add
> +// additional invariants, so it's safe to transmute to `RawType`.
> +// * `DRIVER_DATA_OFFSET` is the offset to the `driver_data` field.
> +unsafe impl RawDeviceId for DeviceId {
> + type RawType = bindings::hid_device_id;
> +
> + const DRIVER_DATA_OFFSET: usize = core::mem::offset_of!(bindings::hid_device_id, driver_data);
> +
> + fn index(&self) -> usize {
> + self.0.driver_data
> + }
> +}
> +
> +/// [`IdTable`] type for HID.
> +pub type IdTable<T> = &'static dyn kernel::device_id::IdTable<DeviceId, T>;
> +
> +/// Create a HID [`IdTable`] with its alias for modpost.
> +#[macro_export]
> +macro_rules! hid_device_table {
> + ($table_name:ident, $module_table_name:ident, $id_info_type: ty, $table_data: expr) => {
> + const $table_name: $crate::device_id::IdArray<
> + $crate::hid::DeviceId,
> + $id_info_type,
> + { $table_data.len() },
> + > = $crate::device_id::IdArray::new($table_data);
> +
> + $crate::module_device_table!("hid", $module_table_name, $table_name);
> + };
> +}
> +
> +/// The HID driver trait.
> +///
> +/// # Examples
> +///
> +/// ```
> +/// use kernel::{bindings, device, hid};
> +///
> +/// struct MyDriver;
> +///
> +/// kernel::hid_device_table!(
> +/// HID_TABLE,
> +/// MODULE_HID_TABLE,
> +/// <MyDriver as hid::Driver>::IdInfo,
> +/// [(
> +/// hid::DeviceId::new_usb(
> +/// hid::Group::Steam,
> +/// bindings::USB_VENDOR_ID_VALVE,
> +/// bindings::USB_DEVICE_ID_STEAM_DECK,
> +/// ),
> +/// (),
> +/// )]
> +/// );
> +///
> +/// #[vtable]
> +/// impl hid::Driver for MyDriver {
> +/// type IdInfo = ();
> +/// const ID_TABLE: hid::IdTable<Self::IdInfo> = &HID_TABLE;
> +///
> +/// /// This function is optional to implement.
> +/// fn report_fixup<'a, 'b: 'a>(_hdev: &hid::Device<device::Core>, rdesc: &'b mut [u8]) -> &'a [u8] {
> +/// // Perform some report descriptor fixup.
> +/// rdesc
> +/// }
> +/// }
> +/// ```
> +/// Drivers must implement this trait in order to get a HID driver registered.
> +/// Please refer to the `Adapter` documentation for an example.
> +#[vtable]
> +pub trait Driver: Send {
> + /// The type holding information about each device id supported by the driver.
> + // TODO: Use `associated_type_defaults` once stabilized:
> + //
> + // ```
> + // type IdInfo: 'static = ();
> + // ```
> + type IdInfo: 'static;
> +
> + /// The table of device ids supported by the driver.
> + const ID_TABLE: IdTable<Self::IdInfo>;
> +
> + /// Called before report descriptor parsing. Can be used to mutate the
> + /// report descriptor before the core HID logic processes the descriptor.
> + /// Useful for problematic report descriptors that prevent HID devices from
> + /// functioning correctly.
> + ///
> + /// Optional to implement.
> + fn report_fixup<'a, 'b: 'a>(_hdev: &Device<device::Core>, _rdesc: &'b mut [u8]) -> &'a [u8] {
> + build_error!(VTABLE_DEFAULT_ERROR)
> + }
> +}
> +
> +/// An adapter for the registration of HID drivers.
> +pub struct Adapter<T: Driver>(T);
> +
> +// SAFETY: A call to `unregister` for a given instance of `RegType` is guaranteed to be valid if
> +// a preceding call to `register` has been successful.
> +unsafe impl<T: Driver + 'static> driver::RegistrationOps for Adapter<T> {
> + type RegType = bindings::hid_driver;
> +
> + unsafe fn register(
> + hdrv: &Opaque<Self::RegType>,
> + name: &'static CStr,
> + module: &'static ThisModule,
> + ) -> Result {
> + // SAFETY: It's safe to set the fields of `struct hid_driver` on initialization.
> + unsafe {
> + (*hdrv.get()).name = name.as_char_ptr();
> + (*hdrv.get()).id_table = T::ID_TABLE.as_ptr();
> + (*hdrv.get()).report_fixup = if T::HAS_REPORT_FIXUP {
> + Some(Self::report_fixup_callback)
> + } else {
> + None
> + };
> + }
> +
> + // SAFETY: `hdrv` is guaranteed to be a valid `RegType`
> + to_result(unsafe {
> + bindings::__hid_register_driver(hdrv.get(), module.0, name.as_char_ptr())
> + })
> + }
> +
> + unsafe fn unregister(hdrv: &Opaque<Self::RegType>) {
> + // SAFETY: `hdrv` is guaranteed to be a valid `RegType`
> + unsafe { bindings::hid_unregister_driver(hdrv.get()) }
> + }
> +}
> +
> +impl<T: Driver + 'static> Adapter<T> {
> + extern "C" fn report_fixup_callback(
> + hdev: *mut bindings::hid_device,
> + buf: *mut u8,
> + size: *mut kernel::ffi::c_uint,
> + ) -> *const u8 {
> + // SAFETY: The HID subsystem only ever calls the report_fixup callback
> + // with a valid pointer to a `struct hid_device`.
> + //
> + // INVARIANT: `hdev` is valid for the duration of
> + // `report_fixup_callback()`.
> + let hdev = unsafe { &*hdev.cast::<Device<device::Core>>() };
> +
> + // SAFETY: The HID subsystem only ever calls the report_fixup callback
> + // with a valid pointer to a `kernel::ffi::c_uint`.
> + //
> + // INVARIANT: `size` is valid for the duration of
> + // `report_fixup_callback()`.
> + let buf_len: usize = match unsafe { *size }.try_into() {
> + Ok(len) => len,
> + Err(e) => {
> + dev_err!(
> + hdev.as_ref(),
> + "Cannot fix report description due to {}!\n",
> + e
> + );
> +
> + return buf;
> + }
> + };
> +
> + // Build a mutable Rust slice from `buf` and `size`.
> + //
> + // SAFETY: The HID subsystem only ever calls the `report_fixup callback`
> + // with a valid pointer to a `u8` buffer.
> + //
> + // INVARIANT: `buf` is valid for the duration of
> + // `report_fixup_callback()`.
> + let rdesc_slice = unsafe { core::slice::from_raw_parts_mut(buf, buf_len) };
> + let rdesc_slice = T::report_fixup(hdev, rdesc_slice);
> +
> + match rdesc_slice.len().try_into() {
> + // SAFETY: The HID subsystem only ever calls the report_fixup
> + // callback with a valid pointer to a `kernel::ffi::c_uint`.
> + //
> + // INVARIANT: `size` is valid for the duration of
> + // `report_fixup_callback()`.
> + Ok(len) => unsafe { *size = len },
> + Err(e) => {
> + dev_err!(
> + hdev.as_ref(),
> + "Fixed report description will not be used due to {}!\n",
> + e
> + );
> +
> + return buf;
> + }
> + }
> +
> + rdesc_slice.as_ptr()
> + }
> +}
> +
> +/// Declares a kernel module that exposes a single HID driver.
> +///
> +/// # Examples
> +///
> +/// ```ignore
> +/// kernel::module_hid_driver! {
> +/// type: MyDriver,
> +/// name: "Module name",
> +/// authors: ["Author name"],
> +/// description: "Description",
> +/// license: "GPL",
> +/// }
> +/// ```
> +#[macro_export]
> +macro_rules! module_hid_driver {
> + ($($f:tt)*) => {
> + $crate::module_driver!(<T>, $crate::hid::Adapter<T>, { $($f)* });
> + };
> +}
> diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
> index e88bc4b27d6e..44c107f20174 100644
> --- a/rust/kernel/lib.rs
> +++ b/rust/kernel/lib.rs
> @@ -80,6 +80,8 @@
> pub mod firmware;
> pub mod fmt;
> pub mod fs;
> +#[cfg(CONFIG_RUST_HID_ABSTRACTIONS)]
> +pub mod hid;
> pub mod init;
> pub mod io;
> pub mod ioctl;
> --
> 2.47.2
>
>
^ permalink raw reply
* Re: [PATCH v4 4/8] mfd: mc13xxx: Use devm_mfd_add_devices and devm_regmap_add_irq_chip
From: Lee Jones @ 2025-09-17 10:04 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Alexander Kurz, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Dzmitry Sankouski, Dr. David Alan Gilbert, Heiko Stuebner,
Uwe Kleine-König, devicetree, linux-input, linux-kernel
In-Reply-To: <fqhldiqylcsp6kp4tvhopxekgszabbemnvbseygkqaipgp5mhl@wtz6c7kjloko>
On Tue, 16 Sep 2025, Dmitry Torokhov wrote:
> Hi Alexander,
>
> On Sun, Sep 14, 2025 at 07:37:19PM +0000, Alexander Kurz wrote:
> > Use devm_mfd_add_devices() for adding MFD child devices and
> > devm_regmap_add_irq_chip() for IRQ chip registration.
> >
> > This reduces the amount of required cleanup.
> >
> > Signed-off-by: Alexander Kurz <akurz@blala.de>
> > ---
> > drivers/mfd/mc13xxx-core.c | 9 ++++-----
> > 1 file changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c
> > index 920797b806ce..091c9171b2b7 100644
> > --- a/drivers/mfd/mc13xxx-core.c
> > +++ b/drivers/mfd/mc13xxx-core.c
> > @@ -381,7 +381,7 @@ static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx,
> > if (!cell.name)
> > return -ENOMEM;
> >
> > - return mfd_add_devices(mc13xxx->dev, -1, &cell, 1, NULL, 0,
> > + return devm_mfd_add_devices(mc13xxx->dev, -1, &cell, 1, NULL, 0,
> > regmap_irq_get_domain(mc13xxx->irq_data));
> > }
> >
> > @@ -455,8 +455,9 @@ int mc13xxx_common_init(struct device *dev)
> > mc13xxx->irq_chip.irqs = mc13xxx->irqs;
> > mc13xxx->irq_chip.num_irqs = ARRAY_SIZE(mc13xxx->irqs);
> >
> > - ret = regmap_add_irq_chip(mc13xxx->regmap, mc13xxx->irq, IRQF_ONESHOT,
> > - 0, &mc13xxx->irq_chip, &mc13xxx->irq_data);
> > + ret = devm_regmap_add_irq_chip(dev, mc13xxx->regmap, mc13xxx->irq,
> > + IRQF_ONESHOT, 0, &mc13xxx->irq_chip,
> > + &mc13xxx->irq_data);
> > if (ret)
> > return ret;
> >
> > @@ -502,8 +503,6 @@ void mc13xxx_common_exit(struct device *dev)
> > {
> > struct mc13xxx *mc13xxx = dev_get_drvdata(dev);
> >
> > - mfd_remove_devices(dev);
> > - regmap_del_irq_chip(mc13xxx->irq, mc13xxx->irq_data);
> > mutex_destroy(&mc13xxx->lock);
>
> This causes the mutex be destroyed while the sub-devices are still
> present. The power button will try to call mc13xxx_lock() and
> mc13xxx_unlock() and of mutex debugging is enabled you'll get errors.
>
> I'd remove mutex_destroy() as well (and transitively get rid of
> mc13xxx_common_exit()) and then look into getting rid of mc13xxx_lock()
> and mc13xxx_unlock() because, as I mentioned in another email, they are
> IMO not needed.
>
> But this version of the patch is broken as far as I can tell.
Thanks for the input Dmitry.
I have removed the patch until this gets resolved.
--
Lee Jones [李琼斯]
^ permalink raw reply
* Re: [PATCH v3 RESEND RESEND 1/3] HID: core: Change hid_driver to use a const char* for name
From: Benjamin Tissoires @ 2025-09-17 9:51 UTC (permalink / raw)
To: Rahul Rameshbabu
Cc: linux-input, linux-kernel, rust-for-linux, Jiri Kosina,
a.hindborg, alex.gaynor, aliceryhl, benno.lossin,
Benjamin Tissoires, bjorn3_gh, boqun.feng, dakr, db48x, gary,
ojeda, tmgross, peter.hutterer
In-Reply-To: <20250913161222.3889-2-sergeantsagara@protonmail.com>
On Sep 13 2025, Rahul Rameshbabu wrote:
> name is never mutated by the core HID stack. Making name a const char*
> simplifies passing the string from Rust to C. Otherwise, it becomes
> difficult to pass a 'static lifetime CStr from Rust to a char*, rather than
> a const char*, due to lack of guarantee that the underlying data of the
> CStr will not be mutated by the C code.
>
> Signed-off-by: Rahul Rameshbabu <sergeantsagara@protonmail.com>
While we figure out the rest, I'm queueing this one patch in my test
setup and will probably merge it for 6.18. This way, the rest of the
series is purely rust and doesn't depend on anything on the HID tree.
Cheers,
Benjamin
> ---
> include/linux/hid.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/hid.h b/include/linux/hid.h
> index 568a9d8c749b..d65c202783da 100644
> --- a/include/linux/hid.h
> +++ b/include/linux/hid.h
> @@ -816,7 +816,7 @@ struct hid_usage_id {
> * zero from them.
> */
> struct hid_driver {
> - char *name;
> + const char *name;
> const struct hid_device_id *id_table;
>
> struct list_head dyn_list;
> --
> 2.47.2
>
>
^ permalink raw reply
* Re: [PATCH v3 0/3] HID: hidraw: rework ioctls
From: Jiri Kosina @ 2025-09-17 9:38 UTC (permalink / raw)
To: Benjamin Tissoires
Cc: Shuah Khan, Arnd Bergmann, linux-input, linux-kselftest,
linux-kernel, Arnd Bergmann
In-Reply-To: <20250912-b4-hidraw-ioctls-v3-0-cd2c6efd8c20@kernel.org>
On Fri, 12 Sep 2025, Benjamin Tissoires wrote:
> Arnd sent the v1 of the series in July, and it was bogus. So with a
> little help from claude-sonnet I built up the missing ioctls tests and
> tried to figure out a way to apply Arnd's logic without breaking the
> existing ioctls.
>
> The end result is in patch 3/3, which makes use of subfunctions to keep
> the main ioctl code path clean.
>
> Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
> ---
> Changes in v3:
> - dropped the co-developed-by tag and put a blurb instead
> - change the attribution of patch 3/3 to me as requested by Arnd.
> - Link to v2: https://lore.kernel.org/r/20250826-b4-hidraw-ioctls-v2-0-c7726b236719@kernel.org
>
> changes in v2:
> - add new hidraw ioctls tests
> - refactor Arnd's patch to keep the existing error path logic
> - link to v1: https://lore.kernel.org/linux-input/20250711072847.2836962-1-arnd@kernel.org/
Now queued in hid.git#for-6.18/hidraw, thanks a lot Arnd and Benjamin!
--
Jiri Kosina
SUSE Labs
^ permalink raw reply
* Re: [PATCH] selftests/hid: update vmtest.sh for virtme-ng
From: Jiri Kosina @ 2025-09-17 9:36 UTC (permalink / raw)
To: Benjamin Tissoires; +Cc: Shuah Khan, linux-input, linux-kselftest, linux-kernel
In-Reply-To: <20250821-virtme-ng-v1-1-0e6359872bf3@kernel.org>
On Thu, 21 Aug 2025, Benjamin Tissoires wrote:
> This commit is a rewrite almost from scratch of vmtest.sh.
>
> By relying on virtme-ng, we get rid of boot2container, reducing the
> total bootup time (and network requirements). That means that we are
> relying on the programs being installed on the host, but that shouldn't
> be an issue. The generation of the kconfig is also now handled by
> virtme-ng, so that's one less thing to worry.
>
> I used tools/testing/selftests/vsock/vmtest.sh as a base and modified it
> to look mostly like my previous script:
> - removed the custom ssh handling
> - make use of vng for compiling, which allows to bring remote
> compilation (and potentially remote compilation on a remote container)
> - change the verbosity logic by having 2 levels:
> - first one shows the tests outputs
> - second level also shows the VM logs
> - instead of only running the compiled kernel when it is built, if we
> are in the kernel tree, use the kernel artifacts there (and complain
> if they are not built)
> - adapted the tests list to match the HID subsystem tests
>
> Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
> ---
> I have switched my workflow to make use of virtme-ng for a few months.
> Now it's time to automate the manual commands I've been running in
> vmtest.sh.
> ---
> tools/testing/selftests/hid/vmtest.sh | 668 +++++++++++++++++++++-------------
> 1 file changed, 423 insertions(+), 245 deletions(-)
Applied to hid.git#for-6.18/selftests, thanks Benjamin.
--
Jiri Kosina
SUSE Labs
^ permalink raw reply
* Re: [PATCH v2 00/11] HID: playstation: Add support for audio jack handling on DualSense
From: Jiri Kosina @ 2025-09-17 9:34 UTC (permalink / raw)
To: Cristian Ciocaltea
Cc: Roderick Colenbrander, Benjamin Tissoires, Henrik Rydberg, kernel,
linux-input, linux-kernel
In-Reply-To: <20250625-dualsense-hid-jack-v2-0-596c0db14128@collabora.com>
On Wed, 25 Jun 2025, Cristian Ciocaltea wrote:
> The Sony DualSense wireless controller (PS5) provides an internal mono
> speaker, in addition to the 3.5mm jack socket for headphone output and
> headset microphone input. However, the default audio output path is set
> to headphones, regardless of whether they are actually inserted or not.
>
> This patch series aims to improve the audio support when operating in
> USB mode, by implementing the following changes:
>
> * Detect when the plugged state of the audio jack changes and toggle
> audio output between headphones and internal speaker, as required.
> The latter is achieved by essentially routing the right channel of the
> audio source to the mono speaker.
>
> * Adjust the speaker volume since its default level is too low and,
> therefore, cannot generate any audible sound.
>
> * Register a dedicated input device for the audio jack and use it to
> report all headphone and headset mic insert events.
>
> It's worth noting the latter is necessary since the controller complies
> with v1.0 of the USB Audio Class spec (UAC1) and, therefore, cannot
> advertise any jack detection capability.
>
> However, this feature can be implemented in the generic USB audio driver
> via quirks, i.e. by configuring an input handler to receive hotplug
> events from the HID driver. That's exactly what has been accomplished
> via the "ALSA: usb-audio: Support jack detection on Sony DualSense"
> patchset [1], which has been already merged and should be available in
> v6.17.
>
> Unrelated to the above, also provide a few driver cleanup patches, e.g.
> make use of bitfields macros, simplify locking, fix coding style.
>
> [1] https://lore.kernel.org/all/20250526-dualsense-alsa-jack-v1-0-1a821463b632@collabora.com/
>
> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
> ---
> Changes in v2:
> - Updated cover letter including a reference to the usb-audio patch series
> - Updated 'HID: playstation: Make use of bitfield macros' patch to drop
> DS_STATUS_CHARGING_SHIFT and use FIELD_GET() for battery status ops
> - Replaced 'HID: playstation: Rename DualSense input report status
> field' with 'HID: playstation: Redefine DualSense input report status
> field' changing data type to a 3-byte array instead of renaming the
> struct member (Roderick)
> - Updated 'HID: playstation: Support DualSense audio jack hotplug
> detection' according to Roderick's feedback:
> * Used DS_STATUS1_ prefixes for the plugged status register and rename
> its bits to match the datasheet
> * Defined MIC_VOLUME_ENABLE bit of DS_OUTPUT_VALID_FLAG0 register
> * Renamed the newly introduced audio controls members in struct
> dualsense_output_report_common: headphone_volume, speaker_volume,
> mic_volume, audio_control, audio_control2
> - Restricted audio jack hotplug detection and event reporting to USB
> operation mode only, since Bluetooth audio is currently not supported
> and it might have a negative impact on the battery life (Roderick)
> - Rebased series onto next-20250624
> - Link to v1: https://lore.kernel.org/r/20250526-dualsense-hid-jack-v1-0-a65fee4a60cc@collabora.com
This is now queued in hid.git#for-6.18/playstation. Thanks,
--
Jiri Kosina
SUSE Labs
^ permalink raw reply
* [PATCH v4 3/6] dt-bindings: touchscreen: add touchscreen-glitch-threshold-ns property
From: Dario Binacchi @ 2025-09-17 8:05 UTC (permalink / raw)
To: linux-kernel
Cc: linux-amarula, Frank Li, Dario Binacchi, Conor Dooley,
Dmitry Torokhov, Javier Carrasco, Jeff LaBundy,
Krzysztof Kozlowski, Rob Herring, devicetree, linux-input
In-Reply-To: <20250917080534.1772202-1-dario.binacchi@amarulasolutions.com>
Add support for glitch threshold configuration. A detected signal is valid
only if it lasts longer than the set threshold; otherwise, it is regarded
as a glitch.
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
(no changes since v2)
Changes in v2:
- Added in v2.
.../devicetree/bindings/input/touchscreen/touchscreen.yaml | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml b/Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml
index 3e3572aa483a..a60b4d08620d 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml
@@ -206,6 +206,10 @@ properties:
unevaluatedProperties: false
+ touchscreen-glitch-threshold-ns:
+ description: Minimum duration in nanoseconds a signal must remain stable
+ to be considered valid.
+
dependencies:
touchscreen-size-x: [ touchscreen-size-y ]
touchscreen-size-y: [ touchscreen-size-x ]
--
2.43.0
^ permalink raw reply related
* [PATCH v4 6/6] Input: imx6ul_tsc - set glitch threshold by DTS property
From: Dario Binacchi @ 2025-09-17 8:05 UTC (permalink / raw)
To: linux-kernel
Cc: linux-amarula, Frank Li, Dario Binacchi, Dmitry Torokhov,
Fabio Estevam, Michael Trimarchi, Pengutronix Kernel Team,
Sascha Hauer, Shawn Guo, imx, linux-arm-kernel, linux-input
In-Reply-To: <20250917080534.1772202-1-dario.binacchi@amarulasolutions.com>
Set the glitch threshold previously hardcoded in the driver. The change
is backward compatible.
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
Changes in v4:
- Adjust property description fsl,imx6ul-tsc.yaml following the
suggestions of Conor Dooley and Frank Li.
Changes in v3:
- Remove the final part of the description that refers to
implementation details in fsl,imx6ul-tsc.yaml.
Changes in v2:
- Replace patch ("dt-bindings: input: touchscreen: fsl,imx6ul-tsc: add
fsl,glitch-threshold") with ("dt-bindings: touchscreen: add
touchscreen-glitch-threshold-ns property"), making the previous property
general by moving it to touchscreen.yaml.
- Rework "Input: imx6ul_tsc - set glitch threshold by DTS property" patch
to match changes made to the DTS property.
- Move "Input: imx6ul_tsc - use BIT, FIELD_{GET,PREP} and GENMASK macros"
patch right after the patch fixing the typo.
- Rework to match changes made to the DTS property.
drivers/input/touchscreen/imx6ul_tsc.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/drivers/input/touchscreen/imx6ul_tsc.c b/drivers/input/touchscreen/imx6ul_tsc.c
index e2c59cc7c82c..0d753aa05fbf 100644
--- a/drivers/input/touchscreen/imx6ul_tsc.c
+++ b/drivers/input/touchscreen/imx6ul_tsc.c
@@ -79,7 +79,7 @@
#define MEASURE_SIG_EN BIT(0)
#define VALID_SIG_EN BIT(8)
#define DE_GLITCH_MASK GENMASK(30, 29)
-#define DE_GLITCH_2 0x02
+#define DE_GLITCH_DEF 0x02
#define START_SENSE BIT(12)
#define TSC_DISABLE BIT(16)
#define DETECT_MODE 0x2
@@ -98,6 +98,7 @@ struct imx6ul_tsc {
u32 pre_charge_time;
bool average_enable;
u32 average_select;
+ u32 de_glitch;
struct completion completion;
};
@@ -205,7 +206,7 @@ static void imx6ul_tsc_set(struct imx6ul_tsc *tsc)
basic_setting |= AUTO_MEASURE;
writel(basic_setting, tsc->tsc_regs + REG_TSC_BASIC_SETTING);
- debug_mode2 = FIELD_PREP(DE_GLITCH_MASK, DE_GLITCH_2);
+ debug_mode2 = FIELD_PREP(DE_GLITCH_MASK, tsc->de_glitch);
writel(debug_mode2, tsc->tsc_regs + REG_TSC_DEBUG_MODE2);
writel(tsc->pre_charge_time, tsc->tsc_regs + REG_TSC_PRE_CHARGE_TIME);
@@ -391,6 +392,7 @@ static int imx6ul_tsc_probe(struct platform_device *pdev)
int tsc_irq;
int adc_irq;
u32 average_samples;
+ u32 de_glitch;
tsc = devm_kzalloc(&pdev->dev, sizeof(*tsc), GFP_KERNEL);
if (!tsc)
@@ -513,6 +515,26 @@ static int imx6ul_tsc_probe(struct platform_device *pdev)
return -EINVAL;
}
+ err = of_property_read_u32(np, "touchscreen-glitch-threshold-ns",
+ &de_glitch);
+ if (err) {
+ tsc->de_glitch = DE_GLITCH_DEF;
+ } else {
+ u64 cycles;
+ unsigned long rate = clk_get_rate(tsc->tsc_clk);
+
+ cycles = DIV64_U64_ROUND_UP((u64)de_glitch * rate, NSEC_PER_SEC);
+
+ if (cycles <= 0x3ff)
+ tsc->de_glitch = 3;
+ else if (cycles <= 0x7ff)
+ tsc->de_glitch = 2;
+ else if (cycles <= 0xfff)
+ tsc->de_glitch = 1;
+ else
+ tsc->de_glitch = 0;
+ }
+
err = input_register_device(tsc->input);
if (err) {
dev_err(&pdev->dev,
--
2.43.0
^ permalink raw reply related
* [PATCH v4 4/6] dt-bindings: touchscreen: fsl,imx6ul-tsc: support glitch thresold
From: Dario Binacchi @ 2025-09-17 8:05 UTC (permalink / raw)
To: linux-kernel
Cc: linux-amarula, Frank Li, Dario Binacchi, Conor Dooley,
Dmitry Torokhov, Fabio Estevam, Haibo Chen, Krzysztof Kozlowski,
Pengutronix Kernel Team, Rob Herring, Sascha Hauer, Shawn Guo,
devicetree, imx, linux-arm-kernel, linux-input
In-Reply-To: <20250917080534.1772202-1-dario.binacchi@amarulasolutions.com>
Support the touchscreen-glitch-threshold-ns property.
Drivers must convert this value to IPG clock cycles and map it to one of
the four discrete thresholds exposed by the TSC_DEBUG_MODE2 register:
0: 8191 IPG cycles
1: 4095 IPG cycles
2: 2047 IPG cycles
3: 1023 IPG cycles
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
Changes in v4:
- Adjust property description following the suggestions of
Conor Dooley and Frank Li.
- Update the commit description.
Changes in v3:
- Remove the final part of the description that refers to
implementation details.
.../bindings/input/touchscreen/fsl,imx6ul-tsc.yaml | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/Documentation/devicetree/bindings/input/touchscreen/fsl,imx6ul-tsc.yaml b/Documentation/devicetree/bindings/input/touchscreen/fsl,imx6ul-tsc.yaml
index 678756ad0f92..1975f741cf3d 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/fsl,imx6ul-tsc.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/fsl,imx6ul-tsc.yaml
@@ -62,6 +62,20 @@ properties:
description: Number of data samples which are averaged for each read.
enum: [ 1, 4, 8, 16, 32 ]
+ touchscreen-glitch-threshold-ns:
+ description: |
+ Minimum duration in nanoseconds a signal must remain stable
+ to be considered valid.
+
+ Drivers must convert this value to IPG clock cycles and map
+ it to one of the four discrete thresholds exposed by the
+ TSC_DEBUG_MODE2 register:
+
+ 0: 8191 IPG cycles
+ 1: 4095 IPG cycles
+ 2: 2047 IPG cycles
+ 3: 1023 IPG cycles
+
required:
- compatible
- reg
--
2.43.0
^ permalink raw reply related
* [PATCH v4 2/6] Input: imx6ul_tsc - use BIT, FIELD_{GET,PREP} and GENMASK macros
From: Dario Binacchi @ 2025-09-17 8:05 UTC (permalink / raw)
To: linux-kernel
Cc: linux-amarula, Frank Li, Dario Binacchi, Dmitry Torokhov,
Fabio Estevam, Michael Trimarchi, Pengutronix Kernel Team,
Sascha Hauer, Shawn Guo, imx, linux-arm-kernel, linux-input
In-Reply-To: <20250917080534.1772202-1-dario.binacchi@amarulasolutions.com>
Replace opencoded masking and shifting, with BIT(), GENMASK(),
FIELD_GET() and FIELD_PREP() macros.
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
---
(no changes since v2)
Changes in v2:
- Add Reviewed-by tag of Frank Li.
- Move the patch right after the one fixing the typo according
to Frank Li's suggestions.
drivers/input/touchscreen/imx6ul_tsc.c | 96 +++++++++++++++-----------
1 file changed, 54 insertions(+), 42 deletions(-)
diff --git a/drivers/input/touchscreen/imx6ul_tsc.c b/drivers/input/touchscreen/imx6ul_tsc.c
index c2c6e50efc54..e2c59cc7c82c 100644
--- a/drivers/input/touchscreen/imx6ul_tsc.c
+++ b/drivers/input/touchscreen/imx6ul_tsc.c
@@ -7,6 +7,7 @@
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/bitfield.h>
#include <linux/gpio/consumer.h>
#include <linux/input.h>
#include <linux/slab.h>
@@ -20,25 +21,23 @@
#include <linux/log2.h>
/* ADC configuration registers field define */
-#define ADC_AIEN (0x1 << 7)
+#define ADC_AIEN BIT(7)
+#define ADC_ADCH_MASK GENMASK(4, 0)
#define ADC_CONV_DISABLE 0x1F
-#define ADC_AVGE (0x1 << 5)
-#define ADC_CAL (0x1 << 7)
-#define ADC_CALF 0x2
-#define ADC_12BIT_MODE (0x2 << 2)
-#define ADC_CONV_MODE_MASK (0x3 << 2)
+#define ADC_AVGE BIT(5)
+#define ADC_CAL BIT(7)
+#define ADC_CALF BIT(1)
+#define ADC_CONV_MODE_MASK GENMASK(3, 2)
+#define ADC_12BIT_MODE 0x2
#define ADC_IPG_CLK 0x00
-#define ADC_INPUT_CLK_MASK 0x3
-#define ADC_CLK_DIV_8 (0x03 << 5)
-#define ADC_CLK_DIV_MASK (0x3 << 5)
-#define ADC_SHORT_SAMPLE_MODE (0x0 << 4)
-#define ADC_SAMPLE_MODE_MASK (0x1 << 4)
-#define ADC_HARDWARE_TRIGGER (0x1 << 13)
-#define ADC_AVGS_SHIFT 14
-#define ADC_AVGS_MASK (0x3 << 14)
+#define ADC_INPUT_CLK_MASK GENMASK(1, 0)
+#define ADC_CLK_DIV_8 0x03
+#define ADC_CLK_DIV_MASK GENMASK(6, 5)
+#define ADC_SAMPLE_MODE BIT(4)
+#define ADC_HARDWARE_TRIGGER BIT(13)
+#define ADC_AVGS_MASK GENMASK(15, 14)
#define SELECT_CHANNEL_4 0x04
#define SELECT_CHANNEL_1 0x01
-#define DISABLE_CONVERSION_INT (0x0 << 7)
/* ADC registers */
#define REG_ADC_HC0 0x00
@@ -65,19 +64,26 @@
#define REG_TSC_DEBUG_MODE 0x70
#define REG_TSC_DEBUG_MODE2 0x80
+/* TSC_MEASURE_VALUE register field define */
+#define X_VALUE_MASK GENMASK(27, 16)
+#define Y_VALUE_MASK GENMASK(11, 0)
+
/* TSC configuration registers field define */
-#define DETECT_4_WIRE_MODE (0x0 << 4)
-#define AUTO_MEASURE 0x1
-#define MEASURE_SIGNAL 0x1
-#define DETECT_SIGNAL (0x1 << 4)
-#define VALID_SIGNAL (0x1 << 8)
-#define MEASURE_INT_EN 0x1
-#define MEASURE_SIG_EN 0x1
-#define VALID_SIG_EN (0x1 << 8)
-#define DE_GLITCH_2 (0x2 << 29)
-#define START_SENSE (0x1 << 12)
-#define TSC_DISABLE (0x1 << 16)
+#define MEASURE_DELAY_TIME_MASK GENMASK(31, 8)
+#define DETECT_5_WIRE_MODE BIT(4)
+#define AUTO_MEASURE BIT(0)
+#define MEASURE_SIGNAL BIT(0)
+#define DETECT_SIGNAL BIT(4)
+#define VALID_SIGNAL BIT(8)
+#define MEASURE_INT_EN BIT(0)
+#define MEASURE_SIG_EN BIT(0)
+#define VALID_SIG_EN BIT(8)
+#define DE_GLITCH_MASK GENMASK(30, 29)
+#define DE_GLITCH_2 0x02
+#define START_SENSE BIT(12)
+#define TSC_DISABLE BIT(16)
#define DETECT_MODE 0x2
+#define STATE_MACHINE_MASK GENMASK(22, 20)
struct imx6ul_tsc {
struct device *dev;
@@ -112,19 +118,20 @@ static int imx6ul_adc_init(struct imx6ul_tsc *tsc)
adc_cfg = readl(tsc->adc_regs + REG_ADC_CFG);
adc_cfg &= ~(ADC_CONV_MODE_MASK | ADC_INPUT_CLK_MASK);
- adc_cfg |= ADC_12BIT_MODE | ADC_IPG_CLK;
- adc_cfg &= ~(ADC_CLK_DIV_MASK | ADC_SAMPLE_MODE_MASK);
- adc_cfg |= ADC_CLK_DIV_8 | ADC_SHORT_SAMPLE_MODE;
+ adc_cfg |= FIELD_PREP(ADC_CONV_MODE_MASK, ADC_12BIT_MODE) |
+ FIELD_PREP(ADC_INPUT_CLK_MASK, ADC_IPG_CLK);
+ adc_cfg &= ~(ADC_CLK_DIV_MASK | ADC_SAMPLE_MODE);
+ adc_cfg |= FIELD_PREP(ADC_CLK_DIV_MASK, ADC_CLK_DIV_8);
if (tsc->average_enable) {
adc_cfg &= ~ADC_AVGS_MASK;
- adc_cfg |= (tsc->average_select) << ADC_AVGS_SHIFT;
+ adc_cfg |= FIELD_PREP(ADC_AVGS_MASK, tsc->average_select);
}
adc_cfg &= ~ADC_HARDWARE_TRIGGER;
writel(adc_cfg, tsc->adc_regs + REG_ADC_CFG);
/* enable calibration interrupt */
adc_hc |= ADC_AIEN;
- adc_hc |= ADC_CONV_DISABLE;
+ adc_hc |= FIELD_PREP(ADC_ADCH_MASK, ADC_CONV_DISABLE);
writel(adc_hc, tsc->adc_regs + REG_ADC_HC0);
/* start ADC calibration */
@@ -164,19 +171,21 @@ static void imx6ul_tsc_channel_config(struct imx6ul_tsc *tsc)
{
u32 adc_hc0, adc_hc1, adc_hc2, adc_hc3, adc_hc4;
- adc_hc0 = DISABLE_CONVERSION_INT;
+ adc_hc0 = FIELD_PREP(ADC_AIEN, 0);
writel(adc_hc0, tsc->adc_regs + REG_ADC_HC0);
- adc_hc1 = DISABLE_CONVERSION_INT | SELECT_CHANNEL_4;
+ adc_hc1 = FIELD_PREP(ADC_AIEN, 0) |
+ FIELD_PREP(ADC_ADCH_MASK, SELECT_CHANNEL_4);
writel(adc_hc1, tsc->adc_regs + REG_ADC_HC1);
- adc_hc2 = DISABLE_CONVERSION_INT;
+ adc_hc2 = FIELD_PREP(ADC_AIEN, 0);
writel(adc_hc2, tsc->adc_regs + REG_ADC_HC2);
- adc_hc3 = DISABLE_CONVERSION_INT | SELECT_CHANNEL_1;
+ adc_hc3 = FIELD_PREP(ADC_AIEN, 0) |
+ FIELD_PREP(ADC_ADCH_MASK, SELECT_CHANNEL_1);
writel(adc_hc3, tsc->adc_regs + REG_ADC_HC3);
- adc_hc4 = DISABLE_CONVERSION_INT;
+ adc_hc4 = FIELD_PREP(ADC_AIEN, 0);
writel(adc_hc4, tsc->adc_regs + REG_ADC_HC4);
}
@@ -188,13 +197,16 @@ static void imx6ul_tsc_channel_config(struct imx6ul_tsc *tsc)
static void imx6ul_tsc_set(struct imx6ul_tsc *tsc)
{
u32 basic_setting = 0;
+ u32 debug_mode2;
u32 start;
- basic_setting |= tsc->measure_delay_time << 8;
- basic_setting |= DETECT_4_WIRE_MODE | AUTO_MEASURE;
+ basic_setting |= FIELD_PREP(MEASURE_DELAY_TIME_MASK,
+ tsc->measure_delay_time);
+ basic_setting |= AUTO_MEASURE;
writel(basic_setting, tsc->tsc_regs + REG_TSC_BASIC_SETTING);
- writel(DE_GLITCH_2, tsc->tsc_regs + REG_TSC_DEBUG_MODE2);
+ debug_mode2 = FIELD_PREP(DE_GLITCH_MASK, DE_GLITCH_2);
+ writel(debug_mode2, tsc->tsc_regs + REG_TSC_DEBUG_MODE2);
writel(tsc->pre_charge_time, tsc->tsc_regs + REG_TSC_PRE_CHARGE_TIME);
writel(MEASURE_INT_EN, tsc->tsc_regs + REG_TSC_INT_EN);
@@ -250,7 +262,7 @@ static bool tsc_wait_detect_mode(struct imx6ul_tsc *tsc)
usleep_range(200, 400);
debug_mode2 = readl(tsc->tsc_regs + REG_TSC_DEBUG_MODE2);
- state_machine = (debug_mode2 >> 20) & 0x7;
+ state_machine = FIELD_GET(STATE_MACHINE_MASK, debug_mode2);
} while (state_machine != DETECT_MODE);
usleep_range(200, 400);
@@ -278,8 +290,8 @@ static irqreturn_t tsc_irq_fn(int irq, void *dev_id)
if (status & MEASURE_SIGNAL) {
value = readl(tsc->tsc_regs + REG_TSC_MEASURE_VALUE);
- x = (value >> 16) & 0x0fff;
- y = value & 0x0fff;
+ x = FIELD_GET(X_VALUE_MASK, value);
+ y = FIELD_GET(Y_VALUE_MASK, value);
/*
* In detect mode, we can get the xnur gpio value,
--
2.43.0
^ permalink raw reply related
* [PATCH v4 1/6] Input: imx6ul_tsc - fix typo in register name
From: Dario Binacchi @ 2025-09-17 8:05 UTC (permalink / raw)
To: linux-kernel
Cc: linux-amarula, Frank Li, Michael Trimarchi, Dario Binacchi,
Dmitry Torokhov, Fabio Estevam, Pengutronix Kernel Team,
Sascha Hauer, Shawn Guo, imx, linux-arm-kernel, linux-input
In-Reply-To: <20250917080534.1772202-1-dario.binacchi@amarulasolutions.com>
From: Michael Trimarchi <michael@amarulasolutions.com>
Replace 'SETING' with 'SETTING'.
Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
---
(no changes since v2)
Changes in v2:
- Add Reviewed-by tag of Frank Li.
drivers/input/touchscreen/imx6ul_tsc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/input/touchscreen/imx6ul_tsc.c b/drivers/input/touchscreen/imx6ul_tsc.c
index 6ac8fa84ed9f..c2c6e50efc54 100644
--- a/drivers/input/touchscreen/imx6ul_tsc.c
+++ b/drivers/input/touchscreen/imx6ul_tsc.c
@@ -55,7 +55,7 @@
#define ADC_TIMEOUT msecs_to_jiffies(100)
/* TSC registers */
-#define REG_TSC_BASIC_SETING 0x00
+#define REG_TSC_BASIC_SETTING 0x00
#define REG_TSC_PRE_CHARGE_TIME 0x10
#define REG_TSC_FLOW_CONTROL 0x20
#define REG_TSC_MEASURE_VALUE 0x30
@@ -192,7 +192,7 @@ static void imx6ul_tsc_set(struct imx6ul_tsc *tsc)
basic_setting |= tsc->measure_delay_time << 8;
basic_setting |= DETECT_4_WIRE_MODE | AUTO_MEASURE;
- writel(basic_setting, tsc->tsc_regs + REG_TSC_BASIC_SETING);
+ writel(basic_setting, tsc->tsc_regs + REG_TSC_BASIC_SETTING);
writel(DE_GLITCH_2, tsc->tsc_regs + REG_TSC_DEBUG_MODE2);
--
2.43.0
^ permalink raw reply related
* [PATCH v4 0/6] Input: imx6ul_tsc - set glitch threshold by dts property
From: Dario Binacchi @ 2025-09-17 8:05 UTC (permalink / raw)
To: linux-kernel
Cc: linux-amarula, Frank Li, Dario Binacchi, Conor Dooley,
Dmitry Torokhov, Fabio Estevam, Haibo Chen, Javier Carrasco,
Jeff LaBundy, Krzysztof Kozlowski, Michael Trimarchi,
Pengutronix Kernel Team, Rob Herring, Sascha Hauer, Shawn Guo,
devicetree, imx, linux-arm-kernel, linux-input
The series allows setting the glitch threshold for the detected signal
from a DTS property instead of a hardcoded value.
In addition, I applied a patch that replaces opencoded masking and
shifting, with BIT(), GENMASK(), FIELD_GET() and FIELD_PREP() macros.
Changes in v4:
- Adjust property description fsl,imx6ul-tsc.yaml following the
suggestions of Conor Dooley and Frank Li.
Changes in v3:
- Remove the final part of the description that refers to
implementation details in fsl,imx6ul-tsc.yaml.
Changes in v2:
- Replace patch ("dt-bindings: input: touchscreen: fsl,imx6ul-tsc: add
fsl,glitch-threshold") with ("dt-bindings: touchscreen: add
touchscreen-glitch-threshold-ns property"), making the previous property
general by moving it to touchscreen.yaml.
- Rework "Input: imx6ul_tsc - set glitch threshold by DTS property" patch
to match changes made to the DTS property.
- Move "Input: imx6ul_tsc - use BIT, FIELD_{GET,PREP} and GENMASK macros"
patch right after the patch fixing the typo.
Dario Binacchi (5):
Input: imx6ul_tsc - use BIT, FIELD_{GET,PREP} and GENMASK macros
dt-bindings: touchscreen: add touchscreen-glitch-threshold-ns property
dt-bindings: touchscreen: fsl,imx6ul-tsc: support glitch thresold
ARM: dts: imx6ull-engicam-microgea-bmm: set touchscreen glitch
threshold
Input: imx6ul_tsc - set glitch threshold by DTS property
Michael Trimarchi (1):
Input: imx6ul_tsc - fix typo in register name
.../input/touchscreen/fsl,imx6ul-tsc.yaml | 14 ++
.../input/touchscreen/touchscreen.yaml | 4 +
.../nxp/imx/imx6ull-engicam-microgea-bmm.dts | 1 +
drivers/input/touchscreen/imx6ul_tsc.c | 122 +++++++++++-------
4 files changed, 97 insertions(+), 44 deletions(-)
--
2.43.0
base-commit: 5aca7966d2a7255ba92fd5e63268dd767b223aa5
branch: tsc_de_glitch
^ permalink raw reply
* Re: [PATCH] HID: hid-ntrig: Fix potential memory leak in ntrig_report_version()
From: Markus Elfring @ 2025-09-17 7:46 UTC (permalink / raw)
To: Masami Ichikawa, linux-input
Cc: LKML, Benjamin Tissoires, Jiri Kosina, Minjong Kim
In-Reply-To: <20250917045026.601848-1-masami256@gmail.com>
…
> It is safe to move the kmalloc() call after the hid_is_usb() check to avoid
> unnecessary allocation and potential memory leak.
* See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.17-rc6#n94
* How do you think about to increase the application of scope-based resource management?
https://elixir.bootlin.com/linux/v6.17-rc6/source/include/linux/slab.h#L476
* Can a summary phrase like “Prevent memory leak in ntrig_report_version()”
be nicer?
Regards,
Markus
^ permalink raw reply
* [PATCH v3] Input: Improve WinWing Orion2 throttle support
From: Ivan Gorinov @ 2025-09-17 5:01 UTC (permalink / raw)
To: Jiri Kosina; +Cc: linux-input, linux-kernel
Add support for Orion2 throttle configurations with more than 32 buttons
on the grip handle (this means the device reports more than 80 buttons).
Map additional button codes to KEY_MACRO1 .. KEY_MACRO28.
Make the module simpler, removing report descriptor fixup.
Changes since v2:
- Add more comments about button mapping
Changes since v1:
- Correct trivial coding style violations
Signed-off-by: Ivan Gorinov <linux-kernel@altimeter.info>
---
drivers/hid/Kconfig | 2 +
drivers/hid/hid-winwing.c | 169 +++++++++++++++++++++++---------------
2 files changed, 106 insertions(+), 65 deletions(-)
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index a57901203aeb..3317981e65dc 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -1309,6 +1309,8 @@ config HID_WINWING
help
Support for WinWing Orion2 throttle base with the following grips:
+ * TGRIP-15E
+ * TGRIP-15EX
* TGRIP-16EX
* TGRIP-18
diff --git a/drivers/hid/hid-winwing.c b/drivers/hid/hid-winwing.c
index d4afbbd27807..775609d0e35a 100644
--- a/drivers/hid/hid-winwing.c
+++ b/drivers/hid/hid-winwing.c
@@ -37,6 +37,7 @@ struct winwing_drv_data {
struct hid_device *hdev;
__u8 *report_buf;
struct mutex lock;
+ int map_more_buttons;
unsigned int num_leds;
struct winwing_led leds[];
};
@@ -81,12 +82,10 @@ static int winwing_init_led(struct hid_device *hdev,
int ret;
int i;
- size_t data_size = struct_size(data, leds, 3);
-
- data = devm_kzalloc(&hdev->dev, data_size, GFP_KERNEL);
+ data = hid_get_drvdata(hdev);
if (!data)
- return -ENOMEM;
+ return -EINVAL;
data->report_buf = devm_kmalloc(&hdev->dev, MAX_REPORT, GFP_KERNEL);
@@ -106,6 +105,7 @@ static int winwing_init_led(struct hid_device *hdev,
"%s::%s",
dev_name(&input->dev),
info->led_name);
+
if (!led->cdev.name)
return -ENOMEM;
@@ -114,14 +114,98 @@ static int winwing_init_led(struct hid_device *hdev,
return ret;
}
- hid_set_drvdata(hdev, data);
-
return ret;
}
+static int winwing_map_button(int button, int map_more_buttons)
+{
+ if (button < 1)
+ return KEY_RESERVED;
+
+ if (button > 112)
+ return KEY_RESERVED;
+
+ if (button <= 16) {
+ /*
+ * Grip buttons [1 .. 16] are mapped to
+ * key codes BTN_TRIGGER .. BTN_DEAD
+ */
+ return (button - 1) + BTN_JOYSTICK;
+ }
+
+ if (button >= 65) {
+ /*
+ * Base buttons [65 .. 112] are mapped to
+ * key codes BTN_TRIGGER_HAPPY17 .. KEY_MAX
+ */
+ return (button - 65) + BTN_TRIGGER_HAPPY17;
+ }
+
+ if (!map_more_buttons) {
+ /*
+ * Not mapping numbers [33 .. 64] which
+ * are not assigned to any real buttons
+ */
+ if (button >= 33)
+ return KEY_RESERVED;
+ /*
+ * Grip buttons [17 .. 32] are mapped to
+ * BTN_TRIGGER_HAPPY1 .. BTN_TRIGGER_HAPPY16
+ */
+ return (button - 17) + BTN_TRIGGER_HAPPY1;
+ }
+
+ if (button >= 49) {
+ /*
+ * Grip buttons [49 .. 64] are mapped to
+ * BTN_TRIGGER_HAPPY1 .. BTN_TRIGGER_HAPPY16
+ */
+ return (button - 49) + BTN_TRIGGER_HAPPY1;
+ }
+
+ /*
+ * Grip buttons [17 .. 44] are mapped to
+ * key codes KEY_MACRO1 .. KEY_MACRO28;
+ * also mapping numbers [45 .. 48] which
+ * are not assigned to any real buttons.
+ */
+ return (button - 17) + KEY_MACRO1;
+}
+
+static int winwing_input_mapping(struct hid_device *hdev,
+ struct hid_input *hi, struct hid_field *field, struct hid_usage *usage,
+ unsigned long **bit, int *max)
+{
+ struct winwing_drv_data *data;
+ int code = KEY_RESERVED;
+ int button = 0;
+
+ data = hid_get_drvdata(hdev);
+
+ if (!data)
+ return -EINVAL;
+
+ if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
+ return 0;
+
+ if (field->application != HID_GD_JOYSTICK)
+ return 0;
+
+ /* Button numbers start with 1 */
+ button = usage->hid & HID_USAGE;
+
+ code = winwing_map_button(button, data->map_more_buttons);
+
+ hid_map_usage(hi, usage, bit, max, EV_KEY, code);
+
+ return 1;
+}
+
static int winwing_probe(struct hid_device *hdev,
const struct hid_device_id *id)
{
+ struct winwing_drv_data *data;
+ size_t data_size = struct_size(data, leds, 3);
int ret;
ret = hid_parse(hdev);
@@ -130,6 +214,15 @@ static int winwing_probe(struct hid_device *hdev,
return ret;
}
+ data = devm_kzalloc(&hdev->dev, data_size, GFP_KERNEL);
+
+ if (!data)
+ return -ENOMEM;
+
+ data->map_more_buttons = id->driver_data;
+
+ hid_set_drvdata(hdev, data);
+
ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
if (ret) {
hid_err(hdev, "hw start failed\n");
@@ -152,64 +245,11 @@ static int winwing_input_configured(struct hid_device *hdev,
return ret;
}
-static const __u8 original_rdesc_buttons[] = {
- 0x05, 0x09, 0x19, 0x01, 0x29, 0x6F,
- 0x15, 0x00, 0x25, 0x01, 0x35, 0x00,
- 0x45, 0x01, 0x75, 0x01, 0x95, 0x6F,
- 0x81, 0x02, 0x75, 0x01, 0x95, 0x01,
- 0x81, 0x01
-};
-
-/*
- * HID report descriptor shows 111 buttons, which exceeds maximum
- * number of buttons (80) supported by Linux kernel HID subsystem.
- *
- * This module skips numbers 32-63, unused on some throttle grips.
- */
-
-static const __u8 *winwing_report_fixup(struct hid_device *hdev, __u8 *rdesc,
- unsigned int *rsize)
-{
- int sig_length = sizeof(original_rdesc_buttons);
- int unused_button_numbers = 32;
-
- if (*rsize < 34)
- return rdesc;
-
- if (memcmp(rdesc + 8, original_rdesc_buttons, sig_length) == 0) {
-
- /* Usage Maximum */
- rdesc[13] -= unused_button_numbers;
-
- /* Report Count for buttons */
- rdesc[25] -= unused_button_numbers;
-
- /* Report Count for padding [HID1_11, 6.2.2.9] */
- rdesc[31] += unused_button_numbers;
-
- hid_info(hdev, "winwing descriptor fixed\n");
- }
-
- return rdesc;
-}
-
-static int winwing_raw_event(struct hid_device *hdev,
- struct hid_report *report, u8 *raw_data, int size)
-{
- if (size >= 15) {
- /* Skip buttons 32 .. 63 */
- memmove(raw_data + 5, raw_data + 9, 6);
-
- /* Clear the padding */
- memset(raw_data + 11, 0, 4);
- }
-
- return 0;
-}
-
static const struct hid_device_id winwing_devices[] = {
- { HID_USB_DEVICE(0x4098, 0xbe62) }, /* TGRIP-18 */
- { HID_USB_DEVICE(0x4098, 0xbe68) }, /* TGRIP-16EX */
+ { HID_USB_DEVICE(0x4098, 0xbd65), .driver_data = 1 }, /* TGRIP-15E */
+ { HID_USB_DEVICE(0x4098, 0xbd64), .driver_data = 1 }, /* TGRIP-15EX */
+ { HID_USB_DEVICE(0x4098, 0xbe68), .driver_data = 0 }, /* TGRIP-16EX */
+ { HID_USB_DEVICE(0x4098, 0xbe62), .driver_data = 0 }, /* TGRIP-18 */
{}
};
@@ -218,10 +258,9 @@ MODULE_DEVICE_TABLE(hid, winwing_devices);
static struct hid_driver winwing_driver = {
.name = "winwing",
.id_table = winwing_devices,
+ .input_mapping = winwing_input_mapping,
.probe = winwing_probe,
.input_configured = winwing_input_configured,
- .report_fixup = winwing_report_fixup,
- .raw_event = winwing_raw_event,
};
module_hid_driver(winwing_driver);
--
2.34.1
^ permalink raw reply related
* [PATCH] HID: hid-ntrig: Fix potential memory leak in ntrig_report_version()
From: Masami Ichikawa @ 2025-09-17 4:50 UTC (permalink / raw)
To: jikos, bentiss; +Cc: minbell.kim, linux-input, linux-kernel, Masami Ichikawa
The kmalloc() was called before checking hid_is_usb(hdev). If hid_is_usb()
returned false, the function would return early and leak the allocated
memory.
It is safe to move the kmalloc() call after the hid_is_usb() check to avoid
unnecessary allocation and potential memory leak.
Fixes: 185c926283da ("HID: hid-ntrig: fix unable to handle page fault in ntrig_report_version()")
Signed-off-by: Masami Ichikawa <masami256@gmail.com>
---
drivers/hid/hid-ntrig.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
index 0f76e241e0af..52e8e7fe9681 100644
--- a/drivers/hid/hid-ntrig.c
+++ b/drivers/hid/hid-ntrig.c
@@ -142,11 +142,12 @@ static void ntrig_report_version(struct hid_device *hdev)
int ret;
char buf[20];
struct usb_device *usb_dev = hid_to_usb_dev(hdev);
- unsigned char *data = kmalloc(8, GFP_KERNEL);
+ unsigned char *data = NULL;
if (!hid_is_usb(hdev))
return;
+ data = kmalloc(8, GFP_KERNEL);
if (!data)
goto err_free;
--
2.51.0
^ permalink raw reply related
* [PATCH v3 RESEND] hid: intel-thc-hid: intel-quicki2c: support ACPI config for advanced features
From: Xinpeng Sun @ 2025-09-17 1:53 UTC (permalink / raw)
To: jikos, bentiss
Cc: srinivas.pandruvada, linux-input, linux-kernel, even.xu,
Xinpeng Sun, Rui Zhang
There is a new BIOS enhancement that adds the capability to configure the
following two features of I2C subsystem introduced in commit 1ed0b48
("Intel-thc: Introduce max input size control") and commit 3f2a921
("Intel-thc: Introduce interrupt delay control"):
- Max input size control
- Interrupt delay control
As BIOS is used for the configuration of these two features, change driver
data usage to indicate hardware capability, and add corresponding ACPI
configuration support in QuickI2C driver.
Signed-off-by: Xinpeng Sun <xinpeng.sun@intel.com>
Tested-by: Rui Zhang <rui1.zhang@intel.com>
---
Changes in v3:
- remove unnecessary initialization of local variables
Changes in v2:
- refine the commit message
---
.../intel-quicki2c/pci-quicki2c.c | 39 +++++++++++++++----
.../intel-quicki2c/quicki2c-dev.h | 24 +++++++++++-
2 files changed, 53 insertions(+), 10 deletions(-)
diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c b/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
index 854926b3cfd4..3ce5a692b92b 100644
--- a/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
+++ b/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
@@ -23,6 +23,7 @@
static struct quicki2c_ddata ptl_ddata = {
.max_detect_size = MAX_RX_DETECT_SIZE_PTL,
+ .max_interrupt_delay = MAX_RX_INTERRUPT_DELAY,
};
/* THC QuickI2C ACPI method to get device properties */
@@ -200,6 +201,21 @@ static int quicki2c_get_acpi_resources(struct quicki2c_device *qcdev)
return -EOPNOTSUPP;
}
+ if (qcdev->ddata) {
+ qcdev->i2c_max_frame_size_enable = i2c_config.FSEN;
+ qcdev->i2c_int_delay_enable = i2c_config.INDE;
+
+ if (i2c_config.FSVL <= qcdev->ddata->max_detect_size)
+ qcdev->i2c_max_frame_size = i2c_config.FSVL;
+ else
+ qcdev->i2c_max_frame_size = qcdev->ddata->max_detect_size;
+
+ if (i2c_config.INDV <= qcdev->ddata->max_interrupt_delay)
+ qcdev->i2c_int_delay = i2c_config.INDV;
+ else
+ qcdev->i2c_int_delay = qcdev->ddata->max_interrupt_delay;
+ }
+
return 0;
}
@@ -441,17 +457,24 @@ static void quicki2c_dma_adv_enable(struct quicki2c_device *qcdev)
* max input length <= THC detect capability, enable the feature with device
* max input length.
*/
- if (qcdev->ddata->max_detect_size >=
- le16_to_cpu(qcdev->dev_desc.max_input_len)) {
- thc_i2c_set_rx_max_size(qcdev->thc_hw,
- le16_to_cpu(qcdev->dev_desc.max_input_len));
+ if (qcdev->i2c_max_frame_size_enable) {
+ if (qcdev->i2c_max_frame_size >=
+ le16_to_cpu(qcdev->dev_desc.max_input_len)) {
+ thc_i2c_set_rx_max_size(qcdev->thc_hw,
+ le16_to_cpu(qcdev->dev_desc.max_input_len));
+ } else {
+ dev_warn(qcdev->dev,
+ "Max frame size is smaller than hid max input length!");
+ thc_i2c_set_rx_max_size(qcdev->thc_hw,
+ le16_to_cpu(qcdev->i2c_max_frame_size));
+ }
thc_i2c_rx_max_size_enable(qcdev->thc_hw, true);
}
/* If platform supports interrupt delay feature, enable it with given delay */
- if (qcdev->ddata->interrupt_delay) {
+ if (qcdev->i2c_int_delay_enable) {
thc_i2c_set_rx_int_delay(qcdev->thc_hw,
- qcdev->ddata->interrupt_delay);
+ qcdev->i2c_int_delay * 10);
thc_i2c_rx_int_delay_enable(qcdev->thc_hw, true);
}
}
@@ -464,10 +487,10 @@ static void quicki2c_dma_adv_enable(struct quicki2c_device *qcdev)
*/
static void quicki2c_dma_adv_disable(struct quicki2c_device *qcdev)
{
- if (qcdev->ddata->max_detect_size)
+ if (qcdev->i2c_max_frame_size_enable)
thc_i2c_rx_max_size_enable(qcdev->thc_hw, false);
- if (qcdev->ddata->interrupt_delay)
+ if (qcdev->i2c_int_delay_enable)
thc_i2c_rx_int_delay_enable(qcdev->thc_hw, false);
}
diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h
index d412eafcf9ea..0d423d5dd7a7 100644
--- a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h
+++ b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h
@@ -38,6 +38,8 @@
/* PTL Max packet size detection capability is 255 Bytes */
#define MAX_RX_DETECT_SIZE_PTL 255
+/* Max interrupt delay capability is 2.56ms */
+#define MAX_RX_INTERRUPT_DELAY 256
/* Default interrupt delay is 1ms, suitable for most devices */
#define DEFAULT_INTERRUPT_DELAY_US (1 * USEC_PER_MSEC)
@@ -101,6 +103,10 @@ struct quicki2c_subip_acpi_parameter {
* @HMTD: High Speed Mode Plus (3.4Mbits/sec) Serial Data Line Transmit HOLD Period
* @HMRD: High Speed Mode Plus (3.4Mbits/sec) Serial Data Line Receive HOLD Period
* @HMSL: Maximum length (in ic_clk_cycles) of suppressed spikes in High Speed Mode
+ * @FSEN: Maximum Frame Size Feature Enable Control
+ * @FSVL: Maximum Frame Size Value (unit in Bytes)
+ * @INDE: Interrupt Delay Feature Enable Control
+ * @INDV: Interrupt Delay Value (unit in 10 us)
*
* Those properties get from QUICKI2C_ACPI_METHOD_NAME_ISUB method, used for
* I2C timing configure.
@@ -127,17 +133,22 @@ struct quicki2c_subip_acpi_config {
u64 HMTD;
u64 HMRD;
u64 HMSL;
+
+ u64 FSEN;
+ u64 FSVL;
+ u64 INDE;
+ u64 INDV;
u8 reserved;
};
/**
* struct quicki2c_ddata - Driver specific data for quicki2c device
* @max_detect_size: Identify max packet size detect for rx
- * @interrupt_delay: Identify interrupt detect delay for rx
+ * @interrupt_delay: Identify max interrupt detect delay for rx
*/
struct quicki2c_ddata {
u32 max_detect_size;
- u32 interrupt_delay;
+ u32 max_interrupt_delay;
};
struct device;
@@ -170,6 +181,10 @@ struct acpi_device;
* @report_len: The length of input/output report packet
* @reset_ack_wq: Workqueue for waiting reset response from device
* @reset_ack: Indicate reset response received or not
+ * @i2c_max_frame_size_enable: Indicate max frame size feature enabled or not
+ * @i2c_max_frame_size: Max RX frame size (unit in Bytes)
+ * @i2c_int_delay_enable: Indicate interrupt delay feature enabled or not
+ * @i2c_int_delay: Interrupt detection delay value (unit in 10 us)
*/
struct quicki2c_device {
struct device *dev;
@@ -200,6 +215,11 @@ struct quicki2c_device {
wait_queue_head_t reset_ack_wq;
bool reset_ack;
+
+ u32 i2c_max_frame_size_enable;
+ u32 i2c_max_frame_size;
+ u32 i2c_int_delay_enable;
+ u32 i2c_int_delay;
};
#endif /* _QUICKI2C_DEV_H_ */
--
2.40.1
^ permalink raw reply related
* RE: [PATCH v3] hid: intel-thc-hid: intel-quicki2c: support ACPI config for advanced features
From: Sun, Xinpeng @ 2025-09-17 1:43 UTC (permalink / raw)
To: srinivas pandruvada, jikos@kernel.org, bentiss@kernel.org
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
Xu, Even, Zhang, Rui1
In-Reply-To: <6e052f056904651aae3cdb2ea50ca54c252cb4a2.camel@linux.intel.com>
> -----Original Message-----
> From: srinivas pandruvada <srinivas.pandruvada@linux.intel.com>
> Sent: Wednesday, September 17, 2025 7:31 AM
> To: Sun, Xinpeng <xinpeng.sun@intel.com>; jikos@kernel.org; bentiss@kernel.org
> Cc: linux-input@vger.kernel.org; linux-kernel@vger.kernel.org; Xu, Even
> <even.xu@intel.com>; Zhang, Rui1 <rui1.zhang@intel.com>
> Subject: Re: [PATCH v3] hid: intel-thc-hid: intel-quicki2c: support ACPI config for
> advanced features
>
> On Tue, 2025-09-16 at 10:57 +0800, Xinpeng Sun wrote:
> > There is a new BIOS enhancement that adds the capability to configure
> > the following two features of I2C subsystem introduced in commit
> > 1ed0b48
> > ("Intel-thc: Introduce max input size control") and commit 3f2a921
> > ("Intel-thc: Introduce interrupt delay control"):
> > - Max input size control
> > - Interrupt delay control
> >
> > As BIOS is used for the configuration of these two features, change
> > driver data usage to indicate hardware capability, and add
> > corresponding ACPI configuration support in QuickI2C driver.
> >
> > Signed-off-by: Xinpeng Sun <xinpeng.sun@intel.com>
> > Tested-by: Rui Zhang <rui1.zhang@intel.com>
> > ---
> You need change log as this v3..
Will add change log and resend v3.
Thanks,
Xinpeng
>
> Thanks,
> Srinivas
>
> > .../intel-quicki2c/pci-quicki2c.c | 39 +++++++++++++++--
> > --
> > .../intel-quicki2c/quicki2c-dev.h | 24 +++++++++++-
> > 2 files changed, 53 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
> > b/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
> > index 854926b3cfd4..3ce5a692b92b 100644
> > --- a/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
> > +++ b/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
> > @@ -23,6 +23,7 @@
> >
> > static struct quicki2c_ddata ptl_ddata = {
> > .max_detect_size = MAX_RX_DETECT_SIZE_PTL,
> > + .max_interrupt_delay = MAX_RX_INTERRUPT_DELAY,
> > };
> >
> > /* THC QuickI2C ACPI method to get device properties */ @@ -200,6
> > +201,21 @@ static int quicki2c_get_acpi_resources(struct
> > quicki2c_device *qcdev)
> > return -EOPNOTSUPP;
> > }
> >
> > + if (qcdev->ddata) {
> > + qcdev->i2c_max_frame_size_enable = i2c_config.FSEN;
> > + qcdev->i2c_int_delay_enable = i2c_config.INDE;
> > +
> > + if (i2c_config.FSVL <= qcdev->ddata-
> > >max_detect_size)
> > + qcdev->i2c_max_frame_size = i2c_config.FSVL;
> > + else
> > + qcdev->i2c_max_frame_size = qcdev->ddata-
> > >max_detect_size;
> > +
> > + if (i2c_config.INDV <= qcdev->ddata-
> > >max_interrupt_delay)
> > + qcdev->i2c_int_delay = i2c_config.INDV;
> > + else
> > + qcdev->i2c_int_delay = qcdev->ddata-
> > >max_interrupt_delay;
> > + }
> > +
> > return 0;
> > }
> >
> > @@ -441,17 +457,24 @@ static void quicki2c_dma_adv_enable(struct
> > quicki2c_device *qcdev)
> > * max input length <= THC detect capability, enable the feature
> > with device
> > * max input length.
> > */
> > - if (qcdev->ddata->max_detect_size >=
> > - le16_to_cpu(qcdev->dev_desc.max_input_len)) {
> > - thc_i2c_set_rx_max_size(qcdev->thc_hw,
> > - le16_to_cpu(qcdev-
> > >dev_desc.max_input_len));
> > + if (qcdev->i2c_max_frame_size_enable) {
> > + if (qcdev->i2c_max_frame_size >=
> > + le16_to_cpu(qcdev->dev_desc.max_input_len)) {
> > + thc_i2c_set_rx_max_size(qcdev->thc_hw,
> > + le16_to_cpu(qcdev-
> > >dev_desc.max_input_len));
> > + } else {
> > + dev_warn(qcdev->dev,
> > + "Max frame size is smaller than hid
> > max input length!");
> > + thc_i2c_set_rx_max_size(qcdev->thc_hw,
> > + le16_to_cpu(qcdev-
> > >i2c_max_frame_size));
> > + }
> > thc_i2c_rx_max_size_enable(qcdev->thc_hw, true);
> > }
> >
> > /* If platform supports interrupt delay feature, enable it with
> > given delay */
> > - if (qcdev->ddata->interrupt_delay) {
> > + if (qcdev->i2c_int_delay_enable) {
> > thc_i2c_set_rx_int_delay(qcdev->thc_hw,
> > - qcdev->ddata-
> > >interrupt_delay);
> > + qcdev->i2c_int_delay * 10);
> > thc_i2c_rx_int_delay_enable(qcdev->thc_hw, true);
> > }
> > }
> > @@ -464,10 +487,10 @@ static void quicki2c_dma_adv_enable(struct
> > quicki2c_device *qcdev)
> > */
> > static void quicki2c_dma_adv_disable(struct quicki2c_device *qcdev)
> > {
> > - if (qcdev->ddata->max_detect_size)
> > + if (qcdev->i2c_max_frame_size_enable)
> > thc_i2c_rx_max_size_enable(qcdev->thc_hw, false);
> >
> > - if (qcdev->ddata->interrupt_delay)
> > + if (qcdev->i2c_int_delay_enable)
> > thc_i2c_rx_int_delay_enable(qcdev->thc_hw, false);
> > }
> >
> > diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h
> > b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h
> > index d412eafcf9ea..0d423d5dd7a7 100644
> > --- a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h
> > +++ b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h
> > @@ -38,6 +38,8 @@
> >
> > /* PTL Max packet size detection capability is 255 Bytes */
> > #define MAX_RX_DETECT_SIZE_PTL 255
> > +/* Max interrupt delay capability is 2.56ms */
> > +#define MAX_RX_INTERRUPT_DELAY 256
> >
> > /* Default interrupt delay is 1ms, suitable for most devices */
> > #define DEFAULT_INTERRUPT_DELAY_US (1 * USEC_PER_MSEC)
> > @@ -101,6 +103,10 @@ struct quicki2c_subip_acpi_parameter {
> > * @HMTD: High Speed Mode Plus (3.4Mbits/sec) Serial Data Line
> > Transmit HOLD Period
> > * @HMRD: High Speed Mode Plus (3.4Mbits/sec) Serial Data Line
> > Receive HOLD Period
> > * @HMSL: Maximum length (in ic_clk_cycles) of suppressed spikes in
> > High Speed Mode
> > + * @FSEN: Maximum Frame Size Feature Enable Control
> > + * @FSVL: Maximum Frame Size Value (unit in Bytes)
> > + * @INDE: Interrupt Delay Feature Enable Control
> > + * @INDV: Interrupt Delay Value (unit in 10 us)
> > *
> > * Those properties get from QUICKI2C_ACPI_METHOD_NAME_ISUB method,
> > used for
> > * I2C timing configure.
> > @@ -127,17 +133,22 @@ struct quicki2c_subip_acpi_config {
> > u64 HMTD;
> > u64 HMRD;
> > u64 HMSL;
> > +
> > + u64 FSEN;
> > + u64 FSVL;
> > + u64 INDE;
> > + u64 INDV;
> > u8 reserved;
> > };
> >
> > /**
> > * struct quicki2c_ddata - Driver specific data for quicki2c device
> > * @max_detect_size: Identify max packet size detect for rx
> > - * @interrupt_delay: Identify interrupt detect delay for rx
> > + * @interrupt_delay: Identify max interrupt detect delay for rx
> > */
> > struct quicki2c_ddata {
> > u32 max_detect_size;
> > - u32 interrupt_delay;
> > + u32 max_interrupt_delay;
> > };
> >
> > struct device;
> > @@ -170,6 +181,10 @@ struct acpi_device;
> > * @report_len: The length of input/output report packet
> > * @reset_ack_wq: Workqueue for waiting reset response from device
> > * @reset_ack: Indicate reset response received or not
> > + * @i2c_max_frame_size_enable: Indicate max frame size feature
> > enabled or not
> > + * @i2c_max_frame_size: Max RX frame size (unit in Bytes)
> > + * @i2c_int_delay_enable: Indicate interrupt delay feature enabled
> > or not
> > + * @i2c_int_delay: Interrupt detection delay value (unit in 10 us)
> > */
> > struct quicki2c_device {
> > struct device *dev;
> > @@ -200,6 +215,11 @@ struct quicki2c_device {
> >
> > wait_queue_head_t reset_ack_wq;
> > bool reset_ack;
> > +
> > + u32 i2c_max_frame_size_enable;
> > + u32 i2c_max_frame_size;
> > + u32 i2c_int_delay_enable;
> > + u32 i2c_int_delay;
> > };
> >
> > #endif /* _QUICKI2C_DEV_H_ */
^ permalink raw reply
* [PATCH v2 5/5] Input: xbox_gip - Add wheel support
From: Vicki Pfau @ 2025-09-17 1:19 UTC (permalink / raw)
To: Dmitry Torokhov, linux-input; +Cc: Vicki Pfau
In-Reply-To: <20250917011937.1649481-1-vi@endrift.com>
This adds preliminary support for racing wheel support in xbox_gip,
exposing them mapped to the newly added axes.
Signed-off-by: Vicki Pfau <vi@endrift.com>
---
drivers/input/joystick/xbox_gip.c | 209 ++++++++++++++++++++++++++++--
1 file changed, 201 insertions(+), 8 deletions(-)
diff --git a/drivers/input/joystick/xbox_gip.c b/drivers/input/joystick/xbox_gip.c
index 94e20ab4b672c..1be6ad0d6eb66 100644
--- a/drivers/input/joystick/xbox_gip.c
+++ b/drivers/input/joystick/xbox_gip.c
@@ -10,7 +10,7 @@
* - Event logging
* - Sending fragmented messages
* - Raw character device
- * - Wheel support
+ * - Wheel force feedback
* - Flight stick support
* - More arcade stick testing
* - Arcade stick extra buttons
@@ -220,6 +220,22 @@
#define GIP_EXTENDED_STATUS_ACCESS_DENIED 3
#define GIP_EXTENDED_STATUS_FAILED 4
+/* Wheel-specific flags */
+#define GIP_WHEEL_HAS_POWER BIT(3)
+#define GIP_WHEEL_HANDBRAKE_CONN BIT(4)
+#define GIP_WHEEL_CLUTCH_CONN BIT(5)
+#define GIP_WHEEL_BRAKE_CONN BIT(6)
+#define GIP_WHEEL_THROTTLE_CONN BIT(7)
+
+#define GIP_HSHIFTER_NONE 0
+#define GIP_HSHIFTER_2POS 1 /* 2 position, no neutral */
+#define GIP_HSHIFTER_2POS_N 2 /* 2 position, neutral */
+#define GIP_HSHIFTER_RTL_1TL 3 /* Reverse top left, first top left */
+#define GIP_HSHIFTER_RTL_1BL 4 /* Reverse top left, first bottom left */
+#define GIP_HSHIFTER_RBL 5 /* Reverse bottom left */
+#define GIP_HSHIFTER_RTR 6 /* Reverse top right */
+#define GIP_HSHIFTER_RBR 7 /* Reverse bottom right */
+
/* Internal constants, not part of protocol */
#define GIP_DEFAULT_IN_SYSTEM_MESSAGES 0x5e
#define GIP_DEFAULT_OUT_SYSTEM_MESSAGES 0x472
@@ -235,6 +251,8 @@
#define GIP_QUIRK_NO_HELLO BIT(0)
#define GIP_QUIRK_NO_IMPULSE_VIBRATION BIT(1)
+#define GIP_QUIRK_FORCE_GAMEPAD_SB BIT(2)
+#define GIP_QUIRK_WHEEL_FORCE_HANDBRAKE BIT(31)
#define GIP_LED_GUIDE_MAX_BRIGHTNESS 100 /* Spec says 47, but larger values work */
#define GIP_LED_GUIDE_INIT_BRIGHTNESS 20
@@ -277,6 +295,11 @@ enum gip_elite_button_format {
GIP_BTN_FMT_XBE2_5,
};
+enum gip_vendor_type {
+ GIP_VENDOR_NONE = 0,
+ GIP_VENDOR_LOGI_TRUE_FORCE_WHEEL = 1,
+};
+
static const guid_t guid_arcade_stick =
GUID_INIT(0x332054cc, 0xa34b, 0x41d5, 0xa3, 0x4a, 0xa6, 0xa6, 0x71, 0x1e, 0xc4, 0xb3);
static const guid_t guid_console_function_map =
@@ -355,6 +378,18 @@ static const struct gip_audio_format gip_audio_format_table[MAX_GIP_AUDIO_FORMAT
[GIP_AUDIO_FORMAT_48000HZ_8CH] = { .rate = 48000, .channels = 8 },
};
+struct gip_wheel_info {
+ uint8_t connections;
+ uint8_t shifter_type: 3;
+ uint8_t max_gear: 5;
+ uint16_t angle_setting;
+ uint16_t max_angle;
+ uint16_t max_throttle;
+ uint16_t max_brake;
+ uint16_t max_clutch;
+ uint8_t max_handbrake;
+};
+
struct gip_quirks {
uint16_t vendor_id;
uint16_t product_id;
@@ -371,6 +406,11 @@ struct gip_quirks {
};
static const struct gip_quirks quirks[] = {
+ /* Thrustmaster T128X GIP Racing Wheel */
+ { 0x044f, 0xb69c, 0,
+ .quirks = GIP_QUIRK_FORCE_GAMEPAD_SB | GIP_QUIRK_WHEEL_FORCE_HANDBRAKE,
+ .device_type = GIP_TYPE_WHEEL },
+
/* Xbox One Controller (model 1573) */
{ 0x045e, 0x02d1, 0, .override_name = "Xbox One Controller" },
@@ -498,11 +538,14 @@ struct gip_attachment {
enum gip_elite_button_format xbe_format;
uint32_t features;
uint32_t quirks;
+ enum gip_vendor_type vendor_type;
int extra_buttons;
int extra_axes;
bool dpad_as_buttons;
+ struct gip_wheel_info wheel;
+ int8_t logi_dial_state;
struct hid_device *hdev;
};
@@ -1574,10 +1617,44 @@ static int gip_setup_input_device(struct gip_attachment *attachment)
input_set_capability(input, EV_KEY, BTN_THUMBR);
input_set_capability(input, EV_KEY, BTN_THUMBL);
break;
- case GIP_TYPE_FLIGHT_STICK:
case GIP_TYPE_WHEEL:
+ input_set_abs_params(input, ABS_WHEEL,
+ -attachment->wheel.max_angle - 1,
+ attachment->wheel.max_angle, 0, 0);
+ input_abs_set_res(input, ABS_WHEEL, attachment->wheel.angle_setting);
+ if (attachment->wheel.max_throttle)
+ input_set_abs_params(input, ABS_GAS, 0,
+ attachment->wheel.max_throttle, 0, 0);
+
+ if (attachment->wheel.max_brake)
+ input_set_abs_params(input, ABS_BRAKE, 0,
+ attachment->wheel.max_brake, 0, 0);
+
+ if (attachment->wheel.max_clutch)
+ input_set_abs_params(input, ABS_CLUTCH, 0,
+ attachment->wheel.max_clutch, 0, 0);
+
+ if (attachment->wheel.max_handbrake)
+ input_set_abs_params(input, ABS_HANDBRAKE, 0,
+ attachment->wheel.max_handbrake, 0, 0);
+
+ if (attachment->wheel.shifter_type)
+ input_set_abs_params(input, ABS_SHIFTER, -1,
+ attachment->wheel.max_gear, 0, 0);
+
+
+ if (attachment->vendor_type == GIP_VENDOR_LOGI_TRUE_FORCE_WHEEL) {
+ input_set_capability(input, EV_KEY, BTN_THUMBL);
+ input_set_capability(input, EV_KEY, BTN_THUMBR);
+ input_set_capability(input, EV_KEY, KEY_KPPLUS);
+ input_set_capability(input, EV_KEY, KEY_KPMINUS);
+ input_set_capability(input, EV_KEY, KEY_KPENTER);
+ input_set_capability(input, EV_REL, REL_DIAL);
+ }
+ break;
case GIP_TYPE_UNKNOWN:
case GIP_TYPE_NAVIGATION_CONTROLLER:
+ case GIP_TYPE_FLIGHT_STICK:
break;
case GIP_TYPE_CHATPAD:
case GIP_TYPE_HEADSET:
@@ -1602,6 +1679,11 @@ static int gip_setup_input_device(struct gip_attachment *attachment)
if (attachment->vendor_id == 0x045e && attachment->product_id == 0x0b0a)
input_set_abs_params(input, ABS_PROFILE, 0, 3, 0, 0);
+ if (attachment->quirks & GIP_QUIRK_WHEEL_FORCE_HANDBRAKE) {
+ input_set_capability(input, EV_KEY, BTN_THUMBR);
+ input_set_capability(input, EV_KEY, BTN_THUMBL);
+ }
+
#ifdef CONFIG_JOYSTICK_XBOX_GIP_FF
if (attachment->features & GIP_FEATURE_MOTOR_CONTROL) {
input_set_capability(input, EV_FF, FF_RUMBLE);
@@ -1681,6 +1763,14 @@ static int gip_send_init_sequence(struct gip_attachment *attachment)
return rc;
}
+ if (attachment->attachment_type == GIP_TYPE_WHEEL) {
+ struct gip_initial_reports_request request = { 0 };
+
+ gip_send_vendor_message(attachment,
+ GIP_CMD_INITIAL_REPORTS_REQUEST, 0, &request,
+ sizeof(request));
+ }
+
usb_make_path(attachment->device->udev, attachment->phys,
sizeof(attachment->phys));
len = strlen(attachment->phys);
@@ -1689,7 +1779,8 @@ static int gip_send_init_sequence(struct gip_attachment *attachment)
sizeof(attachment->phys) - len, "/input%d",
attachment->attachment_index);
- if (gip_attachment_is_controller(attachment) && !attachment->input) {
+ if (gip_attachment_is_controller(attachment) && !attachment->input
+ && attachment->attachment_type != GIP_TYPE_WHEEL) {
rc = gip_setup_input_device(attachment);
if (rc == -ENODEV)
return 0;
@@ -2006,6 +2097,13 @@ static int gip_handle_command_metadata_respose(struct gip_attachment *attachment
expected_guid = &guid_headset;
break;
}
+
+ if (strcmp(type, "Logi.Xbox.Input.TrueForceWheel") == 0) {
+ attachment->attachment_type = GIP_TYPE_WHEEL;
+ attachment->vendor_type = GIP_VENDOR_LOGI_TRUE_FORCE_WHEEL;
+ expected_guid = &guid_logi_true_force_wheel;
+ break;
+ }
}
found_expected_guid = !expected_guid;
@@ -2308,13 +2406,87 @@ static void gip_handle_arcade_stick_report(struct gip_attachment *attachment,
}
}
+static void gip_handle_wheel_report(struct gip_attachment *attachment,
+ struct input_dev *dev, const uint8_t *bytes, int num_bytes)
+{
+ int32_t axis;
+
+ if (num_bytes < 16)
+ return;
+
+ axis = bytes[2];
+ axis |= bytes[3] << 8;
+ input_report_abs(dev, ABS_WHEEL, axis - 0x8000);
+
+ if (attachment->wheel.connections & GIP_WHEEL_THROTTLE_CONN) {
+ axis = bytes[4];
+ axis |= bytes[5] << 8;
+ input_report_abs(dev, ABS_GAS, axis);
+ }
+
+ if (attachment->wheel.connections & GIP_WHEEL_BRAKE_CONN) {
+ axis = bytes[6];
+ axis |= bytes[7] << 8;
+ input_report_abs(dev, ABS_BRAKE, axis);
+ }
+
+ if (attachment->wheel.connections & GIP_WHEEL_CLUTCH_CONN) {
+ axis = bytes[8];
+ axis |= bytes[9] << 8;
+ input_report_abs(dev, ABS_CLUTCH, axis);
+ }
+
+ if (attachment->wheel.connections & GIP_WHEEL_HANDBRAKE_CONN)
+ input_report_abs(dev, ABS_HANDBRAKE, bytes[10]);
+
+ if (attachment->wheel.shifter_type)
+ input_report_abs(dev, ABS_SHIFTER, (int8_t)bytes[12]);
+
+ if (attachment->vendor_type == GIP_VENDOR_LOGI_TRUE_FORCE_WHEEL && num_bytes >= 18) {
+ int dial = bytes[17] >> 5;
+
+ input_report_key(dev, BTN_THUMBL, bytes[17] & BIT(0));
+ input_report_key(dev, BTN_THUMBR, bytes[17] & BIT(1));
+ input_report_key(dev, KEY_KPPLUS, bytes[17] & BIT(2));
+ input_report_key(dev, KEY_KPMINUS, bytes[17] & BIT(3));
+ input_report_key(dev, KEY_KPENTER, bytes[17] & BIT(4));
+ if (dial == 0 && attachment->logi_dial_state == 7)
+ input_report_rel(dev, REL_DIAL, -1);
+ else if (dial == 7 && attachment->logi_dial_state == 0)
+ input_report_rel(dev, REL_DIAL, 1);
+ else
+ input_report_rel(dev, REL_DIAL,
+ attachment->logi_dial_state - dial);
+ attachment->logi_dial_state = dial;
+ }
+}
+
static int gip_handle_ll_input_report(struct gip_attachment *attachment,
const struct gip_header *header, const uint8_t *bytes, int num_bytes)
{
struct input_dev *dev = attachment->input;
- if (!dev)
- return -ENODEV;
+ if (!dev) {
+ if (attachment->attachment_type == GIP_TYPE_WHEEL) {
+ if (num_bytes < 17)
+ return -EINVAL;
+ attachment->wheel.max_gear = bytes[11] & 0x1F;
+ attachment->wheel.shifter_type = bytes[11] >> 5;
+ attachment->wheel.angle_setting = bytes[13];
+ attachment->wheel.angle_setting |= bytes[14] << 8;
+ attachment->wheel.connections = bytes[16];
+
+ if (attachment->quirks & GIP_QUIRK_WHEEL_FORCE_HANDBRAKE)
+ attachment->wheel.connections |= GIP_WHEEL_HANDBRAKE_CONN;
+
+ if (attachment->wheel.angle_setting && attachment->wheel.max_angle)
+ return gip_setup_input_device(attachment);
+ else
+ return 0;
+ } else {
+ return -ENODEV;
+ }
+ }
if (attachment->device_state != GIP_STATE_START) {
dev_dbg(GIP_DEV(attachment), "Discarding early input report\n");
@@ -2337,6 +2509,14 @@ static int gip_handle_ll_input_report(struct gip_attachment *attachment,
case GIP_TYPE_ARCADE_STICK:
gip_handle_arcade_stick_report(attachment, dev, bytes, num_bytes);
break;
+ case GIP_TYPE_WHEEL:
+ gip_handle_wheel_report(attachment, dev, bytes, num_bytes);
+ break;
+ }
+
+ if (attachment->quirks & GIP_QUIRK_FORCE_GAMEPAD_SB) {
+ input_report_key(dev, BTN_THUMBL, bytes[1] & BIT(6));
+ input_report_key(dev, BTN_THUMBR, bytes[1] & BIT(7));
}
if (attachment->features & GIP_FEATURE_ELITE_BUTTONS) {
@@ -2414,9 +2594,22 @@ static int gip_handle_ll_input_report(struct gip_attachment *attachment,
static int gip_handle_ll_static_configuration(struct gip_attachment *attachment,
const struct gip_header *header, const uint8_t *bytes, int num_bytes)
{
- /* TODO */
- dev_dbg(GIP_DEV(attachment), "Unimplemented Static Configuration message\n");
- return -ENOTSUPP;
+ if (attachment->attachment_type == GIP_TYPE_WHEEL) {
+ if (num_bytes < 11)
+ return -EINVAL;
+ attachment->wheel.max_angle = BIT(bytes[0]) - 1;
+ attachment->wheel.max_throttle = BIT(bytes[1]) - 1;
+ attachment->wheel.max_brake = BIT(bytes[2]) - 1;
+ attachment->wheel.max_clutch = BIT(bytes[3]) - 1;
+ attachment->wheel.max_handbrake = BIT(bytes[4]) - 1;
+ if (attachment->wheel.angle_setting && attachment->wheel.max_angle)
+ return gip_setup_input_device(attachment);
+ } else {
+ /* TODO */
+ dev_dbg(GIP_DEV(attachment), "Unimplemented Static Configuration message\n");
+ return -ENOTSUPP;
+ }
+ return 0;
}
static int gip_handle_ll_button_info_report(struct gip_attachment *attachment,
--
2.51.0
^ permalink raw reply related
* [PATCH v2 3/5] Input: Add ABS_CLUTCH, HANDBRAKE, and SHIFTER
From: Vicki Pfau @ 2025-09-17 1:19 UTC (permalink / raw)
To: Dmitry Torokhov, linux-input; +Cc: Vicki Pfau
In-Reply-To: <20250917011937.1649481-1-vi@endrift.com>
Add new absolute axes for racing game controllers
Signed-off-by: Vicki Pfau <vi@endrift.com>
---
drivers/hid/hid-debug.c | 16 +++++++++-------
include/uapi/linux/input-event-codes.h | 3 +++
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c
index 7107071c7c516..77a050ffaa35b 100644
--- a/drivers/hid/hid-debug.c
+++ b/drivers/hid/hid-debug.c
@@ -3505,13 +3505,15 @@ static const char *absolutes[ABS_CNT] = {
[ABS_RY] = "Ry", [ABS_RZ] = "Rz",
[ABS_THROTTLE] = "Throttle", [ABS_RUDDER] = "Rudder",
[ABS_WHEEL] = "Wheel", [ABS_GAS] = "Gas",
- [ABS_BRAKE] = "Brake", [ABS_HAT0X] = "Hat0X",
- [ABS_HAT0Y] = "Hat0Y", [ABS_HAT1X] = "Hat1X",
- [ABS_HAT1Y] = "Hat1Y", [ABS_HAT2X] = "Hat2X",
- [ABS_HAT2Y] = "Hat2Y", [ABS_HAT3X] = "Hat3X",
- [ABS_HAT3Y] = "Hat 3Y", [ABS_PRESSURE] = "Pressure",
- [ABS_DISTANCE] = "Distance", [ABS_TILT_X] = "XTilt",
- [ABS_TILT_Y] = "YTilt", [ABS_TOOL_WIDTH] = "ToolWidth",
+ [ABS_BRAKE] = "Brake", [ABS_CLUTCH] = "Clutch",
+ [ABS_HANDBRAKE] = "Handbrake", [ABS_SHIFTER] = "Shifter",
+ [ABS_HAT0X] = "Hat0X", [ABS_HAT0Y] = "Hat0Y",
+ [ABS_HAT1X] = "Hat1X", [ABS_HAT1Y] = "Hat1Y",
+ [ABS_HAT2X] = "Hat2X", [ABS_HAT2Y] = "Hat2Y",
+ [ABS_HAT3X] = "Hat3X", [ABS_HAT3Y] = "Hat3Y",
+ [ABS_PRESSURE] = "Pressure", [ABS_DISTANCE] = "Distance",
+ [ABS_TILT_X] = "XTilt", [ABS_TILT_Y] = "YTilt",
+ [ABS_TOOL_WIDTH] = "ToolWidth",
[ABS_VOLUME] = "Volume", [ABS_PROFILE] = "Profile",
[ABS_MISC] = "Misc",
[ABS_MT_SLOT] = "MTSlot",
diff --git a/include/uapi/linux/input-event-codes.h b/include/uapi/linux/input-event-codes.h
index ca5851e97fac0..54c61f92b1d40 100644
--- a/include/uapi/linux/input-event-codes.h
+++ b/include/uapi/linux/input-event-codes.h
@@ -862,6 +862,9 @@
#define ABS_WHEEL 0x08
#define ABS_GAS 0x09
#define ABS_BRAKE 0x0a
+#define ABS_CLUTCH 0x0b
+#define ABS_HANDBRAKE 0x0c
+#define ABS_SHIFTER 0x0d
#define ABS_HAT0X 0x10
#define ABS_HAT0Y 0x11
#define ABS_HAT1X 0x12
--
2.51.0
^ permalink raw reply related
* [PATCH v2 4/5] HID: Map more automobile simulation inputs
From: Vicki Pfau @ 2025-09-17 1:19 UTC (permalink / raw)
To: Dmitry Torokhov, linux-input; +Cc: Vicki Pfau, Jiri Kosina
In-Reply-To: <20250917011937.1649481-1-vi@endrift.com>
The HID usage tables section 5.3 specify clutch and shifter values that had
previously been ignored. As the ABS_CLUTCH and ABS_SHIFTER bits now exist,
we should use them appropriately.
Signed-off-by: Vicki Pfau <vi@endrift.com>
Acked-by: Jiri Kosina <jkosina@suse.com>
---
drivers/hid/hid-input.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index ff1784b5c2a47..adcffbcb30834 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -782,6 +782,8 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
case 0xbb: map_abs(ABS_THROTTLE); break;
case 0xc4: map_abs(ABS_GAS); break;
case 0xc5: map_abs(ABS_BRAKE); break;
+ case 0xc6: map_abs(ABS_CLUTCH); break;
+ case 0xc7: map_abs(ABS_SHIFTER); break;
case 0xc8: map_abs(ABS_WHEEL); break;
default: goto ignore;
}
--
2.51.0
^ permalink raw reply related
* [PATCH v2 1/5] Input: xbox_gip - Add new driver for Xbox GIP
From: Vicki Pfau @ 2025-09-17 1:19 UTC (permalink / raw)
To: Dmitry Torokhov, linux-input; +Cc: Vicki Pfau
In-Reply-To: <20250917011937.1649481-1-vi@endrift.com>
This introduces a new driver for the Xbox One/Series controller protocol,
officially known as the Gaming Input Protocol, or GIP for short.
Microsoft released documentation on (some of) GIP in late 2024, upon which
this driver is based. Though the documentation was incomplete, it still
provided enough information to warrant a clean start over the previous,
incomplete implementation.
This driver is already at feature parity with the GIP support in xpad,
along with several more enhancements:
- Proper support for parsing message length and fragmented messages
- Metadata parsing, allowing for auto-detection on various parameters,
including the presence and location in the message of the share button,
as well as detection of specific device types
- Controllable LED support
- HID passthrough for the Chatpad
The framework set out in this driver also allows future expansion for
specialized device types and additional features more cleanly than xpad.
Future plans include:
- Adding support for more device types, such as racing wheels and flight
sticks.
- Support for the security handshake, which is required for devices that
use wireless dongles.
- Exposing a raw character device to enable sending vendor-specific
commands from userspace.
- Event logging to either sysfs or dmesg.
- Support for the headphone jack.
- Splitting the driver into separate drivers treating gip as a bus with
each attachment being able to have its own gip_driver defined by a
preferred type and/or GUID.
Signed-off-by: Vicki Pfau <vi@endrift.com>
---
MAINTAINERS | 6 +
drivers/input/joystick/Kconfig | 26 +
drivers/input/joystick/Makefile | 1 +
drivers/input/joystick/xbox_gip.c | 3122 +++++++++++++++++++++++++++++
4 files changed, 3155 insertions(+)
create mode 100644 drivers/input/joystick/xbox_gip.c
diff --git a/MAINTAINERS b/MAINTAINERS
index daf520a13bdf6..1c08ab283cfb8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -27374,6 +27374,12 @@ S: Maintained
F: drivers/media/rc/keymaps/rc-xbox-dvd.c
F: drivers/media/rc/xbox_remote.c
+XBOX GIP
+M: Vicki Pfau <vi@endrift.com>
+L: linux-input@vger.kernel.org
+S: Maintained
+F: drivers/input/joystick/xbox_gip.c
+
XC2028/3028 TUNER DRIVER
M: Mauro Carvalho Chehab <mchehab@kernel.org>
L: linux-media@vger.kernel.org
diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig
index 7755e5b454d2c..609edc8d78c5d 100644
--- a/drivers/input/joystick/Kconfig
+++ b/drivers/input/joystick/Kconfig
@@ -291,6 +291,32 @@ config JOYSTICK_JOYDUMP
To compile this driver as a module, choose M here: the
module will be called joydump.
+config JOYSTICK_XBOX_GIP
+ tristate "Xbox One/Series controller support"
+ depends on USB_ARCH_HAS_HCD
+ select USB
+ help
+ Say Y here if you want to use Xbox One and Series controllers with your
+ computer. Make sure to say Y to "Joystick support" (CONFIG_INPUT_JOYDEV)
+ and/or "Event interface support" (CONFIG_INPUT_EVDEV) as well.
+
+ To compile this driver as a module, choose M here: the
+ module will be called xbox_gip.
+
+config JOYSTICK_XBOX_GIP_FF
+ bool "Xbox One/Series controller rumble support"
+ depends on JOYSTICK_XBOX_GIP && INPUT
+ select INPUT_FF_MEMLESS
+ help
+ Say Y here if you want to take advantage of Xbox One/Series rumble.
+
+config JOYSTICK_XBOX_GIP_LEDS
+ bool "LED Support for the Xbox One/Series controller Guide button"
+ depends on JOYSTICK_XBOX_GIP && LEDS_CLASS_MULTICOLOR
+ help
+ This option enables support for the LED which surrounds the Big X on
+ Xbox One/Series controllers.
+
config JOYSTICK_XPAD
tristate "Xbox gamepad support"
depends on USB_ARCH_HAS_HCD
diff --git a/drivers/input/joystick/Makefile b/drivers/input/joystick/Makefile
index 9976f596a9208..ad92f1b64b96a 100644
--- a/drivers/input/joystick/Makefile
+++ b/drivers/input/joystick/Makefile
@@ -39,5 +39,6 @@ obj-$(CONFIG_JOYSTICK_TURBOGRAFX) += turbografx.o
obj-$(CONFIG_JOYSTICK_TWIDJOY) += twidjoy.o
obj-$(CONFIG_JOYSTICK_WARRIOR) += warrior.o
obj-$(CONFIG_JOYSTICK_WALKERA0701) += walkera0701.o
+obj-$(CONFIG_JOYSTICK_XBOX_GIP) += xbox_gip.o
obj-$(CONFIG_JOYSTICK_XPAD) += xpad.o
obj-$(CONFIG_JOYSTICK_ZHENHUA) += zhenhua.o
diff --git a/drivers/input/joystick/xbox_gip.c b/drivers/input/joystick/xbox_gip.c
new file mode 100644
index 0000000000000..94e20ab4b672c
--- /dev/null
+++ b/drivers/input/joystick/xbox_gip.c
@@ -0,0 +1,3122 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Gaming Input Protocol driver for Xbox One/Series controllers
+ *
+ * Copyright (c) 2025 Valve Software
+ *
+ * TODO:
+ * - Audio device support
+ * - Security packet handshake
+ * - Event logging
+ * - Sending fragmented messages
+ * - Raw character device
+ * - Wheel support
+ * - Flight stick support
+ * - More arcade stick testing
+ * - Arcade stick extra buttons
+ * - Split into driver-per-attachment GIP-as-a-bus approach drivers
+ *
+ * This driver is based on the Microsoft GIP spec at:
+ * https://aka.ms/gipdocs
+ * https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-gipusb/e7c90904-5e21-426e-b9ad-d82adeee0dbc
+ */
+
+#include <linux/hid.h>
+#include <linux/module.h>
+#include <linux/usb/input.h>
+#include <linux/uuid.h>
+#ifdef CONFIG_JOYSTICK_XBOX_GIP_LEDS
+#include <linux/led-class-multicolor.h>
+#endif
+
+#define GIP_WIRED_INTF_DATA 0
+#define GIP_WIRED_INTF_AUDIO 1
+
+#define BASE_GIP_MTU 64
+#define MAX_GIP_MTU 2048
+
+#define MAX_MESSAGE_LENGTH 0x4000
+#define MAX_ATTACHMENTS 8
+
+#define MAX_IN_MESSAGES 8
+#define MAX_OUT_MESSAGES 8
+
+#define GIP_DATA_CLASS_COMMAND (0u << 5)
+#define GIP_DATA_CLASS_LOW_LATENCY (1u << 5)
+#define GIP_DATA_CLASS_STANDARD_LATENCY (2u << 5)
+#define GIP_DATA_CLASS_AUDIO (3u << 5)
+
+#define GIP_DATA_CLASS_SHIFT 5
+#define GIP_DATA_CLASS_MASK (7u << 5)
+
+/* System messages */
+#define GIP_CMD_PROTO_CONTROL 0x01
+#define GIP_CMD_HELLO_DEVICE 0x02
+#define GIP_CMD_STATUS_DEVICE 0x03
+#define GIP_CMD_METADATA 0x04
+#define GIP_CMD_SET_DEVICE_STATE 0x05
+#define GIP_CMD_SECURITY 0x06
+#define GIP_CMD_GUIDE_BUTTON 0x07
+#define GIP_CMD_AUDIO_CONTROL 0x08
+#define GIP_CMD_LED 0x0a
+#define GIP_CMD_HID_REPORT 0x0b
+#define GIP_CMD_FIRMWARE 0x0c
+#define GIP_CMD_EXTENDED 0x1e
+#define GIP_CMD_DEBUG 0x1f
+#define GIP_AUDIO_DATA 0x60
+
+/* Navigation vendor messages */
+#define GIP_CMD_DIRECT_MOTOR 0x09
+#define GIP_LL_INPUT_REPORT 0x20
+#define GIP_LL_OVERFLOW_INPUT_REPORT 0x26
+
+/* Wheel and ArcadeStick vendor messages */
+#define GIP_CMD_INITIAL_REPORTS_REQUEST 0x0a
+#define GIP_LL_STATIC_CONFIGURATION 0x21
+#define GIP_LL_BUTTON_INFO_REPORT 0x22
+
+/* Wheel vendor messages */
+#define GIP_CMD_SET_APPLICATION_MEMORY 0x0b
+#define GIP_CMD_SET_EQUATIONS_STATES 0x0c
+#define GIP_CMD_SET_EQUATION 0x0d
+
+/* FlightStick vendor messages */
+#define GIP_CMD_DEVICE_CAPABILITIES 0x00
+#define GIP_CMD_LED_CAPABILITIES 0x01
+#define GIP_CMD_SET_LED_STATE 0x02
+
+/* Undocumented Elite 2 vendor messages */
+#define GIP_CMD_RAW_REPORT 0x0c
+#define GIP_CMD_GUIDE_COLOR 0x0e
+#define GIP_SL_ELITE_CONFIG 0x4d
+
+#define GIP_BTN_OFFSET_XBE1 28
+#define GIP_BTN_OFFSET_XBE2 14
+
+#define GIP_FLAG_FRAGMENT BIT(7)
+#define GIP_FLAG_INIT_FRAG BIT(6)
+#define GIP_FLAG_SYSTEM BIT(5)
+#define GIP_FLAG_ACME BIT(4)
+#define GIP_FLAG_ATTACHMENT_MASK 0x7
+
+#define GIP_AUDIO_FORMAT_NULL 0
+#define GIP_AUDIO_FORMAT_8000HZ_1CH 1
+#define GIP_AUDIO_FORMAT_8000HZ_2CH 2
+#define GIP_AUDIO_FORMAT_12000HZ_1CH 3
+#define GIP_AUDIO_FORMAT_12000HZ_2CH 4
+#define GIP_AUDIO_FORMAT_16000HZ_1CH 5
+#define GIP_AUDIO_FORMAT_16000HZ_2CH 6
+#define GIP_AUDIO_FORMAT_20000HZ_1CH 7
+#define GIP_AUDIO_FORMAT_20000HZ_2CH 8
+#define GIP_AUDIO_FORMAT_24000HZ_1CH 9
+#define GIP_AUDIO_FORMAT_24000HZ_2CH 10
+#define GIP_AUDIO_FORMAT_32000HZ_1CH 11
+#define GIP_AUDIO_FORMAT_32000HZ_2CH 12
+#define GIP_AUDIO_FORMAT_40000HZ_1CH 13
+#define GIP_AUDIO_FORMAT_40000HZ_2CH 14
+#define GIP_AUDIO_FORMAT_48000HZ_1CH 15
+#define GIP_AUDIO_FORMAT_48000HZ_2CH 16
+#define GIP_AUDIO_FORMAT_48000HZ_6CH 32
+#define GIP_AUDIO_FORMAT_48000HZ_8CH 33
+#define MAX_GIP_AUDIO_FORMAT GIP_AUDIO_FORMAT_48000HZ_8CH
+
+/* Protocol Control constants */
+#define GIP_CONTROL_CODE_ACK 0
+#define GIP_CONTROL_CODE_NACK 1 /* obsolete */
+#define GIP_CONTROL_CODE_UNK 2 /* obsolete */
+#define GIP_CONTROL_CODE_AB 3 /* obsolete */
+#define GIP_CONTROL_CODE_MPER 4 /* obsolete */
+#define GIP_CONTROL_CODE_STOP 5 /* obsolete */
+#define GIP_CONTROL_CODE_START 6 /* obsolete */
+#define GIP_CONTROL_CODE_ERR 7 /* obsolete */
+
+/* Status Device constants */
+#define GIP_POWER_LEVEL_OFF 0
+#define GIP_POWER_LEVEL_STANDBY 1 /* obsolete */
+#define GIP_POWER_LEVEL_FULL 2
+
+#define GIP_NOT_CHARGING 0
+#define GIP_CHARGING 1
+#define GIP_CHARGE_ERROR 2
+
+#define GIP_BATTERY_ABSENT 0
+#define GIP_BATTERY_STANDARD 1
+#define GIP_BATTERY_RECHARGEABLE 2
+
+#define GIP_BATTERY_CRITICAL 0
+#define GIP_BATTERY_LOW 1
+#define GIP_BATTERY_MEDIUM 2
+#define GIP_BATTERY_FULL 3
+
+#define GIP_EVENT_FAULT 0x0002
+
+#define GIP_FAULT_UNKNOWN 0
+#define GIP_FAULT_HARD 1
+#define GIP_FAULT_NMI 2
+#define GIP_FAULT_SVC 3
+#define GIP_FAULT_PEND_SV 4
+#define GIP_FAULT_SMART_PTR 5
+#define GIP_FAULT_MCU 6
+#define GIP_FAULT_BUS 7
+#define GIP_FAULT_USAGE 8
+#define GIP_FAULT_RADIO_HANG 9
+#define GIP_FAULT_WATCHDOG 10
+#define GIP_FAULT_LINK_STALL 11
+#define GIP_FAULT_ASSERTION 12
+
+/* Metadata constants */
+#define GIP_MESSAGE_FLAG_BIG_ENDIAN BIT(0)
+#define GIP_MESSAGE_FLAG_RELIABLE BIT(1)
+#define GIP_MESSAGE_FLAG_SEQUENCED BIT(2)
+#define GIP_MESSAGE_FLAG_DOWNSTREAM BIT(3)
+#define GIP_MESSAGE_FLAG_UPSTREAM BIT(4)
+#define GIP_MESSAGE_FLAG_DS_REQUEST_RESPONSE BIT(5)
+
+#define GIP_DATA_TYPE_CUSTOM 1
+#define GIP_DATA_TYPE_AUDIO 2
+#define GIP_DATA_TYPE_SECURITY 3
+#define GIP_DATA_TYPE_GIP 4
+
+/* Set Device State constants */
+#define GIP_STATE_START 0
+#define GIP_STATE_STOP 1
+#define GIP_STATE_STANDBY 2 /* obsolete */
+#define GIP_STATE_FULL_POWER 3
+#define GIP_STATE_OFF 4
+#define GIP_STATE_QUIESCE 5
+#define GIP_STATE_UNK6 6
+#define GIP_STATE_RESET 7
+
+/* Guide Button Status constants */
+#define GIP_LED_GUIDE 0
+#define GIP_LID_IR 1 /* deprecated, for Kinect */
+
+#define GIP_LED_GUIDE_OFF 0
+#define GIP_LED_GUIDE_ON 1
+#define GIP_LED_GUIDE_FAST_BLINK 2
+#define GIP_LED_GUIDE_SLOW_BLINK 3
+#define GIP_LED_GUIDE_CHARGING_BLINK 4
+#define GIP_LED_GUIDE_RAMP_TO_LEVEL 0xd
+
+#define GIP_LED_IR_OFF 0
+#define GIP_LED_IR_ON_100MS 1
+#define GIP_LED_IR_PATTERN 4
+
+/* Direct Motor Command constants */
+#define GIP_MOTOR_RIGHT_VIBRATION BIT(0)
+#define GIP_MOTOR_LEFT_VIBRATION BIT(1)
+#define GIP_MOTOR_RIGHT_IMPULSE BIT(2)
+#define GIP_MOTOR_LEFT_IMPULSE BIT(3)
+#define GIP_MOTOR_ALL 0xF
+
+/* Extended Command constants */
+#define GIP_EXTCMD_GET_CAPABILITIES 0x00
+#define GIP_EXTCMD_GET_TELEMETRY_DATA 0x01
+#define GIP_EXTCMD_GET_SERIAL_NUMBER 0x04
+
+#define GIP_EXTENDED_STATUS_OK 0
+#define GIP_EXTENDED_STATUS_NOT_SUPPORTED 1
+#define GIP_EXTENDED_STATUS_NOT_READY 2
+#define GIP_EXTENDED_STATUS_ACCESS_DENIED 3
+#define GIP_EXTENDED_STATUS_FAILED 4
+
+/* Internal constants, not part of protocol */
+#define GIP_DEFAULT_IN_SYSTEM_MESSAGES 0x5e
+#define GIP_DEFAULT_OUT_SYSTEM_MESSAGES 0x472
+
+#define GIP_FEATURE_CONSOLE_FUNCTION_MAP BIT(0)
+#define GIP_FEATURE_CONSOLE_FUNCTION_MAP_OVERFLOW BIT(1)
+#define GIP_FEATURE_ELITE_BUTTONS BIT(2)
+#define GIP_FEATURE_DYNAMIC_LATENCY_INPUT BIT(3)
+#define GIP_FEATURE_SECURITY_OPT_OUT BIT(4)
+#define GIP_FEATURE_MOTOR_CONTROL BIT(5)
+#define GIP_FEATURE_GUIDE_COLOR BIT(6)
+#define GIP_FEATURE_EXTENDED_SET_DEVICE_STATE BIT(7)
+
+#define GIP_QUIRK_NO_HELLO BIT(0)
+#define GIP_QUIRK_NO_IMPULSE_VIBRATION BIT(1)
+
+#define GIP_LED_GUIDE_MAX_BRIGHTNESS 100 /* Spec says 47, but larger values work */
+#define GIP_LED_GUIDE_INIT_BRIGHTNESS 20
+
+#define GIP_DEV(p) \
+ _Generic((p), \
+ struct gip_attachment * : gip_attachment_dev, \
+ struct gip_interface * : gip_interface_dev, \
+ struct gip_device * : gip_device_dev)(p)
+
+static bool dpad_as_buttons;
+
+enum gip_metadata_status {
+ GIP_METADATA_NONE = 0,
+ GIP_METADATA_GOT = 1,
+ GIP_METADATA_FAKED = 2,
+ GIP_METADATA_PENDING = 3,
+};
+
+#ifndef VK_LWIN
+#define VK_LWIN 0x5b
+#endif
+
+enum gip_attachment_type {
+ GIP_TYPE_UNKNOWN = -1,
+ GIP_TYPE_GAMEPAD = 0,
+ GIP_TYPE_ARCADE_STICK = 1,
+ GIP_TYPE_WHEEL = 2,
+ GIP_TYPE_FLIGHT_STICK = 3,
+ GIP_TYPE_NAVIGATION_CONTROLLER = 4,
+ GIP_TYPE_CHATPAD = 5,
+ GIP_TYPE_HEADSET = 6,
+};
+
+enum gip_elite_button_format {
+ GIP_BTN_FMT_UNKNOWN,
+ GIP_BTN_FMT_XBE1,
+ GIP_BTN_FMT_XBE2_RAW,
+ GIP_BTN_FMT_XBE2_4,
+ GIP_BTN_FMT_XBE2_5,
+};
+
+static const guid_t guid_arcade_stick =
+ GUID_INIT(0x332054cc, 0xa34b, 0x41d5, 0xa3, 0x4a, 0xa6, 0xa6, 0x71, 0x1e, 0xc4, 0xb3);
+static const guid_t guid_console_function_map =
+ GUID_INIT(0xecddd2fe, 0xd387, 0x4294, 0xbd, 0x96, 0x1a, 0x71, 0x2e, 0x3d, 0xc7, 0x7d);
+static const guid_t guid_console_function_map_overflow =
+ GUID_INIT(0x137d4bd0, 0x9347, 0x4472, 0xaa, 0x26, 0x8c, 0x34, 0xa0, 0x8f, 0xf9, 0xbd);
+static const guid_t guid_controller =
+ GUID_INIT(0x9776ff56, 0x9bfd, 0x4581, 0xad, 0x45, 0xb6, 0x45, 0xbb, 0xa5, 0x26, 0xd6);
+static const guid_t guid_dev_auth_pc_opt_out =
+ GUID_INIT(0x7a34ce77, 0x7de2, 0x45c6, 0x8c, 0xa4, 0x00, 0x42, 0xc0, 0x8b, 0xd9, 0x4a);
+static const guid_t guid_dynamic_latency_input =
+ GUID_INIT(0x87f2e56b, 0xc3bb, 0x49b1, 0x82, 0x65, 0xff, 0xff, 0xf3, 0x77, 0x99, 0xee);
+static const guid_t guid_elite_buttons =
+ GUID_INIT(0x37d19ff7, 0xb5c6, 0x49d1, 0xa7, 0x5e, 0x03, 0xb2, 0x4b, 0xef, 0x8c, 0x89);
+static const guid_t guid_flight_stick =
+ GUID_INIT(0x03f1a011, 0xefe9, 0x4cc1, 0x96, 0x9c, 0x38, 0xdc, 0x55, 0xf4, 0x04, 0xd0);
+static const guid_t guid_gamepad =
+ GUID_INIT(0x082e402c, 0x07df, 0x45e1, 0xa5, 0xab, 0xa3, 0x12, 0x7a, 0xf1, 0x97, 0xb5);
+static const guid_t guid_headset =
+ GUID_INIT(0xbc25d1a3, 0xc24e, 0x4992, 0x9d, 0xda, 0xef, 0x4f, 0x12, 0x3e, 0xf5, 0xdc);
+static const guid_t guid_navigation =
+ GUID_INIT(0xb8f31fe7, 0x7386, 0x40e9, 0xa9, 0xf8, 0x2f, 0x21, 0x26, 0x3a, 0xcf, 0xb7);
+static const guid_t guid_wheel =
+ GUID_INIT(0x646979cf, 0x6b71, 0x4e96, 0x8d, 0xf9, 0x59, 0xe3, 0x98, 0xd7, 0x42, 0x0c);
+
+static const guid_t guid_logi_true_force_wheel =
+ GUID_INIT(0x6ca319e5, 0x0bc0, 0x41be, 0x83, 0x19, 0x6b, 0xb7, 0x10, 0x81, 0xec, 0x55);
+
+/*
+ * The following GUIDs are observed, but the exact meanings aren't known, so
+ * for now we document them but don't use them anywhere.
+ *
+ * GamepadEmu: GUID_INIT(0xe2e5f1bc, 0xa6e6, 0x41a2, 0x8f, 0x43, 0x33, 0xcf, 0xa2, 0x51, 0x09, 0x81)
+ * IAudioOnly: GUID_INIT(0x92844cd1, 0xf7c8, 0x49ef, 0x97, 0x77, 0x46, 0x7d, 0xa7, 0x08, 0xad, 0x10)
+ * IControllerProfileModeState: GUID_INIT(0xf758dc66, 0x022c, 0x48b8, 0xa4, 0xf6, 0x45, 0x7b, 0xa8, 0x0e, 0x2a, 0x5b)
+ * ICustomAudio: GUID_INIT(0x63fd9cc9, 0x94ee, 0x4b5d, 0x9c, 0x4d, 0x8b, 0x86, 0x4c, 0x14, 0x9c, 0xac)
+ * IExtendedDeviceFlags: GUID_INIT(0x34ad9b1e, 0x36ad, 0x4fb5, 0x8a, 0xc7, 0x17, 0x23, 0x4c, 0x9f, 0x54, 0x6f)
+ * IProgrammableGamepad: GUID_INIT(0x31c1034d, 0xb5b7, 0x4551, 0x98, 0x13, 0x87, 0x69, 0xd4, 0xa0, 0xe4, 0xf9)
+ * IVirtualDevice: GUID_INIT(0xdfd26825, 0x110a, 0x4e94, 0xb9, 0x37, 0xb2, 0x7c, 0xe4, 0x7b, 0x25, 0x40)
+ * OnlineDevAuth: GUID_INIT(0x632b1fd1, 0xa3e9, 0x44f9, 0x84, 0x20, 0x5c, 0xe3, 0x44, 0xa0, 0x64, 0x04)
+ *
+ * Seen on Elite Controller, Adaptive Controller: 9ebd00a3-b5e6-4c08-a33b-673126459ec4
+ * Seen on Adaptive Controller: ce1e58c5-221c-4bdb-9c24-bf3941601320
+ * Seen on Elite 2 Controller: f758dc66-022c-48b8-a4f6-457ba80e2a5b (IControllerProfileModeState)
+ * Seen on Elite 2 Controller: 31c1034d-b5b7-4551-9813-8769d4a0e4f9 (IProgrammableGamepad)
+ * Seen on Elite 2 Controller: 34ad9b1e-36ad-4fb5-8ac7-17234c9f546f (IExtendedDeviceFlags)
+ * Seen on Elite 2 Controller: 88e0b694-6bd9-4416-a560-e7fafdfa528f
+ * Seen on Elite 2 Controller: ea96c8c0-b216-448b-be80-7e5deb0698e2
+ */
+
+static const int gip_data_class_mtu[8] = { 64, 64, 64, 2048, 0, 0, 0, 0 };
+
+struct gip_audio_format {
+ uint16_t rate;
+ uint8_t channels;
+};
+
+static const struct gip_audio_format gip_audio_format_table[MAX_GIP_AUDIO_FORMAT + 1] = {
+ [GIP_AUDIO_FORMAT_8000HZ_1CH] = { .rate = 8000, .channels = 1 },
+ [GIP_AUDIO_FORMAT_8000HZ_2CH] = { .rate = 8000, .channels = 2 },
+ [GIP_AUDIO_FORMAT_12000HZ_1CH] = { .rate = 12000, .channels = 1 },
+ [GIP_AUDIO_FORMAT_12000HZ_2CH] = { .rate = 12000, .channels = 2 },
+ [GIP_AUDIO_FORMAT_16000HZ_1CH] = { .rate = 16000, .channels = 1 },
+ [GIP_AUDIO_FORMAT_16000HZ_2CH] = { .rate = 16000, .channels = 2 },
+ [GIP_AUDIO_FORMAT_20000HZ_1CH] = { .rate = 20000, .channels = 1 },
+ [GIP_AUDIO_FORMAT_20000HZ_2CH] = { .rate = 20000, .channels = 2 },
+ [GIP_AUDIO_FORMAT_24000HZ_1CH] = { .rate = 24000, .channels = 1 },
+ [GIP_AUDIO_FORMAT_24000HZ_2CH] = { .rate = 24000, .channels = 2 },
+ [GIP_AUDIO_FORMAT_32000HZ_1CH] = { .rate = 32000, .channels = 1 },
+ [GIP_AUDIO_FORMAT_32000HZ_2CH] = { .rate = 32000, .channels = 2 },
+ [GIP_AUDIO_FORMAT_40000HZ_1CH] = { .rate = 40000, .channels = 1 },
+ [GIP_AUDIO_FORMAT_40000HZ_2CH] = { .rate = 40000, .channels = 2 },
+ [GIP_AUDIO_FORMAT_48000HZ_1CH] = { .rate = 48000, .channels = 1 },
+ [GIP_AUDIO_FORMAT_48000HZ_2CH] = { .rate = 48000, .channels = 2 },
+ [GIP_AUDIO_FORMAT_48000HZ_6CH] = { .rate = 48000, .channels = 6 },
+ [GIP_AUDIO_FORMAT_48000HZ_8CH] = { .rate = 48000, .channels = 8 },
+};
+
+struct gip_quirks {
+ uint16_t vendor_id;
+ uint16_t product_id;
+ uint8_t attachment_index;
+ const char *override_name;
+ uint32_t added_features;
+ uint32_t filtered_features;
+ uint32_t quirks;
+ uint32_t extra_in_system[8];
+ uint32_t extra_out_system[8];
+ enum gip_attachment_type device_type;
+ uint8_t extra_buttons;
+ uint8_t extra_axes;
+};
+
+static const struct gip_quirks quirks[] = {
+ /* Xbox One Controller (model 1573) */
+ { 0x045e, 0x02d1, 0, .override_name = "Xbox One Controller" },
+
+ /* Xbox One Controller (model 1697) */
+ { 0x045e, 0x02dd, 0, .override_name = "Xbox One Controller" },
+
+ /* Xbox Elite */
+ { 0x045e, 0x02e3, 0,
+ .override_name = "Xbox Elite Controller",
+ .added_features = GIP_FEATURE_ELITE_BUTTONS,
+ .filtered_features = GIP_FEATURE_CONSOLE_FUNCTION_MAP },
+
+ /* Xbox One Controller (model 1708) */
+ { 0x045e, 0x02ea, 0, .override_name = "Xbox One Controller" },
+
+ /* Xbox Elite 2 */
+ { 0x045e, 0x0b00, 0,
+ .override_name = "Xbox Elite Series 2 Controller",
+ .added_features = GIP_FEATURE_GUIDE_COLOR | GIP_FEATURE_EXTENDED_SET_DEVICE_STATE },
+
+ /* Xbox Adaptive Controller */
+ { 0x045e, 0x0b0a, 0, .override_name = "Xbox Adaptive Controller" },
+
+ /* Xbox Wireless Controller */
+ { 0x045e, 0x0b12, 0, .override_name = "Xbox Wireless Controller" },
+
+ /* PDP Rock Candy */
+ { 0x0e6f, 0x0246, 0, .quirks = GIP_QUIRK_NO_HELLO },
+
+ {0},
+};
+
+struct gip_header {
+ uint8_t message_type;
+ uint8_t flags;
+ uint8_t sequence_id;
+ uint64_t length;
+};
+
+struct gip_audio_format_pair {
+ uint8_t inbound;
+ uint8_t outbound;
+};
+static_assert(sizeof(struct gip_audio_format_pair) == 2);
+
+struct gip_device_metadata {
+ uint8_t num_audio_formats;
+ uint8_t num_preferred_types;
+ uint8_t num_supported_interfaces;
+ uint8_t hid_descriptor_size;
+
+ uint32_t in_system_messages[8];
+ uint32_t out_system_messages[8];
+
+ struct gip_audio_format_pair *audio_formats;
+ char **preferred_types;
+ guid_t *supported_interfaces;
+ uint8_t *hid_descriptor;
+
+ enum gip_attachment_type device_type;
+};
+
+struct gip_message_metadata {
+ uint8_t type;
+ uint16_t length;
+ uint16_t data_type;
+ uint32_t flags;
+ uint16_t period;
+ uint16_t persistence_timeout;
+};
+
+struct gip_metadata {
+ uint16_t version_major;
+ uint16_t version_minor;
+
+ struct gip_device_metadata device;
+
+ uint8_t num_messages;
+ struct gip_message_metadata *message_metadata;
+};
+
+struct gip_device;
+struct gip_attachment {
+ struct gip_device *device;
+ uint8_t attachment_index;
+ struct input_dev *input;
+ uint16_t vendor_id;
+ uint16_t product_id;
+ char *uniq;
+ const char *name;
+ char phys[32];
+ char serial[32];
+ struct mutex lock;
+
+ uint8_t fragment_message;
+ uint16_t total_length;
+ uint8_t *fragment_data;
+ uint32_t fragment_offset;
+ struct delayed_work fragment_timeout;
+ int fragment_retries;
+
+ uint16_t firmware_major_version;
+ uint16_t firmware_minor_version;
+
+ enum gip_metadata_status got_metadata;
+ struct delayed_work metadata_next;
+ int metadata_retries;
+ struct gip_metadata metadata;
+
+ uint8_t seq_system;
+ uint8_t seq_security;
+ uint8_t seq_extended;
+ uint8_t seq_audio;
+ uint8_t seq_vendor;
+
+ int device_state;
+#ifdef CONFIG_JOYSTICK_XBOX_GIP_LEDS
+ union {
+ struct led_classdev standard;
+ struct led_classdev_mc color;
+ } guide_led;
+#endif
+
+ enum gip_attachment_type attachment_type;
+ enum gip_elite_button_format xbe_format;
+ uint32_t features;
+ uint32_t quirks;
+
+ int extra_buttons;
+ int extra_axes;
+
+ bool dpad_as_buttons;
+ struct hid_device *hdev;
+};
+
+struct gip_raw_message {
+ uint16_t num_bytes;
+ uint8_t bytes[BASE_GIP_MTU];
+};
+
+struct gip_interface {
+ struct gip_device *device;
+ struct usb_interface *intf;
+ uint32_t mtu;
+
+ struct urb *urb_in;
+ uint8_t *in_data;
+
+ struct urb *urb_out;
+ struct usb_anchor out_anchor;
+ bool urb_out_active;
+ uint8_t *out_data;
+
+ struct gip_raw_message out_queue[MAX_OUT_MESSAGES];
+ int pending_out;
+ int next_out;
+};
+
+struct gip_device {
+ struct usb_device *udev;
+
+ struct gip_interface data;
+
+ struct gip_raw_message in_queue[MAX_IN_MESSAGES];
+ int pending_in_messages;
+ int next_in_message;
+
+ struct work_struct receive_message;
+ spinlock_t message_lock;
+
+ struct gip_attachment *attachments[MAX_ATTACHMENTS];
+};
+
+struct gip_hello_device {
+ uint64_t device_id;
+ uint16_t vendor_id;
+ uint16_t product_id;
+ uint16_t firmware_major_version;
+ uint16_t firmware_minor_version;
+ uint16_t firmware_build_version;
+ uint16_t firmware_revision;
+ uint8_t hardware_major_version;
+ uint8_t hardware_minor_version;
+ uint8_t rf_proto_major_version;
+ uint8_t rf_proto_minor_version;
+ uint8_t security_major_version;
+ uint8_t security_minor_version;
+ uint8_t gip_major_version;
+ uint8_t gip_minor_version;
+};
+
+struct gip_status {
+ int power_level;
+ int charge;
+ int battery_type;
+ int battery_level;
+};
+
+struct gip_status_event {
+ uint16_t event_type;
+ uint32_t fault_tag;
+ uint32_t fault_address;
+};
+
+struct gip_extended_status {
+ struct gip_status base;
+ bool device_active;
+
+ int num_events;
+ struct gip_status_event events[5];
+};
+
+struct gip_direct_motor {
+ uint8_t command;
+ uint8_t motor_bitmap;
+ uint8_t left_impulse_level;
+ uint8_t right_impulse_level;
+ uint8_t left_vibration_level;
+ uint8_t right_vibration_level;
+ uint8_t duration;
+ uint8_t delay;
+ uint8_t repeat;
+};
+
+struct gip_initial_reports_request {
+ uint8_t type;
+ uint8_t data[2];
+};
+
+struct gip_device_capabilities_response {
+ uint8_t extra_button_count;
+ uint8_t extra_axis_count;
+ uint8_t led_count;
+ uint8_t max_global_led_gain;
+};
+
+static inline struct device *gip_attachment_dev(struct gip_attachment *attachment)
+{
+ return &attachment->device->udev->dev;
+}
+
+static inline struct device *gip_interface_dev(struct gip_interface *intf)
+{
+ return &intf->device->udev->dev;
+}
+
+static inline struct device *gip_device_dev(struct gip_device *device)
+{
+ return &device->udev->dev;
+}
+
+static int gip_decode_length(uint64_t *length, const uint8_t *bytes, int num_bytes)
+{
+ *length = 0;
+ int offset;
+
+ for (offset = 0; offset < num_bytes; offset++) {
+ uint8_t byte = bytes[offset];
+
+ *length |= (byte & 0x7full) << (offset * 7);
+ if (!(byte & 0x80)) {
+ offset++;
+ break;
+ }
+ }
+ return offset;
+}
+
+static int gip_encode_length(uint64_t length, uint8_t *bytes, int num_bytes)
+{
+ int offset;
+
+ for (offset = 0; offset < num_bytes; offset++) {
+ uint8_t byte = length & 0x7f;
+
+ length >>= 7;
+ if (length)
+ byte |= 0x80;
+ bytes[offset] = byte;
+ if (!length) {
+ offset++;
+ break;
+ }
+ }
+ return offset;
+}
+
+static bool gip_supports_system_message(struct gip_attachment *attachment,
+ uint8_t command, bool upstream)
+{
+ if (upstream)
+ return attachment->metadata.device
+ .in_system_messages[command >> 5] & (1u << command);
+ else
+ return attachment->metadata.device
+ .out_system_messages[command >> 5] & (1u << command);
+}
+
+static bool gip_supports_vendor_message(struct gip_attachment *attachment,
+ uint8_t command, bool upstream)
+{
+ size_t i;
+
+ for (i = 0; i < attachment->metadata.num_messages; i++) {
+ struct gip_message_metadata *metadata =
+ &attachment->metadata.message_metadata[i];
+
+ if (metadata->type != command)
+ continue;
+ if (metadata->flags & GIP_MESSAGE_FLAG_DS_REQUEST_RESPONSE)
+ return true;
+
+ if (upstream)
+ return metadata->flags & GIP_MESSAGE_FLAG_UPSTREAM;
+ else
+ return metadata->flags & GIP_MESSAGE_FLAG_DOWNSTREAM;
+ }
+ return false;
+}
+
+static uint8_t gip_sequence_next(struct gip_attachment *attachment,
+ uint8_t command, bool system)
+{
+ uint8_t seq;
+
+ if (system) {
+ switch (command) {
+ case GIP_CMD_SECURITY:
+ seq = attachment->seq_security++;
+ if (!seq)
+ seq = attachment->seq_security++;
+ break;
+ case GIP_CMD_EXTENDED:
+ seq = attachment->seq_extended++;
+ if (!seq)
+ seq = attachment->seq_extended++;
+ break;
+ case GIP_AUDIO_DATA:
+ seq = attachment->seq_audio++;
+ if (!seq)
+ seq = attachment->seq_audio++;
+ break;
+ default:
+ seq = attachment->seq_system++;
+ if (!seq)
+ seq = attachment->seq_system++;
+ break;
+ }
+ } else {
+ seq = attachment->seq_vendor++;
+ if (!seq)
+ seq = attachment->seq_vendor++;
+ }
+ return seq;
+}
+
+static void gip_handle_quirks(struct gip_attachment *attachment)
+{
+ size_t i, j;
+
+ for (i = 0; quirks[i].vendor_id; i++) {
+ if (quirks[i].vendor_id != attachment->vendor_id)
+ continue;
+ if (quirks[i].product_id != attachment->product_id)
+ continue;
+ if (quirks[i].attachment_index != attachment->attachment_index)
+ continue;
+
+ attachment->features |= quirks[i].added_features;
+ attachment->features &= ~quirks[i].filtered_features;
+ attachment->quirks = quirks[i].quirks;
+ attachment->attachment_type = quirks[i].device_type;
+
+ if (quirks[i].override_name)
+ attachment->name = quirks[i].override_name;
+
+ for (j = 0; j < 8; ++j) {
+ struct gip_device_metadata *metadata = &attachment->metadata.device;
+
+ metadata->in_system_messages[j] |= quirks[i].extra_in_system[j];
+ metadata->out_system_messages[j] |= quirks[i].extra_out_system[j];
+ }
+
+ attachment->extra_buttons = quirks[i].extra_buttons;
+ attachment->extra_axes = quirks[i].extra_axes;
+ break;
+ }
+}
+
+static int gip_prepare_urb(struct gip_interface *intf)
+{
+ int rc;
+
+ if (!intf->urb_out)
+ return -ENODEV;
+
+ struct gip_raw_message *message = &intf->out_queue[intf->next_out];
+
+ intf->pending_out--;
+ intf->next_out = (intf->next_out + 1) % MAX_OUT_MESSAGES;
+
+ memcpy(intf->out_data, message->bytes, message->num_bytes);
+ intf->urb_out->transfer_buffer_length = message->num_bytes;
+
+ usb_anchor_urb(intf->urb_out, &intf->out_anchor);
+ rc = usb_submit_urb(intf->urb_out, GFP_ATOMIC);
+ if (rc) {
+ dev_err(&intf->intf->dev,
+ "%s - usb_submit_urb failed with result %d\n",
+ __func__, rc);
+ usb_unanchor_urb(intf->urb_out);
+ intf->urb_out_active = false;
+ rc = -EIO;
+ } else {
+ intf->urb_out_active = true;
+ }
+
+ return rc;
+}
+
+static int gip_send_raw_message(struct gip_device *device,
+ uint8_t message_type, uint8_t flags, uint8_t seq, const uint8_t *bytes,
+ int num_bytes)
+{
+ struct gip_interface *intf;
+ int offset = 3;
+ unsigned long irqflags;
+ int rc = 0;
+
+ if (num_bytes < 0) {
+ dev_warn(GIP_DEV(device), "Invalid message length %d\n", num_bytes);
+ return -EINVAL;
+ }
+
+ if (num_bytes > gip_data_class_mtu[message_type >> GIP_DATA_CLASS_SHIFT]) {
+ dev_err(GIP_DEV(device),
+ "Attempted to send a message that requires fragmenting, which is not yet supported.\n");
+ return -ENOTSUPP;
+ }
+
+ if ((message_type & GIP_DATA_CLASS_MASK) == GIP_DATA_CLASS_AUDIO)
+ /* TODO: Needs isochronous transfer support */
+ return -ENOTSUPP;
+ else
+ intf = &device->data;
+
+ spin_lock_irqsave(&device->message_lock, irqflags);
+ if (intf->pending_out >= MAX_OUT_MESSAGES) {
+ dev_err(GIP_DEV(device), "Output queue is full; dropping message\n");
+ } else {
+ int message_id = (intf->next_out + intf->pending_out) % MAX_OUT_MESSAGES;
+ struct gip_raw_message *message = &intf->out_queue[message_id];
+
+ intf->pending_out++;
+
+ message->bytes[0] = message_type;
+ message->bytes[1] = flags;
+ message->bytes[2] = seq;
+ offset += gip_encode_length(num_bytes, &message->bytes[offset],
+ sizeof(message->bytes) - offset);
+
+ if (num_bytes > 0)
+ memcpy(&message->bytes[offset], bytes, num_bytes);
+
+ num_bytes += offset;
+ message->num_bytes = num_bytes;
+
+ print_hex_dump_debug(KBUILD_MODNAME ": Sending message: ",
+ DUMP_PREFIX_OFFSET, 16, 1, message->bytes, num_bytes,
+ false);
+ }
+ if (!intf->urb_out_active)
+ rc = gip_prepare_urb(intf);
+
+ spin_unlock_irqrestore(&device->message_lock, irqflags);
+
+ return rc;
+}
+
+static int gip_send_system_message(struct gip_attachment *attachment,
+ uint8_t message_type, uint8_t flags, const void *bytes, int num_bytes)
+{
+ return gip_send_raw_message(attachment->device, message_type,
+ GIP_FLAG_SYSTEM | attachment->attachment_index | flags,
+ gip_sequence_next(attachment, message_type, true),
+ bytes, num_bytes);
+}
+
+static int gip_send_vendor_message(struct gip_attachment *attachment,
+ uint8_t message_type, uint8_t flags, const void *bytes, int num_bytes)
+{
+ return gip_send_raw_message(attachment->device, message_type, flags,
+ gip_sequence_next(attachment, message_type, false),
+ bytes, num_bytes);
+}
+
+static int gip_hid_ll_parse(struct hid_device *hdev)
+{
+ struct gip_attachment *attachment = hdev->driver_data;
+
+ return hid_parse_report(hdev,
+ attachment->metadata.device.hid_descriptor,
+ attachment->metadata.device.hid_descriptor_size);
+}
+
+static int gip_hid_ll_start(struct hid_device *hdev)
+{
+ return 0;
+}
+
+static void gip_hid_ll_stop(struct hid_device *hdev)
+{
+}
+
+static int gip_hid_ll_open(struct hid_device *hdev)
+{
+ return 0;
+}
+
+static void gip_hid_ll_close(struct hid_device *hdev)
+{
+}
+
+static int gip_hid_ll_raw_request(struct hid_device *hdev,
+ unsigned char reportnum, uint8_t *buf, size_t count,
+ unsigned char report_type, int reqtype)
+{
+ /*
+ * TODO: Based on the metadata, output reports appear to be possible,
+ * but the chatpad doesn't have the LEDs it claims to support, so
+ * it's not clear how to test we're sending them properly.
+ */
+ return 0;
+}
+
+static const struct hid_ll_driver gip_hid_ll_driver = {
+ .parse = gip_hid_ll_parse,
+ .start = gip_hid_ll_start,
+ .stop = gip_hid_ll_stop,
+ .open = gip_hid_ll_open,
+ .close = gip_hid_ll_close,
+ .raw_request = gip_hid_ll_raw_request,
+};
+
+static bool gip_attachment_is_controller(struct gip_attachment *attachment)
+{
+ return attachment->attachment_type != GIP_TYPE_CHATPAD &&
+ attachment->attachment_type != GIP_TYPE_HEADSET;
+}
+
+static void gip_metadata_free(struct device *dev, struct gip_metadata *metadata)
+{
+ devm_kfree(dev, metadata->device.audio_formats);
+
+ if (metadata->device.preferred_types) {
+ int i;
+
+ for (i = 0; i < metadata->device.num_preferred_types; i++)
+ devm_kfree(dev, metadata->device.preferred_types[i]);
+ devm_kfree(dev, metadata->device.preferred_types);
+ }
+ devm_kfree(dev, metadata->device.supported_interfaces);
+ devm_kfree(dev, metadata->device.hid_descriptor);
+ devm_kfree(dev, metadata->message_metadata);
+
+ memset(metadata, 0, sizeof(*metadata));
+}
+
+static int gip_parse_audio_format_metadata(struct device *dev,
+ struct gip_device_metadata *dev_metadata, const uint8_t *bytes,
+ int length, int buffer_offset)
+{
+ unsigned int i;
+
+ dev_metadata->num_audio_formats = bytes[buffer_offset];
+ if (buffer_offset + dev_metadata->num_audio_formats * 2 + 1 > length)
+ return -EINVAL;
+ dev_metadata->audio_formats = devm_kmalloc_array(dev,
+ dev_metadata->num_audio_formats, 2, GFP_KERNEL);
+ if (!dev_metadata->audio_formats)
+ return -ENOMEM;
+ memcpy(dev_metadata->audio_formats, &bytes[buffer_offset + 1],
+ dev_metadata->num_audio_formats * 2);
+
+ for (i = 0; i < dev_metadata->num_audio_formats; i++) {
+ const struct gip_audio_format_pair *pair = &dev_metadata->audio_formats[i];
+ const struct gip_audio_format *inbound = NULL;
+ const struct gip_audio_format *outbound = NULL;
+
+ if (pair->inbound <= MAX_GIP_AUDIO_FORMAT) {
+ inbound = &gip_audio_format_table[pair->inbound];
+ if (pair->inbound != GIP_AUDIO_FORMAT_NULL && inbound->rate == 0)
+ inbound = NULL;
+ }
+ if (!inbound)
+ dev_warn(dev, "Unknown audio format %u\n", pair->inbound);
+
+ if (pair->outbound <= MAX_GIP_AUDIO_FORMAT) {
+ outbound = &gip_audio_format_table[pair->outbound];
+ if (pair->outbound != GIP_AUDIO_FORMAT_NULL && outbound->rate == 0)
+ outbound = NULL;
+ }
+ if (!outbound)
+ dev_warn(dev, "Unknown audio format %u\n", pair->outbound);
+
+ if (inbound && outbound)
+ dev_dbg(dev,
+ "Supported audio format: %uHz %uch inbound, %uHz %uch outbound\n",
+ inbound->rate,
+ inbound->channels,
+ outbound->rate,
+ outbound->channels);
+ }
+ return 0;
+}
+
+static int gip_parse_preferred_types_metadata(struct device *dev,
+ struct gip_device_metadata *dev_metadata, const uint8_t *bytes,
+ int length, int buffer_offset)
+{
+ int i;
+ int count;
+
+ dev_metadata->num_preferred_types = bytes[buffer_offset];
+ dev_metadata->preferred_types = devm_kcalloc(dev,
+ dev_metadata->num_preferred_types, sizeof(char *), GFP_KERNEL);
+ if (!dev_metadata->preferred_types)
+ return -ENOMEM;
+
+ buffer_offset++;
+ for (i = 0; i < dev_metadata->num_preferred_types; i++) {
+ if (buffer_offset + 2 >= length)
+ return -EINVAL;
+
+ count = bytes[buffer_offset];
+ count |= bytes[buffer_offset];
+ buffer_offset += 2;
+ if (buffer_offset + count > length)
+ return -EINVAL;
+
+ dev_metadata->preferred_types[i] = devm_kcalloc(dev, count + 1,
+ sizeof(char), GFP_KERNEL);
+ if (!dev_metadata->preferred_types[i])
+ return -ENOMEM;
+ memcpy(dev_metadata->preferred_types[i], &bytes[buffer_offset], count);
+ buffer_offset += count;
+ }
+
+ return 0;
+}
+
+static int gip_parse_supported_interfaces_metadata(struct device *dev,
+ struct gip_device_metadata *dev_metadata, const uint8_t *bytes,
+ int length, int buffer_offset)
+{
+ dev_metadata->num_supported_interfaces = bytes[buffer_offset];
+ if (buffer_offset + 1 +
+ (int32_t) (dev_metadata->num_supported_interfaces * sizeof(guid_t)) > length)
+ return -EINVAL;
+
+ dev_metadata->supported_interfaces = devm_kmalloc_array(dev,
+ dev_metadata->num_supported_interfaces, sizeof(guid_t), GFP_KERNEL);
+ if (!dev_metadata->supported_interfaces)
+ return -ENOMEM;
+
+ memcpy(dev_metadata->supported_interfaces, &bytes[buffer_offset + 1],
+ sizeof(guid_t) * dev_metadata->num_supported_interfaces);
+
+ return 0;
+}
+
+static int gip_parse_hid_descriptor_metadata(struct device *dev,
+ struct gip_device_metadata *dev_metadata, const uint8_t *bytes,
+ int length, int buffer_offset)
+{
+ dev_metadata->hid_descriptor_size = bytes[buffer_offset];
+ if (buffer_offset + 1 + dev_metadata->hid_descriptor_size > length)
+ return -EINVAL;
+
+ dev_metadata->hid_descriptor = devm_kmalloc(dev,
+ dev_metadata->hid_descriptor_size, GFP_KERNEL);
+ if (!dev_metadata->hid_descriptor)
+ return -ENOMEM;
+
+ memcpy(dev_metadata->hid_descriptor, &bytes[buffer_offset + 1],
+ dev_metadata->hid_descriptor_size);
+ print_hex_dump_debug(KBUILD_MODNAME ": Received HID descriptor: ",
+ DUMP_PREFIX_OFFSET, 16, 1, dev_metadata->hid_descriptor,
+ dev_metadata->hid_descriptor_size, false);
+
+ return 0;
+}
+
+static int gip_parse_device_metadata(struct device *dev,
+ struct gip_metadata *metadata, const uint8_t *bytes, int num_bytes,
+ int *offset)
+{
+ struct gip_device_metadata *dev_metadata = &metadata->device;
+ int buffer_offset;
+ int count;
+ int length;
+ int i;
+ int rc;
+
+ bytes = &bytes[*offset];
+ num_bytes -= *offset;
+ if (num_bytes < 16)
+ return -EINVAL;
+
+ length = bytes[0];
+ length |= bytes[1] << 8;
+ if (num_bytes < length)
+ return -EINVAL;
+
+ /* Skip supported firmware versions for now */
+
+ buffer_offset = bytes[4];
+ buffer_offset |= bytes[5] << 8;
+ if (buffer_offset >= length)
+ return -EINVAL;
+
+ if (buffer_offset > 0) {
+ rc = gip_parse_audio_format_metadata(dev, dev_metadata,
+ bytes, length, buffer_offset);
+ if (rc)
+ return rc;
+ }
+
+ buffer_offset = bytes[6];
+ buffer_offset |= bytes[7] << 8;
+ if (buffer_offset >= length)
+ return -EINVAL;
+
+ if (buffer_offset > 0) {
+ count = bytes[buffer_offset];
+ if (buffer_offset + count + 1 > length)
+ return -EINVAL;
+
+ for (i = 0; i < count; i++) {
+ uint8_t message = bytes[buffer_offset + 1 + i];
+
+ dev_dbg(dev,
+ "Supported upstream system message %02x\n",
+ message);
+ dev_metadata->in_system_messages[message >> 5] |=
+ BIT(message & 0x1F);
+ }
+ }
+
+ buffer_offset = bytes[8];
+ buffer_offset |= bytes[9] << 8;
+ if (buffer_offset >= length)
+ return -EINVAL;
+
+ if (buffer_offset > 0) {
+ count = bytes[buffer_offset];
+ if (buffer_offset + count + 1 > length)
+ return -EINVAL;
+
+ for (i = 0; i < count; i++) {
+ uint8_t message = bytes[buffer_offset + 1 + i];
+
+ dev_dbg(dev,
+ "Supported downstream system message %02x\n",
+ message);
+ dev_metadata->out_system_messages[message >> 5] |=
+ BIT(message & 0x1F);
+ }
+ }
+
+ buffer_offset = bytes[10];
+ buffer_offset |= bytes[11] << 8;
+ if (buffer_offset >= length)
+ return -EINVAL;
+
+ if (buffer_offset > 0) {
+ rc = gip_parse_preferred_types_metadata(dev, dev_metadata,
+ bytes, length, buffer_offset);
+ if (rc)
+ return rc;
+ }
+
+ buffer_offset = bytes[12];
+ buffer_offset |= bytes[13] << 8;
+ if (buffer_offset >= length)
+ return -EINVAL;
+
+ if (buffer_offset > 0) {
+ rc = gip_parse_supported_interfaces_metadata(dev,
+ dev_metadata, bytes, length, buffer_offset);
+ if (rc)
+ return rc;
+ }
+
+ if (metadata->version_major > 1 || metadata->version_minor >= 1) {
+ /* HID descriptor support added in metadata version 1.1 */
+ buffer_offset = bytes[14];
+ buffer_offset |= bytes[15] << 8;
+ if (buffer_offset >= length)
+ return -EINVAL;
+
+ if (buffer_offset > 0) {
+ rc = gip_parse_hid_descriptor_metadata(dev,
+ dev_metadata, bytes, length, buffer_offset);
+ if (rc)
+ return rc;
+ }
+ }
+
+ *offset += length;
+ return 0;
+}
+
+static int gip_parse_message_metadata(struct device *dev,
+ struct gip_message_metadata *metadata, const uint8_t *bytes,
+ int num_bytes, int *offset)
+{
+ uint16_t length;
+
+ bytes = &bytes[*offset];
+ num_bytes -= *offset;
+
+ if (num_bytes < 2)
+ return -EINVAL;
+
+ length = bytes[0];
+ length |= bytes[1] << 8;
+ if (num_bytes < length)
+ return -EINVAL;
+
+ if (length < 15)
+ return -EINVAL;
+
+ metadata->type = bytes[2];
+ metadata->length = bytes[3];
+ metadata->length |= bytes[4] << 8;
+ metadata->data_type = bytes[5];
+ metadata->data_type |= bytes[6] << 8;
+ metadata->flags = bytes[7];
+ metadata->flags |= bytes[8] << 8;
+ metadata->flags |= bytes[9] << 16;
+ metadata->flags |= bytes[10] << 24;
+ metadata->period = bytes[11];
+ metadata->period |= bytes[12] << 8;
+ metadata->persistence_timeout = bytes[13];
+ metadata->persistence_timeout |= bytes[14] << 8;
+
+ dev_dbg(dev,
+ "Supported vendor message type %02x of length %d, %s, %s, %s\n",
+ metadata->type, metadata->length,
+ metadata->flags & GIP_MESSAGE_FLAG_UPSTREAM ?
+ (metadata->flags & GIP_MESSAGE_FLAG_DOWNSTREAM ? "bidirectional" : "upstream") :
+ metadata->flags & GIP_MESSAGE_FLAG_DOWNSTREAM ? "downstream" :
+ metadata->flags & GIP_MESSAGE_FLAG_DS_REQUEST_RESPONSE ? "downstream request response" :
+ "unknown direction",
+ metadata->flags & GIP_MESSAGE_FLAG_SEQUENCED ? "sequenced" : "not sequenced",
+ metadata->flags & GIP_MESSAGE_FLAG_RELIABLE ? "reliable" : "unreliable");
+
+ *offset += length;
+ return 0;
+}
+
+static bool gip_parse_metadata(struct device *dev,
+ struct gip_metadata *metadata, const uint8_t *bytes, int num_bytes)
+{
+ int header_size;
+ int metadata_size;
+ int offset = 0;
+ int i;
+ int rc;
+
+ if (num_bytes < 16)
+ return -EINVAL;
+
+ print_hex_dump_debug(KBUILD_MODNAME ": Received metadata: ", DUMP_PREFIX_OFFSET,
+ 16, 1, bytes, num_bytes, false);
+
+ header_size = bytes[0];
+ header_size |= bytes[1] << 8;
+ if (num_bytes < header_size || header_size < 16)
+ return -EINVAL;
+
+ metadata->version_major = bytes[2];
+ metadata->version_major |= bytes[3] << 8;
+ metadata->version_minor = bytes[4];
+ metadata->version_minor |= bytes[5] << 8;
+ /* Middle bytes are reserved */
+ metadata_size = bytes[14];
+ metadata_size |= bytes[15] << 8;
+
+ if (num_bytes < metadata_size || metadata_size < header_size)
+ return -EINVAL;
+
+ offset = header_size;
+
+ rc = gip_parse_device_metadata(dev, metadata, bytes, num_bytes, &offset);
+ if (rc)
+ goto parse_err;
+
+ if (offset >= num_bytes)
+ goto parse_err;
+
+ metadata->num_messages = bytes[offset];
+ offset++;
+ if (metadata->num_messages > 0) {
+ metadata->message_metadata = devm_kcalloc(dev,
+ metadata->num_messages,
+ sizeof(*metadata->message_metadata), GFP_KERNEL);
+ if (!metadata->message_metadata)
+ return -ENOMEM;
+
+ for (i = 0; i < metadata->num_messages; i++) {
+ rc = gip_parse_message_metadata(dev,
+ &metadata->message_metadata[i], bytes,
+ num_bytes, &offset);
+ if (rc)
+ goto parse_err;
+ }
+ }
+
+ return 0;
+
+parse_err:
+ gip_metadata_free(dev, metadata);
+ return rc;
+}
+
+static int gip_acknowledge(struct gip_device *device,
+ const struct gip_header *header, uint32_t fragment_offset,
+ uint16_t bytes_remaining)
+{
+ uint8_t buffer[] = {
+ GIP_CONTROL_CODE_ACK,
+ header->message_type,
+ header->flags & GIP_FLAG_SYSTEM,
+ fragment_offset,
+ fragment_offset >> 8,
+ fragment_offset >> 16,
+ fragment_offset >> 24,
+ bytes_remaining,
+ bytes_remaining >> 8,
+ };
+
+ return gip_send_raw_message(device, GIP_CMD_PROTO_CONTROL,
+ GIP_FLAG_SYSTEM | (header->flags & GIP_FLAG_ATTACHMENT_MASK),
+ header->sequence_id, buffer, sizeof(buffer));
+}
+
+static int gip_fragment_failed(struct gip_attachment *attachment,
+ const struct gip_header *header)
+{
+ attachment->fragment_retries++;
+ if (attachment->fragment_retries > 8) {
+ devm_kfree(GIP_DEV(attachment), attachment->fragment_data);
+ attachment->fragment_data = NULL;
+ attachment->fragment_message = 0;
+ }
+ return gip_acknowledge(attachment->device, header,
+ attachment->fragment_offset,
+ attachment->total_length - attachment->fragment_offset);
+}
+
+static int gip_enable_elite_buttons(struct gip_attachment *attachment)
+{
+ if (attachment->vendor_id == 0x045e) {
+ if (attachment->product_id == 0x02e3) {
+ attachment->xbe_format = GIP_BTN_FMT_XBE1;
+ } else if (attachment->product_id == 0x0b00) {
+ if (attachment->firmware_major_version == 4) {
+ attachment->xbe_format = GIP_BTN_FMT_XBE2_4;
+ } else if (attachment->firmware_major_version == 5) {
+ /*
+ * The exact range for this being necessary is
+ * unknown, but it starts at 5.11 and at either
+ * 5.16 or 5.17. This approach still works on
+ * 5.21, even if it's not necessary, so having
+ * a loose upper limit is fine.
+ */
+ if (attachment->firmware_minor_version >= 11 &&
+ attachment->firmware_minor_version < 17)
+ attachment->xbe_format = GIP_BTN_FMT_XBE2_RAW;
+ else
+ attachment->xbe_format = GIP_BTN_FMT_XBE2_5;
+ }
+ }
+ }
+
+ if (attachment->xbe_format == GIP_BTN_FMT_XBE2_RAW) {
+ /*
+ * The meaning of this packet is unknown and not documented, but
+ * it's needed for the Elite 2 controller to send raw reports
+ */
+ static const uint8_t enable_raw_report[] = { 7, 0 };
+
+ return gip_send_vendor_message(attachment, GIP_SL_ELITE_CONFIG,
+ 0, enable_raw_report, sizeof(enable_raw_report));
+ }
+
+ return 0;
+}
+
+#ifdef CONFIG_JOYSTICK_XBOX_GIP_FF
+static int gip_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect)
+{
+ struct gip_attachment *attachment = input_get_drvdata(dev);
+ struct gip_direct_motor control = {
+ .motor_bitmap = GIP_MOTOR_LEFT_VIBRATION | GIP_MOTOR_RIGHT_VIBRATION
+ };
+
+ if (effect->type != FF_RUMBLE)
+ return 0;
+
+ control.left_vibration_level = effect->u.rumble.strong_magnitude * 100 / 0xFFFF;
+ control.right_vibration_level = effect->u.rumble.weak_magnitude * 100 / 0xFFFF;
+ control.duration = 255;
+
+ return gip_send_vendor_message(attachment, GIP_CMD_DIRECT_MOTOR,
+ 0, &control, sizeof(control));
+}
+#endif
+
+static int gip_send_guide_button_led(struct gip_attachment *attachment,
+ uint8_t pattern, uint8_t intensity)
+{
+ uint8_t buffer[] = {
+ GIP_LED_GUIDE,
+ pattern,
+ intensity,
+ };
+
+ if (!gip_supports_system_message(attachment, GIP_CMD_LED, false))
+ return 0;
+
+#ifdef CONFIG_JOYSTICK_XBOX_GIP_LEDS
+ if (!(attachment->features & GIP_FEATURE_GUIDE_COLOR))
+ attachment->guide_led.standard.brightness = intensity;
+#endif
+
+ return gip_send_system_message(attachment, GIP_CMD_LED, 0, buffer, sizeof(buffer));
+}
+
+#ifdef CONFIG_JOYSTICK_XBOX_GIP_LEDS
+static int gip_send_guide_button_color_led(struct gip_attachment *attachment,
+ uint8_t r, uint8_t g, uint8_t b, uint8_t w)
+{
+ uint8_t buffer[] = { 0x00, w, r, g, b };
+
+ if (!(attachment->features & GIP_FEATURE_GUIDE_COLOR))
+ return -EINVAL;
+
+ attachment->guide_led.color.subled_info[0].brightness = r;
+ attachment->guide_led.color.subled_info[1].brightness = g;
+ attachment->guide_led.color.subled_info[2].brightness = b;
+ attachment->guide_led.color.subled_info[3].brightness = w;
+
+ return gip_send_vendor_message(attachment, GIP_CMD_GUIDE_COLOR, 0, buffer, sizeof(buffer));
+}
+
+static int gip_guide_led_set(struct led_classdev *led,
+ enum led_brightness value)
+{
+ struct gip_attachment *attachment = container_of(led,
+ struct gip_attachment, guide_led.standard);
+
+ guard(mutex)(&attachment->lock);
+ return gip_send_guide_button_led(attachment, GIP_LED_GUIDE_ON, value);
+}
+
+static int gip_guide_color_led_set(struct led_classdev *led,
+ enum led_brightness value)
+{
+ struct led_classdev_mc *mc_cdev = container_of(led,
+ struct led_classdev_mc, led_cdev);
+ struct gip_attachment *attachment = container_of(mc_cdev,
+ struct gip_attachment, guide_led.color);
+
+ led_mc_calc_color_components(mc_cdev, value);
+ guard(mutex)(&attachment->lock);
+ return gip_send_guide_button_color_led(attachment,
+ mc_cdev->subled_info[0].brightness,
+ mc_cdev->subled_info[1].brightness,
+ mc_cdev->subled_info[2].brightness,
+ mc_cdev->subled_info[3].brightness);
+}
+
+static int gip_guide_led_probe(struct gip_attachment *attachment, struct device *dev)
+{
+ int rc;
+
+ if (!gip_supports_system_message(attachment, GIP_CMD_LED, false))
+ return 0;
+
+ if (attachment->features & GIP_FEATURE_GUIDE_COLOR) {
+ struct mc_subled *mc_led_info;
+ struct led_classdev_mc *mc_cdev = &attachment->guide_led.color;
+ struct led_classdev *cdev = &mc_cdev->led_cdev;
+
+ mc_led_info = devm_kcalloc(dev, 4,
+ sizeof(*mc_led_info), GFP_KERNEL);
+ if (!mc_led_info)
+ return -ENOMEM;
+
+ mc_led_info[0].color_index = LED_COLOR_ID_RED;
+ mc_led_info[1].color_index = LED_COLOR_ID_GREEN;
+ mc_led_info[2].color_index = LED_COLOR_ID_BLUE;
+ mc_led_info[3].color_index = LED_COLOR_ID_WHITE;
+
+ mc_cdev->subled_info = mc_led_info;
+ mc_cdev->num_colors = 4;
+
+ cdev->brightness = 51;
+ cdev->max_brightness = 255;
+ cdev->flags = LED_CORE_SUSPENDRESUME | LED_RETAIN_AT_SHUTDOWN;
+ cdev->brightness_set_blocking = gip_guide_color_led_set;
+ cdev->name = devm_kasprintf(dev, GFP_KERNEL,
+ "%s:rgb:power", dev_name(dev));
+
+ rc = devm_led_classdev_multicolor_register(dev,
+ &attachment->guide_led.color);
+
+ if (rc)
+ devm_kfree(dev, mc_led_info);
+ } else {
+ struct led_classdev *cdev = &attachment->guide_led.standard;
+
+ cdev->max_brightness = GIP_LED_GUIDE_MAX_BRIGHTNESS;
+ cdev->brightness = GIP_LED_GUIDE_INIT_BRIGHTNESS;
+ cdev->flags = LED_CORE_SUSPENDRESUME | LED_RETAIN_AT_SHUTDOWN;
+ cdev->brightness_set_blocking = gip_guide_led_set;
+ cdev->name = devm_kasprintf(dev, GFP_KERNEL,
+ "%s:white:power", dev_name(dev));
+
+ rc = devm_led_classdev_register(dev,
+ &attachment->guide_led.standard);
+ }
+
+ return rc;
+}
+#endif
+
+static bool gip_send_set_device_state(struct gip_attachment *attachment, uint8_t state)
+{
+ uint8_t buffer[] = { state };
+
+ return gip_send_system_message(attachment, GIP_CMD_SET_DEVICE_STATE,
+ attachment->attachment_index, buffer, sizeof(buffer));
+}
+
+static int gip_setup_input_device(struct gip_attachment *attachment)
+{
+ struct input_dev *input;
+ int rc;
+
+ input = input_allocate_device();
+ if (!input)
+ return -ENOMEM;
+ input->id.bustype = BUS_USB;
+ input->id.vendor = attachment->vendor_id;
+ input->id.product = attachment->product_id;
+ input->uniq = attachment->uniq;
+ if (attachment->name)
+ input->name = attachment->name;
+ else if (attachment->attachment_index == 0)
+ input->name = attachment->device->udev->product;
+ input->phys = attachment->phys;
+
+ /* Navigation buttons */
+ input_set_capability(input, EV_KEY, BTN_Y);
+ input_set_capability(input, EV_KEY, BTN_B);
+ input_set_capability(input, EV_KEY, BTN_X);
+ input_set_capability(input, EV_KEY, BTN_A);
+ input_set_capability(input, EV_KEY, BTN_SELECT);
+ input_set_capability(input, EV_KEY, BTN_MODE);
+ input_set_capability(input, EV_KEY, BTN_START);
+ input_set_capability(input, EV_KEY, BTN_TR);
+ input_set_capability(input, EV_KEY, BTN_TL);
+
+ attachment->dpad_as_buttons = dpad_as_buttons;
+ if (attachment->dpad_as_buttons) {
+ input_set_capability(input, EV_KEY, BTN_DPAD_UP);
+ input_set_capability(input, EV_KEY, BTN_DPAD_RIGHT);
+ input_set_capability(input, EV_KEY, BTN_DPAD_LEFT);
+ input_set_capability(input, EV_KEY, BTN_DPAD_DOWN);
+ } else {
+ input_set_abs_params(input, ABS_HAT0X, -1, 1, 0, 0);
+ input_set_abs_params(input, ABS_HAT0Y, -1, 1, 0, 0);
+ }
+
+ switch (attachment->attachment_type) {
+ case GIP_TYPE_GAMEPAD:
+ input_set_capability(input, EV_KEY, BTN_THUMBR);
+ input_set_capability(input, EV_KEY, BTN_THUMBL);
+ input_set_abs_params(input, ABS_X, -32768, 32767, 16, 128);
+ input_set_abs_params(input, ABS_Y, -32768, 32767, 16, 128);
+ input_set_abs_params(input, ABS_RX, -32768, 32767, 16, 128);
+ input_set_abs_params(input, ABS_RY, -32768, 32767, 16, 128);
+ input_set_abs_params(input, ABS_Z, 0, 1023, 0, 0);
+ input_set_abs_params(input, ABS_RZ, 0, 1023, 0, 0);
+ break;
+ case GIP_TYPE_ARCADE_STICK:
+ input_set_capability(input, EV_KEY, BTN_THUMBR);
+ input_set_capability(input, EV_KEY, BTN_THUMBL);
+ break;
+ case GIP_TYPE_FLIGHT_STICK:
+ case GIP_TYPE_WHEEL:
+ case GIP_TYPE_UNKNOWN:
+ case GIP_TYPE_NAVIGATION_CONTROLLER:
+ break;
+ case GIP_TYPE_CHATPAD:
+ case GIP_TYPE_HEADSET:
+ rc = -ENODEV;
+ goto err_free_device;
+ }
+ if (attachment->features & GIP_FEATURE_CONSOLE_FUNCTION_MAP)
+ input_set_capability(input, EV_KEY, KEY_RECORD);
+
+ if (attachment->features & GIP_FEATURE_ELITE_BUTTONS) {
+ input_set_capability(input, EV_KEY, BTN_GRIPL);
+ input_set_capability(input, EV_KEY, BTN_GRIPR);
+ input_set_capability(input, EV_KEY, BTN_GRIPL2);
+ input_set_capability(input, EV_KEY, BTN_GRIPR2);
+ if (attachment->xbe_format == GIP_BTN_FMT_XBE1)
+ input_set_abs_params(input, ABS_PROFILE, 0, 1, 0, 0);
+ else
+ input_set_abs_params(input, ABS_PROFILE, 0, 3, 0, 0);
+ }
+
+ /* Xbox Adaptive Controller */
+ if (attachment->vendor_id == 0x045e && attachment->product_id == 0x0b0a)
+ input_set_abs_params(input, ABS_PROFILE, 0, 3, 0, 0);
+
+#ifdef CONFIG_JOYSTICK_XBOX_GIP_FF
+ if (attachment->features & GIP_FEATURE_MOTOR_CONTROL) {
+ input_set_capability(input, EV_FF, FF_RUMBLE);
+ input_ff_create_memless(input, NULL, gip_play_effect);
+ }
+#endif
+
+ input_set_drvdata(input, attachment);
+ attachment->input = input;
+ rc = input_register_device(input);
+ if (rc)
+ goto err_free_device;
+
+#ifdef CONFIG_JOYSTICK_XBOX_GIP_LEDS
+ rc = gip_guide_led_probe(attachment, &input->dev);
+ if (rc)
+ dev_err(GIP_DEV(attachment), "Failed to register LEDs: %d\n", rc);
+#endif
+
+ return 0;
+
+err_free_device:
+ input_free_device(input);
+ return rc;
+}
+
+static int gip_send_init_sequence(struct gip_attachment *attachment)
+{
+ int rc = 0;
+ size_t len;
+
+ if (attachment->features & GIP_FEATURE_EXTENDED_SET_DEVICE_STATE) {
+ /*
+ * The meaning of this packet is unknown and not documented, but it's
+ * needed for the Elite 2 controller to start up on older firmwares
+ */
+ static const uint8_t set_device_state[] = {
+ GIP_STATE_UNK6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+ 0x55, 0x53, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
+ };
+
+ rc = gip_send_system_message(attachment,
+ GIP_CMD_SET_DEVICE_STATE, 0, set_device_state,
+ sizeof(set_device_state));
+ if (rc)
+ return rc;
+ }
+ rc = gip_enable_elite_buttons(attachment);
+ if (rc)
+ return rc;
+ if (attachment->attachment_type != GIP_TYPE_HEADSET) {
+ rc = gip_send_set_device_state(attachment, GIP_STATE_START);
+ if (rc)
+ return rc;
+ attachment->device_state = GIP_STATE_START;
+ } else {
+ rc = gip_send_set_device_state(attachment, GIP_STATE_STOP);
+ if (rc)
+ return rc;
+ attachment->device_state = GIP_STATE_STOP;
+ }
+
+ rc = gip_send_guide_button_led(attachment,
+ GIP_LED_GUIDE_ON,
+ GIP_LED_GUIDE_INIT_BRIGHTNESS);
+ if (rc)
+ return rc;
+
+ if (gip_supports_system_message(attachment, GIP_CMD_SECURITY, false)
+ && !(attachment->features & GIP_FEATURE_SECURITY_OPT_OUT)) {
+ /* TODO: Implement Security command property */
+ uint8_t buffer[] = { 0x1, 0x0 };
+
+ rc = gip_send_system_message(attachment, GIP_CMD_SECURITY, 0,
+ buffer, sizeof(buffer));
+ if (rc)
+ return rc;
+ }
+
+ usb_make_path(attachment->device->udev, attachment->phys,
+ sizeof(attachment->phys));
+ len = strlen(attachment->phys);
+ if (len < sizeof(attachment->phys) - 1)
+ snprintf(attachment->phys + len,
+ sizeof(attachment->phys) - len, "/input%d",
+ attachment->attachment_index);
+
+ if (gip_attachment_is_controller(attachment) && !attachment->input) {
+ rc = gip_setup_input_device(attachment);
+ if (rc == -ENODEV)
+ return 0;
+ }
+
+ if (attachment->metadata.device.hid_descriptor) {
+ struct hid_device *hdev = hid_allocate_device();
+
+ if (IS_ERR(hdev))
+ return PTR_ERR(hdev);
+
+ hdev->ll_driver = &gip_hid_ll_driver;
+ hdev->bus = BUS_USB;
+ hdev->vendor = attachment->vendor_id;
+ hdev->product = attachment->product_id;
+ hdev->dev.parent = GIP_DEV(attachment);
+ hdev->driver_data = attachment;
+ if (attachment->name)
+ strscpy(hdev->name, attachment->name);
+ else
+ strscpy(hdev->name, "Xbox Chatpad");
+ strscpy(hdev->phys, attachment->phys);
+ rc = hid_add_device(hdev);
+ if (rc) {
+ dev_err(GIP_DEV(attachment), "HID device add failed: %d\n", rc);
+ hid_destroy_device(hdev);
+ } else {
+ attachment->hdev = hdev;
+ }
+ }
+
+ return rc;
+}
+
+static void gip_fragment_timeout(struct work_struct *work)
+{
+ struct gip_attachment *attachment = container_of(to_delayed_work(work),
+ struct gip_attachment, fragment_timeout);
+
+ guard(mutex)(&attachment->lock);
+ devm_kfree(GIP_DEV(attachment), attachment->fragment_data);
+ attachment->fragment_data = NULL;
+ attachment->fragment_message = 0;
+}
+
+static void gip_retry_metadata(struct work_struct *work)
+{
+ struct gip_attachment *attachment = container_of(to_delayed_work(work),
+ struct gip_attachment, metadata_next);
+
+ guard(mutex)(&attachment->lock);
+ if (attachment->metadata_retries < 4) {
+ attachment->metadata_retries++;
+ schedule_delayed_work(&attachment->metadata_next, HZ / 2);
+ gip_send_system_message(attachment, GIP_CMD_METADATA, 0, NULL, 0);
+ } else {
+ dev_info(GIP_DEV(attachment),
+ "Unable to obtain metadata, attempting to reset device\n");
+ gip_send_set_device_state(attachment, GIP_STATE_RESET);
+ }
+}
+
+static int gip_ensure_metadata(struct gip_attachment *attachment)
+{
+ switch (attachment->got_metadata) {
+ case GIP_METADATA_GOT:
+ case GIP_METADATA_FAKED:
+ return 0;
+ case GIP_METADATA_NONE:
+ attachment->got_metadata = GIP_METADATA_PENDING;
+ cancel_delayed_work_sync(&attachment->metadata_next);
+ schedule_delayed_work(&attachment->metadata_next, HZ / 2);
+ attachment->metadata_retries = 0;
+ return gip_send_system_message(attachment, GIP_CMD_METADATA, 0, NULL, 0);
+ default:
+ return 0;
+ }
+}
+
+static bool gip_handle_command_protocol_control(struct gip_attachment *attachment,
+ const struct gip_header *header, const uint8_t *bytes, int num_bytes)
+{
+ /* TODO */
+ dev_warn(GIP_DEV(attachment), "Unimplemented Protocol Control message\n");
+ return -ENOTSUPP;
+}
+
+static bool gip_handle_command_hello_device(struct gip_attachment *attachment,
+ const struct gip_header *header, const uint8_t *bytes, int num_bytes)
+{
+ struct gip_hello_device message = {0};
+
+ if (num_bytes != 28)
+ return -EINVAL;
+
+ message.device_id = (uint64_t) bytes[0];
+ message.device_id |= (uint64_t) bytes[1] << 8;
+ message.device_id |= (uint64_t) bytes[2] << 16;
+ message.device_id |= (uint64_t) bytes[3] << 24;
+ message.device_id |= (uint64_t) bytes[4] << 32;
+ message.device_id |= (uint64_t) bytes[5] << 40;
+ message.device_id |= (uint64_t) bytes[6] << 48;
+ message.device_id |= (uint64_t) bytes[7] << 56;
+
+ message.vendor_id = bytes[8];
+ message.vendor_id |= bytes[9] << 8;
+
+ message.product_id = bytes[10];
+ message.product_id |= bytes[11] << 8;
+
+ message.firmware_major_version = bytes[12];
+ message.firmware_major_version |= bytes[13] << 8;
+
+ message.firmware_minor_version = bytes[14];
+ message.firmware_minor_version |= bytes[15] << 8;
+
+ message.firmware_build_version = bytes[16];
+ message.firmware_build_version |= bytes[17] << 8;
+
+ message.firmware_revision = bytes[18];
+ message.firmware_revision |= bytes[19] << 8;
+
+ message.hardware_major_version = bytes[20];
+ message.hardware_minor_version = bytes[21];
+
+ message.rf_proto_major_version = bytes[22];
+ message.rf_proto_minor_version = bytes[23];
+
+ message.security_major_version = bytes[24];
+ message.security_minor_version = bytes[25];
+
+ message.gip_major_version = bytes[26];
+ message.gip_minor_version = bytes[27];
+
+ dev_dbg(GIP_DEV(attachment), "Device hello from %llx (%04x:%04x)\n",
+ message.device_id, message.vendor_id, message.product_id);
+ dev_dbg(GIP_DEV(attachment), "Firmware version %d.%d.%d rev %d\n",
+ message.firmware_major_version, message.firmware_minor_version,
+ message.firmware_build_version, message.firmware_revision);
+
+ /*
+ * The GIP spec specifies that the host should reject the device if any of these are wrong.
+ * I don't know if Windows or an Xbox do, however, so let's just log warnings instead.
+ */
+ if (message.rf_proto_major_version != 1 && message.rf_proto_minor_version != 0)
+ dev_warn(GIP_DEV(attachment),
+ "Invalid RF protocol version %d.%d, expected 1.0\n",
+ message.rf_proto_major_version, message.rf_proto_minor_version);
+
+ if (message.security_major_version != 1 && message.security_minor_version != 0)
+ dev_warn(GIP_DEV(attachment),
+ "Invalid security protocol version %d.%d, expected 1.0\n",
+ message.security_major_version, message.security_minor_version);
+
+ if (message.gip_major_version != 1 && message.gip_minor_version != 0)
+ dev_warn(GIP_DEV(attachment),
+ "Invalid GIP version %d.%d, expected 1.0\n",
+ message.gip_major_version, message.gip_minor_version);
+
+ if (header->flags & GIP_FLAG_ATTACHMENT_MASK)
+ return gip_send_system_message(attachment, GIP_CMD_METADATA, 0, NULL, 0);
+
+ attachment->firmware_major_version = message.firmware_major_version;
+ attachment->firmware_minor_version = message.firmware_minor_version;
+ attachment->vendor_id = message.vendor_id;
+ attachment->product_id = message.product_id;
+ attachment->uniq = devm_kasprintf(GIP_DEV(attachment),
+ GFP_KERNEL, "%llx", message.device_id);
+
+ if (attachment->got_metadata == GIP_METADATA_FAKED)
+ attachment->got_metadata = GIP_METADATA_NONE;
+ return gip_ensure_metadata(attachment);
+}
+
+static int gip_handle_command_status_device(struct gip_attachment *attachment,
+ const struct gip_header *header, const uint8_t *bytes, int num_bytes)
+{
+ struct gip_extended_status status = {{0}};
+ int i;
+
+ if (num_bytes < 1)
+ return -EINVAL;
+
+ status.base.battery_level = bytes[0] & 3;
+ status.base.battery_type = (bytes[0] >> 2) & 3;
+ status.base.charge = (bytes[0] >> 4) & 3;
+ status.base.power_level = (bytes[0] >> 6) & 3;
+
+ if (num_bytes >= 4) {
+ status.device_active = bytes[1] & 1;
+ if (bytes[1] & 2) {
+ /* Events present */
+ if (num_bytes < 5)
+ return -EINVAL;
+
+ status.num_events = bytes[4];
+ if (status.num_events > 5) {
+ dev_info(GIP_DEV(attachment),
+ "Device reported too many events, %d > 5\n",
+ status.num_events);
+ return -EINVAL;
+ }
+ if (5 + status.num_events * 10 > num_bytes)
+ return -EINVAL;
+
+ for (i = 0; i < status.num_events; i++) {
+ status.events[i].event_type = bytes[i * 10 + 5];
+ status.events[i].event_type |= bytes[i * 10 + 6] << 8;
+ status.events[i].fault_tag = bytes[i * 10 + 7];
+ status.events[i].fault_tag |= bytes[i * 10 + 8] << 8;
+ status.events[i].fault_tag |= bytes[i * 10 + 9] << 16;
+ status.events[i].fault_tag |= bytes[i * 10 + 10] << 24;
+ status.events[i].fault_address = bytes[i * 10 + 11];
+ status.events[i].fault_address |= bytes[i * 10 + 12] << 8;
+ status.events[i].fault_address |= bytes[i * 10 + 13] << 16;
+ status.events[i].fault_address |= bytes[i * 10 + 14] << 24;
+
+ dev_info(GIP_DEV(attachment),
+ "Attachment %i event type %i, tag %i address %x\n",
+ attachment->attachment_index,
+ status.events[i].event_type,
+ status.events[i].fault_tag,
+ status.events[i].fault_address);
+ }
+ }
+ }
+
+ return gip_ensure_metadata(attachment);
+}
+
+static int gip_handle_command_metadata_respose(struct gip_attachment *attachment,
+ const struct gip_header *header, const uint8_t *bytes, int num_bytes)
+{
+ struct gip_metadata metadata = {0};
+ const guid_t *expected_guid = NULL;
+ bool found_expected_guid;
+ bool found_controller_guid = false;
+ int i;
+ int rc;
+
+ rc = gip_parse_metadata(GIP_DEV(attachment), &metadata, bytes, num_bytes);
+ if (rc)
+ return rc;
+
+ if (attachment->got_metadata == GIP_METADATA_GOT) {
+ gip_metadata_free(GIP_DEV(attachment), &attachment->metadata);
+ if (attachment->input) {
+ input_unregister_device(attachment->input);
+ attachment->input = NULL;
+ }
+ }
+
+ attachment->metadata = metadata;
+ attachment->got_metadata = GIP_METADATA_GOT;
+ attachment->features = 0;
+ cancel_delayed_work_sync(&attachment->metadata_next);
+
+ attachment->attachment_type = GIP_TYPE_UNKNOWN;
+ for (i = 0; i < metadata.device.num_preferred_types; i++) {
+ const char *type = metadata.device.preferred_types[i];
+
+ dev_dbg(GIP_DEV(attachment), "Device preferred type: %s\n",
+ type);
+ }
+ for (i = 0; i < metadata.device.num_preferred_types; i++) {
+ const char *type = metadata.device.preferred_types[i];
+
+ if (strcmp(type, "Windows.Xbox.Input.Gamepad") == 0) {
+ attachment->attachment_type = GIP_TYPE_GAMEPAD;
+ expected_guid = &guid_gamepad;
+ break;
+ }
+ if (strcmp(type, "Microsoft.Xbox.Input.ArcadeStick") == 0) {
+ attachment->attachment_type = GIP_TYPE_ARCADE_STICK;
+ expected_guid = &guid_arcade_stick;
+ break;
+ }
+ if (strcmp(type, "Windows.Xbox.Input.ArcadeStick") == 0) {
+ attachment->attachment_type = GIP_TYPE_ARCADE_STICK;
+ expected_guid = &guid_arcade_stick;
+ break;
+ }
+ if (strcmp(type, "Microsoft.Xbox.Input.FlightStick") == 0) {
+ attachment->attachment_type = GIP_TYPE_FLIGHT_STICK;
+ expected_guid = &guid_flight_stick;
+ break;
+ }
+ if (strcmp(type, "Windows.Xbox.Input.FlightStick") == 0) {
+ attachment->attachment_type = GIP_TYPE_FLIGHT_STICK;
+ expected_guid = &guid_flight_stick;
+ break;
+ }
+ if (strcmp(type, "Microsoft.Xbox.Input.Wheel") == 0) {
+ attachment->attachment_type = GIP_TYPE_WHEEL;
+ expected_guid = &guid_wheel;
+ break;
+ }
+ if (strcmp(type, "Windows.Xbox.Input.Wheel") == 0) {
+ attachment->attachment_type = GIP_TYPE_WHEEL;
+ expected_guid = &guid_wheel;
+ break;
+ }
+ if (strcmp(type, "Windows.Xbox.Input.NavigationController") == 0) {
+ attachment->attachment_type = GIP_TYPE_NAVIGATION_CONTROLLER;
+ expected_guid = &guid_navigation;
+ break;
+ }
+ if (strcmp(type, "Windows.Xbox.Input.Chatpad") == 0) {
+ attachment->attachment_type = GIP_TYPE_CHATPAD;
+ break;
+ }
+ if (strcmp(type, "Windows.Xbox.Input.Headset") == 0) {
+ attachment->attachment_type = GIP_TYPE_HEADSET;
+ expected_guid = &guid_headset;
+ break;
+ }
+ }
+
+ found_expected_guid = !expected_guid;
+ for (i = 0; i < metadata.device.num_supported_interfaces; i++) {
+ const guid_t *guid = &metadata.device.supported_interfaces[i];
+
+ dev_dbg(GIP_DEV(attachment), "Supported interface: %pUl\n", guid);
+ if (expected_guid && guid_equal(expected_guid, guid))
+ found_expected_guid = true;
+
+ if (guid_equal(&guid_controller, guid)) {
+ found_controller_guid = true;
+ continue;
+ }
+ if (guid_equal(&guid_dev_auth_pc_opt_out, guid)) {
+ attachment->features |= GIP_FEATURE_SECURITY_OPT_OUT;
+ continue;
+ }
+ if (guid_equal(&guid_console_function_map, guid)) {
+ attachment->features |= GIP_FEATURE_CONSOLE_FUNCTION_MAP;
+ continue;
+ }
+ if (guid_equal(&guid_console_function_map_overflow, guid)) {
+ attachment->features |= GIP_FEATURE_CONSOLE_FUNCTION_MAP_OVERFLOW;
+ continue;
+ }
+ if (guid_equal(&guid_elite_buttons, guid)) {
+ attachment->features |= GIP_FEATURE_ELITE_BUTTONS;
+ continue;
+ }
+ if (guid_equal(&guid_dynamic_latency_input, guid)) {
+ attachment->features |= GIP_FEATURE_DYNAMIC_LATENCY_INPUT;
+ continue;
+ }
+ }
+
+ for (i = 0; i < metadata.num_messages; i++) {
+ struct gip_message_metadata *message = &metadata.message_metadata[i];
+
+ if (message->type == GIP_CMD_DIRECT_MOTOR && message->length >= 9
+ && (message->flags & GIP_MESSAGE_FLAG_DOWNSTREAM))
+ attachment->features |= GIP_FEATURE_MOTOR_CONTROL;
+ }
+
+ if (!found_expected_guid || (gip_attachment_is_controller(attachment)
+ && !found_controller_guid))
+ dev_dbg(GIP_DEV(attachment),
+ "Controller was missing expected GUID. "
+ "This controller probably won't work on an actual Xbox.\n");
+
+ if ((attachment->features & GIP_FEATURE_GUIDE_COLOR)
+ && !gip_supports_vendor_message(attachment,
+ GIP_CMD_GUIDE_COLOR, false))
+ attachment->features &= ~GIP_FEATURE_GUIDE_COLOR;
+
+ gip_handle_quirks(attachment);
+
+ dev_dbg(GIP_DEV(attachment),
+ "Attachment %i of type %i has features: %02x\n",
+ attachment->attachment_index, attachment->attachment_type,
+ attachment->features);
+
+ return gip_send_init_sequence(attachment);
+}
+
+static int gip_handle_command_security(struct gip_attachment *attachment,
+ const struct gip_header *header, const uint8_t *bytes, int num_bytes)
+{
+ /* TODO: Needed for controllers that connect via dongles */
+ dev_warn(GIP_DEV(attachment), "Unimplemented Security message\n");
+ return -ENOTSUPP;
+}
+
+static int gip_handle_command_guide_button_status(struct gip_attachment *attachment,
+ const struct gip_header *header, const uint8_t *bytes, int num_bytes)
+{
+ if (num_bytes < 2)
+ return -EINVAL;
+ if (!attachment->input)
+ return -ENODEV;
+
+ if (bytes[1] == VK_LWIN) {
+ input_report_key(attachment->input, BTN_MODE, bytes[0] & 3);
+ input_sync(attachment->input);
+ }
+
+ return 0;
+}
+
+static int gip_handle_command_audio_control(struct gip_attachment *attachment,
+ const struct gip_header *header, const uint8_t *bytes, int num_bytes)
+{
+ /* TODO: Needed for audio */
+ dev_warn(GIP_DEV(attachment), "Unimplemented Audio Control message\n");
+ return -ENOTSUPP;
+}
+
+static int gip_handle_command_firmware(struct gip_attachment *attachment,
+ const struct gip_header *header, const uint8_t *bytes, int num_bytes)
+{
+ if (num_bytes < 1)
+ return -EINVAL;
+
+ if (bytes[0] == 1) {
+ uint16_t major, minor, build, rev;
+
+ if (num_bytes < 14) {
+ dev_dbg(GIP_DEV(attachment),
+ "Discarding too-short firmware message\n");
+
+ return -EINVAL;
+ }
+ major = bytes[6];
+ major |= bytes[7] << 8;
+ minor = bytes[8];
+ minor |= bytes[9] << 8;
+ build = bytes[10];
+ build |= bytes[11] << 8;
+ rev = bytes[12];
+ rev |= bytes[13] << 8;
+
+ dev_dbg(GIP_DEV(attachment),
+ "Firmware version: %d.%d.%d rev %d\n", major, minor, build, rev);
+
+ attachment->firmware_major_version = major;
+ attachment->firmware_minor_version = minor;
+
+ if (attachment->vendor_id == 0x045e
+ && attachment->product_id == 0x0b00)
+ return gip_enable_elite_buttons(attachment);
+
+ return 0;
+ }
+
+ dev_warn(GIP_DEV(attachment), "Unimplemented Firmware message\n");
+
+ return -ENOTSUPP;
+}
+
+static int gip_handle_command_raw_report(struct gip_attachment *attachment,
+ const struct gip_header *header, const uint8_t *bytes, int num_bytes)
+{
+ if (!attachment->input)
+ return -ENODEV;
+
+ if (num_bytes < 17) {
+ dev_dbg(GIP_DEV(attachment), "Discarding too-short raw report\n");
+ return -EINVAL;
+ }
+
+ if ((attachment->features & GIP_FEATURE_ELITE_BUTTONS)
+ && attachment->xbe_format == GIP_BTN_FMT_XBE2_RAW) {
+ input_report_abs(attachment->input, ABS_PROFILE, bytes[15] & 3);
+ if (bytes[15] & 3) {
+ input_report_key(attachment->input, BTN_GRIPL, 0);
+ input_report_key(attachment->input, BTN_GRIPR, 0);
+ input_report_key(attachment->input, BTN_GRIPL2, 0);
+ input_report_key(attachment->input, BTN_GRIPR2, 0);
+ } else {
+ input_report_key(attachment->input, BTN_GRIPL,
+ bytes[GIP_BTN_OFFSET_XBE2] & BIT(2));
+ input_report_key(attachment->input, BTN_GRIPR,
+ bytes[GIP_BTN_OFFSET_XBE2] & BIT(0));
+ input_report_key(attachment->input, BTN_GRIPL2,
+ bytes[GIP_BTN_OFFSET_XBE2] & BIT(3));
+ input_report_key(attachment->input, BTN_GRIPR2,
+ bytes[GIP_BTN_OFFSET_XBE2] & BIT(1));
+ }
+
+ input_sync(attachment->input);
+ }
+ return 0;
+}
+
+static int gip_handle_command_hid_report(struct gip_attachment *attachment,
+ const struct gip_header *header, uint8_t *bytes, int num_bytes)
+{
+ if (attachment->hdev)
+ return hid_input_report(attachment->hdev, HID_INPUT_REPORT,
+ bytes, num_bytes, true);
+ dev_warn(GIP_DEV(attachment), "Got HID report with no HID descriptor\n");
+ return -EINVAL;
+}
+
+static int gip_handle_command_extended(struct gip_attachment *attachment,
+ const struct gip_header *header, const uint8_t *bytes, int num_bytes)
+{
+ if (num_bytes < 2)
+ return -EINVAL;
+
+ if (bytes[1] != GIP_EXTENDED_STATUS_OK) {
+ dev_dbg(GIP_DEV(attachment),
+ "Extended message type %02x failed with status %i\n",
+ bytes[0], bytes[1]);
+ return -EPROTO;
+ }
+
+ switch (bytes[0]) {
+ case GIP_EXTCMD_GET_SERIAL_NUMBER:
+ memcpy(attachment->serial, &bytes[2],
+ min(sizeof(attachment->serial), (size_t)(num_bytes - 2)));
+ break;
+ default:
+ /* TODO */
+ dev_dbg(GIP_DEV(attachment), "Unimplemented extended message type %02x\n",
+ bytes[0]);
+ return -ENOTSUPP;
+ }
+
+ return 0;
+}
+
+static void gip_handle_navigation_report(struct gip_attachment *attachment,
+ struct input_dev *dev, const u8 *bytes, int num_bytes)
+{
+ input_report_key(dev, BTN_START, bytes[0] & BIT(2));
+ input_report_key(dev, BTN_SELECT, bytes[0] & BIT(3));
+ input_report_key(dev, BTN_A, bytes[0] & BIT(4));
+ input_report_key(dev, BTN_B, bytes[0] & BIT(5));
+ input_report_key(dev, BTN_X, bytes[0] & BIT(6));
+ input_report_key(dev, BTN_Y, bytes[0] & BIT(7));
+
+ if (attachment->dpad_as_buttons) {
+ input_report_key(dev, BTN_DPAD_UP, bytes[1] & BIT(0));
+ input_report_key(dev, BTN_DPAD_DOWN, bytes[1] & BIT(1));
+ input_report_key(dev, BTN_DPAD_LEFT, bytes[1] & BIT(2));
+ input_report_key(dev, BTN_DPAD_RIGHT, bytes[1] & BIT(3));
+ } else {
+ input_report_abs(dev, ABS_HAT0X,
+ !!(bytes[1] & BIT(3)) - !!(bytes[1] & BIT(2)));
+ input_report_abs(dev, ABS_HAT0Y,
+ !!(bytes[1] & BIT(1)) - !!(bytes[1] & BIT(0)));
+ }
+
+ if (attachment->attachment_type == GIP_TYPE_ARCADE_STICK) {
+ /* Previous */
+ input_report_key(dev, BTN_TR, bytes[1] & BIT(4));
+ /* Next */
+ input_report_key(dev, BTN_TL, bytes[1] & BIT(5));
+ } else {
+ input_report_key(dev, BTN_TL, bytes[1] & BIT(4));
+ input_report_key(dev, BTN_TR, bytes[1] & BIT(5));
+ }
+}
+
+static void gip_handle_gamepad_report(struct gip_attachment *attachment,
+ struct input_dev *dev, const uint8_t *bytes, int num_bytes)
+{
+ int16_t axis;
+
+ input_report_key(dev, BTN_THUMBL, bytes[1] & BIT(6));
+ input_report_key(dev, BTN_THUMBR, bytes[1] & BIT(7));
+
+ axis = bytes[2];
+ axis |= bytes[3] << 8;
+ input_report_abs(dev, ABS_Z, axis);
+
+ axis = bytes[4];
+ axis |= bytes[5] << 8;
+ input_report_abs(dev, ABS_RZ, axis);
+
+ axis = bytes[6];
+ axis |= bytes[7] << 8;
+ input_report_abs(dev, ABS_X, axis);
+ axis = bytes[8];
+ axis |= bytes[9] << 8;
+ input_report_abs(dev, ABS_Y, ~axis);
+ axis = bytes[10];
+ axis |= bytes[11] << 8;
+ input_report_abs(dev, ABS_RX, axis);
+ axis = bytes[12];
+ axis |= bytes[13] << 8;
+ input_report_abs(dev, ABS_RY, ~axis);
+}
+
+static void gip_handle_arcade_stick_report(struct gip_attachment *attachment,
+ struct input_dev *dev, const uint8_t *bytes, int num_bytes)
+{
+ if (attachment->extra_axes >= 1) {
+ int16_t axis;
+
+ axis = bytes[2];
+ axis |= bytes[3] << 8;
+ input_report_abs(dev, ABS_Z, axis);
+ }
+
+ if (attachment->extra_axes >= 2) {
+ int16_t axis;
+
+ axis = bytes[4];
+ axis |= bytes[5] << 8;
+ input_report_abs(dev, ABS_RZ, axis);
+ }
+
+ if (num_bytes >= 19) {
+ /* Extra button 6 */
+ input_report_abs(dev, ABS_RZ, (bytes[18] & BIT(6)) ? 32767 : -32768);
+ /* Extra button 7 */
+ input_report_abs(dev, ABS_Z, (bytes[18] & BIT(7)) ? 32767 : -32768);
+ }
+}
+
+static int gip_handle_ll_input_report(struct gip_attachment *attachment,
+ const struct gip_header *header, const uint8_t *bytes, int num_bytes)
+{
+ struct input_dev *dev = attachment->input;
+
+ if (!dev)
+ return -ENODEV;
+
+ if (attachment->device_state != GIP_STATE_START) {
+ dev_dbg(GIP_DEV(attachment), "Discarding early input report\n");
+ attachment->device_state = GIP_STATE_START;
+ return 0;
+ }
+
+ if (num_bytes < 14) {
+ dev_dbg(GIP_DEV(attachment), "Discarding too-short input report\n");
+ return -EINVAL;
+ }
+
+ gip_handle_navigation_report(attachment, dev, bytes, num_bytes);
+
+ switch (attachment->attachment_type) {
+ case GIP_TYPE_GAMEPAD:
+ default:
+ gip_handle_gamepad_report(attachment, dev, bytes, num_bytes);
+ break;
+ case GIP_TYPE_ARCADE_STICK:
+ gip_handle_arcade_stick_report(attachment, dev, bytes, num_bytes);
+ break;
+ }
+
+ if (attachment->features & GIP_FEATURE_ELITE_BUTTONS) {
+ bool grip[4] = { 0, 0, 0, 0 };
+ int profile = -1;
+
+ if (attachment->xbe_format == GIP_BTN_FMT_XBE1
+ && num_bytes > GIP_BTN_OFFSET_XBE1) {
+ profile = bytes[GIP_BTN_OFFSET_XBE1] >> 4;
+ if (profile) {
+ grip[0] = bytes[GIP_BTN_OFFSET_XBE1] & BIT(0);
+ grip[1] = bytes[GIP_BTN_OFFSET_XBE1] & BIT(1);
+ grip[2] = bytes[GIP_BTN_OFFSET_XBE1] & BIT(2);
+ grip[3] = bytes[GIP_BTN_OFFSET_XBE1] & BIT(3);
+ }
+ } else if ((attachment->xbe_format == GIP_BTN_FMT_XBE2_4
+ || attachment->xbe_format == GIP_BTN_FMT_XBE2_5)
+ && num_bytes > GIP_BTN_OFFSET_XBE2) {
+ int profile_offset;
+
+ if (attachment->xbe_format == GIP_BTN_FMT_XBE2_4)
+ profile_offset = 15;
+ else
+ profile_offset = 20;
+ profile = bytes[profile_offset] & 3;
+
+ if (!profile) {
+ grip[0] = bytes[GIP_BTN_OFFSET_XBE2] & BIT(2);
+ grip[1] = bytes[GIP_BTN_OFFSET_XBE2] & BIT(0);
+ grip[2] = bytes[GIP_BTN_OFFSET_XBE2] & BIT(3);
+ grip[3] = bytes[GIP_BTN_OFFSET_XBE2] & BIT(1);
+ }
+ }
+ if (profile >= 0) {
+ input_report_key(attachment->input, BTN_GRIPL,
+ grip[0]);
+ input_report_key(attachment->input, BTN_GRIPR,
+ grip[1]);
+ input_report_key(attachment->input, BTN_GRIPL2,
+ grip[2]);
+ input_report_key(attachment->input, BTN_GRIPR2,
+ grip[3]);
+ input_report_abs(attachment->input, ABS_PROFILE,
+ profile);
+ }
+ }
+
+ if (attachment->vendor_id == 0x045e && attachment->product_id == 0x0b0a
+ && num_bytes >= 31)
+ input_report_abs(attachment->input, ABS_PROFILE,
+ bytes[30] & 3);
+
+ if ((attachment->features & GIP_FEATURE_CONSOLE_FUNCTION_MAP)
+ && num_bytes >= 32) {
+ int function_map_offset = -1;
+
+ if (attachment->features & GIP_FEATURE_DYNAMIC_LATENCY_INPUT) {
+ /* The dynamic latency input bytes are after the console function map */
+ if (num_bytes >= 40)
+ function_map_offset = num_bytes - 26;
+ } else {
+ function_map_offset = num_bytes - 18;
+ }
+ if (function_map_offset >= 14) {
+ input_report_key(dev, KEY_RECORD,
+ bytes[function_map_offset] & BIT(0));
+ }
+ }
+
+ input_sync(dev);
+
+ return 0;
+}
+
+static int gip_handle_ll_static_configuration(struct gip_attachment *attachment,
+ const struct gip_header *header, const uint8_t *bytes, int num_bytes)
+{
+ /* TODO */
+ dev_dbg(GIP_DEV(attachment), "Unimplemented Static Configuration message\n");
+ return -ENOTSUPP;
+}
+
+static int gip_handle_ll_button_info_report(struct gip_attachment *attachment,
+ const struct gip_header *header, const uint8_t *bytes, int num_bytes)
+{
+ /* TODO */
+ dev_dbg(GIP_DEV(attachment), "Unimplemented Button Info Report message\n");
+ return -ENOTSUPP;
+}
+
+static int gip_handle_ll_overflow_input_report(struct gip_attachment *attachment,
+ const struct gip_header *header, const uint8_t *bytes, int num_bytes)
+{
+ /* TODO: Unknown if any devices actually use this */
+ dev_dbg(GIP_DEV(attachment), "Unimplemented Overflow Input Report message\n");
+ return -ENOTSUPP;
+}
+
+static int gip_handle_audio_data(struct gip_attachment *attachment,
+ const struct gip_header *header, const uint8_t *bytes, int num_bytes)
+{
+ /* TODO: Needed for audio support */
+ dev_dbg(GIP_DEV(attachment), "Unimplemented Audio Data message\n");
+ return -ENOTSUPP;
+}
+
+static int gip_handle_system_message(struct gip_attachment *attachment,
+ const struct gip_header *header, uint8_t *bytes, int num_bytes)
+{
+ if (!gip_supports_system_message(attachment, header->message_type, true)) {
+ dev_warn(GIP_DEV(attachment),
+ "Received claimed-unsupported system message type %02x\n",
+ header->message_type);
+ return -EINVAL;
+ }
+ switch (header->message_type) {
+ case GIP_CMD_PROTO_CONTROL:
+ return gip_handle_command_protocol_control(attachment, header,
+ bytes, num_bytes);
+ case GIP_CMD_HELLO_DEVICE:
+ return gip_handle_command_hello_device(attachment, header,
+ bytes, num_bytes);
+ case GIP_CMD_STATUS_DEVICE:
+ return gip_handle_command_status_device(attachment, header,
+ bytes, num_bytes);
+ case GIP_CMD_METADATA:
+ return gip_handle_command_metadata_respose(attachment, header,
+ bytes, num_bytes);
+ case GIP_CMD_SECURITY:
+ return gip_handle_command_security(attachment, header, bytes,
+ num_bytes);
+ case GIP_CMD_GUIDE_BUTTON:
+ return gip_handle_command_guide_button_status(attachment,
+ header, bytes, num_bytes);
+ case GIP_CMD_AUDIO_CONTROL:
+ return gip_handle_command_audio_control(attachment, header,
+ bytes, num_bytes);
+ case GIP_CMD_FIRMWARE:
+ return gip_handle_command_firmware(attachment, header, bytes,
+ num_bytes);
+ case GIP_CMD_HID_REPORT:
+ return gip_handle_command_hid_report(attachment, header,
+ bytes, num_bytes);
+ case GIP_CMD_EXTENDED:
+ return gip_handle_command_extended(attachment, header, bytes,
+ num_bytes);
+ case GIP_AUDIO_DATA:
+ return gip_handle_audio_data(attachment, header, bytes,
+ num_bytes);
+ default:
+ dev_warn(GIP_DEV(attachment),
+ "Received unknown system message type %02x\n",
+ header->message_type);
+ return -EINVAL;
+ }
+}
+
+static struct gip_attachment *gip_ensure_attachment(struct gip_device *device,
+ uint8_t attachment_index)
+{
+ struct gip_attachment *attachment = device->attachments[attachment_index];
+
+ if (!attachment) {
+ attachment = devm_kzalloc(GIP_DEV(device),
+ sizeof(*attachment), GFP_KERNEL);
+ if (!attachment)
+ return ERR_PTR(-ENOMEM);
+
+ attachment->attachment_index = attachment_index;
+ if (attachment_index > 0)
+ attachment->attachment_type = GIP_TYPE_UNKNOWN;
+
+ attachment->device = device;
+ attachment->metadata.device.in_system_messages[0] =
+ GIP_DEFAULT_IN_SYSTEM_MESSAGES;
+ attachment->metadata.device.out_system_messages[0] =
+ GIP_DEFAULT_OUT_SYSTEM_MESSAGES;
+ device->attachments[attachment_index] = attachment;
+
+ mutex_init(&attachment->lock);
+ INIT_DELAYED_WORK(&attachment->fragment_timeout, gip_fragment_timeout);
+ INIT_DELAYED_WORK(&attachment->metadata_next, gip_retry_metadata);
+ }
+ return attachment;
+}
+
+static int gip_handle_message(struct gip_attachment *attachment,
+ const struct gip_header *header, uint8_t *bytes, int num_bytes)
+{
+ if (header->flags & GIP_FLAG_SYSTEM)
+ return gip_handle_system_message(attachment, header, bytes,
+ num_bytes);
+
+ switch (header->message_type) {
+ case GIP_CMD_RAW_REPORT:
+ if (attachment->features & GIP_FEATURE_ELITE_BUTTONS)
+ return gip_handle_command_raw_report(attachment,
+ header, bytes, num_bytes);
+ break;
+ case GIP_LL_INPUT_REPORT:
+ return gip_handle_ll_input_report(attachment, header, bytes,
+ num_bytes);
+ case GIP_LL_STATIC_CONFIGURATION:
+ return gip_handle_ll_static_configuration(attachment, header,
+ bytes, num_bytes);
+ case GIP_LL_BUTTON_INFO_REPORT:
+ return gip_handle_ll_button_info_report(attachment, header,
+ bytes, num_bytes);
+ case GIP_LL_OVERFLOW_INPUT_REPORT:
+ return gip_handle_ll_overflow_input_report(attachment, header,
+ bytes, num_bytes);
+ }
+ dev_warn(GIP_DEV(attachment),
+ "Received unknown vendor message type %02x\n",
+ header->message_type);
+ return -ENOTSUPP;
+}
+
+static int gip_receive_fragment(struct gip_attachment *attachment,
+ const struct gip_header *header, int offset,
+ uint64_t *fragment_offset, uint16_t *bytes_remaining, uint8_t *bytes,
+ int num_bytes)
+{
+ int rc = 0;
+
+ if (header->flags & GIP_FLAG_INIT_FRAG) {
+ uint64_t total_length;
+
+ if (attachment->fragment_message) {
+ /*
+ * Reset fragment buffer if we get a new initial
+ * fragment before finishing the last message.
+ * TODO: Is this the correct behavior?
+ */
+ devm_kfree(GIP_DEV(attachment), attachment->fragment_data);
+ attachment->fragment_data = NULL;
+ }
+ offset += gip_decode_length(&total_length, &bytes[offset],
+ num_bytes - offset);
+ if (total_length > MAX_MESSAGE_LENGTH)
+ return -EINVAL;
+
+ attachment->total_length = total_length;
+ attachment->fragment_message = header->message_type;
+ if (header->length > num_bytes - offset) {
+ dev_warn(GIP_DEV(attachment),
+ "Received fragment that claims to be %llu bytes, expected %i\n",
+ header->length, num_bytes - offset);
+ return -EINVAL;
+ }
+ if (header->length > total_length) {
+ dev_warn(GIP_DEV(attachment),
+ "Received too long fragment, %llu bytes, exceeds %d\n",
+ header->length, attachment->total_length);
+ return -EINVAL;
+ }
+ attachment->fragment_data = devm_kmalloc(GIP_DEV(attachment),
+ attachment->total_length, GFP_KERNEL);
+ if (!attachment->fragment_data)
+ return -ENOMEM;
+ memcpy(attachment->fragment_data, &bytes[offset],
+ header->length);
+ *fragment_offset = header->length;
+ attachment->fragment_offset = header->length;
+ *bytes_remaining = attachment->total_length - header->length;
+ } else {
+ if (header->message_type != attachment->fragment_message) {
+ dev_warn(GIP_DEV(attachment),
+ "Received out of sequence message type %02x, expected %02x\n",
+ header->message_type, attachment->fragment_message);
+ gip_fragment_failed(attachment, header);
+ return -EINVAL;
+ }
+
+ offset += gip_decode_length(fragment_offset, &bytes[offset],
+ num_bytes - offset);
+ if (*fragment_offset != attachment->fragment_offset) {
+ dev_warn(GIP_DEV(attachment),
+ "Received out of sequence fragment, (claimed %llu, expected %d)\n",
+ *fragment_offset, attachment->fragment_offset);
+ gip_acknowledge(attachment->device, header,
+ attachment->fragment_offset,
+ attachment->total_length - attachment->fragment_offset);
+ return -EINVAL;
+ } else if (*fragment_offset + header->length > attachment->total_length) {
+ dev_warn(GIP_DEV(attachment),
+ "Received too long fragment, %llu exceeds %d\n",
+ *fragment_offset + header->length, attachment->total_length);
+ gip_fragment_failed(attachment, header);
+ return -EINVAL;
+ }
+
+ *bytes_remaining = attachment->total_length -
+ (*fragment_offset + header->length);
+ if (header->length != 0) {
+ memcpy(&attachment->fragment_data[*fragment_offset],
+ &bytes[offset], header->length);
+ } else {
+ rc = gip_handle_message(attachment, header,
+ attachment->fragment_data,
+ attachment->total_length);
+ devm_kfree(GIP_DEV(attachment), attachment->fragment_data);
+ attachment->fragment_data = NULL;
+ attachment->fragment_message = 0;
+ }
+ *fragment_offset += header->length;
+ attachment->fragment_offset = *fragment_offset;
+ }
+ cancel_delayed_work_sync(&attachment->fragment_timeout);
+ schedule_delayed_work(&attachment->fragment_timeout, HZ);
+
+ return rc;
+}
+
+static int gip_receive_message(struct gip_device *device, uint8_t *bytes,
+ int num_bytes)
+{
+ struct gip_header header;
+ int offset = 3;
+ int rc = 0;
+ uint64_t fragment_offset = 0;
+ uint16_t bytes_remaining = 0;
+ bool is_fragment;
+ uint8_t attachment_index;
+ struct gip_attachment *attachment;
+
+ if (num_bytes < 5)
+ return -EINVAL;
+
+ header.message_type = bytes[0];
+ header.flags = bytes[1];
+ header.sequence_id = bytes[2];
+ offset += gip_decode_length(&header.length, &bytes[offset], num_bytes - offset);
+
+ is_fragment = header.flags & GIP_FLAG_FRAGMENT;
+ attachment_index = header.flags & GIP_FLAG_ATTACHMENT_MASK;
+ attachment = gip_ensure_attachment(device, attachment_index);
+
+ print_hex_dump_debug(KBUILD_MODNAME ": Received message: ", DUMP_PREFIX_OFFSET,
+ 16, 1, bytes, num_bytes, false);
+
+ guard(mutex)(&attachment->lock);
+ /* Handle coalescing fragmented messages */
+ if (is_fragment) {
+ rc = gip_receive_fragment(attachment, &header, offset,
+ &fragment_offset, &bytes_remaining, bytes, num_bytes);
+ } else if (header.length + offset > num_bytes) {
+ dev_warn(GIP_DEV(device),
+ "Received message with erroneous length (claimed %llu, actual %d), discarding\n",
+ header.length + offset, num_bytes);
+ rc = -EINVAL;
+ } else {
+ num_bytes -= offset;
+ bytes += offset;
+ fragment_offset = header.length;
+ rc = gip_handle_message(attachment, &header, bytes, num_bytes);
+ }
+
+ if (!rc && (header.flags & GIP_FLAG_ACME))
+ gip_acknowledge(device, &header, fragment_offset, bytes_remaining);
+
+ return rc;
+}
+
+static void gip_receive_work(struct work_struct *work)
+{
+ struct gip_device *device = container_of(work, struct gip_device,
+ receive_message);
+ unsigned long flags;
+
+ spin_lock_irqsave(&device->message_lock, flags);
+ while (device->pending_in_messages) {
+ struct gip_raw_message *message = &device->in_queue[device->next_in_message];
+
+ spin_unlock_irqrestore(&device->message_lock, flags);
+
+ gip_receive_message(device, message->bytes, message->num_bytes);
+
+ spin_lock_irqsave(&device->message_lock, flags);
+ device->next_in_message = (device->next_in_message + 1) % MAX_IN_MESSAGES;
+ device->pending_in_messages--;
+ }
+ spin_unlock_irqrestore(&device->message_lock, flags);
+}
+
+static void gip_urb_in(struct urb *urb)
+{
+ struct gip_interface *intf = urb->context;
+ struct gip_device *gip = intf->device;
+ struct device *dev = &intf->intf->dev;
+ int status = urb->status;
+ int message_id;
+ struct gip_raw_message *message;
+ unsigned long flags;
+
+ switch (status) {
+ case 0:
+ /* success */
+ break;
+ case -ECONNRESET:
+ case -ENOENT:
+ case -ESHUTDOWN:
+ /* this urb is terminated, clean up */
+ dev_dbg(dev, "%s - urb shutting down with status: %d\n",
+ __func__, status);
+ return;
+ default:
+ dev_dbg(dev, "%s - urb has status of: %d\n",
+ __func__, status);
+ goto exit;
+ }
+
+ spin_lock_irqsave(&gip->message_lock, flags);
+ if (gip->pending_in_messages >= MAX_IN_MESSAGES) {
+ dev_err(GIP_DEV(gip), "Input queue is full; dropping message\n");
+ } else {
+ message_id = (gip->next_in_message + gip->pending_in_messages) % MAX_IN_MESSAGES;
+ message = &gip->in_queue[message_id];
+ gip->pending_in_messages++;
+ memcpy(message->bytes, intf->in_data, urb->actual_length);
+ message->num_bytes = urb->actual_length;
+ }
+ spin_unlock_irqrestore(&gip->message_lock, flags);
+ schedule_work(&gip->receive_message);
+
+exit:
+ status = usb_submit_urb(urb, GFP_ATOMIC);
+ if (status)
+ dev_err(dev, "%s - usb_submit_urb failed with result %d\n",
+ __func__, status);
+}
+
+static void gip_urb_out(struct urb *urb)
+{
+ struct gip_interface *intf = urb->context;
+ struct device *dev = &intf->intf->dev;
+ int status = urb->status;
+
+ guard(spinlock_irqsave)(&intf->device->message_lock);
+
+ switch (status) {
+ case 0:
+ /* success */
+ if (intf->pending_out)
+ gip_prepare_urb(intf);
+ else
+ intf->urb_out_active = false;
+ break;
+
+ case -ECONNRESET:
+ case -ENOENT:
+ case -ESHUTDOWN:
+ /* this urb is terminated, clean up */
+ dev_dbg(dev, "%s - urb shutting down with status: %d\n",
+ __func__, status);
+ intf->urb_out_active = false;
+ break;
+
+ default:
+ dev_dbg(dev, "%s - nonzero urb status received: %d\n",
+ __func__, status);
+ break;
+ }
+}
+
+static int gip_init_input(struct gip_interface *intf,
+ struct usb_endpoint_descriptor *ep_in)
+{
+ int error;
+ struct usb_device *udev = interface_to_usbdev(intf->intf);
+
+ intf->urb_in = usb_alloc_urb(0, GFP_KERNEL);
+ if (!intf->urb_in)
+ return -ENOMEM;
+
+ intf->in_data = usb_alloc_coherent(udev, intf->mtu, GFP_KERNEL,
+ &intf->urb_in->transfer_dma);
+
+ if (!intf->in_data) {
+ return -ENOMEM;
+ goto err_free_urb;
+ }
+
+ usb_fill_int_urb(intf->urb_in, udev,
+ usb_rcvintpipe(udev, ep_in->bEndpointAddress),
+ intf->in_data, intf->mtu, gip_urb_in, intf,
+ ep_in->bInterval);
+ intf->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
+
+ return 0;
+
+err_free_urb:
+ usb_free_urb(intf->urb_in);
+ intf->urb_in = NULL;
+
+ return error;
+}
+
+static int gip_init_output(struct gip_interface *intf,
+ struct usb_endpoint_descriptor *ep_out)
+{
+ int error;
+ struct usb_device *udev = interface_to_usbdev(intf->intf);
+
+ if (usb_ifnum_to_if(udev, GIP_WIRED_INTF_AUDIO)) {
+ /*
+ * Explicitly disable the audio interface. This is needed
+ * for some controllers, such as the PowerA Enhanced Wired
+ * Controller for Series X|S (0x20d6:0x200e) to report the
+ * guide button.
+ */
+ error = usb_set_interface(udev, GIP_WIRED_INTF_AUDIO, 0);
+ if (error)
+ dev_warn(GIP_DEV(intf),
+ "unable to disable audio interface: %d\n",
+ error);
+ }
+
+ init_usb_anchor(&intf->out_anchor);
+
+ intf->urb_out = usb_alloc_urb(0, GFP_KERNEL);
+ if (!intf->urb_out)
+ error = -ENOMEM;
+
+ intf->out_data = usb_alloc_coherent(udev, intf->mtu, GFP_KERNEL,
+ &intf->urb_out->transfer_dma);
+
+ if (!intf->out_data) {
+ return -ENOMEM;
+ goto err_free_urb;
+ }
+
+ usb_fill_int_urb(intf->urb_out, udev,
+ usb_sndintpipe(udev, ep_out->bEndpointAddress),
+ intf->out_data, intf->mtu, gip_urb_out, intf, ep_out->bInterval);
+ intf->urb_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
+
+ return 0;
+
+err_free_urb:
+ usb_free_urb(intf->urb_out);
+ intf->urb_out = NULL;
+ return error;
+}
+
+static void gip_deinit_output(struct gip_interface *intf)
+{
+ usb_free_coherent(interface_to_usbdev(intf->intf), intf->mtu, intf->out_data,
+ intf->urb_out->transfer_dma);
+ usb_free_urb(intf->urb_out);
+ intf->out_data = NULL;
+ intf->urb_out = NULL;
+}
+
+static void gip_deinit_input(struct gip_interface *intf)
+{
+ usb_free_coherent(interface_to_usbdev(intf->intf), intf->mtu,
+ intf->in_data, intf->urb_in->transfer_dma);
+ usb_free_urb(intf->urb_in);
+ intf->urb_in = NULL;
+}
+
+static int gip_interface_init(struct gip_interface *intf)
+{
+ struct usb_endpoint_descriptor *ep_in = NULL;
+ struct usb_endpoint_descriptor *ep_out = NULL;
+ int error = usb_find_common_endpoints(intf->intf->cur_altsetting,
+ NULL, NULL, &ep_in, &ep_out);
+
+ if (error)
+ return error;
+
+ if (!ep_in || !ep_out)
+ return -ENODEV;
+
+ error = gip_init_input(intf, ep_in);
+ if (error)
+ return error;
+
+ error = gip_init_output(intf, ep_out);
+ if (error)
+ goto err_free_input;
+
+ if (usb_submit_urb(intf->urb_in, GFP_KERNEL)) {
+ error = -EIO;
+ goto err_free_output;
+ }
+
+ return 0;
+
+err_free_output:
+ gip_deinit_output(intf);
+err_free_input:
+ gip_deinit_input(intf);
+ return error;
+}
+
+static int gip_probe(struct usb_interface *intf, const struct usb_device_id *id)
+{
+ struct usb_device *udev = interface_to_usbdev(intf);
+ struct gip_device *gip = NULL;
+ int error;
+
+ if (intf->cur_altsetting->desc.bInterfaceNumber != GIP_WIRED_INTF_DATA) {
+ /*
+ * The Xbox One controller lists three interfaces all with the
+ * same interface class, subclass and protocol. Differentiate by
+ * interface number.
+ */
+ return 0;
+ }
+
+ gip = devm_kzalloc(&udev->dev, sizeof(*gip), GFP_KERNEL);
+ if (!gip)
+ return -ENOMEM;
+
+ gip->udev = udev;
+ gip->data.device = gip;
+ gip->data.intf = intf;
+ gip->data.mtu = BASE_GIP_MTU;
+
+ INIT_WORK(&gip->receive_message, gip_receive_work);
+ spin_lock_init(&gip->message_lock);
+
+ error = gip_interface_init(&gip->data);
+ if (error) {
+ devm_kfree(GIP_DEV(gip), gip);
+ return error;
+ }
+
+ usb_set_intfdata(intf, gip);
+ return 0;
+}
+
+static int gip_shutdown(struct gip_device *device)
+{
+ int i;
+
+ cancel_work_sync(&device->receive_message);
+
+ for (i = 0; i < MAX_ATTACHMENTS; i++) {
+ struct gip_attachment *attachment = device->attachments[i];
+
+ if (!attachment)
+ continue;
+
+ guard(mutex)(&attachment->lock);
+ cancel_delayed_work_sync(&attachment->metadata_next);
+ cancel_delayed_work_sync(&attachment->fragment_timeout);
+
+ if (attachment->input) {
+ input_unregister_device(attachment->input);
+ attachment->input = NULL;
+ }
+ if (attachment->hdev) {
+ hid_destroy_device(attachment->hdev);
+ attachment->hdev = NULL;
+ }
+ }
+
+ return 0;
+}
+
+static void gip_disconnect(struct usb_interface *intf)
+{
+ struct gip_device *gip = usb_get_intfdata(intf);
+ unsigned long flags;
+ int i;
+
+ if (!gip)
+ return;
+
+ usb_kill_urb(gip->data.urb_in);
+
+ gip_shutdown(gip);
+
+ spin_lock_irqsave(&gip->message_lock, flags);
+ gip_deinit_input(&gip->data);
+ gip_deinit_output(&gip->data);
+ spin_unlock_irqrestore(&gip->message_lock, flags);
+
+ usb_set_intfdata(intf, NULL);
+
+ for (i = 0; i < MAX_ATTACHMENTS; i++) {
+ struct gip_attachment *attachment = gip->attachments[i];
+
+ if (!attachment)
+ continue;
+ devm_kfree(GIP_DEV(attachment), attachment->uniq);
+ devm_kfree(GIP_DEV(attachment), attachment);
+ }
+
+ devm_kfree(GIP_DEV(gip), gip);
+}
+
+static int gip_suspend(struct usb_interface *intf, pm_message_t message)
+{
+ struct gip_device *gip = usb_get_intfdata(intf);
+
+ if (!gip)
+ return 0;
+
+ usb_kill_urb(gip->data.urb_in);
+
+ if (gip->attachments[0]) {
+ struct gip_attachment *attachment = gip->attachments[0];
+
+ guard(mutex)(&attachment->lock);
+ gip_send_set_device_state(attachment, GIP_STATE_OFF);
+ attachment->device_state = GIP_STATE_OFF;
+ }
+
+ return gip_shutdown(gip);
+}
+
+static int gip_resume(struct usb_interface *intf)
+{
+ struct gip_device *gip = usb_get_intfdata(intf);
+
+ if (!gip)
+ return 0;
+
+ if (usb_submit_urb(gip->data.urb_in, GFP_KERNEL))
+ return -EIO;
+
+ return 0;
+}
+
+module_param(dpad_as_buttons, bool, 0444);
+MODULE_PARM_DESC(dpad_as_buttons, "Map the D-Pad as buttons instead of axes");
+
+/* The Xbox One controller uses subclass 71 and protocol 208. */
+#define GIP_VENDOR(vend) \
+ { \
+ .match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_INT_INFO, \
+ .idVendor = (vend), \
+ .bInterfaceClass = USB_CLASS_VENDOR_SPEC, \
+ .bInterfaceSubClass = 71, \
+ .bInterfaceProtocol = 208 \
+ }
+
+static const struct usb_device_id gip_table[] = {
+ /*
+ * Please keep this list sorted by vendor ID.
+ */
+ GIP_VENDOR(0x03f0), /* HP/HyperX */
+ GIP_VENDOR(0x044f), /* ThrustMaster */
+ GIP_VENDOR(0x045e), /* Microsoft */
+ GIP_VENDOR(0x046d), /* Logitech */
+ GIP_VENDOR(0x0738), /* Mad Catz */
+ GIP_VENDOR(0x0b05), /* ASUS */
+ GIP_VENDOR(0x0e6f), /* PDP */
+ GIP_VENDOR(0x0f0d), /* Hori */
+ GIP_VENDOR(0x10f5), /* Turtle Beach */
+ GIP_VENDOR(0x1532), /* Razer */
+ GIP_VENDOR(0x20d6), /* PowerA/BDA */
+ GIP_VENDOR(0x24c6), /* PowerA/BDA/ThrustMaster */
+ GIP_VENDOR(0x294b), /* Snakebyte */
+ GIP_VENDOR(0x2dc8), /* 8BitDo */
+ GIP_VENDOR(0x2e24), /* Hyperkin */
+ GIP_VENDOR(0x2e95), /* SCUF Gaming */
+ GIP_VENDOR(0x3285), /* Nacon */
+ GIP_VENDOR(0x3537), /* GameSir */
+ GIP_VENDOR(0x366c), /* ByoWave */
+ { }
+};
+
+MODULE_DEVICE_TABLE(usb, gip_table);
+
+static struct usb_driver gip_driver = {
+ .name = "xbox-gip",
+ .probe = gip_probe,
+ .disconnect = gip_disconnect,
+ .suspend = gip_suspend,
+ .resume = gip_resume,
+ .id_table = gip_table,
+};
+
+module_usb_driver(gip_driver);
+
+MODULE_AUTHOR("Vicki Pfau <vi@endrift.com>");
+MODULE_DESCRIPTION("Xbox Gaming Input Protocol driver");
+MODULE_LICENSE("GPL");
--
2.51.0
^ permalink raw reply related
* [PATCH v2 2/5] Input: xpad - Remove Xbox One support
From: Vicki Pfau @ 2025-09-17 1:19 UTC (permalink / raw)
To: Dmitry Torokhov, linux-input; +Cc: Vicki Pfau
In-Reply-To: <20250917011937.1649481-1-vi@endrift.com>
It has been superseded by xbox_gip. As the new driver is already at feature
parity, removing the fairly rough Xbox One support from xpad is safe and
will prevent any potential conflicts.
Signed-off-by: Vicki Pfau <vi@endrift.com>
---
Documentation/input/devices/xpad.rst | 17 +-
drivers/input/joystick/xpad.c | 634 +--------------------------
2 files changed, 11 insertions(+), 640 deletions(-)
diff --git a/Documentation/input/devices/xpad.rst b/Documentation/input/devices/xpad.rst
index a480bc781565e..fd2afdd7b4059 100644
--- a/Documentation/input/devices/xpad.rst
+++ b/Documentation/input/devices/xpad.rst
@@ -2,19 +2,19 @@
xpad - Linux USB driver for Xbox compatible controllers
=======================================================
-This driver exposes all first-party and third-party Xbox compatible
-controllers. It has a long history and has enjoyed considerable usage
-as Windows' xinput library caused most PC games to focus on Xbox
-controller compatibility.
+This driver exposes all first-party and third-party Xbox and Xbox 360
+compatible controllers. It has a long history and has enjoyed considerable
+usage as Windows' xinput library caused most PC games to focus on Xbox
+controller compatibility. Xbox One/Series controller support has been
+superseded by the xbox_gip driver, which specializes in the Gaming Input
+Protocl that is introduced on the Xbox One.
Due to backwards compatibility all buttons are reported as digital.
This only affects Original Xbox controllers. All later controller models
have only digital face buttons.
Rumble is supported on some models of Xbox 360 controllers but not of
-Original Xbox controllers nor on Xbox One controllers. As of writing
-the Xbox One's rumble protocol has not been reverse-engineered but in
-the future could be supported.
+Original Xbox controllers.
Notes
@@ -98,9 +98,6 @@ All generations of Xbox controllers speak USB over the wire.
- Wireless Xbox 360 controllers require a 'Xbox 360 Wireless Gaming Receiver
for Windows'
- Wired Xbox 360 controllers use standard USB connectors.
-- Xbox One controllers can be wireless but speak Wi-Fi Direct and are not
- yet supported.
-- Xbox One controllers can be wired and use standard Micro-USB connectors.
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 4c94297e17e66..0d9bd1dcb8c67 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -17,7 +17,6 @@
* - the iForce driver drivers/char/joystick/iforce.c
* - the skeleton-driver drivers/usb/usb-skeleton.c
* - Xbox 360 information http://www.free60.org/wiki/Gamepad
- * - Xbox One information https://github.com/quantus/xbox-one-controller-protocol
*
* Thanks to:
* - ITO Takayuki for providing essential xpad information on his website
@@ -80,10 +79,6 @@
#define MAP_DPAD_TO_BUTTONS BIT(0)
#define MAP_TRIGGERS_TO_BUTTONS BIT(1)
#define MAP_STICKS_TO_NULL BIT(2)
-#define MAP_SHARE_BUTTON BIT(3)
-#define MAP_PADDLES BIT(4)
-#define MAP_PROFILE_BUTTON BIT(5)
-#define MAP_SHARE_OFFSET BIT(6)
#define DANCEPAD_MAP_CONFIG (MAP_DPAD_TO_BUTTONS | \
MAP_TRIGGERS_TO_BUTTONS | MAP_STICKS_TO_NULL)
@@ -91,8 +86,7 @@
#define XTYPE_XBOX 0
#define XTYPE_XBOX360 1
#define XTYPE_XBOX360W 2
-#define XTYPE_XBOXONE 3
-#define XTYPE_UNKNOWN 4
+#define XTYPE_UNKNOWN 3
/* Send power-off packet to xpad360w after holding the mode button for this many
* seconds
@@ -137,16 +131,11 @@ static const struct xpad_device {
{ 0x03eb, 0xff02, "Wooting Two (Legacy)", 0, XTYPE_XBOX360 },
{ 0x03f0, 0x038D, "HyperX Clutch", 0, XTYPE_XBOX360 }, /* wired */
{ 0x03f0, 0x048D, "HyperX Clutch", 0, XTYPE_XBOX360 }, /* wireless */
- { 0x03f0, 0x0495, "HyperX Clutch Gladiate", 0, XTYPE_XBOXONE },
- { 0x03f0, 0x07A0, "HyperX Clutch Gladiate RGB", 0, XTYPE_XBOXONE },
- { 0x03f0, 0x08B6, "HyperX Clutch Gladiate", MAP_SHARE_BUTTON, XTYPE_XBOXONE }, /* v2 */
- { 0x03f0, 0x09B4, "HyperX Clutch Tanto", 0, XTYPE_XBOXONE },
{ 0x044f, 0x0f00, "Thrustmaster Wheel", 0, XTYPE_XBOX },
{ 0x044f, 0x0f03, "Thrustmaster Wheel", 0, XTYPE_XBOX },
{ 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", 0, XTYPE_XBOX },
{ 0x044f, 0x0f10, "Thrustmaster Modena GT Wheel", 0, XTYPE_XBOX },
{ 0x044f, 0xb326, "Thrustmaster Gamepad GP XID", 0, XTYPE_XBOX360 },
- { 0x044f, 0xd01e, "ThrustMaster, Inc. ESWAP X 2 ELDEN RING EDITION", 0, XTYPE_XBOXONE },
{ 0x045e, 0x0202, "Microsoft X-Box pad v1 (US)", 0, XTYPE_XBOX },
{ 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", 0, XTYPE_XBOX },
{ 0x045e, 0x0287, "Microsoft Xbox Controller S", 0, XTYPE_XBOX },
@@ -156,14 +145,7 @@ static const struct xpad_device {
{ 0x045e, 0x028f, "Microsoft X-Box 360 pad v2", 0, XTYPE_XBOX360 },
{ 0x045e, 0x0291, "Xbox 360 Wireless Receiver (XBOX)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
{ 0x045e, 0x02a9, "Xbox 360 Wireless Receiver (Unofficial)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
- { 0x045e, 0x02d1, "Microsoft X-Box One pad", 0, XTYPE_XBOXONE },
- { 0x045e, 0x02dd, "Microsoft X-Box One pad (Firmware 2015)", 0, XTYPE_XBOXONE },
- { 0x045e, 0x02e3, "Microsoft X-Box One Elite pad", MAP_PADDLES, XTYPE_XBOXONE },
- { 0x045e, 0x02ea, "Microsoft X-Box One S pad", 0, XTYPE_XBOXONE },
{ 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
- { 0x045e, 0x0b00, "Microsoft X-Box One Elite 2 pad", MAP_PADDLES, XTYPE_XBOXONE },
- { 0x045e, 0x0b0a, "Microsoft X-Box Adaptive Controller", MAP_PROFILE_BUTTON, XTYPE_XBOXONE },
- { 0x045e, 0x0b12, "Microsoft Xbox Series S|X Controller", MAP_SHARE_BUTTON | MAP_SHARE_OFFSET, XTYPE_XBOXONE },
{ 0x046d, 0xc21d, "Logitech Gamepad F310", 0, XTYPE_XBOX360 },
{ 0x046d, 0xc21e, "Logitech Gamepad F510", 0, XTYPE_XBOX360 },
{ 0x046d, 0xc21f, "Logitech Gamepad F710", 0, XTYPE_XBOX360 },
@@ -183,7 +165,6 @@ static const struct xpad_device {
{ 0x06a3, 0x0200, "Saitek Racing Wheel", 0, XTYPE_XBOX },
{ 0x06a3, 0x0201, "Saitek Adrenalin", 0, XTYPE_XBOX },
{ 0x06a3, 0xf51a, "Saitek P3600", 0, XTYPE_XBOX360 },
- { 0x0738, 0x4503, "Mad Catz Racing Wheel", 0, XTYPE_XBOXONE },
{ 0x0738, 0x4506, "Mad Catz 4506 Wireless Controller", 0, XTYPE_XBOX },
{ 0x0738, 0x4516, "Mad Catz Control Pad", 0, XTYPE_XBOX },
{ 0x0738, 0x4520, "Mad Catz Control Pad Pro", 0, XTYPE_XBOX },
@@ -205,7 +186,6 @@ static const struct xpad_device {
{ 0x0738, 0x4740, "Mad Catz Beat Pad", 0, XTYPE_XBOX360 },
{ 0x0738, 0x4743, "Mad Catz Beat Pad Pro", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
{ 0x0738, 0x4758, "Mad Catz Arcade Game Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
- { 0x0738, 0x4a01, "Mad Catz FightStick TE 2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE },
{ 0x0738, 0x6040, "Mad Catz Beat Pad Pro", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
{ 0x0738, 0x9871, "Mad Catz Portable Drum", 0, XTYPE_XBOX360 },
{ 0x0738, 0xb726, "Mad Catz Xbox controller - MW2", 0, XTYPE_XBOX360 },
@@ -216,8 +196,6 @@ static const struct xpad_device {
{ 0x0738, 0xcb29, "Saitek Aviator Stick AV8R02", 0, XTYPE_XBOX360 },
{ 0x0738, 0xf738, "Super SFIV FightStick TE S", 0, XTYPE_XBOX360 },
{ 0x07ff, 0xffff, "Mad Catz GamePad", 0, XTYPE_XBOX360 },
- { 0x0b05, 0x1a38, "ASUS ROG RAIKIRI", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
- { 0x0b05, 0x1abb, "ASUS ROG RAIKIRI PRO", 0, XTYPE_XBOXONE },
{ 0x0c12, 0x0005, "Intec wireless", 0, XTYPE_XBOX },
{ 0x0c12, 0x8801, "Nyko Xbox Controller", 0, XTYPE_XBOX },
{ 0x0c12, 0x8802, "Zeroplus Xbox Controller", 0, XTYPE_XBOX },
@@ -240,34 +218,10 @@ static const struct xpad_device {
{ 0x0e6f, 0x011f, "Rock Candy Gamepad Wired Controller", 0, XTYPE_XBOX360 },
{ 0x0e6f, 0x0131, "PDP EA Sports Controller", 0, XTYPE_XBOX360 },
{ 0x0e6f, 0x0133, "Xbox 360 Wired Controller", 0, XTYPE_XBOX360 },
- { 0x0e6f, 0x0139, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x013a, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x0146, "Rock Candy Wired Controller for Xbox One", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x0147, "PDP Marvel Xbox One Controller", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x015c, "PDP Xbox One Arcade Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE },
- { 0x0e6f, 0x015d, "PDP Mirror's Edge Official Wired Controller for Xbox One", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x0161, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x0162, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x0163, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x0164, "PDP Battlefield One", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x0165, "PDP Titanfall 2", 0, XTYPE_XBOXONE },
{ 0x0e6f, 0x0201, "Pelican PL-3601 'TSZ' Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
{ 0x0e6f, 0x0213, "Afterglow Gamepad for Xbox 360", 0, XTYPE_XBOX360 },
{ 0x0e6f, 0x021f, "Rock Candy Gamepad for Xbox 360", 0, XTYPE_XBOX360 },
- { 0x0e6f, 0x0246, "Rock Candy Gamepad for Xbox One 2015", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x02a0, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x02a1, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x02a2, "PDP Wired Controller for Xbox One - Crimson Red", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x02a4, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x02a6, "PDP Wired Controller for Xbox One - Camo Series", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x02a7, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x02a8, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x02ab, "PDP Controller for Xbox One", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x02ad, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x02b3, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE },
- { 0x0e6f, 0x02b8, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE },
{ 0x0e6f, 0x0301, "Logic3 Controller", 0, XTYPE_XBOX360 },
- { 0x0e6f, 0x0346, "Rock Candy Gamepad for Xbox One 2016", 0, XTYPE_XBOXONE },
{ 0x0e6f, 0x0401, "Logic3 Controller", 0, XTYPE_XBOX360 },
{ 0x0e6f, 0x0413, "Afterglow AX.1 Gamepad for Xbox 360", 0, XTYPE_XBOX360 },
{ 0x0e6f, 0x0501, "PDP Xbox 360 Controller", 0, XTYPE_XBOX360 },
@@ -279,23 +233,13 @@ static const struct xpad_device {
{ 0x0f0d, 0x000d, "Hori Fighting Stick EX2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
{ 0x0f0d, 0x0016, "Hori Real Arcade Pro.EX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
{ 0x0f0d, 0x001b, "Hori Real Arcade Pro VX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
- { 0x0f0d, 0x0063, "Hori Real Arcade Pro Hayabusa (USA) Xbox One", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE },
- { 0x0f0d, 0x0067, "HORIPAD ONE", 0, XTYPE_XBOXONE },
- { 0x0f0d, 0x0078, "Hori Real Arcade Pro V Kai Xbox One", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE },
- { 0x0f0d, 0x00c5, "Hori Fighting Commander ONE", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE },
{ 0x0f0d, 0x00dc, "HORIPAD FPS for Nintendo Switch", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
- { 0x0f0d, 0x0151, "Hori Racing Wheel Overdrive for Xbox Series X", 0, XTYPE_XBOXONE },
- { 0x0f0d, 0x0152, "Hori Racing Wheel Overdrive for Xbox Series X", 0, XTYPE_XBOXONE },
- { 0x0f0d, 0x01b2, "HORI Taiko No Tatsujin Drum Controller", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
{ 0x0f30, 0x010b, "Philips Recoil", 0, XTYPE_XBOX },
{ 0x0f30, 0x0202, "Joytech Advanced Controller", 0, XTYPE_XBOX },
{ 0x0f30, 0x8888, "BigBen XBMiniPad Controller", 0, XTYPE_XBOX },
{ 0x102c, 0xff0c, "Joytech Wireless Advanced Controller", 0, XTYPE_XBOX },
{ 0x1038, 0x1430, "SteelSeries Stratus Duo", 0, XTYPE_XBOX360 },
{ 0x1038, 0x1431, "SteelSeries Stratus Duo", 0, XTYPE_XBOX360 },
- { 0x10f5, 0x7005, "Turtle Beach Recon Controller", 0, XTYPE_XBOXONE },
- { 0x10f5, 0x7008, "Turtle Beach Recon Controller", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
- { 0x10f5, 0x7073, "Turtle Beach Stealth Ultra Controller", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
{ 0x11c9, 0x55f0, "Nacon GC-100XF", 0, XTYPE_XBOX360 },
{ 0x11ff, 0x0511, "PXN V900", 0, XTYPE_XBOX360 },
{ 0x1209, 0x2882, "Ardwiino Controller", 0, XTYPE_XBOX360 },
@@ -308,9 +252,6 @@ static const struct xpad_device {
{ 0x1430, 0xf801, "RedOctane Controller", 0, XTYPE_XBOX360 },
{ 0x146b, 0x0601, "BigBen Interactive XBOX 360 Controller", 0, XTYPE_XBOX360 },
{ 0x146b, 0x0604, "Bigben Interactive DAIJA Arcade Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
- { 0x1532, 0x0a00, "Razer Atrox Arcade Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE },
- { 0x1532, 0x0a03, "Razer Wildcat", 0, XTYPE_XBOXONE },
- { 0x1532, 0x0a29, "Razer Wolverine V2", 0, XTYPE_XBOXONE },
{ 0x15e4, 0x3f00, "Power A Mini Pro Elite", 0, XTYPE_XBOX360 },
{ 0x15e4, 0x3f0a, "Xbox Airflo wired controller", 0, XTYPE_XBOX360 },
{ 0x15e4, 0x3f10, "Batarang Xbox 360 controller", 0, XTYPE_XBOX360 },
@@ -358,12 +299,7 @@ static const struct xpad_device {
{ 0x1bad, 0xfd00, "Razer Onza TE", 0, XTYPE_XBOX360 },
{ 0x1bad, 0xfd01, "Razer Onza", 0, XTYPE_XBOX360 },
{ 0x1ee9, 0x1590, "ZOTAC Gaming Zone", 0, XTYPE_XBOX360 },
- { 0x20d6, 0x2001, "BDA Xbox Series X Wired Controller", 0, XTYPE_XBOXONE },
- { 0x20d6, 0x2009, "PowerA Enhanced Wired Controller for Xbox Series X|S", 0, XTYPE_XBOXONE },
- { 0x20d6, 0x2064, "PowerA Wired Controller for Xbox", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
{ 0x20d6, 0x281f, "PowerA Wired Controller For Xbox 360", 0, XTYPE_XBOX360 },
- { 0x20d6, 0x400b, "PowerA FUSION Pro 4 Wired Controller", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
- { 0x20d6, 0x890b, "PowerA MOGA XP-Ultra Controller", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
{ 0x2345, 0xe00b, "Machenike G5 Pro Controller", 0, XTYPE_XBOX360 },
{ 0x24c6, 0x5000, "Razer Atrox Arcade Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
{ 0x24c6, 0x5300, "PowerA MINI PROEX Controller", 0, XTYPE_XBOX360 },
@@ -371,9 +307,6 @@ static const struct xpad_device {
{ 0x24c6, 0x530a, "Xbox 360 Pro EX Controller", 0, XTYPE_XBOX360 },
{ 0x24c6, 0x531a, "PowerA Pro Ex", 0, XTYPE_XBOX360 },
{ 0x24c6, 0x5397, "FUS1ON Tournament Controller", 0, XTYPE_XBOX360 },
- { 0x24c6, 0x541a, "PowerA Xbox One Mini Wired Controller", 0, XTYPE_XBOXONE },
- { 0x24c6, 0x542a, "Xbox ONE spectra", 0, XTYPE_XBOXONE },
- { 0x24c6, 0x543a, "PowerA Xbox One wired controller", 0, XTYPE_XBOXONE },
{ 0x24c6, 0x5500, "Hori XBOX 360 EX 2 with Turbo", 0, XTYPE_XBOX360 },
{ 0x24c6, 0x5501, "Hori Real Arcade Pro VX-SA", 0, XTYPE_XBOX360 },
{ 0x24c6, 0x5502, "Hori Fighting Stick VX Alt", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
@@ -382,29 +315,18 @@ static const struct xpad_device {
{ 0x24c6, 0x550d, "Hori GEM Xbox controller", 0, XTYPE_XBOX360 },
{ 0x24c6, 0x550e, "Hori Real Arcade Pro V Kai 360", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
{ 0x24c6, 0x5510, "Hori Fighting Commander ONE (Xbox 360/PC Mode)", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
- { 0x24c6, 0x551a, "PowerA FUSION Pro Controller", 0, XTYPE_XBOXONE },
- { 0x24c6, 0x561a, "PowerA FUSION Controller", 0, XTYPE_XBOXONE },
- { 0x24c6, 0x581a, "ThrustMaster XB1 Classic Controller", 0, XTYPE_XBOXONE },
{ 0x24c6, 0x5b00, "ThrustMaster Ferrari 458 Racing Wheel", 0, XTYPE_XBOX360 },
{ 0x24c6, 0x5b02, "Thrustmaster, Inc. GPX Controller", 0, XTYPE_XBOX360 },
{ 0x24c6, 0x5b03, "Thrustmaster Ferrari 458 Racing Wheel", 0, XTYPE_XBOX360 },
{ 0x24c6, 0x5d04, "Razer Sabertooth", 0, XTYPE_XBOX360 },
{ 0x24c6, 0xfafe, "Rock Candy Gamepad for Xbox 360", 0, XTYPE_XBOX360 },
{ 0x2563, 0x058d, "OneXPlayer Gamepad", 0, XTYPE_XBOX360 },
- { 0x294b, 0x3303, "Snakebyte GAMEPAD BASE X", 0, XTYPE_XBOXONE },
- { 0x294b, 0x3404, "Snakebyte GAMEPAD RGB X", 0, XTYPE_XBOXONE },
{ 0x2993, 0x2001, "TECNO Pocket Go", 0, XTYPE_XBOX360 },
- { 0x2dc8, 0x2000, "8BitDo Pro 2 Wired Controller fox Xbox", 0, XTYPE_XBOXONE },
- { 0x2dc8, 0x200f, "8BitDo Ultimate 3-mode Controller for Xbox", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
{ 0x2dc8, 0x3106, "8BitDo Ultimate Wireless / Pro 2 Wired Controller", 0, XTYPE_XBOX360 },
{ 0x2dc8, 0x3109, "8BitDo Ultimate Wireless Bluetooth", 0, XTYPE_XBOX360 },
{ 0x2dc8, 0x310a, "8BitDo Ultimate 2C Wireless Controller", 0, XTYPE_XBOX360 },
{ 0x2dc8, 0x310b, "8BitDo Ultimate 2 Wireless Controller", 0, XTYPE_XBOX360 },
{ 0x2dc8, 0x6001, "8BitDo SN30 Pro", 0, XTYPE_XBOX360 },
- { 0x2e24, 0x0423, "Hyperkin DuchesS Xbox One pad", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
- { 0x2e24, 0x0652, "Hyperkin Duke X-Box One pad", 0, XTYPE_XBOXONE },
- { 0x2e24, 0x1688, "Hyperkin X91 X-Box One pad", 0, XTYPE_XBOXONE },
- { 0x2e95, 0x0504, "SCUF Gaming Controller", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
{ 0x31e3, 0x1100, "Wooting One", 0, XTYPE_XBOX360 },
{ 0x31e3, 0x1200, "Wooting Two", 0, XTYPE_XBOX360 },
{ 0x31e3, 0x1210, "Wooting Lekker", 0, XTYPE_XBOX360 },
@@ -412,15 +334,9 @@ static const struct xpad_device {
{ 0x31e3, 0x1230, "Wooting Two HE (ARM)", 0, XTYPE_XBOX360 },
{ 0x31e3, 0x1300, "Wooting 60HE (AVR)", 0, XTYPE_XBOX360 },
{ 0x31e3, 0x1310, "Wooting 60HE (ARM)", 0, XTYPE_XBOX360 },
- { 0x3285, 0x0603, "Nacon Pro Compact controller for Xbox", 0, XTYPE_XBOXONE },
{ 0x3285, 0x0607, "Nacon GC-100", 0, XTYPE_XBOX360 },
- { 0x3285, 0x0614, "Nacon Pro Compact", 0, XTYPE_XBOXONE },
- { 0x3285, 0x0646, "Nacon Pro Compact", 0, XTYPE_XBOXONE },
{ 0x3285, 0x0662, "Nacon Revolution5 Pro", 0, XTYPE_XBOX360 },
- { 0x3285, 0x0663, "Nacon Evol-X", 0, XTYPE_XBOXONE },
{ 0x3537, 0x1004, "GameSir T4 Kaleid", 0, XTYPE_XBOX360 },
- { 0x3537, 0x1010, "GameSir G7 SE", 0, XTYPE_XBOXONE },
- { 0x366c, 0x0005, "ByoWave Proteus Controller", MAP_SHARE_BUTTON, XTYPE_XBOXONE, FLAG_DELAY_INIT },
{ 0x3767, 0x0101, "Fanatec Speedster 3 Forceshock Wheel", 0, XTYPE_XBOX },
{ 0x413d, 0x2104, "Black Shark Green Ghost Gamepad", 0, XTYPE_XBOX360 },
{ 0xffff, 0xffff, "Chinese-made Xbox Controller", 0, XTYPE_XBOX },
@@ -477,13 +393,6 @@ static const signed short xpad_abs_triggers[] = {
-1
};
-/* used when the controller has extra paddle buttons */
-static const signed short xpad_btn_paddles[] = {
- BTN_GRIPR, BTN_GRIPR2, /* paddle upper right, lower right */
- BTN_GRIPL, BTN_GRIPL2, /* paddle upper left, lower left */
- -1 /* terminating entry */
-};
-
/*
* Xbox 360 has a vendor-specific class, so we cannot match it with only
* USB_INTERFACE_INFO (also specifically refused by USB subsystem), so we
@@ -500,47 +409,28 @@ static const signed short xpad_btn_paddles[] = {
{ XPAD_XBOX360_VENDOR_PROTOCOL((vend), 1) }, \
{ XPAD_XBOX360_VENDOR_PROTOCOL((vend), 129) }
-/* The Xbox One controller uses subclass 71 and protocol 208. */
-#define XPAD_XBOXONE_VENDOR_PROTOCOL(vend, pr) \
- .match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_INT_INFO, \
- .idVendor = (vend), \
- .bInterfaceClass = USB_CLASS_VENDOR_SPEC, \
- .bInterfaceSubClass = 71, \
- .bInterfaceProtocol = (pr)
-#define XPAD_XBOXONE_VENDOR(vend) \
- { XPAD_XBOXONE_VENDOR_PROTOCOL((vend), 208) }
-
static const struct usb_device_id xpad_table[] = {
/*
- * Please keep this list sorted by vendor ID. Note that there are 2
- * macros - XPAD_XBOX360_VENDOR and XPAD_XBOXONE_VENDOR.
+ * Please keep this list sorted by vendor ID
*/
{ USB_INTERFACE_INFO('X', 'B', 0) }, /* Xbox USB-IF not-approved class */
XPAD_XBOX360_VENDOR(0x0079), /* GPD Win 2 controller */
XPAD_XBOX360_VENDOR(0x03eb), /* Wooting Keyboards (Legacy) */
XPAD_XBOX360_VENDOR(0x03f0), /* HP HyperX Xbox 360 controllers */
- XPAD_XBOXONE_VENDOR(0x03f0), /* HP HyperX Xbox One controllers */
XPAD_XBOX360_VENDOR(0x044f), /* Thrustmaster Xbox 360 controllers */
- XPAD_XBOXONE_VENDOR(0x044f), /* Thrustmaster Xbox One controllers */
XPAD_XBOX360_VENDOR(0x045e), /* Microsoft Xbox 360 controllers */
- XPAD_XBOXONE_VENDOR(0x045e), /* Microsoft Xbox One controllers */
XPAD_XBOX360_VENDOR(0x046d), /* Logitech Xbox 360-style controllers */
XPAD_XBOX360_VENDOR(0x0502), /* Acer Inc. Xbox 360 style controllers */
XPAD_XBOX360_VENDOR(0x056e), /* Elecom JC-U3613M */
XPAD_XBOX360_VENDOR(0x06a3), /* Saitek P3600 */
XPAD_XBOX360_VENDOR(0x0738), /* Mad Catz Xbox 360 controllers */
{ USB_DEVICE(0x0738, 0x4540) }, /* Mad Catz Beat Pad */
- XPAD_XBOXONE_VENDOR(0x0738), /* Mad Catz FightStick TE 2 */
XPAD_XBOX360_VENDOR(0x07ff), /* Mad Catz Gamepad */
- XPAD_XBOXONE_VENDOR(0x0b05), /* ASUS controllers */
XPAD_XBOX360_VENDOR(0x0c12), /* Zeroplus X-Box 360 controllers */
XPAD_XBOX360_VENDOR(0x0db0), /* Micro Star International X-Box 360 controllers */
XPAD_XBOX360_VENDOR(0x0e6f), /* 0x0e6f Xbox 360 controllers */
- XPAD_XBOXONE_VENDOR(0x0e6f), /* 0x0e6f Xbox One controllers */
XPAD_XBOX360_VENDOR(0x0f0d), /* Hori controllers */
- XPAD_XBOXONE_VENDOR(0x0f0d), /* Hori controllers */
XPAD_XBOX360_VENDOR(0x1038), /* SteelSeries controllers */
- XPAD_XBOXONE_VENDOR(0x10f5), /* Turtle Beach Controllers */
XPAD_XBOX360_VENDOR(0x11c9), /* Nacon GC100XF */
XPAD_XBOX360_VENDOR(0x11ff), /* PXN V900 */
XPAD_XBOX360_VENDOR(0x1209), /* Ardwiino Controllers */
@@ -548,7 +438,6 @@ static const struct usb_device_id xpad_table[] = {
XPAD_XBOX360_VENDOR(0x1430), /* RedOctane Xbox 360 controllers */
XPAD_XBOX360_VENDOR(0x146b), /* Bigben Interactive controllers */
XPAD_XBOX360_VENDOR(0x1532), /* Razer Sabertooth */
- XPAD_XBOXONE_VENDOR(0x1532), /* Razer Wildcat */
XPAD_XBOX360_VENDOR(0x15e4), /* Numark Xbox 360 controllers */
XPAD_XBOX360_VENDOR(0x162e), /* Joytech Xbox 360 controllers */
XPAD_XBOX360_VENDOR(0x1689), /* Razer Onza */
@@ -558,188 +447,23 @@ static const struct usb_device_id xpad_table[] = {
XPAD_XBOX360_VENDOR(0x1bad), /* Harmonix Rock Band guitar and drums */
XPAD_XBOX360_VENDOR(0x1ee9), /* ZOTAC Technology Limited */
XPAD_XBOX360_VENDOR(0x20d6), /* PowerA controllers */
- XPAD_XBOXONE_VENDOR(0x20d6), /* PowerA controllers */
XPAD_XBOX360_VENDOR(0x2345), /* Machenike Controllers */
XPAD_XBOX360_VENDOR(0x24c6), /* PowerA controllers */
- XPAD_XBOXONE_VENDOR(0x24c6), /* PowerA controllers */
XPAD_XBOX360_VENDOR(0x2563), /* OneXPlayer Gamepad */
XPAD_XBOX360_VENDOR(0x260d), /* Dareu H101 */
- XPAD_XBOXONE_VENDOR(0x294b), /* Snakebyte */
XPAD_XBOX360_VENDOR(0x2993), /* TECNO Mobile */
XPAD_XBOX360_VENDOR(0x2c22), /* Qanba Controllers */
XPAD_XBOX360_VENDOR(0x2dc8), /* 8BitDo Controllers */
- XPAD_XBOXONE_VENDOR(0x2dc8), /* 8BitDo Controllers */
- XPAD_XBOXONE_VENDOR(0x2e24), /* Hyperkin Controllers */
XPAD_XBOX360_VENDOR(0x2f24), /* GameSir Controllers */
- XPAD_XBOXONE_VENDOR(0x2e95), /* SCUF Gaming Controller */
XPAD_XBOX360_VENDOR(0x31e3), /* Wooting Keyboards */
XPAD_XBOX360_VENDOR(0x3285), /* Nacon GC-100 */
- XPAD_XBOXONE_VENDOR(0x3285), /* Nacon Evol-X */
XPAD_XBOX360_VENDOR(0x3537), /* GameSir Controllers */
- XPAD_XBOXONE_VENDOR(0x3537), /* GameSir Controllers */
- XPAD_XBOXONE_VENDOR(0x366c), /* ByoWave controllers */
XPAD_XBOX360_VENDOR(0x413d), /* Black Shark Green Ghost Controller */
{ }
};
MODULE_DEVICE_TABLE(usb, xpad_table);
-struct xboxone_init_packet {
- u16 idVendor;
- u16 idProduct;
- const u8 *data;
- u8 len;
-};
-
-#define XBOXONE_INIT_PKT(_vid, _pid, _data) \
- { \
- .idVendor = (_vid), \
- .idProduct = (_pid), \
- .data = (_data), \
- .len = ARRAY_SIZE(_data), \
- }
-
-/*
- * starting with xbox one, the game input protocol is used
- * magic numbers are taken from
- * - https://github.com/xpadneo/gip-dissector/blob/main/src/gip-dissector.lua
- * - https://github.com/medusalix/xone/blob/master/bus/protocol.c
- */
-#define GIP_CMD_ACK 0x01
-#define GIP_CMD_ANNOUNCE 0x02
-#define GIP_CMD_IDENTIFY 0x04
-#define GIP_CMD_POWER 0x05
-#define GIP_CMD_AUTHENTICATE 0x06
-#define GIP_CMD_VIRTUAL_KEY 0x07
-#define GIP_CMD_RUMBLE 0x09
-#define GIP_CMD_LED 0x0a
-#define GIP_CMD_FIRMWARE 0x0c
-#define GIP_CMD_INPUT 0x20
-
-#define GIP_SEQ0 0x00
-
-#define GIP_OPT_ACK 0x10
-#define GIP_OPT_INTERNAL 0x20
-
-/*
- * length of the command payload encoded with
- * https://en.wikipedia.org/wiki/LEB128
- * which is a no-op for N < 128
- */
-#define GIP_PL_LEN(N) (N)
-
-/*
- * payload specific defines
- */
-#define GIP_PWR_ON 0x00
-#define GIP_LED_ON 0x01
-
-#define GIP_MOTOR_R BIT(0)
-#define GIP_MOTOR_L BIT(1)
-#define GIP_MOTOR_RT BIT(2)
-#define GIP_MOTOR_LT BIT(3)
-#define GIP_MOTOR_ALL (GIP_MOTOR_R | GIP_MOTOR_L | GIP_MOTOR_RT | GIP_MOTOR_LT)
-
-#define GIP_WIRED_INTF_DATA 0
-#define GIP_WIRED_INTF_AUDIO 1
-
-/*
- * This packet is required for all Xbox One pads with 2015
- * or later firmware installed (or present from the factory).
- */
-static const u8 xboxone_power_on[] = {
- GIP_CMD_POWER, GIP_OPT_INTERNAL, GIP_SEQ0, GIP_PL_LEN(1), GIP_PWR_ON
-};
-
-/*
- * This packet is required for Xbox One S (0x045e:0x02ea)
- * and Xbox One Elite Series 2 (0x045e:0x0b00) pads to
- * initialize the controller that was previously used in
- * Bluetooth mode.
- */
-static const u8 xboxone_s_init[] = {
- GIP_CMD_POWER, GIP_OPT_INTERNAL, GIP_SEQ0, 0x0f, 0x06
-};
-
-/*
- * This packet is required to get additional input data
- * from Xbox One Elite Series 2 (0x045e:0x0b00) pads.
- * We mostly do this right now to get paddle data
- */
-static const u8 extra_input_packet_init[] = {
- 0x4d, 0x10, 0x01, 0x02, 0x07, 0x00
-};
-
-/*
- * This packet is required for the Titanfall 2 Xbox One pads
- * (0x0e6f:0x0165) to finish initialization and for Hori pads
- * (0x0f0d:0x0067) to make the analog sticks work.
- */
-static const u8 xboxone_hori_ack_id[] = {
- GIP_CMD_ACK, GIP_OPT_INTERNAL, GIP_SEQ0, GIP_PL_LEN(9),
- 0x00, GIP_CMD_IDENTIFY, GIP_OPT_INTERNAL, 0x3a, 0x00, 0x00, 0x00, 0x80, 0x00
-};
-
-/*
- * This packet is sent by default on Windows, and is required for some pads to
- * start sending input reports, including most (all?) of the PDP. These pads
- * include: (0x0e6f:0x02ab), (0x0e6f:0x02a4), (0x0e6f:0x02a6).
- */
-static const u8 xboxone_led_on[] = { GIP_CMD_LED, GIP_OPT_INTERNAL, GIP_SEQ0,
-GIP_PL_LEN(3), 0x00, GIP_LED_ON, 0x14 };
-
-/*
- * This packet is required for most (all?) of the PDP pads to start
- * sending input reports. These pads include: (0x0e6f:0x02ab),
- * (0x0e6f:0x02a4), (0x0e6f:0x02a6).
- */
-static const u8 xboxone_auth_done[] = {
- GIP_CMD_AUTHENTICATE, GIP_OPT_INTERNAL, GIP_SEQ0, GIP_PL_LEN(2), 0x01, 0x00
-};
-
-/*
- * A specific rumble packet is required for some PowerA pads to start
- * sending input reports. One of those pads is (0x24c6:0x543a).
- */
-static const u8 xboxone_rumblebegin_init[] = {
- GIP_CMD_RUMBLE, 0x00, GIP_SEQ0, GIP_PL_LEN(9),
- 0x00, GIP_MOTOR_ALL, 0x00, 0x00, 0x1D, 0x1D, 0xFF, 0x00, 0x00
-};
-
-/*
- * A rumble packet with zero FF intensity will immediately
- * terminate the rumbling required to init PowerA pads.
- * This should happen fast enough that the motors don't
- * spin up to enough speed to actually vibrate the gamepad.
- */
-static const u8 xboxone_rumbleend_init[] = {
- GIP_CMD_RUMBLE, 0x00, GIP_SEQ0, GIP_PL_LEN(9),
- 0x00, GIP_MOTOR_ALL, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-/*
- * This specifies the selection of init packets that a gamepad
- * will be sent on init *and* the order in which they will be
- * sent. The correct sequence number will be added when the
- * packet is going to be sent.
- */
-static const struct xboxone_init_packet xboxone_init_packets[] = {
- XBOXONE_INIT_PKT(0x0e6f, 0x0165, xboxone_hori_ack_id),
- XBOXONE_INIT_PKT(0x0f0d, 0x0067, xboxone_hori_ack_id),
- XBOXONE_INIT_PKT(0x0000, 0x0000, xboxone_power_on),
- XBOXONE_INIT_PKT(0x045e, 0x02ea, xboxone_s_init),
- XBOXONE_INIT_PKT(0x045e, 0x0b00, xboxone_s_init),
- XBOXONE_INIT_PKT(0x045e, 0x0b00, extra_input_packet_init),
- XBOXONE_INIT_PKT(0x0000, 0x0000, xboxone_led_on),
- XBOXONE_INIT_PKT(0x0000, 0x0000, xboxone_auth_done),
- XBOXONE_INIT_PKT(0x24c6, 0x541a, xboxone_rumblebegin_init),
- XBOXONE_INIT_PKT(0x24c6, 0x542a, xboxone_rumblebegin_init),
- XBOXONE_INIT_PKT(0x24c6, 0x543a, xboxone_rumblebegin_init),
- XBOXONE_INIT_PKT(0x24c6, 0x541a, xboxone_rumbleend_init),
- XBOXONE_INIT_PKT(0x24c6, 0x542a, xboxone_rumbleend_init),
- XBOXONE_INIT_PKT(0x24c6, 0x543a, xboxone_rumbleend_init),
-};
-
struct xpad_output_packet {
u8 data[XPAD_PKT_LEN];
u8 len;
@@ -769,7 +493,6 @@ struct usb_xpad {
struct urb *irq_out; /* urb for interrupt out report */
struct usb_anchor irq_out_anchor;
bool irq_out_active; /* we must not use an active URB */
- u8 odata_serial; /* serial number for xbox one protocol */
unsigned char *odata; /* output data */
dma_addr_t odata_dma;
spinlock_t odata_lock;
@@ -797,8 +520,6 @@ struct usb_xpad {
static int xpad_init_input(struct usb_xpad *xpad);
static void xpad_deinit_input(struct usb_xpad *xpad);
-static int xpad_start_input(struct usb_xpad *xpad);
-static void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 seq_num);
static void xpad360w_poweroff_controller(struct usb_xpad *xpad);
/*
@@ -1036,187 +757,6 @@ static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned cha
rcu_read_unlock();
}
-/*
- * xpadone_process_packet
- *
- * Completes a request by converting the data into events for the
- * input subsystem. This version is for the Xbox One controller.
- *
- * The report format was gleaned from
- * https://github.com/kylelemons/xbox/blob/master/xbox.go
- */
-static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data, u32 len)
-{
- struct input_dev *dev = xpad->dev;
- bool do_sync = false;
-
- /* the xbox button has its own special report */
- if (data[0] == GIP_CMD_VIRTUAL_KEY) {
- /*
- * The Xbox One S controller requires these reports to be
- * acked otherwise it continues sending them forever and
- * won't report further mode button events.
- */
- if (data[1] == (GIP_OPT_ACK | GIP_OPT_INTERNAL))
- xpadone_ack_mode_report(xpad, data[2]);
-
- input_report_key(dev, BTN_MODE, data[4] & GENMASK(1, 0));
- input_sync(dev);
-
- do_sync = true;
- } else if (data[0] == GIP_CMD_FIRMWARE) {
- /* Some packet formats force us to use this separate to poll paddle inputs */
- if (xpad->packet_type == PKT_XBE2_FW_5_11) {
- /* Mute paddles if controller is in a custom profile slot
- * Checked by looking at the active profile slot to
- * verify it's the default slot
- */
- if (data[19] != 0)
- data[18] = 0;
-
- /* Elite Series 2 split packet paddle bits */
- input_report_key(dev, BTN_GRIPR, data[18] & BIT(0));
- input_report_key(dev, BTN_GRIPR2, data[18] & BIT(1));
- input_report_key(dev, BTN_GRIPL, data[18] & BIT(2));
- input_report_key(dev, BTN_GRIPL2, data[18] & BIT(3));
-
- do_sync = true;
- }
- } else if (data[0] == GIP_CMD_ANNOUNCE) {
- int error;
-
- if (xpad->delay_init && !xpad->delayed_init_done) {
- xpad->delayed_init_done = true;
- error = xpad_start_input(xpad);
- if (error)
- dev_warn(&xpad->dev->dev,
- "unable to start delayed input: %d\n",
- error);
- }
- } else if (data[0] == GIP_CMD_INPUT) { /* The main valid packet type for inputs */
- /* menu/view buttons */
- input_report_key(dev, BTN_START, data[4] & BIT(2));
- input_report_key(dev, BTN_SELECT, data[4] & BIT(3));
- if (xpad->mapping & MAP_SHARE_BUTTON) {
- if (xpad->mapping & MAP_SHARE_OFFSET)
- input_report_key(dev, KEY_RECORD, data[len - 26] & BIT(0));
- else
- input_report_key(dev, KEY_RECORD, data[len - 18] & BIT(0));
- }
-
- /* buttons A,B,X,Y */
- input_report_key(dev, BTN_A, data[4] & BIT(4));
- input_report_key(dev, BTN_B, data[4] & BIT(5));
- input_report_key(dev, BTN_X, data[4] & BIT(6));
- input_report_key(dev, BTN_Y, data[4] & BIT(7));
-
- /* digital pad */
- if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
- /* dpad as buttons (left, right, up, down) */
- input_report_key(dev, BTN_DPAD_LEFT, data[5] & BIT(2));
- input_report_key(dev, BTN_DPAD_RIGHT, data[5] & BIT(3));
- input_report_key(dev, BTN_DPAD_UP, data[5] & BIT(0));
- input_report_key(dev, BTN_DPAD_DOWN, data[5] & BIT(1));
- } else {
- input_report_abs(dev, ABS_HAT0X,
- !!(data[5] & 0x08) - !!(data[5] & 0x04));
- input_report_abs(dev, ABS_HAT0Y,
- !!(data[5] & 0x02) - !!(data[5] & 0x01));
- }
-
- /* TL/TR */
- input_report_key(dev, BTN_TL, data[5] & BIT(4));
- input_report_key(dev, BTN_TR, data[5] & BIT(5));
-
- /* stick press left/right */
- input_report_key(dev, BTN_THUMBL, data[5] & BIT(6));
- input_report_key(dev, BTN_THUMBR, data[5] & BIT(7));
-
- if (!(xpad->mapping & MAP_STICKS_TO_NULL)) {
- /* left stick */
- input_report_abs(dev, ABS_X,
- (__s16) le16_to_cpup((__le16 *)(data + 10)));
- input_report_abs(dev, ABS_Y,
- ~(__s16) le16_to_cpup((__le16 *)(data + 12)));
-
- /* right stick */
- input_report_abs(dev, ABS_RX,
- (__s16) le16_to_cpup((__le16 *)(data + 14)));
- input_report_abs(dev, ABS_RY,
- ~(__s16) le16_to_cpup((__le16 *)(data + 16)));
- }
-
- /* triggers left/right */
- if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
- input_report_key(dev, BTN_TL2,
- (__u16) le16_to_cpup((__le16 *)(data + 6)));
- input_report_key(dev, BTN_TR2,
- (__u16) le16_to_cpup((__le16 *)(data + 8)));
- } else {
- input_report_abs(dev, ABS_Z,
- (__u16) le16_to_cpup((__le16 *)(data + 6)));
- input_report_abs(dev, ABS_RZ,
- (__u16) le16_to_cpup((__le16 *)(data + 8)));
- }
-
- /* Profile button has a value of 0-3, so it is reported as an axis */
- if (xpad->mapping & MAP_PROFILE_BUTTON)
- input_report_abs(dev, ABS_PROFILE, data[34]);
-
- /* paddle handling */
- /* based on SDL's SDL_hidapi_xboxone.c */
- if (xpad->mapping & MAP_PADDLES) {
- if (xpad->packet_type == PKT_XBE1) {
- /* Mute paddles if controller has a custom mapping applied.
- * Checked by comparing the current mapping
- * config against the factory mapping config
- */
- if (memcmp(&data[4], &data[18], 2) != 0)
- data[32] = 0;
-
- /* OG Elite Series Controller paddle bits */
- input_report_key(dev, BTN_GRIPR, data[32] & BIT(1));
- input_report_key(dev, BTN_GRIPR2, data[32] & BIT(3));
- input_report_key(dev, BTN_GRIPL, data[32] & BIT(0));
- input_report_key(dev, BTN_GRIPL2, data[32] & BIT(2));
- } else if (xpad->packet_type == PKT_XBE2_FW_OLD) {
- /* Mute paddles if controller has a custom mapping applied.
- * Checked by comparing the current mapping
- * config against the factory mapping config
- */
- if (data[19] != 0)
- data[18] = 0;
-
- /* Elite Series 2 4.x firmware paddle bits */
- input_report_key(dev, BTN_GRIPR, data[18] & BIT(0));
- input_report_key(dev, BTN_GRIPR2, data[18] & BIT(1));
- input_report_key(dev, BTN_GRIPL, data[18] & BIT(2));
- input_report_key(dev, BTN_GRIPL2, data[18] & BIT(3));
- } else if (xpad->packet_type == PKT_XBE2_FW_5_EARLY) {
- /* Mute paddles if controller has a custom mapping applied.
- * Checked by comparing the current mapping
- * config against the factory mapping config
- */
- if (data[23] != 0)
- data[22] = 0;
-
- /* Elite Series 2 5.x firmware paddle bits
- * (before the packet was split)
- */
- input_report_key(dev, BTN_GRIPR, data[22] & BIT(0));
- input_report_key(dev, BTN_GRIPR2, data[22] & BIT(1));
- input_report_key(dev, BTN_GRIPL, data[22] & BIT(2));
- input_report_key(dev, BTN_GRIPL2, data[22] & BIT(3));
- }
- }
-
- do_sync = true;
- }
-
- if (do_sync)
- input_sync(dev);
-}
-
static void xpad_irq_in(struct urb *urb)
{
struct usb_xpad *xpad = urb->context;
@@ -1249,9 +789,6 @@ static void xpad_irq_in(struct urb *urb)
case XTYPE_XBOX360W:
xpad360w_process_packet(xpad, 0, xpad->idata);
break;
- case XTYPE_XBOXONE:
- xpadone_process_packet(xpad, 0, xpad->idata, urb->actual_length);
- break;
default:
xpad_process_packet(xpad, 0, xpad->idata);
}
@@ -1263,56 +800,12 @@ static void xpad_irq_in(struct urb *urb)
__func__, retval);
}
-/* Callers must hold xpad->odata_lock spinlock */
-static bool xpad_prepare_next_init_packet(struct usb_xpad *xpad)
-{
- const struct xboxone_init_packet *init_packet;
-
- if (xpad->xtype != XTYPE_XBOXONE)
- return false;
-
- /*
- * Some dongles will discard init packets if they're sent before the
- * controller connects. In these cases, we need to wait until we get
- * an announce packet from them to send the init packet sequence.
- */
- if (xpad->delay_init && !xpad->delayed_init_done)
- return false;
-
- /* Perform initialization sequence for Xbox One pads that require it */
- while (xpad->init_seq < ARRAY_SIZE(xboxone_init_packets)) {
- init_packet = &xboxone_init_packets[xpad->init_seq++];
-
- if (init_packet->idVendor != 0 &&
- init_packet->idVendor != xpad->dev->id.vendor)
- continue;
-
- if (init_packet->idProduct != 0 &&
- init_packet->idProduct != xpad->dev->id.product)
- continue;
-
- /* This packet applies to our device, so prepare to send it */
- memcpy(xpad->odata, init_packet->data, init_packet->len);
- xpad->irq_out->transfer_buffer_length = init_packet->len;
-
- /* Update packet with current sequence number */
- xpad->odata[2] = xpad->odata_serial++;
- return true;
- }
-
- return false;
-}
-
/* Callers must hold xpad->odata_lock spinlock */
static bool xpad_prepare_next_out_packet(struct usb_xpad *xpad)
{
struct xpad_output_packet *pkt, *packet = NULL;
int i;
- /* We may have init packets to send before we can send user commands */
- if (xpad_prepare_next_init_packet(xpad))
- return true;
-
for (i = 0; i < XPAD_NUM_OUT_PACKETS; i++) {
if (++xpad->last_out_packet >= XPAD_NUM_OUT_PACKETS)
xpad->last_out_packet = 0;
@@ -1488,57 +981,6 @@ static int xpad_inquiry_pad_presence(struct usb_xpad *xpad)
return xpad_try_sending_next_out_packet(xpad);
}
-static int xpad_start_xbox_one(struct usb_xpad *xpad)
-{
- int error;
-
- if (usb_ifnum_to_if(xpad->udev, GIP_WIRED_INTF_AUDIO)) {
- /*
- * Explicitly disable the audio interface. This is needed
- * for some controllers, such as the PowerA Enhanced Wired
- * Controller for Series X|S (0x20d6:0x200e) to report the
- * guide button.
- */
- error = usb_set_interface(xpad->udev,
- GIP_WIRED_INTF_AUDIO, 0);
- if (error)
- dev_warn(&xpad->dev->dev,
- "unable to disable audio interface: %d\n",
- error);
- }
-
- guard(spinlock_irqsave)(&xpad->odata_lock);
-
- /*
- * Begin the init sequence by attempting to send a packet.
- * We will cycle through the init packet sequence before
- * sending any packets from the output ring.
- */
- xpad->init_seq = 0;
- return xpad_try_sending_next_out_packet(xpad);
-}
-
-static void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 seq_num)
-{
- struct xpad_output_packet *packet =
- &xpad->out_packets[XPAD_OUT_CMD_IDX];
- static const u8 mode_report_ack[] = {
- GIP_CMD_ACK, GIP_OPT_INTERNAL, GIP_SEQ0, GIP_PL_LEN(9),
- 0x00, GIP_CMD_VIRTUAL_KEY, GIP_OPT_INTERNAL, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00
- };
-
- guard(spinlock_irqsave)(&xpad->odata_lock);
-
- packet->len = sizeof(mode_report_ack);
- memcpy(packet->data, mode_report_ack, packet->len);
- packet->data[2] = seq_num;
- packet->pending = true;
-
- /* Reset the sequence so we send out the ack now */
- xpad->last_out_packet = -1;
- xpad_try_sending_next_out_packet(xpad);
-}
-
#ifdef CONFIG_JOYSTICK_XPAD_FF
static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect)
{
@@ -1597,24 +1039,6 @@ static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect
packet->pending = true;
break;
- case XTYPE_XBOXONE:
- packet->data[0] = GIP_CMD_RUMBLE; /* activate rumble */
- packet->data[1] = 0x00;
- packet->data[2] = xpad->odata_serial++;
- packet->data[3] = GIP_PL_LEN(9);
- packet->data[4] = 0x00;
- packet->data[5] = GIP_MOTOR_ALL;
- packet->data[6] = 0x00; /* left trigger */
- packet->data[7] = 0x00; /* right trigger */
- packet->data[8] = strong / 512; /* left actuator */
- packet->data[9] = weak / 512; /* right actuator */
- packet->data[10] = 0xFF; /* on period */
- packet->data[11] = 0x00; /* off period */
- packet->data[12] = 0xFF; /* repeat count */
- packet->len = 13;
- packet->pending = true;
- break;
-
default:
dev_dbg(&xpad->dev->dev,
"%s - rumble command sent to unsupported xpad type: %d\n",
@@ -1793,13 +1217,6 @@ static int xpad_start_input(struct usb_xpad *xpad)
if (usb_submit_urb(xpad->irq_in, GFP_KERNEL))
return -EIO;
- if (xpad->xtype == XTYPE_XBOXONE) {
- error = xpad_start_xbox_one(xpad);
- if (error) {
- usb_kill_urb(xpad->irq_in);
- return error;
- }
- }
if (xpad->xtype == XTYPE_XBOX360) {
/*
* Some third-party controllers Xbox 360-style controllers
@@ -1905,8 +1322,6 @@ static void xpad_close(struct input_dev *dev)
static void xpad_set_up_abs(struct input_dev *input_dev, signed short abs)
{
- struct usb_xpad *xpad = input_get_drvdata(input_dev);
-
switch (abs) {
case ABS_X:
case ABS_Y:
@@ -1916,18 +1331,12 @@ static void xpad_set_up_abs(struct input_dev *input_dev, signed short abs)
break;
case ABS_Z:
case ABS_RZ: /* the triggers (if mapped to axes) */
- if (xpad->xtype == XTYPE_XBOXONE)
- input_set_abs_params(input_dev, abs, 0, 1023, 0, 0);
- else
- input_set_abs_params(input_dev, abs, 0, 255, 0, 0);
+ input_set_abs_params(input_dev, abs, 0, 255, 0, 0);
break;
case ABS_HAT0X:
case ABS_HAT0Y: /* the d-pad (only if dpad is mapped to axes */
input_set_abs_params(input_dev, abs, -1, 1, 0, 0);
break;
- case ABS_PROFILE: /* 4 value profile button (such as on XAC) */
- input_set_abs_params(input_dev, abs, 0, 4, 0, 0);
- break;
default:
input_set_abs_params(input_dev, abs, 0, 0, 0, 0);
break;
@@ -1982,12 +1391,9 @@ static int xpad_init_input(struct usb_xpad *xpad)
input_set_capability(input_dev, EV_KEY, xpad_common_btn[i]);
/* set up model-specific ones */
- if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX360W ||
- xpad->xtype == XTYPE_XBOXONE) {
+ if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX360W) {
for (i = 0; xpad360_btn[i] >= 0; i++)
input_set_capability(input_dev, EV_KEY, xpad360_btn[i]);
- if (xpad->mapping & MAP_SHARE_BUTTON)
- input_set_capability(input_dev, EV_KEY, KEY_RECORD);
} else {
for (i = 0; xpad_btn[i] >= 0; i++)
input_set_capability(input_dev, EV_KEY, xpad_btn[i]);
@@ -1999,12 +1405,6 @@ static int xpad_init_input(struct usb_xpad *xpad)
xpad_btn_pad[i]);
}
- /* set up paddles if the controller has them */
- if (xpad->mapping & MAP_PADDLES) {
- for (i = 0; xpad_btn_paddles[i] >= 0; i++)
- input_set_capability(input_dev, EV_KEY, xpad_btn_paddles[i]);
- }
-
/*
* This should be a simple else block. However historically
* xbox360w has mapped DPAD to buttons while xbox360 did not. This
@@ -2026,10 +1426,6 @@ static int xpad_init_input(struct usb_xpad *xpad)
xpad_set_up_abs(input_dev, xpad_abs_triggers[i]);
}
- /* setup profile button as an axis with 4 possible values */
- if (xpad->mapping & MAP_PROFILE_BUTTON)
- xpad_set_up_abs(input_dev, ABS_PROFILE);
-
error = xpad_init_ff(xpad);
if (error)
goto err_free_input;
@@ -2105,8 +1501,6 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) {
if (intf->cur_altsetting->desc.bInterfaceProtocol == 129)
xpad->xtype = XTYPE_XBOX360W;
- else if (intf->cur_altsetting->desc.bInterfaceProtocol == 208)
- xpad->xtype = XTYPE_XBOXONE;
else
xpad->xtype = XTYPE_XBOX360;
} else {
@@ -2121,17 +1515,6 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
xpad->mapping |= MAP_STICKS_TO_NULL;
}
- if (xpad->xtype == XTYPE_XBOXONE &&
- intf->cur_altsetting->desc.bInterfaceNumber != GIP_WIRED_INTF_DATA) {
- /*
- * The Xbox One controller lists three interfaces all with the
- * same interface class, subclass and protocol. Differentiate by
- * interface number.
- */
- error = -ENODEV;
- goto err_free_in_urb;
- }
-
ep_irq_in = ep_irq_out = NULL;
for (i = 0; i < 2; i++) {
@@ -2306,15 +1689,6 @@ static int xpad_resume(struct usb_interface *intf)
if (input_device_enabled(input))
return xpad_start_input(xpad);
- if (xpad->xtype == XTYPE_XBOXONE) {
- /*
- * Even if there are no users, we'll send Xbox One pads
- * the startup sequence so they don't sit there and
- * blink until somebody opens the input device again.
- */
- return xpad_start_xbox_one(xpad);
- }
-
return 0;
}
--
2.51.0
^ permalink raw reply related
* [PATCH v2 0/5] Input: xbox_gip - Add new driver for Xbox GIP
From: Vicki Pfau @ 2025-09-17 1:19 UTC (permalink / raw)
To: Dmitry Torokhov, linux-input; +Cc: Vicki Pfau
This introduces a new driver for the Xbox One/Series controller protocol,
officially known as the Gaming Input Protocol, or GIP for short.
Microsoft released documentation on (some of) GIP in late 2024, upon which
this driver is based. Though the documentation was incomplete, it still
provided enough information to warrant a clean start over the previous,
incomplete implementation.
This driver is already at feature parity with the GIP support in xpad,
along with several more enhancements:
- Proper support for parsing message length and fragmented messages
- Metadata parsing, allowing for auto-detection on various parameters,
including the presence and location in the message of the share button,
as well as detection of specific device types
- Controllable LED support
- HID passthrough for the Chatpad
- Preliminary support for racing wheels
The framework set out in this driver also allows future expansion for
specialized device types and additional features more cleanly than xpad.
Future plans include:
- Flight stick support
- Improved support for racing wheels, including force feedback support
- Support for the security handshake, which is required for devices that use
wireless dongles
- Exposing a raw character device to enable sending vendor-specific commands
from userspace
- Event logging to either sysfs or dmesg
- Support for the headphone jack
- Splitting the driver into separate drivers treating gip as a bus with each
attachment being able to have its own gip_driver defined by a preferred type
and/or GUID
Also included in this series is the addition of three new ABS input types, with
the two relevant ones to HID added to the mappings
v2 of this series is mostly the same as v1 rebased onto dtor/master so it
actually applies cleanly, with one major difference: flight stick support has
been omitted, as I was unhappy with how mapping worked and want to discuss it
further before having a patch readied.
Vicki Pfau (5):
Input: xbox_gip - Add new driver for Xbox GIP
Input: xpad - Remove Xbox One support
Input: Add ABS_CLUTCH, HANDBRAKE, and SHIFTER
HID: Map more automobile simulation inputs
Input: xbox_gip - Add wheel support
Documentation/input/devices/xpad.rst | 17 +-
MAINTAINERS | 6 +
drivers/hid/hid-debug.c | 16 +-
drivers/hid/hid-input.c | 2 +
drivers/input/joystick/Kconfig | 26 +
drivers/input/joystick/Makefile | 1 +
drivers/input/joystick/xbox_gip.c | 3314 ++++++++++++++++++++++++
drivers/input/joystick/xpad.c | 634 +----
include/uapi/linux/input-event-codes.h | 3 +
9 files changed, 3372 insertions(+), 647 deletions(-)
create mode 100644 drivers/input/joystick/xbox_gip.c
--
2.51.0
^ permalink raw reply
* Re: [PATCH v3] hid: intel-thc-hid: intel-quicki2c: support ACPI config for advanced features
From: srinivas pandruvada @ 2025-09-16 23:31 UTC (permalink / raw)
To: Xinpeng Sun, jikos, bentiss; +Cc: linux-input, linux-kernel, even.xu, Rui Zhang
In-Reply-To: <20250916025721.3375164-1-xinpeng.sun@intel.com>
On Tue, 2025-09-16 at 10:57 +0800, Xinpeng Sun wrote:
> There is a new BIOS enhancement that adds the capability to configure
> the
> following two features of I2C subsystem introduced in commit 1ed0b48
> ("Intel-thc: Introduce max input size control") and commit 3f2a921
> ("Intel-thc: Introduce interrupt delay control"):
> - Max input size control
> - Interrupt delay control
>
> As BIOS is used for the configuration of these two features, change
> driver
> data usage to indicate hardware capability, and add corresponding
> ACPI
> configuration support in QuickI2C driver.
>
> Signed-off-by: Xinpeng Sun <xinpeng.sun@intel.com>
> Tested-by: Rui Zhang <rui1.zhang@intel.com>
> ---
You need change log as this v3..
Thanks,
Srinivas
> .../intel-quicki2c/pci-quicki2c.c | 39 +++++++++++++++--
> --
> .../intel-quicki2c/quicki2c-dev.h | 24 +++++++++++-
> 2 files changed, 53 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
> b/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
> index 854926b3cfd4..3ce5a692b92b 100644
> --- a/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
> +++ b/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
> @@ -23,6 +23,7 @@
>
> static struct quicki2c_ddata ptl_ddata = {
> .max_detect_size = MAX_RX_DETECT_SIZE_PTL,
> + .max_interrupt_delay = MAX_RX_INTERRUPT_DELAY,
> };
>
> /* THC QuickI2C ACPI method to get device properties */
> @@ -200,6 +201,21 @@ static int quicki2c_get_acpi_resources(struct
> quicki2c_device *qcdev)
> return -EOPNOTSUPP;
> }
>
> + if (qcdev->ddata) {
> + qcdev->i2c_max_frame_size_enable = i2c_config.FSEN;
> + qcdev->i2c_int_delay_enable = i2c_config.INDE;
> +
> + if (i2c_config.FSVL <= qcdev->ddata-
> >max_detect_size)
> + qcdev->i2c_max_frame_size = i2c_config.FSVL;
> + else
> + qcdev->i2c_max_frame_size = qcdev->ddata-
> >max_detect_size;
> +
> + if (i2c_config.INDV <= qcdev->ddata-
> >max_interrupt_delay)
> + qcdev->i2c_int_delay = i2c_config.INDV;
> + else
> + qcdev->i2c_int_delay = qcdev->ddata-
> >max_interrupt_delay;
> + }
> +
> return 0;
> }
>
> @@ -441,17 +457,24 @@ static void quicki2c_dma_adv_enable(struct
> quicki2c_device *qcdev)
> * max input length <= THC detect capability, enable the
> feature with device
> * max input length.
> */
> - if (qcdev->ddata->max_detect_size >=
> - le16_to_cpu(qcdev->dev_desc.max_input_len)) {
> - thc_i2c_set_rx_max_size(qcdev->thc_hw,
> - le16_to_cpu(qcdev-
> >dev_desc.max_input_len));
> + if (qcdev->i2c_max_frame_size_enable) {
> + if (qcdev->i2c_max_frame_size >=
> + le16_to_cpu(qcdev->dev_desc.max_input_len)) {
> + thc_i2c_set_rx_max_size(qcdev->thc_hw,
> + le16_to_cpu(qcdev-
> >dev_desc.max_input_len));
> + } else {
> + dev_warn(qcdev->dev,
> + "Max frame size is smaller than hid
> max input length!");
> + thc_i2c_set_rx_max_size(qcdev->thc_hw,
> + le16_to_cpu(qcdev-
> >i2c_max_frame_size));
> + }
> thc_i2c_rx_max_size_enable(qcdev->thc_hw, true);
> }
>
> /* If platform supports interrupt delay feature, enable it
> with given delay */
> - if (qcdev->ddata->interrupt_delay) {
> + if (qcdev->i2c_int_delay_enable) {
> thc_i2c_set_rx_int_delay(qcdev->thc_hw,
> - qcdev->ddata-
> >interrupt_delay);
> + qcdev->i2c_int_delay * 10);
> thc_i2c_rx_int_delay_enable(qcdev->thc_hw, true);
> }
> }
> @@ -464,10 +487,10 @@ static void quicki2c_dma_adv_enable(struct
> quicki2c_device *qcdev)
> */
> static void quicki2c_dma_adv_disable(struct quicki2c_device *qcdev)
> {
> - if (qcdev->ddata->max_detect_size)
> + if (qcdev->i2c_max_frame_size_enable)
> thc_i2c_rx_max_size_enable(qcdev->thc_hw, false);
>
> - if (qcdev->ddata->interrupt_delay)
> + if (qcdev->i2c_int_delay_enable)
> thc_i2c_rx_int_delay_enable(qcdev->thc_hw, false);
> }
>
> diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h
> b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h
> index d412eafcf9ea..0d423d5dd7a7 100644
> --- a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h
> +++ b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h
> @@ -38,6 +38,8 @@
>
> /* PTL Max packet size detection capability is 255 Bytes */
> #define MAX_RX_DETECT_SIZE_PTL 255
> +/* Max interrupt delay capability is 2.56ms */
> +#define MAX_RX_INTERRUPT_DELAY 256
>
> /* Default interrupt delay is 1ms, suitable for most devices */
> #define DEFAULT_INTERRUPT_DELAY_US (1 * USEC_PER_MSEC)
> @@ -101,6 +103,10 @@ struct quicki2c_subip_acpi_parameter {
> * @HMTD: High Speed Mode Plus (3.4Mbits/sec) Serial Data Line
> Transmit HOLD Period
> * @HMRD: High Speed Mode Plus (3.4Mbits/sec) Serial Data Line
> Receive HOLD Period
> * @HMSL: Maximum length (in ic_clk_cycles) of suppressed spikes in
> High Speed Mode
> + * @FSEN: Maximum Frame Size Feature Enable Control
> + * @FSVL: Maximum Frame Size Value (unit in Bytes)
> + * @INDE: Interrupt Delay Feature Enable Control
> + * @INDV: Interrupt Delay Value (unit in 10 us)
> *
> * Those properties get from QUICKI2C_ACPI_METHOD_NAME_ISUB method,
> used for
> * I2C timing configure.
> @@ -127,17 +133,22 @@ struct quicki2c_subip_acpi_config {
> u64 HMTD;
> u64 HMRD;
> u64 HMSL;
> +
> + u64 FSEN;
> + u64 FSVL;
> + u64 INDE;
> + u64 INDV;
> u8 reserved;
> };
>
> /**
> * struct quicki2c_ddata - Driver specific data for quicki2c device
> * @max_detect_size: Identify max packet size detect for rx
> - * @interrupt_delay: Identify interrupt detect delay for rx
> + * @interrupt_delay: Identify max interrupt detect delay for rx
> */
> struct quicki2c_ddata {
> u32 max_detect_size;
> - u32 interrupt_delay;
> + u32 max_interrupt_delay;
> };
>
> struct device;
> @@ -170,6 +181,10 @@ struct acpi_device;
> * @report_len: The length of input/output report packet
> * @reset_ack_wq: Workqueue for waiting reset response from device
> * @reset_ack: Indicate reset response received or not
> + * @i2c_max_frame_size_enable: Indicate max frame size feature
> enabled or not
> + * @i2c_max_frame_size: Max RX frame size (unit in Bytes)
> + * @i2c_int_delay_enable: Indicate interrupt delay feature enabled
> or not
> + * @i2c_int_delay: Interrupt detection delay value (unit in 10 us)
> */
> struct quicki2c_device {
> struct device *dev;
> @@ -200,6 +215,11 @@ struct quicki2c_device {
>
> wait_queue_head_t reset_ack_wq;
> bool reset_ack;
> +
> + u32 i2c_max_frame_size_enable;
> + u32 i2c_max_frame_size;
> + u32 i2c_int_delay_enable;
> + u32 i2c_int_delay;
> };
>
> #endif /* _QUICKI2C_DEV_H_ */
^ permalink raw reply
* Re: [PATCH v3 4/6] dt-bindings: touchscreen: fsl,imx6ul-tsc: support glitch thresold
From: Conor Dooley @ 2025-09-16 19:27 UTC (permalink / raw)
To: Frank Li
Cc: Dario Binacchi, linux-kernel, linux-amarula, Conor Dooley,
Dmitry Torokhov, Fabio Estevam, Haibo Chen, Krzysztof Kozlowski,
Pengutronix Kernel Team, Rob Herring, Sascha Hauer, Shawn Guo,
devicetree, imx, linux-arm-kernel, linux-input
In-Reply-To: <20250916-auction-angelfish-0239691a54e5@spud>
[-- Attachment #1: Type: text/plain, Size: 2737 bytes --]
On Tue, Sep 16, 2025 at 08:25:53PM +0100, Conor Dooley wrote:
> On Tue, Sep 16, 2025 at 11:55:17AM -0400, Frank Li wrote:
> > On Mon, Sep 15, 2025 at 09:53:06PM +0200, Dario Binacchi wrote:
> > > Support the touchscreen-glitch-threshold-ns property. Unlike the
> > > generic description in touchscreen.yaml, this controller maps the
> > > provided value to one of four discrete thresholds internally.
> > >
> > > Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
> > >
> > > ---
> > >
> > > Changes in v3:
> > > - Remove the final part of the description that refers to
> > > implementation details.
> > >
> > > .../bindings/input/touchscreen/fsl,imx6ul-tsc.yaml | 12 ++++++++++++
> > > 1 file changed, 12 insertions(+)
> > >
> > > diff --git a/Documentation/devicetree/bindings/input/touchscreen/fsl,imx6ul-tsc.yaml b/Documentation/devicetree/bindings/input/touchscreen/fsl,imx6ul-tsc.yaml
> > > index 678756ad0f92..6214d8be5a99 100644
> > > --- a/Documentation/devicetree/bindings/input/touchscreen/fsl,imx6ul-tsc.yaml
> > > +++ b/Documentation/devicetree/bindings/input/touchscreen/fsl,imx6ul-tsc.yaml
> > > @@ -62,6 +62,18 @@ properties:
> > > description: Number of data samples which are averaged for each read.
> > > enum: [ 1, 4, 8, 16, 32 ]
> > >
> > > + touchscreen-glitch-threshold-ns:
> > > + description: |
> > > + Unlike the generic property defined in touchscreen.yaml, this
> > > + controller does not allow arbitrary values. Internally the value is
> > > + converted to IPG clock cycles and mapped to one of four discrete
> > > + thresholds exposed by the TSC_DEBUG_MODE2 register:
> > > +
> > > + 0: 8191 IPG cycles
> > > + 1: 4095 IPG cycles
> > > + 2: 2047 IPG cycles
> > > + 3: 1023 IPG cycles
> > > +
> >
> > You have to use ns here. You can caculate in driver to match to closed one.
>
> That is what he is saying it is doing - "internally the value is
> converted to IPG clock cycles" and so on. Your repeated misunderstanding
> of this though points out that maybe the description is still lacking?
>
> Dario, how about:
> | The gitch threshold in nanoseconds. Drivers must convert this value to
Or maybe instead of what I did here for the first sentence, yoink the text
from [3/6] instead and re-use it.
> | IPG clock cycles and map it to one of the four discrete thresholds
> | exposed by the TSC_DEBUG_MODE2 register:
> |
> | 0: 8191 IPG cycles
> | 1: 4095 IPG cycles
> | 2: 2047 IPG cycles
> | 3: 1023 IPG cycles
> ?
> I dropped the bit about arbitrary values, due to my comment on the other
> version a few mins ago.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox