blob: 1d5f5af56b5fd8e54247e7d0007bf60927f6fd60 [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) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020025#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020026 case BCM47XX_BUS_TYPE_SSB:
27 return ssb_gpio_in(&bcm47xx_bus.ssb, 1 << gpio);
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020028#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020029 }
30 return -EINVAL;
Aurelien Jarno34cc6622007-09-25 15:42:09 +020031}
32
33static inline void gpio_set_value(unsigned gpio, int value)
34{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020035 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020036#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020037 case BCM47XX_BUS_TYPE_SSB:
38 ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
39 value ? 1 << gpio : 0);
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020040#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020041 }
Aurelien Jarno34cc6622007-09-25 15:42:09 +020042}
43
44static inline int gpio_direction_input(unsigned gpio)
45{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020046 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020047#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020048 case BCM47XX_BUS_TYPE_SSB:
49 ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 0);
50 return 0;
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020051#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020052 }
53 return -EINVAL;
Aurelien Jarno34cc6622007-09-25 15:42:09 +020054}
55
56static inline int gpio_direction_output(unsigned gpio, int value)
57{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020058 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020059#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020060 case BCM47XX_BUS_TYPE_SSB:
61 /* first set the gpio out value */
62 ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
63 value ? 1 << gpio : 0);
64 /* then set the gpio mode */
65 ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 1 << gpio);
66 return 0;
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020067#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020068 }
69 return -EINVAL;
Aurelien Jarnob06f3e12008-10-14 11:44:26 +020070}
71
Michael Buesche0f7ad52009-03-31 15:23:49 -070072static inline int gpio_intmask(unsigned gpio, int value)
Aurelien Jarnob06f3e12008-10-14 11:44:26 +020073{
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_intmask(&bcm47xx_bus.ssb, 1 << gpio,
78 value ? 1 << gpio : 0);
79 return 0;
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020080#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020081 }
82 return -EINVAL;
Aurelien Jarnob06f3e12008-10-14 11:44:26 +020083}
84
Michael Buesche0f7ad52009-03-31 15:23:49 -070085static inline int gpio_polarity(unsigned gpio, int value)
Aurelien Jarnob06f3e12008-10-14 11:44:26 +020086{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020087 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020088#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020089 case BCM47XX_BUS_TYPE_SSB:
90 ssb_gpio_polarity(&bcm47xx_bus.ssb, 1 << gpio,
91 value ? 1 << gpio : 0);
92 return 0;
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020093#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020094 }
95 return -EINVAL;
Aurelien Jarno34cc6622007-09-25 15:42:09 +020096}
97
98
99/* cansleep wrappers */
100#include <asm-generic/gpio.h>
101
102#endif /* __BCM47XX_GPIO_H */