Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79AC4C636CC for ; Mon, 20 Feb 2023 09:03:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231423AbjBTJDb (ORCPT ); Mon, 20 Feb 2023 04:03:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231340AbjBTJD3 (ORCPT ); Mon, 20 Feb 2023 04:03:29 -0500 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F38FB47B for ; Mon, 20 Feb 2023 01:03:02 -0800 (PST) Received: by mail-io1-xd2d.google.com with SMTP id y140so447483iof.6 for ; Mon, 20 Feb 2023 01:03:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=6vK8cWtmG3hyaLbDRLFgpGqrS4p5hCk6+ikOOD3341A=; b=BT2ud7sxoolXPSVz5YqHI7AD9RUl8N77zxnGMFNIRbnYZ5NkGNX9t15jb4JPaWA0gx RjgNyOP62hyyw3LtDM51WRaeDbSW+gmOyX365JR1nV/4MS/DGuN+CxjtV2S82wMFZDkJ APJfi8WJHRCCVh7BpaS6YJFgaYSTVJLIbJWYU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6vK8cWtmG3hyaLbDRLFgpGqrS4p5hCk6+ikOOD3341A=; b=AFOS4p1E/GcvVruU4twSNxfMxzccY7mmMQoNfDNGBtlA/gAEiGGJ4+8DsB7Ob7zzCX WRiFwyq4l/5SuPMRZycPkUfCHFc8JnRhwj0gb8STzAKOdwIHF7k66V2qB6q5zJYZJRQg s1TXq+xOB3xpbpopTdUswRBrpbiihA3DWGJrKvt7qa+DY8W7c9OpF87VwEIMNSg1SZwq iMKxGIymiodrdZMP36egR2AvRYh8lbxZmiJZZZQlbMz6GFeTX+LYoRoGd2RXig+Nq82U 5Qfc7Nmxeh5JZxJC+LYNOLZ1Llq8nxX18SR62yt1BUTWlSqS/6sYXzyCSVcEDjm+1Hj0 RuFg== X-Gm-Message-State: AO0yUKXcxLr9V77dViJIsvCAAcYEOiwQTlBnsvl9EudL/RSheqx0OBSm WI95UNevVoEci1Gsw1D9gGoxz/jGazPupY9sB6qrsg== X-Google-Smtp-Source: AK7set/kfz8hhDABr4DJ+44LUPCJEAg1cYsDPb4PwPecz9RynTAejbvde/9b9DWWLC1U8dNQIeThAlbfMv3O8bnKttg= X-Received: by 2002:a05:6638:1342:b0:3c2:c1c9:8bca with SMTP id u2-20020a056638134200b003c2c1c98bcamr1153386jad.2.1676883781590; Mon, 20 Feb 2023 01:03:01 -0800 (PST) MIME-Version: 1.0 References: <20230204133040.1236799-1-treapking@chromium.org> <20230204133040.1236799-4-treapking@chromium.org> In-Reply-To: From: Pin-yen Lin Date: Mon, 20 Feb 2023 17:02:50 +0800 Message-ID: Subject: Re: [PATCH v11 3/9] drm/display: Add Type-C switch helpers To: Andi Shyti Cc: Andrzej Hajda , Neil Armstrong , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , Rob Herring , Krzysztof Kozlowski , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Prashant Malani , Benson Leung , Guenter Roeck , linux-kernel@vger.kernel.org, =?UTF-8?B?TsOtY29sYXMgRiAuIFIgLiBBIC4gUHJhZG8=?= , Hsin-Yi Wang , devicetree@vger.kernel.org, Allen Chen , Lyude Paul , linux-acpi@vger.kernel.org, dri-devel@lists.freedesktop.org, Marek Vasut , Xin Ji , Stephen Boyd , AngeloGioacchino Del Regno , Thomas Zimmermann , Javier Martinez Canillas , chrome-platform@lists.linux.dev, Alex Deucher , Douglas Anderson , "Gustavo A. R. Silva" , Imre Deak , Jani Nikula , Kees Cook , Thierry Reding , Robert Foss Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I think I accidentally used HTML mode for the previous email. Sorry about t= hat. On Mon, Feb 20, 2023 at 4:41 PM Pin-yen Lin wrote: > > Hi Andi, > > Thanks for the review. > > On Wed, Feb 8, 2023 at 5:25 AM Andi Shyti wr= ote: >> >> Hi Pin-yen, >> >> [...] >> >> > +static int drm_dp_register_mode_switch(struct device *dev, >> > + struct fwnode_handle *fwnode, >> > + struct drm_dp_typec_switch_desc *= switch_desc, >> > + void *data, typec_mux_set_fn_t mu= x_set) >> > +{ >> > + struct drm_dp_typec_port_data *port_data; >> > + struct typec_mux_desc mux_desc =3D {}; >> > + char name[32]; >> > + u32 port_num; >> > + int ret; >> > + >> > + ret =3D fwnode_property_read_u32(fwnode, "reg", &port_num); >> > + if (ret) { >> > + dev_err(dev, "Failed to read reg property: %d\n", ret); >> > + return ret; >> > + } >> > + >> > + port_data =3D &switch_desc->typec_ports[port_num]; >> > + port_data->data =3D data; >> > + port_data->port_num =3D port_num; >> > + port_data->fwnode =3D fwnode; >> > + mux_desc.fwnode =3D fwnode; >> > + mux_desc.drvdata =3D port_data; >> > + snprintf(name, sizeof(name), "%pfwP-%u", fwnode, port_num); >> > + mux_desc.name =3D name; >> > + mux_desc.set =3D mux_set; >> > + >> > + port_data->typec_mux =3D typec_mux_register(dev, &mux_desc); >> > + if (IS_ERR(port_data->typec_mux)) { >> > + ret =3D PTR_ERR(port_data->typec_mux); >> > + dev_err(dev, "Mode switch register for port %d failed: %= d\n", >> > + port_num, ret); >> > + >> > + return ret; >> >> you don't need this return here... >> >> > + } >> > + >> > + return 0; >> >> Just "return ret;" here. This was actually suggested by Angelo in [1]. I personally don't have a strong opinion on either approach. [1]https://lore.kernel.org/all/023519eb-0adb-3b08-71b9-afb92a6cceaf@collabo= ra.com/ Pin-yen >> >> >> > +} >> > + >> > +/** >> > + * drm_dp_register_typec_switches() - register Type-C switches >> > + * @dev: Device that registers Type-C switches >> > + * @port: Device node for the switch >> > + * @switch_desc: A Type-C switch descriptor >> > + * @data: Private data for the switches >> > + * @mux_set: Callback function for typec_mux_set >> > + * >> > + * This function registers USB Type-C switches for DP bridges that ca= n switch >> > + * the output signal between their output pins. >> > + * >> > + * Currently only mode switches are implemented, and the function ass= umes the >> > + * given @port device node has endpoints with "mode-switch" property. >> > + * The port number is determined by the "reg" property of the endpoin= t. >> > + */ >> > +int drm_dp_register_typec_switches(struct device *dev, struct fwnode_= handle *port, >> > + struct drm_dp_typec_switch_desc *swit= ch_desc, >> > + void *data, typec_mux_set_fn_t mux_se= t) >> > +{ >> > + struct fwnode_handle *sw; >> > + int ret; >> > + >> > + fwnode_for_each_child_node(port, sw) { >> > + if (fwnode_property_present(sw, "mode-switch")) >> > + switch_desc->num_typec_switches++; >> > + } >> >> no need for brackets here >> >> > + >> > + if (!switch_desc->num_typec_switches) { >> > + dev_dbg(dev, "No Type-C switches node found\n"); >> >> dev_warn()? > > > 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 curr= ent users (it6505 and anx7625). If we use dev_warn here, there will be warn= ings every time even on use cases without Type-C switches. > > Thanks and regards, > Pin-yen >> >> >> > + return 0; >> > + } >> > + >> > + switch_desc->typec_ports =3D devm_kcalloc( >> > + dev, switch_desc->num_typec_switches, >> > + sizeof(struct drm_dp_typec_port_data), GFP_KERNEL); >> > + >> > + if (!switch_desc->typec_ports) >> > + return -ENOMEM; >> > + >> > + /* Register switches for each connector. */ >> > + fwnode_for_each_child_node(port, sw) { >> > + if (!fwnode_property_present(sw, "mode-switch")) >> > + continue; >> > + ret =3D drm_dp_register_mode_switch(dev, sw, switch_desc= , data, mux_set); >> > + if (ret) >> > + goto err_unregister_typec_switches; >> > + } >> > + >> > + return 0; >> > + >> > +err_unregister_typec_switches: >> > + fwnode_handle_put(sw); >> > + drm_dp_unregister_typec_switches(switch_desc); >> > + dev_err(dev, "Failed to register mode switch: %d\n", ret); >> >> there is a bit of dmesg spamming. Please choose where you want to >> print the error, either in this function or in >> drm_dp_register_mode_switch(). >> >> Andi >> >> > + return ret; >> > +} >> > +EXPORT_SYMBOL(drm_dp_register_typec_switches); >> >> [...]