Dirk Brandewie | 002c53b | 2015-09-29 08:42:22 -0700 | [diff] [blame] | 1 | /* shared_irq - Shared interrupt driver */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (c) 2015 Intel corporation |
| 5 | * |
David B. Kinder | ac74d8b | 2017-01-18 17:01:01 -0800 | [diff] [blame] | 6 | * SPDX-License-Identifier: Apache-2.0 |
Dirk Brandewie | 002c53b | 2015-09-29 08:42:22 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _SHIRQ_H_ |
| 10 | #define _SHIRQ_H_ |
| 11 | |
| 12 | #include <autoconf.h> |
| 13 | |
Peter Mitsis | a0e4568 | 2016-01-22 12:38:49 -0500 | [diff] [blame] | 14 | #ifdef __cplusplus |
| 15 | extern "C" { |
| 16 | #endif |
| 17 | |
Dirk Brandewie | 002c53b | 2015-09-29 08:42:22 -0700 | [diff] [blame] | 18 | typedef int (*isr_t)(struct device *dev); |
| 19 | |
| 20 | /* driver API definition */ |
| 21 | typedef int (*shared_irq_register_t)(struct device *dev, |
| 22 | isr_t isr_func, |
| 23 | struct device *isr_dev); |
| 24 | typedef int (*shared_irq_enable_t)(struct device *dev, struct device *isr_dev); |
| 25 | typedef int (*shared_irq_disable_t)(struct device *dev, struct device *isr_dev); |
| 26 | |
| 27 | struct shared_irq_driver_api { |
| 28 | shared_irq_register_t isr_register; |
| 29 | shared_irq_enable_t enable; |
| 30 | shared_irq_disable_t disable; |
| 31 | }; |
| 32 | |
| 33 | extern int shared_irq_initialize(struct device *port); |
| 34 | |
Andrew Boie | d9cfbd5 | 2016-01-08 00:46:14 -0800 | [diff] [blame] | 35 | typedef void (*shared_irq_config_irq_t)(void); |
Dirk Brandewie | 002c53b | 2015-09-29 08:42:22 -0700 | [diff] [blame] | 36 | |
| 37 | struct shared_irq_config { |
| 38 | uint32_t irq_num; |
| 39 | shared_irq_config_irq_t config; |
| 40 | uint32_t client_count; |
| 41 | }; |
| 42 | |
| 43 | struct shared_irq_client { |
| 44 | struct device *isr_dev; |
| 45 | isr_t isr_func; |
| 46 | uint32_t enabled; |
| 47 | }; |
| 48 | |
| 49 | struct shared_irq_runtime { |
| 50 | struct shared_irq_client client[CONFIG_SHARED_IRQ_NUM_CLIENTS]; |
| 51 | }; |
| 52 | |
| 53 | /** |
| 54 | * @brief Register a device ISR |
| 55 | * @param dev Pointer to device structure for SHARED_IRQ driver instance. |
| 56 | * @param isr_func Pointer to the ISR function for the device. |
| 57 | * @param isr_dev Pointer to the device that will service the interrupt. |
| 58 | */ |
| 59 | static inline int shared_irq_isr_register(struct device *dev, isr_t isr_func, |
| 60 | struct device *isr_dev) |
| 61 | { |
Marcus Shawcroft | a45c3f8 | 2016-10-22 10:00:14 +0100 | [diff] [blame] | 62 | const struct shared_irq_driver_api *api = dev->driver_api; |
Dirk Brandewie | 002c53b | 2015-09-29 08:42:22 -0700 | [diff] [blame] | 63 | |
Dirk Brandewie | 002c53b | 2015-09-29 08:42:22 -0700 | [diff] [blame] | 64 | return api->isr_register(dev, isr_func, isr_dev); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @brief Enable ISR for device |
| 69 | * @param dev Pointer to device structure for SHARED_IRQ driver instance. |
| 70 | * @param isr_dev Pointer to the device that will service the interrupt. |
| 71 | */ |
| 72 | static inline int shared_irq_enable(struct device *dev, struct device *isr_dev) |
| 73 | { |
Marcus Shawcroft | a45c3f8 | 2016-10-22 10:00:14 +0100 | [diff] [blame] | 74 | const struct shared_irq_driver_api *api = dev->driver_api; |
Dirk Brandewie | 002c53b | 2015-09-29 08:42:22 -0700 | [diff] [blame] | 75 | |
Dirk Brandewie | 002c53b | 2015-09-29 08:42:22 -0700 | [diff] [blame] | 76 | return api->enable(dev, isr_dev); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @brief Disable ISR for device |
| 81 | * @param dev Pointer to device structure for SHARED_IRQ driver instance. |
| 82 | * @param isr_dev Pointer to the device that will service the interrupt. |
| 83 | */ |
| 84 | static inline int shared_irq_disable(struct device *dev, struct device *isr_dev) |
| 85 | { |
Marcus Shawcroft | a45c3f8 | 2016-10-22 10:00:14 +0100 | [diff] [blame] | 86 | const struct shared_irq_driver_api *api = dev->driver_api; |
Dirk Brandewie | 002c53b | 2015-09-29 08:42:22 -0700 | [diff] [blame] | 87 | |
Dirk Brandewie | 002c53b | 2015-09-29 08:42:22 -0700 | [diff] [blame] | 88 | return api->disable(dev, isr_dev); |
| 89 | } |
| 90 | |
Peter Mitsis | a0e4568 | 2016-01-22 12:38:49 -0500 | [diff] [blame] | 91 | #ifdef __cplusplus |
| 92 | } |
| 93 | #endif |
| 94 | |
Dirk Brandewie | 002c53b | 2015-09-29 08:42:22 -0700 | [diff] [blame] | 95 | #endif /* _SHARED_IRQ_H_ */ |