diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2024-06-09 21:18:10 -0700 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2024-06-20 14:57:08 -0700 |
commit | 204d18a7a0c67352857dee1bbac517ed63f01d8e (patch) | |
tree | b325c9f35fdb44a05abf07551cccd8e19245eace /drivers/input/misc | |
parent | daa268ae2866ae5c80a0650c04a4989fb069b5d9 (diff) |
Input: ims-pcu - use driver core to instantiate device attributes
Instead of manually creating driver-specific device attributes
set struct usb_driver->dev_groups pointer to have the driver core
do it.
Link: https://lore.kernel.org/r/20240610041813.722445-1-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/misc')
-rw-r--r-- | drivers/input/misc/ims-pcu.c | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c index a8c474de01ad..6f0e4f6567b0 100644 --- a/drivers/input/misc/ims-pcu.c +++ b/drivers/input/misc/ims-pcu.c @@ -1465,9 +1465,27 @@ static struct attribute *ims_pcu_ofn_attrs[] = { NULL }; +static umode_t ims_pcu_ofn_is_attr_visible(struct kobject *kobj, + struct attribute *attr, int n) +{ + struct device *dev = kobj_to_dev(kobj); + struct usb_interface *intf = to_usb_interface(dev); + struct ims_pcu *pcu = usb_get_intfdata(intf); + umode_t mode = attr->mode; + + /* + * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor. + */ + if (pcu->bootloader_mode || pcu->device_id == IMS_PCU_PCU_B_DEVICE_ID) + mode = 0; + + return mode; +} + static const struct attribute_group ims_pcu_ofn_attr_group = { - .name = "ofn", - .attrs = ims_pcu_ofn_attrs, + .name = "ofn", + .is_visible = ims_pcu_ofn_is_attr_visible, + .attrs = ims_pcu_ofn_attrs, }; static void ims_pcu_irq(struct urb *urb) @@ -1889,16 +1907,6 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu) /* Device appears to be operable, complete initialization */ pcu->device_no = atomic_inc_return(&device_no); - /* - * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor - */ - if (pcu->device_id != IMS_PCU_PCU_B_DEVICE_ID) { - error = sysfs_create_group(&pcu->dev->kobj, - &ims_pcu_ofn_attr_group); - if (error) - return error; - } - error = ims_pcu_setup_backlight(pcu); if (error) return error; @@ -1935,10 +1943,6 @@ static void ims_pcu_destroy_application_mode(struct ims_pcu *pcu) ims_pcu_destroy_gamepad(pcu); ims_pcu_destroy_buttons(pcu); ims_pcu_destroy_backlight(pcu); - - if (pcu->device_id != IMS_PCU_PCU_B_DEVICE_ID) - sysfs_remove_group(&pcu->dev->kobj, - &ims_pcu_ofn_attr_group); } } @@ -2030,20 +2034,14 @@ static int ims_pcu_probe(struct usb_interface *intf, if (error) goto err_stop_io; - error = sysfs_create_group(&intf->dev.kobj, &ims_pcu_attr_group); - if (error) - goto err_stop_io; - error = pcu->bootloader_mode ? ims_pcu_init_bootloader_mode(pcu) : ims_pcu_init_application_mode(pcu); if (error) - goto err_remove_sysfs; + goto err_stop_io; return 0; -err_remove_sysfs: - sysfs_remove_group(&intf->dev.kobj, &ims_pcu_attr_group); err_stop_io: ims_pcu_stop_io(pcu); err_free_buffers: @@ -2069,8 +2067,6 @@ static void ims_pcu_disconnect(struct usb_interface *intf) if (alt->desc.bInterfaceClass != USB_CLASS_COMM) return; - sysfs_remove_group(&intf->dev.kobj, &ims_pcu_attr_group); - ims_pcu_stop_io(pcu); if (pcu->bootloader_mode) @@ -2129,9 +2125,16 @@ static const struct usb_device_id ims_pcu_id_table[] = { { } }; +static const struct attribute_group *ims_pcu_sysfs_groups[] = { + &ims_pcu_attr_group, + &ims_pcu_ofn_attr_group, + NULL +}; + static struct usb_driver ims_pcu_driver = { .name = "ims_pcu", .id_table = ims_pcu_id_table, + .dev_groups = ims_pcu_sysfs_groups, .probe = ims_pcu_probe, .disconnect = ims_pcu_disconnect, #ifdef CONFIG_PM |