1 /* SPDX-License-Identifier: GPL-2.0 */
3 * gpio-au1300.h -- GPIO control for Au1300 GPIC and compatibles.
5 * Copyright (c) 2009-2011 Manuel Lauss <manuel.lauss@googlemail.com>
8 #ifndef _GPIO_AU1300_H_
9 #define _GPIO_AU1300_H_
11 #include <asm/addrspace.h>
13 #include <asm/mach-au1x00/au1000.h>
18 /* with the current GPIC design, up to 128 GPIOs are possible.
19 * The only implementation so far is in the Au1300, which has 75 externally
22 #define AU1300_GPIO_BASE 0
23 #define AU1300_GPIO_NUM 75
24 #define AU1300_GPIO_MAX (AU1300_GPIO_BASE + AU1300_GPIO_NUM - 1)
26 #define AU1300_GPIC_ADDR \
27 (void __iomem *)KSEG1ADDR(AU1300_GPIC_PHYS_ADDR)
29 static inline int au1300_gpio_get_value(unsigned int gpio
)
31 void __iomem
*roff
= AU1300_GPIC_ADDR
;
34 gpio
-= AU1300_GPIO_BASE
;
35 roff
+= GPIC_GPIO_BANKOFF(gpio
);
36 bit
= GPIC_GPIO_TO_BIT(gpio
);
37 return __raw_readl(roff
+ AU1300_GPIC_PINVAL
) & bit
;
40 static inline int au1300_gpio_direction_input(unsigned int gpio
)
42 void __iomem
*roff
= AU1300_GPIC_ADDR
;
45 gpio
-= AU1300_GPIO_BASE
;
47 roff
+= GPIC_GPIO_BANKOFF(gpio
);
48 bit
= GPIC_GPIO_TO_BIT(gpio
);
49 __raw_writel(bit
, roff
+ AU1300_GPIC_DEVCLR
);
55 static inline int au1300_gpio_set_value(unsigned int gpio
, int v
)
57 void __iomem
*roff
= AU1300_GPIC_ADDR
;
60 gpio
-= AU1300_GPIO_BASE
;
62 roff
+= GPIC_GPIO_BANKOFF(gpio
);
63 bit
= GPIC_GPIO_TO_BIT(gpio
);
64 __raw_writel(bit
, roff
+ (v
? AU1300_GPIC_PINVAL
65 : AU1300_GPIC_PINVALCLR
));
71 static inline int au1300_gpio_direction_output(unsigned int gpio
, int v
)
73 /* hw switches to output automatically */
74 return au1300_gpio_set_value(gpio
, v
);
77 static inline int au1300_gpio_to_irq(unsigned int gpio
)
79 return AU1300_FIRST_INT
+ (gpio
- AU1300_GPIO_BASE
);
82 static inline int au1300_irq_to_gpio(unsigned int irq
)
84 return (irq
- AU1300_FIRST_INT
) + AU1300_GPIO_BASE
;
87 static inline int au1300_gpio_is_valid(unsigned int gpio
)
91 switch (alchemy_get_cputype()) {
92 case ALCHEMY_CPU_AU1300
:
93 ret
= ((gpio
>= AU1300_GPIO_BASE
) && (gpio
<= AU1300_GPIO_MAX
));
101 /* hardware remembers gpio 0-63 levels on powerup */
102 static inline int au1300_gpio_getinitlvl(unsigned int gpio
)
104 void __iomem
*roff
= AU1300_GPIC_ADDR
;
107 if (unlikely(gpio
> 63))
109 else if (gpio
> 31) {
114 v
= __raw_readl(roff
+ AU1300_GPIC_RSTVAL
);
115 return (v
>> gpio
) & 1;
118 #endif /* _GPIO_AU1300_H_ */