mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Sakari Ailus <sakari.ailus@iki.fi>
Cc: "Denis Benato" <denis.benato@linux.dev>,
	LKML <linux-kernel@vger.kernel.org>,
	platform-driver-x86@vger.kernel.org, linux-input@vger.kernel.org,
	kernel@lists.opengamingcollective.org,
	"Benjamin Tissoires" <bentiss@kernel.org>,
	"Jiri Kosina" <jikos@kernel.org>,
	"Luke D . Jones" <luke@ljones.dev>,
	"Mateusz Schwartz" <matthew.schwartz@linux.dev>,
	"Denis Benato" <benato.denis96@gmail.com>,
	"Jonathan LoBue" <jlobue10@gmail.com>,
	"Khamunetri Clark" <khamunetriclark@gmail.com>,
	"Derek J. Clark" <derekjohn.clark@gmail.com>,
	"Joshua Leivenzon" <hacker1024@users.sourceforge.net>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Rebecca Mara Müller" <rebecca.mara@posteo.de>,
	"Ivan Levchenko" <me@livan.pro>,
	"Corentin Chary" <corentin.chary@gmail.com>,
	"Hans de Goede" <hansg@kernel.org>
Subject: Re: [PATCH v11 08/18] HID: asus: add support to force feedback
Date: Mon, 26 Oct 2026 20:21:54 +0200 (EET)	[thread overview]
Message-ID: <1c017f49-bc69-fc68-20f8-0c66a2c85719@linux.intel.com> (raw)
In-Reply-To: <at9JNgMf8EZdCHEh@valkosipuli.retiisi.eu>

On Mon, 26 Oct 2026, Sakari Ailus wrote:

