| sfking@fdwdc.com | af39bb8 | 2009-06-19 18:11:00 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Coldfire generic GPIO support | 
|  | 3 | * | 
|  | 4 | * (C) Copyright 2009, Steven King <sfking@fdwdc.com> | 
|  | 5 | * | 
|  | 6 | * This program is free software; you can redistribute it and/or modify | 
|  | 7 | * it under the terms of the GNU General Public License as published by | 
|  | 8 | * the Free Software Foundation; version 2 of the License. | 
|  | 9 | * | 
|  | 10 | * This program is distributed in the hope that it will be useful, | 
|  | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 13 | * GNU General Public License for more details. | 
|  | 14 | */ | 
|  | 15 |  | 
|  | 16 | #ifndef coldfire_gpio_h | 
|  | 17 | #define coldfire_gpio_h | 
|  | 18 |  | 
|  | 19 | #include <linux/io.h> | 
| sfking@fdwdc.com | af39bb8 | 2009-06-19 18:11:00 -0700 | [diff] [blame] | 20 | #include <asm/coldfire.h> | 
|  | 21 | #include <asm/mcfsim.h> | 
| Steven King | eac5794 | 2012-05-21 13:10:19 -0700 | [diff] [blame] | 22 | #include <asm/mcfgpio.h> | 
| sfking@fdwdc.com | af39bb8 | 2009-06-19 18:11:00 -0700 | [diff] [blame] | 23 | /* | 
|  | 24 | * The Generic GPIO functions | 
|  | 25 | * | 
|  | 26 | * If the gpio is a compile time constant and is one of the Coldfire gpios, | 
|  | 27 | * use the inline version, otherwise dispatch thru gpiolib. | 
|  | 28 | */ | 
|  | 29 |  | 
|  | 30 | static inline int gpio_get_value(unsigned gpio) | 
|  | 31 | { | 
|  | 32 | if (__builtin_constant_p(gpio) && gpio < MCFGPIO_PIN_MAX) | 
| Steven King | eac5794 | 2012-05-21 13:10:19 -0700 | [diff] [blame] | 33 | return mcfgpio_read(__mcfgpio_ppdr(gpio)) & mcfgpio_bit(gpio); | 
| sfking@fdwdc.com | af39bb8 | 2009-06-19 18:11:00 -0700 | [diff] [blame] | 34 | else | 
|  | 35 | return __gpio_get_value(gpio); | 
|  | 36 | } | 
|  | 37 |  | 
|  | 38 | static inline void gpio_set_value(unsigned gpio, int value) | 
|  | 39 | { | 
|  | 40 | if (__builtin_constant_p(gpio) && gpio < MCFGPIO_PIN_MAX) { | 
|  | 41 | if (gpio < MCFGPIO_SCR_START) { | 
|  | 42 | unsigned long flags; | 
|  | 43 | MCFGPIO_PORTTYPE data; | 
|  | 44 |  | 
|  | 45 | local_irq_save(flags); | 
| Steven King | eac5794 | 2012-05-21 13:10:19 -0700 | [diff] [blame] | 46 | data = mcfgpio_read(__mcfgpio_podr(gpio)); | 
| sfking@fdwdc.com | af39bb8 | 2009-06-19 18:11:00 -0700 | [diff] [blame] | 47 | if (value) | 
|  | 48 | data |= mcfgpio_bit(gpio); | 
|  | 49 | else | 
|  | 50 | data &= ~mcfgpio_bit(gpio); | 
| Steven King | eac5794 | 2012-05-21 13:10:19 -0700 | [diff] [blame] | 51 | mcfgpio_write(data, __mcfgpio_podr(gpio)); | 
| sfking@fdwdc.com | af39bb8 | 2009-06-19 18:11:00 -0700 | [diff] [blame] | 52 | local_irq_restore(flags); | 
|  | 53 | } else { | 
|  | 54 | if (value) | 
|  | 55 | mcfgpio_write(mcfgpio_bit(gpio), | 
|  | 56 | MCFGPIO_SETR_PORT(gpio)); | 
|  | 57 | else | 
|  | 58 | mcfgpio_write(~mcfgpio_bit(gpio), | 
|  | 59 | MCFGPIO_CLRR_PORT(gpio)); | 
|  | 60 | } | 
|  | 61 | } else | 
|  | 62 | __gpio_set_value(gpio, value); | 
|  | 63 | } | 
|  | 64 |  | 
|  | 65 | static inline int gpio_to_irq(unsigned gpio) | 
|  | 66 | { | 
| Steven King | bea8bcb | 2012-06-06 14:28:31 -0700 | [diff] [blame] | 67 | #if defined(MCFGPIO_IRQ_MIN) | 
|  | 68 | if ((gpio >= MCFGPIO_IRQ_MIN) && (gpio < MCFGPIO_IRQ_MAX)) | 
|  | 69 | #else | 
|  | 70 | if (gpio < MCFGPIO_IRQ_MAX) | 
|  | 71 | #endif | 
|  | 72 | return gpio + MCFGPIO_IRQ_VECBASE; | 
|  | 73 | else | 
|  | 74 | return __gpio_to_irq(gpio); | 
| sfking@fdwdc.com | af39bb8 | 2009-06-19 18:11:00 -0700 | [diff] [blame] | 75 | } | 
|  | 76 |  | 
|  | 77 | static inline int irq_to_gpio(unsigned irq) | 
|  | 78 | { | 
|  | 79 | return (irq >= MCFGPIO_IRQ_VECBASE && | 
|  | 80 | irq < (MCFGPIO_IRQ_VECBASE + MCFGPIO_IRQ_MAX)) ? | 
|  | 81 | irq - MCFGPIO_IRQ_VECBASE : -ENXIO; | 
|  | 82 | } | 
|  | 83 |  | 
|  | 84 | static inline int gpio_cansleep(unsigned gpio) | 
|  | 85 | { | 
|  | 86 | return gpio < MCFGPIO_PIN_MAX ? 0 : __gpio_cansleep(gpio); | 
|  | 87 | } | 
|  | 88 |  | 
|  | 89 | #endif |