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 | #include <linux/ssb/ssb.h> |
| 10 | #include <linux/ssb/ssb_driver_chipcommon.h> |
| 11 | #include <linux/ssb/ssb_driver_extif.h> |
| 12 | #include <asm/mach-bcm47xx/bcm47xx.h> |
| 13 | #include <asm/mach-bcm47xx/gpio.h> |
| 14 | |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 15 | #if (BCM47XX_CHIPCO_GPIO_LINES > BCM47XX_EXTIF_GPIO_LINES) |
| 16 | static DECLARE_BITMAP(gpio_in_use, BCM47XX_CHIPCO_GPIO_LINES); |
| 17 | #else |
| 18 | static DECLARE_BITMAP(gpio_in_use, BCM47XX_EXTIF_GPIO_LINES); |
| 19 | #endif |
| 20 | |
| 21 | int gpio_request(unsigned gpio, const char *tag) |
Aurelien Jarno | 34cc662 | 2007-09-25 15:42:09 +0200 | [diff] [blame] | 22 | { |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame^] | 23 | switch (bcm47xx_bus_type) { |
| 24 | case BCM47XX_BUS_TYPE_SSB: |
| 25 | if (ssb_chipco_available(&bcm47xx_bus.ssb.chipco) && |
| 26 | ((unsigned)gpio >= BCM47XX_CHIPCO_GPIO_LINES)) |
| 27 | return -EINVAL; |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 28 | |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame^] | 29 | if (ssb_extif_available(&bcm47xx_bus.ssb.extif) && |
| 30 | ((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES)) |
| 31 | return -EINVAL; |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 32 | |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame^] | 33 | if (test_and_set_bit(gpio, gpio_in_use)) |
| 34 | return -EBUSY; |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 35 | |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame^] | 36 | return 0; |
| 37 | } |
| 38 | return -EINVAL; |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 39 | } |
| 40 | EXPORT_SYMBOL(gpio_request); |
| 41 | |
| 42 | void gpio_free(unsigned gpio) |
| 43 | { |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame^] | 44 | switch (bcm47xx_bus_type) { |
| 45 | case BCM47XX_BUS_TYPE_SSB: |
| 46 | if (ssb_chipco_available(&bcm47xx_bus.ssb.chipco) && |
| 47 | ((unsigned)gpio >= BCM47XX_CHIPCO_GPIO_LINES)) |
| 48 | return; |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 49 | |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame^] | 50 | if (ssb_extif_available(&bcm47xx_bus.ssb.extif) && |
| 51 | ((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES)) |
| 52 | return; |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 53 | |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame^] | 54 | clear_bit(gpio, gpio_in_use); |
| 55 | return; |
| 56 | } |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 57 | } |
| 58 | EXPORT_SYMBOL(gpio_free); |
| 59 | |
| 60 | int gpio_to_irq(unsigned gpio) |
| 61 | { |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame^] | 62 | switch (bcm47xx_bus_type) { |
| 63 | case BCM47XX_BUS_TYPE_SSB: |
| 64 | if (ssb_chipco_available(&bcm47xx_bus.ssb.chipco)) |
| 65 | return ssb_mips_irq(bcm47xx_bus.ssb.chipco.dev) + 2; |
| 66 | else if (ssb_extif_available(&bcm47xx_bus.ssb.extif)) |
| 67 | return ssb_mips_irq(bcm47xx_bus.ssb.extif.dev) + 2; |
| 68 | else |
| 69 | return -EINVAL; |
| 70 | } |
| 71 | return -EINVAL; |
Aurelien Jarno | 34cc662 | 2007-09-25 15:42:09 +0200 | [diff] [blame] | 72 | } |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 73 | EXPORT_SYMBOL_GPL(gpio_to_irq); |