blob: 6b78827dd140e17174041e93e2f6fe540d1e23b2 [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>
13#include <asm/mach-bcm47xx/bcm47xx.h>
14
Aurelien Jarno34cc6622007-09-25 15:42:09 +020015#define BCM47XX_EXTIF_GPIO_LINES 5
16#define BCM47XX_CHIPCO_GPIO_LINES 16
17
Aurelien Jarnob06f3e12008-10-14 11:44:26 +020018extern int gpio_request(unsigned gpio, const char *label);
19extern void gpio_free(unsigned gpio);
20extern int gpio_to_irq(unsigned gpio);
Aurelien Jarno34cc6622007-09-25 15:42:09 +020021
22static inline int gpio_get_value(unsigned gpio)
23{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020024 switch (bcm47xx_bus_type) {
25 case BCM47XX_BUS_TYPE_SSB:
26 return ssb_gpio_in(&bcm47xx_bus.ssb, 1 << gpio);
27 }
28 return -EINVAL;
Aurelien Jarno34cc6622007-09-25 15:42:09 +020029}
30
31static inline void gpio_set_value(unsigned gpio, int value)
32{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020033 switch (bcm47xx_bus_type) {
34 case BCM47XX_BUS_TYPE_SSB:
35 ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
36 value ? 1 << gpio : 0);
37 }
Aurelien Jarno34cc6622007-09-25 15:42:09 +020038}
39
40static inline int gpio_direction_input(unsigned gpio)
41{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020042 switch (bcm47xx_bus_type) {
43 case BCM47XX_BUS_TYPE_SSB:
44 ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 0);
45 return 0;
46 }
47 return -EINVAL;
Aurelien Jarno34cc6622007-09-25 15:42:09 +020048}
49
50static inline int gpio_direction_output(unsigned gpio, int value)
51{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020052 switch (bcm47xx_bus_type) {
53 case BCM47XX_BUS_TYPE_SSB:
54 /* first set the gpio out value */
55 ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
56 value ? 1 << gpio : 0);
57 /* then set the gpio mode */
58 ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 1 << gpio);
59 return 0;
60 }
61 return -EINVAL;
Aurelien Jarnob06f3e12008-10-14 11:44:26 +020062}
63
Michael Buesche0f7ad52009-03-31 15:23:49 -070064static inline int gpio_intmask(unsigned gpio, int value)
Aurelien Jarnob06f3e12008-10-14 11:44:26 +020065{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020066 switch (bcm47xx_bus_type) {
67 case BCM47XX_BUS_TYPE_SSB:
68 ssb_gpio_intmask(&bcm47xx_bus.ssb, 1 << gpio,
69 value ? 1 << gpio : 0);
70 return 0;
71 }
72 return -EINVAL;
Aurelien Jarnob06f3e12008-10-14 11:44:26 +020073}
74
Michael Buesche0f7ad52009-03-31 15:23:49 -070075static inline int gpio_polarity(unsigned gpio, int value)
Aurelien Jarnob06f3e12008-10-14 11:44:26 +020076{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020077 switch (bcm47xx_bus_type) {
78 case BCM47XX_BUS_TYPE_SSB:
79 ssb_gpio_polarity(&bcm47xx_bus.ssb, 1 << gpio,
80 value ? 1 << gpio : 0);
81 return 0;
82 }
83 return -EINVAL;
Aurelien Jarno34cc6622007-09-25 15:42:09 +020084}
85
86
87/* cansleep wrappers */
88#include <asm-generic/gpio.h>
89
90#endif /* __BCM47XX_GPIO_H */