<div dir="ltr"><div dir="ltr">Hi Andi,<div><br></div><div>Thanks for the review.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Feb 8, 2023 at 5:25 AM Andi Shyti <<a href="mailto:andi.shyti@linux.intel.com">andi.shyti@linux.intel.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Pin-yen,<br>
<br>
[...]<br>
<br>
> +static int drm_dp_register_mode_switch(struct device *dev,<br>
> + struct fwnode_handle *fwnode,<br>
> + struct drm_dp_typec_switch_desc *switch_desc,<br>
> + void *data, typec_mux_set_fn_t mux_set)<br>
> +{<br>
> + struct drm_dp_typec_port_data *port_data;<br>
> + struct typec_mux_desc mux_desc = {};<br>
> + char name[32];<br>
> + u32 port_num;<br>
> + int ret;<br>
> +<br>
> + ret = fwnode_property_read_u32(fwnode, "reg", &port_num);<br>
> + if (ret) {<br>
> + dev_err(dev, "Failed to read reg property: %d\n", ret);<br>
> + return ret;<br>
> + }<br>
> +<br>
> + port_data = &switch_desc->typec_ports[port_num];<br>
> + port_data->data = data;<br>
> + port_data->port_num = port_num;<br>
> + port_data->fwnode = fwnode;<br>
> + mux_desc.fwnode = fwnode;<br>
> + mux_desc.drvdata = port_data;<br>
> + snprintf(name, sizeof(name), "%pfwP-%u", fwnode, port_num);<br>
> + <a href="http://mux_desc.name" rel="noreferrer" target="_blank">mux_desc.name</a> = name;<br>
> + mux_desc.set = mux_set;<br>
> +<br>
> + port_data->typec_mux = typec_mux_register(dev, &mux_desc);<br>
> + if (IS_ERR(port_data->typec_mux)) {<br>
> + ret = PTR_ERR(port_data->typec_mux);<br>
> + dev_err(dev, "Mode switch register for port %d failed: %d\n",<br>
> + port_num, ret);<br>
> +<br>
> + return ret;<br>
<br>
you don't need this return here...<br>
<br>
> + }<br>
> +<br>
> + return 0;<br>
<br>
Just "return ret;" here. </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +}<br>
> +<br>
> +/**<br>
> + * drm_dp_register_typec_switches() - register Type-C switches<br>
> + * @dev: Device that registers Type-C switches<br>
> + * @port: Device node for the switch<br>
> + * @switch_desc: A Type-C switch descriptor<br>
> + * @data: Private data for the switches<br>
> + * @mux_set: Callback function for typec_mux_set<br>
> + *<br>
> + * This function registers USB Type-C switches for DP bridges that can switch<br>
> + * the output signal between their output pins.<br>
> + *<br>
> + * Currently only mode switches are implemented, and the function assumes the<br>
> + * given @port device node has endpoints with "mode-switch" property.<br>
> + * The port number is determined by the "reg" property of the endpoint.<br>
> + */<br>
> +int drm_dp_register_typec_switches(struct device *dev, struct fwnode_handle *port,<br>
> + struct drm_dp_typec_switch_desc *switch_desc,<br>
> + void *data, typec_mux_set_fn_t mux_set)<br>
> +{<br>
> + struct fwnode_handle *sw;<br>
> + int ret;<br>
> +<br>
> + fwnode_for_each_child_node(port, sw) {<br>
> + if (fwnode_property_present(sw, "mode-switch"))<br>
> + switch_desc->num_typec_switches++;<br>
> + }<br>
<br>
no need for brackets here<br>
<br>
> +<br>
> + if (!switch_desc->num_typec_switches) {<br>
> + dev_dbg(dev, "No Type-C switches node found\n");<br>
<br>
dev_warn()?<br></blockquote><div><br></div><div>I used dev_dbg here because the users might call this without checking if there are mode switch endpoints present, and this is the case for the current users (it6505 and anx7625). If we use dev_warn here, there will be warnings every time even on use cases without Type-C switches.</div><div><br></div><div>Thanks and regards,</div><div>Pin-yen</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> + return 0;<br>
> + }<br>
> +<br>
> + switch_desc->typec_ports = devm_kcalloc(<br>
> + dev, switch_desc->num_typec_switches,<br>
> + sizeof(struct drm_dp_typec_port_data), GFP_KERNEL);<br>
> +<br>
> + if (!switch_desc->typec_ports)<br>
> + return -ENOMEM;<br>
> +<br>
> + /* Register switches for each connector. */<br>
> + fwnode_for_each_child_node(port, sw) {<br>
> + if (!fwnode_property_present(sw, "mode-switch"))<br>
> + continue;<br>
> + ret = drm_dp_register_mode_switch(dev, sw, switch_desc, data, mux_set);<br>
> + if (ret)<br>
> + goto err_unregister_typec_switches;<br>
> + }<br>
> +<br>
> + return 0;<br>
> +<br>
> +err_unregister_typec_switches:<br>
> + fwnode_handle_put(sw);<br>
> + drm_dp_unregister_typec_switches(switch_desc);<br>
> + dev_err(dev, "Failed to register mode switch: %d\n", ret);<br>
<br>
there is a bit of dmesg spamming. Please choose where you want to<br>
print the error, either in this function or in<br>
drm_dp_register_mode_switch().<br>
<br>
Andi<br>
<br>
> + return ret;<br>
> +}<br>
> +EXPORT_SYMBOL(drm_dp_register_typec_switches);<br>
<br>
[...]<br>
</blockquote></div></div>