blob: e8ae0080f2506aed5cc3fe7e79f5dcfb79d62289 [file] [log] [blame]
Dirk Brandewie002c53b2015-09-29 08:42:22 -07001/* shared_irq - Shared interrupt driver */
2
3/*
4 * Copyright (c) 2015 Intel corporation
5 *
David B. Kinderac74d8b2017-01-18 17:01:01 -08006 * SPDX-License-Identifier: Apache-2.0
Dirk Brandewie002c53b2015-09-29 08:42:22 -07007 */
8
9#ifndef _SHIRQ_H_
10#define _SHIRQ_H_
11
12#include <autoconf.h>
13
Peter Mitsisa0e45682016-01-22 12:38:49 -050014#ifdef __cplusplus
15extern "C" {
16#endif
17
Dirk Brandewie002c53b2015-09-29 08:42:22 -070018typedef int (*isr_t)(struct device *dev);
19
20/* driver API definition */
21typedef int (*shared_irq_register_t)(struct device *dev,
22 isr_t isr_func,
23 struct device *isr_dev);
24typedef int (*shared_irq_enable_t)(struct device *dev, struct device *isr_dev);
25typedef int (*shared_irq_disable_t)(struct device *dev, struct device *isr_dev);
26
27struct 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
33extern int shared_irq_initialize(struct device *port);
34
Andrew Boied9cfbd52016-01-08 00:46:14 -080035typedef void (*shared_irq_config_irq_t)(void);
Dirk Brandewie002c53b2015-09-29 08:42:22 -070036
37struct shared_irq_config {
38 uint32_t irq_num;
39 shared_irq_config_irq_t config;
40 uint32_t client_count;
41};
42
43struct shared_irq_client {
44 struct device *isr_dev;
45 isr_t isr_func;
46 uint32_t enabled;
47};
48
49struct 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 */
59static inline int shared_irq_isr_register(struct device *dev, isr_t isr_func,
60 struct device *isr_dev)
61{
Marcus Shawcrofta45c3f82016-10-22 10:00:14 +010062 const struct shared_irq_driver_api *api = dev->driver_api;
Dirk Brandewie002c53b2015-09-29 08:42:22 -070063
Dirk Brandewie002c53b2015-09-29 08:42:22 -070064 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 */
72static inline int shared_irq_enable(struct device *dev, struct device *isr_dev)
73{
Marcus Shawcrofta45c3f82016-10-22 10:00:14 +010074 const struct shared_irq_driver_api *api = dev->driver_api;
Dirk Brandewie002c53b2015-09-29 08:42:22 -070075
Dirk Brandewie002c53b2015-09-29 08:42:22 -070076 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 */
84static inline int shared_irq_disable(struct device *dev, struct device *isr_dev)
85{
Marcus Shawcrofta45c3f82016-10-22 10:00:14 +010086 const struct shared_irq_driver_api *api = dev->driver_api;
Dirk Brandewie002c53b2015-09-29 08:42:22 -070087
Dirk Brandewie002c53b2015-09-29 08:42:22 -070088 return api->disable(dev, isr_dev);
89}
90
Peter Mitsisa0e45682016-01-22 12:38:49 -050091#ifdef __cplusplus
92}
93#endif
94
Dirk Brandewie002c53b2015-09-29 08:42:22 -070095#endif /* _SHARED_IRQ_H_ */