xref: /openbmc/u-boot/drivers/power/domain/mtk-power-domain.c (revision e16c888fab5014b022d5781dc534f204460a073b)
12ae7e4dcSRyder Lee // SPDX-License-Identifier: GPL-2.0
22ae7e4dcSRyder Lee /*
32ae7e4dcSRyder Lee  * Copyright (C) 2018 MediaTek Inc.
42ae7e4dcSRyder Lee  * Author: Ryder Lee <ryder.lee@mediatek.com>
52ae7e4dcSRyder Lee  */
62ae7e4dcSRyder Lee 
72ae7e4dcSRyder Lee #include <clk.h>
82ae7e4dcSRyder Lee #include <common.h>
92ae7e4dcSRyder Lee #include <dm.h>
102ae7e4dcSRyder Lee #include <power-domain-uclass.h>
112ae7e4dcSRyder Lee #include <regmap.h>
122ae7e4dcSRyder Lee #include <syscon.h>
132ae7e4dcSRyder Lee #include <asm/io.h>
142ae7e4dcSRyder Lee #include <asm/processor.h>
152ae7e4dcSRyder Lee #include <linux/iopoll.h>
162ae7e4dcSRyder Lee 
17*9dec738aSRyder Lee #include <dt-bindings/power/mt7623-power.h>
182ae7e4dcSRyder Lee #include <dt-bindings/power/mt7629-power.h>
192ae7e4dcSRyder Lee 
202ae7e4dcSRyder Lee #define SPM_EN			(0xb16 << 16 | 0x1)
21*9dec738aSRyder Lee #define SPM_VDE_PWR_CON		0x0210
22*9dec738aSRyder Lee #define SPM_MFG_PWR_CON		0x0214
23*9dec738aSRyder Lee #define SPM_ISP_PWR_CON		0x0238
24*9dec738aSRyder Lee #define SPM_DIS_PWR_CON		0x023c
25*9dec738aSRyder Lee #define SPM_CONN_PWR_CON	0x0280
26*9dec738aSRyder Lee #define SPM_BDP_PWR_CON		0x029c
27*9dec738aSRyder Lee #define SPM_ETH_PWR_CON		0x02a0
28*9dec738aSRyder Lee #define SPM_HIF_PWR_CON		0x02a4
29*9dec738aSRyder Lee #define SPM_IFR_MSC_PWR_CON	0x02a8
302ae7e4dcSRyder Lee #define SPM_ETHSYS_PWR_CON	0x2e0
312ae7e4dcSRyder Lee #define SPM_HIF0_PWR_CON	0x2e4
322ae7e4dcSRyder Lee #define SPM_HIF1_PWR_CON	0x2e8
332ae7e4dcSRyder Lee #define SPM_PWR_STATUS		0x60c
342ae7e4dcSRyder Lee #define SPM_PWR_STATUS_2ND	0x610
352ae7e4dcSRyder Lee 
362ae7e4dcSRyder Lee #define PWR_RST_B_BIT		BIT(0)
372ae7e4dcSRyder Lee #define PWR_ISO_BIT		BIT(1)
382ae7e4dcSRyder Lee #define PWR_ON_BIT		BIT(2)
392ae7e4dcSRyder Lee #define PWR_ON_2ND_BIT		BIT(3)
402ae7e4dcSRyder Lee #define PWR_CLK_DIS_BIT		BIT(4)
412ae7e4dcSRyder Lee 
42*9dec738aSRyder Lee #define PWR_STATUS_CONN		BIT(1)
43*9dec738aSRyder Lee #define PWR_STATUS_DISP		BIT(3)
44*9dec738aSRyder Lee #define PWR_STATUS_MFG		BIT(4)
45*9dec738aSRyder Lee #define PWR_STATUS_ISP		BIT(5)
46*9dec738aSRyder Lee #define PWR_STATUS_VDEC		BIT(7)
47*9dec738aSRyder Lee #define PWR_STATUS_BDP		BIT(14)
48*9dec738aSRyder Lee #define PWR_STATUS_ETH		BIT(15)
49*9dec738aSRyder Lee #define PWR_STATUS_HIF		BIT(16)
50*9dec738aSRyder Lee #define PWR_STATUS_IFR_MSC	BIT(17)
512ae7e4dcSRyder Lee #define PWR_STATUS_ETHSYS	BIT(24)
522ae7e4dcSRyder Lee #define PWR_STATUS_HIF0		BIT(25)
532ae7e4dcSRyder Lee #define PWR_STATUS_HIF1		BIT(26)
542ae7e4dcSRyder Lee 
552ae7e4dcSRyder Lee /* Infrasys configuration */
562ae7e4dcSRyder Lee #define INFRA_TOPDCM_CTRL	0x10
572ae7e4dcSRyder Lee #define INFRA_TOPAXI_PROT_EN	0x220
582ae7e4dcSRyder Lee #define INFRA_TOPAXI_PROT_STA1	0x228
592ae7e4dcSRyder Lee 
602ae7e4dcSRyder Lee #define DCM_TOP_EN		BIT(0)
612ae7e4dcSRyder Lee 
622ae7e4dcSRyder Lee enum scp_domain_type {
63*9dec738aSRyder Lee 	SCPSYS_MT7623,
642ae7e4dcSRyder Lee 	SCPSYS_MT7629,
652ae7e4dcSRyder Lee };
662ae7e4dcSRyder Lee 
672ae7e4dcSRyder Lee struct scp_domain;
682ae7e4dcSRyder Lee 
692ae7e4dcSRyder Lee struct scp_domain_data {
702ae7e4dcSRyder Lee 	struct scp_domain *scpd;
712ae7e4dcSRyder Lee 	u32 sta_mask;
722ae7e4dcSRyder Lee 	int ctl_offs;
732ae7e4dcSRyder Lee 	u32 sram_pdn_bits;
742ae7e4dcSRyder Lee 	u32 sram_pdn_ack_bits;
752ae7e4dcSRyder Lee 	u32 bus_prot_mask;
762ae7e4dcSRyder Lee };
772ae7e4dcSRyder Lee 
782ae7e4dcSRyder Lee struct scp_domain {
792ae7e4dcSRyder Lee 	void __iomem *base;
802ae7e4dcSRyder Lee 	void __iomem *infracfg;
812ae7e4dcSRyder Lee 	enum scp_domain_type type;
822ae7e4dcSRyder Lee 	struct scp_domain_data *data;
832ae7e4dcSRyder Lee };
842ae7e4dcSRyder Lee 
85*9dec738aSRyder Lee static struct scp_domain_data scp_domain_mt7623[] = {
86*9dec738aSRyder Lee 	[MT7623_POWER_DOMAIN_CONN] = {
87*9dec738aSRyder Lee 		.sta_mask = PWR_STATUS_CONN,
88*9dec738aSRyder Lee 		.ctl_offs = SPM_CONN_PWR_CON,
89*9dec738aSRyder Lee 		.bus_prot_mask = BIT(8) | BIT(2),
90*9dec738aSRyder Lee 	},
91*9dec738aSRyder Lee 	[MT7623_POWER_DOMAIN_DISP] = {
92*9dec738aSRyder Lee 		.sta_mask = PWR_STATUS_DISP,
93*9dec738aSRyder Lee 		.ctl_offs = SPM_DIS_PWR_CON,
94*9dec738aSRyder Lee 		.sram_pdn_bits = GENMASK(11, 8),
95*9dec738aSRyder Lee 		.bus_prot_mask = BIT(2),
96*9dec738aSRyder Lee 	},
97*9dec738aSRyder Lee 	[MT7623_POWER_DOMAIN_MFG] = {
98*9dec738aSRyder Lee 		.sta_mask = PWR_STATUS_MFG,
99*9dec738aSRyder Lee 		.ctl_offs = SPM_MFG_PWR_CON,
100*9dec738aSRyder Lee 		.sram_pdn_bits = GENMASK(11, 8),
101*9dec738aSRyder Lee 		.sram_pdn_ack_bits = GENMASK(12, 12),
102*9dec738aSRyder Lee 	},
103*9dec738aSRyder Lee 	[MT7623_POWER_DOMAIN_VDEC] = {
104*9dec738aSRyder Lee 		.sta_mask = PWR_STATUS_VDEC,
105*9dec738aSRyder Lee 		.ctl_offs = SPM_VDE_PWR_CON,
106*9dec738aSRyder Lee 		.sram_pdn_bits = GENMASK(11, 8),
107*9dec738aSRyder Lee 		.sram_pdn_ack_bits = GENMASK(12, 12),
108*9dec738aSRyder Lee 	},
109*9dec738aSRyder Lee 	[MT7623_POWER_DOMAIN_ISP] = {
110*9dec738aSRyder Lee 		.sta_mask = PWR_STATUS_ISP,
111*9dec738aSRyder Lee 		.ctl_offs = SPM_ISP_PWR_CON,
112*9dec738aSRyder Lee 		.sram_pdn_bits = GENMASK(11, 8),
113*9dec738aSRyder Lee 		.sram_pdn_ack_bits = GENMASK(13, 12),
114*9dec738aSRyder Lee 	},
115*9dec738aSRyder Lee 	[MT7623_POWER_DOMAIN_BDP] = {
116*9dec738aSRyder Lee 		.sta_mask = PWR_STATUS_BDP,
117*9dec738aSRyder Lee 		.ctl_offs = SPM_BDP_PWR_CON,
118*9dec738aSRyder Lee 		.sram_pdn_bits = GENMASK(11, 8),
119*9dec738aSRyder Lee 	},
120*9dec738aSRyder Lee 	[MT7623_POWER_DOMAIN_ETH] = {
121*9dec738aSRyder Lee 		.sta_mask = PWR_STATUS_ETH,
122*9dec738aSRyder Lee 		.ctl_offs = SPM_ETH_PWR_CON,
123*9dec738aSRyder Lee 		.sram_pdn_bits = GENMASK(11, 8),
124*9dec738aSRyder Lee 		.sram_pdn_ack_bits = GENMASK(15, 12),
125*9dec738aSRyder Lee 	},
126*9dec738aSRyder Lee 	[MT7623_POWER_DOMAIN_HIF] = {
127*9dec738aSRyder Lee 		.sta_mask = PWR_STATUS_HIF,
128*9dec738aSRyder Lee 		.ctl_offs = SPM_HIF_PWR_CON,
129*9dec738aSRyder Lee 		.sram_pdn_bits = GENMASK(11, 8),
130*9dec738aSRyder Lee 		.sram_pdn_ack_bits = GENMASK(15, 12),
131*9dec738aSRyder Lee 	},
132*9dec738aSRyder Lee 	[MT7623_POWER_DOMAIN_IFR_MSC] = {
133*9dec738aSRyder Lee 		.sta_mask = PWR_STATUS_IFR_MSC,
134*9dec738aSRyder Lee 		.ctl_offs = SPM_IFR_MSC_PWR_CON,
135*9dec738aSRyder Lee 	},
136*9dec738aSRyder Lee };
137*9dec738aSRyder Lee 
1382ae7e4dcSRyder Lee static struct scp_domain_data scp_domain_mt7629[] = {
1392ae7e4dcSRyder Lee 	[MT7629_POWER_DOMAIN_ETHSYS] = {
1402ae7e4dcSRyder Lee 		.sta_mask = PWR_STATUS_ETHSYS,
1412ae7e4dcSRyder Lee 		.ctl_offs = SPM_ETHSYS_PWR_CON,
1422ae7e4dcSRyder Lee 		.sram_pdn_bits = GENMASK(11, 8),
1432ae7e4dcSRyder Lee 		.sram_pdn_ack_bits = GENMASK(15, 12),
1442ae7e4dcSRyder Lee 		.bus_prot_mask = (BIT(3) | BIT(17)),
1452ae7e4dcSRyder Lee 	},
1462ae7e4dcSRyder Lee 	[MT7629_POWER_DOMAIN_HIF0] = {
1472ae7e4dcSRyder Lee 		.sta_mask = PWR_STATUS_HIF0,
1482ae7e4dcSRyder Lee 		.ctl_offs = SPM_HIF0_PWR_CON,
1492ae7e4dcSRyder Lee 		.sram_pdn_bits = GENMASK(11, 8),
1502ae7e4dcSRyder Lee 		.sram_pdn_ack_bits = GENMASK(15, 12),
1512ae7e4dcSRyder Lee 		.bus_prot_mask = GENMASK(25, 24),
1522ae7e4dcSRyder Lee 	},
1532ae7e4dcSRyder Lee 	[MT7629_POWER_DOMAIN_HIF1] = {
1542ae7e4dcSRyder Lee 		.sta_mask = PWR_STATUS_HIF1,
1552ae7e4dcSRyder Lee 		.ctl_offs = SPM_HIF1_PWR_CON,
1562ae7e4dcSRyder Lee 		.sram_pdn_bits = GENMASK(11, 8),
1572ae7e4dcSRyder Lee 		.sram_pdn_ack_bits = GENMASK(15, 12),
1582ae7e4dcSRyder Lee 		.bus_prot_mask = GENMASK(28, 26),
1592ae7e4dcSRyder Lee 	},
1602ae7e4dcSRyder Lee };
1612ae7e4dcSRyder Lee 
1622ae7e4dcSRyder Lee /**
1632ae7e4dcSRyder Lee  * This function enables the bus protection bits for disabled power
1642ae7e4dcSRyder Lee  * domains so that the system does not hang when some unit accesses the
1652ae7e4dcSRyder Lee  * bus while in power down.
1662ae7e4dcSRyder Lee  */
mtk_infracfg_set_bus_protection(void __iomem * infracfg,u32 mask)1672ae7e4dcSRyder Lee static int mtk_infracfg_set_bus_protection(void __iomem *infracfg,
1682ae7e4dcSRyder Lee 					   u32 mask)
1692ae7e4dcSRyder Lee {
1702ae7e4dcSRyder Lee 	u32 val;
1712ae7e4dcSRyder Lee 
1722ae7e4dcSRyder Lee 	clrsetbits_le32(infracfg + INFRA_TOPAXI_PROT_EN, mask, mask);
1732ae7e4dcSRyder Lee 
1742ae7e4dcSRyder Lee 	return readl_poll_timeout(infracfg + INFRA_TOPAXI_PROT_STA1, val,
1752ae7e4dcSRyder Lee 				  (val & mask) == mask, 100);
1762ae7e4dcSRyder Lee }
1772ae7e4dcSRyder Lee 
mtk_infracfg_clear_bus_protection(void __iomem * infracfg,u32 mask)1782ae7e4dcSRyder Lee static int mtk_infracfg_clear_bus_protection(void __iomem *infracfg,
1792ae7e4dcSRyder Lee 					     u32 mask)
1802ae7e4dcSRyder Lee {
1812ae7e4dcSRyder Lee 	u32 val;
1822ae7e4dcSRyder Lee 
1832ae7e4dcSRyder Lee 	clrbits_le32(infracfg + INFRA_TOPAXI_PROT_EN, mask);
1842ae7e4dcSRyder Lee 
1852ae7e4dcSRyder Lee 	return readl_poll_timeout(infracfg + INFRA_TOPAXI_PROT_STA1, val,
1862ae7e4dcSRyder Lee 				  !(val & mask), 100);
1872ae7e4dcSRyder Lee }
1882ae7e4dcSRyder Lee 
scpsys_domain_is_on(struct scp_domain_data * data)1892ae7e4dcSRyder Lee static int scpsys_domain_is_on(struct scp_domain_data *data)
1902ae7e4dcSRyder Lee {
1912ae7e4dcSRyder Lee 	struct scp_domain *scpd = data->scpd;
1922ae7e4dcSRyder Lee 	u32 sta = readl(scpd->base + SPM_PWR_STATUS) &
1932ae7e4dcSRyder Lee 			data->sta_mask;
1942ae7e4dcSRyder Lee 	u32 sta2 = readl(scpd->base + SPM_PWR_STATUS_2ND) &
1952ae7e4dcSRyder Lee 			 data->sta_mask;
1962ae7e4dcSRyder Lee 
1972ae7e4dcSRyder Lee 	/*
1982ae7e4dcSRyder Lee 	 * A domain is on when both status bits are set. If only one is set
1992ae7e4dcSRyder Lee 	 * return an error. This happens while powering up a domain
2002ae7e4dcSRyder Lee 	 */
2012ae7e4dcSRyder Lee 	if (sta && sta2)
2022ae7e4dcSRyder Lee 		return true;
2032ae7e4dcSRyder Lee 	if (!sta && !sta2)
2042ae7e4dcSRyder Lee 		return false;
2052ae7e4dcSRyder Lee 
2062ae7e4dcSRyder Lee 	return -EINVAL;
2072ae7e4dcSRyder Lee }
2082ae7e4dcSRyder Lee 
scpsys_power_on(struct power_domain * power_domain)2092ae7e4dcSRyder Lee static int scpsys_power_on(struct power_domain *power_domain)
2102ae7e4dcSRyder Lee {
2112ae7e4dcSRyder Lee 	struct scp_domain *scpd = dev_get_priv(power_domain->dev);
2122ae7e4dcSRyder Lee 	struct scp_domain_data *data = &scpd->data[power_domain->id];
2132ae7e4dcSRyder Lee 	void __iomem *ctl_addr = scpd->base + data->ctl_offs;
2142ae7e4dcSRyder Lee 	u32 pdn_ack = data->sram_pdn_ack_bits;
2152ae7e4dcSRyder Lee 	u32 val;
2162ae7e4dcSRyder Lee 	int ret, tmp;
2172ae7e4dcSRyder Lee 
2182ae7e4dcSRyder Lee 	writel(SPM_EN, scpd->base);
2192ae7e4dcSRyder Lee 
2202ae7e4dcSRyder Lee 	val = readl(ctl_addr);
2212ae7e4dcSRyder Lee 	val |= PWR_ON_BIT;
2222ae7e4dcSRyder Lee 	writel(val, ctl_addr);
2232ae7e4dcSRyder Lee 
2242ae7e4dcSRyder Lee 	val |= PWR_ON_2ND_BIT;
2252ae7e4dcSRyder Lee 	writel(val, ctl_addr);
2262ae7e4dcSRyder Lee 
2272ae7e4dcSRyder Lee 	ret = readx_poll_timeout(scpsys_domain_is_on, data, tmp, tmp > 0,
2282ae7e4dcSRyder Lee 				 100);
2292ae7e4dcSRyder Lee 	if (ret < 0)
2302ae7e4dcSRyder Lee 		return ret;
2312ae7e4dcSRyder Lee 
2322ae7e4dcSRyder Lee 	val &= ~PWR_CLK_DIS_BIT;
2332ae7e4dcSRyder Lee 	writel(val, ctl_addr);
2342ae7e4dcSRyder Lee 
2352ae7e4dcSRyder Lee 	val &= ~PWR_ISO_BIT;
2362ae7e4dcSRyder Lee 	writel(val, ctl_addr);
2372ae7e4dcSRyder Lee 
2382ae7e4dcSRyder Lee 	val |= PWR_RST_B_BIT;
2392ae7e4dcSRyder Lee 	writel(val, ctl_addr);
2402ae7e4dcSRyder Lee 
2412ae7e4dcSRyder Lee 	val &= ~data->sram_pdn_bits;
2422ae7e4dcSRyder Lee 	writel(val, ctl_addr);
2432ae7e4dcSRyder Lee 
2442ae7e4dcSRyder Lee 	ret = readl_poll_timeout(ctl_addr, tmp, !(tmp & pdn_ack), 100);
2452ae7e4dcSRyder Lee 	if (ret < 0)
2462ae7e4dcSRyder Lee 		return ret;
2472ae7e4dcSRyder Lee 
2482ae7e4dcSRyder Lee 	if (data->bus_prot_mask) {
2492ae7e4dcSRyder Lee 		ret = mtk_infracfg_clear_bus_protection(scpd->infracfg,
2502ae7e4dcSRyder Lee 							data->bus_prot_mask);
2512ae7e4dcSRyder Lee 		if (ret)
2522ae7e4dcSRyder Lee 			return ret;
2532ae7e4dcSRyder Lee 	}
2542ae7e4dcSRyder Lee 
2552ae7e4dcSRyder Lee 	return 0;
2562ae7e4dcSRyder Lee }
2572ae7e4dcSRyder Lee 
scpsys_power_off(struct power_domain * power_domain)2582ae7e4dcSRyder Lee static int scpsys_power_off(struct power_domain *power_domain)
2592ae7e4dcSRyder Lee {
2602ae7e4dcSRyder Lee 	struct scp_domain *scpd = dev_get_priv(power_domain->dev);
2612ae7e4dcSRyder Lee 	struct scp_domain_data *data = &scpd->data[power_domain->id];
2622ae7e4dcSRyder Lee 	void __iomem *ctl_addr = scpd->base + data->ctl_offs;
2632ae7e4dcSRyder Lee 	u32 pdn_ack = data->sram_pdn_ack_bits;
2642ae7e4dcSRyder Lee 	u32 val;
2652ae7e4dcSRyder Lee 	int ret, tmp;
2662ae7e4dcSRyder Lee 
2672ae7e4dcSRyder Lee 	if (data->bus_prot_mask) {
2682ae7e4dcSRyder Lee 		ret = mtk_infracfg_set_bus_protection(scpd->infracfg,
2692ae7e4dcSRyder Lee 						      data->bus_prot_mask);
2702ae7e4dcSRyder Lee 		if (ret)
2712ae7e4dcSRyder Lee 			return ret;
2722ae7e4dcSRyder Lee 	}
2732ae7e4dcSRyder Lee 
2742ae7e4dcSRyder Lee 	val = readl(ctl_addr);
2752ae7e4dcSRyder Lee 	val |= data->sram_pdn_bits;
2762ae7e4dcSRyder Lee 	writel(val, ctl_addr);
2772ae7e4dcSRyder Lee 
2782ae7e4dcSRyder Lee 	ret = readl_poll_timeout(ctl_addr, tmp, (tmp & pdn_ack) == pdn_ack,
2792ae7e4dcSRyder Lee 				 100);
2802ae7e4dcSRyder Lee 	if (ret < 0)
2812ae7e4dcSRyder Lee 		return ret;
2822ae7e4dcSRyder Lee 
2832ae7e4dcSRyder Lee 	val |= PWR_ISO_BIT;
2842ae7e4dcSRyder Lee 	writel(val, ctl_addr);
2852ae7e4dcSRyder Lee 
2862ae7e4dcSRyder Lee 	val &= ~PWR_RST_B_BIT;
2872ae7e4dcSRyder Lee 	writel(val, ctl_addr);
2882ae7e4dcSRyder Lee 
2892ae7e4dcSRyder Lee 	val |= PWR_CLK_DIS_BIT;
2902ae7e4dcSRyder Lee 	writel(val, ctl_addr);
2912ae7e4dcSRyder Lee 
2922ae7e4dcSRyder Lee 	val &= ~PWR_ON_BIT;
2932ae7e4dcSRyder Lee 	writel(val, ctl_addr);
2942ae7e4dcSRyder Lee 
2952ae7e4dcSRyder Lee 	val &= ~PWR_ON_2ND_BIT;
2962ae7e4dcSRyder Lee 	writel(val, ctl_addr);
2972ae7e4dcSRyder Lee 
2982ae7e4dcSRyder Lee 	ret = readx_poll_timeout(scpsys_domain_is_on, data, tmp, !tmp, 100);
2992ae7e4dcSRyder Lee 	if (ret < 0)
3002ae7e4dcSRyder Lee 		return ret;
3012ae7e4dcSRyder Lee 
3022ae7e4dcSRyder Lee 	return 0;
3032ae7e4dcSRyder Lee }
3042ae7e4dcSRyder Lee 
scpsys_power_request(struct power_domain * power_domain)3052ae7e4dcSRyder Lee static int scpsys_power_request(struct power_domain *power_domain)
3062ae7e4dcSRyder Lee {
3072ae7e4dcSRyder Lee 	struct scp_domain *scpd = dev_get_priv(power_domain->dev);
3082ae7e4dcSRyder Lee 	struct scp_domain_data *data;
3092ae7e4dcSRyder Lee 
3102ae7e4dcSRyder Lee 	data = &scpd->data[power_domain->id];
3112ae7e4dcSRyder Lee 	data->scpd = scpd;
3122ae7e4dcSRyder Lee 
3132ae7e4dcSRyder Lee 	return 0;
3142ae7e4dcSRyder Lee }
3152ae7e4dcSRyder Lee 
scpsys_power_free(struct power_domain * power_domain)3162ae7e4dcSRyder Lee static int scpsys_power_free(struct power_domain *power_domain)
3172ae7e4dcSRyder Lee {
3182ae7e4dcSRyder Lee 	return 0;
3192ae7e4dcSRyder Lee }
3202ae7e4dcSRyder Lee 
mtk_power_domain_hook(struct udevice * dev)3212ae7e4dcSRyder Lee static int mtk_power_domain_hook(struct udevice *dev)
3222ae7e4dcSRyder Lee {
3232ae7e4dcSRyder Lee 	struct scp_domain *scpd = dev_get_priv(dev);
3242ae7e4dcSRyder Lee 
3252ae7e4dcSRyder Lee 	scpd->type = (enum scp_domain_type)dev_get_driver_data(dev);
3262ae7e4dcSRyder Lee 
3272ae7e4dcSRyder Lee 	switch (scpd->type) {
328*9dec738aSRyder Lee 	case SCPSYS_MT7623:
329*9dec738aSRyder Lee 		scpd->data = scp_domain_mt7623;
330*9dec738aSRyder Lee 		break;
3312ae7e4dcSRyder Lee 	case SCPSYS_MT7629:
3322ae7e4dcSRyder Lee 		scpd->data = scp_domain_mt7629;
3332ae7e4dcSRyder Lee 		break;
3342ae7e4dcSRyder Lee 	default:
3352ae7e4dcSRyder Lee 		return -EINVAL;
3362ae7e4dcSRyder Lee 	}
3372ae7e4dcSRyder Lee 
3382ae7e4dcSRyder Lee 	return 0;
3392ae7e4dcSRyder Lee }
3402ae7e4dcSRyder Lee 
mtk_power_domain_probe(struct udevice * dev)3412ae7e4dcSRyder Lee static int mtk_power_domain_probe(struct udevice *dev)
3422ae7e4dcSRyder Lee {
3432ae7e4dcSRyder Lee 	struct ofnode_phandle_args args;
3442ae7e4dcSRyder Lee 	struct scp_domain *scpd = dev_get_priv(dev);
3452ae7e4dcSRyder Lee 	struct regmap *regmap;
3462ae7e4dcSRyder Lee 	struct clk_bulk bulk;
3472ae7e4dcSRyder Lee 	int err;
3482ae7e4dcSRyder Lee 
3492ae7e4dcSRyder Lee 	scpd->base = dev_read_addr_ptr(dev);
3502ae7e4dcSRyder Lee 	if (!scpd->base)
3512ae7e4dcSRyder Lee 		return -ENOENT;
3522ae7e4dcSRyder Lee 
3532ae7e4dcSRyder Lee 	err = mtk_power_domain_hook(dev);
3542ae7e4dcSRyder Lee 	if (err)
3552ae7e4dcSRyder Lee 		return err;
3562ae7e4dcSRyder Lee 
3572ae7e4dcSRyder Lee 	/* get corresponding syscon phandle */
3582ae7e4dcSRyder Lee 	err = dev_read_phandle_with_args(dev, "infracfg", NULL, 0, 0, &args);
3592ae7e4dcSRyder Lee 	if (err)
3602ae7e4dcSRyder Lee 		return err;
3612ae7e4dcSRyder Lee 
3622ae7e4dcSRyder Lee 	regmap = syscon_node_to_regmap(args.node);
3632ae7e4dcSRyder Lee 	if (IS_ERR(regmap))
3642ae7e4dcSRyder Lee 		return PTR_ERR(regmap);
3652ae7e4dcSRyder Lee 
3662ae7e4dcSRyder Lee 	scpd->infracfg = regmap_get_range(regmap, 0);
3672ae7e4dcSRyder Lee 	if (!scpd->infracfg)
3682ae7e4dcSRyder Lee 		return -ENOENT;
3692ae7e4dcSRyder Lee 
3702ae7e4dcSRyder Lee 	/* enable Infra DCM */
3712ae7e4dcSRyder Lee 	setbits_le32(scpd->infracfg + INFRA_TOPDCM_CTRL, DCM_TOP_EN);
3722ae7e4dcSRyder Lee 
3732ae7e4dcSRyder Lee 	err = clk_get_bulk(dev, &bulk);
3742ae7e4dcSRyder Lee 	if (err)
3752ae7e4dcSRyder Lee 		return err;
3762ae7e4dcSRyder Lee 
3772ae7e4dcSRyder Lee 	return clk_enable_bulk(&bulk);
3782ae7e4dcSRyder Lee }
3792ae7e4dcSRyder Lee 
3802ae7e4dcSRyder Lee static const struct udevice_id mtk_power_domain_ids[] = {
3812ae7e4dcSRyder Lee 	{
382*9dec738aSRyder Lee 		.compatible = "mediatek,mt7623-scpsys",
383*9dec738aSRyder Lee 		.data = SCPSYS_MT7623,
384*9dec738aSRyder Lee 	},
385*9dec738aSRyder Lee 	{
3862ae7e4dcSRyder Lee 		.compatible = "mediatek,mt7629-scpsys",
3872ae7e4dcSRyder Lee 		.data = SCPSYS_MT7629,
3882ae7e4dcSRyder Lee 	},
3892ae7e4dcSRyder Lee 	{ /* sentinel */ }
3902ae7e4dcSRyder Lee };
3912ae7e4dcSRyder Lee 
3922ae7e4dcSRyder Lee struct power_domain_ops mtk_power_domain_ops = {
3932ae7e4dcSRyder Lee 	.free = scpsys_power_free,
3942ae7e4dcSRyder Lee 	.off = scpsys_power_off,
3952ae7e4dcSRyder Lee 	.on = scpsys_power_on,
3962ae7e4dcSRyder Lee 	.request = scpsys_power_request,
3972ae7e4dcSRyder Lee };
3982ae7e4dcSRyder Lee 
3992ae7e4dcSRyder Lee U_BOOT_DRIVER(mtk_power_domain) = {
4002ae7e4dcSRyder Lee 	.name = "mtk_power_domain",
4012ae7e4dcSRyder Lee 	.id = UCLASS_POWER_DOMAIN,
4022ae7e4dcSRyder Lee 	.ops = &mtk_power_domain_ops,
4032ae7e4dcSRyder Lee 	.probe = mtk_power_domain_probe,
4042ae7e4dcSRyder Lee 	.of_match = mtk_power_domain_ids,
4052ae7e4dcSRyder Lee 	.priv_auto_alloc_size = sizeof(struct scp_domain),
4062ae7e4dcSRyder Lee };
407