diff mbox series

[2/9] usb: typec: Add retimer handle to port

Message ID 20220629233314.3540377-3-pmalani@chromium.org (mailing list archive)
State Superseded
Headers show
Series platform/chrome: Type-C switch driver and Type-C framework updates | expand

Commit Message

Prashant Malani June 29, 2022, 11:32 p.m. UTC
Similar to mux and orientation switch, add a handle for registered
retimer to the port, so that it has handles to the various switches
connected to it.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
---
 drivers/usb/typec/class.c | 8 ++++++++
 drivers/usb/typec/class.h | 1 +
 2 files changed, 9 insertions(+)

Comments

Heikki Krogerus June 30, 2022, 8:27 a.m. UTC | #1
Hi,

On Wed, Jun 29, 2022 at 11:32:20PM +0000, Prashant Malani wrote:
> Similar to mux and orientation switch, add a handle for registered
> retimer to the port, so that it has handles to the various switches
> connected to it.
> 
> Signed-off-by: Prashant Malani <pmalani@chromium.org>
> ---
>  drivers/usb/typec/class.c | 8 ++++++++
>  drivers/usb/typec/class.h | 1 +
>  2 files changed, 9 insertions(+)
> 
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 2fa0b3718d23..2bc5fbdb25dd 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -12,6 +12,7 @@
>  #include <linux/slab.h>
>  #include <linux/usb/pd_vdo.h>
>  #include <linux/usb/typec_mux.h>
> +#include <linux/usb/typec_retimer.h>
>  
>  #include "bus.h"
>  #include "class.h"
> @@ -2249,6 +2250,13 @@ struct typec_port *typec_register_port(struct device *parent,
>  		return ERR_PTR(ret);
>  	}
>  
> +	port->retimer = typec_retimer_get(&port->dev);
> +	if (IS_ERR(port->retimer)) {
> +		ret = PTR_ERR(port->retimer);
> +		put_device(&port->dev);
> +		return ERR_PTR(ret);
> +	}
> +
>  	ret = device_add(&port->dev);
>  	if (ret) {
>  		dev_err(parent, "failed to register port (%d)\n", ret);

I think you need to release the reference with typec_retimer_put() in
typec_release().

I guess we can look handle this later, but there can actually be two
onboard retimers for each connector.

thanks,

> diff --git a/drivers/usb/typec/class.h b/drivers/usb/typec/class.h
> index 1bb1da124109..97520406929e 100644
> --- a/drivers/usb/typec/class.h
> +++ b/drivers/usb/typec/class.h
> @@ -55,6 +55,7 @@ struct typec_port {
>  	enum typec_orientation		orientation;
>  	struct typec_switch		*sw;
>  	struct typec_mux		*mux;
> +	struct typec_retimer		*retimer;
>  
>  	const struct typec_capability	*cap;
>  	const struct typec_operations   *ops;
Prashant Malani June 30, 2022, 5:16 p.m. UTC | #2
HI Heikki,

On Thu, Jun 30, 2022 at 1:27 AM Heikki Krogerus
<heikki.krogerus@linux.intel.com> wrote:
>
> Hi,
>
> On Wed, Jun 29, 2022 at 11:32:20PM +0000, Prashant Malani wrote:
> > Similar to mux and orientation switch, add a handle for registered
> > retimer to the port, so that it has handles to the various switches
> > connected to it.
> >
> > Signed-off-by: Prashant Malani <pmalani@chromium.org>
> > ---
> >  drivers/usb/typec/class.c | 8 ++++++++
> >  drivers/usb/typec/class.h | 1 +
> >  2 files changed, 9 insertions(+)
> >
> > diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> > index 2fa0b3718d23..2bc5fbdb25dd 100644
> > --- a/drivers/usb/typec/class.c
> > +++ b/drivers/usb/typec/class.c
> > @@ -12,6 +12,7 @@
> >  #include <linux/slab.h>
> >  #include <linux/usb/pd_vdo.h>
> >  #include <linux/usb/typec_mux.h>
> > +#include <linux/usb/typec_retimer.h>
> >
> >  #include "bus.h"
> >  #include "class.h"
> > @@ -2249,6 +2250,13 @@ struct typec_port *typec_register_port(struct device *parent,
> >               return ERR_PTR(ret);
> >       }
> >
> > +     port->retimer = typec_retimer_get(&port->dev);
> > +     if (IS_ERR(port->retimer)) {
> > +             ret = PTR_ERR(port->retimer);
> > +             put_device(&port->dev);
> > +             return ERR_PTR(ret);
> > +     }
> > +
> >       ret = device_add(&port->dev);
> >       if (ret) {
> >               dev_err(parent, "failed to register port (%d)\n", ret);
>
> I think you need to release the reference with typec_retimer_put() in
> typec_release().

I knew I was forgetting something...
I'll fix this in v2.

>
> I guess we can look handle this later, but there can actually be two
> onboard retimers for each connector.

You're referring to the cascaded case right? OK, I'll bear this in mind for
later series (right now the EC exposes just 1 interface for retimer).

Thanks,

-Prashant
diff mbox series

Patch

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 2fa0b3718d23..2bc5fbdb25dd 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -12,6 +12,7 @@ 
 #include <linux/slab.h>
 #include <linux/usb/pd_vdo.h>
 #include <linux/usb/typec_mux.h>
+#include <linux/usb/typec_retimer.h>
 
 #include "bus.h"
 #include "class.h"
@@ -2249,6 +2250,13 @@  struct typec_port *typec_register_port(struct device *parent,
 		return ERR_PTR(ret);
 	}
 
+	port->retimer = typec_retimer_get(&port->dev);
+	if (IS_ERR(port->retimer)) {
+		ret = PTR_ERR(port->retimer);
+		put_device(&port->dev);
+		return ERR_PTR(ret);
+	}
+
 	ret = device_add(&port->dev);
 	if (ret) {
 		dev_err(parent, "failed to register port (%d)\n", ret);
diff --git a/drivers/usb/typec/class.h b/drivers/usb/typec/class.h
index 1bb1da124109..97520406929e 100644
--- a/drivers/usb/typec/class.h
+++ b/drivers/usb/typec/class.h
@@ -55,6 +55,7 @@  struct typec_port {
 	enum typec_orientation		orientation;
 	struct typec_switch		*sw;
 	struct typec_mux		*mux;
+	struct typec_retimer		*retimer;
 
 	const struct typec_capability	*cap;
 	const struct typec_operations   *ops;