Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: typec: Update sysfs when setting ops

When adding altmode ops, update the sysfs group so that visibility is
also recalculated.

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Benson Leung <bleung@chromium.org>
Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
Signed-off-by: Jameson Thies <jthies@google.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://lore.kernel.org/r/20240510201244.2968152-3-jthies@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Abhishek Pandit-Subedi and committed by
Greg Kroah-Hartman
fe8db0bb 99516f76

+22 -3
+1 -1
drivers/usb/typec/altmodes/displayport.c
··· 746 746 dp->alt = alt; 747 747 748 748 alt->desc = "DisplayPort"; 749 - alt->ops = &dp_altmode_ops; 749 + typec_altmode_set_ops(alt, &dp_altmode_ops); 750 750 751 751 if (plug) { 752 752 plug->desc = "Displayport";
+17 -1
drivers/usb/typec/class.c
··· 467 467 NULL 468 468 }; 469 469 470 + /** 471 + * typec_altmode_set_ops - Set ops for altmode 472 + * @adev: Handle to the alternate mode 473 + * @ops: Ops for the alternate mode 474 + * 475 + * After setting ops, attribute visiblity needs to be refreshed if the alternate 476 + * mode can be activated. 477 + */ 478 + void typec_altmode_set_ops(struct typec_altmode *adev, 479 + const struct typec_altmode_ops *ops) 480 + { 481 + adev->ops = ops; 482 + sysfs_update_group(&adev->dev.kobj, &typec_altmode_group); 483 + } 484 + EXPORT_SYMBOL_GPL(typec_altmode_set_ops); 485 + 470 486 static int altmode_id_get(struct device *dev) 471 487 { 472 488 struct ida *ids; ··· 2333 2317 continue; 2334 2318 } 2335 2319 2336 - alt->ops = ops; 2320 + typec_altmode_set_ops(alt, ops); 2337 2321 typec_altmode_set_drvdata(alt, drvdata); 2338 2322 altmodes[index] = alt; 2339 2323 index++;
+1 -1
drivers/usb/typec/ucsi/displayport.c
··· 333 333 dp->con = con; 334 334 dp->alt = alt; 335 335 336 - alt->ops = &ucsi_displayport_ops; 336 + typec_altmode_set_ops(alt, &ucsi_displayport_ops); 337 337 typec_altmode_set_drvdata(alt, dp); 338 338 339 339 return alt;
+3
include/linux/usb/typec.h
··· 167 167 168 168 void typec_altmode_update_active(struct typec_altmode *alt, bool active); 169 169 170 + void typec_altmode_set_ops(struct typec_altmode *alt, 171 + const struct typec_altmode_ops *ops); 172 + 170 173 enum typec_plug_index { 171 174 TYPEC_PLUG_SOP_P, 172 175 TYPEC_PLUG_SOP_PP,