Message ID | 20220609181106.3695103-1-pmalani@chromium.org |
---|---|
Headers | show |
Series | usb: typec: Introduce typec-switch binding | expand |
Il 09/06/22 20:09, Prashant Malani ha scritto: > There are some drivers that can use the Type C mux API, but don't have > to. Introduce CONFIG guards for the mux functions so that drivers can > include the header file and not run into compilation errors on systems > which don't have CONFIG_TYPEC enabled. When CONFIG_TYPEC is not enabled, > the Type C mux functions will be stub versions of the original calls. > > Reported-by: kernel test robot <lkp@intel.com> > Signed-off-by: Prashant Malani <pmalani@chromium.org> > --- > > Changes since v1: > - Added static inline to stub functions. > - Updated function signature of stub functions from "struct typec_mux" > to "struct typec_mux_dev" in accordance with updates from commit > 713fd49b430c ("usb: typec: mux: Introduce indirection") > > include/linux/usb/typec_mux.h | 38 +++++++++++++++++++++++++++++++++++ > 1 file changed, 38 insertions(+) > > diff --git a/include/linux/usb/typec_mux.h b/include/linux/usb/typec_mux.h > index ee57781dcf28..9eda6146fd26 100644 > --- a/include/linux/usb/typec_mux.h > +++ b/include/linux/usb/typec_mux.h > @@ -58,6 +58,8 @@ struct typec_mux_desc { > void *drvdata; > }; > > +#if IS_ENABLED(CONFIG_TYPEC) || IS_MODULE(CONFIG_TYPEC) IS_ENABLED(x) evaluates to 1 when (x == 'y' || x == 'm') IS_MODULE(x) evaluates to 1 when (x == 'm') ....this means that a IS_ENABLED(CONFIG_TYPEC) check is enough, and the latter is redundant. Regards, Angelo
Hi AngeloGioacchino, On Tue, Jun 14, 2022 at 4:15 PM AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> wrote: > > Il 09/06/22 20:09, Prashant Malani ha scritto: > > From: Pin-Yen Lin <treapking@chromium.org> > > > > Add the callback function when the driver receives state > > changes of the Type-C port. The callback function configures the > > crosspoint switch of the anx7625 bridge chip, which can change the > > output pins of the signals according to the port state. > > > > Signed-off-by: Pin-Yen Lin <treapking@chromium.org> > > Signed-off-by: Prashant Malani <pmalani@chromium.org> > > --- > > > > Changes since v2: > > - No changes. > > > > drivers/gpu/drm/bridge/analogix/anx7625.c | 58 +++++++++++++++++++++++ > > drivers/gpu/drm/bridge/analogix/anx7625.h | 13 +++++ > > 2 files changed, 71 insertions(+) > > > > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c > > index d41a21103bd3..2c308d12fab2 100644 > > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c > > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c > > @@ -15,6 +15,7 @@ > > #include <linux/regulator/consumer.h> > > #include <linux/slab.h> > > #include <linux/types.h> > > +#include <linux/usb/typec_dp.h> > > #include <linux/usb/typec_mux.h> > > #include <linux/workqueue.h> > > > > @@ -2582,9 +2583,66 @@ static void anx7625_runtime_disable(void *data) > > pm_runtime_disable(data); > > } > > > > +static void anx7625_set_crosspoint_switch(struct anx7625_data *ctx, > > + enum typec_orientation orientation) > > +{ > > + if (orientation == TYPEC_ORIENTATION_NORMAL) { > > + anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_0, > > + SW_SEL1_SSRX_RX1 | SW_SEL1_DPTX0_RX2); > > + anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_1, > > + SW_SEL2_SSTX_TX1 | SW_SEL2_DPTX1_TX2); > > + } else if (orientation == TYPEC_ORIENTATION_REVERSE) { > > + anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_0, > > + SW_SEL1_SSRX_RX2 | SW_SEL1_DPTX0_RX1); > > + anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_1, > > + SW_SEL2_SSTX_TX2 | SW_SEL2_DPTX1_TX1); > > + } > > +} > > + > > +static void anx7625_typec_two_ports_update(struct anx7625_data *ctx) > > +{ > > + if (ctx->typec_ports[0].dp_connected && ctx->typec_ports[1].dp_connected) > > + /* Both ports available, do nothing to retain the current one. */ > > + return; > > + else if (ctx->typec_ports[0].dp_connected) > > + anx7625_set_crosspoint_switch(ctx, TYPEC_ORIENTATION_NORMAL); > > + else if (ctx->typec_ports[1].dp_connected) > > + anx7625_set_crosspoint_switch(ctx, TYPEC_ORIENTATION_REVERSE); > > +} > > + > > static int anx7625_typec_mux_set(struct typec_mux_dev *mux, > > struct typec_mux_state *state) > > { > > + struct anx7625_port_data *data = typec_mux_get_drvdata(mux); > > + struct anx7625_data *ctx = data->ctx; > > + struct device *dev = &ctx->client->dev; > > + > > + bool old_dp_connected = (ctx->typec_ports[0].dp_connected || > > + ctx->typec_ports[1].dp_connected); > > So the old connection state is "either port0 or port1 are currently connected"... > > > + bool new_dp_connected; > > + > > + if (ctx->num_typec_switches == 1) > > + return 0; > > + > > + dev_dbg(dev, "mux_set dp_connected: c0=%d, c1=%d\n", > > + ctx->typec_ports[0].dp_connected, ctx->typec_ports[1].dp_connected); > > + > > + data->dp_connected = (state->alt && state->alt->svid == USB_TYPEC_DP_SID && > > + state->alt->mode == USB_TYPEC_DP_MODE); > > + > + new_dp_connected = (ctx->typec_ports[0].dp_connected || > > + ctx->typec_ports[1].dp_connected); > > ...and the new connection state is the same as the old one, because I don't see > anything that could ever modify it in this function's flow, until reaching this > assignment. The typec mux driver data (`struct anx7625_port_data *data = typec_mux_get_drvdata(mux)`) is set to one of the `ctx->typec_ports[*]` in `anx7625_register_mode_switch` (see patch 6 of this series). So, the `data->dp_connected = ...` assignment may change the new connection state. Best regards, Pin-yen > > > + > > + /* dp on, power on first */ > > + if (!old_dp_connected && new_dp_connected) > > + pm_runtime_get_sync(dev); > > ...so that will never happen... > > > + > > + anx7625_typec_two_ports_update(ctx); > > + > > + /* dp off, power off last */ > > + if (old_dp_connected && !new_dp_connected) > > + pm_runtime_put_sync(dev); > > ...and same here. > > Regards, > Angelo
On Tue, Jun 14, 2022 at 2:08 AM Pin-yen Lin <treapking@chromium.org> wrote: > > Hi AngeloGioacchino, > > > On Tue, Jun 14, 2022 at 4:15 PM AngeloGioacchino Del Regno > <angelogioacchino.delregno@collabora.com> wrote: > > > > Il 09/06/22 20:09, Prashant Malani ha scritto: > > > From: Pin-Yen Lin <treapking@chromium.org> > > > > > > Add the callback function when the driver receives state > > > changes of the Type-C port. The callback function configures the > > > crosspoint switch of the anx7625 bridge chip, which can change the > > > output pins of the signals according to the port state. > > > > > > Signed-off-by: Pin-Yen Lin <treapking@chromium.org> > > > Signed-off-by: Prashant Malani <pmalani@chromium.org> > > > --- > > > > > > Changes since v2: > > > - No changes. > > > > > > drivers/gpu/drm/bridge/analogix/anx7625.c | 58 +++++++++++++++++++++++ > > > drivers/gpu/drm/bridge/analogix/anx7625.h | 13 +++++ > > > 2 files changed, 71 insertions(+) > > > > > > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c > > > index d41a21103bd3..2c308d12fab2 100644 > > > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c > > > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c > > > @@ -15,6 +15,7 @@ > > > #include <linux/regulator/consumer.h> > > > #include <linux/slab.h> > > > #include <linux/types.h> > > > +#include <linux/usb/typec_dp.h> > > > #include <linux/usb/typec_mux.h> > > > #include <linux/workqueue.h> > > > > > > @@ -2582,9 +2583,66 @@ static void anx7625_runtime_disable(void *data) > > > pm_runtime_disable(data); > > > } > > > > > > +static void anx7625_set_crosspoint_switch(struct anx7625_data *ctx, > > > + enum typec_orientation orientation) > > > +{ > > > + if (orientation == TYPEC_ORIENTATION_NORMAL) { > > > + anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_0, > > > + SW_SEL1_SSRX_RX1 | SW_SEL1_DPTX0_RX2); > > > + anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_1, > > > + SW_SEL2_SSTX_TX1 | SW_SEL2_DPTX1_TX2); > > > + } else if (orientation == TYPEC_ORIENTATION_REVERSE) { > > > + anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_0, > > > + SW_SEL1_SSRX_RX2 | SW_SEL1_DPTX0_RX1); > > > + anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_1, > > > + SW_SEL2_SSTX_TX2 | SW_SEL2_DPTX1_TX1); > > > + } > > > +} > > > + > > > +static void anx7625_typec_two_ports_update(struct anx7625_data *ctx) > > > +{ > > > + if (ctx->typec_ports[0].dp_connected && ctx->typec_ports[1].dp_connected) > > > + /* Both ports available, do nothing to retain the current one. */ > > > + return; > > > + else if (ctx->typec_ports[0].dp_connected) > > > + anx7625_set_crosspoint_switch(ctx, TYPEC_ORIENTATION_NORMAL); > > > + else if (ctx->typec_ports[1].dp_connected) > > > + anx7625_set_crosspoint_switch(ctx, TYPEC_ORIENTATION_REVERSE); > > > +} > > > + > > > static int anx7625_typec_mux_set(struct typec_mux_dev *mux, > > > struct typec_mux_state *state) > > > { > > > + struct anx7625_port_data *data = typec_mux_get_drvdata(mux); > > > + struct anx7625_data *ctx = data->ctx; > > > + struct device *dev = &ctx->client->dev; > > > + > > > + bool old_dp_connected = (ctx->typec_ports[0].dp_connected || > > > + ctx->typec_ports[1].dp_connected); > > > > So the old connection state is "either port0 or port1 are currently connected"... > > > > > + bool new_dp_connected; > > > + > > > + if (ctx->num_typec_switches == 1) > > > + return 0; > > > + > > > + dev_dbg(dev, "mux_set dp_connected: c0=%d, c1=%d\n", > > > + ctx->typec_ports[0].dp_connected, ctx->typec_ports[1].dp_connected); > > > + > > > + data->dp_connected = (state->alt && state->alt->svid == USB_TYPEC_DP_SID && > > > + state->alt->mode == USB_TYPEC_DP_MODE); > > > + > + new_dp_connected = (ctx->typec_ports[0].dp_connected || > > > + ctx->typec_ports[1].dp_connected); > > > > ...and the new connection state is the same as the old one, because I don't see > > anything that could ever modify it in this function's flow, until reaching this > > assignment. > > The typec mux driver data (`struct anx7625_port_data *data = > typec_mux_get_drvdata(mux)`) is set to one of the > `ctx->typec_ports[*]` in `anx7625_register_mode_switch` (see patch 6 > of this series). > > So, the `data->dp_connected = ...` assignment may change the new > connection state. Angelo, I think your interpretation of this logic is not accurate.. |old_dp_connected| represents *whether* port1 or port0 has a DP partner connected, not that *either* of them has it. So, this logic looks OK to me. > > Best regards, > Pin-yen > > > > > > + > > > + /* dp on, power on first */ > > > + if (!old_dp_connected && new_dp_connected) > > > + pm_runtime_get_sync(dev); > > > > ...so that will never happen... > > > > > + > > > + anx7625_typec_two_ports_update(ctx); > > > + > > > + /* dp off, power off last */ > > > + if (old_dp_connected && !new_dp_connected) > > > + pm_runtime_put_sync(dev); > > > > ...and same here. > > > > Regards, > > Angelo
On Tue, Jun 14, 2022 at 1:22 AM AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> wrote: > > Il 09/06/22 20:09, Prashant Malani ha scritto: > > Parse the "switches" node, if available, and count and store the number > > of Type-C switches within it. Since we currently don't do anything with > > this info, no functional changes are expected from this change. > > > > This patch sets a foundation for the actual registering of Type-C > > switches with the Type-C connector class framework. > > > > Signed-off-by: Prashant Malani <pmalani@chromium.org> > > --- > > > > Changes since v1: > > - No changes. > > > > drivers/gpu/drm/bridge/analogix/anx7625.c | 20 ++++++++++++++++++++ > > drivers/gpu/drm/bridge/analogix/anx7625.h | 1 + > > 2 files changed, 21 insertions(+) > > > > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c > > index 53a5da6c49dd..07ed44c6b839 100644 > > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c > > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c > > @@ -2581,6 +2581,22 @@ static void anx7625_runtime_disable(void *data) > > pm_runtime_disable(data); > > } > > > > +static int anx7625_register_typec_switches(struct device *device, struct anx7625_data *ctx) > > +{ > > + struct device_node *of = NULL; > > + int ret = 0; > > + > > + of = of_get_child_by_name(device->of_node, "switches"); > > + if (!of) > > + return -ENODEV; > > + > > + ctx->num_typec_switches = of_get_child_count(of); > > + if (ctx->num_typec_switches <= 0) > > + return -ENODEV; > > + > > + return ret; > > You aren't using the `ret` variable for anything other than returning zero: > remove it and simply return 0 here. The very next patch does use it, but sure I'll remove it from here and introduce it in v6. > > > +} > > + > > static int anx7625_i2c_probe(struct i2c_client *client, > > const struct i2c_device_id *id) > > { > > @@ -2686,6 +2702,10 @@ static int anx7625_i2c_probe(struct i2c_client *client, > > if (platform->pdata.intp_irq) > > queue_work(platform->workqueue, &platform->work); > > > > + ret = anx7625_register_typec_switches(dev, platform); > > + if (ret) > > + dev_info(dev, "Didn't register Type C switches, err: %d\n", ret); > > Type-C switches are optional for this driver and this will print a sort of error > on boards that are *not* declaring any switches on purpose (because perhaps they > don't have any, or for any other reason). > > Even though this is a dev_info and not a dev_err, it's still printing an alarming > (and useless, in the aforementioned case) message. I'll go ahead and convert this to dev_warn, but only trigger if there is an error other than ENODEV. > > Please fix this. > > Regards, > Angelo >