Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1667232iog; Tue, 14 Jun 2022 10:29:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tMexY+4z4/IZmcQvf4UnwwlCOkBsaNKKAOuW4xDPh7Hqp96GMI2fHgUDTsJxFxa/p3ojQ3 X-Received: by 2002:a62:1589:0:b0:51b:e99c:8f8f with SMTP id 131-20020a621589000000b0051be99c8f8fmr5439321pfv.30.1655227761497; Tue, 14 Jun 2022 10:29:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655227761; cv=none; d=google.com; s=arc-20160816; b=n3MuYKGLNooCgmWGtsXYPenO5Ag1UVSyoAdHiAtO5tbEmRksOhO80/uzcTtLEVcoov 3SUklP3UxQ63HiPwAlN83NSPe1Ws3BIY+BMinIMxAsqFAYjcSYfdcPNv5sQ7gIVpYB2d BlEOJqeQ+SnkfoOyAA3A6IST0aoz/CpJfuFjlUBRf0EGg+w8VWUno1Rwvs7USxImzeNC iplJD2O+HgU4QozFtPId0zsV/lMMiW6TnhNXMXeHeXyHHDPFqowEo6M4GbR8vhp0Jj9E I+r7yXbhkHEdkVQI93era58z334MpmrhsWETRwec6zsdxAVGab5PK35y3AQPOag9Kfax DCkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=F6g97R91sjtVG6ei6JULqw4mFypOAKmb8KKUSEZQlEM=; b=ktvECPs264n2LQ69morbKX4et3VEKmoEj3Y/ah5JTXm8ELYJ5QOA7LQFs0XVYHaBo4 i4iIxqRA2MV1m7u1/WF9344ZYDAklhgdoUIU9ui2+uJT4z7n1xrhWd62XUaE7EAlse57 lKILXgli77fWeRf/4KdGhEGsC4aaiCAU9gC3yi6YlbSA/NVFyf38CWPTqIZVoqU6cfQI KxU1VbJQRcpYs3nmffIeC285jeHxApRh+EmnTQf6KGhKpZuMs3fzdReXN6y851nWdmTf 98uUWpysLzoqz/ZHJVJ1wOYmun8sEKBVHaC4UM7lusgXeyolzQTYwViQL6+Js0esW+TK GC3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OhorWc2m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ix11-20020a170902f80b00b00163c52336fbsi13066178plb.369.2022.06.14.10.29.06; Tue, 14 Jun 2022 10:29:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OhorWc2m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351991AbiFNQ6G (ORCPT + 99 others); Tue, 14 Jun 2022 12:58:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241101AbiFNQ5u (ORCPT ); Tue, 14 Jun 2022 12:57:50 -0400 Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 316A02BD2 for ; Tue, 14 Jun 2022 09:57:42 -0700 (PDT) Received: by mail-yb1-xb33.google.com with SMTP id h27so16200656ybj.4 for ; Tue, 14 Jun 2022 09:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=F6g97R91sjtVG6ei6JULqw4mFypOAKmb8KKUSEZQlEM=; b=OhorWc2mjBDno2pDG8ZqawT9/vJ1MCCttW7q1lpoz7gdDgLYrJO6STISprKObl3IED V3HLrokuHjWh5byp4w9ZoEsXDb/AF69KJt0nEdSktT7jcbnUUmVYFVjf4E92yn15pJLR bncnJl6LfB4Py3RYJgpdu03zYHSoBIp1zBwT0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=F6g97R91sjtVG6ei6JULqw4mFypOAKmb8KKUSEZQlEM=; b=QKAX41I/FVRCEfR2qspIA/FvN7c7BWKU29y8PQHxk94/WmRbnwzK3+5sOFkm2wsB4z zuLL4pyAyPlLwKDyLkrT6nxgtlGeYNGOjWUmwZSvtlcqJU5hHB6T5E78TFV0kXtoCSPa ANV34e0O6VGpC4ZEYfSv6YKY5+B0HJkri3V5dTazrCwNmtHTMO8Ub3XtPmwp17rUrScD nk/oMzWqZarsBw5JdA6nSXJ1vKPboBr8cRmkAIk/0MdsBsNDydf10EOA9ekchcJ/SjwK QIpelUmlzz8BkwaGZLCEvoNXnRiuKeh62HUrLkIY+uvZlQmzaJVPzzb2LFaBNHlNkYP+ pfSw== X-Gm-Message-State: AJIora8Qpb0xFOU9LCVrAz+Orh+1svS5PDNlNVdUQKeoN5sk9y5/3ZlC aJ5K1HVgVISy5hgb+PEOUumXOnZ/9vDzGQaiz1ty/g== X-Received: by 2002:a25:67c2:0:b0:65d:555b:8f59 with SMTP id b185-20020a2567c2000000b0065d555b8f59mr5855580ybc.240.1655225860885; Tue, 14 Jun 2022 09:57:40 -0700 (PDT) MIME-Version: 1.0 References: <20220609181106.3695103-1-pmalani@chromium.org> <20220609181106.3695103-7-pmalani@chromium.org> In-Reply-To: From: Prashant Malani Date: Tue, 14 Jun 2022 09:57:29 -0700 Message-ID: Subject: Re: [PATCH v2 6/7] drm/bridge: anx7625: Register Type-C mode switches To: AngeloGioacchino Del Regno Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, heikki.krogerus@linux.intel.com, Andrzej Hajda , Neil Armstrong , David Airlie , "open list:DRM DRIVERS" , Laurent Pinchart , Krzysztof Kozlowski , Sam Ravnborg , Jernej Skrabec , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , Thomas Zimmermann , =?UTF-8?B?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= , Jonas Karlman , swboyd@chromium.org, Pin-Yen Lin , Rob Herring , Maxime Ripard , Hsin-Yi Wang , Xin Ji , Greg Kroah-Hartman , Robert Foss , =?UTF-8?B?Sm9zw6kgRXhww7NzaXRv?= Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 14, 2022 at 1:18 AM AngeloGioacchino Del Regno wrote: > > Il 09/06/22 20:09, Prashant Malani ha scritto: > > When the DT node has "switches" available, register a Type-C mode-switch > > for each listed "switch". This allows the driver to receive state > > information about what operating mode a Type-C port and its connected > > peripherals are in, as well as status information (like VDOs) related to > > that state. > > > > The callback function is currently a stub, but subsequent patches will > > implement the required functionality. > > > > Signed-off-by: Prashant Malani > > --- > > > > Changes since v2: > > - No changes. > > > > drivers/gpu/drm/bridge/analogix/anx7625.c | 73 +++++++++++++++++++++++ > > drivers/gpu/drm/bridge/analogix/anx7625.h | 6 ++ > > 2 files changed, 79 insertions(+) > > > > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c > > index 07ed44c6b839..d41a21103bd3 100644 > > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c > > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c > > @@ -15,6 +15,7 @@ > > #include > > #include > > #include > > +#include > > #include > > > > #include > > @@ -2581,9 +2582,59 @@ static void anx7625_runtime_disable(void *data) > > pm_runtime_disable(data); > > } > > > > +static int anx7625_typec_mux_set(struct typec_mux_dev *mux, > > + struct typec_mux_state *state) > > +{ > > + return 0; > > +} > > + > > +static int anx7625_register_mode_switch(struct device *dev, struct device_node *node, > > + struct anx7625_data *ctx) > > +{ > > + struct anx7625_port_data *port_data; > > + struct typec_mux_desc mux_desc = {}; > > + char name[32]; > > + u32 port_num; > > + int ret; > > + > > + ret = of_property_read_u32(node, "reg", &port_num); > > + if (ret) > > + return ret; > > + > > + if (port_num >= ctx->num_typec_switches) { > > + dev_err(dev, "Invalid port number specified: %d\n", port_num); > > + return -EINVAL; > > + } > > + > > + port_data = &ctx->typec_ports[port_num]; > > + port_data->ctx = ctx; > > + mux_desc.fwnode = &node->fwnode; > > + mux_desc.drvdata = port_data; > > + snprintf(name, sizeof(name), "%s-%u", node->name, port_num); > > + mux_desc.name = name; > > + mux_desc.set = anx7625_typec_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", port_num, ret); > > + } > > Please return 0 at the end of this function. > > if (IS_ERR(....)) { > ......code...... > return ret; > } > > return 0; > } May I ask why? We're not missing any return paths. I would rather we keep it as is (which has the valid return value). > > > + > > + return ret; > > +} > > + > > +static void anx7625_unregister_typec_switches(struct anx7625_data *ctx) > > +{ > > + int i; > > + > > + for (i = 0; i < ctx->num_typec_switches; i++) > > + typec_mux_unregister(ctx->typec_ports[i].typec_mux); > > +} > > + > > static int anx7625_register_typec_switches(struct device *device, struct anx7625_data *ctx) > > { > > struct device_node *of = NULL; > > + struct device_node *sw; > > int ret = 0; > > > > of = of_get_child_by_name(device->of_node, "switches"); > > @@ -2594,6 +2645,26 @@ static int anx7625_register_typec_switches(struct device *device, struct anx7625 > > if (ctx->num_typec_switches <= 0) > > return -ENODEV; > > > > + ctx->typec_ports = devm_kzalloc(device, > > + ctx->num_typec_switches * sizeof(struct anx7625_port_data), > > + GFP_KERNEL); > > + if (!ctx->typec_ports) > > + return -ENOMEM; > > + > > + /* Register switches for each connector. */ > > + for_each_available_child_of_node(of, sw) { > > + if (!of_property_read_bool(sw, "mode-switch")) > > + continue; > > + ret = anx7625_register_mode_switch(device, sw, ctx); > > + if (ret) { > > + dev_err(device, "Failed to register mode switch: %d\n", ret); > > + break; > > + } > > + } > > + > > + if (ret) > > + anx7625_unregister_typec_switches(ctx); > > + > > return ret; > > } > > > > @@ -2759,6 +2830,8 @@ static int anx7625_i2c_remove(struct i2c_client *client) > > > > drm_bridge_remove(&platform->bridge); > > > > + anx7625_unregister_typec_switches(platform); > > + > > if (platform->pdata.intp_irq) > > destroy_workqueue(platform->workqueue); > > > > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h b/drivers/gpu/drm/bridge/analogix/anx7625.h > > index d5cbca708842..76cfc64f7574 100644 > > --- a/drivers/gpu/drm/bridge/analogix/anx7625.h > > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.h > > @@ -443,6 +443,11 @@ struct anx7625_i2c_client { > > struct i2c_client *tcpc_client; > > }; > > > > +struct anx7625_port_data { > > + struct typec_mux_dev *typec_mux; > > + struct anx7625_data *ctx; > > +}; > > + > > struct anx7625_data { > > struct anx7625_platform_data pdata; > > struct platform_device *audio_pdev; > > @@ -474,6 +479,7 @@ struct anx7625_data { > > struct mipi_dsi_device *dsi; > > struct drm_dp_aux aux; > > int num_typec_switches; > > + struct anx7625_port_data *typec_ports; > > }; > > > > #endif /* __ANX7625_H__ */ >