Lines Matching +full:mt8188 +full:- +full:power

1 // SPDX-License-Identifier: GPL-2.0-only
6 #include <linux/clk-provider.h>
19 #include "mt6735-pm-domains.h"
20 #include "mt6795-pm-domains.h"
21 #include "mt8167-pm-domains.h"
22 #include "mt8173-pm-domains.h"
23 #include "mt8183-pm-domains.h"
24 #include "mt8186-pm-domains.h"
25 #include "mt8188-pm-domains.h"
26 #include "mt8192-pm-domains.h"
27 #include "mt8195-pm-domains.h"
28 #include "mt8365-pm-domains.h"
67 struct scpsys *scpsys = pd->scpsys; in scpsys_domain_is_on()
70 regmap_read(scpsys->base, pd->data->pwr_sta_offs, &status); in scpsys_domain_is_on()
71 status &= pd->data->sta_mask; in scpsys_domain_is_on()
73 regmap_read(scpsys->base, pd->data->pwr_sta2nd_offs, &status2); in scpsys_domain_is_on()
74 status2 &= pd->data->sta_mask; in scpsys_domain_is_on()
82 u32 pdn_ack = pd->data->sram_pdn_ack_bits; in scpsys_sram_enable()
83 struct scpsys *scpsys = pd->scpsys; in scpsys_sram_enable()
87 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, pd->data->sram_pdn_bits); in scpsys_sram_enable()
90 ret = regmap_read_poll_timeout(scpsys->base, pd->data->ctl_offs, tmp, in scpsys_sram_enable()
96 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_ISOINT_B_BIT); in scpsys_sram_enable()
98 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_CLKISO_BIT); in scpsys_sram_enable()
106 u32 pdn_ack = pd->data->sram_pdn_ack_bits; in scpsys_sram_disable()
107 struct scpsys *scpsys = pd->scpsys; in scpsys_sram_disable()
111 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_CLKISO_BIT); in scpsys_sram_disable()
113 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_ISOINT_B_BIT); in scpsys_sram_disable()
116 regmap_set_bits(scpsys->base, pd->data->ctl_offs, pd->data->sram_pdn_bits); in scpsys_sram_disable()
119 return regmap_read_poll_timeout(scpsys->base, pd->data->ctl_offs, tmp, in scpsys_sram_disable()
127 if (bpd->flags & BUS_PROT_COMPONENT_SMI) in scpsys_bus_protect_get_regmap()
128 return pd->smi; in scpsys_bus_protect_get_regmap()
130 return pd->infracfg; in scpsys_bus_protect_get_regmap()
136 if (bpd->flags & BUS_PROT_STA_COMPONENT_INFRA_NAO) in scpsys_bus_protect_get_sta_regmap()
137 return pd->infracfg_nao; in scpsys_bus_protect_get_sta_regmap()
147 u32 sta_mask = bpd->bus_prot_sta_mask; in scpsys_bus_protect_clear()
151 expected_ack = (bpd->flags & BUS_PROT_STA_COMPONENT_INFRA_NAO ? sta_mask : 0); in scpsys_bus_protect_clear()
153 if (bpd->flags & BUS_PROT_REG_UPDATE) in scpsys_bus_protect_clear()
154 regmap_clear_bits(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask); in scpsys_bus_protect_clear()
156 regmap_write(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask); in scpsys_bus_protect_clear()
158 if (bpd->flags & BUS_PROT_IGNORE_CLR_ACK) in scpsys_bus_protect_clear()
161 return regmap_read_poll_timeout(sta_regmap, bpd->bus_prot_sta, in scpsys_bus_protect_clear()
171 u32 sta_mask = bpd->bus_prot_sta_mask; in scpsys_bus_protect_set()
174 if (bpd->flags & BUS_PROT_REG_UPDATE) in scpsys_bus_protect_set()
175 regmap_set_bits(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask); in scpsys_bus_protect_set()
177 regmap_write(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask); in scpsys_bus_protect_set()
179 return regmap_read_poll_timeout(sta_regmap, bpd->bus_prot_sta, in scpsys_bus_protect_set()
187 const struct scpsys_bus_prot_data *bpd = &pd->data->bp_cfg[i]; in scpsys_bus_protect_enable()
190 if (!bpd->bus_prot_set_clr_mask) in scpsys_bus_protect_enable()
193 if (bpd->flags & BUS_PROT_INVERTED) in scpsys_bus_protect_enable()
206 for (int i = SPM_MAX_BUS_PROT_DATA - 1; i >= 0; i--) { in scpsys_bus_protect_disable()
207 const struct scpsys_bus_prot_data *bpd = &pd->data->bp_cfg[i]; in scpsys_bus_protect_disable()
210 if (!bpd->bus_prot_set_clr_mask) in scpsys_bus_protect_disable()
213 if (bpd->flags & BUS_PROT_INVERTED) in scpsys_bus_protect_disable()
237 struct scpsys *scpsys = pd->scpsys; in scpsys_power_on()
241 ret = scpsys_regulator_enable(pd->supply); in scpsys_power_on()
245 ret = clk_bulk_prepare_enable(pd->num_clks, pd->clks); in scpsys_power_on()
249 if (pd->data->ext_buck_iso_offs && MTK_SCPD_CAPS(pd, MTK_SCPD_EXT_BUCK_ISO)) in scpsys_power_on()
250 regmap_clear_bits(scpsys->base, pd->data->ext_buck_iso_offs, in scpsys_power_on()
251 pd->data->ext_buck_iso_mask); in scpsys_power_on()
253 /* subsys power on */ in scpsys_power_on()
254 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_BIT); in scpsys_power_on()
255 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_2ND_BIT); in scpsys_power_on()
263 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_CLK_DIS_BIT); in scpsys_power_on()
264 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ISO_BIT); in scpsys_power_on()
265 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT); in scpsys_power_on()
273 ret = clk_bulk_prepare_enable(pd->num_subsys_clks, in scpsys_power_on()
274 pd->subsys_clks); in scpsys_power_on()
288 ret = clk_bulk_prepare_enable(pd->num_subsys_clks, in scpsys_power_on()
289 pd->subsys_clks); in scpsys_power_on()
302 clk_bulk_disable_unprepare(pd->num_subsys_clks, in scpsys_power_on()
303 pd->subsys_clks); in scpsys_power_on()
305 clk_bulk_disable_unprepare(pd->num_clks, pd->clks); in scpsys_power_on()
307 scpsys_regulator_disable(pd->supply); in scpsys_power_on()
314 struct scpsys *scpsys = pd->scpsys; in scpsys_power_off()
326 if (pd->data->ext_buck_iso_offs && MTK_SCPD_CAPS(pd, MTK_SCPD_EXT_BUCK_ISO)) in scpsys_power_off()
327 regmap_set_bits(scpsys->base, pd->data->ext_buck_iso_offs, in scpsys_power_off()
328 pd->data->ext_buck_iso_mask); in scpsys_power_off()
330 clk_bulk_disable_unprepare(pd->num_subsys_clks, pd->subsys_clks); in scpsys_power_off()
332 /* subsys power off */ in scpsys_power_off()
333 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ISO_BIT); in scpsys_power_off()
334 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_CLK_DIS_BIT); in scpsys_power_off()
335 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT); in scpsys_power_off()
336 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_2ND_BIT); in scpsys_power_off()
337 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_BIT); in scpsys_power_off()
345 clk_bulk_disable_unprepare(pd->num_clks, pd->clks); in scpsys_power_off()
347 scpsys_regulator_disable(pd->supply); in scpsys_power_off()
367 dev_err(scpsys->dev, "%pOF: failed to retrieve domain id from reg: %d\n", in scpsys_add_one_domain()
369 return ERR_PTR(-EINVAL); in scpsys_add_one_domain()
372 if (id >= scpsys->soc_data->num_domains) { in scpsys_add_one_domain()
373 dev_err(scpsys->dev, "%pOF: invalid domain id %d\n", node, id); in scpsys_add_one_domain()
374 return ERR_PTR(-EINVAL); in scpsys_add_one_domain()
377 domain_data = &scpsys->soc_data->domains_data[id]; in scpsys_add_one_domain()
378 if (domain_data->sta_mask == 0) { in scpsys_add_one_domain()
379 dev_err(scpsys->dev, "%pOF: undefined domain id %d\n", node, id); in scpsys_add_one_domain()
380 return ERR_PTR(-EINVAL); in scpsys_add_one_domain()
383 pd = devm_kzalloc(scpsys->dev, sizeof(*pd), GFP_KERNEL); in scpsys_add_one_domain()
385 return ERR_PTR(-ENOMEM); in scpsys_add_one_domain()
387 pd->data = domain_data; in scpsys_add_one_domain()
388 pd->scpsys = scpsys; in scpsys_add_one_domain()
391 pd->supply = devm_of_regulator_get_optional(scpsys->dev, node, "domain"); in scpsys_add_one_domain()
392 if (IS_ERR(pd->supply)) in scpsys_add_one_domain()
393 return dev_err_cast_probe(scpsys->dev, pd->supply, in scpsys_add_one_domain()
394 "%pOF: failed to get power supply.\n", in scpsys_add_one_domain()
398 pd->infracfg = syscon_regmap_lookup_by_phandle_optional(node, "mediatek,infracfg"); in scpsys_add_one_domain()
399 if (IS_ERR(pd->infracfg)) in scpsys_add_one_domain()
400 return ERR_CAST(pd->infracfg); in scpsys_add_one_domain()
404 pd->smi = device_node_to_regmap(smi_node); in scpsys_add_one_domain()
406 if (IS_ERR(pd->smi)) in scpsys_add_one_domain()
407 return ERR_CAST(pd->smi); in scpsys_add_one_domain()
411 pd->infracfg_nao = syscon_regmap_lookup_by_phandle(node, "mediatek,infracfg-nao"); in scpsys_add_one_domain()
412 if (IS_ERR(pd->infracfg_nao)) in scpsys_add_one_domain()
413 return ERR_CAST(pd->infracfg_nao); in scpsys_add_one_domain()
415 pd->infracfg_nao = NULL; in scpsys_add_one_domain()
421 of_property_for_each_string(node, "clock-names", prop, clk_name) { in scpsys_add_one_domain()
424 subsys = strchr(clk_name, '-'); in scpsys_add_one_domain()
426 pd->num_subsys_clks++; in scpsys_add_one_domain()
428 pd->num_clks++; in scpsys_add_one_domain()
431 pd->clks = devm_kcalloc(scpsys->dev, pd->num_clks, sizeof(*pd->clks), GFP_KERNEL); in scpsys_add_one_domain()
432 if (!pd->clks) in scpsys_add_one_domain()
433 return ERR_PTR(-ENOMEM); in scpsys_add_one_domain()
435 pd->subsys_clks = devm_kcalloc(scpsys->dev, pd->num_subsys_clks, in scpsys_add_one_domain()
436 sizeof(*pd->subsys_clks), GFP_KERNEL); in scpsys_add_one_domain()
437 if (!pd->subsys_clks) in scpsys_add_one_domain()
438 return ERR_PTR(-ENOMEM); in scpsys_add_one_domain()
442 for (i = 0; i < pd->num_clks; i++) { in scpsys_add_one_domain()
446 dev_err_probe(scpsys->dev, ret, in scpsys_add_one_domain()
451 pd->clks[clk_ind++].clk = clk; in scpsys_add_one_domain()
454 for (i = 0; i < pd->num_subsys_clks; i++) { in scpsys_add_one_domain()
458 dev_err_probe(scpsys->dev, ret, in scpsys_add_one_domain()
464 pd->subsys_clks[i].clk = clk; in scpsys_add_one_domain()
475 dev_warn(scpsys->dev, in scpsys_add_one_domain()
476 "%pOF: A default off power domain has been ON\n", node); in scpsys_add_one_domain()
478 ret = scpsys_power_on(&pd->genpd); in scpsys_add_one_domain()
480 dev_err(scpsys->dev, "%pOF: failed to power on domain: %d\n", node, ret); in scpsys_add_one_domain()
485 pd->genpd.flags |= GENPD_FLAG_ALWAYS_ON; in scpsys_add_one_domain()
488 if (scpsys->domains[id]) { in scpsys_add_one_domain()
489 ret = -EINVAL; in scpsys_add_one_domain()
490 dev_err(scpsys->dev, in scpsys_add_one_domain()
491 "power domain with id %d already exists, check your device-tree\n", id); in scpsys_add_one_domain()
495 if (!pd->data->name) in scpsys_add_one_domain()
496 pd->genpd.name = node->name; in scpsys_add_one_domain()
498 pd->genpd.name = pd->data->name; in scpsys_add_one_domain()
500 pd->genpd.power_off = scpsys_power_off; in scpsys_add_one_domain()
501 pd->genpd.power_on = scpsys_power_on; in scpsys_add_one_domain()
504 pd->genpd.flags |= GENPD_FLAG_ACTIVE_WAKEUP; in scpsys_add_one_domain()
507 pm_genpd_init(&pd->genpd, NULL, true); in scpsys_add_one_domain()
509 pm_genpd_init(&pd->genpd, NULL, false); in scpsys_add_one_domain()
511 scpsys->domains[id] = &pd->genpd; in scpsys_add_one_domain()
513 return scpsys->pd_data.domains[id]; in scpsys_add_one_domain()
516 clk_bulk_put(pd->num_subsys_clks, pd->subsys_clks); in scpsys_add_one_domain()
518 clk_bulk_put(pd->num_clks, pd->clks); in scpsys_add_one_domain()
533 dev_err(scpsys->dev, "%pOF: failed to get parent domain id\n", child); in scpsys_add_subdomain()
537 if (!scpsys->pd_data.domains[id]) { in scpsys_add_subdomain()
538 ret = -EINVAL; in scpsys_add_subdomain()
539 dev_err(scpsys->dev, "power domain with id %d does not exist\n", id); in scpsys_add_subdomain()
543 parent_pd = scpsys->pd_data.domains[id]; in scpsys_add_subdomain()
548 dev_err_probe(scpsys->dev, ret, "%pOF: failed to get child domain id\n", in scpsys_add_subdomain()
560 dev_err(scpsys->dev, "failed to add %s subdomain to parent %s\n", in scpsys_add_subdomain()
561 child_pd->name, parent_pd->name); in scpsys_add_subdomain()
564 dev_dbg(scpsys->dev, "%s add subdomain: %s\n", parent_pd->name, in scpsys_add_subdomain()
565 child_pd->name); in scpsys_add_subdomain()
584 ret = pm_genpd_remove(&pd->genpd); in scpsys_remove_one_domain()
586 dev_err(pd->scpsys->dev, in scpsys_remove_one_domain()
587 "failed to remove domain '%s' : %d - state may be inconsistent\n", in scpsys_remove_one_domain()
588 pd->genpd.name, ret); in scpsys_remove_one_domain()
590 scpsys_power_off(&pd->genpd); in scpsys_remove_one_domain()
592 clk_bulk_put(pd->num_clks, pd->clks); in scpsys_remove_one_domain()
593 clk_bulk_put(pd->num_subsys_clks, pd->subsys_clks); in scpsys_remove_one_domain()
602 for (i = scpsys->pd_data.num_domains - 1; i >= 0; i--) { in scpsys_domain_cleanup()
603 genpd = scpsys->pd_data.domains[i]; in scpsys_domain_cleanup()
613 .compatible = "mediatek,mt6735-power-controller",
617 .compatible = "mediatek,mt6795-power-controller",
621 .compatible = "mediatek,mt8167-power-controller",
625 .compatible = "mediatek,mt8173-power-controller",
629 .compatible = "mediatek,mt8183-power-controller",
633 .compatible = "mediatek,mt8186-power-controller",
637 .compatible = "mediatek,mt8188-power-controller",
641 .compatible = "mediatek,mt8192-power-controller",
645 .compatible = "mediatek,mt8195-power-controller",
649 .compatible = "mediatek,mt8365-power-controller",
657 struct device *dev = &pdev->dev; in scpsys_probe()
658 struct device_node *np = dev->of_node; in scpsys_probe()
665 soc = of_device_get_match_data(&pdev->dev); in scpsys_probe()
667 dev_err(&pdev->dev, "no power controller data\n"); in scpsys_probe()
668 return -EINVAL; in scpsys_probe()
671 scpsys = devm_kzalloc(dev, struct_size(scpsys, domains, soc->num_domains), GFP_KERNEL); in scpsys_probe()
673 return -ENOMEM; in scpsys_probe()
675 scpsys->dev = dev; in scpsys_probe()
676 scpsys->soc_data = soc; in scpsys_probe()
678 scpsys->pd_data.domains = scpsys->domains; in scpsys_probe()
679 scpsys->pd_data.num_domains = soc->num_domains; in scpsys_probe()
681 parent = dev->parent; in scpsys_probe()
684 return -ENODEV; in scpsys_probe()
687 scpsys->base = syscon_node_to_regmap(parent->of_node); in scpsys_probe()
688 if (IS_ERR(scpsys->base)) { in scpsys_probe()
690 return PTR_ERR(scpsys->base); in scpsys_probe()
693 ret = -ENODEV; in scpsys_probe()
712 dev_dbg(dev, "no power domains present\n"); in scpsys_probe()
716 ret = of_genpd_add_provider_onecell(np, &scpsys->pd_data); in scpsys_probe()
732 .name = "mtk-power-controller",