Lines Matching +full:12 +full:- +full:bit
1 // SPDX-License-Identifier: GPL-2.0-only
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>
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))
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 */
112 * struct scp_domain_data - scp domain data for power on/off flow
114 * @sta_mask: The mask for power on/off status bit.
120 * @caps: The flag for active wake-up action.
174 struct scp *scp = scpd->scp; in scpsys_domain_is_on()
176 u32 status = readl(scp->base + scp->ctrl_reg.pwr_sta_offs) & in scpsys_domain_is_on()
177 scpd->data->sta_mask; in scpsys_domain_is_on()
178 u32 status2 = readl(scp->base + scp->ctrl_reg.pwr_sta2nd_offs) & in scpsys_domain_is_on()
179 scpd->data->sta_mask; in scpsys_domain_is_on()
191 return -EINVAL; in scpsys_domain_is_on()
196 if (!scpd->supply) in scpsys_regulator_enable()
199 return regulator_enable(scpd->supply); in scpsys_regulator_enable()
204 if (!scpd->supply) in scpsys_regulator_disable()
207 return regulator_disable(scpd->supply); in scpsys_regulator_disable()
214 for (i = max_num - 1; i >= 0; i--) in scpsys_clk_disable()
236 u32 pdn_ack = scpd->data->sram_pdn_ack_bits; in scpsys_sram_enable()
240 val &= ~scpd->data->sram_pdn_bits; in scpsys_sram_enable()
266 u32 pdn_ack = scpd->data->sram_pdn_ack_bits; in scpsys_sram_disable()
270 val |= scpd->data->sram_pdn_bits; in scpsys_sram_disable()
281 struct scp *scp = scpd->scp; in scpsys_bus_protect_enable()
283 if (!scpd->data->bus_prot_mask) in scpsys_bus_protect_enable()
286 return mtk_infracfg_set_bus_protection(scp->infracfg, in scpsys_bus_protect_enable()
287 scpd->data->bus_prot_mask, in scpsys_bus_protect_enable()
288 scp->bus_prot_reg_update); in scpsys_bus_protect_enable()
293 struct scp *scp = scpd->scp; in scpsys_bus_protect_disable()
295 if (!scpd->data->bus_prot_mask) in scpsys_bus_protect_disable()
298 return mtk_infracfg_clear_bus_protection(scp->infracfg, in scpsys_bus_protect_disable()
299 scpd->data->bus_prot_mask, in scpsys_bus_protect_disable()
300 scp->bus_prot_reg_update); in scpsys_bus_protect_disable()
306 struct scp *scp = scpd->scp; in scpsys_power_on()
307 void __iomem *ctl_addr = scp->base + scpd->data->ctl_offs; in scpsys_power_on()
315 ret = scpsys_clk_enable(scpd->clk, MAX_CLKS); in scpsys_power_on()
352 scpsys_clk_disable(scpd->clk, MAX_CLKS); in scpsys_power_on()
356 dev_err(scp->dev, "Failed to power on domain %s\n", genpd->name); in scpsys_power_on()
364 struct scp *scp = scpd->scp; in scpsys_power_off()
365 void __iomem *ctl_addr = scp->base + scpd->data->ctl_offs; in scpsys_power_off()
400 scpsys_clk_disable(scpd->clk, MAX_CLKS); in scpsys_power_off()
409 dev_err(scp->dev, "Failed to power off domain %s\n", genpd->name); in scpsys_power_off()
419 clk[i] = devm_clk_get(&pdev->dev, clk_names[i]); in init_clks()
433 scp = devm_kzalloc(&pdev->dev, sizeof(*scp), GFP_KERNEL); in init_scp()
435 return ERR_PTR(-ENOMEM); in init_scp()
437 scp->ctrl_reg.pwr_sta_offs = scp_ctrl_reg->pwr_sta_offs; in init_scp()
438 scp->ctrl_reg.pwr_sta2nd_offs = scp_ctrl_reg->pwr_sta2nd_offs; in init_scp()
440 scp->bus_prot_reg_update = bus_prot_reg_update; in init_scp()
442 scp->dev = &pdev->dev; in init_scp()
445 scp->base = devm_ioremap_resource(&pdev->dev, res); in init_scp()
446 if (IS_ERR(scp->base)) in init_scp()
447 return ERR_CAST(scp->base); in init_scp()
449 scp->domains = devm_kcalloc(&pdev->dev, in init_scp()
450 num, sizeof(*scp->domains), GFP_KERNEL); in init_scp()
451 if (!scp->domains) in init_scp()
452 return ERR_PTR(-ENOMEM); in init_scp()
454 pd_data = &scp->pd_data; in init_scp()
456 pd_data->domains = devm_kcalloc(&pdev->dev, in init_scp()
457 num, sizeof(*pd_data->domains), GFP_KERNEL); in init_scp()
458 if (!pd_data->domains) in init_scp()
459 return ERR_PTR(-ENOMEM); in init_scp()
461 scp->infracfg = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, in init_scp()
463 if (IS_ERR(scp->infracfg)) { in init_scp()
464 dev_err(&pdev->dev, "Cannot find infracfg controller: %ld\n", in init_scp()
465 PTR_ERR(scp->infracfg)); in init_scp()
466 return ERR_CAST(scp->infracfg); in init_scp()
470 struct scp_domain *scpd = &scp->domains[i]; in init_scp()
473 scpd->supply = devm_regulator_get_optional(&pdev->dev, data->name); in init_scp()
474 if (IS_ERR(scpd->supply)) { in init_scp()
475 if (PTR_ERR(scpd->supply) == -ENODEV) in init_scp()
476 scpd->supply = NULL; in init_scp()
478 return ERR_CAST(scpd->supply); in init_scp()
482 pd_data->num_domains = num; in init_scp()
487 struct scp_domain *scpd = &scp->domains[i]; in init_scp()
488 struct generic_pm_domain *genpd = &scpd->genpd; in init_scp()
491 pd_data->domains[i] = genpd; in init_scp()
492 scpd->scp = scp; in init_scp()
494 scpd->data = data; in init_scp()
496 for (j = 0; j < MAX_CLKS && data->clk_id[j]; j++) { in init_scp()
497 struct clk *c = clk[data->clk_id[j]]; in init_scp()
500 dev_err(&pdev->dev, "%s: clk unavailable\n", in init_scp()
501 data->name); in init_scp()
505 scpd->clk[j] = c; in init_scp()
508 genpd->name = data->name; in init_scp()
509 genpd->power_off = scpsys_power_off; in init_scp()
510 genpd->power_on = scpsys_power_on; in init_scp()
512 genpd->flags |= GENPD_FLAG_ACTIVE_WAKEUP; in init_scp()
525 struct scp_domain *scpd = &scp->domains[i]; in mtk_register_power_domains()
526 struct generic_pm_domain *genpd = &scpd->genpd; in mtk_register_power_domains()
535 on = !WARN_ON(genpd->power_on(genpd) < 0); in mtk_register_power_domains()
546 pd_data = &scp->pd_data; in mtk_register_power_domains()
548 ret = of_genpd_add_provider_onecell(pdev->dev.of_node, pd_data); in mtk_register_power_domains()
550 dev_err(&pdev->dev, "Failed to add OF provider: %d\n", ret); in mtk_register_power_domains()
581 .sram_pdn_ack_bits = GENMASK(12, 12),
590 .sram_pdn_ack_bits = GENMASK(12, 12),
599 .sram_pdn_ack_bits = GENMASK(13, 12),
616 .sram_pdn_ack_bits = GENMASK(15, 12),
625 .sram_pdn_ack_bits = GENMASK(15, 12),
647 .sram_pdn_ack_bits = GENMASK(12, 12),
656 .sram_pdn_ack_bits = GENMASK(12, 12),
665 .sram_pdn_ack_bits = GENMASK(15, 12),
674 .sram_pdn_ack_bits = GENMASK(13, 12),
683 .sram_pdn_ack_bits = GENMASK(15, 12),
692 .sram_pdn_ack_bits = GENMASK(14, 12),
701 .sram_pdn_ack_bits = GENMASK(14, 12),
712 .bus_prot_mask = BIT(14) | BIT(21) | BIT(23),
717 .sta_mask = BIT(22),
726 .sta_mask = BIT(23),
735 .sta_mask = BIT(30),
760 .sta_mask = BIT(7),
763 .sram_pdn_ack_bits = GENMASK(12, 12),
768 .sta_mask = BIT(21),
771 .sram_pdn_ack_bits = GENMASK(15, 12),
776 .sta_mask = BIT(5),
779 .sram_pdn_ack_bits = GENMASK(13, 12),
784 .sta_mask = BIT(3),
787 .sram_pdn_ack_bits = GENMASK(12, 12),
789 .bus_prot_mask = (BIT(1) | BIT(2)),
793 .sta_mask = BIT(24),
796 .sram_pdn_ack_bits = GENMASK(15, 12),
801 .sta_mask = BIT(13),
809 .sta_mask = BIT(20),
812 .sram_pdn_ack_bits = GENMASK(12, 12),
837 .sram_pdn_ack_bits = GENMASK(15, 12),
847 .sram_pdn_ack_bits = GENMASK(15, 12),
857 .sram_pdn_ack_bits = GENMASK(15, 12),
893 .sram_pdn_ack_bits = GENMASK(15, 12),
902 .sram_pdn_ack_bits = GENMASK(15, 12),
925 .sram_pdn_ack_bits = GENMASK(12, 12),
933 .sram_pdn_ack_bits = GENMASK(15, 12),
941 .sram_pdn_ack_bits = GENMASK(13, 12),
949 .sram_pdn_ack_bits = GENMASK(12, 12),
959 .sram_pdn_ack_bits = GENMASK(15, 12),
967 .sram_pdn_ack_bits = GENMASK(15, 12),
975 .sram_pdn_ack_bits = GENMASK(15, 12),
992 .sram_pdn_ack_bits = GENMASK(13, 12),
1086 .compatible = "mediatek,mt2701-scpsys",
1089 .compatible = "mediatek,mt2712-scpsys",
1092 .compatible = "mediatek,mt6797-scpsys",
1095 .compatible = "mediatek,mt7622-scpsys",
1098 .compatible = "mediatek,mt7623a-scpsys",
1101 .compatible = "mediatek,mt8173-scpsys",
1116 soc = of_device_get_match_data(&pdev->dev); in scpsys_probe()
1118 scp = init_scp(pdev, soc->domains, soc->num_domains, &soc->regs, in scpsys_probe()
1119 soc->bus_prot_reg_update); in scpsys_probe()
1123 mtk_register_power_domains(pdev, scp, soc->num_domains); in scpsys_probe()
1125 pd_data = &scp->pd_data; in scpsys_probe()
1127 for (i = 0, sd = soc->subdomains; i < soc->num_subdomains; i++, sd++) { in scpsys_probe()
1128 ret = pm_genpd_add_subdomain(pd_data->domains[sd->origin], in scpsys_probe()
1129 pd_data->domains[sd->subdomain]); in scpsys_probe()
1131 dev_err(&pdev->dev, "Failed to add subdomain: %d\n", in scpsys_probe()
1141 .name = "mtk-scpsys",