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) { |
Hauke Mehrtens | a656ffc | 2011-07-23 01:20:13 +0200 | [diff] [blame^] | 25 | #ifdef CONFIG_BCM47XX_SSB |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 26 | case BCM47XX_BUS_TYPE_SSB: |
| 27 | return ssb_gpio_in(&bcm47xx_bus.ssb, 1 << gpio); |
Hauke Mehrtens | a656ffc | 2011-07-23 01:20:13 +0200 | [diff] [blame^] | 28 | #endif |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 29 | } |
| 30 | return -EINVAL; |
Aurelien Jarno | 34cc662 | 2007-09-25 15:42:09 +0200 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | static inline void gpio_set_value(unsigned gpio, int value) |
| 34 | { |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 35 | switch (bcm47xx_bus_type) { |
Hauke Mehrtens | a656ffc | 2011-07-23 01:20:13 +0200 | [diff] [blame^] | 36 | #ifdef CONFIG_BCM47XX_SSB |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 37 | case BCM47XX_BUS_TYPE_SSB: |
| 38 | ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio, |
| 39 | value ? 1 << gpio : 0); |
Hauke Mehrtens | a656ffc | 2011-07-23 01:20:13 +0200 | [diff] [blame^] | 40 | #endif |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 41 | } |
Aurelien Jarno | 34cc662 | 2007-09-25 15:42:09 +0200 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static inline int gpio_direction_input(unsigned gpio) |
| 45 | { |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 46 | switch (bcm47xx_bus_type) { |
Hauke Mehrtens | a656ffc | 2011-07-23 01:20:13 +0200 | [diff] [blame^] | 47 | #ifdef CONFIG_BCM47XX_SSB |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 48 | case BCM47XX_BUS_TYPE_SSB: |
| 49 | ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 0); |
| 50 | return 0; |
Hauke Mehrtens | a656ffc | 2011-07-23 01:20:13 +0200 | [diff] [blame^] | 51 | #endif |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 52 | } |
| 53 | return -EINVAL; |
Aurelien Jarno | 34cc662 | 2007-09-25 15:42:09 +0200 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | static inline int gpio_direction_output(unsigned gpio, int value) |
| 57 | { |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 58 | switch (bcm47xx_bus_type) { |
Hauke Mehrtens | a656ffc | 2011-07-23 01:20:13 +0200 | [diff] [blame^] | 59 | #ifdef CONFIG_BCM47XX_SSB |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 60 | case BCM47XX_BUS_TYPE_SSB: |
| 61 | /* first set the gpio out value */ |
| 62 | ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio, |
| 63 | value ? 1 << gpio : 0); |
| 64 | /* then set the gpio mode */ |
| 65 | ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 1 << gpio); |
| 66 | return 0; |
Hauke Mehrtens | a656ffc | 2011-07-23 01:20:13 +0200 | [diff] [blame^] | 67 | #endif |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 68 | } |
| 69 | return -EINVAL; |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 70 | } |
| 71 | |
Michael Buesch | e0f7ad5 | 2009-03-31 15:23:49 -0700 | [diff] [blame] | 72 | static inline int gpio_intmask(unsigned gpio, int value) |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 73 | { |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 74 | switch (bcm47xx_bus_type) { |
Hauke Mehrtens | a656ffc | 2011-07-23 01:20:13 +0200 | [diff] [blame^] | 75 | #ifdef CONFIG_BCM47XX_SSB |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 76 | case BCM47XX_BUS_TYPE_SSB: |
| 77 | ssb_gpio_intmask(&bcm47xx_bus.ssb, 1 << gpio, |
| 78 | value ? 1 << gpio : 0); |
| 79 | return 0; |
Hauke Mehrtens | a656ffc | 2011-07-23 01:20:13 +0200 | [diff] [blame^] | 80 | #endif |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 81 | } |
| 82 | return -EINVAL; |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 83 | } |
| 84 | |
Michael Buesch | e0f7ad5 | 2009-03-31 15:23:49 -0700 | [diff] [blame] | 85 | static inline int gpio_polarity(unsigned gpio, int value) |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 86 | { |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 87 | switch (bcm47xx_bus_type) { |
Hauke Mehrtens | a656ffc | 2011-07-23 01:20:13 +0200 | [diff] [blame^] | 88 | #ifdef CONFIG_BCM47XX_SSB |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 89 | case BCM47XX_BUS_TYPE_SSB: |
| 90 | ssb_gpio_polarity(&bcm47xx_bus.ssb, 1 << gpio, |
| 91 | value ? 1 << gpio : 0); |
| 92 | return 0; |
Hauke Mehrtens | a656ffc | 2011-07-23 01:20:13 +0200 | [diff] [blame^] | 93 | #endif |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 94 | } |
| 95 | return -EINVAL; |
Aurelien Jarno | 34cc662 | 2007-09-25 15:42:09 +0200 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
| 99 | /* cansleep wrappers */ |
| 100 | #include <asm-generic/gpio.h> |
| 101 | |
| 102 | #endif /* __BCM47XX_GPIO_H */ |