From patchwork Fri Jun 21 11:55:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Griffin X-Patchwork-Id: 13707428 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DF93CC2BA1A for ; Fri, 21 Jun 2024 11:56:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YyW5+VbIADwYbvLjE/DRg3OiI2Mx9SABmjT69Y7dUKk=; b=A+5ySUv2VEe7g+x6QZnYc36++j //f5WVEkC4n6x4fnJgGdCHPDfVef3gfqxayF54Viwz467wnK4wVN7S/ia4Qa7Si5c6wC845+2xl6P sjQeNZKrVO4vPM/6c1NmhXw20U6LcQ1yObFkZqo75vDMBiX+hXVrhYbZIyopiI8MxPbe7rfetq+Zl T/lvMaRoNLtv++ngtFUpPpSVM1kiV+usDwZD9K6IyvaEczGWiwazj9/ikZBOYzNZxG6LAW6MpLvWd Ressx2t8VV7ysEeYlz+ZV+5cBtI2lza3bPR0ltg2de+o8QozodZXeuOnbdBTfMCwEbpshaogCpR1q 0tBeAzfw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKcry-000000091vM-40Un; Fri, 21 Jun 2024 11:55:54 +0000 Received: from mail-lj1-x230.google.com ([2a00:1450:4864:20::230]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKcrv-000000091tz-0Ekm for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2024 11:55:52 +0000 Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2ec50d4e47bso3428801fa.2 for ; Fri, 21 Jun 2024 04:55:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718970949; x=1719575749; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YyW5+VbIADwYbvLjE/DRg3OiI2Mx9SABmjT69Y7dUKk=; b=ZOmQyyfIVVibcO2kooxiTerzBbTYfp+88GKaeU3RynohOPROzm8ObUq5u6zhs/fBpT ZyBe8FwqLYoVwuxsxuV0Qab9Cq2qSesgB+uNJbc02m6bE5YXalWG7iO64AqvOwRLOFoe oY/1twM2EdaaPdPC7UUUDP/9WOUI+XeG5vTr9i6QzTzV37KD18j281khqFDF7XlPOsjz IxUH4ZTCqYpM5+8gnlsSaRO7VzsJ9zVO011hZbje+fgCIbPv1UJKQ5un6PpSHaKnvdpZ M5SBlFR8JW19TakZwEh7A1ORhCoBPENejmpRFzPCCTr7Kz3Gw1QTaIZDytba2Mp7VQAS CYLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718970949; x=1719575749; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YyW5+VbIADwYbvLjE/DRg3OiI2Mx9SABmjT69Y7dUKk=; b=B3xgbGiX3/zamzvb/CcN1QswymuXDx7ot+7ct47scoY62a2aA8BrFaD0cVdec4weku ZwiENE2y8jF3b3Vbi8epmGe95bXuOHC2GS6QKzOFJlVOYv4udQie34EMUyFdmL8DxeLj tLDjBedIGSipHthX4CyCe317jZse+HO33tx29CK5XIkdJhFo1qRMv6Ul3Y4NvleHivug cQN0DNWO2oWI6/Zj72JNWdgXGb4CqigZ22axjbcIUsKvHQZcDMyo9I0PZ7blZlGoQmNF l7cgbY8iKwuXw+1hIPCukTaCryyFJthq8VLD89/88pll90hXqZNxgJAG6qQYrADaNp02 sJyQ== X-Gm-Message-State: AOJu0YzaHOKbOcRaveqt4/D5HEcS1gcQrgGRBJh2xzvhRz8moLEFrOi1 A6T1n4rEKyOHpuz2pYnqg6/Xm+Ec/cUx1epXWdGxJ2xUo7je0m6/Y57S0kpTqh8= X-Google-Smtp-Source: AGHT+IEK99mzL+zVK5iwlAts85kqCZbOM80etX+4cRw1BqvCAihCDCG8nvU55FlE1jsMiBzfFG2c3A== X-Received: by 2002:a05:6512:e98:b0:52c:cb97:ebba with SMTP id 2adb3069b0e04-52ccb97ec44mr6156327e87.24.1718970948984; Fri, 21 Jun 2024 04:55:48 -0700 (PDT) Received: from gpeter-l.lan ([2a0d:3344:2e8:8510::3aa]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d208dcesm60386725e9.31.2024.06.21.04.55.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 04:55:48 -0700 (PDT) From: Peter Griffin To: lee@kernel.org, arnd@arndb.de, krzk@kernel.org, alim.akhtar@samsung.com Cc: linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, tudor.ambarus@linaro.org, andre.draszik@linaro.org, saravanak@google.com, willmcvicker@google.com, semen.protsenko@linaro.org, kernel-team@android.com, Peter Griffin Subject: [PATCH v3 1/2] mfd: syscon: add of_syscon_register_regmap() API Date: Fri, 21 Jun 2024 12:55:43 +0100 Message-ID: <20240621115544.1655458-2-peter.griffin@linaro.org> X-Mailer: git-send-email 2.45.2.741.gdbec12cfda-goog In-Reply-To: <20240621115544.1655458-1-peter.griffin@linaro.org> References: <20240621115544.1655458-1-peter.griffin@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240621_045551_119246_5AFF86E3 X-CRM114-Status: GOOD ( 20.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The of_syscon_register_regmap() API allows an externally created regmap to be registered with syscon. This regmap can then be returned to client drivers using the syscon_regmap_lookup_by_phandle() APIs. The API is used by platforms where mmio access to the syscon registers is not possible, and a underlying soc driver like exynos-pmu provides a SoC specific regmap that can issue a SMC or hypervisor call to write the register. This approach keeps the SoC complexities out of syscon, but allows common drivers such as syscon-poweroff, syscon-reboot and friends that are used by many SoCs already to be re-used. Signed-off-by: Peter Griffin Reviewed-by: Arnd Bergmann Reviewed-by: Sam Protsenko Tested-by: Will McVicker Reviewed-by: Krzysztof Kozlowski --- Changes in v3: - Move kzalloc allocation outside of spin lock (Arnd) - Link to v2 https://lore.kernel.org/linux-arm-kernel/20240620112446.1286223-2-peter.griffin@linaro.org/ Changes in v2: - Keep syscon lock held between checking and adding entry (Krzysztof) - Link to v1 https://lore.kernel.org/linux-arm-kernel/20240614140421.3172674-2-peter.griffin@linaro.org/ --- drivers/mfd/syscon.c | 48 ++++++++++++++++++++++++++++++++++++++ include/linux/mfd/syscon.h | 8 +++++++ 2 files changed, 56 insertions(+) diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c index 7d0e91164cba..33f1e07ab24d 100644 --- a/drivers/mfd/syscon.c +++ b/drivers/mfd/syscon.c @@ -192,6 +192,54 @@ static struct regmap *device_node_get_regmap(struct device_node *np, return syscon->regmap; } +/** + * of_syscon_register_regmap() - Register regmap for specified device node + * @np: Device tree node + * @regmap: Pointer to regmap object + * + * Register an externally created regmap object with syscon for the specified + * device tree node. This regmap will then be returned to client drivers using + * the syscon_regmap_lookup_by_phandle() API. + * + * Return: 0 on success, negative error code on failure. + */ +int of_syscon_register_regmap(struct device_node *np, struct regmap *regmap) +{ + struct syscon *entry, *syscon = NULL; + int ret; + + if (!np || !regmap) + return -EINVAL; + + syscon = kzalloc(sizeof(*syscon), GFP_KERNEL); + if (!syscon) + return -ENOMEM; + + /* check if syscon entry already exists */ + spin_lock(&syscon_list_slock); + + list_for_each_entry(entry, &syscon_list, list) + if (entry->np == np) { + ret = -EEXIST; + goto err_unlock; + } + + syscon->regmap = regmap; + syscon->np = np; + + /* register the regmap in syscon list */ + list_add_tail(&syscon->list, &syscon_list); + spin_unlock(&syscon_list_slock); + + return 0; + +err_unlock: + spin_unlock(&syscon_list_slock); + kfree(syscon); + return ret; +} +EXPORT_SYMBOL_GPL(of_syscon_register_regmap); + struct regmap *device_node_to_regmap(struct device_node *np) { return device_node_get_regmap(np, false); diff --git a/include/linux/mfd/syscon.h b/include/linux/mfd/syscon.h index c315903f6dab..aad9c6b50463 100644 --- a/include/linux/mfd/syscon.h +++ b/include/linux/mfd/syscon.h @@ -28,6 +28,8 @@ struct regmap *syscon_regmap_lookup_by_phandle_args(struct device_node *np, unsigned int *out_args); struct regmap *syscon_regmap_lookup_by_phandle_optional(struct device_node *np, const char *property); +int of_syscon_register_regmap(struct device_node *np, + struct regmap *regmap); #else static inline struct regmap *device_node_to_regmap(struct device_node *np) { @@ -67,6 +69,12 @@ static inline struct regmap *syscon_regmap_lookup_by_phandle_optional( return NULL; } +static inline int of_syscon_register_regmap(struct device_node *np, + struct regmap *regmap) +{ + return -EOPNOTSUPP; +} + #endif #endif /* __LINUX_MFD_SYSCON_H__ */ From patchwork Fri Jun 21 11:55:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Griffin X-Patchwork-Id: 13707429 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C4A5CC27C4F for ; Fri, 21 Jun 2024 11:56:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LsZYfymlFvkNaC7UR+89xyL8YV5RjgSwqJCekyf0v2g=; b=Vl/hpsaXh57ZNwwG83K+rmjcRN o0CeCANkFBg6RI0GdajCvL463NLQoFnRJ29/98MEBg+sA2E8f3Ry05QyFec1IX79BiRBADh7a79Nh MTMwGa82vzirMOFdDqzD0zaXNUV/OEICwnSp1HAyqbcqFTx45h+uWKso0PiNbGb9hdbQnYx0+Yeh4 N53BXUhIAg/3Y8p9Ikxoflwetu/TqmKnNk/zCISPKUeSZeWOKsiiFY7Q4PZ8421OabU5YTBNy/V5o 9YqZsvFrWbzU7hNh3igRDC2kFW0CyQpL5QuX37jzp6m1gS3m8fag1rkn64wHDaDtQnI4XQuJ1oDU3 2VD8eqSw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKcs0-000000091vZ-2Es3; Fri, 21 Jun 2024 11:55:56 +0000 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKcrw-000000091uI-0QBp for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2024 11:55:53 +0000 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-52cd8897c73so491589e87.2 for ; Fri, 21 Jun 2024 04:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718970950; x=1719575750; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LsZYfymlFvkNaC7UR+89xyL8YV5RjgSwqJCekyf0v2g=; b=hc4n5MytQip4/ySMrD+TaK/dih6jCngpmpZM+GdCTEljuDOHu3g95JNlQMO0I2k8mT jMyoHNpTWMjF3jRWwoF+fUMhf1KO4r6qGO6kcJwje/D/twNfbVKBbfrvLnG2DYxNN4Ys KVRIJj3ftM6Jaop2d1o6TRGlvxutVfc2CGwuCQIDvnSIsD+q4fEgAlpU9zxK4kpCF+Ke Gshf8JTHwLLN+XXJZMcn9DRzG2PXFG1LR4cdEbyET4erMeVWXJ6FpbmQJp3+cS+vdoKl 1inMwBAw13BEvk4uI/M7Cm4X2sQ8UX2UxtpjIHPMdTefh5oPnS3hXcQdpCsO0hzTe5Ej bRsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718970950; x=1719575750; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LsZYfymlFvkNaC7UR+89xyL8YV5RjgSwqJCekyf0v2g=; b=GTwuRDXKUIMp2wuqGn2fh0SO692KpWdj2vHApR7j+rCPQNv31KOU3L4Ck6JAIFwxOf phhg3xiKalpgYvh5a5F+rgSOzjxnlgJLiOV8kv4QEWniJIIBXs1a2zlAqJtSJsOYnYb8 R8qJIbunhVDIQiIJIYpnV6bWmlSKneKiKpxq8MmXix268wh7mOwc9sN1i5ndVAVFrFe5 wQAGUCq06pzRUNZy4UrkkhQsWg8uVmLaRbGa1Zy6x/usqyIB0tiwl/ETy3J5CJSQNXI/ cfnd+yV3qmZxwlhAA03kzqCQr2kS/BRyYLdLiJpTz18L5b6EaXGLlIEBzoF6kGr7y7i/ xEuA== X-Gm-Message-State: AOJu0Yy+O1mlur2N8KqYkb5crgwKBnxXAnxutb2LqEBurdbjhi0PExlz 1W+vpXdql2N/7cEXSokyfVX9LBPq4OwHRoHq5hGZ1CUsrz39JOr0aTx6TeI24Hg= X-Google-Smtp-Source: AGHT+IFGgH1vCBp0//n23+QcNNqzHrghhJighi2ENZGyzTBy64LZfl2gFclPwco/HnFbFKAV9o2QbA== X-Received: by 2002:ac2:52b2:0:b0:52b:796e:66a5 with SMTP id 2adb3069b0e04-52ccaaa2607mr4436785e87.66.1718970950311; Fri, 21 Jun 2024 04:55:50 -0700 (PDT) Received: from gpeter-l.lan ([2a0d:3344:2e8:8510::3aa]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d208dcesm60386725e9.31.2024.06.21.04.55.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 04:55:49 -0700 (PDT) From: Peter Griffin To: lee@kernel.org, arnd@arndb.de, krzk@kernel.org, alim.akhtar@samsung.com Cc: linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, tudor.ambarus@linaro.org, andre.draszik@linaro.org, saravanak@google.com, willmcvicker@google.com, semen.protsenko@linaro.org, kernel-team@android.com, Peter Griffin Subject: [PATCH v3 2/2] soc: samsung: exynos-pmu: update to use of_syscon_register_regmap() Date: Fri, 21 Jun 2024 12:55:44 +0100 Message-ID: <20240621115544.1655458-3-peter.griffin@linaro.org> X-Mailer: git-send-email 2.45.2.741.gdbec12cfda-goog In-Reply-To: <20240621115544.1655458-1-peter.griffin@linaro.org> References: <20240621115544.1655458-1-peter.griffin@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240621_045552_162721_52A77D55 X-CRM114-Status: GOOD ( 16.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org For SoCs like gs101 that need a special regmap, register this with of_syscon_register_regmap api, so it can be returned by syscon_regmap_lookup_by_phandle() and friends. For SoCs that don't require a custom regmap, revert back to syscon creating the mmio regmap rather than duplicating the logic here. exynos_get_pmu_regmap_by_phandle() api is also updated to retrieve the regmap via syscon. The exynos_get_pmu_regmap_by_phandle() api is kept around until fw_devlink support for syscon property is added for the pinctrl-samsung driver that also runs at postcore_initcall level. All other exynos client drivers can revert back to syscon_regmap_lookup_by_phandle(). Signed-off-by: Peter Griffin Reviewed-by: Arnd Bergmann Reviewed-by: Sam Protsenko Tested-by: Will McVicker Reviewed-by: Krzysztof Kozlowski --- Changes in v2: - None - Link to v2: https://lore.kernel.org/linux-arm-kernel/20240620112446.1286223-3-peter.griffin@linaro.org/ Changes since v1: - pass pmu_np (not np) to syscon_node_to_regmap() (reported by William) - Link to v1: https://lore.kernel.org/linux-arm-kernel/20240614140421.3172674-3-peter.griffin@linaro.org/ --- drivers/soc/samsung/exynos-pmu.c | 38 ++++++++++++-------------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/drivers/soc/samsung/exynos-pmu.c b/drivers/soc/samsung/exynos-pmu.c index fd8b6ac06656..624324f4001c 100644 --- a/drivers/soc/samsung/exynos-pmu.c +++ b/drivers/soc/samsung/exynos-pmu.c @@ -204,16 +204,6 @@ static const struct regmap_config regmap_smccfg = { .reg_update_bits = tensor_sec_update_bits, }; -static const struct regmap_config regmap_mmiocfg = { - .name = "pmu_regs", - .reg_bits = 32, - .reg_stride = 4, - .val_bits = 32, - .fast_io = true, - .use_single_read = true, - .use_single_write = true, -}; - static const struct exynos_pmu_data gs101_pmu_data = { .pmu_secure = true }; @@ -290,7 +280,6 @@ EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap); struct regmap *exynos_get_pmu_regmap_by_phandle(struct device_node *np, const char *propname) { - struct exynos_pmu_context *ctx; struct device_node *pmu_np; struct device *dev; @@ -316,9 +305,7 @@ struct regmap *exynos_get_pmu_regmap_by_phandle(struct device_node *np, if (!dev) return ERR_PTR(-EPROBE_DEFER); - ctx = dev_get_drvdata(dev); - - return ctx->pmureg; + return syscon_node_to_regmap(pmu_np); } EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap_by_phandle); @@ -355,19 +342,22 @@ static int exynos_pmu_probe(struct platform_device *pdev) regmap = devm_regmap_init(dev, NULL, (void *)(uintptr_t)res->start, &pmu_regmcfg); + + if (IS_ERR(regmap)) + return dev_err_probe(&pdev->dev, PTR_ERR(regmap), + "regmap init failed\n"); + + ret = of_syscon_register_regmap(dev->of_node, regmap); + if (ret) + return ret; } else { - /* All other SoCs use a MMIO regmap */ - pmu_regmcfg = regmap_mmiocfg; - pmu_regmcfg.max_register = resource_size(res) - - pmu_regmcfg.reg_stride; - regmap = devm_regmap_init_mmio(dev, pmu_base_addr, - &pmu_regmcfg); + /* let syscon create mmio regmap */ + regmap = syscon_node_to_regmap(dev->of_node); + if (IS_ERR(regmap)) + return dev_err_probe(&pdev->dev, PTR_ERR(regmap), + "syscon_node_to_regmap failed\n"); } - if (IS_ERR(regmap)) - return dev_err_probe(&pdev->dev, PTR_ERR(regmap), - "regmap init failed\n"); - pmu_context->pmureg = regmap; pmu_context->dev = dev;