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>
17 /* with the current GPIC design, up to 128 GPIOs are possible.
18 * The only implementation so far is in the Au1300, which has 75 externally
21 #define AU1300_GPIO_BASE 0
22 #define AU1300_GPIO_NUM 75
23 #define AU1300_GPIO_MAX (AU1300_GPIO_BASE + AU1300_GPIO_NUM - 1)
25 #define AU1300_GPIC_ADDR \
26 (void __iomem *)KSEG1ADDR(AU1300_GPIC_PHYS_ADDR)
28 static inline int au1300_gpio_get_value(unsigned int gpio
)
30 void __iomem
*roff
= AU1300_GPIC_ADDR
;
33 gpio
-= AU1300_GPIO_BASE
;
34 roff
+= GPIC_GPIO_BANKOFF(gpio
);
35 bit
= GPIC_GPIO_TO_BIT(gpio
);
36 return __raw_readl(roff
+ AU1300_GPIC_PINVAL
) & bit
;
39 static inline int au1300_gpio_direction_input(unsigned int gpio
)
41 void __iomem
*roff
= AU1300_GPIC_ADDR
;
44 gpio
-= AU1300_GPIO_BASE
;
46 roff
+= GPIC_GPIO_BANKOFF(gpio
);
47 bit
= GPIC_GPIO_TO_BIT(gpio
);
48 __raw_writel(bit
, roff
+ AU1300_GPIC_DEVCLR
);
54 static inline int au1300_gpio_set_value(unsigned int gpio
, int v
)
56 void __iomem
*roff
= AU1300_GPIC_ADDR
;
59 gpio
-= AU1300_GPIO_BASE
;
61 roff
+= GPIC_GPIO_BANKOFF(gpio
);
62 bit
= GPIC_GPIO_TO_BIT(gpio
);
63 __raw_writel(bit
, roff
+ (v
? AU1300_GPIC_PINVAL
64 : AU1300_GPIC_PINVALCLR
));
70 static inline int au1300_gpio_direction_output(unsigned int gpio
, int v
)
72 /* hw switches to output automatically */
73 return au1300_gpio_set_value(gpio
, v
);
76 static inline int au1300_gpio_to_irq(unsigned int gpio
)
78 return AU1300_FIRST_INT
+ (gpio
- AU1300_GPIO_BASE
);
81 static inline int au1300_irq_to_gpio(unsigned int irq
)
83 return (irq
- AU1300_FIRST_INT
) + AU1300_GPIO_BASE
;
86 static inline int au1300_gpio_is_valid(unsigned int gpio
)
90 switch (alchemy_get_cputype()) {
91 case ALCHEMY_CPU_AU1300
:
92 ret
= ((gpio
>= AU1300_GPIO_BASE
) && (gpio
<= AU1300_GPIO_MAX
));
100 static inline int au1300_gpio_cansleep(unsigned int gpio
)
105 /* hardware remembers gpio 0-63 levels on powerup */
106 static inline int au1300_gpio_getinitlvl(unsigned int gpio
)
108 void __iomem
*roff
= AU1300_GPIC_ADDR
;
111 if (unlikely(gpio
> 63))
113 else if (gpio
> 31) {
118 v
= __raw_readl(roff
+ AU1300_GPIC_RSTVAL
);
119 return (v
>> gpio
) & 1;
122 /**********************************************************************/
124 /* Linux gpio framework integration.
126 * 4 use cases of Alchemy GPIOS:
127 *(1) GPIOLIB=y, ALCHEMY_GPIO_INDIRECT=y:
128 * Board must register gpiochips.
129 *(2) GPIOLIB=y, ALCHEMY_GPIO_INDIRECT=n:
130 * A gpiochip for the 75 GPIOs is registered.
132 *(3) GPIOLIB=n, ALCHEMY_GPIO_INDIRECT=y:
133 * the boards' gpio.h must provide the linux gpio wrapper functions,
135 *(4) GPIOLIB=n, ALCHEMY_GPIO_INDIRECT=n:
136 * inlinable gpio functions are provided which enable access to the
137 * Au1300 gpios only by using the numbers straight out of the data-
140 * Cases 1 and 3 are intended for boards which want to provide their own
141 * GPIO namespace and -operations (i.e. for example you have 8 GPIOs
142 * which are in part provided by spare Au1300 GPIO pins and in part by
143 * an external FPGA but you still want them to be accssible in linux
144 * as gpio0-7. The board can of course use the alchemy_gpioX_* functions
148 #ifndef CONFIG_GPIOLIB
150 #ifdef CONFIG_ALCHEMY_GPIOINT_AU1300
152 #ifndef CONFIG_ALCHEMY_GPIO_INDIRECT /* case (4) */
154 static inline int gpio_direction_input(unsigned int gpio
)
156 return au1300_gpio_direction_input(gpio
);
159 static inline int gpio_direction_output(unsigned int gpio
, int v
)
161 return au1300_gpio_direction_output(gpio
, v
);
164 static inline int gpio_get_value(unsigned int gpio
)
166 return au1300_gpio_get_value(gpio
);
169 static inline void gpio_set_value(unsigned int gpio
, int v
)
171 au1300_gpio_set_value(gpio
, v
);
174 static inline int gpio_get_value_cansleep(unsigned gpio
)
176 return gpio_get_value(gpio
);
179 static inline void gpio_set_value_cansleep(unsigned gpio
, int value
)
181 gpio_set_value(gpio
, value
);
184 static inline int gpio_is_valid(unsigned int gpio
)
186 return au1300_gpio_is_valid(gpio
);
189 static inline int gpio_cansleep(unsigned int gpio
)
191 return au1300_gpio_cansleep(gpio
);
194 static inline int gpio_to_irq(unsigned int gpio
)
196 return au1300_gpio_to_irq(gpio
);
199 static inline int irq_to_gpio(unsigned int irq
)
201 return au1300_irq_to_gpio(irq
);
204 static inline int gpio_request(unsigned int gpio
, const char *label
)
209 static inline int gpio_request_one(unsigned gpio
,
210 unsigned long flags
, const char *label
)
215 static inline int gpio_request_array(struct gpio
*array
, size_t num
)
220 static inline void gpio_free(unsigned gpio
)
224 static inline void gpio_free_array(struct gpio
*array
, size_t num
)
228 static inline int gpio_set_debounce(unsigned gpio
, unsigned debounce
)
233 static inline void gpio_unexport(unsigned gpio
)
237 static inline int gpio_export(unsigned gpio
, bool direction_may_change
)
242 static inline int gpio_sysfs_set_active_low(unsigned gpio
, int value
)
247 static inline int gpio_export_link(struct device
*dev
, const char *name
,
253 #endif /* !CONFIG_ALCHEMY_GPIO_INDIRECT */
255 #endif /* CONFIG_ALCHEMY_GPIOINT_AU1300 */
257 #endif /* CONFIG GPIOLIB */
259 #endif /* _GPIO_AU1300_H_ */