Lines Matching full:pd

62 static bool scpsys_domain_is_on(struct scpsys_domain *pd)  in scpsys_domain_is_on()  argument
64 struct scpsys *scpsys = pd->scpsys; in scpsys_domain_is_on()
67 regmap_read(scpsys->base, pd->data->pwr_sta_offs, &status); in scpsys_domain_is_on()
68 status &= pd->data->sta_mask; in scpsys_domain_is_on()
70 regmap_read(scpsys->base, pd->data->pwr_sta2nd_offs, &status2); in scpsys_domain_is_on()
71 status2 &= pd->data->sta_mask; in scpsys_domain_is_on()
77 static int scpsys_sram_enable(struct scpsys_domain *pd) in scpsys_sram_enable() argument
79 u32 pdn_ack = pd->data->sram_pdn_ack_bits; in scpsys_sram_enable()
80 struct scpsys *scpsys = pd->scpsys; in scpsys_sram_enable()
84 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, pd->data->sram_pdn_bits); in scpsys_sram_enable()
87 ret = regmap_read_poll_timeout(scpsys->base, pd->data->ctl_offs, tmp, in scpsys_sram_enable()
92 if (MTK_SCPD_CAPS(pd, MTK_SCPD_SRAM_ISO)) { in scpsys_sram_enable()
93 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_ISOINT_B_BIT); in scpsys_sram_enable()
95 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_CLKISO_BIT); in scpsys_sram_enable()
101 static int scpsys_sram_disable(struct scpsys_domain *pd) in scpsys_sram_disable() argument
103 u32 pdn_ack = pd->data->sram_pdn_ack_bits; in scpsys_sram_disable()
104 struct scpsys *scpsys = pd->scpsys; in scpsys_sram_disable()
107 if (MTK_SCPD_CAPS(pd, MTK_SCPD_SRAM_ISO)) { in scpsys_sram_disable()
108 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_CLKISO_BIT); in scpsys_sram_disable()
110 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_ISOINT_B_BIT); in scpsys_sram_disable()
113 regmap_set_bits(scpsys->base, pd->data->ctl_offs, pd->data->sram_pdn_bits); in scpsys_sram_disable()
116 return regmap_read_poll_timeout(scpsys->base, pd->data->ctl_offs, tmp, in scpsys_sram_disable()
146 static int scpsys_bus_protect_enable(struct scpsys_domain *pd) in scpsys_bus_protect_enable() argument
150 ret = _scpsys_bus_protect_enable(pd->data->bp_infracfg, pd->infracfg); in scpsys_bus_protect_enable()
154 return _scpsys_bus_protect_enable(pd->data->bp_smi, pd->smi); in scpsys_bus_protect_enable()
186 static int scpsys_bus_protect_disable(struct scpsys_domain *pd) in scpsys_bus_protect_disable() argument
190 ret = _scpsys_bus_protect_disable(pd->data->bp_smi, pd->smi); in scpsys_bus_protect_disable()
194 return _scpsys_bus_protect_disable(pd->data->bp_infracfg, pd->infracfg); in scpsys_bus_protect_disable()
209 struct scpsys_domain *pd = container_of(genpd, struct scpsys_domain, genpd); in scpsys_power_on() local
210 struct scpsys *scpsys = pd->scpsys; in scpsys_power_on()
214 ret = scpsys_regulator_enable(pd->supply); in scpsys_power_on()
218 ret = clk_bulk_prepare_enable(pd->num_clks, pd->clks); in scpsys_power_on()
222 if (pd->data->ext_buck_iso_offs && MTK_SCPD_CAPS(pd, MTK_SCPD_EXT_BUCK_ISO)) in scpsys_power_on()
223 regmap_clear_bits(scpsys->base, pd->data->ext_buck_iso_offs, in scpsys_power_on()
224 pd->data->ext_buck_iso_mask); in scpsys_power_on()
227 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_BIT); in scpsys_power_on()
228 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_2ND_BIT); in scpsys_power_on()
231 ret = readx_poll_timeout(scpsys_domain_is_on, pd, tmp, tmp, MTK_POLL_DELAY_US, in scpsys_power_on()
236 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_CLK_DIS_BIT); in scpsys_power_on()
237 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ISO_BIT); in scpsys_power_on()
238 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT); in scpsys_power_on()
240 ret = clk_bulk_prepare_enable(pd->num_subsys_clks, pd->subsys_clks); in scpsys_power_on()
244 ret = scpsys_sram_enable(pd); in scpsys_power_on()
248 ret = scpsys_bus_protect_disable(pd); in scpsys_power_on()
255 scpsys_sram_disable(pd); in scpsys_power_on()
257 clk_bulk_disable_unprepare(pd->num_subsys_clks, pd->subsys_clks); in scpsys_power_on()
259 clk_bulk_disable_unprepare(pd->num_clks, pd->clks); in scpsys_power_on()
261 scpsys_regulator_disable(pd->supply); in scpsys_power_on()
267 struct scpsys_domain *pd = container_of(genpd, struct scpsys_domain, genpd); in scpsys_power_off() local
268 struct scpsys *scpsys = pd->scpsys; in scpsys_power_off()
272 ret = scpsys_bus_protect_enable(pd); in scpsys_power_off()
276 ret = scpsys_sram_disable(pd); in scpsys_power_off()
280 if (pd->data->ext_buck_iso_offs && MTK_SCPD_CAPS(pd, MTK_SCPD_EXT_BUCK_ISO)) in scpsys_power_off()
281 regmap_set_bits(scpsys->base, pd->data->ext_buck_iso_offs, in scpsys_power_off()
282 pd->data->ext_buck_iso_mask); in scpsys_power_off()
284 clk_bulk_disable_unprepare(pd->num_subsys_clks, pd->subsys_clks); in scpsys_power_off()
287 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ISO_BIT); in scpsys_power_off()
288 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_CLK_DIS_BIT); in scpsys_power_off()
289 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT); in scpsys_power_off()
290 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_2ND_BIT); in scpsys_power_off()
291 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_BIT); in scpsys_power_off()
294 ret = readx_poll_timeout(scpsys_domain_is_on, pd, tmp, !tmp, MTK_POLL_DELAY_US, in scpsys_power_off()
299 clk_bulk_disable_unprepare(pd->num_clks, pd->clks); in scpsys_power_off()
301 scpsys_regulator_disable(pd->supply); in scpsys_power_off()
310 struct scpsys_domain *pd; in scpsys_add_one_domain() local
338 pd = devm_kzalloc(scpsys->dev, sizeof(*pd), GFP_KERNEL); in scpsys_add_one_domain()
339 if (!pd) in scpsys_add_one_domain()
342 pd->data = domain_data; in scpsys_add_one_domain()
343 pd->scpsys = scpsys; in scpsys_add_one_domain()
345 if (MTK_SCPD_CAPS(pd, MTK_SCPD_DOMAIN_SUPPLY)) { in scpsys_add_one_domain()
354 pd->supply = devm_regulator_get(scpsys->dev, "domain"); in scpsys_add_one_domain()
356 if (IS_ERR(pd->supply)) { in scpsys_add_one_domain()
357 dev_err_probe(scpsys->dev, PTR_ERR(pd->supply), in scpsys_add_one_domain()
360 return ERR_CAST(pd->supply); in scpsys_add_one_domain()
364 pd->infracfg = syscon_regmap_lookup_by_phandle_optional(node, "mediatek,infracfg"); in scpsys_add_one_domain()
365 if (IS_ERR(pd->infracfg)) in scpsys_add_one_domain()
366 return ERR_CAST(pd->infracfg); in scpsys_add_one_domain()
370 pd->smi = device_node_to_regmap(smi_node); in scpsys_add_one_domain()
372 if (IS_ERR(pd->smi)) in scpsys_add_one_domain()
373 return ERR_CAST(pd->smi); in scpsys_add_one_domain()
384 pd->num_subsys_clks++; in scpsys_add_one_domain()
386 pd->num_clks++; in scpsys_add_one_domain()
389 pd->clks = devm_kcalloc(scpsys->dev, pd->num_clks, sizeof(*pd->clks), GFP_KERNEL); in scpsys_add_one_domain()
390 if (!pd->clks) in scpsys_add_one_domain()
393 pd->subsys_clks = devm_kcalloc(scpsys->dev, pd->num_subsys_clks, in scpsys_add_one_domain()
394 sizeof(*pd->subsys_clks), GFP_KERNEL); in scpsys_add_one_domain()
395 if (!pd->subsys_clks) in scpsys_add_one_domain()
400 for (i = 0; i < pd->num_clks; i++) { in scpsys_add_one_domain()
409 pd->clks[clk_ind++].clk = clk; in scpsys_add_one_domain()
412 for (i = 0; i < pd->num_subsys_clks; i++) { in scpsys_add_one_domain()
422 pd->subsys_clks[i].clk = clk; in scpsys_add_one_domain()
431 if (MTK_SCPD_CAPS(pd, MTK_SCPD_KEEP_DEFAULT_OFF)) { in scpsys_add_one_domain()
432 if (scpsys_domain_is_on(pd)) in scpsys_add_one_domain()
436 ret = scpsys_power_on(&pd->genpd); in scpsys_add_one_domain()
442 if (MTK_SCPD_CAPS(pd, MTK_SCPD_ALWAYS_ON)) in scpsys_add_one_domain()
443 pd->genpd.flags |= GENPD_FLAG_ALWAYS_ON; in scpsys_add_one_domain()
453 if (!pd->data->name) in scpsys_add_one_domain()
454 pd->genpd.name = node->name; in scpsys_add_one_domain()
456 pd->genpd.name = pd->data->name; in scpsys_add_one_domain()
458 pd->genpd.power_off = scpsys_power_off; in scpsys_add_one_domain()
459 pd->genpd.power_on = scpsys_power_on; in scpsys_add_one_domain()
461 if (MTK_SCPD_CAPS(pd, MTK_SCPD_ACTIVE_WAKEUP)) in scpsys_add_one_domain()
462 pd->genpd.flags |= GENPD_FLAG_ACTIVE_WAKEUP; in scpsys_add_one_domain()
464 if (MTK_SCPD_CAPS(pd, MTK_SCPD_KEEP_DEFAULT_OFF)) in scpsys_add_one_domain()
465 pm_genpd_init(&pd->genpd, NULL, true); in scpsys_add_one_domain()
467 pm_genpd_init(&pd->genpd, NULL, false); in scpsys_add_one_domain()
469 scpsys->domains[id] = &pd->genpd; in scpsys_add_one_domain()
474 clk_bulk_put(pd->num_subsys_clks, pd->subsys_clks); in scpsys_add_one_domain()
476 clk_bulk_put(pd->num_clks, pd->clks); in scpsys_add_one_domain()
534 static void scpsys_remove_one_domain(struct scpsys_domain *pd) in scpsys_remove_one_domain() argument
542 ret = pm_genpd_remove(&pd->genpd); in scpsys_remove_one_domain()
544 dev_err(pd->scpsys->dev, in scpsys_remove_one_domain()
546 pd->genpd.name, ret); in scpsys_remove_one_domain()
547 if (scpsys_domain_is_on(pd)) in scpsys_remove_one_domain()
548 scpsys_power_off(&pd->genpd); in scpsys_remove_one_domain()
550 clk_bulk_put(pd->num_clks, pd->clks); in scpsys_remove_one_domain()
551 clk_bulk_put(pd->num_subsys_clks, pd->subsys_clks); in scpsys_remove_one_domain()
557 struct scpsys_domain *pd; in scpsys_domain_cleanup() local
563 pd = to_scpsys_domain(genpd); in scpsys_domain_cleanup()
564 scpsys_remove_one_domain(pd); in scpsys_domain_cleanup()