Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1171017pxb; Fri, 21 Jan 2022 11:22:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzdjKFe6uSs+Iku1mh8kLbqZ22CuadLUcRHxIcAyiCbLZrFuLeBGEnQf4r/vtF5tbVlsp22 X-Received: by 2002:a17:903:2342:b0:14a:e540:6c83 with SMTP id c2-20020a170903234200b0014ae5406c83mr4730722plh.69.1642792955695; Fri, 21 Jan 2022 11:22:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642792955; cv=none; d=google.com; s=arc-20160816; b=LZ2tmQH4zhsPbidiB+sLe35yJxAS799Q6YN9Cb1vsKk6KQCgwX9aH4ONBiC+DpC45i L8SJtJC8WdfWK9l5jxCmn+esPMUMXq5kPhyASzyfI4/Mg8PeXstx5aG0rpbWhIiVAmgY lPl8SZ4yHMBtW8HgIJ47e6Ng9LMVKB6EYmIcYTdWTW7lOs6FEldlLKKC3+gKzNYq6Mpv nJrZLgi3IDx8uORHtMhBfT8xIHvYHovwxeDJwo0sMcut7cWatFgjk0XmRWDGMq5ukze0 OlxKkAYCXjuYS67PNKHwBZ0kdv8sBaSorHFd4uBtfCxZ5K/3KkzlPtkAfwZWe8FvYjNM Z15g== 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=865W3nngZbj66iHqIMRPmys+V8jiTQCV4utpzwueQJA=; b=G38HQCmXiJjjr9CG3xb9ZOGV5CELG6/NmN5c7MQDFSK5xd1JMifLdAhUMxlrHVfS3y OB49UmURGcJCelgtBCdMqfVmszVA2zhfavOoh5ugXNGOTGa03QZ+ALU8Gu1GQf+RDXRY LpYMe8gYjS/9YiKt6cBVk9WMOZDH31ooBIRMOThwaUYYJiLh6RbFG0yCURkAbHtCAhJD tTeKBk0i3uuJsvUv/AZ9m9MXb1StKGIwhl+uSTxSW8tpI6bSDMa3ogjk8HYvvQZHmHHY X6wIzjFBQY1h95TZl11wotbvRGgvAbPIn7B5ljGFQrLzR20dXadISHkE16aV0FNslIk9 YR8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YG4ABSlL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l12si5514469pga.479.2022.01.21.11.22.22; Fri, 21 Jan 2022 11:22:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YG4ABSlL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355552AbiASPIT (ORCPT + 99 others); Wed, 19 Jan 2022 10:08:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355517AbiASPIO (ORCPT ); Wed, 19 Jan 2022 10:08:14 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34305C061574 for ; Wed, 19 Jan 2022 07:08:14 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id h12so2710592pjq.3 for ; Wed, 19 Jan 2022 07:08:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=865W3nngZbj66iHqIMRPmys+V8jiTQCV4utpzwueQJA=; b=YG4ABSlLGxGSrrRltRwvLxFF9nwfGLmtMLgSHo2CdjLJO7BJknSzRna5RdBvJEZmQH dQOw4YeX1AXc3l9hACYmCaxK7QJfkcBh73x/emEW8K6Y1SkZYcrKhEWTEu5E6aL7LAj2 0QoYBMz3lwS3KaWNjiZ1K0HChm/Mo8ejT2DlEof45M8NFRoLxouM8OJsrQikw9VAxcZj iq2XmCv+uiksx0OBsdFf/D8UKdfkPExVFdi/+1fPnUyM4aRLi7Ovua474NO7A9chx3X4 FvQiCUJAhb25MBILLFGdyo9NOEN07tMgX4rO6x93aDlCO0IX/kwbk4pkuZa8hlk6Wc6y ZsIQ== 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=865W3nngZbj66iHqIMRPmys+V8jiTQCV4utpzwueQJA=; b=bcRnr6NGbTlmzOGw7KPf57zEZaliOvYk+vQ2s6mQaRjtu80Bkq5u1abYZY3AKOVbrs 3pb6ThNttXa9CzGwoJ4uFfp9UBOh33l9q0xLTC8Tcu7DBRB0S9fMdYxYN0XlIlLvKuh/ JeSkCL9lF8XsDcAF109nZyHyvPPgkYnG2wPqcv04wtrwscgZYTv3Yh0IDFDI2iBCnXvG xrlQtz3BaxUOYUVhuQAdPCeNPCWsLheq/WBRWuf5G1FQh+NNn7UaoBqOB3q968t5jCxs PdG0ETAXqqOj4DIFu6zeqTukuIkh1l8dN/31rdKwC4qnw3B6+muwwUnoHKeygi7sOc/L xKZg== X-Gm-Message-State: AOAM530gWvf1jU4/9OA+fVY2yCnF9ddINhU1wo6JBKOFbHxO/E8Qtyy6 austuaxlcwS98bpvEHoznzjS3ff+BWol+Ea7180bRw== X-Received: by 2002:a17:902:b189:b0:149:6c45:24c with SMTP id s9-20020a170902b18900b001496c45024cmr33019972plr.21.1642604893365; Wed, 19 Jan 2022 07:08:13 -0800 (PST) MIME-Version: 1.0 References: <20220118092002.4267-1-hsinyi@chromium.org> <20220118092002.4267-3-hsinyi@chromium.org> In-Reply-To: <20220118092002.4267-3-hsinyi@chromium.org> From: Robert Foss Date: Wed, 19 Jan 2022 16:08:02 +0100 Message-ID: Subject: Re: [PATCH v4 3/4] drm/bridge: anx7625: Support reading edid through aux channel To: Hsin-Yi Wang Cc: Rob Herring , Xin Ji , David Airlie , Daniel Vetter , Laurent Pinchart , dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Andrzej Hajda , Neil Armstrong , Jonas Karlman , Jernej Skrabec , Sam Ravnborg , Maxime Ripard Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 18 Jan 2022 at 10:20, Hsin-Yi Wang wrote: > > Support reading edid through aux channel if panel is connected to aux > bus. Extend anx7625_aux_dpcd_trans() to implement aux transfer function: > > 1. panel is populated in devm_of_dp_aux_populate_ep_devices(), so move > anx7625_parse_dt() after. > 2. Use pm runtime autosuspend since aux transfer function is called > multiple times when reading edid. > 3. No-op if aux transfer length is 0. > > Signed-off-by: Hsin-Yi Wang > Reviewed-by: Xin Ji > --- > v3->v4: > rebase to latest drm-misc-next > --- > drivers/gpu/drm/bridge/analogix/anx7625.c | 120 ++++++++++++++++++---- > drivers/gpu/drm/bridge/analogix/anx7625.h | 1 + > 2 files changed, 103 insertions(+), 18 deletions(-) > > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c > index b7e3373994b480..50b9c98277f0d7 100644 > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c > @@ -24,6 +24,7 @@ > #include > #include > #include > +#include drivers/gpu/drm/bridge/analogix/anx7625.c:27:10: fatal error: drm/drm_dp_aux_bus.h: No such file or directory 27 | #include drm/dp/rm_dp_aux_bus.h is probably the correct path. > #include > #include > #include > @@ -231,19 +232,23 @@ static int wait_aux_op_finish(struct anx7625_data *ctx) > return 0; > } > > -static int anx7625_aux_dpcd_trans(struct anx7625_data *ctx, u8 op, > - u32 address, u8 len, u8 *buf) > +static int anx7625_aux_trans(struct anx7625_data *ctx, u8 op, u32 address, > + u8 len, u8 *buf) > { > struct device *dev = &ctx->client->dev; > int ret; > u8 addrh, addrm, addrl; > u8 cmd; > + bool is_write = !(op & DP_AUX_I2C_READ); > > - if (len > MAX_DPCD_BUFFER_SIZE) { > + if (len > DP_AUX_MAX_PAYLOAD_BYTES) { > dev_err(dev, "exceed aux buffer len.\n"); > return -EINVAL; > } > > + if (!len) > + return len; > + > addrl = address & 0xFF; > addrm = (address >> 8) & 0xFF; > addrh = (address >> 16) & 0xFF; > @@ -262,7 +267,7 @@ static int anx7625_aux_dpcd_trans(struct anx7625_data *ctx, u8 op, > ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client, > AP_AUX_ADDR_19_16, addrh); > > - if (op == DP_AUX_NATIVE_WRITE) > + if (is_write) > ret |= anx7625_reg_block_write(ctx, ctx->i2c.rx_p0_client, > AP_AUX_BUFF_START, len, buf); > /* Enable aux access */ > @@ -275,14 +280,14 @@ static int anx7625_aux_dpcd_trans(struct anx7625_data *ctx, u8 op, > } > > ret = wait_aux_op_finish(ctx); > - if (ret) { > + if (ret < 0) { > dev_err(dev, "aux IO error: wait aux op finish.\n"); > return ret; > } > > /* Write done */ > - if (op == DP_AUX_NATIVE_WRITE) > - return 0; > + if (is_write) > + return len; > > /* Read done, read out dpcd data */ > ret = anx7625_reg_block_read(ctx, ctx->i2c.rx_p0_client, > @@ -292,7 +297,7 @@ static int anx7625_aux_dpcd_trans(struct anx7625_data *ctx, u8 op, > return -EIO; > } > > - return 0; > + return len; > } > > static int anx7625_video_mute_control(struct anx7625_data *ctx, > @@ -867,7 +872,7 @@ static int anx7625_hdcp_enable(struct anx7625_data *ctx) > } > > /* Read downstream capability */ > - anx7625_aux_dpcd_trans(ctx, DP_AUX_NATIVE_READ, 0x68028, 1, &bcap); > + anx7625_aux_trans(ctx, DP_AUX_NATIVE_READ, 0x68028, 1, &bcap); > if (!(bcap & 0x01)) { > pr_warn("downstream not support HDCP 1.4, cap(%x).\n", bcap); > return 0; > @@ -956,7 +961,7 @@ static void anx7625_dp_stop(struct anx7625_data *ctx) > dev_dbg(dev, "notify downstream enter into standby\n"); > /* Downstream monitor enter into standby mode */ > data = 2; > - ret |= anx7625_aux_dpcd_trans(ctx, DP_AUX_NATIVE_WRITE, 0x000600, 1, &data); > + ret |= anx7625_aux_trans(ctx, DP_AUX_NATIVE_WRITE, 0x000600, 1, &data); > if (ret < 0) > DRM_DEV_ERROR(dev, "IO error : mute video fail\n"); > > @@ -1655,11 +1660,56 @@ static int anx7625_parse_dt(struct device *dev, > return 0; > } > > +static bool anx7625_of_panel_on_aux_bus(struct device *dev) > +{ > + struct device_node *bus, *panel; > + > + bus = of_get_child_by_name(dev->of_node, "aux-bus"); > + if (!bus) > + return false; > + > + panel = of_get_child_by_name(bus, "panel"); > + of_node_put(bus); > + if (!panel) > + return false; > + of_node_put(panel); > + > + return true; > +} > + > static inline struct anx7625_data *bridge_to_anx7625(struct drm_bridge *bridge) > { > return container_of(bridge, struct anx7625_data, bridge); > } > > +static ssize_t anx7625_aux_transfer(struct drm_dp_aux *aux, > + struct drm_dp_aux_msg *msg) checkpatch --strict is unhappy about the above line not using as many tabs as possible. > +{ > + struct anx7625_data *ctx = container_of(aux, struct anx7625_data, aux); > + struct device *dev = &ctx->client->dev; > + u8 request = msg->request & ~DP_AUX_I2C_MOT; > + int ret = 0; > + > + pm_runtime_get_sync(dev); > + msg->reply = 0; > + switch (request) { > + case DP_AUX_NATIVE_WRITE: > + case DP_AUX_I2C_WRITE: > + case DP_AUX_NATIVE_READ: > + case DP_AUX_I2C_READ: > + break; > + default: > + ret = -EINVAL; > + } > + if (!ret) > + ret = anx7625_aux_trans(ctx, msg->request, msg->address, > + msg->size, msg->buffer); > + pm_runtime_mark_last_busy(dev); > + pm_runtime_put_autosuspend(dev); > + > + return ret; > +} > + > static struct edid *anx7625_get_edid(struct anx7625_data *ctx) > { > struct device *dev = &ctx->client->dev; > @@ -2066,6 +2116,13 @@ static int anx7625_bridge_attach(struct drm_bridge *bridge, > return -ENODEV; > } > > + ctx->aux.drm_dev = bridge->dev; > + err = drm_dp_aux_register(&ctx->aux); > + if (err) { > + dev_err(dev, "failed to register aux channel: %d\n", err); > + return err; > + } > + > if (ctx->pdata.panel_bridge) { > err = drm_bridge_attach(bridge->encoder, > ctx->pdata.panel_bridge, > @@ -2079,6 +2136,13 @@ static int anx7625_bridge_attach(struct drm_bridge *bridge, > return 0; > } > > +static void anx7625_bridge_detach(struct drm_bridge *bridge) > +{ > + struct anx7625_data *ctx = bridge_to_anx7625(bridge); > + > + drm_dp_aux_unregister(&ctx->aux); > +} > + > static enum drm_mode_status > anx7625_bridge_mode_valid(struct drm_bridge *bridge, > const struct drm_display_info *info, > @@ -2344,6 +2408,7 @@ static struct edid *anx7625_bridge_get_edid(struct drm_bridge *bridge, > > static const struct drm_bridge_funcs anx7625_bridge_funcs = { > .attach = anx7625_bridge_attach, > + .detach = anx7625_bridge_detach, > .mode_valid = anx7625_bridge_mode_valid, > .mode_set = anx7625_bridge_mode_set, > .atomic_check = anx7625_bridge_atomic_check, > @@ -2501,6 +2566,12 @@ static const struct dev_pm_ops anx7625_pm_ops = { > anx7625_runtime_pm_resume, NULL) > }; > > +static void anx7625_runtime_disable(void *data) > +{ > + pm_runtime_dont_use_autosuspend(data); > + pm_runtime_disable(data); > +} > + > static int anx7625_i2c_probe(struct i2c_client *client, > const struct i2c_device_id *id) > { > @@ -2523,13 +2594,6 @@ static int anx7625_i2c_probe(struct i2c_client *client, > > pdata = &platform->pdata; > > - ret = anx7625_parse_dt(dev, pdata); > - if (ret) { > - if (ret != -EPROBE_DEFER) > - DRM_DEV_ERROR(dev, "fail to parse DT : %d\n", ret); > - return ret; > - } > - > platform->client = client; > i2c_set_clientdata(client, platform); > > @@ -2577,6 +2641,19 @@ static int anx7625_i2c_probe(struct i2c_client *client, > } > } > > + platform->aux.name = "anx7625-aux"; > + platform->aux.dev = dev; > + platform->aux.transfer = anx7625_aux_transfer; > + drm_dp_aux_init(&platform->aux); > + devm_of_dp_aux_populate_ep_devices(&platform->aux); > + > + ret = anx7625_parse_dt(dev, pdata); > + if (ret) { > + if (ret != -EPROBE_DEFER) > + DRM_DEV_ERROR(dev, "fail to parse DT : %d\n", ret); > + return ret; > + } > + > if (anx7625_register_i2c_dummy_clients(platform, client) != 0) { > ret = -ENOMEM; > DRM_DEV_ERROR(dev, "fail to reserve I2C bus.\n"); > @@ -2584,6 +2661,12 @@ static int anx7625_i2c_probe(struct i2c_client *client, > } > > pm_runtime_enable(dev); > + pm_runtime_set_autosuspend_delay(dev, 1000); > + pm_runtime_use_autosuspend(dev); > + pm_suspend_ignore_children(dev, true); > + ret = devm_add_action_or_reset(dev, anx7625_runtime_disable, dev); > + if (ret) > + return ret; > > if (!platform->pdata.low_power_mode) { > anx7625_disable_pd_protocol(platform); > @@ -2596,7 +2679,8 @@ static int anx7625_i2c_probe(struct i2c_client *client, > > platform->bridge.funcs = &anx7625_bridge_funcs; > platform->bridge.of_node = client->dev.of_node; > - platform->bridge.ops = DRM_BRIDGE_OP_EDID; > + if (!anx7625_of_panel_on_aux_bus(&client->dev)) > + platform->bridge.ops |= DRM_BRIDGE_OP_EDID; > if (!platform->pdata.panel_bridge) > platform->bridge.ops |= DRM_BRIDGE_OP_HPD | > DRM_BRIDGE_OP_DETECT; > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h b/drivers/gpu/drm/bridge/analogix/anx7625.h > index 64a8ab56529404..edbbfe410a56e8 100644 > --- a/drivers/gpu/drm/bridge/analogix/anx7625.h > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.h > @@ -472,6 +472,7 @@ struct anx7625_data { > u8 bridge_attached; > struct drm_connector *connector; > struct mipi_dsi_device *dsi; > + struct drm_dp_aux aux; > }; > > #endif /* __ANX7625_H__ */ > -- > 2.34.1.703.g22d0c6ccf7-goog >