Lines Matching full:pd

58 static bool scpsys_domain_is_on(struct scpsys_domain *pd)  in scpsys_domain_is_on()  argument
60 struct scpsys *scpsys = pd->scpsys; in scpsys_domain_is_on()
64 status &= pd->data->sta_mask; in scpsys_domain_is_on()
67 status2 &= pd->data->sta_mask; in scpsys_domain_is_on()
73 static int scpsys_sram_enable(struct scpsys_domain *pd) in scpsys_sram_enable() argument
75 u32 pdn_ack = pd->data->sram_pdn_ack_bits; in scpsys_sram_enable()
76 struct scpsys *scpsys = pd->scpsys; in scpsys_sram_enable()
80 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, pd->data->sram_pdn_bits); in scpsys_sram_enable()
83 ret = regmap_read_poll_timeout(scpsys->base, pd->data->ctl_offs, tmp, in scpsys_sram_enable()
88 if (MTK_SCPD_CAPS(pd, MTK_SCPD_SRAM_ISO)) { in scpsys_sram_enable()
89 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_ISOINT_B_BIT); in scpsys_sram_enable()
91 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_CLKISO_BIT); in scpsys_sram_enable()
97 static int scpsys_sram_disable(struct scpsys_domain *pd) in scpsys_sram_disable() argument
99 u32 pdn_ack = pd->data->sram_pdn_ack_bits; in scpsys_sram_disable()
100 struct scpsys *scpsys = pd->scpsys; in scpsys_sram_disable()
103 if (MTK_SCPD_CAPS(pd, MTK_SCPD_SRAM_ISO)) { in scpsys_sram_disable()
104 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_CLKISO_BIT); in scpsys_sram_disable()
106 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_SRAM_ISOINT_B_BIT); in scpsys_sram_disable()
109 regmap_set_bits(scpsys->base, pd->data->ctl_offs, pd->data->sram_pdn_bits); in scpsys_sram_disable()
112 return regmap_read_poll_timeout(scpsys->base, pd->data->ctl_offs, tmp, in scpsys_sram_disable()
142 static int scpsys_bus_protect_enable(struct scpsys_domain *pd) in scpsys_bus_protect_enable() argument
146 ret = _scpsys_bus_protect_enable(pd->data->bp_infracfg, pd->infracfg); in scpsys_bus_protect_enable()
150 return _scpsys_bus_protect_enable(pd->data->bp_smi, pd->smi); in scpsys_bus_protect_enable()
182 static int scpsys_bus_protect_disable(struct scpsys_domain *pd) in scpsys_bus_protect_disable() argument
186 ret = _scpsys_bus_protect_disable(pd->data->bp_smi, pd->smi); in scpsys_bus_protect_disable()
190 return _scpsys_bus_protect_disable(pd->data->bp_infracfg, pd->infracfg); in scpsys_bus_protect_disable()
205 struct scpsys_domain *pd = container_of(genpd, struct scpsys_domain, genpd); in scpsys_power_on() local
206 struct scpsys *scpsys = pd->scpsys; in scpsys_power_on()
210 ret = scpsys_regulator_enable(pd->supply); in scpsys_power_on()
214 ret = clk_bulk_prepare_enable(pd->num_clks, pd->clks); in scpsys_power_on()
219 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_BIT); in scpsys_power_on()
220 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_2ND_BIT); in scpsys_power_on()
223 ret = readx_poll_timeout(scpsys_domain_is_on, pd, tmp, tmp, MTK_POLL_DELAY_US, in scpsys_power_on()
228 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_CLK_DIS_BIT); in scpsys_power_on()
229 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ISO_BIT); in scpsys_power_on()
230 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT); in scpsys_power_on()
232 ret = clk_bulk_prepare_enable(pd->num_subsys_clks, pd->subsys_clks); in scpsys_power_on()
236 ret = scpsys_sram_enable(pd); in scpsys_power_on()
240 ret = scpsys_bus_protect_disable(pd); in scpsys_power_on()
247 scpsys_sram_disable(pd); in scpsys_power_on()
249 clk_bulk_disable_unprepare(pd->num_subsys_clks, pd->subsys_clks); in scpsys_power_on()
251 clk_bulk_disable_unprepare(pd->num_clks, pd->clks); in scpsys_power_on()
253 scpsys_regulator_disable(pd->supply); in scpsys_power_on()
259 struct scpsys_domain *pd = container_of(genpd, struct scpsys_domain, genpd); in scpsys_power_off() local
260 struct scpsys *scpsys = pd->scpsys; in scpsys_power_off()
264 ret = scpsys_bus_protect_enable(pd); in scpsys_power_off()
268 ret = scpsys_sram_disable(pd); in scpsys_power_off()
272 clk_bulk_disable_unprepare(pd->num_subsys_clks, pd->subsys_clks); in scpsys_power_off()
275 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT); in scpsys_power_off()
276 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ISO_BIT); in scpsys_power_off()
277 regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_CLK_DIS_BIT); in scpsys_power_off()
278 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_2ND_BIT); in scpsys_power_off()
279 regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_BIT); in scpsys_power_off()
282 ret = readx_poll_timeout(scpsys_domain_is_on, pd, tmp, !tmp, MTK_POLL_DELAY_US, in scpsys_power_off()
287 clk_bulk_disable_unprepare(pd->num_clks, pd->clks); in scpsys_power_off()
289 scpsys_regulator_disable(pd->supply); in scpsys_power_off()
298 struct scpsys_domain *pd; in scpsys_add_one_domain() local
326 pd = devm_kzalloc(scpsys->dev, sizeof(*pd), GFP_KERNEL); in scpsys_add_one_domain()
327 if (!pd) in scpsys_add_one_domain()
330 pd->data = domain_data; in scpsys_add_one_domain()
331 pd->scpsys = scpsys; in scpsys_add_one_domain()
333 if (MTK_SCPD_CAPS(pd, MTK_SCPD_DOMAIN_SUPPLY)) { in scpsys_add_one_domain()
342 pd->supply = devm_regulator_get(scpsys->dev, "domain"); in scpsys_add_one_domain()
344 if (IS_ERR(pd->supply)) { in scpsys_add_one_domain()
345 dev_err_probe(scpsys->dev, PTR_ERR(pd->supply), in scpsys_add_one_domain()
348 return ERR_CAST(pd->supply); in scpsys_add_one_domain()
352 pd->infracfg = syscon_regmap_lookup_by_phandle_optional(node, "mediatek,infracfg"); in scpsys_add_one_domain()
353 if (IS_ERR(pd->infracfg)) in scpsys_add_one_domain()
354 return ERR_CAST(pd->infracfg); in scpsys_add_one_domain()
358 pd->smi = device_node_to_regmap(smi_node); in scpsys_add_one_domain()
360 if (IS_ERR(pd->smi)) in scpsys_add_one_domain()
361 return ERR_CAST(pd->smi); in scpsys_add_one_domain()
372 pd->num_subsys_clks++; in scpsys_add_one_domain()
374 pd->num_clks++; in scpsys_add_one_domain()
377 pd->clks = devm_kcalloc(scpsys->dev, pd->num_clks, sizeof(*pd->clks), GFP_KERNEL); in scpsys_add_one_domain()
378 if (!pd->clks) in scpsys_add_one_domain()
381 pd->subsys_clks = devm_kcalloc(scpsys->dev, pd->num_subsys_clks, in scpsys_add_one_domain()
382 sizeof(*pd->subsys_clks), GFP_KERNEL); in scpsys_add_one_domain()
383 if (!pd->subsys_clks) in scpsys_add_one_domain()
388 for (i = 0; i < pd->num_clks; i++) { in scpsys_add_one_domain()
397 pd->clks[clk_ind++].clk = clk; in scpsys_add_one_domain()
400 for (i = 0; i < pd->num_subsys_clks; i++) { in scpsys_add_one_domain()
410 pd->subsys_clks[i].clk = clk; in scpsys_add_one_domain()
419 if (MTK_SCPD_CAPS(pd, MTK_SCPD_KEEP_DEFAULT_OFF)) { in scpsys_add_one_domain()
420 if (scpsys_domain_is_on(pd)) in scpsys_add_one_domain()
424 ret = scpsys_power_on(&pd->genpd); in scpsys_add_one_domain()
438 if (!pd->data->name) in scpsys_add_one_domain()
439 pd->genpd.name = node->name; in scpsys_add_one_domain()
441 pd->genpd.name = pd->data->name; in scpsys_add_one_domain()
443 pd->genpd.power_off = scpsys_power_off; in scpsys_add_one_domain()
444 pd->genpd.power_on = scpsys_power_on; in scpsys_add_one_domain()
446 if (MTK_SCPD_CAPS(pd, MTK_SCPD_KEEP_DEFAULT_OFF)) in scpsys_add_one_domain()
447 pm_genpd_init(&pd->genpd, NULL, true); in scpsys_add_one_domain()
449 pm_genpd_init(&pd->genpd, NULL, false); in scpsys_add_one_domain()
451 scpsys->domains[id] = &pd->genpd; in scpsys_add_one_domain()
456 clk_bulk_put(pd->num_subsys_clks, pd->subsys_clks); in scpsys_add_one_domain()
458 clk_bulk_put(pd->num_clks, pd->clks); in scpsys_add_one_domain()
516 static void scpsys_remove_one_domain(struct scpsys_domain *pd) in scpsys_remove_one_domain() argument
520 if (scpsys_domain_is_on(pd)) in scpsys_remove_one_domain()
521 scpsys_power_off(&pd->genpd); in scpsys_remove_one_domain()
527 ret = pm_genpd_remove(&pd->genpd); in scpsys_remove_one_domain()
529 dev_err(pd->scpsys->dev, in scpsys_remove_one_domain()
531 pd->genpd.name, ret); in scpsys_remove_one_domain()
533 clk_bulk_put(pd->num_clks, pd->clks); in scpsys_remove_one_domain()
534 clk_bulk_put(pd->num_subsys_clks, pd->subsys_clks); in scpsys_remove_one_domain()
540 struct scpsys_domain *pd; in scpsys_domain_cleanup() local
546 pd = to_scpsys_domain(genpd); in scpsys_domain_cleanup()
547 scpsys_remove_one_domain(pd); in scpsys_domain_cleanup()