Lines Matching +full:irq +full:- +full:can +full:- +full:wake

1 // SPDX-License-Identifier: GPL-2.0
5 #include <linux/irq.h>
13 * dev_pm_attach_wake_irq - Attach device interrupt as a wake IRQ
15 * @wirq: Wake irq specific data
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()
28 "wake irq already initialized\n")) { 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
43 * @irq: Device IO interrupt
45 * Attach a device IO interrupt as a wake IRQ. The wake IRQ gets
46 * automatically configured for wake-up from suspend based
50 int dev_pm_set_wake_irq(struct device *dev, int irq) in dev_pm_set_wake_irq() argument
55 if (irq < 0) in dev_pm_set_wake_irq()
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
77 * Detach a device wake IRQ and free resources.
81 * a wake IRQ configured. This avoid adding wake IRQ specific
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
109 * @_wirq: Wake IRQ data
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
114 * specific pm_runtime functions to wake the device, and then it's
117 * use a threaded IRQ.
120 * We assume that the wake-up interrupt just needs to wake-up the
121 * device, and then device's pm_runtime_resume() can deal with the
124 static irqreturn_t handle_threaded_wake_irq(int irq, void *_wirq) in handle_threaded_wake_irq() argument
130 if (irqd_is_wakeup_set(irq_get_irq_data(irq))) { in handle_threaded_wake_irq()
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()
140 "wake IRQ with no resume: %i\n", res); in handle_threaded_wake_irq()
145 static int __dev_pm_set_dedicated_wake_irq(struct device *dev, int irq, unsigned int flag) in __dev_pm_set_dedicated_wake_irq() argument
150 if (irq < 0) in __dev_pm_set_dedicated_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()
167 irq_set_status_flags(irq, IRQ_DISABLE_UNLAZY); in __dev_pm_set_dedicated_wake_irq()
171 * so we use a threaded irq. in __dev_pm_set_dedicated_wake_irq()
173 err = request_threaded_irq(irq, NULL, handle_threaded_wake_irq, 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()
188 free_irq(irq, wirq); in __dev_pm_set_dedicated_wake_irq()
190 kfree(wirq->name); in __dev_pm_set_dedicated_wake_irq()
198 * dev_pm_set_dedicated_wake_irq - Request a dedicated wake-up interrupt
200 * @irq: Device wake-up interrupt
202 * Unless your hardware has separate wake-up interrupts in addition
206 * a dedicated wake-up interrupt in addition to the device IO
209 int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq) in dev_pm_set_dedicated_wake_irq() argument
211 return __dev_pm_set_dedicated_wake_irq(dev, irq, 0); in dev_pm_set_dedicated_wake_irq()
216 * dev_pm_set_dedicated_wake_irq_reverse - Request a dedicated wake-up interrupt
219 * @irq: Device wake-up interrupt
221 * Unless your hardware has separate wake-up interrupts in addition
225 * wake-up interrupt in addition to the device IO interrupt. It sets
227 * to enable dedicated wake-up interrupt after running the runtime suspend
230 int dev_pm_set_dedicated_wake_irq_reverse(struct device *dev, int irq) in dev_pm_set_dedicated_wake_irq_reverse() argument
232 return __dev_pm_set_dedicated_wake_irq(dev, irq, WAKE_IRQ_DEDICATED_REVERSE); in dev_pm_set_dedicated_wake_irq_reverse()
237 * dev_pm_enable_wake_irq_check - Checks and enables wake-up interrupt
239 * @can_change_status: Can change wake-up interrupt status
241 * Enables wakeirq conditionally. We need to enable wake-up interrupt
244 * otherwise try to disable already disabled wakeirq. The wake-up interrupt
248 * Caller must hold &dev->power.lock to change wirq->status
253 struct wake_irq *wirq = dev->power.wakeirq; in dev_pm_enable_wake_irq_check()
255 if (!wirq || !(wirq->status & WAKE_IRQ_DEDICATED_MASK)) in dev_pm_enable_wake_irq_check()
258 if (likely(wirq->status & WAKE_IRQ_DEDICATED_MANAGED)) { in dev_pm_enable_wake_irq_check()
261 wirq->status |= WAKE_IRQ_DEDICATED_MANAGED; in dev_pm_enable_wake_irq_check()
268 if (!can_change_status || !(wirq->status & WAKE_IRQ_DEDICATED_REVERSE)) { in dev_pm_enable_wake_irq_check()
269 enable_irq(wirq->irq); in dev_pm_enable_wake_irq_check()
270 wirq->status |= WAKE_IRQ_DEDICATED_ENABLED; in dev_pm_enable_wake_irq_check()
275 * dev_pm_disable_wake_irq_check - Checks and disables wake-up interrupt
279 * Disables wake-up interrupt conditionally based on status.
284 struct wake_irq *wirq = dev->power.wakeirq; in dev_pm_disable_wake_irq_check()
286 if (!wirq || !(wirq->status & WAKE_IRQ_DEDICATED_MASK)) in dev_pm_disable_wake_irq_check()
289 if (cond_disable && (wirq->status & WAKE_IRQ_DEDICATED_REVERSE)) in dev_pm_disable_wake_irq_check()
292 if (wirq->status & WAKE_IRQ_DEDICATED_MANAGED) { in dev_pm_disable_wake_irq_check()
293 wirq->status &= ~WAKE_IRQ_DEDICATED_ENABLED; in dev_pm_disable_wake_irq_check()
294 disable_irq_nosync(wirq->irq); in dev_pm_disable_wake_irq_check()
299 * dev_pm_enable_wake_irq_complete - enable wake IRQ not enabled before
300 * @dev: Device using the wake IRQ
302 * Enable wake IRQ conditionally based on status, mainly used if want to
303 * enable wake IRQ after running ->runtime_suspend() which depends on
310 struct wake_irq *wirq = dev->power.wakeirq; in dev_pm_enable_wake_irq_complete()
312 if (!wirq || !(wirq->status & WAKE_IRQ_DEDICATED_MASK)) in dev_pm_enable_wake_irq_complete()
315 if (wirq->status & WAKE_IRQ_DEDICATED_MANAGED && in dev_pm_enable_wake_irq_complete()
316 wirq->status & WAKE_IRQ_DEDICATED_REVERSE) in dev_pm_enable_wake_irq_complete()
317 enable_irq(wirq->irq); in dev_pm_enable_wake_irq_complete()
321 * dev_pm_arm_wake_irq - Arm device wake-up
322 * @wirq: Device wake-up interrupt
324 * Sets up the wake-up event conditionally based on the
332 if (device_may_wakeup(wirq->dev)) { in dev_pm_arm_wake_irq()
333 if (wirq->status & WAKE_IRQ_DEDICATED_ALLOCATED && in dev_pm_arm_wake_irq()
334 !(wirq->status & WAKE_IRQ_DEDICATED_ENABLED)) in dev_pm_arm_wake_irq()
335 enable_irq(wirq->irq); in dev_pm_arm_wake_irq()
337 enable_irq_wake(wirq->irq); in dev_pm_arm_wake_irq()
342 * dev_pm_disarm_wake_irq - Disarm device wake-up
343 * @wirq: Device wake-up interrupt
345 * Clears up the wake-up event conditionally based on the
353 if (device_may_wakeup(wirq->dev)) { in dev_pm_disarm_wake_irq()
354 disable_irq_wake(wirq->irq); in dev_pm_disarm_wake_irq()
356 if (wirq->status & WAKE_IRQ_DEDICATED_ALLOCATED && in dev_pm_disarm_wake_irq()
357 !(wirq->status & WAKE_IRQ_DEDICATED_ENABLED)) in dev_pm_disarm_wake_irq()
358 disable_irq_nosync(wirq->irq); in dev_pm_disarm_wake_irq()