linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [v3,06/12] staging: typec: tcpci: support port config passed via dt
@ 2018-03-13  9:34 Jun Li
  0 siblings, 0 replies; 3+ messages in thread
From: Jun Li @ 2018-03-13  9:34 UTC (permalink / raw)
  To: robh+dt, mark.rutland, gregkh, heikki.krogerus
  Cc: a.hajda, jun.li, linux, yueyao, shufan_lee, o_leveque, linux-usb,
	linux-imx

User can define the typec port properties in tcpci node to setup
the port config.

Signed-off-by: Li Jun <jun.li@nxp.com>
---
 drivers/staging/typec/tcpci.c | 63 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
index 24ad44f..ba4627f 100644
--- a/drivers/staging/typec/tcpci.c
+++ b/drivers/staging/typec/tcpci.c
@@ -466,6 +466,9 @@ static const struct regmap_config tcpci_regmap_config = {
 
 static int tcpci_parse_config(struct tcpci *tcpci)
 {
+	struct tcpc_config *tcfg;
+	int ret = -EINVAL;
+
 	tcpci->controls_vbus = true; /* XXX */
 
 	tcpci->tcpc.fwnode = device_get_named_child_node(tcpci->dev,
@@ -475,6 +478,66 @@ static int tcpci_parse_config(struct tcpci *tcpci)
 		return -EINVAL;
 	}
 
+	tcpci->tcpc.config = devm_kzalloc(tcpci->dev, sizeof(*tcfg),
+					  GFP_KERNEL);
+	if (!tcpci->tcpc.config)
+		return -ENOMEM;
+
+	tcfg = tcpci->tcpc.config;
+
+	/* USB data support is optional */
+	ret = typec_get_data_type(tcpci->tcpc.fwnode);
+	if (ret < 0)
+		dev_dbg(tcpci->dev, "USB data is not supported.\n");
+	else
+		tcfg->data = ret;
+
+	/* Get port power type */
+	ret = typec_get_power_type(tcpci->tcpc.fwnode);
+	if (ret < 0) {
+		dev_err(tcpci->dev, "failed to get correct port type.\n");
+		return ret;
+	}
+	tcfg->type = ret;
+
+	if (tcfg->type == TYPEC_PORT_SNK)
+		goto sink;
+
+	tcfg->src_pdo = devm_kcalloc(tcpci->dev, PDO_MAX_OBJECTS,
+				     sizeof(*tcfg->src_pdo), GFP_KERNEL);
+	if (!tcfg->src_pdo)
+		return -ENOMEM;
+
+	/* Get source capability */
+	ret = tcpm_get_src_config(tcpci->tcpc.fwnode, tcfg);
+	if (ret < 0) {
+		dev_err(tcpci->dev, "failed to get source pdo %d\n", ret);
+		return -EINVAL;
+	}
+
+	if (tcfg->type == TYPEC_PORT_SRC)
+		return 0;
+
+	/* Get the preferred power role for DRP */
+	ret = typec_get_preferred_role(tcpci->tcpc.fwnode);
+	if (ret < 0) {
+		dev_err(tcpci->dev, "failed to get correct preferred role.\n");
+		return ret;
+	}
+	tcfg->default_role = ret;
+sink:
+	tcfg->snk_pdo = devm_kcalloc(tcpci->dev, PDO_MAX_OBJECTS,
+				     sizeof(*tcfg->snk_pdo), GFP_KERNEL);
+	if (!tcfg->snk_pdo)
+		return -ENOMEM;
+
+	/* Get power sink config */
+	ret = tcpm_get_snk_config(tcpci->tcpc.fwnode, tcfg);
+	if (ret < 0) {
+		dev_err(tcpci->dev, "failed to get sink configs %d\n", ret);
+		return -EINVAL;
+	}
+
 	return 0;
 }
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread
* [v3,06/12] staging: typec: tcpci: support port config passed via dt
@ 2018-03-15 11:43 Heikki Krogerus
  0 siblings, 0 replies; 3+ messages in thread
From: Heikki Krogerus @ 2018-03-15 11:43 UTC (permalink / raw)
  To: Li Jun
  Cc: robh+dt, mark.rutland, gregkh, a.hajda, linux, yueyao, shufan_lee,
	o_leveque, linux-usb, linux-imx

On Tue, Mar 13, 2018 at 05:34:32PM +0800, Li Jun wrote:
> User can define the typec port properties in tcpci node to setup
> the port config.
> 
> Signed-off-by: Li Jun <jun.li@nxp.com>
> ---
>  drivers/staging/typec/tcpci.c | 63 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 63 insertions(+)
> 
> diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c
> index 24ad44f..ba4627f 100644
> --- a/drivers/staging/typec/tcpci.c
> +++ b/drivers/staging/typec/tcpci.c
> @@ -466,6 +466,9 @@ static const struct regmap_config tcpci_regmap_config = {
>  
>  static int tcpci_parse_config(struct tcpci *tcpci)
>  {
> +	struct tcpc_config *tcfg;
> +	int ret = -EINVAL;
> +
>  	tcpci->controls_vbus = true; /* XXX */
>  
>  	tcpci->tcpc.fwnode = device_get_named_child_node(tcpci->dev,
> @@ -475,6 +478,66 @@ static int tcpci_parse_config(struct tcpci *tcpci)
>  		return -EINVAL;
>  	}
>  
> +	tcpci->tcpc.config = devm_kzalloc(tcpci->dev, sizeof(*tcfg),
> +					  GFP_KERNEL);
> +	if (!tcpci->tcpc.config)
> +		return -ENOMEM;
> +
> +	tcfg = tcpci->tcpc.config;
> +
> +	/* USB data support is optional */
> +	ret = typec_get_data_type(tcpci->tcpc.fwnode);
> +	if (ret < 0)
> +		dev_dbg(tcpci->dev, "USB data is not supported.\n");
> +	else
> +		tcfg->data = ret;
> +
> +	/* Get port power type */
> +	ret = typec_get_power_type(tcpci->tcpc.fwnode);
> +	if (ret < 0) {
> +		dev_err(tcpci->dev, "failed to get correct port type.\n");
> +		return ret;
> +	}
> +	tcfg->type = ret;
> +
> +	if (tcfg->type == TYPEC_PORT_SNK)
> +		goto sink;
> +
> +	tcfg->src_pdo = devm_kcalloc(tcpci->dev, PDO_MAX_OBJECTS,
> +				     sizeof(*tcfg->src_pdo), GFP_KERNEL);
> +	if (!tcfg->src_pdo)
> +		return -ENOMEM;
> +
> +	/* Get source capability */
> +	ret = tcpm_get_src_config(tcpci->tcpc.fwnode, tcfg);
> +	if (ret < 0) {
> +		dev_err(tcpci->dev, "failed to get source pdo %d\n", ret);
> +		return -EINVAL;
> +	}
> +
> +	if (tcfg->type == TYPEC_PORT_SRC)
> +		return 0;
> +
> +	/* Get the preferred power role for DRP */
> +	ret = typec_get_preferred_role(tcpci->tcpc.fwnode);
> +	if (ret < 0) {
> +		dev_err(tcpci->dev, "failed to get correct preferred role.\n");
> +		return ret;
> +	}
> +	tcfg->default_role = ret;
> +sink:
> +	tcfg->snk_pdo = devm_kcalloc(tcpci->dev, PDO_MAX_OBJECTS,
> +				     sizeof(*tcfg->snk_pdo), GFP_KERNEL);
> +	if (!tcfg->snk_pdo)
> +		return -ENOMEM;
> +
> +	/* Get power sink config */
> +	ret = tcpm_get_snk_config(tcpci->tcpc.fwnode, tcfg);
> +	if (ret < 0) {
> +		dev_err(tcpci->dev, "failed to get sink configs %d\n", ret);
> +		return -EINVAL;
> +	}
> +
>  	return 0;
>  }

I think everything here can be done in tcpm.c.

Since you are checking some device properties in tcpm.c in any case
(in tcpm_get_snk_config() and tcpm_get_src_config()), you might as
well check all these there as well.


Br,

^ permalink raw reply	[flat|nested] 3+ messages in thread
* [v3,06/12] staging: typec: tcpci: support port config passed via dt
@ 2018-03-20  2:10 Jun Li
  0 siblings, 0 replies; 3+ messages in thread
From: Jun Li @ 2018-03-20  2:10 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: robh+dt@kernel.org, mark.rutland@arm.com,
	gregkh@linuxfoundation.org, a.hajda@samsung.com,
	linux@roeck-us.net, yueyao@google.com, shufan_lee@richtek.com,
	o_leveque@orange.fr, linux-usb@vger.kernel.org, dl-linux-imx

Hi
> -----Original Message-----
> From: Heikki Krogerus [mailto:heikki.krogerus@linux.intel.com]
> Sent: 2018年3月15日 19:43
> To: Jun Li <jun.li@nxp.com>
> Cc: robh+dt@kernel.org; mark.rutland@arm.com;
> gregkh@linuxfoundation.org; a.hajda@samsung.com; linux@roeck-us.net;
> yueyao@google.com; shufan_lee@richtek.com; o_leveque@orange.fr;
> linux-usb@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>
> Subject: Re: [PATCH v3 06/12] staging: typec: tcpci: support port config passed
> via dt
> 
> On Tue, Mar 13, 2018 at 05:34:32PM +0800, Li Jun wrote:
> > User can define the typec port properties in tcpci node to setup the
> > port config.
> >
> > Signed-off-by: Li Jun <jun.li@nxp.com>
> > ---
> >  drivers/staging/typec/tcpci.c | 63
> > +++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 63 insertions(+)
> >
> > diff --git a/drivers/staging/typec/tcpci.c
> > b/drivers/staging/typec/tcpci.c index 24ad44f..ba4627f 100644
> > --- a/drivers/staging/typec/tcpci.c
> > +++ b/drivers/staging/typec/tcpci.c
> > @@ -466,6 +466,9 @@ static const struct regmap_config
> > tcpci_regmap_config = {
> >
> >  static int tcpci_parse_config(struct tcpci *tcpci)  {
> > +	struct tcpc_config *tcfg;
> > +	int ret = -EINVAL;
> > +
> >  	tcpci->controls_vbus = true; /* XXX */
> >
> >  	tcpci->tcpc.fwnode = device_get_named_child_node(tcpci->dev,
> > @@ -475,6 +478,66 @@ static int tcpci_parse_config(struct tcpci *tcpci)
> >  		return -EINVAL;
> >  	}
> >
> > +	tcpci->tcpc.config = devm_kzalloc(tcpci->dev, sizeof(*tcfg),
> > +					  GFP_KERNEL);
> > +	if (!tcpci->tcpc.config)
> > +		return -ENOMEM;
> > +
> > +	tcfg = tcpci->tcpc.config;
> > +
> > +	/* USB data support is optional */
> > +	ret = typec_get_data_type(tcpci->tcpc.fwnode);
> > +	if (ret < 0)
> > +		dev_dbg(tcpci->dev, "USB data is not supported.\n");
> > +	else
> > +		tcfg->data = ret;
> > +
> > +	/* Get port power type */
> > +	ret = typec_get_power_type(tcpci->tcpc.fwnode);
> > +	if (ret < 0) {
> > +		dev_err(tcpci->dev, "failed to get correct port type.\n");
> > +		return ret;
> > +	}
> > +	tcfg->type = ret;
> > +
> > +	if (tcfg->type == TYPEC_PORT_SNK)
> > +		goto sink;
> > +
> > +	tcfg->src_pdo = devm_kcalloc(tcpci->dev, PDO_MAX_OBJECTS,
> > +				     sizeof(*tcfg->src_pdo), GFP_KERNEL);
> > +	if (!tcfg->src_pdo)
> > +		return -ENOMEM;
> > +
> > +	/* Get source capability */
> > +	ret = tcpm_get_src_config(tcpci->tcpc.fwnode, tcfg);
> > +	if (ret < 0) {
> > +		dev_err(tcpci->dev, "failed to get source pdo %d\n", ret);
> > +		return -EINVAL;
> > +	}
> > +
> > +	if (tcfg->type == TYPEC_PORT_SRC)
> > +		return 0;
> > +
> > +	/* Get the preferred power role for DRP */
> > +	ret = typec_get_preferred_role(tcpci->tcpc.fwnode);
> > +	if (ret < 0) {
> > +		dev_err(tcpci->dev, "failed to get correct preferred role.\n");
> > +		return ret;
> > +	}
> > +	tcfg->default_role = ret;
> > +sink:
> > +	tcfg->snk_pdo = devm_kcalloc(tcpci->dev, PDO_MAX_OBJECTS,
> > +				     sizeof(*tcfg->snk_pdo), GFP_KERNEL);
> > +	if (!tcfg->snk_pdo)
> > +		return -ENOMEM;
> > +
> > +	/* Get power sink config */
> > +	ret = tcpm_get_snk_config(tcpci->tcpc.fwnode, tcfg);
> > +	if (ret < 0) {
> > +		dev_err(tcpci->dev, "failed to get sink configs %d\n", ret);
> > +		return -EINVAL;
> > +	}
> > +
> >  	return 0;
> >  }
> 
> I think everything here can be done in tcpm.c.
> 
> Since you are checking some device properties in tcpm.c in any case (in
> tcpm_get_snk_config() and tcpm_get_src_config()), you might as well check all
> these there as well.

Agreed, I will move those properties read to tcpm, then it can be called/checked
by tcpm_register_port().

> 
> 
> Br,
> 
> --
> heikki

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-03-20  2:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-13  9:34 [v3,06/12] staging: typec: tcpci: support port config passed via dt Jun Li
  -- strict thread matches above, loose matches on Subject: below --
2018-03-15 11:43 Heikki Krogerus
2018-03-20  2:10 Jun Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).