1 /*
2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #ifndef __OAL_INTERRUPT_H__
20 #define __OAL_INTERRUPT_H__
21
22 /* ****************************************************************************
23 1 其他头文件包含
24 **************************************************************************** */
25 #include <linux/interrupt.h>
26 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
27 #include <asm/hal_platform_ints.h>
28 #include "gpio_if.h"
29 #endif
30 #include "hdf_wifi_config.h"
31
32 #ifdef __cplusplus
33 #if __cplusplus
34 extern "C" {
35 #endif
36 #endif
37
38 /* ****************************************************************************
39 2 STRUCT定义
40 **************************************************************************** */
41 typedef void (*irq_func)(unsigned int irq, void *data);
42
43 typedef struct {
44 unsigned int groupnumber;
45 unsigned int bitnumber;
46
47 unsigned char value;
48 #define GPIO_VALUE_HIGH 1
49 #define GPIO_VALUE_LOW 0
50 unsigned char direction;
51 #define GPIO_DIR_IN 0
52 #define GPIO_DIR_OUT 1
53
54 unsigned char irq_status;
55 unsigned char irq_enable;
56 #define GPIO_IRQ_ENABLE 1
57 #define GPIO_IRQ_DISABLE 0
58 irq_func irq_handler;
59 unsigned int irq_type;
60 #define IRQ_TYPE_NONE 0x00000000
61 #define IRQ_TYPE_EDGE_RISING 0x00000001
62 #define IRQ_TYPE_EDGE_FALLING 0x00000002
63 #define IRQ_TYPE_EDGE_BOTH (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)
64 #define IRQ_TYPE_LEVEL_HIGH 0x00000004
65 #define IRQ_TYPE_LEVEL_LOW 0x00000008
66 #define IRQ_TYPE_LEVEL_MASK (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)
67 void *data;
68 } gpio_groupbit_info;
69
70 /* ****************************************************************************
71 3 枚举定义
72 **************************************************************************** */
73 /* ****************************************************************************
74 4 全局变量声明
75 **************************************************************************** */
76 /* ****************************************************************************
77 5 消息头定义
78 **************************************************************************** */
79 /* ****************************************************************************
80 6 消息定义
81 **************************************************************************** */
82 /* ****************************************************************************
83 7 宏定义
84 **************************************************************************** */
85 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
86 #ifndef IRQF_NO_SUSPEND
87 #define IRQF_NO_SUSPEND 0x0000
88 #endif
89
90 #ifndef IRQF_DISABLED
91 #define IRQF_DISABLED 0x0000
92 #endif
93
94 static uint8_t wifi_get_gpio_bit_num(void);
95
96 #define GPIO_TO_IRQ(group, bit) ((group) * (wifi_get_gpio_bit_num()) + (bit) + (OS_USER_HWI_MAX))
97 #define IRQ_TO_GPIO_GROUP(irq) (((irq) - (OS_USER_HWI_MAX)) / (wifi_get_gpio_bit_num()))
98 #define IRQ_TO_GPIO_BIT(irq) (((irq) - (OS_USER_HWI_MAX)) % (wifi_get_gpio_bit_num()))
99 #endif
100
101 /* ****************************************************************************
102 8 UNION定义
103 **************************************************************************** */
104 /* ****************************************************************************
105 9 OTHERS定义
106 **************************************************************************** */
107 /* ****************************************************************************
108 10 函数声明
109 **************************************************************************** */
wifi_get_gpio_bit_num(void)110 static uint8_t wifi_get_gpio_bit_num(void)
111 {
112 const struct HdfConfigWifiRoot *rootConfig = HdfWifiGetModuleConfigRoot();
113
114 return rootConfig->wifiConfig.board.gpioArgs[1];
115 }
116
oal_request_irq(hi_u32 irq,irq_handler_t handler,unsigned long flags,const hi_char * name,hi_void * dev)117 static inline hi_s32 oal_request_irq(hi_u32 irq, irq_handler_t handler, unsigned long flags, const hi_char *name,
118 hi_void *dev)
119 {
120 uint16_t gpio;
121 uint8_t gpio_bit_num;
122
123 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
124 return request_irq(irq, handler, flags, name, dev);
125 #elif (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
126 if (irq <= OS_USER_HWI_MAX) {
127 return request_irq(irq, handler, flags, name, dev);
128 } else {
129 gpio_groupbit_info st_gpio_info = {0};
130 st_gpio_info.groupnumber = IRQ_TO_GPIO_GROUP(irq);
131 st_gpio_info.bitnumber = IRQ_TO_GPIO_BIT(irq);
132 st_gpio_info.irq_handler = (irq_func)handler;
133 st_gpio_info.irq_type = 0;
134 st_gpio_info.data = dev;
135
136 gpio_bit_num = wifi_get_gpio_bit_num();
137 gpio = st_gpio_info.groupnumber * gpio_bit_num + st_gpio_info.bitnumber;
138 return GpioSetIrq(gpio, st_gpio_info.irq_type, (GpioIrqFunc)st_gpio_info.irq_handler, st_gpio_info.data);
139 }
140 #endif
141 }
142
oal_free_irq(hi_u32 irq,hi_void * dev)143 static inline hi_void oal_free_irq(hi_u32 irq, hi_void *dev)
144 {
145 free_irq(irq, dev);
146 }
147
oal_enable_irq(hi_u32 irq)148 static inline hi_void oal_enable_irq(hi_u32 irq)
149 {
150 enable_irq(irq);
151 }
152
oal_disable_irq(hi_u32 irq)153 static inline hi_void oal_disable_irq(hi_u32 irq)
154 {
155 disable_irq(irq);
156 }
157
oal_disable_irq_nosync(hi_u32 irq)158 static inline hi_void oal_disable_irq_nosync(hi_u32 irq)
159 {
160 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
161 disable_irq_nosync(irq);
162 #elif (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
163 disable_irq(irq);
164 #endif
165 }
166
167 #ifdef __cplusplus
168 #if __cplusplus
169 }
170 #endif
171 #endif
172
173 #endif /* end of oal_completion.h */
174