Re: [PATCH v12 03/10] drm/display: Add Type-C switch helpers

Andy Shevchenko
2023-02-21T11:48:41Z

On Tue, Feb 21, 2023 at 05:50:47PM +0800, Pin-yen Lin wrote:
> Add helpers to register and unregister Type-C "switches" for bridges
> capable of switching their output between two downstream devices.
>
> The helper registers USB Type-C mode switches when the "mode-switch"
> and the "reg" properties are available in Device Tree.
>
> Signed-off-by: Pin-yen Lin <treapking@chromium.org>

...

> + fwnode_for_each_typec_mode_switch(port, sw)
> + switch_desc->num_typec_switches++;
> +
> + if (!switch_desc->num_typec_switches) {
> + dev_dbg(dev, "No Type-C switches node found\n");
> + return 0;
> + }

What about

static inline unsigned int typec_mode_switch_node_count(... *port)
{
... *sw;
unsigned int count = 0;

for_each_typec_mode_switch_node(port, sw)
count++;

return count;
}

And then it seems something like

unsigned int count;

count = typec_mode_switch_node_count(port);
if (!count) {
...
}

_switches = count;

...

> + switch_desc->typec_ports = devm_kcalloc(
> + dev, switch_desc->num_typec_switches,

Strange indentation.

> + sizeof(struct drm_dp_typec_port_data), GFP_KERNEL);

> +

Redundant blank line.

> + if (!switch_desc->typec_ports)
> + return -ENOMEM;

...

> +void drm_dp_unregister_typec_switches(struct drm_dp_typec_switch_desc *switch_desc)
> +{
> + int i;

unsigned?

> + for (i = 0; i < switch_desc->num_typec_switches; i++)
> + typec_mux_unregister(switch_desc->typec_ports[i].typec_mux);
> +}

...

> #include <linux/delay.h>
> #include <linux/i2c.h>
> +#include <linux/usb/typec_mux.h>

I don't see users of this.
But a few forward declarations are missing.

> #include <drm/display/drm_dp.h>
> #include <drm/drm_connector.h>

...

> +#define fwnode_for_each_typec_mode_switch(port, sw) \
> + fwnode_for_each_child_node((port), (sw)) \
> + for_each_if(fwnode_property_present((sw), "mode-switch"))

Please don't use fwnode namespace (see above), something like

#define for_each_typec_mode_switch_node(port, sw) \
...

--
With Best Regards,
Andy Shevchenko