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 | |
Paul Gortmaker | cae39d1 | 2011-07-28 18:46:31 -0400 | [diff] [blame] | 9 | #include <linux/export.h> |
Aurelien Jarno | 34cc662 | 2007-09-25 15:42:09 +0200 | [diff] [blame] | 10 | #include <linux/ssb/ssb.h> |
| 11 | #include <linux/ssb/ssb_driver_chipcommon.h> |
| 12 | #include <linux/ssb/ssb_driver_extif.h> |
| 13 | #include <asm/mach-bcm47xx/bcm47xx.h> |
| 14 | #include <asm/mach-bcm47xx/gpio.h> |
| 15 | |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 16 | #if (BCM47XX_CHIPCO_GPIO_LINES > BCM47XX_EXTIF_GPIO_LINES) |
| 17 | static DECLARE_BITMAP(gpio_in_use, BCM47XX_CHIPCO_GPIO_LINES); |
| 18 | #else |
| 19 | static DECLARE_BITMAP(gpio_in_use, BCM47XX_EXTIF_GPIO_LINES); |
| 20 | #endif |
| 21 | |
| 22 | int gpio_request(unsigned gpio, const char *tag) |
Aurelien Jarno | 34cc662 | 2007-09-25 15:42:09 +0200 | [diff] [blame] | 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 | if (ssb_chipco_available(&bcm47xx_bus.ssb.chipco) && |
| 28 | ((unsigned)gpio >= BCM47XX_CHIPCO_GPIO_LINES)) |
| 29 | return -EINVAL; |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 30 | |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 31 | if (ssb_extif_available(&bcm47xx_bus.ssb.extif) && |
| 32 | ((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES)) |
| 33 | return -EINVAL; |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 34 | |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 35 | if (test_and_set_bit(gpio, gpio_in_use)) |
| 36 | return -EBUSY; |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 37 | |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 38 | return 0; |
Hauke Mehrtens | a656ffc | 2011-07-23 01:20:13 +0200 | [diff] [blame] | 39 | #endif |
Hauke Mehrtens | c1d1c5d | 2011-07-23 01:20:14 +0200 | [diff] [blame] | 40 | #ifdef CONFIG_BCM47XX_BCMA |
| 41 | case BCM47XX_BUS_TYPE_BCMA: |
| 42 | if (gpio >= BCM47XX_CHIPCO_GPIO_LINES) |
| 43 | return -EINVAL; |
| 44 | |
| 45 | if (test_and_set_bit(gpio, gpio_in_use)) |
| 46 | return -EBUSY; |
| 47 | |
| 48 | return 0; |
| 49 | #endif |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 50 | } |
| 51 | return -EINVAL; |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 52 | } |
| 53 | EXPORT_SYMBOL(gpio_request); |
| 54 | |
| 55 | void gpio_free(unsigned gpio) |
| 56 | { |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 57 | switch (bcm47xx_bus_type) { |
Hauke Mehrtens | a656ffc | 2011-07-23 01:20:13 +0200 | [diff] [blame] | 58 | #ifdef CONFIG_BCM47XX_SSB |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 59 | case BCM47XX_BUS_TYPE_SSB: |
| 60 | if (ssb_chipco_available(&bcm47xx_bus.ssb.chipco) && |
| 61 | ((unsigned)gpio >= BCM47XX_CHIPCO_GPIO_LINES)) |
| 62 | return; |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 63 | |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 64 | if (ssb_extif_available(&bcm47xx_bus.ssb.extif) && |
| 65 | ((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES)) |
| 66 | return; |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 67 | |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 68 | clear_bit(gpio, gpio_in_use); |
| 69 | return; |
Hauke Mehrtens | a656ffc | 2011-07-23 01:20:13 +0200 | [diff] [blame] | 70 | #endif |
Hauke Mehrtens | c1d1c5d | 2011-07-23 01:20:14 +0200 | [diff] [blame] | 71 | #ifdef CONFIG_BCM47XX_BCMA |
| 72 | case BCM47XX_BUS_TYPE_BCMA: |
| 73 | if (gpio >= BCM47XX_CHIPCO_GPIO_LINES) |
| 74 | return; |
| 75 | |
| 76 | clear_bit(gpio, gpio_in_use); |
| 77 | return; |
| 78 | #endif |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 79 | } |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 80 | } |
| 81 | EXPORT_SYMBOL(gpio_free); |
| 82 | |
| 83 | int gpio_to_irq(unsigned gpio) |
| 84 | { |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 85 | switch (bcm47xx_bus_type) { |
Hauke Mehrtens | a656ffc | 2011-07-23 01:20:13 +0200 | [diff] [blame] | 86 | #ifdef CONFIG_BCM47XX_SSB |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 87 | case BCM47XX_BUS_TYPE_SSB: |
| 88 | if (ssb_chipco_available(&bcm47xx_bus.ssb.chipco)) |
| 89 | return ssb_mips_irq(bcm47xx_bus.ssb.chipco.dev) + 2; |
| 90 | else if (ssb_extif_available(&bcm47xx_bus.ssb.extif)) |
| 91 | return ssb_mips_irq(bcm47xx_bus.ssb.extif.dev) + 2; |
| 92 | else |
| 93 | return -EINVAL; |
Hauke Mehrtens | a656ffc | 2011-07-23 01:20:13 +0200 | [diff] [blame] | 94 | #endif |
Hauke Mehrtens | c1d1c5d | 2011-07-23 01:20:14 +0200 | [diff] [blame] | 95 | #ifdef CONFIG_BCM47XX_BCMA |
| 96 | case BCM47XX_BUS_TYPE_BCMA: |
| 97 | return bcma_core_mips_irq(bcm47xx_bus.bcma.bus.drv_cc.core) + 2; |
| 98 | #endif |
Hauke Mehrtens | 08ccf572 | 2011-07-23 01:20:12 +0200 | [diff] [blame] | 99 | } |
| 100 | return -EINVAL; |
Aurelien Jarno | 34cc662 | 2007-09-25 15:42:09 +0200 | [diff] [blame] | 101 | } |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 102 | EXPORT_SYMBOL_GPL(gpio_to_irq); |