blob: 2ef17e8df40346f07aea6e01431186686214a1f7 [file] [log] [blame]
Aurelien Jarno34cc6622007-09-25 15:42:09 +02001/*
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 Jarnob06f3e12008-10-14 11:44:26 +020012#include <linux/ssb/ssb_embedded.h>
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +020013#include <linux/bcma/bcma.h>
Aurelien Jarnob06f3e12008-10-14 11:44:26 +020014#include <asm/mach-bcm47xx/bcm47xx.h>
15
Aurelien Jarno34cc6622007-09-25 15:42:09 +020016#define BCM47XX_EXTIF_GPIO_LINES 5
17#define BCM47XX_CHIPCO_GPIO_LINES 16
18
Aurelien Jarnob06f3e12008-10-14 11:44:26 +020019extern int gpio_request(unsigned gpio, const char *label);
20extern void gpio_free(unsigned gpio);
21extern int gpio_to_irq(unsigned gpio);
Aurelien Jarno34cc6622007-09-25 15:42:09 +020022
23static inline int gpio_get_value(unsigned gpio)
24{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020025 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020026#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020027 case BCM47XX_BUS_TYPE_SSB:
28 return ssb_gpio_in(&bcm47xx_bus.ssb, 1 << gpio);
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020029#endif
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +020030#ifdef CONFIG_BCM47XX_BCMA
31 case BCM47XX_BUS_TYPE_BCMA:
32 return bcma_chipco_gpio_in(&bcm47xx_bus.bcma.bus.drv_cc,
33 1 << gpio);
34#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020035 }
36 return -EINVAL;
Aurelien Jarno34cc6622007-09-25 15:42:09 +020037}
38
Florian Fainellidf55a662011-11-04 11:17:46 +010039#define gpio_get_value_cansleep gpio_get_value
40
Aurelien Jarno34cc6622007-09-25 15:42:09 +020041static inline void gpio_set_value(unsigned gpio, int value)
42{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020043 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020044#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020045 case BCM47XX_BUS_TYPE_SSB:
46 ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
47 value ? 1 << gpio : 0);
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +020048 return;
49#endif
50#ifdef CONFIG_BCM47XX_BCMA
51 case BCM47XX_BUS_TYPE_BCMA:
52 bcma_chipco_gpio_out(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
53 value ? 1 << gpio : 0);
54 return;
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020055#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020056 }
Aurelien Jarno34cc6622007-09-25 15:42:09 +020057}
58
Florian Fainellidf55a662011-11-04 11:17:46 +010059#define gpio_set_value_cansleep gpio_set_value
60
61static inline int gpio_cansleep(unsigned gpio)
62{
63 return 0;
64}
65
66static inline int gpio_is_valid(unsigned gpio)
67{
68 return gpio < (BCM47XX_EXTIF_GPIO_LINES + BCM47XX_CHIPCO_GPIO_LINES);
69}
70
71
Aurelien Jarno34cc6622007-09-25 15:42:09 +020072static inline int gpio_direction_input(unsigned gpio)
73{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020074 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020075#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020076 case BCM47XX_BUS_TYPE_SSB:
77 ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 0);
78 return 0;
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020079#endif
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +020080#ifdef CONFIG_BCM47XX_BCMA
81 case BCM47XX_BUS_TYPE_BCMA:
82 bcma_chipco_gpio_outen(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
83 0);
84 return 0;
85#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020086 }
87 return -EINVAL;
Aurelien Jarno34cc6622007-09-25 15:42:09 +020088}
89
90static inline int gpio_direction_output(unsigned gpio, int value)
91{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020092 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020093#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020094 case BCM47XX_BUS_TYPE_SSB:
95 /* first set the gpio out value */
96 ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
97 value ? 1 << gpio : 0);
98 /* then set the gpio mode */
99 ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 1 << gpio);
100 return 0;
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +0200101#endif
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +0200102#ifdef CONFIG_BCM47XX_BCMA
103 case BCM47XX_BUS_TYPE_BCMA:
104 /* first set the gpio out value */
105 bcma_chipco_gpio_out(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
106 value ? 1 << gpio : 0);
107 /* then set the gpio mode */
108 bcma_chipco_gpio_outen(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
109 1 << gpio);
110 return 0;
111#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200112 }
113 return -EINVAL;
Aurelien Jarnob06f3e12008-10-14 11:44:26 +0200114}
115
Michael Buesche0f7ad52009-03-31 15:23:49 -0700116static inline int gpio_intmask(unsigned gpio, int value)
Aurelien Jarnob06f3e12008-10-14 11:44:26 +0200117{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200118 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +0200119#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200120 case BCM47XX_BUS_TYPE_SSB:
121 ssb_gpio_intmask(&bcm47xx_bus.ssb, 1 << gpio,
122 value ? 1 << gpio : 0);
123 return 0;
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +0200124#endif
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +0200125#ifdef CONFIG_BCM47XX_BCMA
126 case BCM47XX_BUS_TYPE_BCMA:
127 bcma_chipco_gpio_intmask(&bcm47xx_bus.bcma.bus.drv_cc,
128 1 << gpio, value ? 1 << gpio : 0);
129 return 0;
130#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200131 }
132 return -EINVAL;
Aurelien Jarnob06f3e12008-10-14 11:44:26 +0200133}
134
Michael Buesche0f7ad52009-03-31 15:23:49 -0700135static inline int gpio_polarity(unsigned gpio, int value)
Aurelien Jarnob06f3e12008-10-14 11:44:26 +0200136{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200137 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +0200138#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200139 case BCM47XX_BUS_TYPE_SSB:
140 ssb_gpio_polarity(&bcm47xx_bus.ssb, 1 << gpio,
141 value ? 1 << gpio : 0);
142 return 0;
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +0200143#endif
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +0200144#ifdef CONFIG_BCM47XX_BCMA
145 case BCM47XX_BUS_TYPE_BCMA:
146 bcma_chipco_gpio_polarity(&bcm47xx_bus.bcma.bus.drv_cc,
147 1 << gpio, value ? 1 << gpio : 0);
148 return 0;
149#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200150 }
151 return -EINVAL;
Aurelien Jarno34cc6622007-09-25 15:42:09 +0200152}
153
154
Aurelien Jarno34cc6622007-09-25 15:42:09 +0200155#endif /* __BCM47XX_GPIO_H */