From: Sam Protsenko <semen.protsenko@linaro.org>
To: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
Rob Herring <robh+dt@kernel.org>
Cc: Alim Akhtar <alim.akhtar@samsung.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Chanwoo Choi <cw00.choi@samsung.com>,
Chanho Park <chanho61.park@samsung.com>,
David Virag <virag.david003@gmail.com>,
linux-arm-kernel@lists.infradead.org,
linux-samsung-soc@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 4/6] soc: samsung: pm_domains: Implement proper I/O operations
Date: Wed, 8 Mar 2023 17:09:29 -0600 [thread overview]
Message-ID: <20230308230931.27261-5-semen.protsenko@linaro.org> (raw)
In-Reply-To: <20230308230931.27261-1-semen.protsenko@linaro.org>
Instead of doing in-place readl()/writel() calls fed with magic numbers,
provide dedicated read/write functions which implement proper register
accesses:
- Get rid of magic numbers by introducing actual constants for PD
registers
- Rework the write function to perform a RMW operation, as PD
registers have some bits markes as "Reserved" in TRM, which
shouldn't be changed
- Add helper functions for reading the STATUS reg and writing
CONFIGURATION reg, to make user code more neat and clean
New functions are designed in such a way that it's easy to rework those
further on top of regmap API.
Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
---
drivers/soc/samsung/pm_domains.c | 42 +++++++++++++++++++++++++++++---
1 file changed, 38 insertions(+), 4 deletions(-)
diff --git a/drivers/soc/samsung/pm_domains.c b/drivers/soc/samsung/pm_domains.c
index 522a43005a5a..dd1ec3541e11 100644
--- a/drivers/soc/samsung/pm_domains.c
+++ b/drivers/soc/samsung/pm_domains.c
@@ -18,6 +18,10 @@
#include <linux/of_platform.h>
#include <linux/pm_runtime.h>
+/* Register offsets inside Power Domain area in PMU */
+#define EXYNOS_PD_CONF 0x0
+#define EXYNOS_PD_STATUS 0x4
+
struct exynos_pm_domain_config {
/* Value for LOCAL_PWR_CFG and STATUS fields for each domain */
u32 local_pwr_cfg;
@@ -33,6 +37,37 @@ struct exynos_pm_domain {
u32 local_pwr_cfg;
};
+static void exynos_pd_write(struct exynos_pm_domain *pd, unsigned int reg,
+ unsigned int mask, unsigned int val)
+{
+ u32 v;
+
+ v = readl_relaxed(pd->base + reg);
+ v = (v & ~mask) | val;
+ writel_relaxed(v, pd->base + reg);
+}
+
+static void exynos_pd_read(struct exynos_pm_domain *pd, unsigned int reg,
+ unsigned int *val)
+{
+ *val = readl_relaxed(pd->base + reg);
+}
+
+static unsigned int exynos_pd_read_status(struct exynos_pm_domain *pd)
+{
+ unsigned int val;
+
+ exynos_pd_read(pd, EXYNOS_PD_STATUS, &val);
+ val &= pd->local_pwr_cfg;
+
+ return val;
+}
+
+static void exynos_pd_write_conf(struct exynos_pm_domain *pd, u32 val)
+{
+ exynos_pd_write(pd, EXYNOS_PD_CONF, pd->local_pwr_cfg, val);
+}
+
static int exynos_pd_power(struct generic_pm_domain *domain, bool power_on)
{
struct exynos_pm_domain *pd;
@@ -44,12 +79,12 @@ static int exynos_pd_power(struct generic_pm_domain *domain, bool power_on)
base = pd->base;
pwr = power_on ? pd->local_pwr_cfg : 0;
- writel_relaxed(pwr, base);
+ exynos_pd_write_conf(pd, pwr);
/* Wait max 1ms */
timeout = 10;
- while ((readl_relaxed(base + 0x4) & pd->local_pwr_cfg) != pwr) {
+ while (exynos_pd_read_status(pd) != pwr) {
if (!timeout) {
op = (power_on) ? "enable" : "disable";
pr_err("Power domain %s %s failed\n", domain->name, op);
@@ -135,8 +170,7 @@ static int exynos_pd_probe(struct platform_device *pdev)
pd->pd.power_off = exynos_pd_power_off;
pd->pd.power_on = exynos_pd_power_on;
- on = readl_relaxed(pd->base + 0x4) & pd->local_pwr_cfg;
-
+ on = exynos_pd_read_status(pd);
pm_genpd_init(&pd->pd, NULL, !on);
ret = of_genpd_add_provider_simple(np, &pd->pd);
--
2.39.2
next prev parent reply other threads:[~2023-03-08 23:10 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20230308230935eucas1p1e919f4d4b020e3386ce0eac8b4c8d299@eucas1p1.samsung.com>
2023-03-08 23:09 ` [PATCH 0/6] soc: samsung: pm_domains: Add Exynos850 support Sam Protsenko
2023-03-08 23:09 ` [PATCH 1/6] dt-bindings: power: pd-samsung: " Sam Protsenko
2023-03-09 9:15 ` Krzysztof Kozlowski
2023-03-08 23:09 ` [PATCH 2/6] dt-bindings: power: pd-samsung: Allow pd nodes to be children of PMU Sam Protsenko
2023-03-10 14:41 ` Krzysztof Kozlowski
2023-03-08 23:09 ` [PATCH 3/6] soc: samsung: pm_domains: Extract DT handling into a separate function Sam Protsenko
2023-03-08 23:09 ` Sam Protsenko [this message]
2023-03-09 0:45 ` [PATCH 4/6] soc: samsung: pm_domains: Implement proper I/O operations kernel test robot
2023-03-08 23:09 ` [PATCH 5/6] soc: samsung: pm_domains: Allow PD to be a child of PMU syscon Sam Protsenko
2023-03-08 23:09 ` [PATCH 6/6] soc: samsung: pm_domains: Add Exynos850 support Sam Protsenko
2023-03-09 10:12 ` [PATCH 0/6] " Marek Szyprowski
2023-03-10 14:41 ` Krzysztof Kozlowski
2023-03-20 17:57 ` Sam Protsenko
2023-03-22 18:52 ` Krzysztof Kozlowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230308230931.27261-5-semen.protsenko@linaro.org \
--to=semen.protsenko@linaro.org \
--cc=alim.akhtar@samsung.com \
--cc=chanho61.park@samsung.com \
--cc=cw00.choi@samsung.com \
--cc=devicetree@vger.kernel.org \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=robh+dt@kernel.org \
--cc=virag.david003@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®