16
16
#include <mach/hardware.h>
17
17
#include <mach/irqs.h>
18
18
19
+ struct sa1100_gpio_chip {
20
+ struct gpio_chip chip ;
21
+ void __iomem * membase ;
22
+ int irqbase ;
23
+ u32 irqmask ;
24
+ u32 irqrising ;
25
+ u32 irqfalling ;
26
+ u32 irqwake ;
27
+ };
28
+
29
+ #define sa1100_gpio_chip (x ) container_of(x, struct sa1100_gpio_chip, chip)
30
+
31
+ enum {
32
+ R_GPLR = 0x00 ,
33
+ R_GPDR = 0x04 ,
34
+ R_GPSR = 0x08 ,
35
+ R_GPCR = 0x0c ,
36
+ R_GRER = 0x10 ,
37
+ R_GFER = 0x14 ,
38
+ R_GEDR = 0x18 ,
39
+ R_GAFR = 0x1c ,
40
+ };
41
+
19
42
static int sa1100_gpio_get (struct gpio_chip * chip , unsigned offset )
20
43
{
21
- return !!(GPLR & GPIO_GPIO (offset ));
44
+ return readl_relaxed (sa1100_gpio_chip (chip )-> membase + R_GPLR ) &
45
+ BIT (offset );
22
46
}
23
47
24
48
static void sa1100_gpio_set (struct gpio_chip * chip , unsigned offset , int value )
25
49
{
26
- if (value )
27
- GPSR = GPIO_GPIO (offset );
28
- else
29
- GPCR = GPIO_GPIO (offset );
50
+ int reg = value ? R_GPSR : R_GPCR ;
51
+
52
+ writel_relaxed (BIT (offset ), sa1100_gpio_chip (chip )-> membase + reg );
30
53
}
31
54
32
55
static int sa1100_direction_input (struct gpio_chip * chip , unsigned offset )
33
56
{
57
+ void __iomem * gpdr = sa1100_gpio_chip (chip )-> membase + R_GPDR ;
34
58
unsigned long flags ;
35
59
36
60
local_irq_save (flags );
37
- GPDR &= ~ GPIO_GPIO (offset );
61
+ writel_relaxed ( readl_relaxed ( gpdr ) & ~ BIT (offset ), gpdr );
38
62
local_irq_restore (flags );
63
+
39
64
return 0 ;
40
65
}
41
66
42
67
static int sa1100_direction_output (struct gpio_chip * chip , unsigned offset , int value )
43
68
{
69
+ void __iomem * gpdr = sa1100_gpio_chip (chip )-> membase + R_GPDR ;
44
70
unsigned long flags ;
45
71
46
72
local_irq_save (flags );
47
73
sa1100_gpio_set (chip , offset , value );
48
- GPDR |= GPIO_GPIO (offset );
74
+ writel_relaxed ( readl_relaxed ( gpdr ) | BIT (offset ), gpdr );
49
75
local_irq_restore (flags );
76
+
50
77
return 0 ;
51
78
}
52
79
53
80
static int sa1100_to_irq (struct gpio_chip * chip , unsigned offset )
54
81
{
55
- return IRQ_GPIO0 + offset ;
82
+ return sa1100_gpio_chip ( chip ) -> irqbase + offset ;
56
83
}
57
84
58
- static struct gpio_chip sa1100_gpio_chip = {
59
- .label = "gpio" ,
60
- .direction_input = sa1100_direction_input ,
61
- .direction_output = sa1100_direction_output ,
62
- .set = sa1100_gpio_set ,
63
- .get = sa1100_gpio_get ,
64
- .to_irq = sa1100_to_irq ,
65
- .base = 0 ,
66
- .ngpio = GPIO_MAX + 1 ,
85
+ static struct sa1100_gpio_chip sa1100_gpio_chip = {
86
+ .chip = {
87
+ .label = "gpio" ,
88
+ .direction_input = sa1100_direction_input ,
89
+ .direction_output = sa1100_direction_output ,
90
+ .set = sa1100_gpio_set ,
91
+ .get = sa1100_gpio_get ,
92
+ .to_irq = sa1100_to_irq ,
93
+ .base = 0 ,
94
+ .ngpio = GPIO_MAX + 1 ,
95
+ },
96
+ .membase = (void * )& GPLR ,
97
+ .irqbase = IRQ_GPIO0 ,
67
98
};
68
99
69
100
/*
70
101
* SA1100 GPIO edge detection for IRQs:
71
102
* IRQs are generated on Falling-Edge, Rising-Edge, or both.
72
103
* Use this instead of directly setting GRER/GFER.
73
104
*/
74
- static int GPIO_IRQ_rising_edge ;
75
- static int GPIO_IRQ_falling_edge ;
76
- static int GPIO_IRQ_mask ;
77
- static int GPIO_IRQ_wake ;
105
+ static void sa1100_update_edge_regs (struct sa1100_gpio_chip * sgc )
106
+ {
107
+ void * base = sgc -> membase ;
108
+ u32 grer , gfer ;
109
+
110
+ grer = sgc -> irqrising & sgc -> irqmask ;
111
+ gfer = sgc -> irqfalling & sgc -> irqmask ;
112
+
113
+ writel_relaxed (grer , base + R_GRER );
114
+ writel_relaxed (gfer , base + R_GFER );
115
+ }
78
116
79
117
static int sa1100_gpio_type (struct irq_data * d , unsigned int type )
80
118
{
81
- unsigned int mask ;
82
-
83
- mask = BIT (d -> hwirq );
119
+ struct sa1100_gpio_chip * sgc = irq_data_get_irq_chip_data (d );
120
+ unsigned int mask = BIT (d -> hwirq );
84
121
85
122
if (type == IRQ_TYPE_PROBE ) {
86
- if ((GPIO_IRQ_rising_edge | GPIO_IRQ_falling_edge ) & mask )
123
+ if ((sgc -> irqrising | sgc -> irqfalling ) & mask )
87
124
return 0 ;
88
125
type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING ;
89
126
}
90
127
91
128
if (type & IRQ_TYPE_EDGE_RISING )
92
- GPIO_IRQ_rising_edge |= mask ;
129
+ sgc -> irqrising |= mask ;
93
130
else
94
- GPIO_IRQ_rising_edge &= ~mask ;
131
+ sgc -> irqrising &= ~mask ;
95
132
if (type & IRQ_TYPE_EDGE_FALLING )
96
- GPIO_IRQ_falling_edge |= mask ;
133
+ sgc -> irqfalling |= mask ;
97
134
else
98
- GPIO_IRQ_falling_edge &= ~mask ;
135
+ sgc -> irqfalling &= ~mask ;
99
136
100
- GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask ;
101
- GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask ;
137
+ sa1100_update_edge_regs (sgc );
102
138
103
139
return 0 ;
104
140
}
@@ -108,37 +144,40 @@ static int sa1100_gpio_type(struct irq_data *d, unsigned int type)
108
144
*/
109
145
static void sa1100_gpio_ack (struct irq_data * d )
110
146
{
111
- GEDR = BIT (d -> hwirq );
147
+ struct sa1100_gpio_chip * sgc = irq_data_get_irq_chip_data (d );
148
+
149
+ writel_relaxed (BIT (d -> hwirq ), sgc -> membase + R_GEDR );
112
150
}
113
151
114
152
static void sa1100_gpio_mask (struct irq_data * d )
115
153
{
154
+ struct sa1100_gpio_chip * sgc = irq_data_get_irq_chip_data (d );
116
155
unsigned int mask = BIT (d -> hwirq );
117
156
118
- GPIO_IRQ_mask &= ~mask ;
157
+ sgc -> irqmask &= ~mask ;
119
158
120
- GRER &= ~mask ;
121
- GFER &= ~mask ;
159
+ sa1100_update_edge_regs (sgc );
122
160
}
123
161
124
162
static void sa1100_gpio_unmask (struct irq_data * d )
125
163
{
164
+ struct sa1100_gpio_chip * sgc = irq_data_get_irq_chip_data (d );
126
165
unsigned int mask = BIT (d -> hwirq );
127
166
128
- GPIO_IRQ_mask |= mask ;
167
+ sgc -> irqmask |= mask ;
129
168
130
- GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask ;
131
- GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask ;
169
+ sa1100_update_edge_regs (sgc );
132
170
}
133
171
134
172
static int sa1100_gpio_wake (struct irq_data * d , unsigned int on )
135
173
{
174
+ struct sa1100_gpio_chip * sgc = irq_data_get_irq_chip_data (d );
136
175
int ret = sa11x0_gpio_set_wake (d -> hwirq , on );
137
176
if (!ret ) {
138
177
if (on )
139
- GPIO_IRQ_wake |= BIT (d -> hwirq );
178
+ sgc -> irqwake |= BIT (d -> hwirq );
140
179
else
141
- GPIO_IRQ_wake &= ~BIT (d -> hwirq );
180
+ sgc -> irqwake &= ~BIT (d -> hwirq );
142
181
}
143
182
return ret ;
144
183
}
@@ -158,8 +197,10 @@ static struct irq_chip sa1100_gpio_irq_chip = {
158
197
static int sa1100_gpio_irqdomain_map (struct irq_domain * d ,
159
198
unsigned int irq , irq_hw_number_t hwirq )
160
199
{
161
- irq_set_chip_and_handler (irq , & sa1100_gpio_irq_chip ,
162
- handle_edge_irq );
200
+ struct sa1100_gpio_chip * sgc = d -> host_data ;
201
+
202
+ irq_set_chip_data (irq , sgc );
203
+ irq_set_chip_and_handler (irq , & sa1100_gpio_irq_chip , handle_edge_irq );
163
204
irq_set_probe (irq );
164
205
165
206
return 0 ;
@@ -179,48 +220,52 @@ static struct irq_domain *sa1100_gpio_irqdomain;
179
220
*/
180
221
static void sa1100_gpio_handler (struct irq_desc * desc )
181
222
{
223
+ struct sa1100_gpio_chip * sgc = irq_desc_get_handler_data (desc );
182
224
unsigned int irq , mask ;
225
+ void __iomem * gedr = sgc -> membase + R_GEDR ;
183
226
184
- mask = GEDR ;
227
+ mask = readl_relaxed ( gedr ) ;
185
228
do {
186
229
/*
187
230
* clear down all currently active IRQ sources.
188
231
* We will be processing them all.
189
232
*/
190
- GEDR = mask ;
233
+ writel_relaxed ( mask , gedr ) ;
191
234
192
- irq = IRQ_GPIO0 ;
235
+ irq = sgc -> irqbase ;
193
236
do {
194
237
if (mask & 1 )
195
238
generic_handle_irq (irq );
196
239
mask >>= 1 ;
197
240
irq ++ ;
198
241
} while (mask );
199
242
200
- mask = GEDR ;
243
+ mask = readl_relaxed ( gedr ) ;
201
244
} while (mask );
202
245
}
203
246
204
247
static int sa1100_gpio_suspend (void )
205
248
{
249
+ struct sa1100_gpio_chip * sgc = & sa1100_gpio_chip ;
250
+
206
251
/*
207
252
* Set the appropriate edges for wakeup.
208
253
*/
209
- GRER = GPIO_IRQ_wake & GPIO_IRQ_rising_edge ;
210
- GFER = GPIO_IRQ_wake & GPIO_IRQ_falling_edge ;
254
+ writel_relaxed ( sgc -> irqwake & sgc -> irqrising , sgc -> membase + R_GRER ) ;
255
+ writel_relaxed ( sgc -> irqwake & sgc -> irqfalling , sgc -> membase + R_GFER ) ;
211
256
212
257
/*
213
258
* Clear any pending GPIO interrupts.
214
259
*/
215
- GEDR = GEDR ;
260
+ writel_relaxed (readl_relaxed (sgc -> membase + R_GEDR ),
261
+ sgc -> membase + R_GEDR );
216
262
217
263
return 0 ;
218
264
}
219
265
220
266
static void sa1100_gpio_resume (void )
221
267
{
222
- GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask ;
223
- GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask ;
268
+ sa1100_update_edge_regs (& sa1100_gpio_chip );
224
269
}
225
270
226
271
static struct syscore_ops sa1100_gpio_syscore_ops = {
@@ -236,36 +281,40 @@ static int __init sa1100_gpio_init_devicefs(void)
236
281
237
282
device_initcall (sa1100_gpio_init_devicefs );
238
283
284
+ static const int sa1100_gpio_irqs [] __initconst = {
285
+ /* Install handlers for GPIO 0-10 edge detect interrupts */
286
+ IRQ_GPIO0_SC ,
287
+ IRQ_GPIO1_SC ,
288
+ IRQ_GPIO2_SC ,
289
+ IRQ_GPIO3_SC ,
290
+ IRQ_GPIO4_SC ,
291
+ IRQ_GPIO5_SC ,
292
+ IRQ_GPIO6_SC ,
293
+ IRQ_GPIO7_SC ,
294
+ IRQ_GPIO8_SC ,
295
+ IRQ_GPIO9_SC ,
296
+ IRQ_GPIO10_SC ,
297
+ /* Install handler for GPIO 11-27 edge detect interrupts */
298
+ IRQ_GPIO11_27 ,
299
+ };
300
+
239
301
void __init sa1100_init_gpio (void )
240
302
{
303
+ struct sa1100_gpio_chip * sgc = & sa1100_gpio_chip ;
304
+ int i ;
305
+
241
306
/* clear all GPIO edge detects */
242
- GFER = 0 ;
243
- GRER = 0 ;
244
- GEDR = -1 ;
307
+ writel_relaxed ( 0 , sgc -> membase + R_GFER ) ;
308
+ writel_relaxed ( 0 , sgc -> membase + R_GRER ) ;
309
+ writel_relaxed ( -1 , sgc -> membase + R_GEDR ) ;
245
310
246
- gpiochip_add_data (& sa1100_gpio_chip , NULL );
311
+ gpiochip_add_data (& sa1100_gpio_chip . chip , NULL );
247
312
248
313
sa1100_gpio_irqdomain = irq_domain_add_simple (NULL ,
249
314
28 , IRQ_GPIO0 ,
250
- & sa1100_gpio_irqdomain_ops , NULL );
251
-
252
- /*
253
- * Install handlers for GPIO 0-10 edge detect interrupts
254
- */
255
- irq_set_chained_handler (IRQ_GPIO0_SC , sa1100_gpio_handler );
256
- irq_set_chained_handler (IRQ_GPIO1_SC , sa1100_gpio_handler );
257
- irq_set_chained_handler (IRQ_GPIO2_SC , sa1100_gpio_handler );
258
- irq_set_chained_handler (IRQ_GPIO3_SC , sa1100_gpio_handler );
259
- irq_set_chained_handler (IRQ_GPIO4_SC , sa1100_gpio_handler );
260
- irq_set_chained_handler (IRQ_GPIO5_SC , sa1100_gpio_handler );
261
- irq_set_chained_handler (IRQ_GPIO6_SC , sa1100_gpio_handler );
262
- irq_set_chained_handler (IRQ_GPIO7_SC , sa1100_gpio_handler );
263
- irq_set_chained_handler (IRQ_GPIO8_SC , sa1100_gpio_handler );
264
- irq_set_chained_handler (IRQ_GPIO9_SC , sa1100_gpio_handler );
265
- irq_set_chained_handler (IRQ_GPIO10_SC , sa1100_gpio_handler );
266
- /*
267
- * Install handler for GPIO 11-27 edge detect interrupts
268
- */
269
- irq_set_chained_handler (IRQ_GPIO11_27 , sa1100_gpio_handler );
315
+ & sa1100_gpio_irqdomain_ops , sgc );
270
316
317
+ for (i = 0 ; i < ARRAY_SIZE (sa1100_gpio_irqs ); i ++ )
318
+ irq_set_chained_handler_and_data (sa1100_gpio_irqs [i ],
319
+ sa1100_gpio_handler , sgc );
271
320
}
0 commit comments