summaryrefslogtreecommitdiff
path: root/bsp/synopsys/emsk_em9d/drivers/dw_gpio_obj.c
blob: 8701a0e9c76bfb668981469c08fb77d4dc78d411 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*
 * Copyright (c) 2018, Synopsys, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */
#include "inc/arc/arc.h"
#include "inc/arc/arc_builtin.h"

#include "dw_gpio_obj.h"

#include "emsk_hardware.h"
/*
 * Uncomment this to enable default
 * gpio bit handler output message
 * by uart
 */

#ifdef ARC_FEATURE_DMP_PERIPHERAL
#define PERIPHERAL_BASE     ARC_FEATURE_DMP_PERIPHERAL
#else
#define PERIPHERAL_BASE     _arc_aux_read(AUX_DMP_PERIPHERAL)
#endif

#if (USE_DW_GPIO_PORT_A)
static DEV_GPIO     port_a;
static DW_GPIO_PORT dw_gpio_port_a;
static DEV_GPIO_HANDLER dw_gpio_bit_handler_a[EMSK_GPIO_A_INT_MAX_COUNT];
static DW_GPIO_BIT_ISR dw_gpio_bit_isr_a = {
    EMSK_GPIO_A_INT_MAX_COUNT, dw_gpio_bit_handler_a
};

static int32_t porta_open(uint32_t dir)
{
    return dw_gpio_open(&port_a, dir);
}

static int32_t porta_close(void)
{
    return dw_gpio_close(&port_a);
}

static int32_t porta_control(uint32_t ctrl_cmd, void *param)
{
    return dw_gpio_control(&port_a, ctrl_cmd, param);
}

static int32_t porta_write(uint32_t val, uint32_t mask)
{
    return dw_gpio_write(&port_a, val, mask);
}

static int32_t porta_read(uint32_t *val, uint32_t mask)
{
    return dw_gpio_read(&port_a, val, mask);
}

static void porta_isr(void *ptr)
{
    dw_gpio_isr_handler(&port_a, ptr);
}

static void porta_install(void)
{
    uint32_t i;
    DEV_GPIO_PTR port_ptr = &port_a;
    DEV_GPIO_INFO_PTR info_ptr = &(port_a.gpio_info);
    DW_GPIO_PORT_PTR dw_port_ptr = &(dw_gpio_port_a);

    info_ptr->gpio_ctrl = (void *)dw_port_ptr;
    info_ptr->opn_cnt = 0;
    info_ptr->method = 0;
    info_ptr->direction = 0;
    info_ptr->extra = 0;

    dw_port_ptr->no = DW_GPIO_PORT_A;
    dw_port_ptr->regs = (DW_GPIO_REG_PTR)(PERIPHERAL_BASE|REL_REGBASE_GPIO0);
    dw_port_ptr->valid_bit_mask = EMSK_GPIO_A_VALID_MASK;
    dw_port_ptr->intno = INTNO_GPIO;
    dw_port_ptr->int_handler = porta_isr;

    for (i=0; i<dw_gpio_bit_isr_a.int_bit_max_cnt; i++) {
        dw_gpio_bit_isr_a.int_bit_handler_ptr[i] = NULL;
    }
    dw_port_ptr->gpio_bit_isr = &dw_gpio_bit_isr_a;

    port_ptr->gpio_open = porta_open;
    port_ptr->gpio_close = porta_close;
    port_ptr->gpio_control = porta_control;
    port_ptr->gpio_write = porta_write;
    port_ptr->gpio_read = porta_read;
}
#endif

#if (USE_DW_GPIO_PORT_B)
static DEV_GPIO     port_b;
static DW_GPIO_PORT dw_gpio_port_b;

static int32_t portb_open(uint32_t dir)
{
    return dw_gpio_open(&port_b, dir);
}

static int32_t portb_close(void)
{
    return dw_gpio_close(&port_b);
}

static int32_t portb_control(uint32_t ctrl_cmd, void *param)
{
    return dw_gpio_control(&port_b, ctrl_cmd, param);
}

static int32_t portb_write(uint32_t val, uint32_t mask)
{
    return dw_gpio_write(&port_b, val, mask);
}

static int32_t portb_read(uint32_t *val, uint32_t mask)
{
    return dw_gpio_read(&port_b, val, mask);
}

static void portb_isr(void *ptr)
{
    dw_gpio_isr_handler(&port_b, ptr);
}

static void portb_install(void)
{
    DEV_GPIO_PTR port_ptr = &port_b;
    DEV_GPIO_INFO_PTR info_ptr = &(port_b.gpio_info);
    DW_GPIO_PORT_PTR dw_port_ptr = &(dw_gpio_port_b);

    info_ptr->gpio_ctrl = (void *)dw_port_ptr;
    info_ptr->opn_cnt = 0;
    info_ptr->method = 0;
    info_ptr->direction = 0;
    info_ptr->extra = 0;

    dw_port_ptr->no = DW_GPIO_PORT_B;
    dw_port_ptr->regs = (DW_GPIO_REG_PTR)(PERIPHERAL_BASE|REL_REGBASE_GPIO0);
    dw_port_ptr->valid_bit_mask = EMSK_GPIO_B_VALID_MASK;

    dw_port_ptr->intno = INTNO_GPIO;
    dw_port_ptr->int_handler = portb_isr;
    dw_port_ptr->gpio_bit_isr = NULL;

    port_ptr->gpio_open = portb_open;
    port_ptr->gpio_close = portb_close;
    port_ptr->gpio_control = portb_control;
    port_ptr->gpio_write = portb_write;
    port_ptr->gpio_read = portb_read;
}
#endif


