Hi 2021. január 2., szombat 23:31 keltezéssel, Roderick Colenbrander írta: > From: Roderick Colenbrander <roderick.colenbrander@xxxxxxxx> > > The DualSense features 5 player LEDs below its touchpad, which are > meant as player id indications. This patch exposes the player LEDs > as individual LEDs. > > Signed-off-by: Roderick Colenbrander <roderick.colenbrander@xxxxxxxx> > > diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c > index ebf8a6550308..183f011f081b 100644 > --- a/drivers/hid/hid-playstation.c > +++ b/drivers/hid/hid-playstation.c > [...] > +static enum led_brightness dualsense_player_led_get_brightness(struct led_classdev *led) > +{ > + struct hid_device *hdev = to_hid_device(led->dev->parent); > + struct dualsense *ds = hid_get_drvdata(hdev); > + > + return !!(ds->player_leds_state & BIT(led - ds->player_leds)); > +} > + > +static void dualsense_player_led_set_brightness(struct led_classdev *led, enum led_brightness value) > +{ > + struct hid_device *hdev = to_hid_device(led->dev->parent); > + struct dualsense *ds = hid_get_drvdata(hdev); > + unsigned long flags; > + unsigned int led_index; > + > + spin_lock_irqsave(&ds->base.lock, flags); > + > + led_index = led - ds->player_leds; > + if (value == LED_OFF) > + ds->player_leds_state &= ~(1 << led_index); > + else > + ds->player_leds_state |= (1 << led_index); A minor thing: I think `BIT(led_index)` should be used here. > + > + ds->update_player_leds = true; > + spin_unlock_irqrestore(&ds->base.lock, flags); > + > + schedule_work(&ds->output_worker); > +} > + > static void dualsense_init_output_report(struct dualsense *ds, struct dualsense_output_report *rp, > void *buf) > { > @@ -820,6 +855,13 @@ static void dualsense_output_worker(struct work_struct *work) > ds->update_lightbar = false; > } > > + if (ds->update_player_leds) { > + common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_PLAYER_INDICATOR_CONTROL_ENABLE; > + common->player_leds = ds->player_leds_state; > + > + ds->update_player_leds = false; > + } > + > if (ds->update_mic_mute) { > if (ds->mic_muted) { > common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_MIC_MUTE_LED_CONTROL_ENABLE; > @@ -1065,12 +1107,20 @@ static struct ps_device *dualsense_create(struct hid_device *hdev) > struct dualsense *ds; > struct ps_device *ps_dev; > uint8_t max_output_report_size; > - int ret; > + int i, ret; > > struct ps_led_info mute_led_info = { > "micmute", dualsense_mute_led_get_brightness, dualsense_mute_led_set_brightness > }; > > + struct ps_led_info player_leds_info[] = { > + { "led1", dualsense_player_led_get_brightness, dualsense_player_led_set_brightness }, > + { "led2", dualsense_player_led_get_brightness, dualsense_player_led_set_brightness }, > + { "led3", dualsense_player_led_get_brightness, dualsense_player_led_set_brightness }, > + { "led4", dualsense_player_led_get_brightness, dualsense_player_led_set_brightness }, > + { "led5", dualsense_player_led_get_brightness, dualsense_player_led_set_brightness } > + }; I think it would make sense to make `player_leds_info` and even `mute_led_info` `const` and `static`. > + > ds = devm_kzalloc(&hdev->dev, sizeof(*ds), GFP_KERNEL); > if (!ds) > return ERR_PTR(-ENOMEM); > @@ -1149,6 +1199,14 @@ static struct ps_device *dualsense_create(struct hid_device *hdev) > if (ret < 0) > goto err; > > + for (i = 0; i < ARRAY_SIZE(player_leds_info); i++) { > + struct ps_led_info *led_info = &player_leds_info[i]; > + > + ret = ps_led_register(ps_dev, &ds->player_leds[i], led_info); > + if (ret < 0) > + goto err; > + } > + > return &ds->base; > > err: Regards, Barnabás Pőcze