00418b586347f194ed5a3b31c0f430f5db72f8aa
2 * Copyright (C) 2007 OpenWrt.org
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef __AR7_GPIO_H__
20 #define __AR7_GPIO_H__
21 #include <asm/ar7/ar7.h>
23 #define AR7_GPIO_MAX 32
25 extern int gpio_request(unsigned gpio
, const char *label
);
26 extern void gpio_free(unsigned gpio
);
28 /* Common GPIO layer */
29 static inline int gpio_get_value(unsigned gpio
)
34 void __iomem
*gpio_in
= (void __iomem
*)
35 KSEG1ADDR(AR7_REGS_GPIO
+ AR7_GPIO_INPUT
);
36 addr
= readl(gpio_in
);
39 return addr
& (1 << gpio
);
42 static inline void gpio_set_value(unsigned gpio
, int value
)
44 static void __iomem
*gpio_out
;
48 gpio_out
= (void __iomem
*)
49 KSEG1ADDR(AR7_REGS_GPIO
+ AR7_GPIO_OUTPUT
);
51 tmp
= readl(gpio_out
) & ~(1 << gpio
);
54 writel(tmp
, gpio_out
);
57 static inline int gpio_direction_input(unsigned gpio
)
59 void __iomem
*gpio_dir
=
60 (void __iomem
*)KSEG1ADDR(AR7_REGS_GPIO
+ AR7_GPIO_DIR
);
62 if (gpio
>= AR7_GPIO_MAX
)
65 writel(readl(gpio_dir
) | (1 << gpio
), gpio_dir
);
70 static inline int gpio_direction_output(unsigned gpio
, int value
)
72 void __iomem
*gpio_dir
=
73 (void __iomem
*)KSEG1ADDR(AR7_REGS_GPIO
+ AR7_GPIO_DIR
);
75 if (gpio
>= AR7_GPIO_MAX
)
78 gpio_set_value(gpio
, value
);
79 writel(readl(gpio_dir
) & ~(1 << gpio
), gpio_dir
);
84 static inline int gpio_to_irq(unsigned gpio
)
89 static inline int irq_to_gpio(unsigned irq
)
94 /* Board specific GPIO functions */
95 static inline int ar7_gpio_enable(unsigned gpio
)
97 void __iomem
*gpio_en
=
98 (void __iomem
*)KSEG1ADDR(AR7_REGS_GPIO
+ AR7_GPIO_ENABLE
);
100 writel(readl(gpio_en
) | (1 << gpio
), gpio_en
);
105 static inline int ar7_gpio_disable(unsigned gpio
)
107 void __iomem
*gpio_en
=
108 (void __iomem
*)KSEG1ADDR(AR7_REGS_GPIO
+ AR7_GPIO_ENABLE
);
110 writel(readl(gpio_en
) & ~(1 << gpio
), gpio_en
);
115 #include <asm-generic/gpio.h>
This page took 0.045232 seconds and 3 git commands to generate.