4 * Copyright (C) 2007 OpenWrt.org
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef __AR7_GPIO_H__
22 #define __AR7_GPIO_H__
23 #include <asm/ar7/ar7.h>
25 #define AR7_GPIO_MAX 32
27 extern int gpio_request(unsigned gpio
, char *label
);
28 extern void gpio_free(unsigned gpio
);
30 /* Common GPIO layer */
31 static inline int gpio_direction_input(unsigned gpio
)
33 void __iomem
*gpio_dir
= (void __iomem
*)KSEG1ADDR(AR7_REGS_GPIO
+ AR7_GPIO_DIR
);
35 if (gpio
>= AR7_GPIO_MAX
)
38 writel(readl(gpio_dir
) | (1 << gpio
), gpio_dir
);
43 static inline int gpio_direction_output(unsigned gpio
)
45 void __iomem
*gpio_dir
= (void __iomem
*)KSEG1ADDR(AR7_REGS_GPIO
+ AR7_GPIO_DIR
);
47 if (gpio
>= AR7_GPIO_MAX
)
50 writel(readl(gpio_dir
) & ~(1 << gpio
), gpio_dir
);
55 static inline int gpio_get_value(unsigned gpio
)
57 void __iomem
*gpio_in
= (void __iomem
*)KSEG1ADDR(AR7_REGS_GPIO
+ AR7_GPIO_INPUT
);
59 if (gpio
>= AR7_GPIO_MAX
)
62 return ((readl(gpio_in
) & (1 << gpio
)) != 0);
65 static inline void gpio_set_value(unsigned gpio
, int value
)
67 void __iomem
*gpio_out
= (void __iomem
*)KSEG1ADDR(AR7_REGS_GPIO
+ AR7_GPIO_OUTPUT
);
68 volatile unsigned tmp
;
70 if (gpio
>= AR7_GPIO_MAX
)
73 tmp
= readl(gpio_out
) & ~(1 << gpio
);
76 writel(tmp
, gpio_out
);
79 static inline int gpio_to_irq(unsigned gpio
)
84 static inline int irq_to_gpio(unsigned irq
)
89 /* Board specific GPIO functions */
90 static inline int ar7_gpio_enable(unsigned gpio
)
92 void __iomem
*gpio_en
= (void __iomem
*)KSEG1ADDR(AR7_REGS_GPIO
+ AR7_GPIO_ENABLE
);
94 if (gpio
>= AR7_GPIO_MAX
)
97 writel(readl(gpio_en
) | (1 << gpio
), gpio_en
);
102 static inline int ar7_gpio_disable(unsigned gpio
)
104 void __iomem
*gpio_en
= (void __iomem
*)KSEG1ADDR(AR7_REGS_GPIO
+ AR7_GPIO_ENABLE
);
106 if (gpio
>= AR7_GPIO_MAX
)
109 writel(readl(gpio_en
) & ~(1 << gpio
), gpio_en
);
114 #include <asm-generic/gpio.h>
This page took 0.048868 seconds and 5 git commands to generate.