diff options
Diffstat (limited to 'arch/mips/jz4740/gpio.c')
-rw-r--r-- | arch/mips/jz4740/gpio.c | 123 |
1 files changed, 56 insertions, 67 deletions
diff --git a/arch/mips/jz4740/gpio.c b/arch/mips/jz4740/gpio.c index 38f60f35156c..73031f7fc827 100644 --- a/arch/mips/jz4740/gpio.c +++ b/arch/mips/jz4740/gpio.c | |||
@@ -86,7 +86,6 @@ struct jz_gpio_chip { | |||
86 | spinlock_t lock; | 86 | spinlock_t lock; |
87 | 87 | ||
88 | struct gpio_chip gpio_chip; | 88 | struct gpio_chip gpio_chip; |
89 | struct irq_chip irq_chip; | ||
90 | struct sys_device sysdev; | 89 | struct sys_device sysdev; |
91 | }; | 90 | }; |
92 | 91 | ||
@@ -102,9 +101,9 @@ static inline struct jz_gpio_chip *gpio_chip_to_jz_gpio_chip(struct gpio_chip *g | |||
102 | return container_of(gpio_chip, struct jz_gpio_chip, gpio_chip); | 101 | return container_of(gpio_chip, struct jz_gpio_chip, gpio_chip); |
103 | } | 102 | } |
104 | 103 | ||
105 | static inline struct jz_gpio_chip *irq_to_jz_gpio_chip(unsigned int irq) | 104 | static inline struct jz_gpio_chip *irq_to_jz_gpio_chip(struct irq_data *data) |
106 | { | 105 | { |
107 | return get_irq_chip_data(irq); | 106 | return irq_data_get_irq_chip_data(data); |
108 | } | 107 | } |
109 | 108 | ||
110 | static inline void jz_gpio_write_bit(unsigned int gpio, unsigned int reg) | 109 | static inline void jz_gpio_write_bit(unsigned int gpio, unsigned int reg) |
@@ -307,7 +306,7 @@ static void jz_gpio_irq_demux_handler(unsigned int irq, struct irq_desc *desc) | |||
307 | uint32_t flag; | 306 | uint32_t flag; |
308 | unsigned int gpio_irq; | 307 | unsigned int gpio_irq; |
309 | unsigned int gpio_bank; | 308 | unsigned int gpio_bank; |
310 | struct jz_gpio_chip *chip = get_irq_desc_data(desc); | 309 | struct jz_gpio_chip *chip = irq_desc_get_handler_data(desc); |
311 | 310 | ||
312 | gpio_bank = JZ4740_IRQ_GPIO0 - irq; | 311 | gpio_bank = JZ4740_IRQ_GPIO0 - irq; |
313 | 312 | ||
@@ -325,62 +324,52 @@ static void jz_gpio_irq_demux_handler(unsigned int irq, struct irq_desc *desc) | |||
325 | generic_handle_irq(gpio_irq); | 324 | generic_handle_irq(gpio_irq); |
326 | }; | 325 | }; |
327 | 326 | ||
328 | static inline void jz_gpio_set_irq_bit(unsigned int irq, unsigned int reg) | 327 | static inline void jz_gpio_set_irq_bit(struct irq_data *data, unsigned int reg) |
329 | { | 328 | { |
330 | struct jz_gpio_chip *chip = irq_to_jz_gpio_chip(irq); | 329 | struct jz_gpio_chip *chip = irq_to_jz_gpio_chip(data); |
331 | writel(IRQ_TO_BIT(irq), chip->base + reg); | 330 | writel(IRQ_TO_BIT(data->irq), chip->base + reg); |
332 | } | 331 | } |
333 | 332 | ||
334 | static void jz_gpio_irq_mask(unsigned int irq) | 333 | static void jz_gpio_irq_mask(struct irq_data *data) |
335 | { | 334 | { |
336 | jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_MASK_SET); | 335 | jz_gpio_set_irq_bit(data, JZ_REG_GPIO_MASK_SET); |
337 | }; | 336 | }; |
338 | 337 | ||
339 | static void jz_gpio_irq_unmask(unsigned int irq) | 338 | static void jz_gpio_irq_unmask(struct irq_data *data) |
340 | { | 339 | { |
341 | struct jz_gpio_chip *chip = irq_to_jz_gpio_chip(irq); | 340 | struct jz_gpio_chip *chip = irq_to_jz_gpio_chip(data); |
342 | 341 | ||
343 | jz_gpio_check_trigger_both(chip, irq); | 342 | jz_gpio_check_trigger_both(chip, data->irq); |
344 | 343 | ||
345 | jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_MASK_CLEAR); | 344 | jz_gpio_set_irq_bit(data, JZ_REG_GPIO_MASK_CLEAR); |
346 | }; | 345 | }; |
347 | 346 | ||
348 | /* TODO: Check if function is gpio */ | 347 | /* TODO: Check if function is gpio */ |
349 | static unsigned int jz_gpio_irq_startup(unsigned int irq) | 348 | static unsigned int jz_gpio_irq_startup(struct irq_data *data) |
350 | { | 349 | { |
351 | struct irq_desc *desc = irq_to_desc(irq); | 350 | jz_gpio_set_irq_bit(data, JZ_REG_GPIO_SELECT_SET); |
352 | 351 | jz_gpio_irq_unmask(data); | |
353 | jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_SELECT_SET); | ||
354 | |||
355 | desc->status &= ~IRQ_MASKED; | ||
356 | jz_gpio_irq_unmask(irq); | ||
357 | |||
358 | return 0; | 352 | return 0; |
359 | } | 353 | } |
360 | 354 | ||
361 | static void jz_gpio_irq_shutdown(unsigned int irq) | 355 | static void jz_gpio_irq_shutdown(struct irq_data *data) |
362 | { | 356 | { |
363 | struct irq_desc *desc = irq_to_desc(irq); | 357 | jz_gpio_irq_mask(data); |
364 | |||
365 | jz_gpio_irq_mask(irq); | ||
366 | desc->status |= IRQ_MASKED; | ||
367 | 358 | ||
368 | /* Set direction to input */ | 359 | /* Set direction to input */ |
369 | jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_DIRECTION_CLEAR); | 360 | jz_gpio_set_irq_bit(data, JZ_REG_GPIO_DIRECTION_CLEAR); |
370 | jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_SELECT_CLEAR); | 361 | jz_gpio_set_irq_bit(data, JZ_REG_GPIO_SELECT_CLEAR); |
371 | } | 362 | } |
372 | 363 | ||
373 | static void jz_gpio_irq_ack(unsigned int irq) | 364 | static void jz_gpio_irq_ack(struct irq_data *data) |
374 | { | 365 | { |
375 | jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_FLAG_CLEAR); | 366 | jz_gpio_set_irq_bit(data, JZ_REG_GPIO_FLAG_CLEAR); |
376 | }; | 367 | }; |
377 | 368 | ||
378 | static int jz_gpio_irq_set_type(unsigned int irq, unsigned int flow_type) | 369 | static int jz_gpio_irq_set_type(struct irq_data *data, unsigned int flow_type) |
379 | { | 370 | { |
380 | struct jz_gpio_chip *chip = irq_to_jz_gpio_chip(irq); | 371 | struct jz_gpio_chip *chip = irq_to_jz_gpio_chip(data); |
381 | struct irq_desc *desc = irq_to_desc(irq); | 372 | unsigned int irq = data->irq; |
382 | |||
383 | jz_gpio_irq_mask(irq); | ||
384 | 373 | ||
385 | if (flow_type == IRQ_TYPE_EDGE_BOTH) { | 374 | if (flow_type == IRQ_TYPE_EDGE_BOTH) { |
386 | uint32_t value = readl(chip->base + JZ_REG_GPIO_PIN); | 375 | uint32_t value = readl(chip->base + JZ_REG_GPIO_PIN); |
@@ -395,45 +384,54 @@ static int jz_gpio_irq_set_type(unsigned int irq, unsigned int flow_type) | |||
395 | 384 | ||
396 | switch (flow_type) { | 385 | switch (flow_type) { |
397 | case IRQ_TYPE_EDGE_RISING: | 386 | case IRQ_TYPE_EDGE_RISING: |
398 | jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_DIRECTION_SET); | 387 | jz_gpio_set_irq_bit(data, JZ_REG_GPIO_DIRECTION_SET); |
399 | jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_TRIGGER_SET); | 388 | jz_gpio_set_irq_bit(data, JZ_REG_GPIO_TRIGGER_SET); |
400 | break; | 389 | break; |
401 | case IRQ_TYPE_EDGE_FALLING: | 390 | case IRQ_TYPE_EDGE_FALLING: |
402 | jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_DIRECTION_CLEAR); | 391 | jz_gpio_set_irq_bit(data, JZ_REG_GPIO_DIRECTION_CLEAR); |
403 | jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_TRIGGER_SET); | 392 | jz_gpio_set_irq_bit(data, JZ_REG_GPIO_TRIGGER_SET); |
404 | break; | 393 | break; |
405 | case IRQ_TYPE_LEVEL_HIGH: | 394 | case IRQ_TYPE_LEVEL_HIGH: |
406 | jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_DIRECTION_SET); | 395 | jz_gpio_set_irq_bit(data, JZ_REG_GPIO_DIRECTION_SET); |
407 | jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_TRIGGER_CLEAR); | 396 | jz_gpio_set_irq_bit(data, JZ_REG_GPIO_TRIGGER_CLEAR); |
408 | break; | 397 | break; |
409 | case IRQ_TYPE_LEVEL_LOW: | 398 | case IRQ_TYPE_LEVEL_LOW: |
410 | jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_DIRECTION_CLEAR); | 399 | jz_gpio_set_irq_bit(data, JZ_REG_GPIO_DIRECTION_CLEAR); |
411 | jz_gpio_set_irq_bit(irq, JZ_REG_GPIO_TRIGGER_CLEAR); | 400 | jz_gpio_set_irq_bit(data, JZ_REG_GPIO_TRIGGER_CLEAR); |
412 | break; | 401 | break; |
413 | default: | 402 | default: |
414 | return -EINVAL; | 403 | return -EINVAL; |
415 | } | 404 | } |
416 | 405 | ||
417 | if (!(desc->status & IRQ_MASKED)) | ||
418 | jz_gpio_irq_unmask(irq); | ||
419 | |||
420 | return 0; | 406 | return 0; |
421 | } | 407 | } |
422 | 408 | ||
423 | static int jz_gpio_irq_set_wake(unsigned int irq, unsigned int on) | 409 | static int jz_gpio_irq_set_wake(struct irq_data *data, unsigned int on) |
424 | { | 410 | { |
425 | struct jz_gpio_chip *chip = irq_to_jz_gpio_chip(irq); | 411 | struct jz_gpio_chip *chip = irq_to_jz_gpio_chip(data); |
426 | spin_lock(&chip->lock); | 412 | spin_lock(&chip->lock); |
427 | if (on) | 413 | if (on) |
428 | chip->wakeup |= IRQ_TO_BIT(irq); | 414 | chip->wakeup |= IRQ_TO_BIT(data->irq); |
429 | else | 415 | else |
430 | chip->wakeup &= ~IRQ_TO_BIT(irq); | 416 | chip->wakeup &= ~IRQ_TO_BIT(data->irq); |
431 | spin_unlock(&chip->lock); | 417 | spin_unlock(&chip->lock); |
432 | 418 | ||
433 | set_irq_wake(chip->irq, on); | 419 | irq_set_irq_wake(chip->irq, on); |
434 | return 0; | 420 | return 0; |
435 | } | 421 | } |
436 | 422 | ||
423 | static struct irq_chip jz_gpio_irq_chip = { | ||
424 | .name = "GPIO", | ||
425 | .irq_mask = jz_gpio_irq_mask, | ||
426 | .irq_unmask = jz_gpio_irq_unmask, | ||
427 | .irq_ack = jz_gpio_irq_ack, | ||
428 | .irq_startup = jz_gpio_irq_startup, | ||
429 | .irq_shutdown = jz_gpio_irq_shutdown, | ||
430 | .irq_set_type = jz_gpio_irq_set_type, | ||
431 | .irq_set_wake = jz_gpio_irq_set_wake, | ||
432 | .flags = IRQCHIP_SET_TYPE_MASKED, | ||
433 | }; | ||
434 | |||
437 | /* | 435 | /* |
438 | * This lock class tells lockdep that GPIO irqs are in a different | 436 | * This lock class tells lockdep that GPIO irqs are in a different |
439 | * category than their parents, so it won't report false recursion. | 437 | * category than their parents, so it won't report false recursion. |
@@ -452,16 +450,6 @@ static struct lock_class_key gpio_lock_class; | |||
452 | .base = JZ4740_GPIO_BASE_ ## _bank, \ | 450 | .base = JZ4740_GPIO_BASE_ ## _bank, \ |
453 | .ngpio = JZ4740_GPIO_NUM_ ## _bank, \ | 451 | .ngpio = JZ4740_GPIO_NUM_ ## _bank, \ |
454 | }, \ | 452 | }, \ |
455 | .irq_chip = { \ | ||
456 | .name = "GPIO Bank " # _bank, \ | ||
457 | .mask = jz_gpio_irq_mask, \ | ||
458 | .unmask = jz_gpio_irq_unmask, \ | ||
459 | .ack = jz_gpio_irq_ack, \ | ||
460 | .startup = jz_gpio_irq_startup, \ | ||
461 | .shutdown = jz_gpio_irq_shutdown, \ | ||
462 | .set_type = jz_gpio_irq_set_type, \ | ||
463 | .set_wake = jz_gpio_irq_set_wake, \ | ||
464 | }, \ | ||
465 | } | 453 | } |
466 | 454 | ||
467 | static struct jz_gpio_chip jz4740_gpio_chips[] = { | 455 | static struct jz_gpio_chip jz4740_gpio_chips[] = { |
@@ -522,13 +510,14 @@ static int jz4740_gpio_chip_init(struct jz_gpio_chip *chip, unsigned int id) | |||
522 | gpiochip_add(&chip->gpio_chip); | 510 | gpiochip_add(&chip->gpio_chip); |
523 | 511 | ||
524 | chip->irq = JZ4740_IRQ_INTC_GPIO(id); | 512 | chip->irq = JZ4740_IRQ_INTC_GPIO(id); |
525 | set_irq_data(chip->irq, chip); | 513 | irq_set_handler_data(chip->irq, chip); |
526 | set_irq_chained_handler(chip->irq, jz_gpio_irq_demux_handler); | 514 | irq_set_chained_handler(chip->irq, jz_gpio_irq_demux_handler); |
527 | 515 | ||
528 | for (irq = chip->irq_base; irq < chip->irq_base + chip->gpio_chip.ngpio; ++irq) { | 516 | for (irq = chip->irq_base; irq < chip->irq_base + chip->gpio_chip.ngpio; ++irq) { |
529 | lockdep_set_class(&irq_desc[irq].lock, &gpio_lock_class); | 517 | irq_set_lockdep_class(irq, &gpio_lock_class); |
530 | set_irq_chip_data(irq, chip); | 518 | irq_set_chip_data(irq, chip); |
531 | set_irq_chip_and_handler(irq, &chip->irq_chip, handle_level_irq); | 519 | irq_set_chip_and_handler(irq, &jz_gpio_irq_chip, |
520 | handle_level_irq); | ||
532 | } | 521 | } |
533 | 522 | ||
534 | return 0; | 523 | return 0; |
@@ -546,7 +535,7 @@ static int __init jz4740_gpio_init(void) | |||
546 | for (i = 0; i < ARRAY_SIZE(jz4740_gpio_chips); ++i) | 535 | for (i = 0; i < ARRAY_SIZE(jz4740_gpio_chips); ++i) |
547 | jz4740_gpio_chip_init(&jz4740_gpio_chips[i], i); | 536 | jz4740_gpio_chip_init(&jz4740_gpio_chips[i], i); |
548 | 537 | ||
549 | printk(KERN_INFO "JZ4740 GPIO initalized\n"); | 538 | printk(KERN_INFO "JZ4740 GPIO initialized\n"); |
550 | 539 | ||
551 | return 0; | 540 | return 0; |
552 | } | 541 | } |