24
24
#include "../pinctrl/core.h"
25
25
#include "../pinctrl/pinctrl-rockchip.h"
26
26
27
- /* GPIO control registers */
28
- #define GPIO_SWPORT_DR 0x00
29
- #define GPIO_SWPORT_DDR 0x04
30
- #define GPIO_INTEN 0x30
31
- #define GPIO_INTMASK 0x34
32
- #define GPIO_INTTYPE_LEVEL 0x38
33
- #define GPIO_INT_POLARITY 0x3c
34
- #define GPIO_INT_STATUS 0x40
35
- #define GPIO_INT_RAWSTATUS 0x44
36
- #define GPIO_DEBOUNCE 0x48
37
- #define GPIO_PORTS_EOI 0x4c
38
- #define GPIO_EXT_PORT 0x50
39
- #define GPIO_LS_SYNC 0x60
27
+ #define GPIO_TYPE_V1 (0) /* GPIO Version ID reserved */
28
+
29
+ static const struct rockchip_gpio_regs gpio_regs_v1 = {
30
+ .port_dr = 0x00 ,
31
+ .port_ddr = 0x04 ,
32
+ .int_en = 0x30 ,
33
+ .int_mask = 0x34 ,
34
+ .int_type = 0x38 ,
35
+ .int_polarity = 0x3c ,
36
+ .int_status = 0x40 ,
37
+ .int_rawstatus = 0x44 ,
38
+ .debounce = 0x48 ,
39
+ .port_eoi = 0x4c ,
40
+ .ext_port = 0x50 ,
41
+ };
40
42
41
43
static int rockchip_gpio_get_direction (struct gpio_chip * chip ,
42
44
unsigned int offset )
43
45
{
44
46
struct rockchip_pin_bank * bank = gpiochip_get_data (chip );
45
47
u32 data ;
46
48
47
- data = readl_relaxed (bank -> reg_base + GPIO_SWPORT_DDR );
49
+ data = readl_relaxed (bank -> reg_base + bank -> gpio_regs -> port_ddr );
48
50
if (data & BIT (offset ))
49
51
return GPIO_LINE_DIRECTION_OUT ;
50
52
@@ -60,13 +62,13 @@ static int rockchip_gpio_set_direction(struct gpio_chip *chip,
60
62
61
63
raw_spin_lock_irqsave (& bank -> slock , flags );
62
64
63
- data = readl_relaxed (bank -> reg_base + GPIO_SWPORT_DDR );
65
+ data = readl_relaxed (bank -> reg_base + bank -> gpio_regs -> port_ddr );
64
66
/* set bit to 1 for output, 0 for input */
65
67
if (!input )
66
68
data |= BIT (offset );
67
69
else
68
70
data &= ~BIT (offset );
69
- writel_relaxed (data , bank -> reg_base + GPIO_SWPORT_DDR );
71
+ writel_relaxed (data , bank -> reg_base + bank -> gpio_regs -> port_ddr );
70
72
71
73
raw_spin_unlock_irqrestore (& bank -> slock , flags );
72
74
@@ -77,7 +79,7 @@ static void rockchip_gpio_set(struct gpio_chip *gc, unsigned int offset,
77
79
int value )
78
80
{
79
81
struct rockchip_pin_bank * bank = gpiochip_get_data (gc );
80
- void __iomem * reg = bank -> reg_base + GPIO_SWPORT_DR ;
82
+ void __iomem * reg = bank -> reg_base + bank -> gpio_regs -> port_dr ;
81
83
unsigned long flags ;
82
84
u32 data ;
83
85
@@ -97,17 +99,18 @@ static int rockchip_gpio_get(struct gpio_chip *gc, unsigned int offset)
97
99
struct rockchip_pin_bank * bank = gpiochip_get_data (gc );
98
100
u32 data ;
99
101
100
- data = readl (bank -> reg_base + GPIO_EXT_PORT );
102
+ data = readl (bank -> reg_base + bank -> gpio_regs -> ext_port );
101
103
data >>= offset ;
102
104
data &= 1 ;
105
+
103
106
return data ;
104
107
}
105
108
106
109
static void rockchip_gpio_set_debounce (struct gpio_chip * gc ,
107
110
unsigned int offset , bool enable )
108
111
{
109
112
struct rockchip_pin_bank * bank = gpiochip_get_data (gc );
110
- void __iomem * reg = bank -> reg_base + GPIO_DEBOUNCE ;
113
+ void __iomem * reg = bank -> reg_base + bank -> gpio_regs -> debounce ;
111
114
unsigned long flags ;
112
115
u32 data ;
113
116
@@ -207,7 +210,7 @@ static void rockchip_irq_demux(struct irq_desc *desc)
207
210
208
211
chained_irq_enter (chip , desc );
209
212
210
- pend = readl_relaxed (bank -> reg_base + GPIO_INT_STATUS );
213
+ pend = readl_relaxed (bank -> reg_base + bank -> gpio_regs -> int_status );
211
214
212
215
while (pend ) {
213
216
unsigned int irq , virq ;
@@ -231,24 +234,26 @@ static void rockchip_irq_demux(struct irq_desc *desc)
231
234
u32 data , data_old , polarity ;
232
235
unsigned long flags ;
233
236
234
- data = readl_relaxed (bank -> reg_base + GPIO_EXT_PORT );
237
+ data = readl_relaxed (bank -> reg_base +
238
+ bank -> gpio_regs -> ext_port );
235
239
do {
236
240
raw_spin_lock_irqsave (& bank -> slock , flags );
237
241
238
242
polarity = readl_relaxed (bank -> reg_base +
239
- GPIO_INT_POLARITY );
243
+ bank -> gpio_regs -> int_polarity );
240
244
if (data & BIT (irq ))
241
245
polarity &= ~BIT (irq );
242
246
else
243
247
polarity |= BIT (irq );
244
248
writel (polarity ,
245
- bank -> reg_base + GPIO_INT_POLARITY );
249
+ bank -> reg_base +
250
+ bank -> gpio_regs -> int_polarity );
246
251
247
252
raw_spin_unlock_irqrestore (& bank -> slock , flags );
248
253
249
254
data_old = data ;
250
255
data = readl_relaxed (bank -> reg_base +
251
- GPIO_EXT_PORT );
256
+ bank -> gpio_regs -> ext_port );
252
257
} while ((data & BIT (irq )) != (data_old & BIT (irq )));
253
258
}
254
259
@@ -270,9 +275,9 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type)
270
275
271
276
raw_spin_lock_irqsave (& bank -> slock , flags );
272
277
273
- data = readl_relaxed (bank -> reg_base + GPIO_SWPORT_DDR );
278
+ data = readl_relaxed (bank -> reg_base + bank -> gpio_regs -> port_ddr );
274
279
data &= ~mask ;
275
- writel_relaxed (data , bank -> reg_base + GPIO_SWPORT_DDR );
280
+ writel_relaxed (data , bank -> reg_base + bank -> gpio_regs -> port_ddr );
276
281
277
282
raw_spin_unlock_irqrestore (& bank -> slock , flags );
278
283
@@ -284,8 +289,8 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type)
284
289
raw_spin_lock_irqsave (& bank -> slock , flags );
285
290
irq_gc_lock (gc );
286
291
287
- level = readl_relaxed (gc -> reg_base + GPIO_INTTYPE_LEVEL );
288
- polarity = readl_relaxed (gc -> reg_base + GPIO_INT_POLARITY );
292
+ level = readl_relaxed (gc -> reg_base + bank -> gpio_regs -> int_type );
293
+ polarity = readl_relaxed (gc -> reg_base + bank -> gpio_regs -> int_polarity );
289
294
290
295
switch (type ) {
291
296
case IRQ_TYPE_EDGE_BOTH :
@@ -296,7 +301,7 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type)
296
301
* Determine gpio state. If 1 next interrupt should be falling
297
302
* otherwise rising.
298
303
*/
299
- data = readl (bank -> reg_base + GPIO_EXT_PORT );
304
+ data = readl (bank -> reg_base + bank -> gpio_regs -> ext_port );
300
305
if (data & mask )
301
306
polarity &= ~mask ;
302
307
else
@@ -329,8 +334,8 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type)
329
334
return - EINVAL ;
330
335
}
331
336
332
- writel_relaxed (level , gc -> reg_base + GPIO_INTTYPE_LEVEL );
333
- writel_relaxed (polarity , gc -> reg_base + GPIO_INT_POLARITY );
337
+ writel_relaxed (level , gc -> reg_base + bank -> gpio_regs -> int_type );
338
+ writel_relaxed (polarity , gc -> reg_base + bank -> gpio_regs -> int_polarity );
334
339
335
340
irq_gc_unlock (gc );
336
341
raw_spin_unlock_irqrestore (& bank -> slock , flags );
@@ -343,16 +348,16 @@ static void rockchip_irq_suspend(struct irq_data *d)
343
348
struct irq_chip_generic * gc = irq_data_get_irq_chip_data (d );
344
349
struct rockchip_pin_bank * bank = gc -> private ;
345
350
346
- bank -> saved_masks = irq_reg_readl (gc , GPIO_INTMASK );
347
- irq_reg_writel (gc , ~gc -> wake_active , GPIO_INTMASK );
351
+ bank -> saved_masks = irq_reg_readl (gc , bank -> gpio_regs -> int_mask );
352
+ irq_reg_writel (gc , ~gc -> wake_active , bank -> gpio_regs -> int_mask );
348
353
}
349
354
350
355
static void rockchip_irq_resume (struct irq_data * d )
351
356
{
352
357
struct irq_chip_generic * gc = irq_data_get_irq_chip_data (d );
353
358
struct rockchip_pin_bank * bank = gc -> private ;
354
359
355
- irq_reg_writel (gc , bank -> saved_masks , GPIO_INTMASK );
360
+ irq_reg_writel (gc , bank -> saved_masks , bank -> gpio_regs -> int_mask );
356
361
}
357
362
358
363
static void rockchip_irq_enable (struct irq_data * d )
@@ -400,8 +405,8 @@ static int rockchip_interrupts_register(struct rockchip_pin_bank *bank)
400
405
gc = irq_get_domain_generic_chip (bank -> domain , 0 );
401
406
gc -> reg_base = bank -> reg_base ;
402
407
gc -> private = bank ;
403
- gc -> chip_types [0 ].regs .mask = GPIO_INTMASK ;
404
- gc -> chip_types [0 ].regs .ack = GPIO_PORTS_EOI ;
408
+ gc -> chip_types [0 ].regs .mask = bank -> gpio_regs -> int_mask ;
409
+ gc -> chip_types [0 ].regs .ack = bank -> gpio_regs -> port_eoi ;
405
410
gc -> chip_types [0 ].chip .irq_ack = irq_gc_ack_set_bit ;
406
411
gc -> chip_types [0 ].chip .irq_mask = irq_gc_mask_set_bit ;
407
412
gc -> chip_types [0 ].chip .irq_unmask = irq_gc_mask_clr_bit ;
@@ -418,9 +423,9 @@ static int rockchip_interrupts_register(struct rockchip_pin_bank *bank)
418
423
* Our driver only uses the concept of masked and always keeps
419
424
* things enabled, so for us that's all masked and all enabled.
420
425
*/
421
- writel_relaxed (0xffffffff , bank -> reg_base + GPIO_INTMASK );
422
- writel_relaxed (0xffffffff , bank -> reg_base + GPIO_PORTS_EOI );
423
- writel_relaxed (0xffffffff , bank -> reg_base + GPIO_INTEN );
426
+ writel_relaxed (0xffffffff , bank -> reg_base + bank -> gpio_regs -> int_mask );
427
+ writel_relaxed (0xffffffff , bank -> reg_base + bank -> gpio_regs -> port_eoi );
428
+ writel_relaxed (0xffffffff , bank -> reg_base + bank -> gpio_regs -> int_en );
424
429
gc -> mask_cache = 0xffffffff ;
425
430
426
431
irq_set_chained_handler_and_data (bank -> irq ,
@@ -510,6 +515,9 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
510
515
511
516
bank -> irq = irq_of_parse_and_map (bank -> of_node , 0 );
512
517
518
+ bank -> gpio_regs = & gpio_regs_v1 ;
519
+ bank -> gpio_type = GPIO_TYPE_V1 ;
520
+
513
521
bank -> clk = of_clk_get (bank -> of_node , 0 );
514
522
if (!IS_ERR (bank -> clk ))
515
523
return clk_prepare_enable (bank -> clk );
0 commit comments