Lines Matching full:pd

65 static bool scpsys_domain_is_on(struct scpsys_domain *pd)  in scpsys_domain_is_on()  argument
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()
80 static int scpsys_sram_enable(struct scpsys_domain *pd) in scpsys_sram_enable() argument
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()
95 if (MTK_SCPD_CAPS(pd, MTK_SCPD_SRAM_ISO)) { 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()
104 static int scpsys_sram_disable(struct scpsys_domain *pd) in scpsys_sram_disable() argument
106 u32 pdn_ack = pd->data->sram_pdn_ack_bits; in scpsys_sram_disable()
107 struct scpsys *scpsys = pd->scpsys; in scpsys_sram_disable()
110 if (MTK_SCPD_CAPS(pd, MTK_SCPD_SRAM_ISO)) { 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()
124 static struct regmap *scpsys_bus_protect_get_regmap(struct scpsys_domain *pd, in scpsys_bus_protect_get_regmap() argument
128 return pd->smi; in scpsys_bus_protect_get_regmap()
130 return pd->infracfg; in scpsys_bus_protect_get_regmap()
133 static struct regmap *scpsys_bus_protect_get_sta_regmap(struct scpsys_domain *pd, in scpsys_bus_protect_get_sta_regmap() argument
137 return pd->infracfg_nao; in scpsys_bus_protect_get_sta_regmap()
139 return scpsys_bus_protect_get_regmap(pd, bpd); in scpsys_bus_protect_get_sta_regmap()
142 static int scpsys_bus_protect_clear(struct scpsys_domain *pd, in scpsys_bus_protect_clear() argument
145 struct regmap *sta_regmap = scpsys_bus_protect_get_sta_regmap(pd, bpd); in scpsys_bus_protect_clear()
146 struct regmap *regmap = scpsys_bus_protect_get_regmap(pd, bpd); in scpsys_bus_protect_clear()
166 static int scpsys_bus_protect_set(struct scpsys_domain *pd, in scpsys_bus_protect_set() argument
169 struct regmap *sta_regmap = scpsys_bus_protect_get_sta_regmap(pd, bpd); in scpsys_bus_protect_set()
170 struct regmap *regmap = scpsys_bus_protect_get_regmap(pd, bpd); in scpsys_bus_protect_set()
184 static int scpsys_bus_protect_enable(struct scpsys_domain *pd) in scpsys_bus_protect_enable() argument
187 const struct scpsys_bus_prot_data *bpd = &pd->data->bp_cfg[i]; in scpsys_bus_protect_enable()
194 ret = scpsys_bus_protect_clear(pd, bpd); in scpsys_bus_protect_enable()
196 ret = scpsys_bus_protect_set(pd, bpd); in scpsys_bus_protect_enable()
204 static int scpsys_bus_protect_disable(struct scpsys_domain *pd) in scpsys_bus_protect_disable() argument
207 const struct scpsys_bus_prot_data *bpd = &pd->data->bp_cfg[i]; in scpsys_bus_protect_disable()
214 ret = scpsys_bus_protect_set(pd, bpd); in scpsys_bus_protect_disable()
216 ret = scpsys_bus_protect_clear(pd, bpd); in scpsys_bus_protect_disable()
236 struct scpsys_domain *pd = container_of(genpd, struct scpsys_domain, genpd); in scpsys_power_on() local
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()
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()
258 ret = readx_poll_timeout(scpsys_domain_is_on, pd, tmp, tmp, MTK_POLL_DELAY_US, 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()
272 if (!MTK_SCPD_CAPS(pd, MTK_SCPD_STRICT_BUS_PROTECTION)) { 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()
279 ret = scpsys_sram_enable(pd); in scpsys_power_on()
283 ret = scpsys_bus_protect_disable(pd); in scpsys_power_on()
287 if (MTK_SCPD_CAPS(pd, MTK_SCPD_STRICT_BUS_PROTECTION)) { 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()
297 scpsys_bus_protect_enable(pd); in scpsys_power_on()
299 scpsys_sram_disable(pd); in scpsys_power_on()
301 if (!MTK_SCPD_CAPS(pd, MTK_SCPD_STRICT_BUS_PROTECTION)) 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()
313 struct scpsys_domain *pd = container_of(genpd, struct scpsys_domain, genpd); in scpsys_power_off() local
314 struct scpsys *scpsys = pd->scpsys; in scpsys_power_off()
318 ret = scpsys_bus_protect_enable(pd); in scpsys_power_off()
322 ret = scpsys_sram_disable(pd); 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()
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()
340 ret = readx_poll_timeout(scpsys_domain_is_on, pd, tmp, !tmp, MTK_POLL_DELAY_US, 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()
356 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()
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()
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()
410 if (MTK_SCPD_CAPS(pd, MTK_SCPD_HAS_INFRA_NAO)) { 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()
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()
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()
442 for (i = 0; i < pd->num_clks; i++) { 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()
464 pd->subsys_clks[i].clk = clk; in scpsys_add_one_domain()
473 if (MTK_SCPD_CAPS(pd, MTK_SCPD_KEEP_DEFAULT_OFF)) { in scpsys_add_one_domain()
474 if (scpsys_domain_is_on(pd)) in scpsys_add_one_domain()
478 ret = scpsys_power_on(&pd->genpd); in scpsys_add_one_domain()
484 if (MTK_SCPD_CAPS(pd, MTK_SCPD_ALWAYS_ON)) in scpsys_add_one_domain()
485 pd->genpd.flags |= GENPD_FLAG_ALWAYS_ON; 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()
503 if (MTK_SCPD_CAPS(pd, MTK_SCPD_ACTIVE_WAKEUP)) in scpsys_add_one_domain()
504 pd->genpd.flags |= GENPD_FLAG_ACTIVE_WAKEUP; in scpsys_add_one_domain()
506 if (MTK_SCPD_CAPS(pd, MTK_SCPD_KEEP_DEFAULT_OFF)) 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()
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()
576 static void scpsys_remove_one_domain(struct scpsys_domain *pd) in scpsys_remove_one_domain() argument
584 ret = pm_genpd_remove(&pd->genpd); in scpsys_remove_one_domain()
586 dev_err(pd->scpsys->dev, in scpsys_remove_one_domain()
588 pd->genpd.name, ret); in scpsys_remove_one_domain()
589 if (scpsys_domain_is_on(pd)) 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()
599 struct scpsys_domain *pd; in scpsys_domain_cleanup() local
605 pd = to_scpsys_domain(genpd); in scpsys_domain_cleanup()
606 scpsys_remove_one_domain(pd); in scpsys_domain_cleanup()