xref: /linux/arch/m68k/include/asm/mcfgpio.h (revision e269f90f3d3f7c70cf661c660bf445597261f54a)
1 /*
2  * Coldfire generic GPIO support.
3  *
4  * (C) Copyright 2009, Steven King <sfking@fdwdc.com>
5  *
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.
9  *
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.
14  */
15 
16 #ifndef mcfgpio_h
17 #define mcfgpio_h
18 
19 #include <linux/io.h>
20 #include <asm-generic/gpio.h>
21 
22 struct mcf_gpio_chip {
23 	struct gpio_chip gpio_chip;
24 	void __iomem *pddr;
25 	void __iomem *podr;
26 	void __iomem *ppdr;
27 	void __iomem *setr;
28 	void __iomem *clrr;
29 	const u8 *gpio_to_pinmux;
30 };
31 
32 extern struct mcf_gpio_chip mcf_gpio_chips[];
33 extern unsigned int mcf_gpio_chips_size;
34 
35 int mcf_gpio_direction_input(struct gpio_chip *, unsigned);
36 int mcf_gpio_get_value(struct gpio_chip *, unsigned);
37 int mcf_gpio_direction_output(struct gpio_chip *, unsigned, int);
38 void mcf_gpio_set_value(struct gpio_chip *, unsigned, int);
39 void mcf_gpio_set_value_fast(struct gpio_chip *, unsigned, int);
40 int mcf_gpio_request(struct gpio_chip *, unsigned);
41 void mcf_gpio_free(struct gpio_chip *, unsigned);
42 
43 /*
44  *	Define macros to ease the pain of setting up the GPIO tables. There
45  *	are two cases we need to deal with here, they cover all currently
46  *	available ColdFire GPIO hardware. There are of course minor differences
47  *	in the layout and number of bits in each ColdFire part, but the macros
48  *	take all that in.
49  *
50  *	Firstly is the conventional GPIO registers where we toggle individual
51  *	bits in a register, preserving the other bits in the register. For
52  *	lack of a better term I have called this the slow method.
53  */
54 #define	MCFGPS(mlabel, mbase, mngpio, mpddr, mpodr, mppdr)		    \
55 	{								    \
56 		.gpio_chip			= {			    \
57 			.label			= #mlabel,		    \
58 			.request		= mcf_gpio_request,	    \
59 			.free			= mcf_gpio_free,	    \
60 			.direction_input	= mcf_gpio_direction_input, \
61 			.direction_output	= mcf_gpio_direction_output,\
62 			.get			= mcf_gpio_get_value,	    \
63 			.set			= mcf_gpio_set_value,       \
64 			.base			= mbase,		    \
65 			.ngpio			= mngpio,		    \
66 		},							    \
67 		.pddr		= (void __iomem *) mpddr,		    \
68 		.podr		= (void __iomem *) mpodr,		    \
69 		.ppdr		= (void __iomem *) mppdr,		    \
70 	}
71 
72 /*
73  *	Secondly is the faster case, where we have set and clear registers
74  *	that allow us to set or clear a bit with a single write, not having
75  *	to worry about preserving other bits.
76  */
77 #define	MCFGPF(mlabel, mbase, mngpio)					    \
78 	{								    \
79 		.gpio_chip			= {			    \
80 			.label			= #mlabel,		    \
81 			.request		= mcf_gpio_request,	    \
82 			.free			= mcf_gpio_free,	    \
83 			.direction_input	= mcf_gpio_direction_input, \
84 			.direction_output	= mcf_gpio_direction_output,\
85 			.get			= mcf_gpio_get_value,	    \
86 			.set			= mcf_gpio_set_value_fast,  \
87 			.base			= mbase,		    \
88 			.ngpio			= mngpio,		    \
89 		},							    \
90 		.pddr		= (void __iomem *) MCFGPIO_PDDR_##mlabel,   \
91 		.podr		= (void __iomem *) MCFGPIO_PODR_##mlabel,   \
92 		.ppdr		= (void __iomem *) MCFGPIO_PPDSDR_##mlabel, \
93 		.setr		= (void __iomem *) MCFGPIO_PPDSDR_##mlabel, \
94 		.clrr		= (void __iomem *) MCFGPIO_PCLRR_##mlabel,  \
95 	}
96 
97 #endif
98