Lines Matching +full:mt8173 +full:- +full:infracfg
1 // SPDX-License-Identifier: GPL-2.0-only
6 #include <linux/clk-provider.h>
17 #include <linux/soc/mediatek/infracfg.h>
19 #include "mt6795-pm-domains.h"
20 #include "mt8167-pm-domains.h"
21 #include "mt8173-pm-domains.h"
22 #include "mt8183-pm-domains.h"
23 #include "mt8186-pm-domains.h"
24 #include "mt8188-pm-domains.h"
25 #include "mt8192-pm-domains.h"
26 #include "mt8195-pm-domains.h"
27 #include "mt8365-pm-domains.h"
49 struct regmap *infracfg; member
66 struct scpsys *scpsys = pd->scpsys; in scpsys_domain_is_on()
69 regmap_read(scpsys->base, pd->data->pwr_sta_offs, &status); in scpsys_domain_is_on()
70 status &= pd->data->sta_mask; in scpsys_domain_is_on()
72 regmap_read(scpsys->base, pd->data->pwr_sta2nd_offs, &status2); in scpsys_domain_is_on()
73 status2 &= pd->data->sta_mask; in scpsys_domain_is_on()
81 u32 pdn_ack = pd->data->sram_pdn_ack_bits; in scpsys_sram_enable()
82 struct scpsys *scpsys = pd->scpsys; in scpsys_sram_enable()
86 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, pd->data->sram_pdn_bits); in scpsys_sram_enable()
89 ret = regmap_read_poll_timeout(scpsys->base, pd->data->ctl_offs, tmp, in scpsys_sram_enable()
95 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_ISOINT_B_BIT); in scpsys_sram_enable()
97 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_CLKISO_BIT); in scpsys_sram_enable()
105 u32 pdn_ack = pd->data->sram_pdn_ack_bits; in scpsys_sram_disable()
106 struct scpsys *scpsys = pd->scpsys; in scpsys_sram_disable()
110 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_CLKISO_BIT); in scpsys_sram_disable()
112 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_ISOINT_B_BIT); in scpsys_sram_disable()
115 regmap_set_bits(scpsys->base, pd->data->ctl_offs, pd->data->sram_pdn_bits); in scpsys_sram_disable()
118 return regmap_read_poll_timeout(scpsys->base, pd->data->ctl_offs, tmp, in scpsys_sram_disable()
126 if (bpd->flags & BUS_PROT_COMPONENT_SMI) in scpsys_bus_protect_get_regmap()
127 return pd->smi; in scpsys_bus_protect_get_regmap()
129 return pd->infracfg; in scpsys_bus_protect_get_regmap()
135 if (bpd->flags & BUS_PROT_STA_COMPONENT_INFRA_NAO) in scpsys_bus_protect_get_sta_regmap()
136 return pd->infracfg_nao; in scpsys_bus_protect_get_sta_regmap()
146 u32 sta_mask = bpd->bus_prot_sta_mask; in scpsys_bus_protect_clear()
150 expected_ack = (bpd->flags & BUS_PROT_STA_COMPONENT_INFRA_NAO ? sta_mask : 0); in scpsys_bus_protect_clear()
152 if (bpd->flags & BUS_PROT_REG_UPDATE) in scpsys_bus_protect_clear()
153 regmap_clear_bits(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask); in scpsys_bus_protect_clear()
155 regmap_write(regmap, bpd->bus_prot_clr, bpd->bus_prot_set_clr_mask); in scpsys_bus_protect_clear()
157 if (bpd->flags & BUS_PROT_IGNORE_CLR_ACK) in scpsys_bus_protect_clear()
160 return regmap_read_poll_timeout(sta_regmap, bpd->bus_prot_sta, in scpsys_bus_protect_clear()
170 u32 sta_mask = bpd->bus_prot_sta_mask; in scpsys_bus_protect_set()
173 if (bpd->flags & BUS_PROT_REG_UPDATE) in scpsys_bus_protect_set()
174 regmap_set_bits(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask); in scpsys_bus_protect_set()
176 regmap_write(regmap, bpd->bus_prot_set, bpd->bus_prot_set_clr_mask); in scpsys_bus_protect_set()
178 return regmap_read_poll_timeout(sta_regmap, bpd->bus_prot_sta, in scpsys_bus_protect_set()
186 const struct scpsys_bus_prot_data *bpd = &pd->data->bp_cfg[i]; in scpsys_bus_protect_enable()
189 if (!bpd->bus_prot_set_clr_mask) in scpsys_bus_protect_enable()
192 if (bpd->flags & BUS_PROT_INVERTED) in scpsys_bus_protect_enable()
205 for (int i = SPM_MAX_BUS_PROT_DATA - 1; i >= 0; i--) { in scpsys_bus_protect_disable()
206 const struct scpsys_bus_prot_data *bpd = &pd->data->bp_cfg[i]; in scpsys_bus_protect_disable()
209 if (!bpd->bus_prot_set_clr_mask) in scpsys_bus_protect_disable()
212 if (bpd->flags & BUS_PROT_INVERTED) in scpsys_bus_protect_disable()
236 struct scpsys *scpsys = pd->scpsys; in scpsys_power_on()
240 ret = scpsys_regulator_enable(pd->supply); in scpsys_power_on()
244 ret = clk_bulk_prepare_enable(pd->num_clks, pd->clks); in scpsys_power_on()
248 if (pd->data->ext_buck_iso_offs && MTK_SCPD_CAPS(pd, MTK_SCPD_EXT_BUCK_ISO)) in scpsys_power_on()
249 regmap_clear_bits(scpsys->base, pd->data->ext_buck_iso_offs, in scpsys_power_on()
250 pd->data->ext_buck_iso_mask); in scpsys_power_on()
253 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_BIT); in scpsys_power_on()
254 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_2ND_BIT); in scpsys_power_on()
262 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_CLK_DIS_BIT); in scpsys_power_on()
263 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ISO_BIT); in scpsys_power_on()
264 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT); in scpsys_power_on()
272 ret = clk_bulk_prepare_enable(pd->num_subsys_clks, in scpsys_power_on()
273 pd->subsys_clks); in scpsys_power_on()
287 ret = clk_bulk_prepare_enable(pd->num_subsys_clks, in scpsys_power_on()
288 pd->subsys_clks); in scpsys_power_on()
301 clk_bulk_disable_unprepare(pd->num_subsys_clks, in scpsys_power_on()
302 pd->subsys_clks); in scpsys_power_on()
304 clk_bulk_disable_unprepare(pd->num_clks, pd->clks); in scpsys_power_on()
306 scpsys_regulator_disable(pd->supply); in scpsys_power_on()
313 struct scpsys *scpsys = pd->scpsys; in scpsys_power_off()
325 if (pd->data->ext_buck_iso_offs && MTK_SCPD_CAPS(pd, MTK_SCPD_EXT_BUCK_ISO)) in scpsys_power_off()
326 regmap_set_bits(scpsys->base, pd->data->ext_buck_iso_offs, in scpsys_power_off()
327 pd->data->ext_buck_iso_mask); in scpsys_power_off()
329 clk_bulk_disable_unprepare(pd->num_subsys_clks, pd->subsys_clks); in scpsys_power_off()
332 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ISO_BIT); in scpsys_power_off()
333 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_CLK_DIS_BIT); in scpsys_power_off()
334 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT); in scpsys_power_off()
335 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_2ND_BIT); in scpsys_power_off()
336 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_BIT); in scpsys_power_off()
344 clk_bulk_disable_unprepare(pd->num_clks, pd->clks); in scpsys_power_off()
346 scpsys_regulator_disable(pd->supply); in scpsys_power_off()
356 struct device_node *root_node = scpsys->dev->of_node; in scpsys_add_one_domain()
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()
398 scpsys->dev->of_node = node; in scpsys_add_one_domain()
399 pd->supply = devm_regulator_get(scpsys->dev, "domain"); in scpsys_add_one_domain()
400 scpsys->dev->of_node = root_node; in scpsys_add_one_domain()
401 if (IS_ERR(pd->supply)) in scpsys_add_one_domain()
402 return dev_err_cast_probe(scpsys->dev, pd->supply, in scpsys_add_one_domain()
407 pd->infracfg = syscon_regmap_lookup_by_phandle_optional(node, "mediatek,infracfg"); in scpsys_add_one_domain()
408 if (IS_ERR(pd->infracfg)) in scpsys_add_one_domain()
409 return ERR_CAST(pd->infracfg); in scpsys_add_one_domain()
413 pd->smi = device_node_to_regmap(smi_node); in scpsys_add_one_domain()
415 if (IS_ERR(pd->smi)) in scpsys_add_one_domain()
416 return ERR_CAST(pd->smi); in scpsys_add_one_domain()
420 pd->infracfg_nao = syscon_regmap_lookup_by_phandle(node, "mediatek,infracfg-nao"); in scpsys_add_one_domain()
421 if (IS_ERR(pd->infracfg_nao)) in scpsys_add_one_domain()
422 return ERR_CAST(pd->infracfg_nao); in scpsys_add_one_domain()
424 pd->infracfg_nao = NULL; in scpsys_add_one_domain()
430 of_property_for_each_string(node, "clock-names", prop, clk_name) { in scpsys_add_one_domain()
433 subsys = strchr(clk_name, '-'); in scpsys_add_one_domain()
435 pd->num_subsys_clks++; in scpsys_add_one_domain()
437 pd->num_clks++; in scpsys_add_one_domain()
440 pd->clks = devm_kcalloc(scpsys->dev, pd->num_clks, sizeof(*pd->clks), GFP_KERNEL); in scpsys_add_one_domain()
441 if (!pd->clks) in scpsys_add_one_domain()
442 return ERR_PTR(-ENOMEM); in scpsys_add_one_domain()
444 pd->subsys_clks = devm_kcalloc(scpsys->dev, pd->num_subsys_clks, in scpsys_add_one_domain()
445 sizeof(*pd->subsys_clks), GFP_KERNEL); in scpsys_add_one_domain()
446 if (!pd->subsys_clks) in scpsys_add_one_domain()
447 return ERR_PTR(-ENOMEM); in scpsys_add_one_domain()
451 for (i = 0; i < pd->num_clks; i++) { in scpsys_add_one_domain()
455 dev_err_probe(scpsys->dev, ret, in scpsys_add_one_domain()
460 pd->clks[clk_ind++].clk = clk; in scpsys_add_one_domain()
463 for (i = 0; i < pd->num_subsys_clks; i++) { in scpsys_add_one_domain()
467 dev_err_probe(scpsys->dev, ret, in scpsys_add_one_domain()
473 pd->subsys_clks[i].clk = clk; in scpsys_add_one_domain()
484 dev_warn(scpsys->dev, in scpsys_add_one_domain()
487 ret = scpsys_power_on(&pd->genpd); in scpsys_add_one_domain()
489 dev_err(scpsys->dev, "%pOF: failed to power on domain: %d\n", node, ret); in scpsys_add_one_domain()
494 pd->genpd.flags |= GENPD_FLAG_ALWAYS_ON; in scpsys_add_one_domain()
497 if (scpsys->domains[id]) { in scpsys_add_one_domain()
498 ret = -EINVAL; in scpsys_add_one_domain()
499 dev_err(scpsys->dev, in scpsys_add_one_domain()
500 "power domain with id %d already exists, check your device-tree\n", id); in scpsys_add_one_domain()
504 if (!pd->data->name) in scpsys_add_one_domain()
505 pd->genpd.name = node->name; in scpsys_add_one_domain()
507 pd->genpd.name = pd->data->name; in scpsys_add_one_domain()
509 pd->genpd.power_off = scpsys_power_off; in scpsys_add_one_domain()
510 pd->genpd.power_on = scpsys_power_on; in scpsys_add_one_domain()
513 pd->genpd.flags |= GENPD_FLAG_ACTIVE_WAKEUP; in scpsys_add_one_domain()
516 pm_genpd_init(&pd->genpd, NULL, true); in scpsys_add_one_domain()
518 pm_genpd_init(&pd->genpd, NULL, false); in scpsys_add_one_domain()
520 scpsys->domains[id] = &pd->genpd; in scpsys_add_one_domain()
522 return scpsys->pd_data.domains[id]; in scpsys_add_one_domain()
525 clk_bulk_put(pd->num_subsys_clks, pd->subsys_clks); in scpsys_add_one_domain()
527 clk_bulk_put(pd->num_clks, pd->clks); in scpsys_add_one_domain()
542 dev_err(scpsys->dev, "%pOF: failed to get parent domain id\n", child); in scpsys_add_subdomain()
546 if (!scpsys->pd_data.domains[id]) { in scpsys_add_subdomain()
547 ret = -EINVAL; in scpsys_add_subdomain()
548 dev_err(scpsys->dev, "power domain with id %d does not exist\n", id); in scpsys_add_subdomain()
552 parent_pd = scpsys->pd_data.domains[id]; in scpsys_add_subdomain()
557 dev_err_probe(scpsys->dev, ret, "%pOF: failed to get child domain id\n", in scpsys_add_subdomain()
569 dev_err(scpsys->dev, "failed to add %s subdomain to parent %s\n", in scpsys_add_subdomain()
570 child_pd->name, parent_pd->name); in scpsys_add_subdomain()
573 dev_dbg(scpsys->dev, "%s add subdomain: %s\n", parent_pd->name, in scpsys_add_subdomain()
574 child_pd->name); in scpsys_add_subdomain()
593 ret = pm_genpd_remove(&pd->genpd); in scpsys_remove_one_domain()
595 dev_err(pd->scpsys->dev, in scpsys_remove_one_domain()
596 "failed to remove domain '%s' : %d - state may be inconsistent\n", in scpsys_remove_one_domain()
597 pd->genpd.name, ret); in scpsys_remove_one_domain()
599 scpsys_power_off(&pd->genpd); in scpsys_remove_one_domain()
601 clk_bulk_put(pd->num_clks, pd->clks); in scpsys_remove_one_domain()
602 clk_bulk_put(pd->num_subsys_clks, pd->subsys_clks); in scpsys_remove_one_domain()
611 for (i = scpsys->pd_data.num_domains - 1; i >= 0; i--) { in scpsys_domain_cleanup()
612 genpd = scpsys->pd_data.domains[i]; in scpsys_domain_cleanup()
622 .compatible = "mediatek,mt6795-power-controller",
626 .compatible = "mediatek,mt8167-power-controller",
630 .compatible = "mediatek,mt8173-power-controller",
634 .compatible = "mediatek,mt8183-power-controller",
638 .compatible = "mediatek,mt8186-power-controller",
642 .compatible = "mediatek,mt8188-power-controller",
646 .compatible = "mediatek,mt8192-power-controller",
650 .compatible = "mediatek,mt8195-power-controller",
654 .compatible = "mediatek,mt8365-power-controller",
662 struct device *dev = &pdev->dev; in scpsys_probe()
663 struct device_node *np = dev->of_node; in scpsys_probe()
670 soc = of_device_get_match_data(&pdev->dev); in scpsys_probe()
672 dev_err(&pdev->dev, "no power controller data\n"); in scpsys_probe()
673 return -EINVAL; in scpsys_probe()
676 scpsys = devm_kzalloc(dev, struct_size(scpsys, domains, soc->num_domains), GFP_KERNEL); in scpsys_probe()
678 return -ENOMEM; in scpsys_probe()
680 scpsys->dev = dev; in scpsys_probe()
681 scpsys->soc_data = soc; in scpsys_probe()
683 scpsys->pd_data.domains = scpsys->domains; in scpsys_probe()
684 scpsys->pd_data.num_domains = soc->num_domains; in scpsys_probe()
686 parent = dev->parent; in scpsys_probe()
689 return -ENODEV; in scpsys_probe()
692 scpsys->base = syscon_node_to_regmap(parent->of_node); in scpsys_probe()
693 if (IS_ERR(scpsys->base)) { in scpsys_probe()
695 return PTR_ERR(scpsys->base); in scpsys_probe()
698 ret = -ENODEV; in scpsys_probe()
721 ret = of_genpd_add_provider_onecell(np, &scpsys->pd_data); in scpsys_probe()
737 .name = "mtk-power-controller",