Skip to content

Commit 0a0f7cc

Browse files
MrVanShawn Guo
authored andcommitted
soc: imx: add i.MX93 SRC power domain driver
Support controlling power domain managed by System Reset Controller(SRC). Current supported power domain is mediamix power domain. Signed-off-by: Peng Fan <peng.fan@nxp.com> Signed-off-by: Shawn Guo <shawnguo@kernel.org>
1 parent df5a696 commit 0a0f7cc

File tree

4 files changed

+206
-0
lines changed

4 files changed

+206
-0
lines changed

drivers/soc/imx/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,12 @@ config SOC_IMX8M
2020
support, it will provide the SoC info like SoC family,
2121
ID and revision etc.
2222

23+
config SOC_IMX9
24+
tristate "i.MX9 SoC family support"
25+
depends on ARCH_MXC || COMPILE_TEST
26+
default ARCH_MXC && ARM64
27+
select SOC_BUS
28+
help
29+
If you say yes here, you get support for the NXP i.MX9 family
30+
2331
endmenu

drivers/soc/imx/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ obj-$(CONFIG_IMX_GPCV2_PM_DOMAINS) += gpcv2.o
77
obj-$(CONFIG_SOC_IMX8M) += soc-imx8m.o
88
obj-$(CONFIG_SOC_IMX8M) += imx8m-blk-ctrl.o
99
obj-$(CONFIG_SOC_IMX8M) += imx8mp-blk-ctrl.o
10+
obj-$(CONFIG_SOC_IMX9) += imx93-src.o imx93-pd.o

