Lines Matching +full:pmgr +full:- +full:pwrstate
1 // SPDX-License-Identifier: GPL-2.0-only OR MIT
3 * Apple SoC PMGR device power state driver
17 #include <linux/reset-controller.h>
58 ret = regmap_read(ps->regmap, ps->offset, ®); in apple_pmgr_ps_set()
64 dev_err(ps->dev, "PS %s: powering off with RESET active\n", in apple_pmgr_ps_set()
65 genpd->name); in apple_pmgr_ps_set()
70 dev_dbg(ps->dev, "PS %s: pwrstate = 0x%x: 0x%x\n", genpd->name, pstate, reg); in apple_pmgr_ps_set()
72 regmap_write(ps->regmap, ps->offset, reg); in apple_pmgr_ps_set()
75 ps->regmap, ps->offset, reg, in apple_pmgr_ps_set()
79 dev_err(ps->dev, "PS %s: Failed to reach power state 0x%x (now: 0x%x)\n", in apple_pmgr_ps_set()
80 genpd->name, pstate, reg); in apple_pmgr_ps_set()
83 /* Not all devices implement this; this is a no-op where not implemented. */ in apple_pmgr_ps_set()
86 regmap_write(ps->regmap, ps->offset, reg); in apple_pmgr_ps_set()
96 regmap_read(ps->regmap, ps->offset, ®); in apple_pmgr_ps_is_active()
98 * We consider domains as active if they are actually on, or if they have auto-PM in apple_pmgr_ps_is_active()
120 mutex_lock(&ps->genpd.mlock); in apple_pmgr_reset_assert()
122 if (ps->genpd.status == GENPD_STATE_OFF) in apple_pmgr_reset_assert()
123 dev_err(ps->dev, "PS 0x%x: asserting RESET while powered down\n", ps->offset); in apple_pmgr_reset_assert()
125 dev_dbg(ps->dev, "PS 0x%x: assert reset\n", ps->offset); in apple_pmgr_reset_assert()
127 regmap_update_bits(ps->regmap, ps->offset, APPLE_PMGR_FLAGS | APPLE_PMGR_DEV_DISABLE, in apple_pmgr_reset_assert()
129 regmap_update_bits(ps->regmap, ps->offset, APPLE_PMGR_FLAGS | APPLE_PMGR_RESET, in apple_pmgr_reset_assert()
132 mutex_unlock(&ps->genpd.mlock); in apple_pmgr_reset_assert()
141 mutex_lock(&ps->genpd.mlock); in apple_pmgr_reset_deassert()
143 dev_dbg(ps->dev, "PS 0x%x: deassert reset\n", ps->offset); in apple_pmgr_reset_deassert()
144 regmap_update_bits(ps->regmap, ps->offset, APPLE_PMGR_FLAGS | APPLE_PMGR_RESET, 0); in apple_pmgr_reset_deassert()
145 regmap_update_bits(ps->regmap, ps->offset, APPLE_PMGR_FLAGS | APPLE_PMGR_DEV_DISABLE, 0); in apple_pmgr_reset_deassert()
147 if (ps->genpd.status == GENPD_STATE_OFF) in apple_pmgr_reset_deassert()
148 dev_err(ps->dev, "PS 0x%x: RESET was deasserted while powered down\n", ps->offset); in apple_pmgr_reset_deassert()
150 mutex_unlock(&ps->genpd.mlock); in apple_pmgr_reset_deassert()
173 regmap_read(ps->regmap, ps->offset, ®); in apple_pmgr_reset_status()
193 struct device *dev = &pdev->dev; in apple_pmgr_ps_probe()
194 struct device_node *node = dev->of_node; in apple_pmgr_ps_probe()
202 regmap = syscon_node_to_regmap(node->parent); in apple_pmgr_ps_probe()
208 return -ENOMEM; in apple_pmgr_ps_probe()
210 ps->dev = dev; in apple_pmgr_ps_probe()
211 ps->regmap = regmap; in apple_pmgr_ps_probe()
219 ret = of_property_read_u32(node, "reg", &ps->offset); in apple_pmgr_ps_probe()
225 ps->genpd.name = name; in apple_pmgr_ps_probe()
226 ps->genpd.power_on = apple_pmgr_ps_power_on; in apple_pmgr_ps_probe()
227 ps->genpd.power_off = apple_pmgr_ps_power_off; in apple_pmgr_ps_probe()
229 ret = of_property_read_u32(node, "apple,min-state", &ps->min_state); in apple_pmgr_ps_probe()
230 if (ret == 0 && ps->min_state <= APPLE_PMGR_PS_ACTIVE) in apple_pmgr_ps_probe()
231 regmap_update_bits(regmap, ps->offset, APPLE_PMGR_FLAGS | APPLE_PMGR_PS_MIN, in apple_pmgr_ps_probe()
232 FIELD_PREP(APPLE_PMGR_PS_MIN, ps->min_state)); in apple_pmgr_ps_probe()
235 if (of_property_read_bool(node, "apple,always-on")) { in apple_pmgr_ps_probe()
236 ps->genpd.flags |= GENPD_FLAG_ALWAYS_ON; in apple_pmgr_ps_probe()
238 dev_warn(dev, "always-on domain %s is not on at boot\n", name); in apple_pmgr_ps_probe()
240 active = apple_pmgr_ps_power_on(&ps->genpd) == 0; in apple_pmgr_ps_probe()
244 /* Turn on auto-PM if the domain is already on */ in apple_pmgr_ps_probe()
246 regmap_update_bits(regmap, ps->offset, APPLE_PMGR_FLAGS | APPLE_PMGR_AUTO_ENABLE, in apple_pmgr_ps_probe()
249 ret = pm_genpd_init(&ps->genpd, NULL, !active); in apple_pmgr_ps_probe()
255 ret = of_genpd_add_provider_simple(node, &ps->genpd); in apple_pmgr_ps_probe()
261 of_for_each_phandle(&it, ret, node, "power-domains", "#power-domain-cells", -1) { in apple_pmgr_ps_probe()
270 if (ret == -EPROBE_DEFER) { in apple_pmgr_ps_probe()
274 dev_err(dev, "failed to add to parent domain: %d (%s -> %s)\n", in apple_pmgr_ps_probe()
275 ret, it.node->name, node->name); in apple_pmgr_ps_probe()
287 ps->rcdev.owner = THIS_MODULE; in apple_pmgr_ps_probe()
288 ps->rcdev.nr_resets = 1; in apple_pmgr_ps_probe()
289 ps->rcdev.ops = &apple_pmgr_reset_ops; in apple_pmgr_ps_probe()
290 ps->rcdev.of_node = dev->of_node; in apple_pmgr_ps_probe()
291 ps->rcdev.of_reset_n_cells = 0; in apple_pmgr_ps_probe()
292 ps->rcdev.of_xlate = apple_pmgr_reset_xlate; in apple_pmgr_ps_probe()
294 ret = devm_reset_controller_register(dev, &ps->rcdev); in apple_pmgr_ps_probe()
301 pm_genpd_remove(&ps->genpd); in apple_pmgr_ps_probe()
306 { .compatible = "apple,pmgr-pwrstate" },
315 .name = "apple-pmgr-pwrstate",
321 MODULE_DESCRIPTION("PMGR power state driver for Apple SoCs");