Message ID | 20220711072333.2064341-1-pmalani@chromium.org |
---|---|
Headers | show |
Series | Type-C switch driver and Type-C framework updates | expand |
Mon, Jul 11, 2022 at 07:22:55AM +0000, Prashant Malani kirjoitti: > Introduce a retimer device class and associated functions that register > and use retimer "switch" devices. These operate in a manner similar to > the "mode-switch" and help configure retimers that exist between the > Type-C connector and host controller(s). > > Type C ports can be linked to retimers using firmware node device > references (again, in a manner similar to "mode-switch"). > > There are no new sysfs files being created; there is the new retimer > class directory, but there are no class-specific files being created > there. > > Signed-off-by: Prashant Malani <pmalani@chromium.org> Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> > --- > > Changes since v3: > - Updated Commit message to mention that no new class-specific sysfs > files are being added. > > Changes since v2: > - No changes. > > Changes since v1: > - Change class name to "retimer" > - Change device type to "typec_retimer". > > drivers/usb/typec/Makefile | 2 +- > drivers/usb/typec/class.c | 9 +- > drivers/usb/typec/class.h | 1 + > drivers/usb/typec/retimer.c | 168 ++++++++++++++++++++++++++++++ > drivers/usb/typec/retimer.h | 15 +++ > include/linux/usb/typec_retimer.h | 45 ++++++++ > 6 files changed, 238 insertions(+), 2 deletions(-) > create mode 100644 drivers/usb/typec/retimer.c > create mode 100644 drivers/usb/typec/retimer.h > create mode 100644 include/linux/usb/typec_retimer.h > > diff --git a/drivers/usb/typec/Makefile b/drivers/usb/typec/Makefile > index 2f174cd3e5df..4955d9af0811 100644 > --- a/drivers/usb/typec/Makefile > +++ b/drivers/usb/typec/Makefile > @@ -1,6 +1,6 @@ > # SPDX-License-Identifier: GPL-2.0 > obj-$(CONFIG_TYPEC) += typec.o > -typec-y := class.o mux.o bus.o pd.o > +typec-y := class.o mux.o bus.o pd.o retimer.o > typec-$(CONFIG_ACPI) += port-mapper.o > obj-$(CONFIG_TYPEC) += altmodes/ > obj-$(CONFIG_TYPEC_TCPM) += tcpm/ > diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c > index bbc46b14f99a..9062836bb638 100644 > --- a/drivers/usb/typec/class.c > +++ b/drivers/usb/typec/class.c > @@ -2299,10 +2299,14 @@ static int __init typec_init(void) > if (ret) > goto err_unregister_bus; > > - ret = class_register(&typec_class); > + ret = class_register(&retimer_class); > if (ret) > goto err_unregister_mux_class; > > + ret = class_register(&typec_class); > + if (ret) > + goto err_unregister_retimer_class; > + > ret = usb_power_delivery_init(); > if (ret) > goto err_unregister_class; > @@ -2312,6 +2316,9 @@ static int __init typec_init(void) > err_unregister_class: > class_unregister(&typec_class); > > +err_unregister_retimer_class: > + class_unregister(&retimer_class); > + > err_unregister_mux_class: > class_unregister(&typec_mux_class); > > diff --git a/drivers/usb/typec/class.h b/drivers/usb/typec/class.h > index b531f9853bc0..43fcf9e37a8c 100644 > --- a/drivers/usb/typec/class.h > +++ b/drivers/usb/typec/class.h > @@ -76,6 +76,7 @@ extern const struct device_type typec_port_dev_type; > #define is_typec_port(dev) ((dev)->type == &typec_port_dev_type) > > extern struct class typec_mux_class; > +extern struct class retimer_class; > extern struct class typec_class; > > #if defined(CONFIG_ACPI) > diff --git a/drivers/usb/typec/retimer.c b/drivers/usb/typec/retimer.c > new file mode 100644 > index 000000000000..051eaa7d2899 > --- /dev/null > +++ b/drivers/usb/typec/retimer.c > @@ -0,0 +1,168 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright 2022 Google LLC > + * > + * USB Type-C Retimer support. > + * Author: Prashant Malani <pmalani@chromium.org> > + * > + */ > + > +#include <linux/device.h> > +#include <linux/list.h> > +#include <linux/module.h> > +#include <linux/mutex.h> > +#include <linux/property.h> > +#include <linux/slab.h> > + > +#include "class.h" > +#include "retimer.h" > + > +static bool dev_name_ends_with(struct device *dev, const char *suffix) > +{ > + const char *name = dev_name(dev); > + const int name_len = strlen(name); > + const int suffix_len = strlen(suffix); > + > + if (suffix_len > name_len) > + return false; > + > + return strcmp(name + (name_len - suffix_len), suffix) == 0; > +} > + > +static int retimer_fwnode_match(struct device *dev, const void *fwnode) > +{ > + return dev_fwnode(dev) == fwnode && dev_name_ends_with(dev, "-retimer"); > +} > + > +static void *typec_retimer_match(struct fwnode_handle *fwnode, const char *id, void *data) > +{ > + struct device *dev = class_find_device(&retimer_class, NULL, fwnode, > + retimer_fwnode_match); > + > + return dev ? to_typec_retimer(dev) : ERR_PTR(-EPROBE_DEFER); > +} > + > +/** > + * fwnode_typec_retimer_get - Find USB Type-C retimer. > + * @fwnode: The caller device node. > + * > + * Finds a retimer linked to the caller. This function is primarily meant for the > + * Type-C drivers. Returns a reference to the retimer on success, NULL if no > + * matching connection was found, or ERR_PTR(-EPROBE_DEFER) when a connection > + * was found but the retimer has not been enumerated yet. > + */ > +struct typec_retimer *fwnode_typec_retimer_get(struct fwnode_handle *fwnode) > +{ > + struct typec_retimer *retimer; > + > + retimer = fwnode_connection_find_match(fwnode, "retimer-switch", NULL, typec_retimer_match); > + if (!IS_ERR_OR_NULL(retimer)) > + WARN_ON(!try_module_get(retimer->dev.parent->driver->owner)); > + > + return retimer; > +} > +EXPORT_SYMBOL_GPL(fwnode_typec_retimer_get); > + > +/** > + * typec_retimer_put - Release handle to a retimer. > + * @retimer: USB Type-C Connector Retimer. > + * > + * Decrements reference count for @retimer. > + */ > +void typec_retimer_put(struct typec_retimer *retimer) > +{ > + if (!IS_ERR_OR_NULL(retimer)) { > + module_put(retimer->dev.parent->driver->owner); > + put_device(&retimer->dev); > + } > +} > +EXPORT_SYMBOL_GPL(typec_retimer_put); > + > +int typec_retimer_set(struct typec_retimer *retimer, struct typec_retimer_state *state) > +{ > + if (IS_ERR_OR_NULL(retimer)) > + return 0; > + > + return retimer->set(retimer, state); > +} > +EXPORT_SYMBOL_GPL(typec_retimer_set); > + > +static void typec_retimer_release(struct device *dev) > +{ > + kfree(to_typec_retimer(dev)); > +} > + > +static const struct device_type typec_retimer_dev_type = { > + .name = "typec_retimer", > + .release = typec_retimer_release, > +}; > + > +/** > + * typec_retimer_register - Register a retimer device. > + * @parent: Parent device. > + * @desc: Retimer description. > + * > + * Some USB Type-C connectors have their physical lines routed through retimers before they > + * reach muxes or host controllers. In some cases (for example: using alternate modes) > + * these retimers need to be reconfigured appropriately. This function registers retimer > + * switches which route and potentially modify the signals on the Type C physical lines > + * enroute to the host controllers. > + */ > +struct typec_retimer * > +typec_retimer_register(struct device *parent, const struct typec_retimer_desc *desc) > +{ > + struct typec_retimer *retimer; > + int ret; > + > + if (!desc || !desc->set) > + return ERR_PTR(-EINVAL); > + > + retimer = kzalloc(sizeof(*retimer), GFP_KERNEL); > + if (!retimer) > + return ERR_PTR(-ENOMEM); > + > + retimer->set = desc->set; > + > + device_initialize(&retimer->dev); > + retimer->dev.parent = parent; > + retimer->dev.fwnode = desc->fwnode; > + retimer->dev.class = &retimer_class; > + retimer->dev.type = &typec_retimer_dev_type; > + retimer->dev.driver_data = desc->drvdata; > + dev_set_name(&retimer->dev, "%s-retimer", > + desc->name ? desc->name : dev_name(parent)); > + > + ret = device_add(&retimer->dev); > + if (ret) { > + dev_err(parent, "failed to register retimer (%d)\n", ret); > + put_device(&retimer->dev); > + return ERR_PTR(ret); > + } > + > + return retimer; > +} > +EXPORT_SYMBOL_GPL(typec_retimer_register); > + > +/** > + * typec_retimer_unregister - Unregister retimer device. > + * @retimer: USB Type-C Connector retimer. > + * > + * Unregister retimer that was registered with typec_retimer_register(). > + */ > +void typec_retimer_unregister(struct typec_retimer *retimer) > +{ > + if (!IS_ERR_OR_NULL(retimer)) > + device_unregister(&retimer->dev); > +} > +EXPORT_SYMBOL_GPL(typec_retimer_unregister); > + > +void *typec_retimer_get_drvdata(struct typec_retimer *retimer) > +{ > + return dev_get_drvdata(&retimer->dev); > +} > +EXPORT_SYMBOL_GPL(typec_retimer_get_drvdata); > + > +struct class retimer_class = { > + .name = "retimer", > + .owner = THIS_MODULE, > +}; > diff --git a/drivers/usb/typec/retimer.h b/drivers/usb/typec/retimer.h > new file mode 100644 > index 000000000000..fa15951d4846 > --- /dev/null > +++ b/drivers/usb/typec/retimer.h > @@ -0,0 +1,15 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > + > +#ifndef __USB_TYPEC_RETIMER__ > +#define __USB_TYPEC_RETIMER__ > + > +#include <linux/usb/typec_retimer.h> > + > +struct typec_retimer { > + struct device dev; > + typec_retimer_set_fn_t set; > +}; > + > +#define to_typec_retimer(_dev_) container_of(_dev_, struct typec_retimer, dev) > + > +#endif /* __USB_TYPEC_RETIMER__ */ > diff --git a/include/linux/usb/typec_retimer.h b/include/linux/usb/typec_retimer.h > new file mode 100644 > index 000000000000..5e036b3360e2 > --- /dev/null > +++ b/include/linux/usb/typec_retimer.h > @@ -0,0 +1,45 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > + > +#ifndef __USB_TYPEC_RETIMER > +#define __USB_TYPEC_RETIMER > + > +#include <linux/property.h> > +#include <linux/usb/typec.h> > + > +struct device; > +struct typec_retimer; > +struct typec_altmode; > +struct fwnode_handle; > + > +struct typec_retimer_state { > + struct typec_altmode *alt; > + unsigned long mode; > + void *data; > +}; > + > +typedef int (*typec_retimer_set_fn_t)(struct typec_retimer *retimer, > + struct typec_retimer_state *state); > + > +struct typec_retimer_desc { > + struct fwnode_handle *fwnode; > + typec_retimer_set_fn_t set; > + const char *name; > + void *drvdata; > +}; > + > +struct typec_retimer *fwnode_typec_retimer_get(struct fwnode_handle *fwnode); > +void typec_retimer_put(struct typec_retimer *retimer); > +int typec_retimer_set(struct typec_retimer *retimer, struct typec_retimer_state *state); > + > +static inline struct typec_retimer *typec_retimer_get(struct device *dev) > +{ > + return fwnode_typec_retimer_get(dev_fwnode(dev)); > +} > + > +struct typec_retimer * > +typec_retimer_register(struct device *parent, const struct typec_retimer_desc *desc); > +void typec_retimer_unregister(struct typec_retimer *retimer); > + > +void *typec_retimer_get_drvdata(struct typec_retimer *retimer); > + > +#endif /* __USB_TYPEC_RETIMER */ > -- > 2.37.0.144.g8ac04bfd2-goog
On Mon, Jul 11, 2022 at 07:22:54AM +0000, Prashant Malani wrote: > This series introduces a retimer class to the USB Type-C framework, > It also introduces a Chrome EC (Embedded Controller) switch driver which > registers the aforementioned retimer switches as well as mode-switches. > > Patch 1 and 2 introduce the retimer class and associated functions to > the Type-C common code. > > Patches 3-7 add the cros-typec-switch driver. > > Patches 8-9 update cros-ec-typec to get and use retimer switch handles. > > Submission suggestion (as always, open to better suggestions): > - Patch 1 and 2 can go through the USB repo. > - Patch 3-9 can go through the chrome-platform repo. Since they depend > on patches 1 and 2, we can create an "topic branch" off of usb-next > once Patch 1 and 2 are submitted, and then apply Patches 3-9 on top > of that "topic branch" before merging it back into chrome-platform's > for-next branch That's a mess, I can just take all of them into my tree if you want. thanks, greg k-h
On Mon, Jul 11, 2022 at 07:22:54AM +0000, Prashant Malani wrote: > This series introduces a retimer class to the USB Type-C framework, > It also introduces a Chrome EC (Embedded Controller) switch driver which > registers the aforementioned retimer switches as well as mode-switches. > > Patch 1 and 2 introduce the retimer class and associated functions to > the Type-C common code. > > Patches 3-7 add the cros-typec-switch driver. > > Patches 8-9 update cros-ec-typec to get and use retimer switch handles. > > Submission suggestion (as always, open to better suggestions): > - Patch 1 and 2 can go through the USB repo. Patches 1 and 2 now in my tree. thanks, greg k-h
Hi Greg, On Thu, Jul 14, 2022 at 7:15 AM Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote: > > On Mon, Jul 11, 2022 at 07:22:54AM +0000, Prashant Malani wrote: > > This series introduces a retimer class to the USB Type-C framework, > > It also introduces a Chrome EC (Embedded Controller) switch driver which > > registers the aforementioned retimer switches as well as mode-switches. > > > > Patch 1 and 2 introduce the retimer class and associated functions to > > the Type-C common code. > > > > Patches 3-7 add the cros-typec-switch driver. > > > > Patches 8-9 update cros-ec-typec to get and use retimer switch handles. > > > > Submission suggestion (as always, open to better suggestions): > > - Patch 1 and 2 can go through the USB repo. > > - Patch 3-9 can go through the chrome-platform repo. Since they depend > > on patches 1 and 2, we can create an "topic branch" off of usb-next > > once Patch 1 and 2 are submitted, and then apply Patches 3-9 on top > > of that "topic branch" before merging it back into chrome-platform's > > for-next branch > > That's a mess, I can just take all of them into my tree if you want. That works for me. Thanks for taking Patch 1 and 2; it should be fine to apply the rest of the patches to your tree too. Best regards,
On Thu, Jul 14, 2022 at 10:02:32AM -0700, Prashant Malani wrote: > Hi Greg, > > On Thu, Jul 14, 2022 at 7:15 AM Greg Kroah-Hartman > <gregkh@linuxfoundation.org> wrote: > > > > On Mon, Jul 11, 2022 at 07:22:54AM +0000, Prashant Malani wrote: > > > This series introduces a retimer class to the USB Type-C framework, > > > It also introduces a Chrome EC (Embedded Controller) switch driver which > > > registers the aforementioned retimer switches as well as mode-switches. > > > > > > Patch 1 and 2 introduce the retimer class and associated functions to > > > the Type-C common code. > > > > > > Patches 3-7 add the cros-typec-switch driver. > > > > > > Patches 8-9 update cros-ec-typec to get and use retimer switch handles. > > > > > > Submission suggestion (as always, open to better suggestions): > > > - Patch 1 and 2 can go through the USB repo. > > > - Patch 3-9 can go through the chrome-platform repo. Since they depend > > > on patches 1 and 2, we can create an "topic branch" off of usb-next > > > once Patch 1 and 2 are submitted, and then apply Patches 3-9 on top > > > of that "topic branch" before merging it back into chrome-platform's > > > for-next branch > > > > That's a mess, I can just take all of them into my tree if you want. > > That works for me. Thanks for taking Patch 1 and 2; it should be fine > to apply the rest of the patches to your tree too. Ok, now queued up. greg k-h
Hello: This series was applied to chrome-platform/linux.git (for-kernelci) by Greg Kroah-Hartman <gregkh@linuxfoundation.org>: On Mon, 11 Jul 2022 07:22:54 +0000 you wrote: > This series introduces a retimer class to the USB Type-C framework, > It also introduces a Chrome EC (Embedded Controller) switch driver which > registers the aforementioned retimer switches as well as mode-switches. > > Patch 1 and 2 introduce the retimer class and associated functions to > the Type-C common code. > > [...] Here is the summary with links: - [v4,1/9] usb: typec: Add support for retimers https://git.kernel.org/chrome-platform/c/ddaf8d96f93b - [v4,2/9] usb: typec: Add retimer handle to port https://git.kernel.org/chrome-platform/c/f31a8702cd36 - [v4,3/9] platform/chrome: Add Type-C mux set command definitions https://git.kernel.org/chrome-platform/c/28a6ed8e39f7 - [v4,4/9] platform/chrome: cros_typec_switch: Add switch driver https://git.kernel.org/chrome-platform/c/e54369058f3d - [v4,5/9] platform/chrome: cros_typec_switch: Set EC retimer https://git.kernel.org/chrome-platform/c/34f375f0fdf6 - [v4,6/9] platform/chrome: cros_typec_switch: Add event check https://git.kernel.org/chrome-platform/c/bb53ad958012 - [v4,7/9] platform/chrome: cros_typec_switch: Register mode switches https://git.kernel.org/chrome-platform/c/f5434e30011e - [v4,8/9] platform/chrome: cros_ec_typec: Cleanup switch handle return paths https://git.kernel.org/chrome-platform/c/66fe238a9bcc - [v4,9/9] platform/chrome: cros_ec_typec: Get retimer handle https://git.kernel.org/chrome-platform/c/c76d09da77d6 You are awesome, thank you!
Hello: This series was applied to chrome-platform/linux.git (for-next) by Greg Kroah-Hartman <gregkh@linuxfoundation.org>: On Mon, 11 Jul 2022 07:22:54 +0000 you wrote: > This series introduces a retimer class to the USB Type-C framework, > It also introduces a Chrome EC (Embedded Controller) switch driver which > registers the aforementioned retimer switches as well as mode-switches. > > Patch 1 and 2 introduce the retimer class and associated functions to > the Type-C common code. > > [...] Here is the summary with links: - [v4,1/9] usb: typec: Add support for retimers https://git.kernel.org/chrome-platform/c/ddaf8d96f93b - [v4,2/9] usb: typec: Add retimer handle to port https://git.kernel.org/chrome-platform/c/f31a8702cd36 - [v4,3/9] platform/chrome: Add Type-C mux set command definitions https://git.kernel.org/chrome-platform/c/28a6ed8e39f7 - [v4,4/9] platform/chrome: cros_typec_switch: Add switch driver https://git.kernel.org/chrome-platform/c/e54369058f3d - [v4,5/9] platform/chrome: cros_typec_switch: Set EC retimer https://git.kernel.org/chrome-platform/c/34f375f0fdf6 - [v4,6/9] platform/chrome: cros_typec_switch: Add event check https://git.kernel.org/chrome-platform/c/bb53ad958012 - [v4,7/9] platform/chrome: cros_typec_switch: Register mode switches https://git.kernel.org/chrome-platform/c/f5434e30011e - [v4,8/9] platform/chrome: cros_ec_typec: Cleanup switch handle return paths https://git.kernel.org/chrome-platform/c/66fe238a9bcc - [v4,9/9] platform/chrome: cros_ec_typec: Get retimer handle https://git.kernel.org/chrome-platform/c/c76d09da77d6 You are awesome, thank you!