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/mfd/syscon.h>
17 #include <linux/of_device.h>
18 #include <linux/platform_device.h>
19 #include <linux/pm_domain.h>
20 #include <linux/regulator/consumer.h>
21 #include <linux/soc/mediatek/infracfg.h>
23 #include <dt-bindings/power/mt2701-power.h>
24 #include <dt-bindings/power/mt2712-power.h>
25 #include <dt-bindings/power/mt6797-power.h>
26 #include <dt-bindings/power/mt7622-power.h>
27 #include <dt-bindings/power/mt8173-power.h>
29 #define SPM_VDE_PWR_CON 0x0210
30 #define SPM_MFG_PWR_CON 0x0214
31 #define SPM_VEN_PWR_CON 0x0230
32 #define SPM_ISP_PWR_CON 0x0238
33 #define SPM_DIS_PWR_CON 0x023c
34 #define SPM_CONN_PWR_CON 0x0280
35 #define SPM_VEN2_PWR_CON 0x0298
36 #define SPM_AUDIO_PWR_CON 0x029c /* MT8173, MT2712 */
37 #define SPM_BDP_PWR_CON 0x029c /* MT2701 */
38 #define SPM_ETH_PWR_CON 0x02a0
39 #define SPM_HIF_PWR_CON 0x02a4
40 #define SPM_IFR_MSC_PWR_CON 0x02a8
41 #define SPM_MFG_2D_PWR_CON 0x02c0
42 #define SPM_MFG_ASYNC_PWR_CON 0x02c4
43 #define SPM_USB_PWR_CON 0x02cc
44 #define SPM_USB2_PWR_CON 0x02d4 /* MT2712 */
45 #define SPM_ETHSYS_PWR_CON 0x02e0 /* MT7622 */
46 #define SPM_HIF0_PWR_CON 0x02e4 /* MT7622 */
47 #define SPM_HIF1_PWR_CON 0x02e8 /* MT7622 */
48 #define SPM_WB_PWR_CON 0x02ec /* MT7622 */
50 #define SPM_PWR_STATUS 0x060c
51 #define SPM_PWR_STATUS_2ND 0x0610
53 #define PWR_RST_B_BIT BIT(0)
54 #define PWR_ISO_BIT BIT(1)
55 #define PWR_ON_BIT BIT(2)
56 #define PWR_ON_2ND_BIT BIT(3)
57 #define PWR_CLK_DIS_BIT BIT(4)
59 #define PWR_STATUS_CONN BIT(1)
60 #define PWR_STATUS_DISP BIT(3)
61 #define PWR_STATUS_MFG BIT(4)
62 #define PWR_STATUS_ISP BIT(5)
63 #define PWR_STATUS_VDEC BIT(7)
64 #define PWR_STATUS_BDP BIT(14)
65 #define PWR_STATUS_ETH BIT(15)
66 #define PWR_STATUS_HIF BIT(16)
67 #define PWR_STATUS_IFR_MSC BIT(17)
68 #define PWR_STATUS_USB2 BIT(19) /* MT2712 */
69 #define PWR_STATUS_VENC_LT BIT(20)
70 #define PWR_STATUS_VENC BIT(21)
71 #define PWR_STATUS_MFG_2D BIT(22) /* MT8173 */
72 #define PWR_STATUS_MFG_ASYNC BIT(23) /* MT8173 */
73 #define PWR_STATUS_AUDIO BIT(24) /* MT8173, MT2712 */
74 #define PWR_STATUS_USB BIT(25) /* MT8173, MT2712 */
75 #define PWR_STATUS_ETHSYS BIT(24) /* MT7622 */
76 #define PWR_STATUS_HIF0 BIT(25) /* MT7622 */
77 #define PWR_STATUS_HIF1 BIT(26) /* MT7622 */
78 #define PWR_STATUS_WB BIT(27) /* MT7622 */
94 static const char * const clk_names
[] = {
110 struct scp_domain_data
{
115 u32 sram_pdn_ack_bits
;
117 enum clk_id clk_id
[MAX_CLKS
];
124 struct generic_pm_domain genpd
;
126 struct clk
*clk
[MAX_CLKS
];
127 const struct scp_domain_data
*data
;
128 struct regulator
*supply
;
131 struct scp_ctrl_reg
{
137 struct scp_domain
*domains
;
138 struct genpd_onecell_data pd_data
;
141 struct regmap
*infracfg
;
142 struct scp_ctrl_reg ctrl_reg
;
143 bool bus_prot_reg_update
;
146 struct scp_subdomain
{
151 struct scp_soc_data
{
152 const struct scp_domain_data
*domains
;
154 const struct scp_subdomain
*subdomains
;
156 const struct scp_ctrl_reg regs
;
157 bool bus_prot_reg_update
;
160 static int scpsys_domain_is_on(struct scp_domain
*scpd
)
162 struct scp
*scp
= scpd
->scp
;
164 u32 status
= readl(scp
->base
+ scp
->ctrl_reg
.pwr_sta_offs
) &
165 scpd
->data
->sta_mask
;
166 u32 status2
= readl(scp
->base
+ scp
->ctrl_reg
.pwr_sta2nd_offs
) &
167 scpd
->data
->sta_mask
;
170 * A domain is on when both status bits are set. If only one is set
171 * return an error. This happens while powering up a domain
174 if (status
&& status2
)
176 if (!status
&& !status2
)
182 static int scpsys_power_on(struct generic_pm_domain
*genpd
)
184 struct scp_domain
*scpd
= container_of(genpd
, struct scp_domain
, genpd
);
185 struct scp
*scp
= scpd
->scp
;
186 unsigned long timeout
;
188 void __iomem
*ctl_addr
= scp
->base
+ scpd
->data
->ctl_offs
;
189 u32 sram_pdn_ack
= scpd
->data
->sram_pdn_ack_bits
;
195 ret
= regulator_enable(scpd
->supply
);
200 for (i
= 0; i
< MAX_CLKS
&& scpd
->clk
[i
]; i
++) {
201 ret
= clk_prepare_enable(scpd
->clk
[i
]);
203 for (--i
; i
>= 0; i
--)
204 clk_disable_unprepare(scpd
->clk
[i
]);
210 val
= readl(ctl_addr
);
212 writel(val
, ctl_addr
);
213 val
|= PWR_ON_2ND_BIT
;
214 writel(val
, ctl_addr
);
216 /* wait until PWR_ACK = 1 */
217 timeout
= jiffies
+ HZ
;
220 ret
= scpsys_domain_is_on(scpd
);
231 if (time_after(jiffies
, timeout
))
235 val
&= ~PWR_CLK_DIS_BIT
;
236 writel(val
, ctl_addr
);
239 writel(val
, ctl_addr
);
241 val
|= PWR_RST_B_BIT
;
242 writel(val
, ctl_addr
);
244 val
&= ~scpd
->data
->sram_pdn_bits
;
245 writel(val
, ctl_addr
);
247 /* wait until SRAM_PDN_ACK all 0 */
248 timeout
= jiffies
+ HZ
;
250 while (sram_pdn_ack
&& (readl(ctl_addr
) & sram_pdn_ack
)) {
259 if (time_after(jiffies
, timeout
))
263 if (scpd
->data
->bus_prot_mask
) {
264 ret
= mtk_infracfg_clear_bus_protection(scp
->infracfg
,
265 scpd
->data
->bus_prot_mask
,
266 scp
->bus_prot_reg_update
);
274 for (i
= MAX_CLKS
- 1; i
>= 0; i
--) {
276 clk_disable_unprepare(scpd
->clk
[i
]);
280 regulator_disable(scpd
->supply
);
282 dev_err(scp
->dev
, "Failed to power on domain %s\n", genpd
->name
);
287 static int scpsys_power_off(struct generic_pm_domain
*genpd
)
289 struct scp_domain
*scpd
= container_of(genpd
, struct scp_domain
, genpd
);
290 struct scp
*scp
= scpd
->scp
;
291 unsigned long timeout
;
293 void __iomem
*ctl_addr
= scp
->base
+ scpd
->data
->ctl_offs
;
294 u32 pdn_ack
= scpd
->data
->sram_pdn_ack_bits
;
299 if (scpd
->data
->bus_prot_mask
) {
300 ret
= mtk_infracfg_set_bus_protection(scp
->infracfg
,
301 scpd
->data
->bus_prot_mask
,
302 scp
->bus_prot_reg_update
);
307 val
= readl(ctl_addr
);
308 val
|= scpd
->data
->sram_pdn_bits
;
309 writel(val
, ctl_addr
);
311 /* wait until SRAM_PDN_ACK all 1 */
312 timeout
= jiffies
+ HZ
;
314 while (pdn_ack
&& (readl(ctl_addr
) & pdn_ack
) != pdn_ack
) {
322 if (time_after(jiffies
, timeout
))
327 writel(val
, ctl_addr
);
329 val
&= ~PWR_RST_B_BIT
;
330 writel(val
, ctl_addr
);
332 val
|= PWR_CLK_DIS_BIT
;
333 writel(val
, ctl_addr
);
336 writel(val
, ctl_addr
);
338 val
&= ~PWR_ON_2ND_BIT
;
339 writel(val
, ctl_addr
);
341 /* wait until PWR_ACK = 0 */
342 timeout
= jiffies
+ HZ
;
345 ret
= scpsys_domain_is_on(scpd
);
356 if (time_after(jiffies
, timeout
))
360 for (i
= 0; i
< MAX_CLKS
&& scpd
->clk
[i
]; i
++)
361 clk_disable_unprepare(scpd
->clk
[i
]);
364 regulator_disable(scpd
->supply
);
369 dev_err(scp
->dev
, "Failed to power off domain %s\n", genpd
->name
);
374 static void init_clks(struct platform_device
*pdev
, struct clk
**clk
)
378 for (i
= CLK_NONE
+ 1; i
< CLK_MAX
; i
++)
379 clk
[i
] = devm_clk_get(&pdev
->dev
, clk_names
[i
]);
382 static struct scp
*init_scp(struct platform_device
*pdev
,
383 const struct scp_domain_data
*scp_domain_data
, int num
,
384 const struct scp_ctrl_reg
*scp_ctrl_reg
,
385 bool bus_prot_reg_update
)
387 struct genpd_onecell_data
*pd_data
;
388 struct resource
*res
;
391 struct clk
*clk
[CLK_MAX
];
393 scp
= devm_kzalloc(&pdev
->dev
, sizeof(*scp
), GFP_KERNEL
);
395 return ERR_PTR(-ENOMEM
);
397 scp
->ctrl_reg
.pwr_sta_offs
= scp_ctrl_reg
->pwr_sta_offs
;
398 scp
->ctrl_reg
.pwr_sta2nd_offs
= scp_ctrl_reg
->pwr_sta2nd_offs
;
400 scp
->bus_prot_reg_update
= bus_prot_reg_update
;
402 scp
->dev
= &pdev
->dev
;
404 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
405 scp
->base
= devm_ioremap_resource(&pdev
->dev
, res
);
406 if (IS_ERR(scp
->base
))
407 return ERR_CAST(scp
->base
);
409 scp
->domains
= devm_kzalloc(&pdev
->dev
,
410 sizeof(*scp
->domains
) * num
, GFP_KERNEL
);
412 return ERR_PTR(-ENOMEM
);
414 pd_data
= &scp
->pd_data
;
416 pd_data
->domains
= devm_kzalloc(&pdev
->dev
,
417 sizeof(*pd_data
->domains
) * num
, GFP_KERNEL
);
418 if (!pd_data
->domains
)
419 return ERR_PTR(-ENOMEM
);
421 scp
->infracfg
= syscon_regmap_lookup_by_phandle(pdev
->dev
.of_node
,
423 if (IS_ERR(scp
->infracfg
)) {
424 dev_err(&pdev
->dev
, "Cannot find infracfg controller: %ld\n",
425 PTR_ERR(scp
->infracfg
));
426 return ERR_CAST(scp
->infracfg
);
429 for (i
= 0; i
< num
; i
++) {
430 struct scp_domain
*scpd
= &scp
->domains
[i
];
431 const struct scp_domain_data
*data
= &scp_domain_data
[i
];
433 scpd
->supply
= devm_regulator_get_optional(&pdev
->dev
, data
->name
);
434 if (IS_ERR(scpd
->supply
)) {
435 if (PTR_ERR(scpd
->supply
) == -ENODEV
)
438 return ERR_CAST(scpd
->supply
);
442 pd_data
->num_domains
= num
;
444 init_clks(pdev
, clk
);
446 for (i
= 0; i
< num
; i
++) {
447 struct scp_domain
*scpd
= &scp
->domains
[i
];
448 struct generic_pm_domain
*genpd
= &scpd
->genpd
;
449 const struct scp_domain_data
*data
= &scp_domain_data
[i
];
451 pd_data
->domains
[i
] = genpd
;
456 for (j
= 0; j
< MAX_CLKS
&& data
->clk_id
[j
]; j
++) {
457 struct clk
*c
= clk
[data
->clk_id
[j
]];
460 dev_err(&pdev
->dev
, "%s: clk unavailable\n",
468 genpd
->name
= data
->name
;
469 genpd
->power_off
= scpsys_power_off
;
470 genpd
->power_on
= scpsys_power_on
;
471 if (scpd
->data
->active_wakeup
)
472 genpd
->flags
|= GENPD_FLAG_ACTIVE_WAKEUP
;
478 static void mtk_register_power_domains(struct platform_device
*pdev
,
479 struct scp
*scp
, int num
)
481 struct genpd_onecell_data
*pd_data
;
484 for (i
= 0; i
< num
; i
++) {
485 struct scp_domain
*scpd
= &scp
->domains
[i
];
486 struct generic_pm_domain
*genpd
= &scpd
->genpd
;
489 * Initially turn on all domains to make the domains usable
490 * with !CONFIG_PM and to get the hardware in sync with the
491 * software. The unused domains will be switched off during
494 genpd
->power_on(genpd
);
496 pm_genpd_init(genpd
, NULL
, false);
500 * We are not allowed to fail here since there is no way to unregister
501 * a power domain. Once registered above we have to keep the domains
505 pd_data
= &scp
->pd_data
;
507 ret
= of_genpd_add_provider_onecell(pdev
->dev
.of_node
, pd_data
);
509 dev_err(&pdev
->dev
, "Failed to add OF provider: %d\n", ret
);
513 * MT2701 power domain support
516 static const struct scp_domain_data scp_domain_data_mt2701
[] = {
517 [MT2701_POWER_DOMAIN_CONN
] = {
519 .sta_mask
= PWR_STATUS_CONN
,
520 .ctl_offs
= SPM_CONN_PWR_CON
,
521 .bus_prot_mask
= 0x0104,
522 .clk_id
= {CLK_NONE
},
523 .active_wakeup
= true,
525 [MT2701_POWER_DOMAIN_DISP
] = {
527 .sta_mask
= PWR_STATUS_DISP
,
528 .ctl_offs
= SPM_DIS_PWR_CON
,
529 .sram_pdn_bits
= GENMASK(11, 8),
531 .bus_prot_mask
= 0x0002,
532 .active_wakeup
= true,
534 [MT2701_POWER_DOMAIN_MFG
] = {
536 .sta_mask
= PWR_STATUS_MFG
,
537 .ctl_offs
= SPM_MFG_PWR_CON
,
538 .sram_pdn_bits
= GENMASK(11, 8),
539 .sram_pdn_ack_bits
= GENMASK(12, 12),
541 .active_wakeup
= true,
543 [MT2701_POWER_DOMAIN_VDEC
] = {
545 .sta_mask
= PWR_STATUS_VDEC
,
546 .ctl_offs
= SPM_VDE_PWR_CON
,
547 .sram_pdn_bits
= GENMASK(11, 8),
548 .sram_pdn_ack_bits
= GENMASK(12, 12),
550 .active_wakeup
= true,
552 [MT2701_POWER_DOMAIN_ISP
] = {
554 .sta_mask
= PWR_STATUS_ISP
,
555 .ctl_offs
= SPM_ISP_PWR_CON
,
556 .sram_pdn_bits
= GENMASK(11, 8),
557 .sram_pdn_ack_bits
= GENMASK(13, 12),
559 .active_wakeup
= true,
561 [MT2701_POWER_DOMAIN_BDP
] = {
563 .sta_mask
= PWR_STATUS_BDP
,
564 .ctl_offs
= SPM_BDP_PWR_CON
,
565 .sram_pdn_bits
= GENMASK(11, 8),
566 .clk_id
= {CLK_NONE
},
567 .active_wakeup
= true,
569 [MT2701_POWER_DOMAIN_ETH
] = {
571 .sta_mask
= PWR_STATUS_ETH
,
572 .ctl_offs
= SPM_ETH_PWR_CON
,
573 .sram_pdn_bits
= GENMASK(11, 8),
574 .sram_pdn_ack_bits
= GENMASK(15, 12),
575 .clk_id
= {CLK_ETHIF
},
576 .active_wakeup
= true,
578 [MT2701_POWER_DOMAIN_HIF
] = {
580 .sta_mask
= PWR_STATUS_HIF
,
581 .ctl_offs
= SPM_HIF_PWR_CON
,
582 .sram_pdn_bits
= GENMASK(11, 8),
583 .sram_pdn_ack_bits
= GENMASK(15, 12),
584 .clk_id
= {CLK_ETHIF
},
585 .active_wakeup
= true,
587 [MT2701_POWER_DOMAIN_IFR_MSC
] = {
589 .sta_mask
= PWR_STATUS_IFR_MSC
,
590 .ctl_offs
= SPM_IFR_MSC_PWR_CON
,
591 .clk_id
= {CLK_NONE
},
592 .active_wakeup
= true,
597 * MT2712 power domain support
599 static const struct scp_domain_data scp_domain_data_mt2712
[] = {
600 [MT2712_POWER_DOMAIN_MM
] = {
602 .sta_mask
= PWR_STATUS_DISP
,
603 .ctl_offs
= SPM_DIS_PWR_CON
,
604 .sram_pdn_bits
= GENMASK(8, 8),
605 .sram_pdn_ack_bits
= GENMASK(12, 12),
607 .active_wakeup
= true,
609 [MT2712_POWER_DOMAIN_VDEC
] = {
611 .sta_mask
= PWR_STATUS_VDEC
,
612 .ctl_offs
= SPM_VDE_PWR_CON
,
613 .sram_pdn_bits
= GENMASK(8, 8),
614 .sram_pdn_ack_bits
= GENMASK(12, 12),
615 .clk_id
= {CLK_MM
, CLK_VDEC
},
616 .active_wakeup
= true,
618 [MT2712_POWER_DOMAIN_VENC
] = {
620 .sta_mask
= PWR_STATUS_VENC
,
621 .ctl_offs
= SPM_VEN_PWR_CON
,
622 .sram_pdn_bits
= GENMASK(11, 8),
623 .sram_pdn_ack_bits
= GENMASK(15, 12),
624 .clk_id
= {CLK_MM
, CLK_VENC
, CLK_JPGDEC
},
625 .active_wakeup
= true,
627 [MT2712_POWER_DOMAIN_ISP
] = {
629 .sta_mask
= PWR_STATUS_ISP
,
630 .ctl_offs
= SPM_ISP_PWR_CON
,
631 .sram_pdn_bits
= GENMASK(11, 8),
632 .sram_pdn_ack_bits
= GENMASK(13, 12),
634 .active_wakeup
= true,
636 [MT2712_POWER_DOMAIN_AUDIO
] = {
638 .sta_mask
= PWR_STATUS_AUDIO
,
639 .ctl_offs
= SPM_AUDIO_PWR_CON
,
640 .sram_pdn_bits
= GENMASK(11, 8),
641 .sram_pdn_ack_bits
= GENMASK(15, 12),
642 .clk_id
= {CLK_AUDIO
},
643 .active_wakeup
= true,
645 [MT2712_POWER_DOMAIN_USB
] = {
647 .sta_mask
= PWR_STATUS_USB
,
648 .ctl_offs
= SPM_USB_PWR_CON
,
649 .sram_pdn_bits
= GENMASK(10, 8),
650 .sram_pdn_ack_bits
= GENMASK(14, 12),
651 .clk_id
= {CLK_NONE
},
652 .active_wakeup
= true,
654 [MT2712_POWER_DOMAIN_USB2
] = {
656 .sta_mask
= PWR_STATUS_USB2
,
657 .ctl_offs
= SPM_USB2_PWR_CON
,
658 .sram_pdn_bits
= GENMASK(10, 8),
659 .sram_pdn_ack_bits
= GENMASK(14, 12),
660 .clk_id
= {CLK_NONE
},
661 .active_wakeup
= true,
663 [MT2712_POWER_DOMAIN_MFG
] = {
665 .sta_mask
= PWR_STATUS_MFG
,
666 .ctl_offs
= SPM_MFG_PWR_CON
,
667 .sram_pdn_bits
= GENMASK(11, 8),
668 .sram_pdn_ack_bits
= GENMASK(19, 16),
670 .bus_prot_mask
= BIT(14) | BIT(21) | BIT(23),
671 .active_wakeup
= true,
676 * MT6797 power domain support
679 static const struct scp_domain_data scp_domain_data_mt6797
[] = {
680 [MT6797_POWER_DOMAIN_VDEC
] = {
684 .sram_pdn_bits
= GENMASK(8, 8),
685 .sram_pdn_ack_bits
= GENMASK(12, 12),
686 .clk_id
= {CLK_VDEC
},
688 [MT6797_POWER_DOMAIN_VENC
] = {
692 .sram_pdn_bits
= GENMASK(11, 8),
693 .sram_pdn_ack_bits
= GENMASK(15, 12),
694 .clk_id
= {CLK_NONE
},
696 [MT6797_POWER_DOMAIN_ISP
] = {
700 .sram_pdn_bits
= GENMASK(9, 8),
701 .sram_pdn_ack_bits
= GENMASK(13, 12),
702 .clk_id
= {CLK_NONE
},
704 [MT6797_POWER_DOMAIN_MM
] = {
708 .sram_pdn_bits
= GENMASK(8, 8),
709 .sram_pdn_ack_bits
= GENMASK(12, 12),
711 .bus_prot_mask
= (BIT(1) | BIT(2)),
713 [MT6797_POWER_DOMAIN_AUDIO
] = {
717 .sram_pdn_bits
= GENMASK(11, 8),
718 .sram_pdn_ack_bits
= GENMASK(15, 12),
719 .clk_id
= {CLK_NONE
},
721 [MT6797_POWER_DOMAIN_MFG_ASYNC
] = {
726 .sram_pdn_ack_bits
= 0,
729 [MT6797_POWER_DOMAIN_MJC
] = {
733 .sram_pdn_bits
= GENMASK(8, 8),
734 .sram_pdn_ack_bits
= GENMASK(12, 12),
735 .clk_id
= {CLK_NONE
},
739 #define SPM_PWR_STATUS_MT6797 0x0180
740 #define SPM_PWR_STATUS_2ND_MT6797 0x0184
742 static const struct scp_subdomain scp_subdomain_mt6797
[] = {
743 {MT6797_POWER_DOMAIN_MM
, MT6797_POWER_DOMAIN_VDEC
},
744 {MT6797_POWER_DOMAIN_MM
, MT6797_POWER_DOMAIN_ISP
},
745 {MT6797_POWER_DOMAIN_MM
, MT6797_POWER_DOMAIN_VENC
},
746 {MT6797_POWER_DOMAIN_MM
, MT6797_POWER_DOMAIN_MJC
},
750 * MT7622 power domain support
753 static const struct scp_domain_data scp_domain_data_mt7622
[] = {
754 [MT7622_POWER_DOMAIN_ETHSYS
] = {
756 .sta_mask
= PWR_STATUS_ETHSYS
,
757 .ctl_offs
= SPM_ETHSYS_PWR_CON
,
758 .sram_pdn_bits
= GENMASK(11, 8),
759 .sram_pdn_ack_bits
= GENMASK(15, 12),
760 .clk_id
= {CLK_NONE
},
761 .bus_prot_mask
= MT7622_TOP_AXI_PROT_EN_ETHSYS
,
762 .active_wakeup
= true,
764 [MT7622_POWER_DOMAIN_HIF0
] = {
766 .sta_mask
= PWR_STATUS_HIF0
,
767 .ctl_offs
= SPM_HIF0_PWR_CON
,
768 .sram_pdn_bits
= GENMASK(11, 8),
769 .sram_pdn_ack_bits
= GENMASK(15, 12),
770 .clk_id
= {CLK_HIFSEL
},
771 .bus_prot_mask
= MT7622_TOP_AXI_PROT_EN_HIF0
,
772 .active_wakeup
= true,
774 [MT7622_POWER_DOMAIN_HIF1
] = {
776 .sta_mask
= PWR_STATUS_HIF1
,
777 .ctl_offs
= SPM_HIF1_PWR_CON
,
778 .sram_pdn_bits
= GENMASK(11, 8),
779 .sram_pdn_ack_bits
= GENMASK(15, 12),
780 .clk_id
= {CLK_HIFSEL
},
781 .bus_prot_mask
= MT7622_TOP_AXI_PROT_EN_HIF1
,
782 .active_wakeup
= true,
784 [MT7622_POWER_DOMAIN_WB
] = {
786 .sta_mask
= PWR_STATUS_WB
,
787 .ctl_offs
= SPM_WB_PWR_CON
,
789 .sram_pdn_ack_bits
= 0,
790 .clk_id
= {CLK_NONE
},
791 .bus_prot_mask
= MT7622_TOP_AXI_PROT_EN_WB
,
792 .active_wakeup
= true,
797 * MT8173 power domain support
800 static const struct scp_domain_data scp_domain_data_mt8173
[] = {
801 [MT8173_POWER_DOMAIN_VDEC
] = {
803 .sta_mask
= PWR_STATUS_VDEC
,
804 .ctl_offs
= SPM_VDE_PWR_CON
,
805 .sram_pdn_bits
= GENMASK(11, 8),
806 .sram_pdn_ack_bits
= GENMASK(12, 12),
809 [MT8173_POWER_DOMAIN_VENC
] = {
811 .sta_mask
= PWR_STATUS_VENC
,
812 .ctl_offs
= SPM_VEN_PWR_CON
,
813 .sram_pdn_bits
= GENMASK(11, 8),
814 .sram_pdn_ack_bits
= GENMASK(15, 12),
815 .clk_id
= {CLK_MM
, CLK_VENC
},
817 [MT8173_POWER_DOMAIN_ISP
] = {
819 .sta_mask
= PWR_STATUS_ISP
,
820 .ctl_offs
= SPM_ISP_PWR_CON
,
821 .sram_pdn_bits
= GENMASK(11, 8),
822 .sram_pdn_ack_bits
= GENMASK(13, 12),
825 [MT8173_POWER_DOMAIN_MM
] = {
827 .sta_mask
= PWR_STATUS_DISP
,
828 .ctl_offs
= SPM_DIS_PWR_CON
,
829 .sram_pdn_bits
= GENMASK(11, 8),
830 .sram_pdn_ack_bits
= GENMASK(12, 12),
832 .bus_prot_mask
= MT8173_TOP_AXI_PROT_EN_MM_M0
|
833 MT8173_TOP_AXI_PROT_EN_MM_M1
,
835 [MT8173_POWER_DOMAIN_VENC_LT
] = {
837 .sta_mask
= PWR_STATUS_VENC_LT
,
838 .ctl_offs
= SPM_VEN2_PWR_CON
,
839 .sram_pdn_bits
= GENMASK(11, 8),
840 .sram_pdn_ack_bits
= GENMASK(15, 12),
841 .clk_id
= {CLK_MM
, CLK_VENC_LT
},
843 [MT8173_POWER_DOMAIN_AUDIO
] = {
845 .sta_mask
= PWR_STATUS_AUDIO
,
846 .ctl_offs
= SPM_AUDIO_PWR_CON
,
847 .sram_pdn_bits
= GENMASK(11, 8),
848 .sram_pdn_ack_bits
= GENMASK(15, 12),
849 .clk_id
= {CLK_NONE
},
851 [MT8173_POWER_DOMAIN_USB
] = {
853 .sta_mask
= PWR_STATUS_USB
,
854 .ctl_offs
= SPM_USB_PWR_CON
,
855 .sram_pdn_bits
= GENMASK(11, 8),
856 .sram_pdn_ack_bits
= GENMASK(15, 12),
857 .clk_id
= {CLK_NONE
},
858 .active_wakeup
= true,
860 [MT8173_POWER_DOMAIN_MFG_ASYNC
] = {
862 .sta_mask
= PWR_STATUS_MFG_ASYNC
,
863 .ctl_offs
= SPM_MFG_ASYNC_PWR_CON
,
864 .sram_pdn_bits
= GENMASK(11, 8),
865 .sram_pdn_ack_bits
= 0,
868 [MT8173_POWER_DOMAIN_MFG_2D
] = {
870 .sta_mask
= PWR_STATUS_MFG_2D
,
871 .ctl_offs
= SPM_MFG_2D_PWR_CON
,
872 .sram_pdn_bits
= GENMASK(11, 8),
873 .sram_pdn_ack_bits
= GENMASK(13, 12),
874 .clk_id
= {CLK_NONE
},
876 [MT8173_POWER_DOMAIN_MFG
] = {
878 .sta_mask
= PWR_STATUS_MFG
,
879 .ctl_offs
= SPM_MFG_PWR_CON
,
880 .sram_pdn_bits
= GENMASK(13, 8),
881 .sram_pdn_ack_bits
= GENMASK(21, 16),
882 .clk_id
= {CLK_NONE
},
883 .bus_prot_mask
= MT8173_TOP_AXI_PROT_EN_MFG_S
|
884 MT8173_TOP_AXI_PROT_EN_MFG_M0
|
885 MT8173_TOP_AXI_PROT_EN_MFG_M1
|
886 MT8173_TOP_AXI_PROT_EN_MFG_SNOOP_OUT
,
890 static const struct scp_subdomain scp_subdomain_mt8173
[] = {
891 {MT8173_POWER_DOMAIN_MFG_ASYNC
, MT8173_POWER_DOMAIN_MFG_2D
},
892 {MT8173_POWER_DOMAIN_MFG_2D
, MT8173_POWER_DOMAIN_MFG
},
895 static const struct scp_soc_data mt2701_data
= {
896 .domains
= scp_domain_data_mt2701
,
897 .num_domains
= ARRAY_SIZE(scp_domain_data_mt2701
),
899 .pwr_sta_offs
= SPM_PWR_STATUS
,
900 .pwr_sta2nd_offs
= SPM_PWR_STATUS_2ND
902 .bus_prot_reg_update
= true,
905 static const struct scp_soc_data mt2712_data
= {
906 .domains
= scp_domain_data_mt2712
,
907 .num_domains
= ARRAY_SIZE(scp_domain_data_mt2712
),
909 .pwr_sta_offs
= SPM_PWR_STATUS
,
910 .pwr_sta2nd_offs
= SPM_PWR_STATUS_2ND
912 .bus_prot_reg_update
= false,
915 static const struct scp_soc_data mt6797_data
= {
916 .domains
= scp_domain_data_mt6797
,
917 .num_domains
= ARRAY_SIZE(scp_domain_data_mt6797
),
918 .subdomains
= scp_subdomain_mt6797
,
919 .num_subdomains
= ARRAY_SIZE(scp_subdomain_mt6797
),
921 .pwr_sta_offs
= SPM_PWR_STATUS_MT6797
,
922 .pwr_sta2nd_offs
= SPM_PWR_STATUS_2ND_MT6797
924 .bus_prot_reg_update
= true,
927 static const struct scp_soc_data mt7622_data
= {
928 .domains
= scp_domain_data_mt7622
,
929 .num_domains
= ARRAY_SIZE(scp_domain_data_mt7622
),
931 .pwr_sta_offs
= SPM_PWR_STATUS
,
932 .pwr_sta2nd_offs
= SPM_PWR_STATUS_2ND
934 .bus_prot_reg_update
= true,
937 static const struct scp_soc_data mt8173_data
= {
938 .domains
= scp_domain_data_mt8173
,
939 .num_domains
= ARRAY_SIZE(scp_domain_data_mt8173
),
940 .subdomains
= scp_subdomain_mt8173
,
941 .num_subdomains
= ARRAY_SIZE(scp_subdomain_mt8173
),
943 .pwr_sta_offs
= SPM_PWR_STATUS
,
944 .pwr_sta2nd_offs
= SPM_PWR_STATUS_2ND
946 .bus_prot_reg_update
= true,
953 static const struct of_device_id of_scpsys_match_tbl
[] = {
955 .compatible
= "mediatek,mt2701-scpsys",
956 .data
= &mt2701_data
,
958 .compatible
= "mediatek,mt2712-scpsys",
959 .data
= &mt2712_data
,
961 .compatible
= "mediatek,mt6797-scpsys",
962 .data
= &mt6797_data
,
964 .compatible
= "mediatek,mt7622-scpsys",
965 .data
= &mt7622_data
,
967 .compatible
= "mediatek,mt8173-scpsys",
968 .data
= &mt8173_data
,
974 static int scpsys_probe(struct platform_device
*pdev
)
976 const struct of_device_id
*match
;
977 const struct scp_subdomain
*sd
;
978 const struct scp_soc_data
*soc
;
980 struct genpd_onecell_data
*pd_data
;
983 match
= of_match_device(of_scpsys_match_tbl
, &pdev
->dev
);
984 soc
= (const struct scp_soc_data
*)match
->data
;
986 scp
= init_scp(pdev
, soc
->domains
, soc
->num_domains
, &soc
->regs
,
987 soc
->bus_prot_reg_update
);
991 mtk_register_power_domains(pdev
, scp
, soc
->num_domains
);
993 pd_data
= &scp
->pd_data
;
995 for (i
= 0, sd
= soc
->subdomains
; i
< soc
->num_subdomains
; i
++) {
996 ret
= pm_genpd_add_subdomain(pd_data
->domains
[sd
->origin
],
997 pd_data
->domains
[sd
->subdomain
]);
998 if (ret
&& IS_ENABLED(CONFIG_PM
))
999 dev_err(&pdev
->dev
, "Failed to add subdomain: %d\n",
1006 static struct platform_driver scpsys_drv
= {
1007 .probe
= scpsys_probe
,
1009 .name
= "mtk-scpsys",
1010 .suppress_bind_attrs
= true,
1011 .owner
= THIS_MODULE
,
1012 .of_match_table
= of_match_ptr(of_scpsys_match_tbl
),
1015 builtin_platform_driver(scpsys_drv
);