1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2015 Pengutronix, Sascha Hauer <kernel@pengutronix.de>
6 #include <linux/init.h>
8 #include <linux/iopoll.h>
9 #include <linux/mfd/syscon.h>
11 #include <linux/platform_device.h>
12 #include <linux/pm_domain.h>
13 #include <linux/regulator/consumer.h>
14 #include <linux/soc/mediatek/infracfg.h>
16 #include <dt-bindings/power/mt2701-power.h>
17 #include <dt-bindings/power/mt2712-power.h>
18 #include <dt-bindings/power/mt6797-power.h>
19 #include <dt-bindings/power/mt7622-power.h>
20 #include <dt-bindings/power/mt7623a-power.h>
21 #include <dt-bindings/power/mt8173-power.h>
23 #define MTK_POLL_DELAY_US 10
24 #define MTK_POLL_TIMEOUT USEC_PER_SEC
26 #define MTK_SCPD_ACTIVE_WAKEUP BIT(0)
27 #define MTK_SCPD_FWAIT_SRAM BIT(1)
28 #define MTK_SCPD_CAPS(_scpd, _x) ((_scpd)->data->caps & (_x))
30 #define SPM_VDE_PWR_CON 0x0210
31 #define SPM_MFG_PWR_CON 0x0214
32 #define SPM_VEN_PWR_CON 0x0230
33 #define SPM_ISP_PWR_CON 0x0238
34 #define SPM_DIS_PWR_CON 0x023c
35 #define SPM_CONN_PWR_CON 0x0280
36 #define SPM_VEN2_PWR_CON 0x0298
37 #define SPM_AUDIO_PWR_CON 0x029c /* MT8173, MT2712 */
38 #define SPM_BDP_PWR_CON 0x029c /* MT2701 */
39 #define SPM_ETH_PWR_CON 0x02a0
40 #define SPM_HIF_PWR_CON 0x02a4
41 #define SPM_IFR_MSC_PWR_CON 0x02a8
42 #define SPM_MFG_2D_PWR_CON 0x02c0
43 #define SPM_MFG_ASYNC_PWR_CON 0x02c4
44 #define SPM_USB_PWR_CON 0x02cc
45 #define SPM_USB2_PWR_CON 0x02d4 /* MT2712 */
46 #define SPM_ETHSYS_PWR_CON 0x02e0 /* MT7622 */
47 #define SPM_HIF0_PWR_CON 0x02e4 /* MT7622 */
48 #define SPM_HIF1_PWR_CON 0x02e8 /* MT7622 */
49 #define SPM_WB_PWR_CON 0x02ec /* MT7622 */
51 #define SPM_PWR_STATUS 0x060c
52 #define SPM_PWR_STATUS_2ND 0x0610
54 #define PWR_RST_B_BIT BIT(0)
55 #define PWR_ISO_BIT BIT(1)
56 #define PWR_ON_BIT BIT(2)
57 #define PWR_ON_2ND_BIT BIT(3)
58 #define PWR_CLK_DIS_BIT BIT(4)
60 #define PWR_STATUS_CONN BIT(1)
61 #define PWR_STATUS_DISP BIT(3)
62 #define PWR_STATUS_MFG BIT(4)
63 #define PWR_STATUS_ISP BIT(5)
64 #define PWR_STATUS_VDEC BIT(7)
65 #define PWR_STATUS_BDP BIT(14)
66 #define PWR_STATUS_ETH BIT(15)
67 #define PWR_STATUS_HIF BIT(16)
68 #define PWR_STATUS_IFR_MSC BIT(17)
69 #define PWR_STATUS_USB2 BIT(19) /* MT2712 */
70 #define PWR_STATUS_VENC_LT BIT(20)
71 #define PWR_STATUS_VENC BIT(21)
72 #define PWR_STATUS_MFG_2D BIT(22) /* MT8173 */
73 #define PWR_STATUS_MFG_ASYNC BIT(23) /* MT8173 */
74 #define PWR_STATUS_AUDIO BIT(24) /* MT8173, MT2712 */
75 #define PWR_STATUS_USB BIT(25) /* MT8173, MT2712 */
76 #define PWR_STATUS_ETHSYS BIT(24) /* MT7622 */
77 #define PWR_STATUS_HIF0 BIT(25) /* MT7622 */
78 #define PWR_STATUS_HIF1 BIT(26) /* MT7622 */
79 #define PWR_STATUS_WB BIT(27) /* MT7622 */
95 static const char * const clk_names
[] = {
112 * struct scp_domain_data - scp domain data for power on/off flow
113 * @name: The domain name.
114 * @sta_mask: The mask for power on/off status bit.
115 * @ctl_offs: The offset for main power control register.
116 * @sram_pdn_bits: The mask for sram power control bits.
117 * @sram_pdn_ack_bits: The mask for sram power control acked bits.
118 * @bus_prot_mask: The mask for single step bus protection.
119 * @clk_id: The basic clocks required by this power domain.
120 * @caps: The flag for active wake-up action.
122 struct scp_domain_data
{
127 u32 sram_pdn_ack_bits
;
129 enum clk_id clk_id
[MAX_CLKS
];
136 struct generic_pm_domain genpd
;
138 struct clk
*clk
[MAX_CLKS
];
139 const struct scp_domain_data
*data
;
140 struct regulator
*supply
;
143 struct scp_ctrl_reg
{
149 struct scp_domain
*domains
;
150 struct genpd_onecell_data pd_data
;
153 struct regmap
*infracfg
;
154 struct scp_ctrl_reg ctrl_reg
;
155 bool bus_prot_reg_update
;
158 struct scp_subdomain
{
163 struct scp_soc_data
{
164 const struct scp_domain_data
*domains
;
166 const struct scp_subdomain
*subdomains
;
168 const struct scp_ctrl_reg regs
;
169 bool bus_prot_reg_update
;
172 static int scpsys_domain_is_on(struct scp_domain
*scpd
)
174 struct scp
*scp
= scpd
->scp
;
176 u32 status
= readl(scp
->base
+ scp
->ctrl_reg
.pwr_sta_offs
) &
177 scpd
->data
->sta_mask
;
178 u32 status2
= readl(scp
->base
+ scp
->ctrl_reg
.pwr_sta2nd_offs
) &
179 scpd
->data
->sta_mask
;
182 * A domain is on when both status bits are set. If only one is set
183 * return an error. This happens while powering up a domain
186 if (status
&& status2
)
188 if (!status
&& !status2
)
194 static int scpsys_regulator_enable(struct scp_domain
*scpd
)
199 return regulator_enable(scpd
->supply
);
202 static int scpsys_regulator_disable(struct scp_domain
*scpd
)
207 return regulator_disable(scpd
->supply
);
210 static void scpsys_clk_disable(struct clk
*clk
[], int max_num
)
214 for (i
= max_num
- 1; i
>= 0; i
--)
215 clk_disable_unprepare(clk
[i
]);
218 static int scpsys_clk_enable(struct clk
*clk
[], int max_num
)
222 for (i
= 0; i
< max_num
&& clk
[i
]; i
++) {
223 ret
= clk_prepare_enable(clk
[i
]);
225 scpsys_clk_disable(clk
, i
);
233 static int scpsys_sram_enable(struct scp_domain
*scpd
, void __iomem
*ctl_addr
)
236 u32 pdn_ack
= scpd
->data
->sram_pdn_ack_bits
;
239 val
= readl(ctl_addr
);
240 val
&= ~scpd
->data
->sram_pdn_bits
;
241 writel(val
, ctl_addr
);
243 /* Either wait until SRAM_PDN_ACK all 0 or have a force wait */
244 if (MTK_SCPD_CAPS(scpd
, MTK_SCPD_FWAIT_SRAM
)) {
246 * Currently, MTK_SCPD_FWAIT_SRAM is necessary only for
247 * MT7622_POWER_DOMAIN_WB and thus just a trivial setup
250 usleep_range(12000, 12100);
252 /* Either wait until SRAM_PDN_ACK all 1 or 0 */
253 int ret
= readl_poll_timeout(ctl_addr
, tmp
,
254 (tmp
& pdn_ack
) == 0,
255 MTK_POLL_DELAY_US
, MTK_POLL_TIMEOUT
);
263 static int scpsys_sram_disable(struct scp_domain
*scpd
, void __iomem
*ctl_addr
)
266 u32 pdn_ack
= scpd
->data
->sram_pdn_ack_bits
;
269 val
= readl(ctl_addr
);
270 val
|= scpd
->data
->sram_pdn_bits
;
271 writel(val
, ctl_addr
);
273 /* Either wait until SRAM_PDN_ACK all 1 or 0 */
274 return readl_poll_timeout(ctl_addr
, tmp
,
275 (tmp
& pdn_ack
) == pdn_ack
,
276 MTK_POLL_DELAY_US
, MTK_POLL_TIMEOUT
);
279 static int scpsys_bus_protect_enable(struct scp_domain
*scpd
)
281 struct scp
*scp
= scpd
->scp
;
283 if (!scpd
->data
->bus_prot_mask
)
286 return mtk_infracfg_set_bus_protection(scp
->infracfg
,
287 scpd
->data
->bus_prot_mask
,
288 scp
->bus_prot_reg_update
);
291 static int scpsys_bus_protect_disable(struct scp_domain
*scpd
)
293 struct scp
*scp
= scpd
->scp
;
295 if (!scpd
->data
->bus_prot_mask
)
298 return mtk_infracfg_clear_bus_protection(scp
->infracfg
,
299 scpd
->data
->bus_prot_mask
,
300 scp
->bus_prot_reg_update
);
303 static int scpsys_power_on(struct generic_pm_domain
*genpd
)
305 struct scp_domain
*scpd
= container_of(genpd
, struct scp_domain
, genpd
);
306 struct scp
*scp
= scpd
->scp
;
307 void __iomem
*ctl_addr
= scp
->base
+ scpd
->data
->ctl_offs
;
311 ret
= scpsys_regulator_enable(scpd
);
315 ret
= scpsys_clk_enable(scpd
->clk
, MAX_CLKS
);
319 /* subsys power on */
320 val
= readl(ctl_addr
);
322 writel(val
, ctl_addr
);
323 val
|= PWR_ON_2ND_BIT
;
324 writel(val
, ctl_addr
);
326 /* wait until PWR_ACK = 1 */
327 ret
= readx_poll_timeout(scpsys_domain_is_on
, scpd
, tmp
, tmp
> 0,
328 MTK_POLL_DELAY_US
, MTK_POLL_TIMEOUT
);
332 val
&= ~PWR_CLK_DIS_BIT
;
333 writel(val
, ctl_addr
);
336 writel(val
, ctl_addr
);
338 val
|= PWR_RST_B_BIT
;
339 writel(val
, ctl_addr
);
341 ret
= scpsys_sram_enable(scpd
, ctl_addr
);
345 ret
= scpsys_bus_protect_disable(scpd
);
352 scpsys_clk_disable(scpd
->clk
, MAX_CLKS
);
354 scpsys_regulator_disable(scpd
);
356 dev_err(scp
->dev
, "Failed to power on domain %s\n", genpd
->name
);
361 static int scpsys_power_off(struct generic_pm_domain
*genpd
)
363 struct scp_domain
*scpd
= container_of(genpd
, struct scp_domain
, genpd
);
364 struct scp
*scp
= scpd
->scp
;
365 void __iomem
*ctl_addr
= scp
->base
+ scpd
->data
->ctl_offs
;
369 ret
= scpsys_bus_protect_enable(scpd
);
373 ret
= scpsys_sram_disable(scpd
, ctl_addr
);
377 /* subsys power off */
378 val
= readl(ctl_addr
);
380 writel(val
, ctl_addr
);
382 val
&= ~PWR_RST_B_BIT
;
383 writel(val
, ctl_addr
);
385 val
|= PWR_CLK_DIS_BIT
;
386 writel(val
, ctl_addr
);
389 writel(val
, ctl_addr
);
391 val
&= ~PWR_ON_2ND_BIT
;
392 writel(val
, ctl_addr
);
394 /* wait until PWR_ACK = 0 */
395 ret
= readx_poll_timeout(scpsys_domain_is_on
, scpd
, tmp
, tmp
== 0,
396 MTK_POLL_DELAY_US
, MTK_POLL_TIMEOUT
);
400 scpsys_clk_disable(scpd
->clk
, MAX_CLKS
);
402 ret
= scpsys_regulator_disable(scpd
);
409 dev_err(scp
->dev
, "Failed to power off domain %s\n", genpd
->name
);
414 static void init_clks(struct platform_device
*pdev
, struct clk
**clk
)
418 for (i
= CLK_NONE
+ 1; i
< CLK_MAX
; i
++)
419 clk
[i
] = devm_clk_get(&pdev
->dev
, clk_names
[i
]);
422 static struct scp
*init_scp(struct platform_device
*pdev
,
423 const struct scp_domain_data
*scp_domain_data
, int num
,
424 const struct scp_ctrl_reg
*scp_ctrl_reg
,
425 bool bus_prot_reg_update
)
427 struct genpd_onecell_data
*pd_data
;
430 struct clk
*clk
[CLK_MAX
];
432 scp
= devm_kzalloc(&pdev
->dev
, sizeof(*scp
), GFP_KERNEL
);
434 return ERR_PTR(-ENOMEM
);
436 scp
->ctrl_reg
.pwr_sta_offs
= scp_ctrl_reg
->pwr_sta_offs
;
437 scp
->ctrl_reg
.pwr_sta2nd_offs
= scp_ctrl_reg
->pwr_sta2nd_offs
;
439 scp
->bus_prot_reg_update
= bus_prot_reg_update
;
441 scp
->dev
= &pdev
->dev
;
443 scp
->base
= devm_platform_ioremap_resource(pdev
, 0);
444 if (IS_ERR(scp
->base
))
445 return ERR_CAST(scp
->base
);
447 scp
->domains
= devm_kcalloc(&pdev
->dev
,
448 num
, sizeof(*scp
->domains
), GFP_KERNEL
);
450 return ERR_PTR(-ENOMEM
);
452 pd_data
= &scp
->pd_data
;
454 pd_data
->domains
= devm_kcalloc(&pdev
->dev
,
455 num
, sizeof(*pd_data
->domains
), GFP_KERNEL
);
456 if (!pd_data
->domains
)
457 return ERR_PTR(-ENOMEM
);
459 scp
->infracfg
= syscon_regmap_lookup_by_phandle(pdev
->dev
.of_node
,
461 if (IS_ERR(scp
->infracfg
)) {
462 dev_err(&pdev
->dev
, "Cannot find infracfg controller: %ld\n",
463 PTR_ERR(scp
->infracfg
));
464 return ERR_CAST(scp
->infracfg
);
467 for (i
= 0; i
< num
; i
++) {
468 struct scp_domain
*scpd
= &scp
->domains
[i
];
469 const struct scp_domain_data
*data
= &scp_domain_data
[i
];
471 scpd
->supply
= devm_regulator_get_optional(&pdev
->dev
, data
->name
);
472 if (IS_ERR(scpd
->supply
)) {
473 if (PTR_ERR(scpd
->supply
) == -ENODEV
)
476 return ERR_CAST(scpd
->supply
);
480 pd_data
->num_domains
= num
;
482 init_clks(pdev
, clk
);
484 for (i
= 0; i
< num
; i
++) {
485 struct scp_domain
*scpd
= &scp
->domains
[i
];
486 struct generic_pm_domain
*genpd
= &scpd
->genpd
;
487 const struct scp_domain_data
*data
= &scp_domain_data
[i
];
489 pd_data
->domains
[i
] = genpd
;
494 for (j
= 0; j
< MAX_CLKS
&& data
->clk_id
[j
]; j
++) {
495 struct clk
*c
= clk
[data
->clk_id
[j
]];
498 dev_err(&pdev
->dev
, "%s: clk unavailable\n",
506 genpd
->name
= data
->name
;
507 genpd
->power_off
= scpsys_power_off
;
508 genpd
->power_on
= scpsys_power_on
;
509 if (MTK_SCPD_CAPS(scpd
, MTK_SCPD_ACTIVE_WAKEUP
))
510 genpd
->flags
|= GENPD_FLAG_ACTIVE_WAKEUP
;
516 static void mtk_register_power_domains(struct platform_device
*pdev
,
517 struct scp
*scp
, int num
)
519 struct genpd_onecell_data
*pd_data
;
522 for (i
= 0; i
< num
; i
++) {
523 struct scp_domain
*scpd
= &scp
->domains
[i
];
524 struct generic_pm_domain
*genpd
= &scpd
->genpd
;
528 * Initially turn on all domains to make the domains usable
529 * with !CONFIG_PM and to get the hardware in sync with the
530 * software. The unused domains will be switched off during
533 on
= !WARN_ON(genpd
->power_on(genpd
) < 0);
535 pm_genpd_init(genpd
, NULL
, !on
);
539 * We are not allowed to fail here since there is no way to unregister
540 * a power domain. Once registered above we have to keep the domains
544 pd_data
= &scp
->pd_data
;
546 ret
= of_genpd_add_provider_onecell(pdev
->dev
.of_node
, pd_data
);
548 dev_err(&pdev
->dev
, "Failed to add OF provider: %d\n", ret
);
552 * MT2701 power domain support
555 static const struct scp_domain_data scp_domain_data_mt2701
[] = {
556 [MT2701_POWER_DOMAIN_CONN
] = {
558 .sta_mask
= PWR_STATUS_CONN
,
559 .ctl_offs
= SPM_CONN_PWR_CON
,
560 .bus_prot_mask
= MT2701_TOP_AXI_PROT_EN_CONN_M
|
561 MT2701_TOP_AXI_PROT_EN_CONN_S
,
562 .clk_id
= {CLK_NONE
},
563 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
565 [MT2701_POWER_DOMAIN_DISP
] = {
567 .sta_mask
= PWR_STATUS_DISP
,
568 .ctl_offs
= SPM_DIS_PWR_CON
,
569 .sram_pdn_bits
= GENMASK(11, 8),
571 .bus_prot_mask
= MT2701_TOP_AXI_PROT_EN_MM_M0
,
572 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
574 [MT2701_POWER_DOMAIN_MFG
] = {
576 .sta_mask
= PWR_STATUS_MFG
,
577 .ctl_offs
= SPM_MFG_PWR_CON
,
578 .sram_pdn_bits
= GENMASK(11, 8),
579 .sram_pdn_ack_bits
= GENMASK(12, 12),
581 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
583 [MT2701_POWER_DOMAIN_VDEC
] = {
585 .sta_mask
= PWR_STATUS_VDEC
,
586 .ctl_offs
= SPM_VDE_PWR_CON
,
587 .sram_pdn_bits
= GENMASK(11, 8),
588 .sram_pdn_ack_bits
= GENMASK(12, 12),
590 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
592 [MT2701_POWER_DOMAIN_ISP
] = {
594 .sta_mask
= PWR_STATUS_ISP
,
595 .ctl_offs
= SPM_ISP_PWR_CON
,
596 .sram_pdn_bits
= GENMASK(11, 8),
597 .sram_pdn_ack_bits
= GENMASK(13, 12),
599 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
601 [MT2701_POWER_DOMAIN_BDP
] = {
603 .sta_mask
= PWR_STATUS_BDP
,
604 .ctl_offs
= SPM_BDP_PWR_CON
,
605 .sram_pdn_bits
= GENMASK(11, 8),
606 .clk_id
= {CLK_NONE
},
607 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
609 [MT2701_POWER_DOMAIN_ETH
] = {
611 .sta_mask
= PWR_STATUS_ETH
,
612 .ctl_offs
= SPM_ETH_PWR_CON
,
613 .sram_pdn_bits
= GENMASK(11, 8),
614 .sram_pdn_ack_bits
= GENMASK(15, 12),
615 .clk_id
= {CLK_ETHIF
},
616 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
618 [MT2701_POWER_DOMAIN_HIF
] = {
620 .sta_mask
= PWR_STATUS_HIF
,
621 .ctl_offs
= SPM_HIF_PWR_CON
,
622 .sram_pdn_bits
= GENMASK(11, 8),
623 .sram_pdn_ack_bits
= GENMASK(15, 12),
624 .clk_id
= {CLK_ETHIF
},
625 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
627 [MT2701_POWER_DOMAIN_IFR_MSC
] = {
629 .sta_mask
= PWR_STATUS_IFR_MSC
,
630 .ctl_offs
= SPM_IFR_MSC_PWR_CON
,
631 .clk_id
= {CLK_NONE
},
632 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
637 * MT2712 power domain support
639 static const struct scp_domain_data scp_domain_data_mt2712
[] = {
640 [MT2712_POWER_DOMAIN_MM
] = {
642 .sta_mask
= PWR_STATUS_DISP
,
643 .ctl_offs
= SPM_DIS_PWR_CON
,
644 .sram_pdn_bits
= GENMASK(8, 8),
645 .sram_pdn_ack_bits
= GENMASK(12, 12),
647 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
649 [MT2712_POWER_DOMAIN_VDEC
] = {
651 .sta_mask
= PWR_STATUS_VDEC
,
652 .ctl_offs
= SPM_VDE_PWR_CON
,
653 .sram_pdn_bits
= GENMASK(8, 8),
654 .sram_pdn_ack_bits
= GENMASK(12, 12),
655 .clk_id
= {CLK_MM
, CLK_VDEC
},
656 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
658 [MT2712_POWER_DOMAIN_VENC
] = {
660 .sta_mask
= PWR_STATUS_VENC
,
661 .ctl_offs
= SPM_VEN_PWR_CON
,
662 .sram_pdn_bits
= GENMASK(11, 8),
663 .sram_pdn_ack_bits
= GENMASK(15, 12),
664 .clk_id
= {CLK_MM
, CLK_VENC
, CLK_JPGDEC
},
665 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
667 [MT2712_POWER_DOMAIN_ISP
] = {
669 .sta_mask
= PWR_STATUS_ISP
,
670 .ctl_offs
= SPM_ISP_PWR_CON
,
671 .sram_pdn_bits
= GENMASK(11, 8),
672 .sram_pdn_ack_bits
= GENMASK(13, 12),
674 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
676 [MT2712_POWER_DOMAIN_AUDIO
] = {
678 .sta_mask
= PWR_STATUS_AUDIO
,
679 .ctl_offs
= SPM_AUDIO_PWR_CON
,
680 .sram_pdn_bits
= GENMASK(11, 8),
681 .sram_pdn_ack_bits
= GENMASK(15, 12),
682 .clk_id
= {CLK_AUDIO
},
683 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
685 [MT2712_POWER_DOMAIN_USB
] = {
687 .sta_mask
= PWR_STATUS_USB
,
688 .ctl_offs
= SPM_USB_PWR_CON
,
689 .sram_pdn_bits
= GENMASK(10, 8),
690 .sram_pdn_ack_bits
= GENMASK(14, 12),
691 .clk_id
= {CLK_NONE
},
692 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
694 [MT2712_POWER_DOMAIN_USB2
] = {
696 .sta_mask
= PWR_STATUS_USB2
,
697 .ctl_offs
= SPM_USB2_PWR_CON
,
698 .sram_pdn_bits
= GENMASK(10, 8),
699 .sram_pdn_ack_bits
= GENMASK(14, 12),
700 .clk_id
= {CLK_NONE
},
701 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
703 [MT2712_POWER_DOMAIN_MFG
] = {
705 .sta_mask
= PWR_STATUS_MFG
,
706 .ctl_offs
= SPM_MFG_PWR_CON
,
707 .sram_pdn_bits
= GENMASK(8, 8),
708 .sram_pdn_ack_bits
= GENMASK(16, 16),
710 .bus_prot_mask
= BIT(14) | BIT(21) | BIT(23),
711 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
713 [MT2712_POWER_DOMAIN_MFG_SC1
] = {
717 .sram_pdn_bits
= GENMASK(8, 8),
718 .sram_pdn_ack_bits
= GENMASK(16, 16),
719 .clk_id
= {CLK_NONE
},
720 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
722 [MT2712_POWER_DOMAIN_MFG_SC2
] = {
726 .sram_pdn_bits
= GENMASK(8, 8),
727 .sram_pdn_ack_bits
= GENMASK(16, 16),
728 .clk_id
= {CLK_NONE
},
729 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
731 [MT2712_POWER_DOMAIN_MFG_SC3
] = {
735 .sram_pdn_bits
= GENMASK(8, 8),
736 .sram_pdn_ack_bits
= GENMASK(16, 16),
737 .clk_id
= {CLK_NONE
},
738 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
742 static const struct scp_subdomain scp_subdomain_mt2712
[] = {
743 {MT2712_POWER_DOMAIN_MM
, MT2712_POWER_DOMAIN_VDEC
},
744 {MT2712_POWER_DOMAIN_MM
, MT2712_POWER_DOMAIN_VENC
},
745 {MT2712_POWER_DOMAIN_MM
, MT2712_POWER_DOMAIN_ISP
},
746 {MT2712_POWER_DOMAIN_MFG
, MT2712_POWER_DOMAIN_MFG_SC1
},
747 {MT2712_POWER_DOMAIN_MFG_SC1
, MT2712_POWER_DOMAIN_MFG_SC2
},
748 {MT2712_POWER_DOMAIN_MFG_SC2
, MT2712_POWER_DOMAIN_MFG_SC3
},
752 * MT6797 power domain support
755 static const struct scp_domain_data scp_domain_data_mt6797
[] = {
756 [MT6797_POWER_DOMAIN_VDEC
] = {
760 .sram_pdn_bits
= GENMASK(8, 8),
761 .sram_pdn_ack_bits
= GENMASK(12, 12),
762 .clk_id
= {CLK_VDEC
},
764 [MT6797_POWER_DOMAIN_VENC
] = {
768 .sram_pdn_bits
= GENMASK(11, 8),
769 .sram_pdn_ack_bits
= GENMASK(15, 12),
770 .clk_id
= {CLK_NONE
},
772 [MT6797_POWER_DOMAIN_ISP
] = {
776 .sram_pdn_bits
= GENMASK(9, 8),
777 .sram_pdn_ack_bits
= GENMASK(13, 12),
778 .clk_id
= {CLK_NONE
},
780 [MT6797_POWER_DOMAIN_MM
] = {
784 .sram_pdn_bits
= GENMASK(8, 8),
785 .sram_pdn_ack_bits
= GENMASK(12, 12),
787 .bus_prot_mask
= (BIT(1) | BIT(2)),
789 [MT6797_POWER_DOMAIN_AUDIO
] = {
793 .sram_pdn_bits
= GENMASK(11, 8),
794 .sram_pdn_ack_bits
= GENMASK(15, 12),
795 .clk_id
= {CLK_NONE
},
797 [MT6797_POWER_DOMAIN_MFG_ASYNC
] = {
802 .sram_pdn_ack_bits
= 0,
805 [MT6797_POWER_DOMAIN_MJC
] = {
809 .sram_pdn_bits
= GENMASK(8, 8),
810 .sram_pdn_ack_bits
= GENMASK(12, 12),
811 .clk_id
= {CLK_NONE
},
815 #define SPM_PWR_STATUS_MT6797 0x0180
816 #define SPM_PWR_STATUS_2ND_MT6797 0x0184
818 static const struct scp_subdomain scp_subdomain_mt6797
[] = {
819 {MT6797_POWER_DOMAIN_MM
, MT6797_POWER_DOMAIN_VDEC
},
820 {MT6797_POWER_DOMAIN_MM
, MT6797_POWER_DOMAIN_ISP
},
821 {MT6797_POWER_DOMAIN_MM
, MT6797_POWER_DOMAIN_VENC
},
822 {MT6797_POWER_DOMAIN_MM
, MT6797_POWER_DOMAIN_MJC
},
826 * MT7622 power domain support
829 static const struct scp_domain_data scp_domain_data_mt7622
[] = {
830 [MT7622_POWER_DOMAIN_ETHSYS
] = {
832 .sta_mask
= PWR_STATUS_ETHSYS
,
833 .ctl_offs
= SPM_ETHSYS_PWR_CON
,
834 .sram_pdn_bits
= GENMASK(11, 8),
835 .sram_pdn_ack_bits
= GENMASK(15, 12),
836 .clk_id
= {CLK_NONE
},
837 .bus_prot_mask
= MT7622_TOP_AXI_PROT_EN_ETHSYS
,
838 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
840 [MT7622_POWER_DOMAIN_HIF0
] = {
842 .sta_mask
= PWR_STATUS_HIF0
,
843 .ctl_offs
= SPM_HIF0_PWR_CON
,
844 .sram_pdn_bits
= GENMASK(11, 8),
845 .sram_pdn_ack_bits
= GENMASK(15, 12),
846 .clk_id
= {CLK_HIFSEL
},
847 .bus_prot_mask
= MT7622_TOP_AXI_PROT_EN_HIF0
,
848 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
850 [MT7622_POWER_DOMAIN_HIF1
] = {
852 .sta_mask
= PWR_STATUS_HIF1
,
853 .ctl_offs
= SPM_HIF1_PWR_CON
,
854 .sram_pdn_bits
= GENMASK(11, 8),
855 .sram_pdn_ack_bits
= GENMASK(15, 12),
856 .clk_id
= {CLK_HIFSEL
},
857 .bus_prot_mask
= MT7622_TOP_AXI_PROT_EN_HIF1
,
858 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
860 [MT7622_POWER_DOMAIN_WB
] = {
862 .sta_mask
= PWR_STATUS_WB
,
863 .ctl_offs
= SPM_WB_PWR_CON
,
865 .sram_pdn_ack_bits
= 0,
866 .clk_id
= {CLK_NONE
},
867 .bus_prot_mask
= MT7622_TOP_AXI_PROT_EN_WB
,
868 .caps
= MTK_SCPD_ACTIVE_WAKEUP
| MTK_SCPD_FWAIT_SRAM
,
873 * MT7623A power domain support
876 static const struct scp_domain_data scp_domain_data_mt7623a
[] = {
877 [MT7623A_POWER_DOMAIN_CONN
] = {
879 .sta_mask
= PWR_STATUS_CONN
,
880 .ctl_offs
= SPM_CONN_PWR_CON
,
881 .bus_prot_mask
= MT2701_TOP_AXI_PROT_EN_CONN_M
|
882 MT2701_TOP_AXI_PROT_EN_CONN_S
,
883 .clk_id
= {CLK_NONE
},
884 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
886 [MT7623A_POWER_DOMAIN_ETH
] = {
888 .sta_mask
= PWR_STATUS_ETH
,
889 .ctl_offs
= SPM_ETH_PWR_CON
,
890 .sram_pdn_bits
= GENMASK(11, 8),
891 .sram_pdn_ack_bits
= GENMASK(15, 12),
892 .clk_id
= {CLK_ETHIF
},
893 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
895 [MT7623A_POWER_DOMAIN_HIF
] = {
897 .sta_mask
= PWR_STATUS_HIF
,
898 .ctl_offs
= SPM_HIF_PWR_CON
,
899 .sram_pdn_bits
= GENMASK(11, 8),
900 .sram_pdn_ack_bits
= GENMASK(15, 12),
901 .clk_id
= {CLK_ETHIF
},
902 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
904 [MT7623A_POWER_DOMAIN_IFR_MSC
] = {
906 .sta_mask
= PWR_STATUS_IFR_MSC
,
907 .ctl_offs
= SPM_IFR_MSC_PWR_CON
,
908 .clk_id
= {CLK_NONE
},
909 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
914 * MT8173 power domain support
917 static const struct scp_domain_data scp_domain_data_mt8173
[] = {
918 [MT8173_POWER_DOMAIN_VDEC
] = {
920 .sta_mask
= PWR_STATUS_VDEC
,
921 .ctl_offs
= SPM_VDE_PWR_CON
,
922 .sram_pdn_bits
= GENMASK(11, 8),
923 .sram_pdn_ack_bits
= GENMASK(12, 12),
926 [MT8173_POWER_DOMAIN_VENC
] = {
928 .sta_mask
= PWR_STATUS_VENC
,
929 .ctl_offs
= SPM_VEN_PWR_CON
,
930 .sram_pdn_bits
= GENMASK(11, 8),
931 .sram_pdn_ack_bits
= GENMASK(15, 12),
932 .clk_id
= {CLK_MM
, CLK_VENC
},
934 [MT8173_POWER_DOMAIN_ISP
] = {
936 .sta_mask
= PWR_STATUS_ISP
,
937 .ctl_offs
= SPM_ISP_PWR_CON
,
938 .sram_pdn_bits
= GENMASK(11, 8),
939 .sram_pdn_ack_bits
= GENMASK(13, 12),
942 [MT8173_POWER_DOMAIN_MM
] = {
944 .sta_mask
= PWR_STATUS_DISP
,
945 .ctl_offs
= SPM_DIS_PWR_CON
,
946 .sram_pdn_bits
= GENMASK(11, 8),
947 .sram_pdn_ack_bits
= GENMASK(12, 12),
949 .bus_prot_mask
= MT8173_TOP_AXI_PROT_EN_MM_M0
|
950 MT8173_TOP_AXI_PROT_EN_MM_M1
,
952 [MT8173_POWER_DOMAIN_VENC_LT
] = {
954 .sta_mask
= PWR_STATUS_VENC_LT
,
955 .ctl_offs
= SPM_VEN2_PWR_CON
,
956 .sram_pdn_bits
= GENMASK(11, 8),
957 .sram_pdn_ack_bits
= GENMASK(15, 12),
958 .clk_id
= {CLK_MM
, CLK_VENC_LT
},
960 [MT8173_POWER_DOMAIN_AUDIO
] = {
962 .sta_mask
= PWR_STATUS_AUDIO
,
963 .ctl_offs
= SPM_AUDIO_PWR_CON
,
964 .sram_pdn_bits
= GENMASK(11, 8),
965 .sram_pdn_ack_bits
= GENMASK(15, 12),
966 .clk_id
= {CLK_NONE
},
968 [MT8173_POWER_DOMAIN_USB
] = {
970 .sta_mask
= PWR_STATUS_USB
,
971 .ctl_offs
= SPM_USB_PWR_CON
,
972 .sram_pdn_bits
= GENMASK(11, 8),
973 .sram_pdn_ack_bits
= GENMASK(15, 12),
974 .clk_id
= {CLK_NONE
},
975 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
977 [MT8173_POWER_DOMAIN_MFG_ASYNC
] = {
979 .sta_mask
= PWR_STATUS_MFG_ASYNC
,
980 .ctl_offs
= SPM_MFG_ASYNC_PWR_CON
,
981 .sram_pdn_bits
= GENMASK(11, 8),
982 .sram_pdn_ack_bits
= 0,
985 [MT8173_POWER_DOMAIN_MFG_2D
] = {
987 .sta_mask
= PWR_STATUS_MFG_2D
,
988 .ctl_offs
= SPM_MFG_2D_PWR_CON
,
989 .sram_pdn_bits
= GENMASK(11, 8),
990 .sram_pdn_ack_bits
= GENMASK(13, 12),
991 .clk_id
= {CLK_NONE
},
993 [MT8173_POWER_DOMAIN_MFG
] = {
995 .sta_mask
= PWR_STATUS_MFG
,
996 .ctl_offs
= SPM_MFG_PWR_CON
,
997 .sram_pdn_bits
= GENMASK(13, 8),
998 .sram_pdn_ack_bits
= GENMASK(21, 16),
999 .clk_id
= {CLK_NONE
},
1000 .bus_prot_mask
= MT8173_TOP_AXI_PROT_EN_MFG_S
|
1001 MT8173_TOP_AXI_PROT_EN_MFG_M0
|
1002 MT8173_TOP_AXI_PROT_EN_MFG_M1
|
1003 MT8173_TOP_AXI_PROT_EN_MFG_SNOOP_OUT
,
1007 static const struct scp_subdomain scp_subdomain_mt8173
[] = {
1008 {MT8173_POWER_DOMAIN_MFG_ASYNC
, MT8173_POWER_DOMAIN_MFG_2D
},
1009 {MT8173_POWER_DOMAIN_MFG_2D
, MT8173_POWER_DOMAIN_MFG
},
1012 static const struct scp_soc_data mt2701_data
= {
1013 .domains
= scp_domain_data_mt2701
,
1014 .num_domains
= ARRAY_SIZE(scp_domain_data_mt2701
),
1016 .pwr_sta_offs
= SPM_PWR_STATUS
,
1017 .pwr_sta2nd_offs
= SPM_PWR_STATUS_2ND
1019 .bus_prot_reg_update
= true,
1022 static const struct scp_soc_data mt2712_data
= {
1023 .domains
= scp_domain_data_mt2712
,
1024 .num_domains
= ARRAY_SIZE(scp_domain_data_mt2712
),
1025 .subdomains
= scp_subdomain_mt2712
,
1026 .num_subdomains
= ARRAY_SIZE(scp_subdomain_mt2712
),
1028 .pwr_sta_offs
= SPM_PWR_STATUS
,
1029 .pwr_sta2nd_offs
= SPM_PWR_STATUS_2ND
1031 .bus_prot_reg_update
= false,
1034 static const struct scp_soc_data mt6797_data
= {
1035 .domains
= scp_domain_data_mt6797
,
1036 .num_domains
= ARRAY_SIZE(scp_domain_data_mt6797
),
1037 .subdomains
= scp_subdomain_mt6797
,
1038 .num_subdomains
= ARRAY_SIZE(scp_subdomain_mt6797
),
1040 .pwr_sta_offs
= SPM_PWR_STATUS_MT6797
,
1041 .pwr_sta2nd_offs
= SPM_PWR_STATUS_2ND_MT6797
1043 .bus_prot_reg_update
= true,
1046 static const struct scp_soc_data mt7622_data
= {
1047 .domains
= scp_domain_data_mt7622
,
1048 .num_domains
= ARRAY_SIZE(scp_domain_data_mt7622
),
1050 .pwr_sta_offs
= SPM_PWR_STATUS
,
1051 .pwr_sta2nd_offs
= SPM_PWR_STATUS_2ND
1053 .bus_prot_reg_update
= true,
1056 static const struct scp_soc_data mt7623a_data
= {
1057 .domains
= scp_domain_data_mt7623a
,
1058 .num_domains
= ARRAY_SIZE(scp_domain_data_mt7623a
),
1060 .pwr_sta_offs
= SPM_PWR_STATUS
,
1061 .pwr_sta2nd_offs
= SPM_PWR_STATUS_2ND
1063 .bus_prot_reg_update
= true,
1066 static const struct scp_soc_data mt8173_data
= {
1067 .domains
= scp_domain_data_mt8173
,
1068 .num_domains
= ARRAY_SIZE(scp_domain_data_mt8173
),
1069 .subdomains
= scp_subdomain_mt8173
,
1070 .num_subdomains
= ARRAY_SIZE(scp_subdomain_mt8173
),
1072 .pwr_sta_offs
= SPM_PWR_STATUS
,
1073 .pwr_sta2nd_offs
= SPM_PWR_STATUS_2ND
1075 .bus_prot_reg_update
= true,
1079 * scpsys driver init
1082 static const struct of_device_id of_scpsys_match_tbl
[] = {
1084 .compatible
= "mediatek,mt2701-scpsys",
1085 .data
= &mt2701_data
,
1087 .compatible
= "mediatek,mt2712-scpsys",
1088 .data
= &mt2712_data
,
1090 .compatible
= "mediatek,mt6797-scpsys",
1091 .data
= &mt6797_data
,
1093 .compatible
= "mediatek,mt7622-scpsys",
1094 .data
= &mt7622_data
,
1096 .compatible
= "mediatek,mt7623a-scpsys",
1097 .data
= &mt7623a_data
,
1099 .compatible
= "mediatek,mt8173-scpsys",
1100 .data
= &mt8173_data
,
1106 static int scpsys_probe(struct platform_device
*pdev
)
1108 const struct scp_subdomain
*sd
;
1109 const struct scp_soc_data
*soc
;
1111 struct genpd_onecell_data
*pd_data
;
1114 soc
= of_device_get_match_data(&pdev
->dev
);
1116 scp
= init_scp(pdev
, soc
->domains
, soc
->num_domains
, &soc
->regs
,
1117 soc
->bus_prot_reg_update
);
1119 return PTR_ERR(scp
);
1121 mtk_register_power_domains(pdev
, scp
, soc
->num_domains
);
1123 pd_data
= &scp
->pd_data
;
1125 for (i
= 0, sd
= soc
->subdomains
; i
< soc
->num_subdomains
; i
++, sd
++) {
1126 ret
= pm_genpd_add_subdomain(pd_data
->domains
[sd
->origin
],
1127 pd_data
->domains
[sd
->subdomain
]);
1128 if (ret
&& IS_ENABLED(CONFIG_PM
))
1129 dev_err(&pdev
->dev
, "Failed to add subdomain: %d\n",
1136 static struct platform_driver scpsys_drv
= {
1137 .probe
= scpsys_probe
,
1139 .name
= "mtk-scpsys",
1140 .suppress_bind_attrs
= true,
1141 .of_match_table
= of_scpsys_match_tbl
,
1144 builtin_platform_driver(scpsys_drv
);