Aurelien Jarno | 34cc662 | 2007-09-25 15:42:09 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 2007 Aurelien Jarno <aurelien@aurel32.net> |
| 7 | */ |
| 8 | |
| 9 | #ifndef __BCM47XX_GPIO_H |
| 10 | #define __BCM47XX_GPIO_H |
| 11 | |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 12 | #include <linux/ssb/ssb_embedded.h> |
| 13 | #include <asm/mach-bcm47xx/bcm47xx.h> |
| 14 | |
Aurelien Jarno | 34cc662 | 2007-09-25 15:42:09 +0200 | [diff] [blame] | 15 | #define BCM47XX_EXTIF_GPIO_LINES 5 |
| 16 | #define BCM47XX_CHIPCO_GPIO_LINES 16 |
| 17 | |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 18 | extern int gpio_request(unsigned gpio, const char *label); |
| 19 | extern void gpio_free(unsigned gpio); |
| 20 | extern int gpio_to_irq(unsigned gpio); |
Aurelien Jarno | 34cc662 | 2007-09-25 15:42:09 +0200 | [diff] [blame] | 21 | |
| 22 | static inline int gpio_get_value(unsigned gpio) |
| 23 | { |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame^] | 24 | switch (bcm47xx_bus_type) { |
| 25 | case BCM47XX_BUS_TYPE_SSB: |
| 26 | return ssb_gpio_in(&bcm47xx_bus.ssb, 1 << gpio); |
| 27 | } |
| 28 | return -EINVAL; |
Aurelien Jarno | 34cc662 | 2007-09-25 15:42:09 +0200 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static inline void gpio_set_value(unsigned gpio, int value) |
| 32 | { |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame^] | 33 | switch (bcm47xx_bus_type) { |
| 34 | case BCM47XX_BUS_TYPE_SSB: |
| 35 | ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio, |
| 36 | value ? 1 << gpio : 0); |
| 37 | } |
Aurelien Jarno | 34cc662 | 2007-09-25 15:42:09 +0200 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | static inline int gpio_direction_input(unsigned gpio) |
| 41 | { |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame^] | 42 | switch (bcm47xx_bus_type) { |
| 43 | case BCM47XX_BUS_TYPE_SSB: |
| 44 | ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 0); |
| 45 | return 0; |
| 46 | } |
| 47 | return -EINVAL; |
Aurelien Jarno | 34cc662 | 2007-09-25 15:42:09 +0200 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static inline int gpio_direction_output(unsigned gpio, int value) |
| 51 | { |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame^] | 52 | switch (bcm47xx_bus_type) { |
| 53 | case BCM47XX_BUS_TYPE_SSB: |
| 54 | /* first set the gpio out value */ |
| 55 | ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio, |
| 56 | value ? 1 << gpio : 0); |
| 57 | /* then set the gpio mode */ |
| 58 | ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 1 << gpio); |
| 59 | return 0; |
| 60 | } |
| 61 | return -EINVAL; |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 62 | } |
| 63 | |
Michael Buesch | e0f7ad5 | 2009-03-31 15:23:49 -0700 | [diff] [blame] | 64 | static inline int gpio_intmask(unsigned gpio, int value) |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 65 | { |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame^] | 66 | switch (bcm47xx_bus_type) { |
| 67 | case BCM47XX_BUS_TYPE_SSB: |
| 68 | ssb_gpio_intmask(&bcm47xx_bus.ssb, 1 << gpio, |
| 69 | value ? 1 << gpio : 0); |
| 70 | return 0; |
| 71 | } |
| 72 | return -EINVAL; |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 73 | } |
| 74 | |
Michael Buesch | e0f7ad5 | 2009-03-31 15:23:49 -0700 | [diff] [blame] | 75 | static inline int gpio_polarity(unsigned gpio, int value) |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 76 | { |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame^] | 77 | switch (bcm47xx_bus_type) { |
| 78 | case BCM47XX_BUS_TYPE_SSB: |
| 79 | ssb_gpio_polarity(&bcm47xx_bus.ssb, 1 << gpio, |
| 80 | value ? 1 << gpio : 0); |
| 81 | return 0; |
| 82 | } |
| 83 | return -EINVAL; |
Aurelien Jarno | 34cc662 | 2007-09-25 15:42:09 +0200 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | |
| 87 | /* cansleep wrappers */ |
| 88 | #include <asm-generic/gpio.h> |
| 89 | |
| 90 | #endif /* __BCM47XX_GPIO_H */ |