Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp90215pxb; Thu, 30 Sep 2021 01:39:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweoymAgkaMqb7Kg0B9zKLv8GIPmb6LuwB53byFjK/T6WDrt1t309+a57zx9Us/fC9HJqLL X-Received: by 2002:a17:906:aed1:: with SMTP id me17mr5308417ejb.474.1632991176227; Thu, 30 Sep 2021 01:39:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632991176; cv=none; d=google.com; s=arc-20160816; b=fWQCwq25Wistvl/ymfQt1D2Ydm0PhVJySIYrJl9Wgv3QQ/0pkHue7UuK9Is2kOkrME NulQ7vNd0zoQ20MCwLDob6J1hzbwSsrAuGRDmfRDew/1hEN5B7/GtiTVtGfDn2H4gb/m MSeNfOxKoYPXInTHy7drQ2dU3/EJNY5mXGU636ujnsKUAhdqas53XRGVxvht7FEs12IX TdISFDRNgdTgAUcCRUgPs0zt+x3THXK+8UlVvT70c4wsijmqVgeUM5BLVZXx5tSTWfLa ksU1pVFmLeB8ggcPWuOAfRvLRvQbb0Z8glCJs8t7xTTLLPJNlu89pm9D+KhzVCOE+rCa od8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=LGbeb7yqatBM9JvIBaP/sCPxHKG6Wu7QxG158MI4MrI=; b=UhEQyf5JD8w+0trtLqJvGbADcLO7/P+gI5eCkx7Rfk60Dkxa1jICJPVAcuiDKUA6ER EE1ZduIHCxDcTZ1Y9sapN+v2dYccNKF+WSaH+wUdveB/LmOKmMnWT4v7paT2evJbdJxV FwDxstPr4TrhUGZmzKMkyy3bKVmljoXICVUrVLCn1fyQr8TADHsfjkB+jnfTGZ3JOxna 54VbyPoiQJZ889xnxpFh3ZSBLvKEbwbEF0SJwjioZKVz05b94emOjQ1js5jKRaG0H8rz 2Nt/MWVrK0Zdnpp+00OURaZa5hcDYXGkRKlhg3MYFiwY6F2EQdc8NpK3AmUuKqVcZD5m rdEA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n2si3282433edi.385.2021.09.30.01.39.10; Thu, 30 Sep 2021 01:39:36 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349217AbhI3Id7 (ORCPT + 99 others); Thu, 30 Sep 2021 04:33:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349242AbhI3Idt (ORCPT ); Thu, 30 Sep 2021 04:33:49 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E617C061779 for ; Thu, 30 Sep 2021 01:32:04 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id A49541F449FB From: Enric Balletbo i Serra To: linux-kernel@vger.kernel.org Cc: linux-mediatek@lists.infradead.org, eizan@chromium.org, kernel@collabora.com, drinkcat@chromium.org, jitao.shi@mediatek.com, chunkuang.hu@kernel.org, hsinyi@chromium.org, matthias.bgg@gmail.com, Philipp Zabel , linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 6/7] soc: mediatek: mmsys: Add reset controller support Date: Thu, 30 Sep 2021 10:31:49 +0200 Message-Id: <20210930103105.v4.6.I15e2419141a69b2e5c7e700c34d92a69df47e04d@changeid> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210930083150.3317003-1-enric.balletbo@collabora.com> References: <20210930083150.3317003-1-enric.balletbo@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Among other features the mmsys driver should implement a reset controller to be able to reset different bits from their space. Cc: Jitao Shi Suggested-by: Chun-Kuang Hu Signed-off-by: Enric Balletbo i Serra Reviewed-by: Philipp Zabel --- Changes in v4: - Remove unnused variable as pointed by Hsin-Yi. drivers/soc/mediatek/mtk-mmsys.c | 68 ++++++++++++++++++++++++++++++++ drivers/soc/mediatek/mtk-mmsys.h | 2 + 2 files changed, 70 insertions(+) diff --git a/drivers/soc/mediatek/mtk-mmsys.c b/drivers/soc/mediatek/mtk-mmsys.c index d9bbb0721ff4..132302154349 100644 --- a/drivers/soc/mediatek/mtk-mmsys.c +++ b/drivers/soc/mediatek/mtk-mmsys.c @@ -4,10 +4,12 @@ * Author: James Liao */ +#include #include #include #include #include +#include #include #include "mtk-mmsys.h" @@ -62,6 +64,8 @@ static const struct mtk_mmsys_driver_data mt8365_mmsys_driver_data = { struct mtk_mmsys { void __iomem *regs; const struct mtk_mmsys_driver_data *data; + spinlock_t lock; /* protects mmsys_sw_rst_b reg */ + struct reset_controller_dev rcdev; }; void mtk_mmsys_ddp_connect(struct device *dev, @@ -101,6 +105,58 @@ void mtk_mmsys_ddp_disconnect(struct device *dev, } EXPORT_SYMBOL_GPL(mtk_mmsys_ddp_disconnect); +static int mtk_mmsys_reset_update(struct reset_controller_dev *rcdev, unsigned long id, + bool assert) +{ + struct mtk_mmsys *mmsys = container_of(rcdev, struct mtk_mmsys, rcdev); + unsigned long flags; + u32 reg; + + spin_lock_irqsave(&mmsys->lock, flags); + + reg = readl_relaxed(mmsys->regs + MMSYS_SW0_RST_B); + + if (assert) + reg &= ~BIT(id); + else + reg |= BIT(id); + + writel_relaxed(reg, mmsys->regs + MMSYS_SW0_RST_B); + + spin_unlock_irqrestore(&mmsys->lock, flags); + + return 0; +} + +static int mtk_mmsys_reset_assert(struct reset_controller_dev *rcdev, unsigned long id) +{ + return mtk_mmsys_reset_update(rcdev, id, true); +} + +static int mtk_mmsys_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id) +{ + return mtk_mmsys_reset_update(rcdev, id, false); +} + +static int mtk_mmsys_reset(struct reset_controller_dev *rcdev, unsigned long id) +{ + int ret; + + ret = mtk_mmsys_reset_assert(rcdev, id); + if (ret) + return ret; + + usleep_range(1000, 1100); + + return mtk_mmsys_reset_deassert(rcdev, id); +} + +static const struct reset_control_ops mtk_mmsys_reset_ops = { + .assert = mtk_mmsys_reset_assert, + .deassert = mtk_mmsys_reset_deassert, + .reset = mtk_mmsys_reset, +}; + static int mtk_mmsys_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -121,6 +177,18 @@ static int mtk_mmsys_probe(struct platform_device *pdev) return ret; } + spin_lock_init(&mmsys->lock); + + mmsys->rcdev.owner = THIS_MODULE; + mmsys->rcdev.nr_resets = 32; + mmsys->rcdev.ops = &mtk_mmsys_reset_ops; + mmsys->rcdev.of_node = pdev->dev.of_node; + ret = devm_reset_controller_register(&pdev->dev, &mmsys->rcdev); + if (ret) { + dev_err(&pdev->dev, "Couldn't register mmsys reset controller: %d\n", ret); + return ret; + } + mmsys->data = of_device_get_match_data(&pdev->dev); platform_set_drvdata(pdev, mmsys); diff --git a/drivers/soc/mediatek/mtk-mmsys.h b/drivers/soc/mediatek/mtk-mmsys.h index 9e2b81bd38db..8b0ed05117ea 100644 --- a/drivers/soc/mediatek/mtk-mmsys.h +++ b/drivers/soc/mediatek/mtk-mmsys.h @@ -78,6 +78,8 @@ #define DSI_SEL_IN_RDMA 0x1 #define DSI_SEL_IN_MASK 0x1 +#define MMSYS_SW0_RST_B 0x140 + struct mtk_mmsys_routes { u32 from_comp; u32 to_comp; -- 2.30.2