1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Coldfire generic GPIO support.
5 * (C) Copyright 2009, Steven King <sfking@fdwdc.com>
12 #include <asm-generic/gpio.h>
15 int __mcfgpio_get_value(unsigned gpio
);
16 void __mcfgpio_set_value(unsigned gpio
, int value
);
17 int __mcfgpio_direction_input(unsigned gpio
);
18 int __mcfgpio_direction_output(unsigned gpio
, int value
);
19 int __mcfgpio_request(unsigned gpio
);
20 void __mcfgpio_free(unsigned gpio
);
22 /* our alternate 'gpiolib' functions */
23 static inline int __gpio_get_value(unsigned gpio
)
25 if (gpio
< MCFGPIO_PIN_MAX
)
26 return __mcfgpio_get_value(gpio
);
31 static inline void __gpio_set_value(unsigned gpio
, int value
)
33 if (gpio
< MCFGPIO_PIN_MAX
)
34 __mcfgpio_set_value(gpio
, value
);
37 static inline int __gpio_cansleep(unsigned gpio
)
39 if (gpio
< MCFGPIO_PIN_MAX
)
45 static inline int __gpio_to_irq(unsigned gpio
)
50 static inline int gpio_direction_input(unsigned gpio
)
52 if (gpio
< MCFGPIO_PIN_MAX
)
53 return __mcfgpio_direction_input(gpio
);
58 static inline int gpio_direction_output(unsigned gpio
, int value
)
60 if (gpio
< MCFGPIO_PIN_MAX
)
61 return __mcfgpio_direction_output(gpio
, value
);
66 static inline int gpio_request(unsigned gpio
, const char *label
)
68 if (gpio
< MCFGPIO_PIN_MAX
)
69 return __mcfgpio_request(gpio
);
74 static inline void gpio_free(unsigned gpio
)
76 if (gpio
< MCFGPIO_PIN_MAX
)
80 #endif /* CONFIG_GPIOLIB */
84 * The Freescale Coldfire family is quite varied in how they implement GPIO.
85 * Some parts have 8 bit ports, some have 16bit and some have 32bit; some have
86 * only one port, others have multiple ports; some have a single data latch
87 * for both input and output, others have a separate pin data register to read
88 * input; some require a read-modify-write access to change an output, others
89 * have set and clear registers for some of the outputs; Some have all the
90 * GPIOs in a single control area, others have some GPIOs implemented in
93 * This implementation attempts accommodate the differences while presenting
94 * a generic interface that will optimize to as few instructions as possible.
96 #if defined(CONFIG_M5206) || defined(CONFIG_M5206e) || \
97 defined(CONFIG_M520x) || defined(CONFIG_M523x) || \
98 defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
99 defined(CONFIG_M53xx) || defined(CONFIG_M54xx) || \
100 defined(CONFIG_M5441x)
102 /* These parts have GPIO organized by 8 bit ports */
104 #define MCFGPIO_PORTTYPE u8
105 #define MCFGPIO_PORTSIZE 8
106 #define mcfgpio_read(port) __raw_readb(port)
107 #define mcfgpio_write(data, port) __raw_writeb(data, port)
109 #elif defined(CONFIG_M5307) || defined(CONFIG_M5407) || defined(CONFIG_M5272)
111 /* These parts have GPIO organized by 16 bit ports */
113 #define MCFGPIO_PORTTYPE u16
114 #define MCFGPIO_PORTSIZE 16
115 #define mcfgpio_read(port) __raw_readw(port)
116 #define mcfgpio_write(data, port) __raw_writew(data, port)
118 #elif defined(CONFIG_M5249) || defined(CONFIG_M525x)
120 /* These parts have GPIO organized by 32 bit ports */
122 #define MCFGPIO_PORTTYPE u32
123 #define MCFGPIO_PORTSIZE 32
124 #define mcfgpio_read(port) __raw_readl(port)
125 #define mcfgpio_write(data, port) __raw_writel(data, port)
129 #define mcfgpio_bit(gpio) (1 << ((gpio) % MCFGPIO_PORTSIZE))
130 #define mcfgpio_port(gpio) ((gpio) / MCFGPIO_PORTSIZE)
132 #if defined(CONFIG_M520x) || defined(CONFIG_M523x) || \
133 defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
134 defined(CONFIG_M53xx) || defined(CONFIG_M54xx) || \
135 defined(CONFIG_M5441x)
137 * These parts have an 'Edge' Port module (external interrupt/GPIO) which uses
138 * read-modify-write to change an output and a GPIO module which has separate
139 * set/clr registers to directly change outputs with a single write access.
141 #if defined(CONFIG_M528x)
143 * The 528x also has GPIOs in other modules (GPT, QADC) which use
144 * read-modify-write as well as those controlled by the EPORT and GPIO modules.
146 #define MCFGPIO_SCR_START 40
147 #elif defined(CONFIGM5441x)
148 /* The m5441x EPORT doesn't have its own GPIO port, uses PORT C */
149 #define MCFGPIO_SCR_START 0
151 #define MCFGPIO_SCR_START 8
154 #define MCFGPIO_SETR_PORT(gpio) (MCFGPIO_SETR + \
155 mcfgpio_port(gpio - MCFGPIO_SCR_START))
157 #define MCFGPIO_CLRR_PORT(gpio) (MCFGPIO_CLRR + \
158 mcfgpio_port(gpio - MCFGPIO_SCR_START))
161 #define MCFGPIO_SCR_START MCFGPIO_PIN_MAX
162 /* with MCFGPIO_SCR == MCFGPIO_PIN_MAX, these will be optimized away */
163 #define MCFGPIO_SETR_PORT(gpio) 0
164 #define MCFGPIO_CLRR_PORT(gpio) 0
168 * Coldfire specific helper functions
171 /* return the port pin data register for a gpio */
172 static inline u32
__mcfgpio_ppdr(unsigned gpio
)
174 #if defined(CONFIG_M5206) || defined(CONFIG_M5206e) || \
175 defined(CONFIG_M5307) || defined(CONFIG_M5407)
177 #elif defined(CONFIG_M5272)
184 #elif defined(CONFIG_M5249) || defined(CONFIG_M525x)
186 return MCFSIM2_GPIOREAD
;
188 return MCFSIM2_GPIO1READ
;
189 #elif defined(CONFIG_M520x) || defined(CONFIG_M523x) || \
190 defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
191 defined(CONFIG_M53xx) || defined(CONFIG_M54xx) || \
192 defined(CONFIG_M5441x)
193 #if !defined(CONFIG_M5441x)
195 return MCFEPORT_EPPDR
;
196 #if defined(CONFIG_M528x)
198 return MCFGPTA_GPTPORT
;
200 return MCFGPTB_GPTPORT
;
202 return MCFQADC_PORTQA
;
204 return MCFQADC_PORTQB
;
205 #endif /* defined(CONFIG_M528x) */
207 #endif /* !defined(CONFIG_M5441x) */
208 return MCFGPIO_PPDR
+ mcfgpio_port(gpio
- MCFGPIO_SCR_START
);
214 /* return the port output data register for a gpio */
215 static inline u32
__mcfgpio_podr(unsigned gpio
)
217 #if defined(CONFIG_M5206) || defined(CONFIG_M5206e) || \
218 defined(CONFIG_M5307) || defined(CONFIG_M5407)
220 #elif defined(CONFIG_M5272)
227 #elif defined(CONFIG_M5249) || defined(CONFIG_M525x)
229 return MCFSIM2_GPIOWRITE
;
231 return MCFSIM2_GPIO1WRITE
;
232 #elif defined(CONFIG_M520x) || defined(CONFIG_M523x) || \
233 defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
234 defined(CONFIG_M53xx) || defined(CONFIG_M54xx) || \
235 defined(CONFIG_M5441x)
236 #if !defined(CONFIG_M5441x)
238 return MCFEPORT_EPDR
;
239 #if defined(CONFIG_M528x)
241 return MCFGPTA_GPTPORT
;
243 return MCFGPTB_GPTPORT
;
245 return MCFQADC_PORTQA
;
247 return MCFQADC_PORTQB
;
248 #endif /* defined(CONFIG_M528x) */
250 #endif /* !defined(CONFIG_M5441x) */
251 return MCFGPIO_PODR
+ mcfgpio_port(gpio
- MCFGPIO_SCR_START
);
257 /* return the port direction data register for a gpio */
258 static inline u32
__mcfgpio_pddr(unsigned gpio
)
260 #if defined(CONFIG_M5206) || defined(CONFIG_M5206e) || \
261 defined(CONFIG_M5307) || defined(CONFIG_M5407)
263 #elif defined(CONFIG_M5272)
270 #elif defined(CONFIG_M5249) || defined(CONFIG_M525x)
272 return MCFSIM2_GPIOENABLE
;
274 return MCFSIM2_GPIO1ENABLE
;
275 #elif defined(CONFIG_M520x) || defined(CONFIG_M523x) || \
276 defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
277 defined(CONFIG_M53xx) || defined(CONFIG_M54xx) || \
278 defined(CONFIG_M5441x)
279 #if !defined(CONFIG_M5441x)
281 return MCFEPORT_EPDDR
;
282 #if defined(CONFIG_M528x)
284 return MCFGPTA_GPTDDR
;
286 return MCFGPTB_GPTDDR
;
288 return MCFQADC_DDRQA
;
290 return MCFQADC_DDRQB
;
291 #endif /* defined(CONFIG_M528x) */
293 #endif /* !defined(CONFIG_M5441x) */
294 return MCFGPIO_PDDR
+ mcfgpio_port(gpio
- MCFGPIO_SCR_START
);
300 #endif /* mcfgpio_h */