From patchwork Wed May 6 21:02:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 11531869 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 61A2E912 for ; Wed, 6 May 2020 21:03:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 451DB2076D for ; Wed, 6 May 2020 21:03:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="RuTQe/Ik" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729404AbgEFVDC (ORCPT ); Wed, 6 May 2020 17:03:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726538AbgEFVDC (ORCPT ); Wed, 6 May 2020 17:03:02 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DF39C061A0F for ; Wed, 6 May 2020 14:03:02 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id 18so1733107pfv.8 for ; Wed, 06 May 2020 14:03:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kNOjcx8gUe4LcNa0DGD/2mZyxy2UY+rOg6kDdh95q/g=; b=RuTQe/IkdPESXaNP0CW9o3PGMXt5OyadMALmxpnvDvBq85fe+3WJ/6n02THqluRrek QZRfAgYsXh3vtVrr3NCTkl7eaTPqgoiDnpn9PDY8jLk1P/fT+Vj7d//djvSQ3YuDm4fm ZIjPRibQH1qqD2NccofSkzzX3Ox60qrj5pAnY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kNOjcx8gUe4LcNa0DGD/2mZyxy2UY+rOg6kDdh95q/g=; b=mM+WRVRVh12XibEBrlEvclQGA6e61+YHE/bzQoPtappZ4UCeg5oAoFqE3k1ImWz7fL kOEQWkx5aGGepUSCUvdnfhynkbycSkNOSIfOUIp6xXCAuviQpEsyVKjWJqNnFmtUh9Ps FuA6FTX77gz8FKI3K+ngh8NtYmRNjcA2qgF7HzkCxghL33ZrdfrJtPouBoU8Kfq9SmJy Omddm3KWFmYGGPN4B6CPmYrrNm3jujmfM/aBnyZbGfEaU5BomXXh+TDTRjViUSwBWGHG C3ajPRgGzMYfAxMOPbJ9zrFE9CVTQXYC3rktyW8tAsWIVoYvXa296pgPz3DBm/EvFSFS ZDXg== X-Gm-Message-State: AGi0PuYYO+SnbI2EtfxJU0TjfgWF3TyX/qWpex3Cmdk0MsTeNID7B+E2 qEExq5clgq01v8QLp3BrqObWBQ== X-Google-Smtp-Source: APiQypLw5mWEXXaLMtP1aPqbjJPjyqUpxyfRnW5wUrhN7JEcZmZKlPMPl/8nk6HjSB0z7aCypH+3Nw== X-Received: by 2002:a63:7ce:: with SMTP id 197mr8968956pgh.113.1588798981792; Wed, 06 May 2020 14:03:01 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id u5sm2256412pgi.70.2020.05.06.14.03.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2020 14:03:01 -0700 (PDT) From: Douglas Anderson To: Andrzej Hajda , Neil Armstrong , Laurent Pinchart Cc: robdclark@chromium.org, seanpaul@chromium.org, swboyd@chromium.org, linux-arm-msm@vger.kernel.org, Douglas Anderson , Daniel Vetter , David Airlie , Jernej Skrabec , Jonas Karlman , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] drm/bridge: ti-sn65dsi86: Implement lane reordering + polarity Date: Wed, 6 May 2020 14:02:41 -0700 Message-Id: <20200506140208.v2.1.Ibc8eeddcee94984a608d6900b46f9ffde4045da4@changeid> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The ti-sn65dsi86 MIPI DSI to eDP bridge chip supports arbitrary remapping of eDP lanes and also polarity inversion. Both of these features have been described in the device tree bindings for the device since the beginning but were never implemented in the driver. Implement both of them. Part of this change also allows you to (via the same device tree bindings) specify to use fewer than the max number of DP lanes that the panel reports. This could be useful if your display supports more lanes but only a few are hooked up on your board. Signed-off-by: Douglas Anderson Reviewed-by: Stephen Boyd Reviewed-by: Rob Clark --- This patch is based upon my my outstanding series[1] not because there is any real requirement but simply to avoid merge conflicts. I believe that my previous series is ready to land. If, however, you'd prefer that I rebase this patch somewhere atop something else then please shout. [1] https://lore.kernel.org/r/20200430194617.197510-1-dianders@chromium.org Changes in v2: - Use SN_MAX_DP_LANES instead of 4 in one place. - Comment that we aren't doing full validation of dts params. - Check dp_lanes <= SN_MAX_DP_LANES to avoid buffer overrun. - Add missing of_node_put() drivers/gpu/drm/bridge/ti-sn65dsi86.c | 82 ++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c index 1a125423eb07..534b712dccf8 100644 --- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c +++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c @@ -50,8 +50,12 @@ #define SN_CHA_VERTICAL_BACK_PORCH_REG 0x36 #define SN_CHA_HORIZONTAL_FRONT_PORCH_REG 0x38 #define SN_CHA_VERTICAL_FRONT_PORCH_REG 0x3A +#define SN_LN_ASSIGN_REG 0x59 +#define LN_ASSIGN_WIDTH 2 #define SN_ENH_FRAME_REG 0x5A #define VSTREAM_ENABLE BIT(3) +#define LN_POLRS_OFFSET 4 +#define LN_POLRS_MASK 0xf0 #define SN_DATA_FORMAT_REG 0x5B #define BPP_18_RGB BIT(0) #define SN_HPD_DISABLE_REG 0x5C @@ -98,6 +102,7 @@ #define SN_REGULATOR_SUPPLY_NUM 4 +#define SN_MAX_DP_LANES 4 #define SN_NUM_GPIOS 4 /** @@ -115,6 +120,8 @@ * @enable_gpio: The GPIO we toggle to enable the bridge. * @supplies: Data for bulk enabling/disabling our regulators. * @dp_lanes: Count of dp_lanes we're using. + * @ln_assign: Value to program to the LN_ASSIGN register. + * @ln_polr: Value for the 4-bit LN_POLRS field of SN_ENH_FRAME_REG. * * @gchip: If we expose our GPIOs, this is used. * @gchip_output: A cache of whether we've set GPIOs to output. This @@ -140,6 +147,8 @@ struct ti_sn_bridge { struct gpio_desc *enable_gpio; struct regulator_bulk_data supplies[SN_REGULATOR_SUPPLY_NUM]; int dp_lanes; + u8 ln_assign; + u8 ln_polrs; struct gpio_chip gchip; DECLARE_BITMAP(gchip_output, SN_NUM_GPIOS); @@ -707,26 +716,20 @@ static void ti_sn_bridge_enable(struct drm_bridge *bridge) int dp_rate_idx; unsigned int val; int ret = -EINVAL; + int max_dp_lanes; - /* - * Run with the maximum number of lanes that the DP sink supports. - * - * Depending use cases, we might want to revisit this later because: - * - It's plausible that someone may have run fewer lines to the - * sink than the sink actually supports, assuming that the lines - * will just be driven at a higher rate. - * - The DP spec seems to indicate that it's more important to minimize - * the number of lanes than the link rate. - * - * If we do revisit, it would be important to measure the power impact. - */ - pdata->dp_lanes = ti_sn_get_max_lanes(pdata); + max_dp_lanes = ti_sn_get_max_lanes(pdata); + pdata->dp_lanes = min(pdata->dp_lanes, max_dp_lanes); /* DSI_A lane config */ - val = CHA_DSI_LANES(4 - pdata->dsi->lanes); + val = CHA_DSI_LANES(SN_MAX_DP_LANES - pdata->dsi->lanes); regmap_update_bits(pdata->regmap, SN_DSI_LANES_REG, CHA_DSI_LANES_MASK, val); + regmap_write(pdata->regmap, SN_LN_ASSIGN_REG, pdata->ln_assign); + regmap_update_bits(pdata->regmap, SN_ENH_FRAME_REG, LN_POLRS_MASK, + pdata->ln_polrs << LN_POLRS_OFFSET); + /* set dsi clk frequency value */ ti_sn_bridge_set_dsi_rate(pdata); @@ -1063,6 +1066,55 @@ static int ti_sn_setup_gpio_controller(struct ti_sn_bridge *pdata) return ret; } +static void ti_sn_bridge_parse_lanes(struct ti_sn_bridge *pdata, + struct device_node *np) +{ + u32 lane_assignments[SN_MAX_DP_LANES] = { 0, 1, 2, 3 }; + u32 lane_polarities[SN_MAX_DP_LANES] = { }; + struct device_node *endpoint; + u8 ln_assign = 0; + u8 ln_polrs = 0; + int dp_lanes; + int i; + + /* + * Read config from the device tree about lane remapping and lane + * polarities. These are optional and we assume identity map and + * normal polarity if nothing is specified. It's OK to specify just + * data-lanes but not lane-polarities but not vice versa. + * + * Error checking is light (we just make sure we don't crash or + * buffer overrun) and we assume dts is well formed and specifying + * mappings that the hardware supports. + */ + endpoint = of_graph_get_endpoint_by_regs(np, 1, -1); + dp_lanes = of_property_count_u32_elems(endpoint, "data-lanes"); + if (dp_lanes > 0 && dp_lanes <= SN_MAX_DP_LANES) { + of_property_read_u32_array(endpoint, "data-lanes", + lane_assignments, dp_lanes); + of_property_read_u32_array(endpoint, "lane-polarities", + lane_polarities, dp_lanes); + } else { + dp_lanes = SN_MAX_DP_LANES; + } + of_node_put(endpoint); + + /* + * Convert into register format. Loop over all lanes even if + * data-lanes had fewer elements so that we nicely initialize + * the LN_ASSIGN register. + */ + for (i = SN_MAX_DP_LANES - 1; i >= 0; i--) { + ln_assign = ln_assign << LN_ASSIGN_WIDTH | lane_assignments[i]; + ln_polrs = ln_polrs << 1 | lane_polarities[i]; + } + + /* Stash in our struct for when we power on */ + pdata->dp_lanes = dp_lanes; + pdata->ln_assign = ln_assign; + pdata->ln_polrs = ln_polrs; +} + static int ti_sn_bridge_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -1105,6 +1157,8 @@ static int ti_sn_bridge_probe(struct i2c_client *client, return ret; } + ti_sn_bridge_parse_lanes(pdata, client->dev.of_node); + ret = ti_sn_bridge_parse_regulators(pdata); if (ret) { DRM_ERROR("failed to parse regulators\n"); From patchwork Wed May 6 21:02:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 11531875 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 66AAA1392 for ; Wed, 6 May 2020 21:03:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 49B66207DD for ; Wed, 6 May 2020 21:03:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="D6iW4e20" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728665AbgEFVDF (ORCPT ); Wed, 6 May 2020 17:03:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729627AbgEFVDE (ORCPT ); Wed, 6 May 2020 17:03:04 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A182C061A41 for ; Wed, 6 May 2020 14:03:04 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id x15so1743751pfa.1 for ; Wed, 06 May 2020 14:03:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jTg3u14b1jSChok706rtCh0zd7QjZC6auThVS1AFynQ=; b=D6iW4e20bdBvu9vZ4q+2yhDpXY+9Am0tRCu81Dhyy+TifmOTdibQPRuQja2EVK19fY WreYomwshtRjtUvP46bVo9YS8KsZM2rbEQN/0uXvAujvDkzUVef/U0ryQ3Z0cMYh69zp EkUSaDewJjfjp/zQ9hImIR112v3DRjTwU6Vj4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jTg3u14b1jSChok706rtCh0zd7QjZC6auThVS1AFynQ=; b=kgZGrUJFFhtA3p8CAaDhLiCqUMIMrMyoXh8bdY/QFXFJIVxmRTJyCgoFVl3evUFfWB 8ZMu0Sax/4Mwp9DpKnxL5XI/cTUa8C5lzijh1pt3l+ub3gL6FUJ2tIjG40SAMi12GiUR Zc8bknfVSCkqEhtpb7YI+2WNS+S6WlD0yABDGXeJZQ4yMBfJkxwerbIIsznVaFX2nQjH nGZi4DZnECrh5rEgSuO1OjpXfOF3W29K8+DvBONRYdi77crydV/0KiqvlM69iZjYCm0q K6XxdkkZjZmkLBfBEMvfaizfPWWnYT5MR/Ep0ZAHV+9h6ly6ca7BaD9cbFvg2spwCXR/ GixA== X-Gm-Message-State: AGi0PuadzLnxX9uwTp28ZDOrCrCjyYBUuKWbDT18vsPNIhJe5cVZ32Od aoXQ6/bn/xaBKnOkOam9/CFfng== X-Google-Smtp-Source: APiQypJ4p2EB66cdVsjU8aoV6seeh84NlanroNemlQHB07n6r/taT/MsTAE900J1+tl8XNpWPOf5pg== X-Received: by 2002:a63:cf10:: with SMTP id j16mr8528746pgg.201.1588798983499; Wed, 06 May 2020 14:03:03 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id u5sm2256412pgi.70.2020.05.06.14.03.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2020 14:03:02 -0700 (PDT) From: Douglas Anderson To: Andrzej Hajda , Neil Armstrong , Laurent Pinchart Cc: robdclark@chromium.org, seanpaul@chromium.org, swboyd@chromium.org, linux-arm-msm@vger.kernel.org, Douglas Anderson , Daniel Vetter , David Airlie , Linus Walleij , Rob Herring , devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] dt-bindings: drm/bridge: ti-sn65dsi86: Improve the yaml validation Date: Wed, 6 May 2020 14:02:42 -0700 Message-Id: <20200506140208.v2.2.I0a2bca02b09c1fcb6b09479b489736d600b3e57f@changeid> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog In-Reply-To: <20200506140208.v2.1.Ibc8eeddcee94984a608d6900b46f9ffde4045da4@changeid> References: <20200506140208.v2.1.Ibc8eeddcee94984a608d6900b46f9ffde4045da4@changeid> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org This patch adds the following checks to the yaml: - Remapping of the eDP output lanes is now limited to the subset of remappings that the hardware supports. - No more additional properties can be added under 'ports'. This patch fixes the following bugs in the original yaml conversion: - Fixed dependency between 'data-lanes' and 'lane-polarities', which was backwards. Now you can only specify 'lane-polarities' if you specified 'data-lanes'. I could have sworn I tried this before. - We can't remap input lanes in this hardware. This patch doesn't do, but if someone knew how I'd love to: - Make sure if we have both 'lane-polarities' and 'data-lanes' that they have the same number of elements. Signed-off-by: Douglas Anderson --- This patch could be squashed atop the patch adding the yaml [1]. I'm sending separately for now to avoid churning the series another time. [1] https://lore.kernel.org/r/20200430124442.v4.4.Ifcdc4ecb12742a27862744ee1e8753cb95a38a7f@changeid Changes in v2: - ("... Improve the yaml validation") new for v2. .../bindings/display/bridge/ti,sn65dsi86.yaml | 74 ++++++++++--------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/Documentation/devicetree/bindings/display/bridge/ti,sn65dsi86.yaml b/Documentation/devicetree/bindings/display/bridge/ti,sn65dsi86.yaml index 75c4e8b8e4b7..be10e8cf31e1 100644 --- a/Documentation/devicetree/bindings/display/bridge/ti,sn65dsi86.yaml +++ b/Documentation/devicetree/bindings/display/bridge/ti,sn65dsi86.yaml @@ -72,6 +72,7 @@ properties: ports: type: object + additionalProperties: false properties: "#address-cells": @@ -94,33 +95,9 @@ properties: endpoint: type: object additionalProperties: false - properties: remote-endpoint: true - data-lanes: - minItems: 1 - maxItems: 4 - items: - enum: - - 0 - - 1 - - 2 - - 3 - description: See ../../media/video-interface.txt - - lane-polarities: - minItems: 1 - maxItems: 4 - items: - enum: - - 0 - - 1 - description: See ../../media/video-interface.txt - - dependencies: - data-lanes: [lane-polarities] - required: - reg @@ -143,15 +120,44 @@ properties: remote-endpoint: true data-lanes: - minItems: 1 - maxItems: 4 - items: - enum: - - 0 - - 1 - - 2 - - 3 - description: See ../../media/video-interface.txt + oneOf: + - minItems: 1 + maxItems: 1 + uniqueItems: true + items: + enum: + - 0 + - 1 + description: + If you have 1 logical lane the bridge supports routing + to either port 0 or port 1. Port 0 is suggested. + See ../../media/video-interface.txt for details. + + - minItems: 2 + maxItems: 2 + uniqueItems: true + items: + enum: + - 0 + - 1 + description: + If you have 2 logical lanes the bridge supports + reordering but only on physical ports 0 and 1. + See ../../media/video-interface.txt for details. + + - minItems: 4 + maxItems: 4 + uniqueItems: true + items: + enum: + - 0 + - 1 + - 2 + - 3 + description: + If you have 4 logical lanes the bridge supports + reordering in any way. + See ../../media/video-interface.txt for details. lane-polarities: minItems: 1 @@ -163,7 +169,7 @@ properties: description: See ../../media/video-interface.txt dependencies: - data-lanes: [lane-polarities] + lane-polarities: [data-lanes] required: - reg