2 * Coldfire generic GPIO support.
4 * (C) Copyright 2009, Steven King <sfking@fdwdc.com>
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; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
20 #include <asm-generic/gpio.h>
23 int __mcfgpio_get_value(unsigned gpio
);
24 void __mcfgpio_set_value(unsigned gpio
, int value
);
25 int __mcfgpio_direction_input(unsigned gpio
);
26 int __mcfgpio_direction_output(unsigned gpio
, int value
);
27 int __mcfgpio_request(unsigned gpio
);
28 void __mcfgpio_free(unsigned gpio
);
30 /* our alternate 'gpiolib' functions */
31 static inline int __gpio_get_value(unsigned gpio
)
33 if (gpio
< MCFGPIO_PIN_MAX
)
34 return __mcfgpio_get_value(gpio
);
39 static inline void __gpio_set_value(unsigned gpio
, int value
)
41 if (gpio
< MCFGPIO_PIN_MAX
)
42 __mcfgpio_set_value(gpio
, value
);
45 static inline int __gpio_cansleep(unsigned gpio
)
47 if (gpio
< MCFGPIO_PIN_MAX
)
53 static inline int __gpio_to_irq(unsigned gpio
)
58 static inline int gpio_direction_input(unsigned gpio
)
60 if (gpio
< MCFGPIO_PIN_MAX
)
61 return __mcfgpio_direction_input(gpio
);
66 static inline int gpio_direction_output(unsigned gpio
, int value
)
68 if (gpio
< MCFGPIO_PIN_MAX
)
69 return __mcfgpio_direction_output(gpio
, value
);
74 static inline int gpio_request(unsigned gpio
, const char *label
)
76 if (gpio
< MCFGPIO_PIN_MAX
)
77 return __mcfgpio_request(gpio
);
82 static inline void gpio_free(unsigned gpio
)
84 if (gpio
< MCFGPIO_PIN_MAX
)
88 #endif /* CONFIG_GPIOLIB */
92 * The Freescale Coldfire family is quite varied in how they implement GPIO.
93 * Some parts have 8 bit ports, some have 16bit and some have 32bit; some have
94 * only one port, others have multiple ports; some have a single data latch
95 * for both input and output, others have a separate pin data register to read
96 * input; some require a read-modify-write access to change an output, others
97 * have set and clear registers for some of the outputs; Some have all the
98 * GPIOs in a single control area, others have some GPIOs implemented in
101 * This implementation attempts accommodate the differences while presenting
102 * a generic interface that will optimize to as few instructions as possible.
104 #if defined(CONFIG_M5206) || defined(CONFIG_M5206e) || \
105 defined(CONFIG_M520x) || defined(CONFIG_M523x) || \
106 defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
107 defined(CONFIG_M53xx) || defined(CONFIG_M54xx) || \
108 defined(CONFIG_M5441x)
110 /* These parts have GPIO organized by 8 bit ports */
112 #define MCFGPIO_PORTTYPE u8
113 #define MCFGPIO_PORTSIZE 8
114 #define mcfgpio_read(port) __raw_readb(port)
115 #define mcfgpio_write(data, port) __raw_writeb(data, port)
117 #elif defined(CONFIG_M5307) || defined(CONFIG_M5407) || defined(CONFIG_M5272)
119 /* These parts have GPIO organized by 16 bit ports */
121 #define MCFGPIO_PORTTYPE u16
122 #define MCFGPIO_PORTSIZE 16
123 #define mcfgpio_read(port) __raw_readw(port)
124 #define mcfgpio_write(data, port) __raw_writew(data, port)
126 #elif defined(CONFIG_M5249) || defined(CONFIG_M525x)
128 /* These parts have GPIO organized by 32 bit ports */
130 #define MCFGPIO_PORTTYPE u32
131 #define MCFGPIO_PORTSIZE 32
132 #define mcfgpio_read(port) __raw_readl(port)
133 #define mcfgpio_write(data, port) __raw_writel(data, port)
137 #define mcfgpio_bit(gpio) (1 << ((gpio) % MCFGPIO_PORTSIZE))
138 #define mcfgpio_port(gpio) ((gpio) / MCFGPIO_PORTSIZE)
140 #if defined(CONFIG_M520x) || defined(CONFIG_M523x) || \
141 defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
142 defined(CONFIG_M53xx) || defined(CONFIG_M5441x)
144 * These parts have an 'Edge' Port module (external interrupt/GPIO) which uses
145 * read-modify-write to change an output and a GPIO module which has separate
146 * set/clr registers to directly change outputs with a single write access.
148 #if defined(CONFIG_M528x)
150 * The 528x also has GPIOs in other modules (GPT, QADC) which use
151 * read-modify-write as well as those controlled by the EPORT and GPIO modules.
153 #define MCFGPIO_SCR_START 40
154 #elif defined(CONFIGM5441x)
155 /* The m5441x EPORT doesn't have its own GPIO port, uses PORT C */
156 #define MCFGPIO_SCR_START 0
158 #define MCFGPIO_SCR_START 8
161 #define MCFGPIO_SETR_PORT(gpio) (MCFGPIO_SETR + \
162 mcfgpio_port(gpio - MCFGPIO_SCR_START))
164 #define MCFGPIO_CLRR_PORT(gpio) (MCFGPIO_CLRR + \
165 mcfgpio_port(gpio - MCFGPIO_SCR_START))
168 #define MCFGPIO_SCR_START MCFGPIO_PIN_MAX
169 /* with MCFGPIO_SCR == MCFGPIO_PIN_MAX, these will be optimized away */
170 #define MCFGPIO_SETR_PORT(gpio) 0
171 #define MCFGPIO_CLRR_PORT(gpio) 0
175 * Coldfire specific helper functions
178 /* return the port pin data register for a gpio */
179 static inline u32
__mcfgpio_ppdr(unsigned gpio
)
181 #if defined(CONFIG_M5206) || defined(CONFIG_M5206e) || \
182 defined(CONFIG_M5307) || defined(CONFIG_M5407)
184 #elif defined(CONFIG_M5272)
191 #elif defined(CONFIG_M5249) || defined(CONFIG_M525x)
193 return MCFSIM2_GPIOREAD
;
195 return MCFSIM2_GPIO1READ
;
196 #elif defined(CONFIG_M520x) || defined(CONFIG_M523x) || \
197 defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
198 defined(CONFIG_M53xx) || defined(CONFIG_M5441x)
199 #if !defined(CONFIG_M5441x)
201 return MCFEPORT_EPPDR
;
202 #if defined(CONFIG_M528x)
204 return MCFGPTA_GPTPORT
;
206 return MCFGPTB_GPTPORT
;
208 return MCFQADC_PORTQA
;
210 return MCFQADC_PORTQB
;
211 #endif /* defined(CONFIG_M528x) */
213 #endif /* !defined(CONFIG_M5441x) */
214 return MCFGPIO_PPDR
+ mcfgpio_port(gpio
- MCFGPIO_SCR_START
);
220 /* return the port output data register for a gpio */
221 static inline u32
__mcfgpio_podr(unsigned gpio
)
223 #if defined(CONFIG_M5206) || defined(CONFIG_M5206e) || \
224 defined(CONFIG_M5307) || defined(CONFIG_M5407)
226 #elif defined(CONFIG_M5272)
233 #elif defined(CONFIG_M5249) || defined(CONFIG_M525x)
235 return MCFSIM2_GPIOWRITE
;
237 return MCFSIM2_GPIO1WRITE
;
238 #elif defined(CONFIG_M520x) || defined(CONFIG_M523x) || \
239 defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
240 defined(CONFIG_M53xx) || defined(CONFIG_M5441x)
241 #if !defined(CONFIG_M5441x)
243 return MCFEPORT_EPDR
;
244 #if defined(CONFIG_M528x)
246 return MCFGPTA_GPTPORT
;
248 return MCFGPTB_GPTPORT
;
250 return MCFQADC_PORTQA
;
252 return MCFQADC_PORTQB
;
253 #endif /* defined(CONFIG_M528x) */
255 #endif /* !defined(CONFIG_M5441x) */
256 return MCFGPIO_PODR
+ mcfgpio_port(gpio
- MCFGPIO_SCR_START
);
262 /* return the port direction data register for a gpio */
263 static inline u32
__mcfgpio_pddr(unsigned gpio
)
265 #if defined(CONFIG_M5206) || defined(CONFIG_M5206e) || \
266 defined(CONFIG_M5307) || defined(CONFIG_M5407)
268 #elif defined(CONFIG_M5272)
275 #elif defined(CONFIG_M5249) || defined(CONFIG_M525x)
277 return MCFSIM2_GPIOENABLE
;
279 return MCFSIM2_GPIO1ENABLE
;
280 #elif defined(CONFIG_M520x) || defined(CONFIG_M523x) || \
281 defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
282 defined(CONFIG_M53xx) || defined(CONFIG_M5441x)
283 #if !defined(CONFIG_M5441x)
285 return MCFEPORT_EPDDR
;
286 #if defined(CONFIG_M528x)
288 return MCFGPTA_GPTDDR
;
290 return MCFGPTB_GPTDDR
;
292 return MCFQADC_DDRQA
;
294 return MCFQADC_DDRQB
;
295 #endif /* defined(CONFIG_M528x) */
297 #endif /* !defined(CONFIG_M5441x) */
298 return MCFGPIO_PDDR
+ mcfgpio_port(gpio
- MCFGPIO_SCR_START
);
304 #endif /* mcfgpio_h */