Lines Matching +full:power +full:- +full:up

1 // SPDX-License-Identifier: GPL-2.0
10 #include "power.h"
13 * dev_pm_attach_wake_irq - Attach device interrupt as a wake IRQ
17 * Internal function to attach a dedicated wake-up interrupt as a wake IRQ.
24 return -EINVAL; in dev_pm_attach_wake_irq()
26 spin_lock_irqsave(&dev->power.lock, flags); in dev_pm_attach_wake_irq()
27 if (dev_WARN_ONCE(dev, dev->power.wakeirq, in dev_pm_attach_wake_irq()
29 spin_unlock_irqrestore(&dev->power.lock, flags); in dev_pm_attach_wake_irq()
30 return -EEXIST; in dev_pm_attach_wake_irq()
33 dev->power.wakeirq = wirq; in dev_pm_attach_wake_irq()
36 spin_unlock_irqrestore(&dev->power.lock, flags); in dev_pm_attach_wake_irq()
41 * dev_pm_set_wake_irq - Attach device IO interrupt as wake IRQ
46 * automatically configured for wake-up from suspend based
56 return -EINVAL; in dev_pm_set_wake_irq()
60 return -ENOMEM; in dev_pm_set_wake_irq()
62 wirq->dev = dev; in dev_pm_set_wake_irq()
63 wirq->irq = irq; in dev_pm_set_wake_irq()
74 * dev_pm_clear_wake_irq - Detach a device IO interrupt wake IRQ
86 struct wake_irq *wirq = dev->power.wakeirq; in dev_pm_clear_wake_irq()
92 spin_lock_irqsave(&dev->power.lock, flags); in dev_pm_clear_wake_irq()
94 dev->power.wakeirq = NULL; in dev_pm_clear_wake_irq()
95 spin_unlock_irqrestore(&dev->power.lock, flags); in dev_pm_clear_wake_irq()
97 if (wirq->status & WAKE_IRQ_DEDICATED_ALLOCATED) { in dev_pm_clear_wake_irq()
98 free_irq(wirq->irq, wirq); in dev_pm_clear_wake_irq()
99 wirq->status &= ~WAKE_IRQ_DEDICATED_MASK; in dev_pm_clear_wake_irq()
101 kfree(wirq->name); in dev_pm_clear_wake_irq()
107 * handle_threaded_wake_irq - Handler for dedicated wake-up interrupts
108 * @irq: Device specific dedicated wake-up interrupt
111 * Some devices have a separate wake-up interrupt in addition to the
112 * device IO interrupt. The wake-up interrupt signals that a device
113 * should be woken up from it's idle state. This handler uses device
115 * up to the device to do whatever it needs to. Note that as the
116 * device may need to restore context and start up regulators, we
120 * We assume that the wake-up interrupt just needs to wake-up the
131 pm_wakeup_event(wirq->dev, 0); in handle_threaded_wake_irq()
137 res = pm_runtime_resume(wirq->dev); in handle_threaded_wake_irq()
139 dev_warn(wirq->dev, in handle_threaded_wake_irq()
151 return -EINVAL; in __dev_pm_set_dedicated_wake_irq()
155 return -ENOMEM; in __dev_pm_set_dedicated_wake_irq()
157 wirq->name = kasprintf(GFP_KERNEL, "%s:wakeup", dev_name(dev)); in __dev_pm_set_dedicated_wake_irq()
158 if (!wirq->name) { in __dev_pm_set_dedicated_wake_irq()
159 err = -ENOMEM; in __dev_pm_set_dedicated_wake_irq()
163 wirq->dev = dev; in __dev_pm_set_dedicated_wake_irq()
164 wirq->irq = irq; in __dev_pm_set_dedicated_wake_irq()
170 * Consumer device may need to power up and restore state in __dev_pm_set_dedicated_wake_irq()
175 wirq->name, wirq); in __dev_pm_set_dedicated_wake_irq()
183 wirq->status = WAKE_IRQ_DEDICATED_ALLOCATED | flag; in __dev_pm_set_dedicated_wake_irq()
190 kfree(wirq->name); in __dev_pm_set_dedicated_wake_irq()
199 * dev_pm_set_dedicated_wake_irq - Request a dedicated wake-up interrupt
201 * @irq: Device wake-up interrupt
203 * Unless your hardware has separate wake-up interrupts in addition
206 * Sets up a threaded interrupt handler for a device that has
207 * a dedicated wake-up interrupt in addition to the device IO
222 * dev_pm_set_dedicated_wake_irq_reverse - Request a dedicated wake-up interrupt
225 * @irq: Device wake-up interrupt
227 * Unless your hardware has separate wake-up interrupts in addition
230 * Sets up a threaded interrupt handler for a device that has a dedicated
231 * wake-up interrupt in addition to the device IO interrupt. It sets
233 * to enable dedicated wake-up interrupt after running the runtime suspend
248 * dev_pm_enable_wake_irq - Enable device wake-up interrupt
252 * runtime_resume() to override the PM runtime core managed wake-up
253 * interrupt handling to enable the wake-up interrupt.
255 * Note that for runtime_suspend()) the wake-up interrupts
261 struct wake_irq *wirq = dev->power.wakeirq; in dev_pm_enable_wake_irq()
263 if (wirq && (wirq->status & WAKE_IRQ_DEDICATED_ALLOCATED)) in dev_pm_enable_wake_irq()
264 enable_irq(wirq->irq); in dev_pm_enable_wake_irq()
269 * dev_pm_disable_wake_irq - Disable device wake-up interrupt
273 * runtime_suspend() to override the PM runtime core managed wake-up
274 * interrupt handling to disable the wake-up interrupt.
278 struct wake_irq *wirq = dev->power.wakeirq; in dev_pm_disable_wake_irq()
280 if (wirq && (wirq->status & WAKE_IRQ_DEDICATED_ALLOCATED)) in dev_pm_disable_wake_irq()
281 disable_irq_nosync(wirq->irq); in dev_pm_disable_wake_irq()
286 * dev_pm_enable_wake_irq_check - Checks and enables wake-up interrupt
288 * @can_change_status: Can change wake-up interrupt status
290 * Enables wakeirq conditionally. We need to enable wake-up interrupt
293 * otherwise try to disable already disabled wakeirq. The wake-up interrupt
297 * Caller must hold &dev->power.lock to change wirq->status
302 struct wake_irq *wirq = dev->power.wakeirq; in dev_pm_enable_wake_irq_check()
304 if (!wirq || !(wirq->status & WAKE_IRQ_DEDICATED_MASK)) in dev_pm_enable_wake_irq_check()
307 if (likely(wirq->status & WAKE_IRQ_DEDICATED_MANAGED)) { in dev_pm_enable_wake_irq_check()
310 wirq->status |= WAKE_IRQ_DEDICATED_MANAGED; in dev_pm_enable_wake_irq_check()
317 if (!can_change_status || !(wirq->status & WAKE_IRQ_DEDICATED_REVERSE)) in dev_pm_enable_wake_irq_check()
318 enable_irq(wirq->irq); in dev_pm_enable_wake_irq_check()
322 * dev_pm_disable_wake_irq_check - Checks and disables wake-up interrupt
326 * Disables wake-up interrupt conditionally based on status.
331 struct wake_irq *wirq = dev->power.wakeirq; in dev_pm_disable_wake_irq_check()
333 if (!wirq || !(wirq->status & WAKE_IRQ_DEDICATED_MASK)) in dev_pm_disable_wake_irq_check()
336 if (cond_disable && (wirq->status & WAKE_IRQ_DEDICATED_REVERSE)) in dev_pm_disable_wake_irq_check()
339 if (wirq->status & WAKE_IRQ_DEDICATED_MANAGED) in dev_pm_disable_wake_irq_check()
340 disable_irq_nosync(wirq->irq); in dev_pm_disable_wake_irq_check()
344 * dev_pm_enable_wake_irq_complete - enable wake IRQ not enabled before
348 * enable wake IRQ after running ->runtime_suspend() which depends on
355 struct wake_irq *wirq = dev->power.wakeirq; in dev_pm_enable_wake_irq_complete()
357 if (!wirq || !(wirq->status & WAKE_IRQ_DEDICATED_MASK)) in dev_pm_enable_wake_irq_complete()
360 if (wirq->status & WAKE_IRQ_DEDICATED_MANAGED && in dev_pm_enable_wake_irq_complete()
361 wirq->status & WAKE_IRQ_DEDICATED_REVERSE) in dev_pm_enable_wake_irq_complete()
362 enable_irq(wirq->irq); in dev_pm_enable_wake_irq_complete()
366 * dev_pm_arm_wake_irq - Arm device wake-up
367 * @wirq: Device wake-up interrupt
369 * Sets up the wake-up event conditionally based on the
377 if (device_may_wakeup(wirq->dev)) { in dev_pm_arm_wake_irq()
378 if (wirq->status & WAKE_IRQ_DEDICATED_ALLOCATED && in dev_pm_arm_wake_irq()
379 !pm_runtime_status_suspended(wirq->dev)) in dev_pm_arm_wake_irq()
380 enable_irq(wirq->irq); in dev_pm_arm_wake_irq()
382 enable_irq_wake(wirq->irq); in dev_pm_arm_wake_irq()
387 * dev_pm_disarm_wake_irq - Disarm device wake-up
388 * @wirq: Device wake-up interrupt
390 * Clears up the wake-up event conditionally based on the
398 if (device_may_wakeup(wirq->dev)) { in dev_pm_disarm_wake_irq()
399 disable_irq_wake(wirq->irq); in dev_pm_disarm_wake_irq()
401 if (wirq->status & WAKE_IRQ_DEDICATED_ALLOCATED && in dev_pm_disarm_wake_irq()
402 !pm_runtime_status_suspended(wirq->dev)) in dev_pm_disarm_wake_irq()
403 disable_irq_nosync(wirq->irq); in dev_pm_disarm_wake_irq()