Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2116597imm; Tue, 10 Jul 2018 13:37:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcVl9qK/L3JKU2B2JA+7tOw5/Hs0yBOmNyV2uXAmJ9SVtovqOfuURgUJQxju2fnMxIMOMi+ X-Received: by 2002:a63:4b1f:: with SMTP id y31-v6mr24471449pga.14.1531255024442; Tue, 10 Jul 2018 13:37:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531255024; cv=none; d=google.com; s=arc-20160816; b=Mj+9c1FPT0YyCXU29RS78qpf3qWP0NoxxKf5JYZDJYmYPKD0vbdrrMKgxJMh/cm0yk s7TiEUI6ja7ax3SYbRVMMdGpnrTonSNav9GlI1YZFzcStvInqKdTqf5Mu8SWxjzPvCLP fMWGCSBxSKbaiBq8Dd9yFWdisuEIen4aUXNZDiXh1Dagxxl8f3bJZF6tjD7F/3IDItw9 2tNEkGNvtzE55hkeW0Y1t+9vxCfgixvniZsNIp1DTgkBIHZyI5WP8xoU7fmXtFC0Nq2P MpocvfG0NEDgfNWZtOwvmSg5JsLPOJIzXGcrxVQtnxLKFJLGMcmK9tzBLkBNm/tMrk6O XsYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=cPDEQtVdTXFTBwWzO8xNoG3b7pVMLYoS5S3ZTZqu++Q=; b=rfecVnyLGwxCeSPZT9wsP5GkgcaMqEo5828nwVVB1niyt5DRL2ELZp7r3O7H9yN0Pa +q5nWic6vwM/c1Rc+hVhTEWlDG1U1HE98RqVZl2ScM3MjVofGfvr0TdXkoA76Lw6OsTj 9NEGU/xj788MUlPtdC8dLZZU9FHofqAzs6pPm4bJfqUG7XKUR0d8FRHFg1OQNhxFMLxh c8vYNLUWMbQS7gthH7rBOKnQc/Zx72YUS6bkOTLswjfg+Xvf079eBBQoGekLv+nX8CYv lkrdVr4NilfWogbuNPztUFabMszP2foDz+7aDsB7/RdhL5FojcZ2z3jFx5Ybx2BlOImt Cjpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si17197193plj.411.2018.07.10.13.36.48; Tue, 10 Jul 2018 13:37:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733004AbeGJUgd (ORCPT + 99 others); Tue, 10 Jul 2018 16:36:33 -0400 Received: from mailoutvs37.siol.net ([185.57.226.228]:47470 "EHLO mail.siol.net" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732333AbeGJUgc (ORCPT ); Tue, 10 Jul 2018 16:36:32 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.siol.net (Zimbra) with ESMTP id A7DA552271F; Tue, 10 Jul 2018 22:35:48 +0200 (CEST) X-Virus-Scanned: amavisd-new at psrvmta12.zcs-production.pri Received: from mail.siol.net ([127.0.0.1]) by localhost (psrvmta12.zcs-production.pri [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 7vSh_yrvUsue; Tue, 10 Jul 2018 22:35:48 +0200 (CEST) Received: from mail.siol.net (localhost [127.0.0.1]) by mail.siol.net (Zimbra) with ESMTPS id 19BC5522724; Tue, 10 Jul 2018 22:35:48 +0200 (CEST) Received: from localhost.localdomain (unknown [194.152.15.144]) (Authenticated sender: 031275009) by mail.siol.net (Zimbra) with ESMTPSA id A8F0252272E; Tue, 10 Jul 2018 22:35:45 +0200 (CEST) From: Jernej Skrabec To: maxime.ripard@bootlin.com, wens@csie.org, robh+dt@kernel.org Cc: airlied@linux.ie, mark.rutland@arm.com, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com Subject: [PATCH v2 11/18] drm/sun4i: tcon-top: Add helpers for mux switching Date: Tue, 10 Jul 2018 22:35:04 +0200 Message-Id: <20180710203511.18454-12-jernej.skrabec@siol.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180710203511.18454-1-jernej.skrabec@siol.net> References: <20180710203511.18454-1-jernej.skrabec@siol.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We want to be able to set TCON TOP muxes at runtime. Add helpers for that. Old, static configuration of muxes at probe time is preserved for now. It will be removed when R40 TCON starts using them. Reviewed-by: Chen-Yu Tsai Signed-off-by: Jernej Skrabec --- drivers/gpu/drm/sun4i/sun8i_tcon_top.c | 74 ++++++++++++++++++++++++++ drivers/gpu/drm/sun4i/sun8i_tcon_top.h | 4 ++ 2 files changed, 78 insertions(+) diff --git a/drivers/gpu/drm/sun4i/sun8i_tcon_top.c b/drivers/gpu/drm/sun4i/sun8i_tcon_top.c index 9fb51940156f..c09b15b64192 100644 --- a/drivers/gpu/drm/sun4i/sun8i_tcon_top.c +++ b/drivers/gpu/drm/sun4i/sun8i_tcon_top.c @@ -14,6 +14,79 @@ #include "sun8i_tcon_top.h" +static bool sun8i_tcon_top_node_is_tcon_top(struct device_node *node) +{ + return !!of_match_node(sun8i_tcon_top_of_table, node); +} + +int sun8i_tcon_top_set_hdmi_src(struct device *dev, int tcon) +{ + struct sun8i_tcon_top *tcon_top = dev_get_drvdata(dev); + unsigned long flags; + u32 val; + + if (!sun8i_tcon_top_node_is_tcon_top(dev->of_node)) { + dev_err(dev, "Device is not TCON TOP!\n"); + return -EINVAL; + } + + if (tcon < 2 || tcon > 3) { + dev_err(dev, "TCON index must be 2 or 3!\n"); + return -EINVAL; + } + + spin_lock_irqsave(&tcon_top->reg_lock, flags); + + val = readl(tcon_top->regs + TCON_TOP_GATE_SRC_REG); + val &= ~TCON_TOP_HDMI_SRC_MSK; + val |= FIELD_PREP(TCON_TOP_HDMI_SRC_MSK, tcon - 1); + writel(val, tcon_top->regs + TCON_TOP_GATE_SRC_REG); + + spin_unlock_irqrestore(&tcon_top->reg_lock, flags); + + return 0; +} +EXPORT_SYMBOL(sun8i_tcon_top_set_hdmi_src); + +int sun8i_tcon_top_de_config(struct device *dev, int mixer, int tcon) +{ + struct sun8i_tcon_top *tcon_top = dev_get_drvdata(dev); + unsigned long flags; + u32 reg; + + if (!sun8i_tcon_top_node_is_tcon_top(dev->of_node)) { + dev_err(dev, "Device is not TCON TOP!\n"); + return -EINVAL; + } + + if (mixer > 1) { + dev_err(dev, "Mixer index is too high!\n"); + return -EINVAL; + } + + if (tcon > 3) { + dev_err(dev, "TCON index is too high!\n"); + return -EINVAL; + } + + spin_lock_irqsave(&tcon_top->reg_lock, flags); + + reg = readl(tcon_top->regs + TCON_TOP_PORT_SEL_REG); + if (mixer == 0) { + reg &= ~TCON_TOP_PORT_DE0_MSK; + reg |= FIELD_PREP(TCON_TOP_PORT_DE0_MSK, tcon); + } else { + reg &= ~TCON_TOP_PORT_DE1_MSK; + reg |= FIELD_PREP(TCON_TOP_PORT_DE1_MSK, tcon); + } + writel(reg, tcon_top->regs + TCON_TOP_PORT_SEL_REG); + + spin_unlock_irqrestore(&tcon_top->reg_lock, flags); + + return 0; +} +EXPORT_SYMBOL(sun8i_tcon_top_de_config); + static int sun8i_tcon_top_get_connected_ep_id(struct device_node *node, int port_id) { @@ -109,6 +182,7 @@ static int sun8i_tcon_top_bind(struct device *dev, struct device *master, res = platform_get_resource(pdev, IORESOURCE_MEM, 0); regs = devm_ioremap_resource(dev, res); + tcon_top->regs = regs; if (IS_ERR(regs)) return PTR_ERR(regs); diff --git a/drivers/gpu/drm/sun4i/sun8i_tcon_top.h b/drivers/gpu/drm/sun4i/sun8i_tcon_top.h index 39838bbfeaee..0390584a330e 100644 --- a/drivers/gpu/drm/sun4i/sun8i_tcon_top.h +++ b/drivers/gpu/drm/sun4i/sun8i_tcon_top.h @@ -26,6 +26,7 @@ struct sun8i_tcon_top { struct clk *bus; struct clk_hw_onecell_data *clk_data; + void __iomem *regs; struct reset_control *rst; /* @@ -37,4 +38,7 @@ struct sun8i_tcon_top { extern const struct of_device_id sun8i_tcon_top_of_table[]; +int sun8i_tcon_top_set_hdmi_src(struct device *dev, int tcon); +int sun8i_tcon_top_de_config(struct device *dev, int mixer, int tcon); + #endif /* _SUN8I_TCON_TOP_H_ */ -- 2.18.0