> Hi Denis,
> 
> I tested this on Asus T100TA, it seems to work fine.
> 
> Please see my other comments below.
> 
> On Sun, Oct 25, 2026 at 11:52:21PM +0000, Denis Benato wrote:
> > Unlike ROG ally the X version and following ones uses DInput protocol
> > and the force feedback needs to be implemented as its protocol is
> > vendor-specific, therefore add support for FF_RUMBLE with magnitude
> > scaling on a work-queue based approach to avoid using possibly
> > sleeping calls in atomic context.
> > 
> > Signed-off-by: Denis Benato <denis.benato@linux.dev>
> > Signed-off-by: Khamunetri Clark <khamunetriclark@gmail.com>
> > Signed-off-by: Luke Jones <luke@ljones.dev>
> > ---
> >  drivers/hid/Kconfig    |   1 +
> >  drivers/hid/hid-asus.c | 321 +++++++++++++++++++++++++++++++++++++----
> >  2 files changed, 297 insertions(+), 25 deletions(-)
> > 
> > diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
> > index 2481bc01c435..042e3bb0d817 100644
> > --- a/drivers/hid/Kconfig
> > +++ b/drivers/hid/Kconfig
> > @@ -189,6 +189,7 @@ config HID_ASUS
> >  	depends on USB_HID
> >  	depends on LEDS_CLASS
> >  	depends on ASUS_WMI || ASUS_WMI=n
> > +        select INPUT_FF_MEMLESS
> 
> Tabs, please.
> 
> >  	select POWER_SUPPLY
> >  	help
> >  	Support for Asus notebook built-in keyboard and touchpad via i2c, and
> > diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c
> > index e1883ee20413..a3a21a1493aa 100644
> > --- a/drivers/hid/hid-asus.c
> > +++ b/drivers/hid/hid-asus.c
> > @@ -244,6 +244,23 @@ struct ally_config {
> >   */
> >  static struct ally_config *ally_config;
> >  
> > +/* XInput force-feedback report (output report 0x0d, gamepad interface) */
> > +struct ff_data {
> > +	u8 enable;
> > +	u8 magnitude_left;
> > +	u8 magnitude_right;
> > +	u8 magnitude_strong;
> > +	u8 magnitude_weak;
> > +	u8 pulse_sustain_10ms;
> > +	u8 pulse_release_10ms;
> > +	u8 loop_count;
> > +} __packed;
> > +
> > +struct ff_report {
> > +	u8 report_id;
> > +	struct ff_data ff;
> > +} __packed;
> > +
> >  struct ally_handheld {
> >  	/* All read/write to IN interfaces must lock */
> >  	struct mutex intf_mutex;
> > @@ -269,6 +286,13 @@ struct ally_handheld {
> >  	bool ally_x_probe_in_progress;
> >  	bool keyboard_probe_in_progress;
> >  
> > +	struct ff_report ff_packet;
> > +	struct work_struct ff_work;
> > +	/* Serializes ff_packet and update_ff between play_effect and ff_work */
> > +	spinlock_t ff_lock;
> > +	bool ff_work_initialized;
> > +	bool update_ff;
> 
> Arranging these with the rest of the bools would save some memory.
> 
> > +
> >  	struct hid_device *keyboard_hdev;
> >  	struct input_dev *keyboard_input;
> >  
> > @@ -384,10 +408,15 @@ enum ally_command_codes {
> >  	CMD_SET_ANTI_DEADZONE           = 0x18,
> >  };
> >  
> > +/* XInput rumble magnitudes use the hardware's 0..100 intensity range. */
> > +#define ALLY_FF_MAX_INTENSITY 100
> > +
> >  static const u8 ALLY_FORCE_FEEDBACK_OFF[] = {
> >  	0x0D, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xEB
> >  };
> >  
> > +static_assert(sizeof(struct ff_report) == sizeof(ALLY_FORCE_FEEDBACK_OFF));
> > +
> >  /*
> >   * The ROG Ally device presents multiple USB interfaces (keyboard, mouse, gamepad,
> >   * and custom configuration interface) that bind to the same module. Since only
> > @@ -395,6 +424,7 @@ static const u8 ALLY_FORCE_FEEDBACK_OFF[] = {
> >   * ally_handheld structure to share state across these separate HID interfaces.
> >   */
> >  static void ally_resume_work_fn(struct work_struct *work);
> > +static void ally_x_ff_work_fn(struct work_struct *work);
> >  
> >  /*
> >   * Changes to ally_drvdata must lock: the raw_event callbacks, which may
> > @@ -410,6 +440,13 @@ static struct ally_handheld ally_drvdata = {
> >  	 */
> >  	.resume_work = __DELAYED_WORK_INITIALIZER(ally_drvdata.resume_work,
> >  						  ally_resume_work_fn, 0),
> > +	/*
> > +	 * Initialised statically for the same reason as resume_work: remove()
> > +	 * drains the work whichever of the interfaces probed or failed to
> > +	 * probe, so it must be safe to cancel unconditionally.
> > +	 */
> > +	.ff_work = __WORK_INITIALIZER(ally_drvdata.ff_work, ally_x_ff_work_fn),
> > +	.ff_lock = __SPIN_LOCK_UNLOCKED(ally_drvdata.ff_lock),
> >  };
> >  
> >  /*
> > @@ -2425,7 +2462,8 @@ static void ally_config_remove(struct hid_device *hdev, struct ally_config *cfg)
> >  	 * create them, so a device without those capabilities does not
> >  	 * trigger a "not found" warning.
> >  	 */
> > -	if (cfg->user_cal_support || cfg->anti_deadzone_support) {
> > +	if (cfg->user_cal_support || cfg->anti_deadzone_support ||
> > +	    cfg->resp_curve_support) {
> >  		for (i = 0; i < ARRAY_SIZE(ally_cal_attr_groups); i++)
> >  			sysfs_remove_group(&hdev->dev.kobj,
> >  					   ally_cal_attr_groups[i]);
> > @@ -2611,6 +2649,106 @@ static void ally_x_input_close(struct input_dev *dev)
> >  	hid_hw_close(input_get_drvdata(dev));
> >  }
> >  
> > +/**
> > + * ally_x_send_ff_report() - Send a force-feedback report to the gamepad
> > + * @hdev: HID device
> > + * @buf: buffer containing the report to send
> > + * @len: length of the report
> > + *
> > + * The gamepad interface consumes force-feedback packets as output reports,
> > + * unlike the config interface which expects feature reports: a rumble packet
> > + * sent as HID_REQ_SET_REPORT would be rejected by the hardware.
> > + *
> > + * The caller must hold ally->intf_mutex, so that a send cannot race with
> > + * the gamepad interface being unbound and its transport being stopped.
> > + *
> > + * Return: count of data transferred, negative if error
> > + */
> > +static int ally_x_send_ff_report(struct hid_device *hdev,
> > +				 const u8 *buf, size_t len)
> > +{
> > +	u8 *dmabuf __free(kfree) = kmemdup(buf, len, GFP_KERNEL);
> 
> It's not very nice to assign variables and then check for errors. I'd thus
> separate the declaration and the assignment.

I actually thought the same thing first.

But then stopped and realized, it's mid-function declaration of a cleanup 
variable exactly following the guidelines (the long comment in cleanup.h).

So this function doesn't really have variable declaration block at all, 
making the mid-function variable declaration look like one. I understand 
it looks confusing when encountering this for the first time, it was for 
me as well.

> > +	if (!dmabuf)
> > +		return -ENOMEM;
> > +
> > +	return hid_hw_output_report(hdev, dmabuf, len);
> > +}

-- 
 i.


  reply	other threads:[~2026-10-26 18:22 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-25 23:52 [PATCH v11 00/18] HID: asus: add support for ROG Ally handhelds Denis Benato
2026-10-25 23:52 ` [PATCH v11 01/18] " Denis Benato
2026-10-26 12:38   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 02/18] HID: asus: add gamepad configuration Denis Benato
2026-10-26 12:56   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 03/18] HID: asus: add vibration strength configuration Denis Benato
2026-10-25 23:52 ` [PATCH v11 04/18] HID: asus: add joysticks inner and outer range configuration Denis Benato
2026-10-26 13:00   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 05/18] HID: asus: add triggers " Denis Benato
2026-10-25 23:52 ` [PATCH v11 06/18] HID: asus: add joysticks anti-deadzone configuration Denis Benato
2026-10-25 23:52 ` [PATCH v11 07/18] HID: asus: add support for response curve Denis Benato
2026-10-26 13:06   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 08/18] HID: asus: add support to force feedback Denis Benato
2026-10-26 12:36   ` Sakari Ailus
2026-10-26 18:21     ` Ilpo Järvinen [this message]
2026-10-26 18:27       ` Sakari Ailus
2026-10-26 13:13   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 09/18] HID: asus: add support for gamepad mode Denis Benato
2026-10-26 13:20   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 10/18] HID: asus: add support for turbo buttons Denis Benato
2026-10-26 13:29   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 11/18] HID: asus: add support for btn remapping Denis Benato
2026-10-26 14:03   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 12/18] HID: asus: size feature reports from the HID report descriptor Denis Benato
2026-10-26 13:06   ` Rebecca Mara Müller
2026-10-26 19:38     ` Denis Benato
2026-10-25 23:52 ` [PATCH v11 13/18] HID: asus: identify XG Mobile stations and bind the LED to the reported model Denis Benato
2026-10-25 23:52 ` [PATCH v11 14/18] HID: asus: expose XG Mobile identity and firmware information Denis Benato
2026-10-26 14:10   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 15/18] HID: asus: size ally gamepad commands from the HID report descriptor Denis Benato
2026-10-25 23:52 ` [PATCH v11 16/18] platform/x86: asus-armoury: pick the eGPU activation from the reported GPU Denis Benato
2026-10-25 23:52 ` [PATCH v11 17/18] HID: asus: report the XG Mobile GPU vendor to asus-wmi Denis Benato
2026-10-26 14:15   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 18/18] MAINTAINERS: add maintainer for the ASUS HID driver Denis Benato
2026-10-26 14:24 ` [PATCH v11 00/18] HID: asus: add support for ROG Ally handhelds Ilpo Järvinen
2026-10-26 18:03   ` Denis Benato

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1c017f49-bc69-fc68-20f8-0c66a2c85719@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=benato.denis96@gmail.com \
    --cc=bentiss@kernel.org \
    --cc=corentin.chary@gmail.com \
    --cc=denis.benato@linux.dev \
    --cc=derekjohn.clark@gmail.com \
    --cc=hacker1024@users.sourceforge.net \
    --cc=hansg@kernel.org \
    --cc=jikos@kernel.org \
    --cc=jlobue10@gmail.com \
    --cc=kernel@lists.opengamingcollective.org \
    --cc=khamunetriclark@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luke@ljones.dev \
    --cc=matthew.schwartz@linux.dev \
    --cc=me@livan.pro \
    --cc=nathan@kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rebecca.mara@posteo.de \
    --cc=sakari.ailus@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®