linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Barnabás Pőcze" <pobrn@protonmail.com>
To: Roderick Colenbrander <roderick@gaikai.com>
Cc: Jiri Kosina <jikos@kernel.org>,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	"linux-input@vger.kernel.org" <linux-input@vger.kernel.org>,
	Chris Ye <lzye@google.com>,
	Roderick Colenbrander <roderick.colenbrander@sony.com>
Subject: Re: [PATCH v2 09/13] HID: playstation: add DualSense lightbar support
Date: Thu, 07 Jan 2021 21:01:24 +0000	[thread overview]
Message-ID: <ALCENkx-A9Ev61S-COD8OEepdiT-CJWxze7GbpoOgZfU7C3z0h4IL0MAPUt3QizapD_4WVhpH6oFVbpQfl_Vf9ekkCvjOn_v68haPJDTTQM=@protonmail.com> (raw)
In-Reply-To: <20210102223109.996781-10-roderick@gaikai.com>

2021. január 2., szombat 23:31 keltezéssel, Roderick Colenbrander írta:

> From: Roderick Colenbrander <roderick.colenbrander@sony.com>
>
> Expose the DualSense its RGB lightbar using the new multicolor LED
> framework.
>
> Signed-off-by: Roderick Colenbrander <roderick.colenbrander@sony.com>
> [...]
> +/* Register a DualSense/DualShock4 RGB lightbar represented by a multicolor LED. */
> +static int ps_lightbar_register(struct ps_device *ps_dev, struct led_classdev_mc *lightbar_mc_dev,
> +	int (*brightness_set)(struct led_classdev *, enum led_brightness))
> +{
> +	struct hid_device *hdev = ps_dev->hdev;
> +	struct mc_subled *mc_led_info;
> +	struct led_classdev *led_cdev;
> +	int ret;
> +
> +	mc_led_info = devm_kzalloc(&hdev->dev, 3*sizeof(*mc_led_info), GFP_KERNEL);

I believe `devm_kmalloc_array()` would be more appropriate. Have you looked at it?


> +	if (!mc_led_info)
> +		return -ENOMEM;
> +
> +	mc_led_info[0].color_index = LED_COLOR_ID_RED;
> +	mc_led_info[0].channel = 0;
> +	mc_led_info[1].color_index = LED_COLOR_ID_GREEN;
> +	mc_led_info[1].channel = 1;
> +	mc_led_info[2].color_index = LED_COLOR_ID_BLUE;
> +	mc_led_info[2].channel = 2;

Just a small note, as far as I'm aware, the `channel` member is not used by
multicolor LED functions, and it's not even used in this module as far as I see.


> +
> +	lightbar_mc_dev->subled_info = mc_led_info;
> +	lightbar_mc_dev->num_colors = 3;
> +
> +	led_cdev = &lightbar_mc_dev->led_cdev;
> +	led_cdev->name = devm_kasprintf(&hdev->dev, GFP_KERNEL, "playstation::%pMR::rgb",
> +			ps_dev->mac_address);
> +	led_cdev->brightness = 255;
> +	led_cdev->max_brightness = 255;
> +	led_cdev->brightness_set_blocking = brightness_set;
> +
> +	ret = devm_led_classdev_multicolor_register(&hdev->dev, lightbar_mc_dev);
> +	if (ret < 0) {
> +		hid_err(hdev, "Cannot register multicolor LED device\n");
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
>  static struct input_dev *ps_sensors_create(struct hid_device *hdev, int accel_range, int accel_res,
>  		int gyro_range, int gyro_res)
>  {
> @@ -601,6 +652,27 @@  static int dualsense_get_mac_address(struct dualsense *ds)
>  	return ret;
>  }
>
> +static int dualsense_lightbar_set_brightness(struct led_classdev *cdev,
> +	enum led_brightness brightness)
> +{
> +	struct led_classdev_mc *mc_cdev = lcdev_to_mccdev(cdev);
> +	struct hid_device *hdev = to_hid_device(cdev->dev->parent);
> +	struct dualsense *ds = hid_get_drvdata(hdev);

I think the previous two lines could be replaced with

```
struct dualsense *ds = container_of(mc_cdev, struct dualsense, lightbar);
```


> +	unsigned long flags;
> +
> +	led_mc_calc_color_components(mc_cdev, brightness);
> +
> +	spin_lock_irqsave(&ds->base.lock, flags);
> +	ds->update_lightbar = true;
> +	ds->lightbar_red = mc_cdev->subled_info[0].brightness;
> +	ds->lightbar_green = mc_cdev->subled_info[1].brightness;
> +	ds->lightbar_blue = mc_cdev->subled_info[2].brightness;
> +	spin_unlock_irqrestore(&ds->base.lock, flags);
> +
> +	schedule_work(&ds->output_worker);
> +	return 0;
> +}
> +
>  static void dualsense_init_output_report(struct dualsense *ds, struct dualsense_output_report *rp,
>  		void *buf)
>  {
> @@ -682,6 +754,15 @@  static void dualsense_output_worker(struct work_struct *work)
>  		ds->update_rumble = false;
>  	}
>
> +	if (ds->update_lightbar) {
> +		common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_LIGHTBAR_CONTROL_ENABLE;
> +		common->lightbar_red = ds->lightbar_red;
> +		common->lightbar_green = ds->lightbar_green;
> +		common->lightbar_blue = ds->lightbar_blue;
> +
> +		ds->update_lightbar = false;
> +	}
> +
>  	spin_unlock_irqrestore(&ds->base.lock, flags);
>
>  	dualsense_send_output_report(ds, &report);
> @@ -861,6 +942,30 @@  static int dualsense_play_effect(struct input_dev *dev, void *data, struct ff_ef
>  	return 0;
>  }
> [...]
>  static struct ps_device *dualsense_create(struct hid_device *hdev)
>  {
>  	struct dualsense *ds;
> @@ -930,6 +1035,18 @@  static struct ps_device *dualsense_create(struct hid_device *hdev)
>  	if (ret < 0)
>  		goto err;
>
> +	/* The hardware may have control over the LEDs (e.g. in Bluetooth on startup).
> +	 * Reset the LEDs (lightbar, mute, player leds), so we can control them
> +	 * from software.
> +	 */
> +	ret = dualsense_reset_leds(ds);
> +	if (ret < 0)

I believe if `dualsense_reset_leds()` can only return 0 on success, or an errno,
then `if (ret)` would be better.


> +		goto err;
> +
> +	ret = ps_lightbar_register(ps_dev, &ds->lightbar, dualsense_lightbar_set_brightness);
> +	if (ret < 0)
> [...]

Same here.


Regards,
Barnabás Pőcze

  reply	other threads:[~2021-01-07 21:02 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-02 22:30 [PATCH v2 00/13] HID: new driver for PS5 'DualSense' controller Roderick Colenbrander
2021-01-02 22:30 ` [PATCH v2 01/13] HID: playstation: initial DualSense USB support Roderick Colenbrander
2021-01-04 12:20   ` Jiri Kosina
2021-01-05  8:20   ` Benjamin Tissoires
2021-01-07 17:14   ` Barnabás Pőcze
2021-01-08  7:12     ` Roderick Colenbrander
2021-01-08 11:53       ` Barnabás Pőcze
2021-01-02 22:30 ` [PATCH v2 02/13] HID: playstation: use DualSense MAC address as unique identifier Roderick Colenbrander
2021-01-07 17:22   ` Barnabás Pőcze
2021-01-02 22:30 ` [PATCH v2 03/13] HID: playstation: add DualSense battery support Roderick Colenbrander
2021-01-07 17:50   ` Barnabás Pőcze
2021-01-02 22:31 ` [PATCH v2 04/13] HID: playstation: add DualSense touchpad support Roderick Colenbrander
2021-01-07 17:55   ` Barnabás Pőcze
2021-01-02 22:31 ` [PATCH v2 05/13] HID: playstation: add DualSense accelerometer and gyroscope support Roderick Colenbrander
2021-01-07 13:34   ` Florian Märkl
2021-01-08  5:51     ` Roderick Colenbrander
2021-01-07 18:51   ` Barnabás Pőcze
2021-01-08  6:06     ` Roderick Colenbrander
2021-01-08 12:01       ` Barnabás Pőcze
2021-01-08 17:15         ` Siarhei Vishniakou
2021-01-08 19:54           ` Roderick Colenbrander
2021-01-09  0:11             ` Siarhei Vishniakou
2021-01-11  0:06               ` Roderick Colenbrander
2021-01-02 22:31 ` [PATCH v2 06/13] HID: playstation: track devices in list Roderick Colenbrander
2021-01-07 20:13   ` Barnabás Pőcze
2021-01-02 22:31 ` [PATCH v2 07/13] HID: playstation: add DualSense Bluetooth support Roderick Colenbrander
2021-01-07 20:18   ` Barnabás Pőcze
2021-01-02 22:31 ` [PATCH v2 08/13] HID: playstation: add DualSense classic rumble support Roderick Colenbrander
2021-01-07 20:41   ` Barnabás Pőcze
2021-01-07 20:48     ` Barnabás Pőcze
2021-01-08 17:01     ` Roderick Colenbrander
2021-01-02 22:31 ` [PATCH v2 09/13] HID: playstation: add DualSense lightbar support Roderick Colenbrander
2021-01-07 21:01   ` Barnabás Pőcze [this message]
2021-01-02 22:31 ` [PATCH v2 10/13] HID: playstation: add microphone mute support for DualSense Roderick Colenbrander
2021-01-07 21:57   ` Barnabás Pőcze
2021-01-02 22:31 ` [PATCH v2 11/13] HID: playstation: add DualSense player LEDs support Roderick Colenbrander
2021-01-07 22:17   ` Barnabás Pőcze
2021-01-02 22:31 ` [PATCH v2 12/13] HID: playstation: DualSense set LEDs to default player id Roderick Colenbrander
2021-01-07 22:25   ` Barnabás Pőcze
2021-01-02 22:31 ` [PATCH v2 13/13] HID: playstation: report DualSense hardware and firmware version Roderick Colenbrander
2021-01-07 22:26   ` Barnabás Pőcze
2021-01-09  1:35     ` Roderick Colenbrander

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='ALCENkx-A9Ev61S-COD8OEepdiT-CJWxze7GbpoOgZfU7C3z0h4IL0MAPUt3QizapD_4WVhpH6oFVbpQfl_Vf9ekkCvjOn_v68haPJDTTQM=@protonmail.com' \
    --to=pobrn@protonmail.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=lzye@google.com \
    --cc=roderick.colenbrander@sony.com \
    --cc=roderick@gaikai.com \
    /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;
as well as URLs for NNTP newsgroup(s).