GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / arm / mach-davinci / include / mach / gpio.h
blobf8c2e9c665e3e65c3e8c3396b738b68c7303bc5d
1 /*
2 * TI DaVinci GPIO Support
4 * Copyright (c) 2006 David Brownell
5 * Copyright (c) 2007, MontaVista Software, Inc. <source@mvista.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
13 #ifndef __DAVINCI_GPIO_H
14 #define __DAVINCI_GPIO_H
16 #include <linux/io.h>
17 #include <linux/spinlock.h>
19 #include <asm-generic/gpio.h>
21 #include <mach/irqs.h>
22 #include <mach/common.h>
24 #define DAVINCI_GPIO_BASE 0x01C67000
26 enum davinci_gpio_type {
27 GPIO_TYPE_DAVINCI = 0,
28 GPIO_TYPE_TNETV107X,
31 #define GPIO(X) (X) /* 0 <= X <= (DAVINCI_N_GPIO - 1) */
33 /* Convert GPIO signal to GPIO pin number */
34 #define GPIO_TO_PIN(bank, gpio) (16 * (bank) + (gpio))
36 struct davinci_gpio_controller {
37 struct gpio_chip chip;
38 int irq_base;
39 spinlock_t lock;
40 void __iomem *regs;
41 void __iomem *set_data;
42 void __iomem *clr_data;
43 void __iomem *in_data;
46 /* The __gpio_to_controller() and __gpio_mask() functions inline to constants
47 * with constant parameters; or in outlined code they execute at runtime.
49 * You'd access the controller directly when reading or writing more than
50 * one gpio value at a time, and to support wired logic where the value
51 * being driven by the cpu need not match the value read back.
53 * These are NOT part of the cross-platform GPIO interface
55 static inline struct davinci_gpio_controller *
56 __gpio_to_controller(unsigned gpio)
58 struct davinci_gpio_controller *ctlrs = davinci_soc_info.gpio_ctlrs;
59 int index = gpio / 32;
61 if (!ctlrs || index >= davinci_soc_info.gpio_ctlrs_num)
62 return NULL;
64 return ctlrs + index;
67 static inline u32 __gpio_mask(unsigned gpio)
69 return 1 << (gpio % 32);
73 * The get/set/clear functions will inline when called with constant
74 * parameters referencing built-in GPIOs, for low-overhead bitbanging.
76 * gpio_set_value() will inline only on traditional Davinci style controllers
77 * with distinct set/clear registers.
79 * Otherwise, calls with variable parameters or referencing external
80 * GPIOs (e.g. on GPIO expander chips) use outlined functions.
82 static inline void gpio_set_value(unsigned gpio, int value)
84 if (__builtin_constant_p(value) && gpio < davinci_soc_info.gpio_num) {
85 struct davinci_gpio_controller *ctlr;
86 u32 mask;
88 ctlr = __gpio_to_controller(gpio);
90 if (ctlr->set_data != ctlr->clr_data) {
91 mask = __gpio_mask(gpio);
92 if (value)
93 __raw_writel(mask, ctlr->set_data);
94 else
95 __raw_writel(mask, ctlr->clr_data);
96 return;
100 __gpio_set_value(gpio, value);
103 /* Returns zero or nonzero; works for gpios configured as inputs OR
104 * as outputs, at least for built-in GPIOs.
106 * NOTE: for built-in GPIOs, changes in reported values are synchronized
107 * to the GPIO clock. This is easily seen after calling gpio_set_value()
108 * and then immediately gpio_get_value(), where the gpio_get_value() will
109 * return the old value until the GPIO clock ticks and the new value gets
110 * latched.
112 static inline int gpio_get_value(unsigned gpio)
114 struct davinci_gpio_controller *ctlr;
116 if (!__builtin_constant_p(gpio) || gpio >= davinci_soc_info.gpio_num)
117 return __gpio_get_value(gpio);
119 ctlr = __gpio_to_controller(gpio);
120 return __gpio_mask(gpio) & __raw_readl(ctlr->in_data);
123 static inline int gpio_cansleep(unsigned gpio)
125 if (__builtin_constant_p(gpio) && gpio < davinci_soc_info.gpio_num)
126 return 0;
127 else
128 return __gpio_cansleep(gpio);
131 static inline int gpio_to_irq(unsigned gpio)
133 return __gpio_to_irq(gpio);
136 static inline int irq_to_gpio(unsigned irq)
138 /* don't support the reverse mapping */
139 return -ENOSYS;
142 #endif /* __DAVINCI_GPIO_H */