2 * gpio-au1300.h -- GPIO control for Au1300 GPIC and compatibles.
4 * Copyright (c) 2009-2011 Manuel Lauss <manuel.lauss@googlemail.com>
7 #ifndef _GPIO_AU1300_H_
8 #define _GPIO_AU1300_H_
10 #include <asm/addrspace.h>
12 #include <asm/mach-au1x00/au1000.h>
14 /* with the current GPIC design, up to 128 GPIOs are possible.
15 * The only implementation so far is in the Au1300, which has 75 externally
18 #define AU1300_GPIO_BASE 0
19 #define AU1300_GPIO_NUM 75
20 #define AU1300_GPIO_MAX (AU1300_GPIO_BASE + AU1300_GPIO_NUM - 1)
22 #define AU1300_GPIC_ADDR \
23 (void __iomem *)KSEG1ADDR(AU1300_GPIC_PHYS_ADDR)
25 static inline int au1300_gpio_get_value(unsigned int gpio)
27 void __iomem *roff = AU1300_GPIC_ADDR;
30 gpio -= AU1300_GPIO_BASE;
31 roff += GPIC_GPIO_BANKOFF(gpio);
32 bit = GPIC_GPIO_TO_BIT(gpio);
33 return __raw_readl(roff + AU1300_GPIC_PINVAL) & bit;
36 static inline int au1300_gpio_direction_input(unsigned int gpio)
38 void __iomem *roff = AU1300_GPIC_ADDR;
41 gpio -= AU1300_GPIO_BASE;
43 roff += GPIC_GPIO_BANKOFF(gpio);
44 bit = GPIC_GPIO_TO_BIT(gpio);
45 __raw_writel(bit, roff + AU1300_GPIC_DEVCLR);
51 static inline int au1300_gpio_set_value(unsigned int gpio, int v)
53 void __iomem *roff = AU1300_GPIC_ADDR;
56 gpio -= AU1300_GPIO_BASE;
58 roff += GPIC_GPIO_BANKOFF(gpio);
59 bit = GPIC_GPIO_TO_BIT(gpio);
60 __raw_writel(bit, roff + (v ? AU1300_GPIC_PINVAL
61 : AU1300_GPIC_PINVALCLR));
67 static inline int au1300_gpio_direction_output(unsigned int gpio, int v)
69 /* hw switches to output automatically */
70 return au1300_gpio_set_value(gpio, v);
73 static inline int au1300_gpio_to_irq(unsigned int gpio)
75 return AU1300_FIRST_INT + (gpio - AU1300_GPIO_BASE);
78 static inline int au1300_irq_to_gpio(unsigned int irq)
80 return (irq - AU1300_FIRST_INT) + AU1300_GPIO_BASE;
83 static inline int au1300_gpio_is_valid(unsigned int gpio)
87 switch (alchemy_get_cputype()) {
88 case ALCHEMY_CPU_AU1300:
89 ret = ((gpio >= AU1300_GPIO_BASE) && (gpio <= AU1300_GPIO_MAX));
97 static inline int au1300_gpio_cansleep(unsigned int gpio)
102 /* hardware remembers gpio 0-63 levels on powerup */
103 static inline int au1300_gpio_getinitlvl(unsigned int gpio)
105 void __iomem *roff = AU1300_GPIC_ADDR;
108 if (unlikely(gpio > 63))
110 else if (gpio > 31) {
115 v = __raw_readl(roff + AU1300_GPIC_RSTVAL);
116 return (v >> gpio) & 1;
119 /**********************************************************************/
121 /* Linux gpio framework integration.
123 * 4 use cases of Alchemy GPIOS:
124 *(1) GPIOLIB=y, ALCHEMY_GPIO_INDIRECT=y:
125 * Board must register gpiochips.
126 *(2) GPIOLIB=y, ALCHEMY_GPIO_INDIRECT=n:
127 * A gpiochip for the 75 GPIOs is registered.
129 *(3) GPIOLIB=n, ALCHEMY_GPIO_INDIRECT=y:
130 * the boards' gpio.h must provide the linux gpio wrapper functions,
132 *(4) GPIOLIB=n, ALCHEMY_GPIO_INDIRECT=n:
133 * inlinable gpio functions are provided which enable access to the
134 * Au1300 gpios only by using the numbers straight out of the data-
137 * Cases 1 and 3 are intended for boards which want to provide their own
138 * GPIO namespace and -operations (i.e. for example you have 8 GPIOs
139 * which are in part provided by spare Au1300 GPIO pins and in part by
140 * an external FPGA but you still want them to be accssible in linux
141 * as gpio0-7. The board can of course use the alchemy_gpioX_* functions
145 #ifndef CONFIG_GPIOLIB
147 #ifdef CONFIG_ALCHEMY_GPIOINT_AU1300
149 #ifndef CONFIG_ALCHEMY_GPIO_INDIRECT /* case (4) */
151 static inline int gpio_direction_input(unsigned int gpio)
153 return au1300_gpio_direction_input(gpio);
156 static inline int gpio_direction_output(unsigned int gpio, int v)
158 return au1300_gpio_direction_output(gpio, v);
161 static inline int gpio_get_value(unsigned int gpio)
163 return au1300_gpio_get_value(gpio);
166 static inline void gpio_set_value(unsigned int gpio, int v)
168 au1300_gpio_set_value(gpio, v);
171 static inline int gpio_get_value_cansleep(unsigned gpio)
173 return gpio_get_value(gpio);
176 static inline void gpio_set_value_cansleep(unsigned gpio, int value)
178 gpio_set_value(gpio, value);
181 static inline int gpio_is_valid(unsigned int gpio)
183 return au1300_gpio_is_valid(gpio);
186 static inline int gpio_cansleep(unsigned int gpio)
188 return au1300_gpio_cansleep(gpio);
191 static inline int gpio_to_irq(unsigned int gpio)
193 return au1300_gpio_to_irq(gpio);
196 static inline int irq_to_gpio(unsigned int irq)
198 return au1300_irq_to_gpio(irq);
201 static inline int gpio_request(unsigned int gpio, const char *label)
206 static inline void gpio_free(unsigned int gpio)
210 static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
215 static inline void gpio_unexport(unsigned gpio)
219 static inline int gpio_export(unsigned gpio, bool direction_may_change)
224 static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
229 static inline int gpio_export_link(struct device *dev, const char *name,
235 #endif /* !CONFIG_ALCHEMY_GPIO_INDIRECT */
237 #endif /* CONFIG_ALCHEMY_GPIOINT_AU1300 */
239 #endif /* CONFIG GPIOLIB */
241 #endif /* _GPIO_AU1300_H_ */