From patchwork Mon Dec 9 05:08:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11278825 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 73AFB930 for ; Mon, 9 Dec 2019 09:46:50 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5C2DF20726 for ; Mon, 9 Dec 2019 09:46:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C2DF20726 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CE4156E343; Mon, 9 Dec 2019 09:46:37 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2A60D6E0E8 for ; Mon, 9 Dec 2019 05:09:06 +0000 (UTC) Received: by mail-pf1-x444.google.com with SMTP id s18so6579807pfm.4 for ; Sun, 08 Dec 2019 21:09:06 -0800 (PST) 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=0XEcja4j0Y7wjAXUdzpkpUFGjQtVSvVgIR5k+TIOO3A=; b=G5bQX0hfZgnfX71VPuLTO68n9CzDsmeTRWCgFwC8KEaAzq5foVDopQCovw5raL9T1Y kfbyMqBPQtCk6YZZhL8RKPBg6hhF6IPLvHAAeOfxi8qnVsrq1L8nEd37jCmX5Sk9piyN KAq4gMUnmc1ulM2XhzTqRIL0S29aK4X537qoqECHy8X2xrmby2F+oKyoHVAfvDMxkaFu sXRz9QE85UkdsutxP1lzETwm3DU8JfdQXMl1Ew2WayFzC1aBFqR6dUyMrZsuBUDBHd9C FkJW+e8zG5Baf6PJimFeAZ2aBNqz2Tp8yhT+IAh2+HFWPsWkpoPuKMu1RBvP0I4SfiOj NlGw== X-Gm-Message-State: APjAAAV4G8NieibrNLijNIeO/gvVdKXbYRaRLx+apLL9axwVyvylJdHB GJsXbg6kUsh+UA/uCa6+hUVsMgO4Zvs= X-Google-Smtp-Source: APXvYqwajQf/Bi8UAd63eQFE7lsxK1wBbKgiKULZAysTm170wg2Z4MW+U4HqpikvYcXF2/agV8Hvcw== X-Received: by 2002:a62:2a12:: with SMTP id q18mr3738243pfq.203.1575868145350; Sun, 08 Dec 2019 21:09:05 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id k15sm25752119pfg.37.2019.12.08.21.09.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 21:09:04 -0800 (PST) From: Andrey Smirnov To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 2/2] drm/bridge: tc358767: Expose test mode functionality via debugfs Date: Sun, 8 Dec 2019 21:08:57 -0800 Message-Id: <20191209050857.31624-3-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191209050857.31624-1-andrew.smirnov@gmail.com> References: <20191209050857.31624-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 09 Dec 2019 09:46:36 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0XEcja4j0Y7wjAXUdzpkpUFGjQtVSvVgIR5k+TIOO3A=; b=Byl0tHTW1y0U1nhXhbir9SOQQUeoUvfSopB4RAvpD3us/55LRl2d2XvYDcEkv2YoQt gYDAvtunNSXfWf3T1WsWB6Ufg28MFe0a0BZElON27SPZiDDb/rIlRZnUhTg4zbt+kJDQ HPjDy8jXUS8+86QGGTuyo1wDwzYk1YBQ7Tl9kgVXwPDRAQCJdUtpbNnkLvIL4PfkjH0x 0m7GmwAbyKQKt7b6hJuy/XQKdgI1NWARM4UqHsMzt5JOIM+H/bnIqQTh+RConkfOGNAB GScPalGMLvGANYC4pjyrvBkPeSN0YE9+92jDi/ppSRyMy7x5I8NCAa1/IbtJ4+MRhyz/ BPug== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cory Tusar , Andrey Smirnov , linux-kernel@vger.kernel.org, Tomi Valkeinen , Laurent Pinchart , Chris Healy Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Presently, the driver code artificially limits test pattern mode to a single pattern with fixed color selection. It being a kernel module parameter makes switching "test pattern" <-> "proper output" modes on-the-fly clunky and outright impossible if the driver is built into the kernel. To improve the situation a bit, convert current test pattern code to use debugfs instead by exposing "TestCtl" register. This way old "tc_test_pattern=1" functionality can be emulated via: echo -n 0x78146302 > tstctl and switch back to regular mode can be done with: echo -n 0x78146300 > tstctl Note that switching to any of the test patterns, will NOT trigger link re-establishment whereas switching to normal operation WILL. This is done so: a) we can isolate and verify (e)DP link functionality by switching to one of the test patters b) trigger a link re-establishment by switching back to normal mode Signed-off-by: Andrey Smirnov Cc: Andrzej Hajda Cc: Laurent Pinchart Cc: Tomi Valkeinen Cc: Cory Tusar Cc: Chris Healy Cc: Lucas Stach Cc: dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org --- drivers/gpu/drm/bridge/tc358767.c | 152 ++++++++++++++++++++++++------ 1 file changed, 125 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/bridge/tc358767.c b/drivers/gpu/drm/bridge/tc358767.c index 3c252ae0ee6f..12a8829e0ed1 100644 --- a/drivers/gpu/drm/bridge/tc358767.c +++ b/drivers/gpu/drm/bridge/tc358767.c @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -221,11 +222,10 @@ #define COLOR_B GENMASK(15, 8) #define ENI2CFILTER BIT(4) #define COLOR_BAR_MODE GENMASK(1, 0) +#define COLOR_BAR_MODE_NORMAL 0 #define COLOR_BAR_MODE_BARS 2 -#define PLL_DBG 0x0a04 -static bool tc_test_pattern; -module_param_named(test, tc_test_pattern, bool, 0644); +#define PLL_DBG 0x0a04 struct tc_edp_link { struct drm_dp_link base; @@ -263,6 +263,9 @@ struct tc_data { /* HPD pin number (0 or 1) or -ENODEV */ int hpd_pin; + + struct mutex tstctl_lock; + bool enabled; }; static inline struct tc_data *aux_to_tc(struct drm_dp_aux *a) @@ -791,16 +794,6 @@ static int tc_set_video_mode(struct tc_data *tc, if (ret) return ret; - /* Test pattern settings */ - ret = regmap_write(tc->regmap, TSTCTL, - FIELD_PREP(COLOR_R, 120) | - FIELD_PREP(COLOR_G, 20) | - FIELD_PREP(COLOR_B, 99) | - ENI2CFILTER | - FIELD_PREP(COLOR_BAR_MODE, COLOR_BAR_MODE_BARS)); - if (ret) - return ret; - /* DP Main Stream Attributes */ vid_sync_dly = hsync_len + left_margin + mode->hdisplay; ret = regmap_write(tc->regmap, DP0_VIDSYNCDELAY, @@ -1152,14 +1145,6 @@ static int tc_stream_enable(struct tc_data *tc) dev_dbg(tc->dev, "enable video stream\n"); - /* PXL PLL setup */ - if (tc_test_pattern) { - ret = tc_pxl_pll_en(tc, clk_get_rate(tc->refclk), - 1000 * tc->mode.clock); - if (ret) - return ret; - } - ret = tc_set_video_mode(tc, &tc->mode); if (ret) return ret; @@ -1188,12 +1173,8 @@ static int tc_stream_enable(struct tc_data *tc) if (ret) return ret; /* Set input interface */ - value = DP0_AUDSRC_NO_INPUT; - if (tc_test_pattern) - value |= DP0_VIDSRC_COLOR_BAR; - else - value |= DP0_VIDSRC_DPI_RX; - ret = regmap_write(tc->regmap, SYSCTRL, value); + ret = regmap_write(tc->regmap, SYSCTRL, + DP0_AUDSRC_NO_INPUT | DP0_VIDSRC_DPI_RX); if (ret) return ret; @@ -1252,8 +1233,13 @@ static void tc_bridge_enable(struct drm_bridge *bridge) { struct tc_data *tc = bridge_to_tc(bridge); + mutex_lock(&tc->tstctl_lock); + if (!__tc_bridge_enable(tc)) drm_panel_enable(tc->panel); + + tc->enabled = true; + mutex_unlock(&tc->tstctl_lock); } static int __tc_bridge_disable(struct tc_data *tc) @@ -1275,8 +1261,13 @@ static void tc_bridge_disable(struct drm_bridge *bridge) { struct tc_data *tc = bridge_to_tc(bridge); + mutex_lock(&tc->tstctl_lock); + drm_panel_disable(tc->panel); __tc_bridge_disable(tc); + + tc->enabled = false; + mutex_unlock(&tc->tstctl_lock); } static void tc_bridge_post_disable(struct drm_bridge *bridge) @@ -1388,6 +1379,99 @@ static enum drm_connector_status tc_connector_detect(struct drm_connector *conne return connector_status_disconnected; } +static int tc_tstctl_set(void *data, u64 val) +{ + struct tc_data *tc = data; + int ret; + + mutex_lock(&tc->tstctl_lock); + + if (!tc->enabled) { + dev_err(tc->dev, "bridge needs to be enabled first\n"); + ret = -EBUSY; + goto unlock; + } + + if (FIELD_GET(COLOR_BAR_MODE, val) == COLOR_BAR_MODE_NORMAL) { + ret = regmap_write(tc->regmap, SYSCTRL, DP0_VIDSRC_DPI_RX); + if (ret) { + dev_err(tc->dev, + "failed to select dpi video stream\n"); + goto unlock; + } + + ret = regmap_write(tc->regmap, TSTCTL, val | ENI2CFILTER); + if (ret) { + dev_err(tc->dev, "failed to set TSTCTL\n"); + goto unlock; + } + + ret = tc_pxl_pll_dis(tc); + if (ret) { + dev_err(tc->dev, "failed to disable PLL\n"); + goto unlock; + } + + /* + * Re-establish DP link + */ + ret = __tc_bridge_disable(tc); + if (ret) + goto unlock; + + ret = __tc_bridge_enable(tc); + if (ret) + goto unlock; + } else { + ret = tc_pxl_pll_en(tc, clk_get_rate(tc->refclk), + 1000 * tc->mode.clock); + if (ret) { + dev_err(tc->dev, "failed to enable PLL\n"); + goto unlock; + } + + ret = regmap_write(tc->regmap, TSTCTL, val | ENI2CFILTER); + if (ret) { + dev_err(tc->dev, "failed to set TSTCTL\n"); + goto unlock; + } + + ret = regmap_write(tc->regmap, SYSCTRL, DP0_VIDSRC_COLOR_BAR); + if (ret) { + dev_err(tc->dev, "failed to set SYSCTRL\n"); + goto unlock; + } + } + +unlock: + mutex_unlock(&tc->tstctl_lock); + return ret; +} +/* + * "tstctl" attribute has the following format: + * + * RR_GG_BB_0_P + * + * "RR" is red, "GG" is green and "BB" is blue color components (byte + * each) used for various test patterns controlled by this register. + * + * "P" represents test pattern of the bridge. Valid values are: + * + * "0" - normal operation + * "1" - solid color test pattern + * "2" - color bar test pattern + * "3" - "checkers" test pattern + * + * This way old "tc_test_pattern=1" functionality can be emulated via: + * + * echo -n 0x78146302 > tstctl + * + * and switch back to regular mode can be done with: + * + * echo -n 0 > tstctl + */ +DEFINE_SIMPLE_ATTRIBUTE(tc_tstctl_fops, NULL, tc_tstctl_set, "%llu\n"); + static const struct drm_connector_funcs tc_connector_funcs = { .detect = tc_connector_detect, .fill_modes = drm_helper_probe_single_connector_modes, @@ -1530,9 +1614,15 @@ static irqreturn_t tc_irq_handler(int irq, void *arg) return IRQ_HANDLED; } +static void tc_remove_debugfs(void *data) +{ + debugfs_remove_recursive(data); +} + static int tc_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct device *dev = &client->dev; + struct dentry *debugfs; struct tc_data *tc; int ret; @@ -1541,6 +1631,7 @@ static int tc_probe(struct i2c_client *client, const struct i2c_device_id *id) return -ENOMEM; tc->dev = dev; + mutex_init(&tc->tstctl_lock); /* port@2 is the output port */ ret = drm_of_find_panel_or_bridge(dev->of_node, 2, 0, &tc->panel, NULL); @@ -1671,6 +1762,13 @@ static int tc_probe(struct i2c_client *client, const struct i2c_device_id *id) i2c_set_clientdata(client, tc); + debugfs = debugfs_create_dir(dev_name(dev), NULL); + if (!IS_ERR(debugfs)) { + debugfs_create_file_unsafe("tstctl", 0200, debugfs, tc, + &tc_tstctl_fops); + devm_add_action_or_reset(dev, tc_remove_debugfs, debugfs); + } + return 0; }