drivers/soc/imx/imx93-pd.c

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright 2022 NXP
4+
*/
5+
6+
#include <linux/clk.h>
7+
#include <linux/delay.h>
8+
#include <linux/of_device.h>
9+
#include <linux/iopoll.h>
10+
#include <linux/module.h>
11+
#include <linux/platform_device.h>
12+
#include <linux/pm_domain.h>
13+
14+
#define MIX_SLICE_SW_CTRL_OFF 0x20
15+
#define SLICE_SW_CTRL_PSW_CTRL_OFF_MASK BIT(4)
16+
#define SLICE_SW_CTRL_PDN_SOFT_MASK BIT(31)
17+
18+
#define MIX_FUNC_STAT_OFF 0xB4
19+
20+
#define FUNC_STAT_PSW_STAT_MASK BIT(0)
21+
#define FUNC_STAT_RST_STAT_MASK BIT(2)
22+
#define FUNC_STAT_ISO_STAT_MASK BIT(4)
23+
24+
struct imx93_power_domain {
25+
struct generic_pm_domain genpd;
26+
struct device *dev;
27+
void __iomem *addr;
28+
struct clk_bulk_data *clks;
29+
int num_clks;
30+
bool init_off;
31+
};
32+
33+
#define to_imx93_pd(_genpd) container_of(_genpd, struct imx93_power_domain, genpd)
34+
35+
static int imx93_pd_on(struct generic_pm_domain *genpd)
36+
{
37+
struct imx93_power_domain *domain = to_imx93_pd(genpd);
38+
void __iomem *addr = domain->addr;
39+
u32 val;
40+
int ret;
41+
42+
ret = clk_bulk_prepare_enable(domain->num_clks, domain->clks);
43+
if (ret) {
44+
dev_err(domain->dev, "failed to enable clocks for domain: %s\n", genpd->name);
45+
return ret;
46+
}
47+
48+
val = readl(addr + MIX_SLICE_SW_CTRL_OFF);
49+
val &= ~SLICE_SW_CTRL_PDN_SOFT_MASK;
50+
writel(val, addr + MIX_SLICE_SW_CTRL_OFF);
51+
52+
ret = readl_poll_timeout(addr + MIX_FUNC_STAT_OFF, val,
53+
!(val & FUNC_STAT_ISO_STAT_MASK), 1, 10000);
54+
if (ret) {
55+
dev_err(domain->dev, "pd_on timeout: name: %s, stat: %x\n", genpd->name, val);
56+
return ret;
57+
}
58+
59+
return 0;
60+
}
61+
62+
static int imx93_pd_off(struct generic_pm_domain *genpd)
63+
{
64+
struct imx93_power_domain *domain = to_imx93_pd(genpd);
65+
void __iomem *addr = domain->addr;
66+
int ret;
67+
u32 val;
68+
69+
/* Power off MIX */
70+
val = readl(addr + MIX_SLICE_SW_CTRL_OFF);
71+
val |= SLICE_SW_CTRL_PDN_SOFT_MASK;
72+
writel(val, addr + MIX_SLICE_SW_CTRL_OFF);
73+
74+
ret = readl_poll_timeout(addr + MIX_FUNC_STAT_OFF, val,
75+
val & FUNC_STAT_PSW_STAT_MASK, 1, 1000);
76+
if (ret) {
77+
dev_err(domain->dev, "pd_off timeout: name: %s, stat: %x\n", genpd->name, val);
78+
return ret;
79+
}
80+
81+
clk_bulk_disable_unprepare(domain->num_clks, domain->clks);
82+
83+
return 0;
84+
};
85+
86+
static int imx93_pd_remove(struct platform_device *pdev)
87+
{
88+
struct imx93_power_domain *domain = platform_get_drvdata(pdev);
89+
struct device *dev = &pdev->dev;
90+
struct device_node *np = dev->of_node;
91+
92+
if (!domain->init_off)
93+
clk_bulk_disable_unprepare(domain->num_clks, domain->clks);
94+
95+
of_genpd_del_provider(np);
96+
pm_genpd_remove(&domain->genpd);
97+
98+
return 0;
99+
}
100+
101+
static int imx93_pd_probe(struct platform_device *pdev)
102+
{
103+
struct device *dev = &pdev->dev;
104+
struct device_node *np = dev->of_node;
105+
struct imx93_power_domain *domain;
106+
int ret;
107+
108+
domain = devm_kzalloc(dev, sizeof(*domain), GFP_KERNEL);
109+
if (!domain)
110+
return -ENOMEM;
111+
112+
domain->addr = devm_platform_ioremap_resource(pdev, 0);
113+
if (IS_ERR(domain->addr))
114+
return PTR_ERR(domain->addr);
115+
116+
domain->num_clks = devm_clk_bulk_get_all(dev, &domain->clks);
117+
if (domain->num_clks < 0)
118+
return dev_err_probe(dev, domain->num_clks, "Failed to get domain's clocks\n");
119+
120+
domain->genpd.name = dev_name(dev);
121+
domain->genpd.power_off = imx93_pd_off;
122+
domain->genpd.power_on = imx93_pd_on;
123+
domain->dev = dev;
124+
125+
domain->init_off = readl(domain->addr + MIX_FUNC_STAT_OFF) & FUNC_STAT_ISO_STAT_MASK;
126+
/* Just to sync the status of hardware */
127+
if (!domain->init_off) {
128+
ret = clk_bulk_prepare_enable(domain->num_clks, domain->clks);
129+
if (ret) {
130+
dev_err(domain->dev, "failed to enable clocks for domain: %s\n",
131+
domain->genpd.name);
132+
return ret;
133+
}
134+
}
135+
136+
ret = pm_genpd_init(&domain->genpd, NULL, domain->init_off);
137+
if (ret)
138+
return ret;
139+
140+
platform_set_drvdata(pdev, domain);
141+
142+
return of_genpd_add_provider_simple(np, &domain->genpd);
143+
}
144+
145+
static const struct of_device_id imx93_pd_ids[] = {
146+
{ .compatible = "fsl,imx93-src-slice" },
147+
{ }
148+
};
149+
MODULE_DEVICE_TABLE(of, imx93_pd_ids);
150+
151+
static struct platform_driver imx93_power_domain_driver = {
152+
.driver = {
153+
.name = "imx93_power_domain",
154+
.owner = THIS_MODULE,
155+
.of_match_table = imx93_pd_ids,
156+
},
157+
.probe = imx93_pd_probe,
158+
.remove = imx93_pd_remove,
159+
};
160+
module_platform_driver(imx93_power_domain_driver);
161+
162+
MODULE_AUTHOR("Peng Fan <peng.fan@nxp.com>");
163+
MODULE_DESCRIPTION("NXP i.MX93 power domain driver");
164+
MODULE_LICENSE("GPL");

drivers/soc/imx/imx93-src.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright 2022 NXP
4+
*/
5+
6+
#include <linux/module.h>
7+
#include <linux/of_platform.h>
8+
#include <linux/platform_device.h>
9+
10+
static int imx93_src_probe(struct platform_device *pdev)
11+
{
12+
return devm_of_platform_populate(&pdev->dev);
13+
}
14+
15+
static const struct of_device_id imx93_src_ids[] = {
16+
{ .compatible = "fsl,imx93-src" },
17+
{ }
18+
};
19+
MODULE_DEVICE_TABLE(of, imx93_src_ids);
20+
21+
static struct platform_driver imx93_src_driver = {
22+
.driver = {
23+
.name = "imx93_src",
24+
.owner = THIS_MODULE,
25+
.of_match_table = imx93_src_ids,
26+
},
27+
.probe = imx93_src_probe,
28+
};
29+
module_platform_driver(imx93_src_driver);
30+
31+
MODULE_AUTHOR("Peng Fan <peng.fan@nxp.com>");
32+
MODULE_DESCRIPTION("NXP i.MX93 src driver");
33+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)