1 /* shared_irq - Shared interrupt driver */
2 
3 /*
4  * Copyright (c) 2015 - 2023 Intel corporation
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #ifndef ZEPHYR_INCLUDE_SHARED_IRQ_H_
10 #define ZEPHYR_INCLUDE_SHARED_IRQ_H_
11 
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 typedef int (*isr_t)(const struct device *dev, unsigned int irq_number);
18 
19 /* driver API definition */
20 typedef int (*shared_irq_register_t)(const struct device *dev,
21 				     isr_t isr_func,
22 				     const struct device *isr_dev);
23 typedef int (*shared_irq_enable_t)(const struct device *dev,
24 				   const struct device *isr_dev);
25 typedef int (*shared_irq_disable_t)(const struct device *dev,
26 				    const struct device *isr_dev);
27 
28 struct shared_irq_driver_api {
29 	shared_irq_register_t isr_register;
30 	shared_irq_enable_t enable;
31 	shared_irq_disable_t disable;
32 };
33 
34 /**
35  *  @brief Register a device ISR
36  *  @param dev Pointer to device structure for SHARED_IRQ driver instance.
37  *  @param isr_func Pointer to the ISR function for the device.
38  *  @param isr_dev Pointer to the device that will service the interrupt.
39  */
shared_irq_isr_register(const struct device * dev,isr_t isr_func,const struct device * isr_dev)40 static inline int shared_irq_isr_register(const struct device *dev,
41 					  isr_t isr_func,
42 					  const struct device *isr_dev)
43 {
44 	const struct shared_irq_driver_api *api =
45 		(const struct shared_irq_driver_api *)dev->api;
46 
47 	return api->isr_register(dev, isr_func, isr_dev);
48 }
49 
50 /**
51  *  @brief Enable ISR for device
52  *  @param dev Pointer to device structure for SHARED_IRQ driver instance.
53  *  @param isr_dev Pointer to the device that will service the interrupt.
54  */
shared_irq_enable(const struct device * dev,const struct device * isr_dev)55 static inline int shared_irq_enable(const struct device *dev,
56 				    const struct device *isr_dev)
57 {
58 	const struct shared_irq_driver_api *api =
59 		(const struct shared_irq_driver_api *)dev->api;
60 
61 	return api->enable(dev, isr_dev);
62 }
63 
64 /**
65  *  @brief Disable ISR for device
66  *  @param dev Pointer to device structure for SHARED_IRQ driver instance.
67  *  @param isr_dev Pointer to the device that will service the interrupt.
68  */
shared_irq_disable(const struct device * dev,const struct device * isr_dev)69 static inline int shared_irq_disable(const struct device *dev,
70 				     const struct device *isr_dev)
71 {
72 	const struct shared_irq_driver_api *api =
73 		(const struct shared_irq_driver_api *)dev->api;
74 
75 	return api->disable(dev, isr_dev);
76 }
77 
78 #ifdef __cplusplus
79 }
80 #endif
81 
82 #endif /* ZEPHYR_INCLUDE_SHARED_IRQ_H_ */
83