blob: 76961cabeedfe1cdac4caaef7e9989ca04a345be [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
39static inline void gpio_set_value(unsigned gpio, int value)
40{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020041 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020042#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020043 case BCM47XX_BUS_TYPE_SSB:
44 ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
45 value ? 1 << gpio : 0);
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +020046 return;
47#endif
48#ifdef CONFIG_BCM47XX_BCMA
49 case BCM47XX_BUS_TYPE_BCMA:
50 bcma_chipco_gpio_out(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
51 value ? 1 << gpio : 0);
52 return;
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020053#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020054 }
Aurelien Jarno34cc6622007-09-25 15:42:09 +020055}
56
57static inline int gpio_direction_input(unsigned gpio)
58{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020059 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020060#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020061 case BCM47XX_BUS_TYPE_SSB:
62 ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 0);
63 return 0;
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020064#endif
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +020065#ifdef CONFIG_BCM47XX_BCMA
66 case BCM47XX_BUS_TYPE_BCMA:
67 bcma_chipco_gpio_outen(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
68 0);
69 return 0;
70#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020071 }
72 return -EINVAL;
Aurelien Jarno34cc6622007-09-25 15:42:09 +020073}
74
75static inline int gpio_direction_output(unsigned gpio, int value)
76{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020077 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020078#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020079 case BCM47XX_BUS_TYPE_SSB:
80 /* first set the gpio out value */
81 ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
82 value ? 1 << gpio : 0);
83 /* then set the gpio mode */
84 ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 1 << gpio);
85 return 0;
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020086#endif
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +020087#ifdef CONFIG_BCM47XX_BCMA
88 case BCM47XX_BUS_TYPE_BCMA:
89 /* first set the gpio out value */
90 bcma_chipco_gpio_out(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
91 value ? 1 << gpio : 0);
92 /* then set the gpio mode */
93 bcma_chipco_gpio_outen(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
94 1 << gpio);
95 return 0;
96#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020097 }
98 return -EINVAL;
Aurelien Jarnob06f3e12008-10-14 11:44:26 +020099}
100
Michael Buesche0f7ad52009-03-31 15:23:49 -0700101static inline int gpio_intmask(unsigned gpio, int value)
Aurelien Jarnob06f3e12008-10-14 11:44:26 +0200102{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200103 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +0200104#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200105 case BCM47XX_BUS_TYPE_SSB:
106 ssb_gpio_intmask(&bcm47xx_bus.ssb, 1 << gpio,
107 value ? 1 << gpio : 0);
108 return 0;
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +0200109#endif
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +0200110#ifdef CONFIG_BCM47XX_BCMA
111 case BCM47XX_BUS_TYPE_BCMA:
112 bcma_chipco_gpio_intmask(&bcm47xx_bus.bcma.bus.drv_cc,
113 1 << gpio, value ? 1 << gpio : 0);
114 return 0;
115#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200116 }
117 return -EINVAL;
Aurelien Jarnob06f3e12008-10-14 11:44:26 +0200118}
119
Michael Buesche0f7ad52009-03-31 15:23:49 -0700120static inline int gpio_polarity(unsigned gpio, int value)
Aurelien Jarnob06f3e12008-10-14 11:44:26 +0200121{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200122 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +0200123#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200124 case BCM47XX_BUS_TYPE_SSB:
125 ssb_gpio_polarity(&bcm47xx_bus.ssb, 1 << gpio,
126 value ? 1 << gpio : 0);
127 return 0;
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +0200128#endif
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +0200129#ifdef CONFIG_BCM47XX_BCMA
130 case BCM47XX_BUS_TYPE_BCMA:
131 bcma_chipco_gpio_polarity(&bcm47xx_bus.bcma.bus.drv_cc,
132 1 << gpio, value ? 1 << gpio : 0);
133 return 0;
134#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200135 }
136 return -EINVAL;
Aurelien Jarno34cc6622007-09-25 15:42:09 +0200137}
138
139
140/* cansleep wrappers */
141#include <asm-generic/gpio.h>
142
143#endif /* __BCM47XX_GPIO_H */