2023-01-23 09:36:49

by Victor Ding

[permalink] [raw]
Subject: [PATCH] platform/chrome: cros_ec_typec: allow deferred probe of switch handles

`fwnode_typec_{retimer,mux,switch}_get()` could return `-EPROBE_DEFER`,
which is called from `cros_typec_get_switch_handles`. When this happens,
it does not indicate absence of switches; instead, it only hints that
probing of switches should occur at a later time.

Progagate `-EPROBE_DEFER` to upper layer logic so that they can re-try
probing switches as a better time.

Signed-off-by: Victor Ding <[email protected]>
---

drivers/platform/chrome/cros_ec_typec.c | 30 +++++++++++++++++--------
1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 59de4ce01fab..f4b3fc788491 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -145,31 +145,37 @@ static int cros_typec_get_switch_handles(struct cros_typec_port *port,
struct fwnode_handle *fwnode,
struct device *dev)
{
+ int ret = 0;
+
port->mux = fwnode_typec_mux_get(fwnode, NULL);
if (IS_ERR(port->mux)) {
- dev_dbg(dev, "Mux handle not found.\n");
+ ret = PTR_ERR(port->mux);
+ dev_dbg(dev, "Mux handle not found: %d.\n", ret);
goto mux_err;
}

port->retimer = fwnode_typec_retimer_get(fwnode);
if (IS_ERR(port->retimer)) {
- dev_dbg(dev, "Retimer handle not found.\n");
+ ret = PTR_ERR(port->retimer);
+ dev_dbg(dev, "Retimer handle not found: %d.\n", ret);
goto retimer_sw_err;
}

port->ori_sw = fwnode_typec_switch_get(fwnode);
if (IS_ERR(port->ori_sw)) {
- dev_dbg(dev, "Orientation switch handle not found.\n");
+ ret = PTR_ERR(port->ori_sw);
+ dev_dbg(dev, "Orientation switch handle not found: %d\n", ret);
goto ori_sw_err;
}

port->role_sw = fwnode_usb_role_switch_get(fwnode);
if (IS_ERR(port->role_sw)) {
- dev_dbg(dev, "USB role switch handle not found.\n");
+ ret = PTR_ERR(port->role_sw);
+ dev_dbg(dev, "USB role switch handle not found: %d\n", ret);
goto role_sw_err;
}

- return 0;
+ return ret;

role_sw_err:
typec_switch_put(port->ori_sw);
@@ -181,7 +187,7 @@ static int cros_typec_get_switch_handles(struct cros_typec_port *port,
typec_mux_put(port->mux);
port->mux = NULL;
mux_err:
- return -ENODEV;
+ return ret;
}

static int cros_typec_add_partner(struct cros_typec_data *typec, int port_num,
@@ -423,9 +429,15 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
}

ret = cros_typec_get_switch_handles(cros_port, fwnode, dev);
- if (ret)
- dev_dbg(dev, "No switch control for port %d\n",
- port_num);
+ switch (ret) {
+ case 0:
+ break;
+ case -EPROBE_DEFER:
+ dev_err(dev, "Deferring getting switch handles at port %d\n", port_num);
+ goto unregister_ports;
+ default:
+ dev_dbg(dev, "No switch control for port %d, err: %d\n", port_num, ret);
+ }

ret = cros_typec_register_port_altmodes(typec, port_num);
if (ret) {
--
2.39.0.246.g2a6d74b583-goog



2023-01-23 16:00:48

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH] platform/chrome: cros_ec_typec: allow deferred probe of switch handles

On Mon, Jan 23, 2023 at 1:36 AM Victor Ding <[email protected]> wrote:
>
> `fwnode_typec_{retimer,mux,switch}_get()` could return `-EPROBE_DEFER`,
> which is called from `cros_typec_get_switch_handles`. When this happens,
> it does not indicate absence of switches; instead, it only hints that
> probing of switches should occur at a later time.
>
> Progagate `-EPROBE_DEFER` to upper layer logic so that they can re-try
> probing switches as a better time.
>
> Signed-off-by: Victor Ding <[email protected]>
> ---
>
> drivers/platform/chrome/cros_ec_typec.c | 30 +++++++++++++++++--------
> 1 file changed, 21 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 59de4ce01fab..f4b3fc788491 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -145,31 +145,37 @@ static int cros_typec_get_switch_handles(struct cros_typec_port *port,
> struct fwnode_handle *fwnode,
> struct device *dev)
> {
> + int ret = 0;
> +
> port->mux = fwnode_typec_mux_get(fwnode, NULL);
> if (IS_ERR(port->mux)) {
> - dev_dbg(dev, "Mux handle not found.\n");
> + ret = PTR_ERR(port->mux);
> + dev_dbg(dev, "Mux handle not found: %d.\n", ret);

All of those should call dev_err_probe().

> goto mux_err;

and this can return directly.

> }
>
> port->retimer = fwnode_typec_retimer_get(fwnode);
> if (IS_ERR(port->retimer)) {
> - dev_dbg(dev, "Retimer handle not found.\n");
> + ret = PTR_ERR(port->retimer);
> + dev_dbg(dev, "Retimer handle not found: %d.\n", ret);
> goto retimer_sw_err;
> }
>
> port->ori_sw = fwnode_typec_switch_get(fwnode);
> if (IS_ERR(port->ori_sw)) {
> - dev_dbg(dev, "Orientation switch handle not found.\n");
> + ret = PTR_ERR(port->ori_sw);
> + dev_dbg(dev, "Orientation switch handle not found: %d\n", ret);
> goto ori_sw_err;
> }
>
> port->role_sw = fwnode_usb_role_switch_get(fwnode);
> if (IS_ERR(port->role_sw)) {
> - dev_dbg(dev, "USB role switch handle not found.\n");
> + ret = PTR_ERR(port->role_sw);
> + dev_dbg(dev, "USB role switch handle not found: %d\n", ret);
> goto role_sw_err;
> }
>
> - return 0;
> + return ret;
>
> role_sw_err:
> typec_switch_put(port->ori_sw);
> @@ -181,7 +187,7 @@ static int cros_typec_get_switch_handles(struct cros_typec_port *port,
> typec_mux_put(port->mux);
> port->mux = NULL;
> mux_err:
> - return -ENODEV;
> + return ret;
> }
>
> static int cros_typec_add_partner(struct cros_typec_data *typec, int port_num,
> @@ -423,9 +429,15 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
> }
>
> ret = cros_typec_get_switch_handles(cros_port, fwnode, dev);
> - if (ret)
> - dev_dbg(dev, "No switch control for port %d\n",
> - port_num);
> + switch (ret) {
> + case 0:
> + break;
> + case -EPROBE_DEFER:
> + dev_err(dev, "Deferring getting switch handles at port %d\n", port_num);
> + goto unregister_ports;
> + default:
> + dev_dbg(dev, "No switch control for port %d, err: %d\n", port_num, ret);
> + }
>
> ret = cros_typec_register_port_altmodes(typec, port_num);
> if (ret) {
> --
> 2.39.0.246.g2a6d74b583-goog
>

2023-01-24 00:43:40

by Prashant Malani

[permalink] [raw]
Subject: Re: [PATCH] platform/chrome: cros_ec_typec: allow deferred probe of switch handles

On Mon, Jan 23, 2023 at 1:36 AM Victor Ding <[email protected]> wrote:
>
> `fwnode_typec_{retimer,mux,switch}_get()` could return `-EPROBE_DEFER`,
> which is called from `cros_typec_get_switch_handles`. When this happens,
> it does not indicate absence of switches; instead, it only hints that
> probing of switches should occur at a later time.
>
> Progagate `-EPROBE_DEFER` to upper layer logic so that they can re-try
> probing switches as a better time.
>
> Signed-off-by: Victor Ding <[email protected]>
> ---
>
> drivers/platform/chrome/cros_ec_typec.c | 30 +++++++++++++++++--------
> 1 file changed, 21 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 59de4ce01fab..f4b3fc788491 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -145,31 +145,37 @@ static int cros_typec_get_switch_handles(struct cros_typec_port *port,
> struct fwnode_handle *fwnode,
> struct device *dev)
> {
> + int ret = 0;
> +
> port->mux = fwnode_typec_mux_get(fwnode, NULL);
> if (IS_ERR(port->mux)) {
> - dev_dbg(dev, "Mux handle not found.\n");
> + ret = PTR_ERR(port->mux);
> + dev_dbg(dev, "Mux handle not found: %d.\n", ret);
> goto mux_err;
> }
>
> port->retimer = fwnode_typec_retimer_get(fwnode);
> if (IS_ERR(port->retimer)) {
> - dev_dbg(dev, "Retimer handle not found.\n");
> + ret = PTR_ERR(port->retimer);
> + dev_dbg(dev, "Retimer handle not found: %d.\n", ret);
> goto retimer_sw_err;
> }
>
> port->ori_sw = fwnode_typec_switch_get(fwnode);
> if (IS_ERR(port->ori_sw)) {
> - dev_dbg(dev, "Orientation switch handle not found.\n");
> + ret = PTR_ERR(port->ori_sw);
> + dev_dbg(dev, "Orientation switch handle not found: %d\n", ret);
> goto ori_sw_err;
> }
>
> port->role_sw = fwnode_usb_role_switch_get(fwnode);
> if (IS_ERR(port->role_sw)) {
> - dev_dbg(dev, "USB role switch handle not found.\n");
> + ret = PTR_ERR(port->role_sw);
> + dev_dbg(dev, "USB role switch handle not found: %d\n", ret);
> goto role_sw_err;
> }
>
> - return 0;
> + return ret;
>
> role_sw_err:
> typec_switch_put(port->ori_sw);
> @@ -181,7 +187,7 @@ static int cros_typec_get_switch_handles(struct cros_typec_port *port,
> typec_mux_put(port->mux);
> port->mux = NULL;
> mux_err:
> - return -ENODEV;
> + return ret;
> }
>
> static int cros_typec_add_partner(struct cros_typec_data *typec, int port_num,
> @@ -423,9 +429,15 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
> }
>
> ret = cros_typec_get_switch_handles(cros_port, fwnode, dev);
> - if (ret)
> - dev_dbg(dev, "No switch control for port %d\n",
> - port_num);
> + switch (ret) {
> + case 0:
> + break;
> + case -EPROBE_DEFER:
> + dev_err(dev, "Deferring getting switch handles at port %d\n", port_num);
> + goto unregister_ports;
> + default:
> + dev_dbg(dev, "No switch control for port %d, err: %d\n", port_num, ret);
> + }

The switch statement seems a little clunky here. Instead, nest a couple
of ifs; it is shorter and easier to read IMO.

ret = cros_typec_get_switch_handles(cros_port, fwnode, dev);
if (ret) {
dev_err_probe(dev, ret, "No switch control for port: %d\n", port_num);
if (ret == -EPROBE_DEFER)
goto unregister_ports;
}

}
}
>
> ret = cros_typec_register_port_altmodes(typec, port_num);
> if (ret) {
> --
> 2.39.0.246.g2a6d74b583-goog
>

2023-01-24 03:18:46

by Victor Ding

[permalink] [raw]
Subject: Re: [PATCH] platform/chrome: cros_ec_typec: allow deferred probe of switch handles

On Tue, Jan 24, 2023 at 11:43 AM Prashant Malani <[email protected]> wrote:
>
> On Mon, Jan 23, 2023 at 1:36 AM Victor Ding <[email protected]> wrote:
> >
> > `fwnode_typec_{retimer,mux,switch}_get()` could return `-EPROBE_DEFER`,
> > which is called from `cros_typec_get_switch_handles`. When this happens,
> > it does not indicate absence of switches; instead, it only hints that
> > probing of switches should occur at a later time.
> >
> > Progagate `-EPROBE_DEFER` to upper layer logic so that they can re-try
> > probing switches as a better time.
> >
> > Signed-off-by: Victor Ding <[email protected]>
> > ---
> >
> > drivers/platform/chrome/cros_ec_typec.c | 30 +++++++++++++++++--------
> > 1 file changed, 21 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> > index 59de4ce01fab..f4b3fc788491 100644
> > --- a/drivers/platform/chrome/cros_ec_typec.c
> > +++ b/drivers/platform/chrome/cros_ec_typec.c
> > @@ -145,31 +145,37 @@ static int cros_typec_get_switch_handles(struct cros_typec_port *port,
> > struct fwnode_handle *fwnode,
> > struct device *dev)
> > {
> > + int ret = 0;
> > +
> > port->mux = fwnode_typec_mux_get(fwnode, NULL);
> > if (IS_ERR(port->mux)) {
> > - dev_dbg(dev, "Mux handle not found.\n");
> > + ret = PTR_ERR(port->mux);
> > + dev_dbg(dev, "Mux handle not found: %d.\n", ret);
> > goto mux_err;
> > }
> >
> > port->retimer = fwnode_typec_retimer_get(fwnode);
> > if (IS_ERR(port->retimer)) {
> > - dev_dbg(dev, "Retimer handle not found.\n");
> > + ret = PTR_ERR(port->retimer);
> > + dev_dbg(dev, "Retimer handle not found: %d.\n", ret);
> > goto retimer_sw_err;
> > }
> >
> > port->ori_sw = fwnode_typec_switch_get(fwnode);
> > if (IS_ERR(port->ori_sw)) {
> > - dev_dbg(dev, "Orientation switch handle not found.\n");
> > + ret = PTR_ERR(port->ori_sw);
> > + dev_dbg(dev, "Orientation switch handle not found: %d\n", ret);
> > goto ori_sw_err;
> > }
> >
> > port->role_sw = fwnode_usb_role_switch_get(fwnode);
> > if (IS_ERR(port->role_sw)) {
> > - dev_dbg(dev, "USB role switch handle not found.\n");
> > + ret = PTR_ERR(port->role_sw);
> > + dev_dbg(dev, "USB role switch handle not found: %d\n", ret);
> > goto role_sw_err;
> > }
> >
> > - return 0;
> > + return ret;
> >
> > role_sw_err:
> > typec_switch_put(port->ori_sw);
> > @@ -181,7 +187,7 @@ static int cros_typec_get_switch_handles(struct cros_typec_port *port,
> > typec_mux_put(port->mux);
> > port->mux = NULL;
> > mux_err:
> > - return -ENODEV;
> > + return ret;
> > }
> >
> > static int cros_typec_add_partner(struct cros_typec_data *typec, int port_num,
> > @@ -423,9 +429,15 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
> > }
> >
> > ret = cros_typec_get_switch_handles(cros_port, fwnode, dev);
> > - if (ret)
> > - dev_dbg(dev, "No switch control for port %d\n",
> > - port_num);
> > + switch (ret) {
> > + case 0:
> > + break;
> > + case -EPROBE_DEFER:
> > + dev_err(dev, "Deferring getting switch handles at port %d\n", port_num);
> > + goto unregister_ports;
> > + default:
> > + dev_dbg(dev, "No switch control for port %d, err: %d\n", port_num, ret);
> > + }
>
> The switch statement seems a little clunky here. Instead, nest a couple
> of ifs; it is shorter and easier to read IMO.
>
> ret = cros_typec_get_switch_handles(cros_port, fwnode, dev);
> if (ret) {
> dev_err_probe(dev, ret, "No switch control for port: %d\n", port_num);
> if (ret == -EPROBE_DEFER)
> goto unregister_ports;
> }
>
Good idea, I'll update accordingly in the next revision.
> }
> }
> >
> > ret = cros_typec_register_port_altmodes(typec, port_num);
> > if (ret) {
> > --
> > 2.39.0.246.g2a6d74b583-goog
> >