Lines Matching full:pd
64 static bool scpsys_domain_is_on(struct scpsys_domain *pd) in scpsys_domain_is_on() argument
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()
79 static int scpsys_sram_enable(struct scpsys_domain *pd) in scpsys_sram_enable() argument
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()
94 if (MTK_SCPD_CAPS(pd, MTK_SCPD_SRAM_ISO)) { 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()
103 static int scpsys_sram_disable(struct scpsys_domain *pd) in scpsys_sram_disable() argument
105 u32 pdn_ack = pd->data->sram_pdn_ack_bits; in scpsys_sram_disable()
106 struct scpsys *scpsys = pd->scpsys; in scpsys_sram_disable()
109 if (MTK_SCPD_CAPS(pd, MTK_SCPD_SRAM_ISO)) { 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()
123 static struct regmap *scpsys_bus_protect_get_regmap(struct scpsys_domain *pd, in scpsys_bus_protect_get_regmap() argument
127 return pd->smi; in scpsys_bus_protect_get_regmap()
129 return pd->infracfg; in scpsys_bus_protect_get_regmap()
132 static struct regmap *scpsys_bus_protect_get_sta_regmap(struct scpsys_domain *pd, in scpsys_bus_protect_get_sta_regmap() argument
136 return pd->infracfg_nao; in scpsys_bus_protect_get_sta_regmap()
138 return scpsys_bus_protect_get_regmap(pd, bpd); in scpsys_bus_protect_get_sta_regmap()
141 static int scpsys_bus_protect_clear(struct scpsys_domain *pd, in scpsys_bus_protect_clear() argument
144 struct regmap *sta_regmap = scpsys_bus_protect_get_sta_regmap(pd, bpd); in scpsys_bus_protect_clear()
145 struct regmap *regmap = scpsys_bus_protect_get_regmap(pd, bpd); in scpsys_bus_protect_clear()
165 static int scpsys_bus_protect_set(struct scpsys_domain *pd, in scpsys_bus_protect_set() argument
168 struct regmap *sta_regmap = scpsys_bus_protect_get_sta_regmap(pd, bpd); in scpsys_bus_protect_set()
169 struct regmap *regmap = scpsys_bus_protect_get_regmap(pd, bpd); in scpsys_bus_protect_set()
183 static int scpsys_bus_protect_enable(struct scpsys_domain *pd) in scpsys_bus_protect_enable() argument
186 const struct scpsys_bus_prot_data *bpd = &pd->data->bp_cfg[i]; in scpsys_bus_protect_enable()
193 ret = scpsys_bus_protect_clear(pd, bpd); in scpsys_bus_protect_enable()
195 ret = scpsys_bus_protect_set(pd, bpd); in scpsys_bus_protect_enable()
203 static int scpsys_bus_protect_disable(struct scpsys_domain *pd) in scpsys_bus_protect_disable() argument
206 const struct scpsys_bus_prot_data *bpd = &pd->data->bp_cfg[i]; in scpsys_bus_protect_disable()
213 ret = scpsys_bus_protect_set(pd, bpd); in scpsys_bus_protect_disable()
215 ret = scpsys_bus_protect_clear(pd, bpd); in scpsys_bus_protect_disable()
235 struct scpsys_domain *pd = container_of(genpd, struct scpsys_domain, genpd); in scpsys_power_on() local
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()
257 ret = readx_poll_timeout(scpsys_domain_is_on, pd, tmp, tmp, MTK_POLL_DELAY_US, 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()
271 if (!MTK_SCPD_CAPS(pd, MTK_SCPD_STRICT_BUS_PROTECTION)) { 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()
278 ret = scpsys_sram_enable(pd); in scpsys_power_on()
282 ret = scpsys_bus_protect_disable(pd); in scpsys_power_on()
286 if (MTK_SCPD_CAPS(pd, MTK_SCPD_STRICT_BUS_PROTECTION)) { 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()
296 scpsys_bus_protect_enable(pd); in scpsys_power_on()
298 scpsys_sram_disable(pd); in scpsys_power_on()
300 if (!MTK_SCPD_CAPS(pd, MTK_SCPD_STRICT_BUS_PROTECTION)) 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()
312 struct scpsys_domain *pd = container_of(genpd, struct scpsys_domain, genpd); in scpsys_power_off() local
313 struct scpsys *scpsys = pd->scpsys; in scpsys_power_off()
317 ret = scpsys_bus_protect_enable(pd); in scpsys_power_off()
321 ret = scpsys_sram_disable(pd); 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()
339 ret = readx_poll_timeout(scpsys_domain_is_on, pd, tmp, !tmp, MTK_POLL_DELAY_US, 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()
355 struct scpsys_domain *pd; in scpsys_add_one_domain() local
383 pd = devm_kzalloc(scpsys->dev, sizeof(*pd), GFP_KERNEL); in scpsys_add_one_domain()
384 if (!pd) in scpsys_add_one_domain()
387 pd->data = domain_data; in scpsys_add_one_domain()
388 pd->scpsys = scpsys; in scpsys_add_one_domain()
390 if (MTK_SCPD_CAPS(pd, MTK_SCPD_DOMAIN_SUPPLY)) { in scpsys_add_one_domain()
399 pd->supply = devm_regulator_get(scpsys->dev, "domain"); 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()
419 if (MTK_SCPD_CAPS(pd, MTK_SCPD_HAS_INFRA_NAO)) { 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()
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()
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()
451 for (i = 0; i < pd->num_clks; i++) { 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()
473 pd->subsys_clks[i].clk = clk; in scpsys_add_one_domain()
482 if (MTK_SCPD_CAPS(pd, MTK_SCPD_KEEP_DEFAULT_OFF)) { in scpsys_add_one_domain()
483 if (scpsys_domain_is_on(pd)) in scpsys_add_one_domain()
487 ret = scpsys_power_on(&pd->genpd); in scpsys_add_one_domain()
493 if (MTK_SCPD_CAPS(pd, MTK_SCPD_ALWAYS_ON)) in scpsys_add_one_domain()
494 pd->genpd.flags |= GENPD_FLAG_ALWAYS_ON; 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()
512 if (MTK_SCPD_CAPS(pd, MTK_SCPD_ACTIVE_WAKEUP)) in scpsys_add_one_domain()
513 pd->genpd.flags |= GENPD_FLAG_ACTIVE_WAKEUP; in scpsys_add_one_domain()
515 if (MTK_SCPD_CAPS(pd, MTK_SCPD_KEEP_DEFAULT_OFF)) 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()
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()
585 static void scpsys_remove_one_domain(struct scpsys_domain *pd) in scpsys_remove_one_domain() argument
593 ret = pm_genpd_remove(&pd->genpd); in scpsys_remove_one_domain()
595 dev_err(pd->scpsys->dev, in scpsys_remove_one_domain()
597 pd->genpd.name, ret); in scpsys_remove_one_domain()
598 if (scpsys_domain_is_on(pd)) 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()
608 struct scpsys_domain *pd; in scpsys_domain_cleanup() local
614 pd = to_scpsys_domain(genpd); in scpsys_domain_cleanup()
615 scpsys_remove_one_domain(pd); in scpsys_domain_cleanup()