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 1B6CDC636D3 for ; Tue, 7 Feb 2023 21:26:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230117AbjBGV0Z (ORCPT ); Tue, 7 Feb 2023 16:26:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbjBGV0L (ORCPT ); Tue, 7 Feb 2023 16:26:11 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3397B3EFF8; Tue, 7 Feb 2023 13:25:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675805149; x=1707341149; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=wNen/FnBjNX3bzOs+p58aweLxojs1tMz6HAqiUGxA78=; b=MlgW8QcLa+XIsZoejVc1UIbmHkyvefrbedsQ2HDfmjGn22HYAdVhWrLk jb54i2ck3nsKMVQEZ+H8Ykx8HZKJjwl0pj9oNJBdkzJdPmUXjAqaVgS4x P6KQyuh/Zdep8+uoK0l2bEwNwy9fx7URarzOH0rYIfobECOKHgI3xNYr9 6gL1BEq3v4oNAKWoIRlzWGrnv2iglDzD1sRwlgtcVfg3bSns5ZCShRVyI S7kY1yHmND0/lTiTa72Ohl7xzC4IAhCypmNiH362WlO2lUFeA/Kfygenc xfdyVnkpS5QMSvZF5Zr3OFETz4rm/DbToOoEGs2UXjMEQ+KkCABfudSOj A==; X-IronPort-AV: E=McAfee;i="6500,9779,10614"; a="331765716" X-IronPort-AV: E=Sophos;i="5.97,279,1669104000"; d="scan'208";a="331765716" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2023 13:25:47 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10614"; a="730595933" X-IronPort-AV: E=Sophos;i="5.97,279,1669104000"; d="scan'208";a="730595933" Received: from isergee-mobl3.ger.corp.intel.com (HELO intel.com) ([10.249.37.137]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2023 13:25:37 -0800 Date: Tue, 7 Feb 2023 22:25:34 +0100 From: Andi Shyti To: Pin-yen Lin Cc: Andrzej Hajda , Neil Armstrong , Robert Foss , 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, =?iso-8859-15?Q?N=EDcolas_F_=2E_R_=2E_A_=2E?= Prado , 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 , Andi Shyti , Douglas Anderson , "Gustavo A. R. Silva" , Imre Deak , Jani Nikula , Kees Cook , Thierry Reding Subject: Re: [PATCH v11 3/9] drm/display: Add Type-C switch helpers Message-ID: References: <20230204133040.1236799-1-treapking@chromium.org> <20230204133040.1236799-4-treapking@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230204133040.1236799-4-treapking@chromium.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 mux_set) > +{ > + struct drm_dp_typec_port_data *port_data; > + struct typec_mux_desc mux_desc = {}; > + char name[32]; > + u32 port_num; > + int ret; > + > + ret = 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 = &switch_desc->typec_ports[port_num]; > + port_data->data = data; > + port_data->port_num = port_num; > + port_data->fwnode = fwnode; > + mux_desc.fwnode = fwnode; > + mux_desc.drvdata = port_data; > + snprintf(name, sizeof(name), "%pfwP-%u", fwnode, port_num); > + mux_desc.name = name; > + mux_desc.set = mux_set; > + > + port_data->typec_mux = typec_mux_register(dev, &mux_desc); > + if (IS_ERR(port_data->typec_mux)) { > + ret = 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. > +} > + > +/** > + * 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 can switch > + * the output signal between their output pins. > + * > + * Currently only mode switches are implemented, and the function assumes the > + * given @port device node has endpoints with "mode-switch" property. > + * The port number is determined by the "reg" property of the endpoint. > + */ > +int drm_dp_register_typec_switches(struct device *dev, struct fwnode_handle *port, > + struct drm_dp_typec_switch_desc *switch_desc, > + void *data, typec_mux_set_fn_t mux_set) > +{ > + 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()? > + return 0; > + } > + > + switch_desc->typec_ports = 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 = 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); [...]