Hi
> -----Original Message-----
> From: Heikki Krogerus [mailto:heikki.kroge...@linux.intel.com]
> Sent: 2018年3月15日 19:43
> To: Jun Li <jun...@nxp.com>
> Cc: robh...@kernel.org; mark.rutl...@arm.com;
> gre...@linuxfoundation.org; a.ha...@samsung.com; li...@roeck-us.net;
> yue...@google.com; shufan_...@richtek.com; o_leve...@orange.fr;
> linux-usb@vger.kernel.org; dl-linux-imx <linux-...@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...@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

Reply via email to