#if (USE_DW_GPIO_PORT_C)
static DEV_GPIO     port_c;
static DW_GPIO_PORT dw_gpio_port_c;

static int32_t portc_open(uint32_t dir)
{
    return dw_gpio_open(&port_c, dir);
}

static int32_t portc_close(void)
{
    return dw_gpio_close(&port_c);
}

static int32_t portc_control(uint32_t ctrl_cmd, void *param)
{
    return dw_gpio_control(&port_c, ctrl_cmd, param);
}

static int32_t portc_write(uint32_t val, uint32_t mask)
{
    return dw_gpio_write(&port_c, val, mask);
}

static int32_t portc_read(uint32_t *val, uint32_t mask)
{
    return dw_gpio_read(&port_c, val, mask);
}

static void portc_isr(void *ptr)
{
    dw_gpio_isr_handler(&port_c, ptr);
}

static void portc_install(void)
{
    DEV_GPIO_PTR port_ptr = &port_c;
    DEV_GPIO_INFO_PTR info_ptr = &(port_c.gpio_info);
    DW_GPIO_PORT_PTR dw_port_ptr = &(dw_gpio_port_c);

    info_ptr->gpio_ctrl = (void *)dw_port_ptr;
    info_ptr->opn_cnt = 0;
    info_ptr->method = 0;
    info_ptr->direction = 0;
    info_ptr->extra = 0;

    dw_port_ptr->no = DW_GPIO_PORT_C;
    dw_port_ptr->regs = (DW_GPIO_REG_PTR)(PERIPHERAL_BASE|REL_REGBASE_GPIO0);
    dw_port_ptr->valid_bit_mask = EMSK_GPIO_C_VALID_MASK;

    dw_port_ptr->intno = INTNO_GPIO;
    dw_port_ptr->int_handler = portc_isr;
    dw_port_ptr->gpio_bit_isr = NULL;

    port_ptr->gpio_open = portc_open;
    port_ptr->gpio_close = portc_close;
    port_ptr->gpio_control = portc_control;
    port_ptr->gpio_write = portc_write;
    port_ptr->gpio_read = portc_read;
}
#endif

#if (USE_DW_GPIO_PORT_D)
static DEV_GPIO     port_d;
static DW_GPIO_PORT dw_gpio_port_d;

static int32_t portd_open(uint32_t dir)
{
    return dw_gpio_open(&port_d, dir);
}

static int32_t portd_close(void)
{
    return dw_gpio_close(&port_d);
}

static int32_t portd_control(uint32_t ctrl_cmd, void *param)
{
    return dw_gpio_control(&port_d, ctrl_cmd, param);
}

static int32_t portd_write(uint32_t val, uint32_t mask)
{
    return dw_gpio_write(&port_d, val, mask);
}

static int32_t portd_read(uint32_t *val, uint32_t mask)
{
    return dw_gpio_read(&port_d, val, mask);
}

static void portd_isr(void *ptr)
{
    dw_gpio_isr_handler(&port_d, ptr);
}

static void portd_install(void)
{
    DEV_GPIO_PTR port_ptr = &port_d;
    DEV_GPIO_INFO_PTR info_ptr = &(port_d.gpio_info);
    DW_GPIO_PORT_PTR dw_port_ptr = &(dw_gpio_port_d);

    info_ptr->gpio_ctrl = (void *)dw_port_ptr;
    info_ptr->opn_cnt = 0;
    info_ptr->method = 0;
    info_ptr->direction = 0;
    info_ptr->extra = 0;

    dw_port_ptr->no = DW_GPIO_PORT_D;
    dw_port_ptr->regs = (DW_GPIO_REG_PTR)(PERIPHERAL_BASE|REL_REGBASE_GPIO0);
    dw_port_ptr->valid_bit_mask = EMSK_GPIO_D_VALID_MASK;

    dw_port_ptr->intno = INTNO_GPIO;
    dw_port_ptr->int_handler = portd_isr;
    dw_port_ptr->gpio_bit_isr = NULL;

    port_ptr->gpio_open = portd_open;
    port_ptr->gpio_close = portd_close;
    port_ptr->gpio_control = portd_control;
    port_ptr->gpio_write = portd_write;
    port_ptr->gpio_read = portd_read;
}
#endif

DEV_GPIO_PTR gpio_get_dev(int32_t gpio_id)
{
    static uint32_t install_flag = 0;

    /* intall device objects */
    if (install_flag == 0) {
        install_flag = 1;
        dw_gpio_all_install();
    }

    switch (gpio_id) {
#if (USE_DW_GPIO_PORT_A)
        case DW_GPIO_PORT_A: return &port_a;
#endif
#if (USE_DW_GPIO_PORT_B)
        case DW_GPIO_PORT_B: return &port_b;
#endif
#if (USE_DW_GPIO_PORT_C)
        case DW_GPIO_PORT_C: return &port_c;
#endif
#if (USE_DW_GPIO_PORT_D)
        case DW_GPIO_PORT_D: return &port_d;
#endif
        default:
            break;
    }
    return NULL;
}

void dw_gpio_all_install(void)
{
#if (USE_DW_GPIO_PORT_A)
    porta_install();
#endif
#if (USE_DW_GPIO_PORT_B)
    portb_install();
#endif
#if (USE_DW_GPIO_PORT_C)
    portc_install();
#endif
#if (USE_DW_GPIO_PORT_D)
    portd_install();
#endif
}