Lines Matching +full:mt8192 +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 "mt8192-pm-domains.h"
25 #include "mt8195-pm-domains.h"
46 struct regmap *infracfg; member
63 struct scpsys *scpsys = pd->scpsys; in scpsys_domain_is_on()
66 regmap_read(scpsys->base, pd->data->pwr_sta_offs, &status); in scpsys_domain_is_on()
67 status &= pd->data->sta_mask; in scpsys_domain_is_on()
69 regmap_read(scpsys->base, pd->data->pwr_sta2nd_offs, &status2); in scpsys_domain_is_on()
70 status2 &= pd->data->sta_mask; in scpsys_domain_is_on()
78 u32 pdn_ack = pd->data->sram_pdn_ack_bits; in scpsys_sram_enable()
79 struct scpsys *scpsys = pd->scpsys; in scpsys_sram_enable()
83 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, pd->data->sram_pdn_bits); in scpsys_sram_enable()
86 ret = regmap_read_poll_timeout(scpsys->base, pd->data->ctl_offs, tmp, in scpsys_sram_enable()
92 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_ISOINT_B_BIT); in scpsys_sram_enable()
94 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_CLKISO_BIT); in scpsys_sram_enable()
102 u32 pdn_ack = pd->data->sram_pdn_ack_bits; in scpsys_sram_disable()
103 struct scpsys *scpsys = pd->scpsys; in scpsys_sram_disable()
107 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_CLKISO_BIT); in scpsys_sram_disable()
109 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_ISOINT_B_BIT); in scpsys_sram_disable()
112 regmap_set_bits(scpsys->base, pd->data->ctl_offs, pd->data->sram_pdn_bits); in scpsys_sram_disable()
115 return regmap_read_poll_timeout(scpsys->base, pd->data->ctl_offs, tmp, in scpsys_sram_disable()
149 ret = _scpsys_bus_protect_enable(pd->data->bp_infracfg, pd->infracfg); in scpsys_bus_protect_enable()
153 return _scpsys_bus_protect_enable(pd->data->bp_smi, pd->smi); in scpsys_bus_protect_enable()
161 for (i = SPM_MAX_BUS_PROT_DATA - 1; i >= 0; i--) { in _scpsys_bus_protect_disable()
189 ret = _scpsys_bus_protect_disable(pd->data->bp_smi, pd->smi); in scpsys_bus_protect_disable()
193 return _scpsys_bus_protect_disable(pd->data->bp_infracfg, pd->infracfg); in scpsys_bus_protect_disable()
209 struct scpsys *scpsys = pd->scpsys; in scpsys_power_on()
213 ret = scpsys_regulator_enable(pd->supply); in scpsys_power_on()
217 ret = clk_bulk_prepare_enable(pd->num_clks, pd->clks); in scpsys_power_on()
222 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_BIT); in scpsys_power_on()
223 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_2ND_BIT); in scpsys_power_on()
231 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_CLK_DIS_BIT); in scpsys_power_on()
232 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ISO_BIT); in scpsys_power_on()
233 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT); in scpsys_power_on()
235 ret = clk_bulk_prepare_enable(pd->num_subsys_clks, pd->subsys_clks); in scpsys_power_on()
252 clk_bulk_disable_unprepare(pd->num_subsys_clks, pd->subsys_clks); in scpsys_power_on()
254 clk_bulk_disable_unprepare(pd->num_clks, pd->clks); in scpsys_power_on()
256 scpsys_regulator_disable(pd->supply); in scpsys_power_on()
263 struct scpsys *scpsys = pd->scpsys; in scpsys_power_off()
275 clk_bulk_disable_unprepare(pd->num_subsys_clks, pd->subsys_clks); in scpsys_power_off()
278 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT); in scpsys_power_off()
279 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ISO_BIT); in scpsys_power_off()
280 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_CLK_DIS_BIT); in scpsys_power_off()
281 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_2ND_BIT); in scpsys_power_off()
282 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_BIT); in scpsys_power_off()
290 clk_bulk_disable_unprepare(pd->num_clks, pd->clks); in scpsys_power_off()
292 scpsys_regulator_disable(pd->supply); in scpsys_power_off()
302 struct device_node *root_node = scpsys->dev->of_node; in scpsys_add_one_domain()
313 dev_err(scpsys->dev, "%pOF: failed to retrieve domain id from reg: %d\n", in scpsys_add_one_domain()
315 return ERR_PTR(-EINVAL); in scpsys_add_one_domain()
318 if (id >= scpsys->soc_data->num_domains) { in scpsys_add_one_domain()
319 dev_err(scpsys->dev, "%pOF: invalid domain id %d\n", node, id); in scpsys_add_one_domain()
320 return ERR_PTR(-EINVAL); in scpsys_add_one_domain()
323 domain_data = &scpsys->soc_data->domains_data[id]; in scpsys_add_one_domain()
324 if (domain_data->sta_mask == 0) { in scpsys_add_one_domain()
325 dev_err(scpsys->dev, "%pOF: undefined domain id %d\n", node, id); in scpsys_add_one_domain()
326 return ERR_PTR(-EINVAL); in scpsys_add_one_domain()
329 pd = devm_kzalloc(scpsys->dev, sizeof(*pd), GFP_KERNEL); in scpsys_add_one_domain()
331 return ERR_PTR(-ENOMEM); in scpsys_add_one_domain()
333 pd->data = domain_data; in scpsys_add_one_domain()
334 pd->scpsys = scpsys; in scpsys_add_one_domain()
344 scpsys->dev->of_node = node; in scpsys_add_one_domain()
345 pd->supply = devm_regulator_get(scpsys->dev, "domain"); in scpsys_add_one_domain()
346 scpsys->dev->of_node = root_node; in scpsys_add_one_domain()
347 if (IS_ERR(pd->supply)) { in scpsys_add_one_domain()
348 dev_err_probe(scpsys->dev, PTR_ERR(pd->supply), in scpsys_add_one_domain()
351 return ERR_CAST(pd->supply); in scpsys_add_one_domain()
355 pd->infracfg = syscon_regmap_lookup_by_phandle_optional(node, "mediatek,infracfg"); in scpsys_add_one_domain()
356 if (IS_ERR(pd->infracfg)) in scpsys_add_one_domain()
357 return ERR_CAST(pd->infracfg); in scpsys_add_one_domain()
361 pd->smi = device_node_to_regmap(smi_node); in scpsys_add_one_domain()
363 if (IS_ERR(pd->smi)) in scpsys_add_one_domain()
364 return ERR_CAST(pd->smi); in scpsys_add_one_domain()
370 of_property_for_each_string(node, "clock-names", prop, clk_name) { in scpsys_add_one_domain()
373 subsys = strchr(clk_name, '-'); in scpsys_add_one_domain()
375 pd->num_subsys_clks++; in scpsys_add_one_domain()
377 pd->num_clks++; in scpsys_add_one_domain()
380 pd->clks = devm_kcalloc(scpsys->dev, pd->num_clks, sizeof(*pd->clks), GFP_KERNEL); in scpsys_add_one_domain()
381 if (!pd->clks) in scpsys_add_one_domain()
382 return ERR_PTR(-ENOMEM); in scpsys_add_one_domain()
384 pd->subsys_clks = devm_kcalloc(scpsys->dev, pd->num_subsys_clks, in scpsys_add_one_domain()
385 sizeof(*pd->subsys_clks), GFP_KERNEL); in scpsys_add_one_domain()
386 if (!pd->subsys_clks) in scpsys_add_one_domain()
387 return ERR_PTR(-ENOMEM); in scpsys_add_one_domain()
391 for (i = 0; i < pd->num_clks; i++) { in scpsys_add_one_domain()
395 dev_err_probe(scpsys->dev, ret, in scpsys_add_one_domain()
400 pd->clks[clk_ind++].clk = clk; in scpsys_add_one_domain()
403 for (i = 0; i < pd->num_subsys_clks; i++) { in scpsys_add_one_domain()
407 dev_err_probe(scpsys->dev, ret, in scpsys_add_one_domain()
413 pd->subsys_clks[i].clk = clk; in scpsys_add_one_domain()
424 dev_warn(scpsys->dev, in scpsys_add_one_domain()
427 ret = scpsys_power_on(&pd->genpd); in scpsys_add_one_domain()
429 dev_err(scpsys->dev, "%pOF: failed to power on domain: %d\n", node, ret); in scpsys_add_one_domain()
434 pd->genpd.flags |= GENPD_FLAG_ALWAYS_ON; in scpsys_add_one_domain()
437 if (scpsys->domains[id]) { in scpsys_add_one_domain()
438 ret = -EINVAL; in scpsys_add_one_domain()
439 dev_err(scpsys->dev, in scpsys_add_one_domain()
440 "power domain with id %d already exists, check your device-tree\n", id); in scpsys_add_one_domain()
444 if (!pd->data->name) in scpsys_add_one_domain()
445 pd->genpd.name = node->name; in scpsys_add_one_domain()
447 pd->genpd.name = pd->data->name; in scpsys_add_one_domain()
449 pd->genpd.power_off = scpsys_power_off; in scpsys_add_one_domain()
450 pd->genpd.power_on = scpsys_power_on; in scpsys_add_one_domain()
453 pd->genpd.flags |= GENPD_FLAG_ACTIVE_WAKEUP; in scpsys_add_one_domain()
456 pm_genpd_init(&pd->genpd, NULL, true); in scpsys_add_one_domain()
458 pm_genpd_init(&pd->genpd, NULL, false); in scpsys_add_one_domain()
460 scpsys->domains[id] = &pd->genpd; in scpsys_add_one_domain()
462 return scpsys->pd_data.domains[id]; in scpsys_add_one_domain()
465 clk_bulk_put(pd->num_subsys_clks, pd->subsys_clks); in scpsys_add_one_domain()
467 clk_bulk_put(pd->num_clks, pd->clks); in scpsys_add_one_domain()
482 dev_err(scpsys->dev, "%pOF: failed to get parent domain id\n", child); in scpsys_add_subdomain()
486 if (!scpsys->pd_data.domains[id]) { in scpsys_add_subdomain()
487 ret = -EINVAL; in scpsys_add_subdomain()
488 dev_err(scpsys->dev, "power domain with id %d does not exist\n", id); in scpsys_add_subdomain()
492 parent_pd = scpsys->pd_data.domains[id]; in scpsys_add_subdomain()
497 dev_err_probe(scpsys->dev, ret, "%pOF: failed to get child domain id\n", in scpsys_add_subdomain()
504 dev_err(scpsys->dev, "failed to add %s subdomain to parent %s\n", in scpsys_add_subdomain()
505 child_pd->name, parent_pd->name); in scpsys_add_subdomain()
508 dev_dbg(scpsys->dev, "%s add subdomain: %s\n", parent_pd->name, in scpsys_add_subdomain()
509 child_pd->name); in scpsys_add_subdomain()
530 scpsys_power_off(&pd->genpd); in scpsys_remove_one_domain()
536 ret = pm_genpd_remove(&pd->genpd); in scpsys_remove_one_domain()
538 dev_err(pd->scpsys->dev, in scpsys_remove_one_domain()
539 "failed to remove domain '%s' : %d - state may be inconsistent\n", in scpsys_remove_one_domain()
540 pd->genpd.name, ret); in scpsys_remove_one_domain()
542 clk_bulk_put(pd->num_clks, pd->clks); in scpsys_remove_one_domain()
543 clk_bulk_put(pd->num_subsys_clks, pd->subsys_clks); in scpsys_remove_one_domain()
552 for (i = scpsys->pd_data.num_domains - 1; i >= 0; i--) { in scpsys_domain_cleanup()
553 genpd = scpsys->pd_data.domains[i]; in scpsys_domain_cleanup()
563 .compatible = "mediatek,mt6795-power-controller",
567 .compatible = "mediatek,mt8167-power-controller",
571 .compatible = "mediatek,mt8173-power-controller",
575 .compatible = "mediatek,mt8183-power-controller",
579 .compatible = "mediatek,mt8186-power-controller",
583 .compatible = "mediatek,mt8192-power-controller",
587 .compatible = "mediatek,mt8195-power-controller",
595 struct device *dev = &pdev->dev; in scpsys_probe()
596 struct device_node *np = dev->of_node; in scpsys_probe()
603 soc = of_device_get_match_data(&pdev->dev); in scpsys_probe()
605 dev_err(&pdev->dev, "no power controller data\n"); in scpsys_probe()
606 return -EINVAL; in scpsys_probe()
609 scpsys = devm_kzalloc(dev, struct_size(scpsys, domains, soc->num_domains), GFP_KERNEL); in scpsys_probe()
611 return -ENOMEM; in scpsys_probe()
613 scpsys->dev = dev; in scpsys_probe()
614 scpsys->soc_data = soc; in scpsys_probe()
616 scpsys->pd_data.domains = scpsys->domains; in scpsys_probe()
617 scpsys->pd_data.num_domains = soc->num_domains; in scpsys_probe()
619 parent = dev->parent; in scpsys_probe()
622 return -ENODEV; in scpsys_probe()
625 scpsys->base = syscon_node_to_regmap(parent->of_node); in scpsys_probe()
626 if (IS_ERR(scpsys->base)) { in scpsys_probe()
628 return PTR_ERR(scpsys->base); in scpsys_probe()
631 ret = -ENODEV; in scpsys_probe()
654 ret = of_genpd_add_provider_onecell(np, &scpsys->pd_data); in scpsys_probe()
670 .name = "mtk-power-controller",