aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-ep93xx
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-ep93xx')
-rw-r--r--arch/arm/mach-ep93xx/core.c262
1 files changed, 157 insertions, 105 deletions
diff --git a/arch/arm/mach-ep93xx/core.c b/arch/arm/mach-ep93xx/core.c
index 70b2c7801110..91f6a07a51d5 100644
--- a/arch/arm/mach-ep93xx/core.c
+++ b/arch/arm/mach-ep93xx/core.c
@@ -3,6 +3,7 @@
3 * Core routines for Cirrus EP93xx chips. 3 * Core routines for Cirrus EP93xx chips.
4 * 4 *
5 * Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org> 5 * Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org>
6 * Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org>
6 * 7 *
7 * Thanks go to Michael Burian and Ray Lehtiniemi for their key 8 * Thanks go to Michael Burian and Ray Lehtiniemi for their key
8 * role in the ep93xx linux community. 9 * role in the ep93xx linux community.
@@ -21,7 +22,6 @@
21#include <linux/serial.h> 22#include <linux/serial.h>
22#include <linux/tty.h> 23#include <linux/tty.h>
23#include <linux/bitops.h> 24#include <linux/bitops.h>
24#include <linux/serial.h>
25#include <linux/serial_8250.h> 25#include <linux/serial_8250.h>
26#include <linux/serial_core.h> 26#include <linux/serial_core.h>
27#include <linux/device.h> 27#include <linux/device.h>
@@ -99,8 +99,6 @@ static unsigned int last_jiffy_time;
99 99
100static int ep93xx_timer_interrupt(int irq, void *dev_id) 100static int ep93xx_timer_interrupt(int irq, void *dev_id)
101{ 101{
102 write_seqlock(&xtime_lock);
103
104 __raw_writel(1, EP93XX_TIMER1_CLEAR); 102 __raw_writel(1, EP93XX_TIMER1_CLEAR);
105 while ((signed long) 103 while ((signed long)
106 (__raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time) 104 (__raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time)
@@ -109,8 +107,6 @@ static int ep93xx_timer_interrupt(int irq, void *dev_id)
109 timer_tick(); 107 timer_tick();
110 } 108 }
111 109
112 write_sequnlock(&xtime_lock);
113
114 return IRQ_HANDLED; 110 return IRQ_HANDLED;
115} 111}
116 112
@@ -157,38 +153,41 @@ static unsigned char gpio_int_enabled[3];
157static unsigned char gpio_int_type1[3]; 153static unsigned char gpio_int_type1[3];
158static unsigned char gpio_int_type2[3]; 154static unsigned char gpio_int_type2[3];
159 155
160static void update_gpio_int_params(int abf) 156/* Port ordering is: A B F */
157static const u8 int_type1_register_offset[3] = { 0x90, 0xac, 0x4c };
158static const u8 int_type2_register_offset[3] = { 0x94, 0xb0, 0x50 };
159static const u8 eoi_register_offset[3] = { 0x98, 0xb4, 0x54 };
160static const u8 int_en_register_offset[3] = { 0x9c, 0xb8, 0x5c };
161
162static void update_gpio_int_params(unsigned port)
161{ 163{
162 if (abf == 0) { 164 BUG_ON(port > 2);
163 __raw_writeb(0, EP93XX_GPIO_A_INT_ENABLE);
164 __raw_writeb(gpio_int_type2[0], EP93XX_GPIO_A_INT_TYPE2);
165 __raw_writeb(gpio_int_type1[0], EP93XX_GPIO_A_INT_TYPE1);
166 __raw_writeb(gpio_int_unmasked[0] & gpio_int_enabled[0], EP93XX_GPIO_A_INT_ENABLE);
167 } else if (abf == 1) {
168 __raw_writeb(0, EP93XX_GPIO_B_INT_ENABLE);
169 __raw_writeb(gpio_int_type2[1], EP93XX_GPIO_B_INT_TYPE2);
170 __raw_writeb(gpio_int_type1[1], EP93XX_GPIO_B_INT_TYPE1);
171 __raw_writeb(gpio_int_unmasked[1] & gpio_int_enabled[1], EP93XX_GPIO_B_INT_ENABLE);
172 } else if (abf == 2) {
173 __raw_writeb(0, EP93XX_GPIO_F_INT_ENABLE);
174 __raw_writeb(gpio_int_type2[2], EP93XX_GPIO_F_INT_TYPE2);
175 __raw_writeb(gpio_int_type1[2], EP93XX_GPIO_F_INT_TYPE1);
176 __raw_writeb(gpio_int_unmasked[2] & gpio_int_enabled[2], EP93XX_GPIO_F_INT_ENABLE);
177 } else {
178 BUG();
179 }
180}
181 165
166 __raw_writeb(0, EP93XX_GPIO_REG(int_en_register_offset[port]));
182 167
183static unsigned char data_register_offset[8] = { 168 __raw_writeb(gpio_int_type2[port],
184 0x00, 0x04, 0x08, 0x0c, 0x20, 0x30, 0x38, 0x40, 169 EP93XX_GPIO_REG(int_type2_register_offset[port]));
170
171 __raw_writeb(gpio_int_type1[port],
172 EP93XX_GPIO_REG(int_type1_register_offset[port]));
173
174 __raw_writeb(gpio_int_unmasked[port] & gpio_int_enabled[port],
175 EP93XX_GPIO_REG(int_en_register_offset[port]));
176}
177
178/* Port ordering is: A B F D E C G H */
179static const u8 data_register_offset[8] = {
180 0x00, 0x04, 0x30, 0x0c, 0x20, 0x08, 0x38, 0x40,
185}; 181};
186 182
187static unsigned char data_direction_register_offset[8] = { 183static const u8 data_direction_register_offset[8] = {
188 0x10, 0x14, 0x18, 0x1c, 0x24, 0x34, 0x3c, 0x44, 184 0x10, 0x14, 0x34, 0x1c, 0x24, 0x18, 0x3c, 0x44,
189}; 185};
190 186
191void gpio_line_config(int line, int direction) 187#define GPIO_IN 0
188#define GPIO_OUT 1
189
190static void ep93xx_gpio_set_direction(unsigned line, int direction)
192{ 191{
193 unsigned int data_direction_register; 192 unsigned int data_direction_register;
194 unsigned long flags; 193 unsigned long flags;
@@ -199,14 +198,10 @@ void gpio_line_config(int line, int direction)
199 198
200 local_irq_save(flags); 199 local_irq_save(flags);
201 if (direction == GPIO_OUT) { 200 if (direction == GPIO_OUT) {
202 if (line >= 0 && line < 16) { 201 if (line >= 0 && line <= EP93XX_GPIO_LINE_MAX_IRQ) {
203 /* Port A/B. */ 202 /* Port A/B/F */
204 gpio_int_unmasked[line >> 3] &= ~(1 << (line & 7)); 203 gpio_int_unmasked[line >> 3] &= ~(1 << (line & 7));
205 update_gpio_int_params(line >> 3); 204 update_gpio_int_params(line >> 3);
206 } else if (line >= 40 && line < 48) {
207 /* Port F. */
208 gpio_int_unmasked[2] &= ~(1 << (line & 7));
209 update_gpio_int_params(2);
210 } 205 }
211 206
212 v = __raw_readb(data_direction_register); 207 v = __raw_readb(data_direction_register);
@@ -219,39 +214,58 @@ void gpio_line_config(int line, int direction)
219 } 214 }
220 local_irq_restore(flags); 215 local_irq_restore(flags);
221} 216}
222EXPORT_SYMBOL(gpio_line_config);
223 217
224int gpio_line_get(int line) 218int gpio_direction_input(unsigned gpio)
219{
220 if (gpio > EP93XX_GPIO_LINE_MAX)
221 return -EINVAL;
222
223 ep93xx_gpio_set_direction(gpio, GPIO_IN);
224
225 return 0;
226}
227EXPORT_SYMBOL(gpio_direction_input);
228
229int gpio_direction_output(unsigned gpio, int value)
230{
231 if (gpio > EP93XX_GPIO_LINE_MAX)
232 return -EINVAL;
233
234 gpio_set_value(gpio, value);
235 ep93xx_gpio_set_direction(gpio, GPIO_OUT);
236
237 return 0;
238}
239EXPORT_SYMBOL(gpio_direction_output);
240
241int gpio_get_value(unsigned gpio)
225{ 242{
226 unsigned int data_register; 243 unsigned int data_register;
227 244
228 data_register = EP93XX_GPIO_REG(data_register_offset[line >> 3]); 245 data_register = EP93XX_GPIO_REG(data_register_offset[gpio >> 3]);
229 246
230 return !!(__raw_readb(data_register) & (1 << (line & 7))); 247 return !!(__raw_readb(data_register) & (1 << (gpio & 7)));
231} 248}
232EXPORT_SYMBOL(gpio_line_get); 249EXPORT_SYMBOL(gpio_get_value);
233 250
234void gpio_line_set(int line, int value) 251void gpio_set_value(unsigned gpio, int value)
235{ 252{
236 unsigned int data_register; 253 unsigned int data_register;
237 unsigned long flags; 254 unsigned long flags;
238 unsigned char v; 255 unsigned char v;
239 256
240 data_register = EP93XX_GPIO_REG(data_register_offset[line >> 3]); 257 data_register = EP93XX_GPIO_REG(data_register_offset[gpio >> 3]);
241 258
242 local_irq_save(flags); 259 local_irq_save(flags);
243 if (value == EP93XX_GPIO_HIGH) { 260 v = __raw_readb(data_register);
244 v = __raw_readb(data_register); 261 if (value)
245 v |= 1 << (line & 7); 262 v |= 1 << (gpio & 7);
246 __raw_writeb(v, data_register); 263 else
247 } else if (value == EP93XX_GPIO_LOW) { 264 v &= ~(1 << (gpio & 7));
248 v = __raw_readb(data_register); 265 __raw_writeb(v, data_register);
249 v &= ~(1 << (line & 7));
250 __raw_writeb(v, data_register);
251 }
252 local_irq_restore(flags); 266 local_irq_restore(flags);
253} 267}
254EXPORT_SYMBOL(gpio_line_set); 268EXPORT_SYMBOL(gpio_set_value);
255 269
256 270
257/************************************************************************* 271/*************************************************************************
@@ -265,47 +279,67 @@ static void ep93xx_gpio_ab_irq_handler(unsigned int irq, struct irq_desc *desc)
265 status = __raw_readb(EP93XX_GPIO_A_INT_STATUS); 279 status = __raw_readb(EP93XX_GPIO_A_INT_STATUS);
266 for (i = 0; i < 8; i++) { 280 for (i = 0; i < 8; i++) {
267 if (status & (1 << i)) { 281 if (status & (1 << i)) {
268 desc = irq_desc + IRQ_EP93XX_GPIO(0) + i; 282 int gpio_irq = gpio_to_irq(EP93XX_GPIO_LINE_A(0)) + i;
269 desc_handle_irq(IRQ_EP93XX_GPIO(0) + i, desc); 283 desc = irq_desc + gpio_irq;
284 desc_handle_irq(gpio_irq, desc);
270 } 285 }
271 } 286 }
272 287
273 status = __raw_readb(EP93XX_GPIO_B_INT_STATUS); 288 status = __raw_readb(EP93XX_GPIO_B_INT_STATUS);
274 for (i = 0; i < 8; i++) { 289 for (i = 0; i < 8; i++) {
275 if (status & (1 << i)) { 290 if (status & (1 << i)) {
276 desc = irq_desc + IRQ_EP93XX_GPIO(8) + i; 291 int gpio_irq = gpio_to_irq(EP93XX_GPIO_LINE_B(0)) + i;
277 desc_handle_irq(IRQ_EP93XX_GPIO(8) + i, desc); 292 desc = irq_desc + gpio_irq;
293 desc_handle_irq(gpio_irq, desc);
278 } 294 }
279 } 295 }
280} 296}
281 297
282static void ep93xx_gpio_f_irq_handler(unsigned int irq, struct irq_desc *desc) 298static void ep93xx_gpio_f_irq_handler(unsigned int irq, struct irq_desc *desc)
283{ 299{
284 int gpio_irq = IRQ_EP93XX_GPIO(16) + (((irq + 1) & 7) ^ 4); 300 /*
301 * map discontiguous hw irq range to continous sw irq range:
302 *
303 * IRQ_EP93XX_GPIO{0..7}MUX -> gpio_to_irq(EP93XX_GPIO_LINE_F({0..7})
304 */
305 int port_f_idx = ((irq + 1) & 7) ^ 4; /* {19..22,47..50} -> {0..7} */
306 int gpio_irq = gpio_to_irq(EP93XX_GPIO_LINE_F(0)) + port_f_idx;
285 307
286 desc_handle_irq(gpio_irq, irq_desc + gpio_irq); 308 desc_handle_irq(gpio_irq, irq_desc + gpio_irq);
287} 309}
288 310
311static void ep93xx_gpio_irq_ack(unsigned int irq)
312{
313 int line = irq_to_gpio(irq);
314 int port = line >> 3;
315 int port_mask = 1 << (line & 7);
316
317 if ((irq_desc[irq].status & IRQ_TYPE_SENSE_MASK) == IRQT_BOTHEDGE) {
318 gpio_int_type2[port] ^= port_mask; /* switch edge direction */
319 update_gpio_int_params(port);
320 }
321
322 __raw_writeb(port_mask, EP93XX_GPIO_REG(eoi_register_offset[port]));
323}
324
289static void ep93xx_gpio_irq_mask_ack(unsigned int irq) 325static void ep93xx_gpio_irq_mask_ack(unsigned int irq)
290{ 326{
291 int line = irq - IRQ_EP93XX_GPIO(0); 327 int line = irq_to_gpio(irq);
292 int port = line >> 3; 328 int port = line >> 3;
329 int port_mask = 1 << (line & 7);
293 330
294 gpio_int_unmasked[port] &= ~(1 << (line & 7)); 331 if ((irq_desc[irq].status & IRQ_TYPE_SENSE_MASK) == IRQT_BOTHEDGE)
332 gpio_int_type2[port] ^= port_mask; /* switch edge direction */
333
334 gpio_int_unmasked[port] &= ~port_mask;
295 update_gpio_int_params(port); 335 update_gpio_int_params(port);
296 336
297 if (port == 0) { 337 __raw_writeb(port_mask, EP93XX_GPIO_REG(eoi_register_offset[port]));
298 __raw_writel(1 << (line & 7), EP93XX_GPIO_A_INT_ACK);
299 } else if (port == 1) {
300 __raw_writel(1 << (line & 7), EP93XX_GPIO_B_INT_ACK);
301 } else if (port == 2) {
302 __raw_writel(1 << (line & 7), EP93XX_GPIO_F_INT_ACK);
303 }
304} 338}
305 339
306static void ep93xx_gpio_irq_mask(unsigned int irq) 340static void ep93xx_gpio_irq_mask(unsigned int irq)
307{ 341{
308 int line = irq - IRQ_EP93XX_GPIO(0); 342 int line = irq_to_gpio(irq);
309 int port = line >> 3; 343 int port = line >> 3;
310 344
311 gpio_int_unmasked[port] &= ~(1 << (line & 7)); 345 gpio_int_unmasked[port] &= ~(1 << (line & 7));
@@ -314,7 +348,7 @@ static void ep93xx_gpio_irq_mask(unsigned int irq)
314 348
315static void ep93xx_gpio_irq_unmask(unsigned int irq) 349static void ep93xx_gpio_irq_unmask(unsigned int irq)
316{ 350{
317 int line = irq - IRQ_EP93XX_GPIO(0); 351 int line = irq_to_gpio(irq);
318 int port = line >> 3; 352 int port = line >> 3;
319 353
320 gpio_int_unmasked[port] |= 1 << (line & 7); 354 gpio_int_unmasked[port] |= 1 << (line & 7);
@@ -329,38 +363,54 @@ static void ep93xx_gpio_irq_unmask(unsigned int irq)
329 */ 363 */
330static int ep93xx_gpio_irq_type(unsigned int irq, unsigned int type) 364static int ep93xx_gpio_irq_type(unsigned int irq, unsigned int type)
331{ 365{
332 int port; 366 struct irq_desc *desc = irq_desc + irq;
333 int line; 367 const int gpio = irq_to_gpio(irq);
334 368 const int port = gpio >> 3;
335 line = irq - IRQ_EP93XX_GPIO(0); 369 const int port_mask = 1 << (gpio & 7);
336 if (line >= 0 && line < 16) { 370
337 gpio_line_config(line, GPIO_IN); 371 ep93xx_gpio_set_direction(gpio, GPIO_IN);
338 } else { 372
339 gpio_line_config(EP93XX_GPIO_LINE_F(line-16), GPIO_IN); 373 switch (type) {
374 case IRQT_RISING:
375 gpio_int_type1[port] |= port_mask;
376 gpio_int_type2[port] |= port_mask;
377 desc->handle_irq = handle_edge_irq;
378 break;
379 case IRQT_FALLING:
380 gpio_int_type1[port] |= port_mask;
381 gpio_int_type2[port] &= ~port_mask;
382 desc->handle_irq = handle_edge_irq;
383 break;
384 case IRQT_HIGH:
385 gpio_int_type1[port] &= ~port_mask;
386 gpio_int_type2[port] |= port_mask;
387 desc->handle_irq = handle_level_irq;
388 break;
389 case IRQT_LOW:
390 gpio_int_type1[port] &= ~port_mask;
391 gpio_int_type2[port] &= ~port_mask;
392 desc->handle_irq = handle_level_irq;
393 break;
394 case IRQT_BOTHEDGE:
395 gpio_int_type1[port] |= port_mask;
396 /* set initial polarity based on current input level */
397 if (gpio_get_value(gpio))
398 gpio_int_type2[port] &= ~port_mask; /* falling */
399 else
400 gpio_int_type2[port] |= port_mask; /* rising */
401 desc->handle_irq = handle_edge_irq;
402 break;
403 default:
404 pr_err("ep93xx: failed to set irq type %d for gpio %d\n",
405 type, gpio);
406 return -EINVAL;
340 } 407 }
341 408
342 port = line >> 3; 409 gpio_int_enabled[port] |= port_mask;
343 line &= 7; 410
344 411 desc->status &= ~IRQ_TYPE_SENSE_MASK;
345 if (type & IRQT_RISING) { 412 desc->status |= type & IRQ_TYPE_SENSE_MASK;
346 gpio_int_enabled[port] |= 1 << line; 413
347 gpio_int_type1[port] |= 1 << line;
348 gpio_int_type2[port] |= 1 << line;
349 } else if (type & IRQT_FALLING) {
350 gpio_int_enabled[port] |= 1 << line;
351 gpio_int_type1[port] |= 1 << line;
352 gpio_int_type2[port] &= ~(1 << line);
353 } else if (type & IRQT_HIGH) {
354 gpio_int_enabled[port] |= 1 << line;
355 gpio_int_type1[port] &= ~(1 << line);
356 gpio_int_type2[port] |= 1 << line;
357 } else if (type & IRQT_LOW) {
358 gpio_int_enabled[port] |= 1 << line;
359 gpio_int_type1[port] &= ~(1 << line);
360 gpio_int_type2[port] &= ~(1 << line);
361 } else {
362 gpio_int_enabled[port] &= ~(1 << line);
363 }
364 update_gpio_int_params(port); 414 update_gpio_int_params(port);
365 415
366 return 0; 416 return 0;
@@ -368,7 +418,8 @@ static int ep93xx_gpio_irq_type(unsigned int irq, unsigned int type)
368 418
369static struct irq_chip ep93xx_gpio_irq_chip = { 419static struct irq_chip ep93xx_gpio_irq_chip = {
370 .name = "GPIO", 420 .name = "GPIO",
371 .ack = ep93xx_gpio_irq_mask_ack, 421 .ack = ep93xx_gpio_irq_ack,
422 .mask_ack = ep93xx_gpio_irq_mask_ack,
372 .mask = ep93xx_gpio_irq_mask, 423 .mask = ep93xx_gpio_irq_mask,
373 .unmask = ep93xx_gpio_irq_unmask, 424 .unmask = ep93xx_gpio_irq_unmask,
374 .set_type = ep93xx_gpio_irq_type, 425 .set_type = ep93xx_gpio_irq_type,
@@ -377,15 +428,16 @@ static struct irq_chip ep93xx_gpio_irq_chip = {
377 428
378void __init ep93xx_init_irq(void) 429void __init ep93xx_init_irq(void)
379{ 430{
380 int irq; 431 int gpio_irq;
381 432
382 vic_init((void *)EP93XX_VIC1_BASE, 0, EP93XX_VIC1_VALID_IRQ_MASK); 433 vic_init((void *)EP93XX_VIC1_BASE, 0, EP93XX_VIC1_VALID_IRQ_MASK);
383 vic_init((void *)EP93XX_VIC2_BASE, 32, EP93XX_VIC2_VALID_IRQ_MASK); 434 vic_init((void *)EP93XX_VIC2_BASE, 32, EP93XX_VIC2_VALID_IRQ_MASK);
384 435
385 for (irq = IRQ_EP93XX_GPIO(0); irq <= IRQ_EP93XX_GPIO(23); irq++) { 436 for (gpio_irq = gpio_to_irq(0);
386 set_irq_chip(irq, &ep93xx_gpio_irq_chip); 437 gpio_irq <= gpio_to_irq(EP93XX_GPIO_LINE_MAX_IRQ); ++gpio_irq) {
387 set_irq_handler(irq, handle_level_irq); 438 set_irq_chip(gpio_irq, &ep93xx_gpio_irq_chip);
388 set_irq_flags(irq, IRQF_VALID); 439 set_irq_handler(gpio_irq, handle_level_irq);
440 set_irq_flags(gpio_irq, IRQF_VALID);
389 } 441 }
390 442
391 set_irq_chained_handler(IRQ_EP93XX_GPIO_AB, ep93xx_gpio_ab_irq_handler); 443 set_irq_chained_handler(IRQ_EP93XX_GPIO_AB, ep93xx_gpio_ab_irq_handler);