2 * Copyright (c) 2015 Pengutronix, Sascha Hauer <kernel@pengutronix.de>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 #include <linux/clk.h>
14 #include <linux/init.h>
16 #include <linux/iopoll.h>
17 #include <linux/mfd/syscon.h>
18 #include <linux/of_device.h>
19 #include <linux/platform_device.h>
20 #include <linux/pm_domain.h>
21 #include <linux/regulator/consumer.h>
22 #include <linux/soc/mediatek/infracfg.h>
24 #include <dt-bindings/power/mt2701-power.h>
25 #include <dt-bindings/power/mt2712-power.h>
26 #include <dt-bindings/power/mt6797-power.h>
27 #include <dt-bindings/power/mt7622-power.h>
28 #include <dt-bindings/power/mt7623a-power.h>
29 #include <dt-bindings/power/mt8173-power.h>
31 #define MTK_POLL_DELAY_US 10
32 #define MTK_POLL_TIMEOUT (jiffies_to_usecs(HZ))
34 #define MTK_SCPD_ACTIVE_WAKEUP BIT(0)
35 #define MTK_SCPD_FWAIT_SRAM BIT(1)
36 #define MTK_SCPD_CAPS(_scpd, _x) ((_scpd)->data->caps & (_x))
38 #define SPM_VDE_PWR_CON 0x0210
39 #define SPM_MFG_PWR_CON 0x0214
40 #define SPM_VEN_PWR_CON 0x0230
41 #define SPM_ISP_PWR_CON 0x0238
42 #define SPM_DIS_PWR_CON 0x023c
43 #define SPM_CONN_PWR_CON 0x0280
44 #define SPM_VEN2_PWR_CON 0x0298
45 #define SPM_AUDIO_PWR_CON 0x029c /* MT8173, MT2712 */
46 #define SPM_BDP_PWR_CON 0x029c /* MT2701 */
47 #define SPM_ETH_PWR_CON 0x02a0
48 #define SPM_HIF_PWR_CON 0x02a4
49 #define SPM_IFR_MSC_PWR_CON 0x02a8
50 #define SPM_MFG_2D_PWR_CON 0x02c0
51 #define SPM_MFG_ASYNC_PWR_CON 0x02c4
52 #define SPM_USB_PWR_CON 0x02cc
53 #define SPM_USB2_PWR_CON 0x02d4 /* MT2712 */
54 #define SPM_ETHSYS_PWR_CON 0x02e0 /* MT7622 */
55 #define SPM_HIF0_PWR_CON 0x02e4 /* MT7622 */
56 #define SPM_HIF1_PWR_CON 0x02e8 /* MT7622 */
57 #define SPM_WB_PWR_CON 0x02ec /* MT7622 */
59 #define SPM_PWR_STATUS 0x060c
60 #define SPM_PWR_STATUS_2ND 0x0610
62 #define PWR_RST_B_BIT BIT(0)
63 #define PWR_ISO_BIT BIT(1)
64 #define PWR_ON_BIT BIT(2)
65 #define PWR_ON_2ND_BIT BIT(3)
66 #define PWR_CLK_DIS_BIT BIT(4)
68 #define PWR_STATUS_CONN BIT(1)
69 #define PWR_STATUS_DISP BIT(3)
70 #define PWR_STATUS_MFG BIT(4)
71 #define PWR_STATUS_ISP BIT(5)
72 #define PWR_STATUS_VDEC BIT(7)
73 #define PWR_STATUS_BDP BIT(14)
74 #define PWR_STATUS_ETH BIT(15)
75 #define PWR_STATUS_HIF BIT(16)
76 #define PWR_STATUS_IFR_MSC BIT(17)
77 #define PWR_STATUS_USB2 BIT(19) /* MT2712 */
78 #define PWR_STATUS_VENC_LT BIT(20)
79 #define PWR_STATUS_VENC BIT(21)
80 #define PWR_STATUS_MFG_2D BIT(22) /* MT8173 */
81 #define PWR_STATUS_MFG_ASYNC BIT(23) /* MT8173 */
82 #define PWR_STATUS_AUDIO BIT(24) /* MT8173, MT2712 */
83 #define PWR_STATUS_USB BIT(25) /* MT8173, MT2712 */
84 #define PWR_STATUS_ETHSYS BIT(24) /* MT7622 */
85 #define PWR_STATUS_HIF0 BIT(25) /* MT7622 */
86 #define PWR_STATUS_HIF1 BIT(26) /* MT7622 */
87 #define PWR_STATUS_WB BIT(27) /* MT7622 */
103 static const char * const clk_names
[] = {
119 struct scp_domain_data
{
124 u32 sram_pdn_ack_bits
;
126 enum clk_id clk_id
[MAX_CLKS
];
133 struct generic_pm_domain genpd
;
135 struct clk
*clk
[MAX_CLKS
];
136 const struct scp_domain_data
*data
;
137 struct regulator
*supply
;
140 struct scp_ctrl_reg
{
146 struct scp_domain
*domains
;
147 struct genpd_onecell_data pd_data
;
150 struct regmap
*infracfg
;
151 struct scp_ctrl_reg ctrl_reg
;
152 bool bus_prot_reg_update
;
155 struct scp_subdomain
{
160 struct scp_soc_data
{
161 const struct scp_domain_data
*domains
;
163 const struct scp_subdomain
*subdomains
;
165 const struct scp_ctrl_reg regs
;
166 bool bus_prot_reg_update
;
169 static int scpsys_domain_is_on(struct scp_domain
*scpd
)
171 struct scp
*scp
= scpd
->scp
;
173 u32 status
= readl(scp
->base
+ scp
->ctrl_reg
.pwr_sta_offs
) &
174 scpd
->data
->sta_mask
;
175 u32 status2
= readl(scp
->base
+ scp
->ctrl_reg
.pwr_sta2nd_offs
) &
176 scpd
->data
->sta_mask
;
179 * A domain is on when both status bits are set. If only one is set
180 * return an error. This happens while powering up a domain
183 if (status
&& status2
)
185 if (!status
&& !status2
)
191 static int scpsys_power_on(struct generic_pm_domain
*genpd
)
193 struct scp_domain
*scpd
= container_of(genpd
, struct scp_domain
, genpd
);
194 struct scp
*scp
= scpd
->scp
;
195 void __iomem
*ctl_addr
= scp
->base
+ scpd
->data
->ctl_offs
;
196 u32 pdn_ack
= scpd
->data
->sram_pdn_ack_bits
;
202 ret
= regulator_enable(scpd
->supply
);
207 for (i
= 0; i
< MAX_CLKS
&& scpd
->clk
[i
]; i
++) {
208 ret
= clk_prepare_enable(scpd
->clk
[i
]);
210 for (--i
; i
>= 0; i
--)
211 clk_disable_unprepare(scpd
->clk
[i
]);
217 val
= readl(ctl_addr
);
219 writel(val
, ctl_addr
);
220 val
|= PWR_ON_2ND_BIT
;
221 writel(val
, ctl_addr
);
223 /* wait until PWR_ACK = 1 */
224 ret
= readx_poll_timeout(scpsys_domain_is_on
, scpd
, tmp
, tmp
> 0,
225 MTK_POLL_DELAY_US
, MTK_POLL_TIMEOUT
);
229 val
&= ~PWR_CLK_DIS_BIT
;
230 writel(val
, ctl_addr
);
233 writel(val
, ctl_addr
);
235 val
|= PWR_RST_B_BIT
;
236 writel(val
, ctl_addr
);
238 val
&= ~scpd
->data
->sram_pdn_bits
;
239 writel(val
, ctl_addr
);
241 /* Either wait until SRAM_PDN_ACK all 0 or have a force wait */
242 if (MTK_SCPD_CAPS(scpd
, MTK_SCPD_FWAIT_SRAM
)) {
244 * Currently, MTK_SCPD_FWAIT_SRAM is necessary only for
245 * MT7622_POWER_DOMAIN_WB and thus just a trivial setup is
248 usleep_range(12000, 12100);
251 ret
= readl_poll_timeout(ctl_addr
, tmp
, (tmp
& pdn_ack
) == 0,
252 MTK_POLL_DELAY_US
, MTK_POLL_TIMEOUT
);
257 if (scpd
->data
->bus_prot_mask
) {
258 ret
= mtk_infracfg_clear_bus_protection(scp
->infracfg
,
259 scpd
->data
->bus_prot_mask
,
260 scp
->bus_prot_reg_update
);
268 for (i
= MAX_CLKS
- 1; i
>= 0; i
--) {
270 clk_disable_unprepare(scpd
->clk
[i
]);
274 regulator_disable(scpd
->supply
);
276 dev_err(scp
->dev
, "Failed to power on domain %s\n", genpd
->name
);
281 static int scpsys_power_off(struct generic_pm_domain
*genpd
)
283 struct scp_domain
*scpd
= container_of(genpd
, struct scp_domain
, genpd
);
284 struct scp
*scp
= scpd
->scp
;
285 void __iomem
*ctl_addr
= scp
->base
+ scpd
->data
->ctl_offs
;
286 u32 pdn_ack
= scpd
->data
->sram_pdn_ack_bits
;
291 if (scpd
->data
->bus_prot_mask
) {
292 ret
= mtk_infracfg_set_bus_protection(scp
->infracfg
,
293 scpd
->data
->bus_prot_mask
,
294 scp
->bus_prot_reg_update
);
299 val
= readl(ctl_addr
);
300 val
|= scpd
->data
->sram_pdn_bits
;
301 writel(val
, ctl_addr
);
303 /* wait until SRAM_PDN_ACK all 1 */
304 ret
= readl_poll_timeout(ctl_addr
, tmp
, (tmp
& pdn_ack
) == pdn_ack
,
305 MTK_POLL_DELAY_US
, MTK_POLL_TIMEOUT
);
310 writel(val
, ctl_addr
);
312 val
&= ~PWR_RST_B_BIT
;
313 writel(val
, ctl_addr
);
315 val
|= PWR_CLK_DIS_BIT
;
316 writel(val
, ctl_addr
);
319 writel(val
, ctl_addr
);
321 val
&= ~PWR_ON_2ND_BIT
;
322 writel(val
, ctl_addr
);
324 /* wait until PWR_ACK = 0 */
325 ret
= readx_poll_timeout(scpsys_domain_is_on
, scpd
, tmp
, tmp
== 0,
326 MTK_POLL_DELAY_US
, MTK_POLL_TIMEOUT
);
330 for (i
= 0; i
< MAX_CLKS
&& scpd
->clk
[i
]; i
++)
331 clk_disable_unprepare(scpd
->clk
[i
]);
334 regulator_disable(scpd
->supply
);
339 dev_err(scp
->dev
, "Failed to power off domain %s\n", genpd
->name
);
344 static void init_clks(struct platform_device
*pdev
, struct clk
**clk
)
348 for (i
= CLK_NONE
+ 1; i
< CLK_MAX
; i
++)
349 clk
[i
] = devm_clk_get(&pdev
->dev
, clk_names
[i
]);
352 static struct scp
*init_scp(struct platform_device
*pdev
,
353 const struct scp_domain_data
*scp_domain_data
, int num
,
354 const struct scp_ctrl_reg
*scp_ctrl_reg
,
355 bool bus_prot_reg_update
)
357 struct genpd_onecell_data
*pd_data
;
358 struct resource
*res
;
361 struct clk
*clk
[CLK_MAX
];
363 scp
= devm_kzalloc(&pdev
->dev
, sizeof(*scp
), GFP_KERNEL
);
365 return ERR_PTR(-ENOMEM
);
367 scp
->ctrl_reg
.pwr_sta_offs
= scp_ctrl_reg
->pwr_sta_offs
;
368 scp
->ctrl_reg
.pwr_sta2nd_offs
= scp_ctrl_reg
->pwr_sta2nd_offs
;
370 scp
->bus_prot_reg_update
= bus_prot_reg_update
;
372 scp
->dev
= &pdev
->dev
;
374 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
375 scp
->base
= devm_ioremap_resource(&pdev
->dev
, res
);
376 if (IS_ERR(scp
->base
))
377 return ERR_CAST(scp
->base
);
379 scp
->domains
= devm_kcalloc(&pdev
->dev
,
380 num
, sizeof(*scp
->domains
), GFP_KERNEL
);
382 return ERR_PTR(-ENOMEM
);
384 pd_data
= &scp
->pd_data
;
386 pd_data
->domains
= devm_kcalloc(&pdev
->dev
,
387 num
, sizeof(*pd_data
->domains
), GFP_KERNEL
);
388 if (!pd_data
->domains
)
389 return ERR_PTR(-ENOMEM
);
391 scp
->infracfg
= syscon_regmap_lookup_by_phandle(pdev
->dev
.of_node
,
393 if (IS_ERR(scp
->infracfg
)) {
394 dev_err(&pdev
->dev
, "Cannot find infracfg controller: %ld\n",
395 PTR_ERR(scp
->infracfg
));
396 return ERR_CAST(scp
->infracfg
);
399 for (i
= 0; i
< num
; i
++) {
400 struct scp_domain
*scpd
= &scp
->domains
[i
];
401 const struct scp_domain_data
*data
= &scp_domain_data
[i
];
403 scpd
->supply
= devm_regulator_get_optional(&pdev
->dev
, data
->name
);
404 if (IS_ERR(scpd
->supply
)) {
405 if (PTR_ERR(scpd
->supply
) == -ENODEV
)
408 return ERR_CAST(scpd
->supply
);
412 pd_data
->num_domains
= num
;
414 init_clks(pdev
, clk
);
416 for (i
= 0; i
< num
; i
++) {
417 struct scp_domain
*scpd
= &scp
->domains
[i
];
418 struct generic_pm_domain
*genpd
= &scpd
->genpd
;
419 const struct scp_domain_data
*data
= &scp_domain_data
[i
];
421 pd_data
->domains
[i
] = genpd
;
426 for (j
= 0; j
< MAX_CLKS
&& data
->clk_id
[j
]; j
++) {
427 struct clk
*c
= clk
[data
->clk_id
[j
]];
430 dev_err(&pdev
->dev
, "%s: clk unavailable\n",
438 genpd
->name
= data
->name
;
439 genpd
->power_off
= scpsys_power_off
;
440 genpd
->power_on
= scpsys_power_on
;
441 if (MTK_SCPD_CAPS(scpd
, MTK_SCPD_ACTIVE_WAKEUP
))
442 genpd
->flags
|= GENPD_FLAG_ACTIVE_WAKEUP
;
448 static void mtk_register_power_domains(struct platform_device
*pdev
,
449 struct scp
*scp
, int num
)
451 struct genpd_onecell_data
*pd_data
;
454 for (i
= 0; i
< num
; i
++) {
455 struct scp_domain
*scpd
= &scp
->domains
[i
];
456 struct generic_pm_domain
*genpd
= &scpd
->genpd
;
459 * Initially turn on all domains to make the domains usable
460 * with !CONFIG_PM and to get the hardware in sync with the
461 * software. The unused domains will be switched off during
464 genpd
->power_on(genpd
);
466 pm_genpd_init(genpd
, NULL
, false);
470 * We are not allowed to fail here since there is no way to unregister
471 * a power domain. Once registered above we have to keep the domains
475 pd_data
= &scp
->pd_data
;
477 ret
= of_genpd_add_provider_onecell(pdev
->dev
.of_node
, pd_data
);
479 dev_err(&pdev
->dev
, "Failed to add OF provider: %d\n", ret
);
483 * MT2701 power domain support
486 static const struct scp_domain_data scp_domain_data_mt2701
[] = {
487 [MT2701_POWER_DOMAIN_CONN
] = {
489 .sta_mask
= PWR_STATUS_CONN
,
490 .ctl_offs
= SPM_CONN_PWR_CON
,
491 .bus_prot_mask
= MT2701_TOP_AXI_PROT_EN_CONN_M
|
492 MT2701_TOP_AXI_PROT_EN_CONN_S
,
493 .clk_id
= {CLK_NONE
},
494 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
496 [MT2701_POWER_DOMAIN_DISP
] = {
498 .sta_mask
= PWR_STATUS_DISP
,
499 .ctl_offs
= SPM_DIS_PWR_CON
,
500 .sram_pdn_bits
= GENMASK(11, 8),
502 .bus_prot_mask
= MT2701_TOP_AXI_PROT_EN_MM_M0
,
503 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
505 [MT2701_POWER_DOMAIN_MFG
] = {
507 .sta_mask
= PWR_STATUS_MFG
,
508 .ctl_offs
= SPM_MFG_PWR_CON
,
509 .sram_pdn_bits
= GENMASK(11, 8),
510 .sram_pdn_ack_bits
= GENMASK(12, 12),
512 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
514 [MT2701_POWER_DOMAIN_VDEC
] = {
516 .sta_mask
= PWR_STATUS_VDEC
,
517 .ctl_offs
= SPM_VDE_PWR_CON
,
518 .sram_pdn_bits
= GENMASK(11, 8),
519 .sram_pdn_ack_bits
= GENMASK(12, 12),
521 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
523 [MT2701_POWER_DOMAIN_ISP
] = {
525 .sta_mask
= PWR_STATUS_ISP
,
526 .ctl_offs
= SPM_ISP_PWR_CON
,
527 .sram_pdn_bits
= GENMASK(11, 8),
528 .sram_pdn_ack_bits
= GENMASK(13, 12),
530 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
532 [MT2701_POWER_DOMAIN_BDP
] = {
534 .sta_mask
= PWR_STATUS_BDP
,
535 .ctl_offs
= SPM_BDP_PWR_CON
,
536 .sram_pdn_bits
= GENMASK(11, 8),
537 .clk_id
= {CLK_NONE
},
538 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
540 [MT2701_POWER_DOMAIN_ETH
] = {
542 .sta_mask
= PWR_STATUS_ETH
,
543 .ctl_offs
= SPM_ETH_PWR_CON
,
544 .sram_pdn_bits
= GENMASK(11, 8),
545 .sram_pdn_ack_bits
= GENMASK(15, 12),
546 .clk_id
= {CLK_ETHIF
},
547 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
549 [MT2701_POWER_DOMAIN_HIF
] = {
551 .sta_mask
= PWR_STATUS_HIF
,
552 .ctl_offs
= SPM_HIF_PWR_CON
,
553 .sram_pdn_bits
= GENMASK(11, 8),
554 .sram_pdn_ack_bits
= GENMASK(15, 12),
555 .clk_id
= {CLK_ETHIF
},
556 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
558 [MT2701_POWER_DOMAIN_IFR_MSC
] = {
560 .sta_mask
= PWR_STATUS_IFR_MSC
,
561 .ctl_offs
= SPM_IFR_MSC_PWR_CON
,
562 .clk_id
= {CLK_NONE
},
563 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
568 * MT2712 power domain support
570 static const struct scp_domain_data scp_domain_data_mt2712
[] = {
571 [MT2712_POWER_DOMAIN_MM
] = {
573 .sta_mask
= PWR_STATUS_DISP
,
574 .ctl_offs
= SPM_DIS_PWR_CON
,
575 .sram_pdn_bits
= GENMASK(8, 8),
576 .sram_pdn_ack_bits
= GENMASK(12, 12),
578 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
580 [MT2712_POWER_DOMAIN_VDEC
] = {
582 .sta_mask
= PWR_STATUS_VDEC
,
583 .ctl_offs
= SPM_VDE_PWR_CON
,
584 .sram_pdn_bits
= GENMASK(8, 8),
585 .sram_pdn_ack_bits
= GENMASK(12, 12),
586 .clk_id
= {CLK_MM
, CLK_VDEC
},
587 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
589 [MT2712_POWER_DOMAIN_VENC
] = {
591 .sta_mask
= PWR_STATUS_VENC
,
592 .ctl_offs
= SPM_VEN_PWR_CON
,
593 .sram_pdn_bits
= GENMASK(11, 8),
594 .sram_pdn_ack_bits
= GENMASK(15, 12),
595 .clk_id
= {CLK_MM
, CLK_VENC
, CLK_JPGDEC
},
596 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
598 [MT2712_POWER_DOMAIN_ISP
] = {
600 .sta_mask
= PWR_STATUS_ISP
,
601 .ctl_offs
= SPM_ISP_PWR_CON
,
602 .sram_pdn_bits
= GENMASK(11, 8),
603 .sram_pdn_ack_bits
= GENMASK(13, 12),
605 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
607 [MT2712_POWER_DOMAIN_AUDIO
] = {
609 .sta_mask
= PWR_STATUS_AUDIO
,
610 .ctl_offs
= SPM_AUDIO_PWR_CON
,
611 .sram_pdn_bits
= GENMASK(11, 8),
612 .sram_pdn_ack_bits
= GENMASK(15, 12),
613 .clk_id
= {CLK_AUDIO
},
614 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
616 [MT2712_POWER_DOMAIN_USB
] = {
618 .sta_mask
= PWR_STATUS_USB
,
619 .ctl_offs
= SPM_USB_PWR_CON
,
620 .sram_pdn_bits
= GENMASK(10, 8),
621 .sram_pdn_ack_bits
= GENMASK(14, 12),
622 .clk_id
= {CLK_NONE
},
623 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
625 [MT2712_POWER_DOMAIN_USB2
] = {
627 .sta_mask
= PWR_STATUS_USB2
,
628 .ctl_offs
= SPM_USB2_PWR_CON
,
629 .sram_pdn_bits
= GENMASK(10, 8),
630 .sram_pdn_ack_bits
= GENMASK(14, 12),
631 .clk_id
= {CLK_NONE
},
632 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
634 [MT2712_POWER_DOMAIN_MFG
] = {
636 .sta_mask
= PWR_STATUS_MFG
,
637 .ctl_offs
= SPM_MFG_PWR_CON
,
638 .sram_pdn_bits
= GENMASK(8, 8),
639 .sram_pdn_ack_bits
= GENMASK(16, 16),
641 .bus_prot_mask
= BIT(14) | BIT(21) | BIT(23),
642 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
644 [MT2712_POWER_DOMAIN_MFG_SC1
] = {
648 .sram_pdn_bits
= GENMASK(8, 8),
649 .sram_pdn_ack_bits
= GENMASK(16, 16),
650 .clk_id
= {CLK_NONE
},
651 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
653 [MT2712_POWER_DOMAIN_MFG_SC2
] = {
657 .sram_pdn_bits
= GENMASK(8, 8),
658 .sram_pdn_ack_bits
= GENMASK(16, 16),
659 .clk_id
= {CLK_NONE
},
660 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
662 [MT2712_POWER_DOMAIN_MFG_SC3
] = {
666 .sram_pdn_bits
= GENMASK(8, 8),
667 .sram_pdn_ack_bits
= GENMASK(16, 16),
668 .clk_id
= {CLK_NONE
},
669 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
673 static const struct scp_subdomain scp_subdomain_mt2712
[] = {
674 {MT2712_POWER_DOMAIN_MM
, MT2712_POWER_DOMAIN_VDEC
},
675 {MT2712_POWER_DOMAIN_MM
, MT2712_POWER_DOMAIN_VENC
},
676 {MT2712_POWER_DOMAIN_MM
, MT2712_POWER_DOMAIN_ISP
},
677 {MT2712_POWER_DOMAIN_MFG
, MT2712_POWER_DOMAIN_MFG_SC1
},
678 {MT2712_POWER_DOMAIN_MFG_SC1
, MT2712_POWER_DOMAIN_MFG_SC2
},
679 {MT2712_POWER_DOMAIN_MFG_SC2
, MT2712_POWER_DOMAIN_MFG_SC3
},
683 * MT6797 power domain support
686 static const struct scp_domain_data scp_domain_data_mt6797
[] = {
687 [MT6797_POWER_DOMAIN_VDEC
] = {
691 .sram_pdn_bits
= GENMASK(8, 8),
692 .sram_pdn_ack_bits
= GENMASK(12, 12),
693 .clk_id
= {CLK_VDEC
},
695 [MT6797_POWER_DOMAIN_VENC
] = {
699 .sram_pdn_bits
= GENMASK(11, 8),
700 .sram_pdn_ack_bits
= GENMASK(15, 12),
701 .clk_id
= {CLK_NONE
},
703 [MT6797_POWER_DOMAIN_ISP
] = {
707 .sram_pdn_bits
= GENMASK(9, 8),
708 .sram_pdn_ack_bits
= GENMASK(13, 12),
709 .clk_id
= {CLK_NONE
},
711 [MT6797_POWER_DOMAIN_MM
] = {
715 .sram_pdn_bits
= GENMASK(8, 8),
716 .sram_pdn_ack_bits
= GENMASK(12, 12),
718 .bus_prot_mask
= (BIT(1) | BIT(2)),
720 [MT6797_POWER_DOMAIN_AUDIO
] = {
724 .sram_pdn_bits
= GENMASK(11, 8),
725 .sram_pdn_ack_bits
= GENMASK(15, 12),
726 .clk_id
= {CLK_NONE
},
728 [MT6797_POWER_DOMAIN_MFG_ASYNC
] = {
733 .sram_pdn_ack_bits
= 0,
736 [MT6797_POWER_DOMAIN_MJC
] = {
740 .sram_pdn_bits
= GENMASK(8, 8),
741 .sram_pdn_ack_bits
= GENMASK(12, 12),
742 .clk_id
= {CLK_NONE
},
746 #define SPM_PWR_STATUS_MT6797 0x0180
747 #define SPM_PWR_STATUS_2ND_MT6797 0x0184
749 static const struct scp_subdomain scp_subdomain_mt6797
[] = {
750 {MT6797_POWER_DOMAIN_MM
, MT6797_POWER_DOMAIN_VDEC
},
751 {MT6797_POWER_DOMAIN_MM
, MT6797_POWER_DOMAIN_ISP
},
752 {MT6797_POWER_DOMAIN_MM
, MT6797_POWER_DOMAIN_VENC
},
753 {MT6797_POWER_DOMAIN_MM
, MT6797_POWER_DOMAIN_MJC
},
757 * MT7622 power domain support
760 static const struct scp_domain_data scp_domain_data_mt7622
[] = {
761 [MT7622_POWER_DOMAIN_ETHSYS
] = {
763 .sta_mask
= PWR_STATUS_ETHSYS
,
764 .ctl_offs
= SPM_ETHSYS_PWR_CON
,
765 .sram_pdn_bits
= GENMASK(11, 8),
766 .sram_pdn_ack_bits
= GENMASK(15, 12),
767 .clk_id
= {CLK_NONE
},
768 .bus_prot_mask
= MT7622_TOP_AXI_PROT_EN_ETHSYS
,
769 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
771 [MT7622_POWER_DOMAIN_HIF0
] = {
773 .sta_mask
= PWR_STATUS_HIF0
,
774 .ctl_offs
= SPM_HIF0_PWR_CON
,
775 .sram_pdn_bits
= GENMASK(11, 8),
776 .sram_pdn_ack_bits
= GENMASK(15, 12),
777 .clk_id
= {CLK_HIFSEL
},
778 .bus_prot_mask
= MT7622_TOP_AXI_PROT_EN_HIF0
,
779 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
781 [MT7622_POWER_DOMAIN_HIF1
] = {
783 .sta_mask
= PWR_STATUS_HIF1
,
784 .ctl_offs
= SPM_HIF1_PWR_CON
,
785 .sram_pdn_bits
= GENMASK(11, 8),
786 .sram_pdn_ack_bits
= GENMASK(15, 12),
787 .clk_id
= {CLK_HIFSEL
},
788 .bus_prot_mask
= MT7622_TOP_AXI_PROT_EN_HIF1
,
789 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
791 [MT7622_POWER_DOMAIN_WB
] = {
793 .sta_mask
= PWR_STATUS_WB
,
794 .ctl_offs
= SPM_WB_PWR_CON
,
796 .sram_pdn_ack_bits
= 0,
797 .clk_id
= {CLK_NONE
},
798 .bus_prot_mask
= MT7622_TOP_AXI_PROT_EN_WB
,
799 .caps
= MTK_SCPD_ACTIVE_WAKEUP
| MTK_SCPD_FWAIT_SRAM
,
804 * MT7623A power domain support
807 static const struct scp_domain_data scp_domain_data_mt7623a
[] = {
808 [MT7623A_POWER_DOMAIN_CONN
] = {
810 .sta_mask
= PWR_STATUS_CONN
,
811 .ctl_offs
= SPM_CONN_PWR_CON
,
812 .bus_prot_mask
= MT2701_TOP_AXI_PROT_EN_CONN_M
|
813 MT2701_TOP_AXI_PROT_EN_CONN_S
,
814 .clk_id
= {CLK_NONE
},
815 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
817 [MT7623A_POWER_DOMAIN_ETH
] = {
819 .sta_mask
= PWR_STATUS_ETH
,
820 .ctl_offs
= SPM_ETH_PWR_CON
,
821 .sram_pdn_bits
= GENMASK(11, 8),
822 .sram_pdn_ack_bits
= GENMASK(15, 12),
823 .clk_id
= {CLK_ETHIF
},
824 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
826 [MT7623A_POWER_DOMAIN_HIF
] = {
828 .sta_mask
= PWR_STATUS_HIF
,
829 .ctl_offs
= SPM_HIF_PWR_CON
,
830 .sram_pdn_bits
= GENMASK(11, 8),
831 .sram_pdn_ack_bits
= GENMASK(15, 12),
832 .clk_id
= {CLK_ETHIF
},
833 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
835 [MT7623A_POWER_DOMAIN_IFR_MSC
] = {
837 .sta_mask
= PWR_STATUS_IFR_MSC
,
838 .ctl_offs
= SPM_IFR_MSC_PWR_CON
,
839 .clk_id
= {CLK_NONE
},
840 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
845 * MT8173 power domain support
848 static const struct scp_domain_data scp_domain_data_mt8173
[] = {
849 [MT8173_POWER_DOMAIN_VDEC
] = {
851 .sta_mask
= PWR_STATUS_VDEC
,
852 .ctl_offs
= SPM_VDE_PWR_CON
,
853 .sram_pdn_bits
= GENMASK(11, 8),
854 .sram_pdn_ack_bits
= GENMASK(12, 12),
857 [MT8173_POWER_DOMAIN_VENC
] = {
859 .sta_mask
= PWR_STATUS_VENC
,
860 .ctl_offs
= SPM_VEN_PWR_CON
,
861 .sram_pdn_bits
= GENMASK(11, 8),
862 .sram_pdn_ack_bits
= GENMASK(15, 12),
863 .clk_id
= {CLK_MM
, CLK_VENC
},
865 [MT8173_POWER_DOMAIN_ISP
] = {
867 .sta_mask
= PWR_STATUS_ISP
,
868 .ctl_offs
= SPM_ISP_PWR_CON
,
869 .sram_pdn_bits
= GENMASK(11, 8),
870 .sram_pdn_ack_bits
= GENMASK(13, 12),
873 [MT8173_POWER_DOMAIN_MM
] = {
875 .sta_mask
= PWR_STATUS_DISP
,
876 .ctl_offs
= SPM_DIS_PWR_CON
,
877 .sram_pdn_bits
= GENMASK(11, 8),
878 .sram_pdn_ack_bits
= GENMASK(12, 12),
880 .bus_prot_mask
= MT8173_TOP_AXI_PROT_EN_MM_M0
|
881 MT8173_TOP_AXI_PROT_EN_MM_M1
,
883 [MT8173_POWER_DOMAIN_VENC_LT
] = {
885 .sta_mask
= PWR_STATUS_VENC_LT
,
886 .ctl_offs
= SPM_VEN2_PWR_CON
,
887 .sram_pdn_bits
= GENMASK(11, 8),
888 .sram_pdn_ack_bits
= GENMASK(15, 12),
889 .clk_id
= {CLK_MM
, CLK_VENC_LT
},
891 [MT8173_POWER_DOMAIN_AUDIO
] = {
893 .sta_mask
= PWR_STATUS_AUDIO
,
894 .ctl_offs
= SPM_AUDIO_PWR_CON
,
895 .sram_pdn_bits
= GENMASK(11, 8),
896 .sram_pdn_ack_bits
= GENMASK(15, 12),
897 .clk_id
= {CLK_NONE
},
899 [MT8173_POWER_DOMAIN_USB
] = {
901 .sta_mask
= PWR_STATUS_USB
,
902 .ctl_offs
= SPM_USB_PWR_CON
,
903 .sram_pdn_bits
= GENMASK(11, 8),
904 .sram_pdn_ack_bits
= GENMASK(15, 12),
905 .clk_id
= {CLK_NONE
},
906 .caps
= MTK_SCPD_ACTIVE_WAKEUP
,
908 [MT8173_POWER_DOMAIN_MFG_ASYNC
] = {
910 .sta_mask
= PWR_STATUS_MFG_ASYNC
,
911 .ctl_offs
= SPM_MFG_ASYNC_PWR_CON
,
912 .sram_pdn_bits
= GENMASK(11, 8),
913 .sram_pdn_ack_bits
= 0,
916 [MT8173_POWER_DOMAIN_MFG_2D
] = {
918 .sta_mask
= PWR_STATUS_MFG_2D
,
919 .ctl_offs
= SPM_MFG_2D_PWR_CON
,
920 .sram_pdn_bits
= GENMASK(11, 8),
921 .sram_pdn_ack_bits
= GENMASK(13, 12),
922 .clk_id
= {CLK_NONE
},
924 [MT8173_POWER_DOMAIN_MFG
] = {
926 .sta_mask
= PWR_STATUS_MFG
,
927 .ctl_offs
= SPM_MFG_PWR_CON
,
928 .sram_pdn_bits
= GENMASK(13, 8),
929 .sram_pdn_ack_bits
= GENMASK(21, 16),
930 .clk_id
= {CLK_NONE
},
931 .bus_prot_mask
= MT8173_TOP_AXI_PROT_EN_MFG_S
|
932 MT8173_TOP_AXI_PROT_EN_MFG_M0
|
933 MT8173_TOP_AXI_PROT_EN_MFG_M1
|
934 MT8173_TOP_AXI_PROT_EN_MFG_SNOOP_OUT
,
938 static const struct scp_subdomain scp_subdomain_mt8173
[] = {
939 {MT8173_POWER_DOMAIN_MFG_ASYNC
, MT8173_POWER_DOMAIN_MFG_2D
},
940 {MT8173_POWER_DOMAIN_MFG_2D
, MT8173_POWER_DOMAIN_MFG
},
943 static const struct scp_soc_data mt2701_data
= {
944 .domains
= scp_domain_data_mt2701
,
945 .num_domains
= ARRAY_SIZE(scp_domain_data_mt2701
),
947 .pwr_sta_offs
= SPM_PWR_STATUS
,
948 .pwr_sta2nd_offs
= SPM_PWR_STATUS_2ND
950 .bus_prot_reg_update
= true,
953 static const struct scp_soc_data mt2712_data
= {
954 .domains
= scp_domain_data_mt2712
,
955 .num_domains
= ARRAY_SIZE(scp_domain_data_mt2712
),
956 .subdomains
= scp_subdomain_mt2712
,
957 .num_subdomains
= ARRAY_SIZE(scp_subdomain_mt2712
),
959 .pwr_sta_offs
= SPM_PWR_STATUS
,
960 .pwr_sta2nd_offs
= SPM_PWR_STATUS_2ND
962 .bus_prot_reg_update
= false,
965 static const struct scp_soc_data mt6797_data
= {
966 .domains
= scp_domain_data_mt6797
,
967 .num_domains
= ARRAY_SIZE(scp_domain_data_mt6797
),
968 .subdomains
= scp_subdomain_mt6797
,
969 .num_subdomains
= ARRAY_SIZE(scp_subdomain_mt6797
),
971 .pwr_sta_offs
= SPM_PWR_STATUS_MT6797
,
972 .pwr_sta2nd_offs
= SPM_PWR_STATUS_2ND_MT6797
974 .bus_prot_reg_update
= true,
977 static const struct scp_soc_data mt7622_data
= {
978 .domains
= scp_domain_data_mt7622
,
979 .num_domains
= ARRAY_SIZE(scp_domain_data_mt7622
),
981 .pwr_sta_offs
= SPM_PWR_STATUS
,
982 .pwr_sta2nd_offs
= SPM_PWR_STATUS_2ND
984 .bus_prot_reg_update
= true,
987 static const struct scp_soc_data mt7623a_data
= {
988 .domains
= scp_domain_data_mt7623a
,
989 .num_domains
= ARRAY_SIZE(scp_domain_data_mt7623a
),
991 .pwr_sta_offs
= SPM_PWR_STATUS
,
992 .pwr_sta2nd_offs
= SPM_PWR_STATUS_2ND
994 .bus_prot_reg_update
= true,
997 static const struct scp_soc_data mt8173_data
= {
998 .domains
= scp_domain_data_mt8173
,
999 .num_domains
= ARRAY_SIZE(scp_domain_data_mt8173
),
1000 .subdomains
= scp_subdomain_mt8173
,
1001 .num_subdomains
= ARRAY_SIZE(scp_subdomain_mt8173
),
1003 .pwr_sta_offs
= SPM_PWR_STATUS
,
1004 .pwr_sta2nd_offs
= SPM_PWR_STATUS_2ND
1006 .bus_prot_reg_update
= true,
1010 * scpsys driver init
1013 static const struct of_device_id of_scpsys_match_tbl
[] = {
1015 .compatible
= "mediatek,mt2701-scpsys",
1016 .data
= &mt2701_data
,
1018 .compatible
= "mediatek,mt2712-scpsys",
1019 .data
= &mt2712_data
,
1021 .compatible
= "mediatek,mt6797-scpsys",
1022 .data
= &mt6797_data
,
1024 .compatible
= "mediatek,mt7622-scpsys",
1025 .data
= &mt7622_data
,
1027 .compatible
= "mediatek,mt7623a-scpsys",
1028 .data
= &mt7623a_data
,
1030 .compatible
= "mediatek,mt8173-scpsys",
1031 .data
= &mt8173_data
,
1037 static int scpsys_probe(struct platform_device
*pdev
)
1039 const struct scp_subdomain
*sd
;
1040 const struct scp_soc_data
*soc
;
1042 struct genpd_onecell_data
*pd_data
;
1045 soc
= of_device_get_match_data(&pdev
->dev
);
1047 scp
= init_scp(pdev
, soc
->domains
, soc
->num_domains
, &soc
->regs
,
1048 soc
->bus_prot_reg_update
);
1050 return PTR_ERR(scp
);
1052 mtk_register_power_domains(pdev
, scp
, soc
->num_domains
);
1054 pd_data
= &scp
->pd_data
;
1056 for (i
= 0, sd
= soc
->subdomains
; i
< soc
->num_subdomains
; i
++, sd
++) {
1057 ret
= pm_genpd_add_subdomain(pd_data
->domains
[sd
->origin
],
1058 pd_data
->domains
[sd
->subdomain
]);
1059 if (ret
&& IS_ENABLED(CONFIG_PM
))
1060 dev_err(&pdev
->dev
, "Failed to add subdomain: %d\n",
1067 static struct platform_driver scpsys_drv
= {
1068 .probe
= scpsys_probe
,
1070 .name
= "mtk-scpsys",
1071 .suppress_bind_attrs
= true,
1072 .owner
= THIS_MODULE
,
1073 .of_match_table
= of_match_ptr(of_scpsys_match_tbl
),
1076 builtin_platform_driver(scpsys_drv
);