Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * MPC52xx gpio driver
  4 *
  5 * Copyright (c) 2008 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
 
 
 
 
 
 
 
 
 
 
 
 
 
  6 */
  7
  8#include <linux/of.h>
  9#include <linux/kernel.h>
 10#include <linux/slab.h>
 11#include <linux/gpio/legacy-of-mm-gpiochip.h>
 12#include <linux/io.h>
 13#include <linux/platform_device.h>
 14#include <linux/module.h>
 15
 
 16#include <asm/mpc52xx.h>
 17#include <sysdev/fsl_soc.h>
 18
 19static DEFINE_SPINLOCK(gpio_lock);
 20
 21struct mpc52xx_gpiochip {
 22	struct of_mm_gpio_chip mmchip;
 23	unsigned int shadow_dvo;
 24	unsigned int shadow_gpioe;
 25	unsigned int shadow_ddr;
 26};
 27
 28/*
 29 * GPIO LIB API implementation for wakeup GPIOs.
 30 *
 31 * There's a maximum of 8 wakeup GPIOs. Which of these are available
 32 * for use depends on your board setup.
 33 *
 34 * 0 -> GPIO_WKUP_7
 35 * 1 -> GPIO_WKUP_6
 36 * 2 -> PSC6_1
 37 * 3 -> PSC6_0
 38 * 4 -> ETH_17
 39 * 5 -> PSC3_9
 40 * 6 -> PSC2_4
 41 * 7 -> PSC1_4
 42 *
 43 */
 44static int mpc52xx_wkup_gpio_get(struct gpio_chip *gc, unsigned int gpio)
 45{
 46	struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
 47	struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
 48	unsigned int ret;
 49
 50	ret = (in_8(&regs->wkup_ival) >> (7 - gpio)) & 1;
 51
 52	pr_debug("%s: gpio: %d ret: %d\n", __func__, gpio, ret);
 53
 54	return ret;
 55}
 56
 57static inline void
 58__mpc52xx_wkup_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
 59{
 60	struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
 61	struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc);
 
 62	struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
 63
 64	if (val)
 65		chip->shadow_dvo |= 1 << (7 - gpio);
 66	else
 67		chip->shadow_dvo &= ~(1 << (7 - gpio));
 68
 69	out_8(&regs->wkup_dvo, chip->shadow_dvo);
 70}
 71
 72static void
 73mpc52xx_wkup_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
 74{
 75	unsigned long flags;
 76
 77	spin_lock_irqsave(&gpio_lock, flags);
 78
 79	__mpc52xx_wkup_gpio_set(gc, gpio, val);
 80
 81	spin_unlock_irqrestore(&gpio_lock, flags);
 82
 83	pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
 84}
 85
 86static int mpc52xx_wkup_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
 87{
 88	struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
 89	struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc);
 
 90	struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
 91	unsigned long flags;
 92
 93	spin_lock_irqsave(&gpio_lock, flags);
 94
 95	/* set the direction */
 96	chip->shadow_ddr &= ~(1 << (7 - gpio));
 97	out_8(&regs->wkup_ddr, chip->shadow_ddr);
 98
 99	/* and enable the pin */
100	chip->shadow_gpioe |= 1 << (7 - gpio);
101	out_8(&regs->wkup_gpioe, chip->shadow_gpioe);
102
103	spin_unlock_irqrestore(&gpio_lock, flags);
104
105	return 0;
106}
107
108static int
109mpc52xx_wkup_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
110{
111	struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
112	struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
113	struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc);
 
114	unsigned long flags;
115
116	spin_lock_irqsave(&gpio_lock, flags);
117
118	__mpc52xx_wkup_gpio_set(gc, gpio, val);
119
120	/* Then set direction */
121	chip->shadow_ddr |= 1 << (7 - gpio);
122	out_8(&regs->wkup_ddr, chip->shadow_ddr);
123
124	/* Finally enable the pin */
125	chip->shadow_gpioe |= 1 << (7 - gpio);
126	out_8(&regs->wkup_gpioe, chip->shadow_gpioe);
127
128	spin_unlock_irqrestore(&gpio_lock, flags);
129
130	pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
131
132	return 0;
133}
134
135static int mpc52xx_wkup_gpiochip_probe(struct platform_device *ofdev)
136{
137	struct mpc52xx_gpiochip *chip;
138	struct mpc52xx_gpio_wkup __iomem *regs;
139	struct gpio_chip *gc;
140	int ret;
141
142	chip = devm_kzalloc(&ofdev->dev, sizeof(*chip), GFP_KERNEL);
143	if (!chip)
144		return -ENOMEM;
145
146	platform_set_drvdata(ofdev, chip);
147
148	gc = &chip->mmchip.gc;
149
150	gc->ngpio            = 8;
151	gc->direction_input  = mpc52xx_wkup_gpio_dir_in;
152	gc->direction_output = mpc52xx_wkup_gpio_dir_out;
153	gc->get              = mpc52xx_wkup_gpio_get;
154	gc->set              = mpc52xx_wkup_gpio_set;
155
156	ret = of_mm_gpiochip_add_data(ofdev->dev.of_node, &chip->mmchip, chip);
157	if (ret)
158		return ret;
159
160	regs = chip->mmchip.regs;
161	chip->shadow_gpioe = in_8(&regs->wkup_gpioe);
162	chip->shadow_ddr = in_8(&regs->wkup_ddr);
163	chip->shadow_dvo = in_8(&regs->wkup_dvo);
164
165	return 0;
166}
167
168static void mpc52xx_gpiochip_remove(struct platform_device *ofdev)
169{
170	struct mpc52xx_gpiochip *chip = platform_get_drvdata(ofdev);
171
172	of_mm_gpiochip_remove(&chip->mmchip);
173}
174
175static const struct of_device_id mpc52xx_wkup_gpiochip_match[] = {
176	{ .compatible = "fsl,mpc5200-gpio-wkup", },
177	{}
178};
179
180static struct platform_driver mpc52xx_wkup_gpiochip_driver = {
181	.driver = {
182		.name = "mpc5200-gpio-wkup",
 
183		.of_match_table = mpc52xx_wkup_gpiochip_match,
184	},
185	.probe = mpc52xx_wkup_gpiochip_probe,
186	.remove_new = mpc52xx_gpiochip_remove,
187};
188
189/*
190 * GPIO LIB API implementation for simple GPIOs
191 *
192 * There's a maximum of 32 simple GPIOs. Which of these are available
193 * for use depends on your board setup.
194 * The numbering reflects the bit numbering in the port registers:
195 *
196 *  0..1  > reserved
197 *  2..3  > IRDA
198 *  4..7  > ETHR
199 *  8..11 > reserved
200 * 12..15 > USB
201 * 16..17 > reserved
202 * 18..23 > PSC3
203 * 24..27 > PSC2
204 * 28..31 > PSC1
205 */
206static int mpc52xx_simple_gpio_get(struct gpio_chip *gc, unsigned int gpio)
207{
208	struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
209	struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
210	unsigned int ret;
211
212	ret = (in_be32(&regs->simple_ival) >> (31 - gpio)) & 1;
213
214	return ret;
215}
216
217static inline void
218__mpc52xx_simple_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
219{
220	struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
221	struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc);
 
222	struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
223
224	if (val)
225		chip->shadow_dvo |= 1 << (31 - gpio);
226	else
227		chip->shadow_dvo &= ~(1 << (31 - gpio));
228	out_be32(&regs->simple_dvo, chip->shadow_dvo);
229}
230
231static void
232mpc52xx_simple_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
233{
234	unsigned long flags;
235
236	spin_lock_irqsave(&gpio_lock, flags);
237
238	__mpc52xx_simple_gpio_set(gc, gpio, val);
239
240	spin_unlock_irqrestore(&gpio_lock, flags);
241
242	pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
243}
244
245static int mpc52xx_simple_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
246{
247	struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
248	struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc);
 
249	struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
250	unsigned long flags;
251
252	spin_lock_irqsave(&gpio_lock, flags);
253
254	/* set the direction */
255	chip->shadow_ddr &= ~(1 << (31 - gpio));
256	out_be32(&regs->simple_ddr, chip->shadow_ddr);
257
258	/* and enable the pin */
259	chip->shadow_gpioe |= 1 << (31 - gpio);
260	out_be32(&regs->simple_gpioe, chip->shadow_gpioe);
261
262	spin_unlock_irqrestore(&gpio_lock, flags);
263
264	return 0;
265}
266
267static int
268mpc52xx_simple_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
269{
270	struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
271	struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc);
 
272	struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
273	unsigned long flags;
274
275	spin_lock_irqsave(&gpio_lock, flags);
276
277	/* First set initial value */
278	__mpc52xx_simple_gpio_set(gc, gpio, val);
279
280	/* Then set direction */
281	chip->shadow_ddr |= 1 << (31 - gpio);
282	out_be32(&regs->simple_ddr, chip->shadow_ddr);
283
284	/* Finally enable the pin */
285	chip->shadow_gpioe |= 1 << (31 - gpio);
286	out_be32(&regs->simple_gpioe, chip->shadow_gpioe);
287
288	spin_unlock_irqrestore(&gpio_lock, flags);
289
290	pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
291
292	return 0;
293}
294
295static int mpc52xx_simple_gpiochip_probe(struct platform_device *ofdev)
296{
297	struct mpc52xx_gpiochip *chip;
298	struct gpio_chip *gc;
299	struct mpc52xx_gpio __iomem *regs;
300	int ret;
301
302	chip = devm_kzalloc(&ofdev->dev, sizeof(*chip), GFP_KERNEL);
303	if (!chip)
304		return -ENOMEM;
305
306	platform_set_drvdata(ofdev, chip);
307
308	gc = &chip->mmchip.gc;
309
310	gc->ngpio            = 32;
311	gc->direction_input  = mpc52xx_simple_gpio_dir_in;
312	gc->direction_output = mpc52xx_simple_gpio_dir_out;
313	gc->get              = mpc52xx_simple_gpio_get;
314	gc->set              = mpc52xx_simple_gpio_set;
315
316	ret = of_mm_gpiochip_add_data(ofdev->dev.of_node, &chip->mmchip, chip);
317	if (ret)
318		return ret;
319
320	regs = chip->mmchip.regs;
321	chip->shadow_gpioe = in_be32(&regs->simple_gpioe);
322	chip->shadow_ddr = in_be32(&regs->simple_ddr);
323	chip->shadow_dvo = in_be32(&regs->simple_dvo);
324
325	return 0;
326}
327
328static const struct of_device_id mpc52xx_simple_gpiochip_match[] = {
329	{ .compatible = "fsl,mpc5200-gpio", },
330	{}
331};
332
333static struct platform_driver mpc52xx_simple_gpiochip_driver = {
334	.driver = {
335		.name = "mpc5200-gpio",
 
336		.of_match_table = mpc52xx_simple_gpiochip_match,
337	},
338	.probe = mpc52xx_simple_gpiochip_probe,
339	.remove_new = mpc52xx_gpiochip_remove,
340};
341
342static struct platform_driver * const drivers[] = {
343	&mpc52xx_wkup_gpiochip_driver,
344	&mpc52xx_simple_gpiochip_driver,
345};
346
347static int __init mpc52xx_gpio_init(void)
348{
349	return platform_register_drivers(drivers, ARRAY_SIZE(drivers));
 
 
 
 
 
 
350}
351
 
352/* Make sure we get initialised before anyone else tries to use us */
353subsys_initcall(mpc52xx_gpio_init);
354
355static void __exit mpc52xx_gpio_exit(void)
356{
357	platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
358}
359module_exit(mpc52xx_gpio_exit);
360
361MODULE_DESCRIPTION("Freescale MPC52xx gpio driver");
362MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de");
363MODULE_LICENSE("GPL v2");
364
v3.1
 
  1/*
  2 * MPC52xx gpio driver
  3 *
  4 * Copyright (c) 2008 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
  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 version 2
  8 * as published by the Free Software Foundation.
  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 * You should have received a copy of the GNU General Public License
 16 * along with this program; if not, write to the Free Software
 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18 */
 19
 20#include <linux/of.h>
 21#include <linux/kernel.h>
 22#include <linux/slab.h>
 23#include <linux/of_gpio.h>
 24#include <linux/io.h>
 25#include <linux/of_platform.h>
 
 26
 27#include <asm/gpio.h>
 28#include <asm/mpc52xx.h>
 29#include <sysdev/fsl_soc.h>
 30
 31static DEFINE_SPINLOCK(gpio_lock);
 32
 33struct mpc52xx_gpiochip {
 34	struct of_mm_gpio_chip mmchip;
 35	unsigned int shadow_dvo;
 36	unsigned int shadow_gpioe;
 37	unsigned int shadow_ddr;
 38};
 39
 40/*
 41 * GPIO LIB API implementation for wakeup GPIOs.
 42 *
 43 * There's a maximum of 8 wakeup GPIOs. Which of these are available
 44 * for use depends on your board setup.
 45 *
 46 * 0 -> GPIO_WKUP_7
 47 * 1 -> GPIO_WKUP_6
 48 * 2 -> PSC6_1
 49 * 3 -> PSC6_0
 50 * 4 -> ETH_17
 51 * 5 -> PSC3_9
 52 * 6 -> PSC2_4
 53 * 7 -> PSC1_4
 54 *
 55 */
 56static int mpc52xx_wkup_gpio_get(struct gpio_chip *gc, unsigned int gpio)
 57{
 58	struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
 59	struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
 60	unsigned int ret;
 61
 62	ret = (in_8(&regs->wkup_ival) >> (7 - gpio)) & 1;
 63
 64	pr_debug("%s: gpio: %d ret: %d\n", __func__, gpio, ret);
 65
 66	return ret;
 67}
 68
 69static inline void
 70__mpc52xx_wkup_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
 71{
 72	struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
 73	struct mpc52xx_gpiochip *chip = container_of(mm_gc,
 74			struct mpc52xx_gpiochip, mmchip);
 75	struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
 76
 77	if (val)
 78		chip->shadow_dvo |= 1 << (7 - gpio);
 79	else
 80		chip->shadow_dvo &= ~(1 << (7 - gpio));
 81
 82	out_8(&regs->wkup_dvo, chip->shadow_dvo);
 83}
 84
 85static void
 86mpc52xx_wkup_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
 87{
 88	unsigned long flags;
 89
 90	spin_lock_irqsave(&gpio_lock, flags);
 91
 92	__mpc52xx_wkup_gpio_set(gc, gpio, val);
 93
 94	spin_unlock_irqrestore(&gpio_lock, flags);
 95
 96	pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
 97}
 98
 99static int mpc52xx_wkup_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
100{
101	struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
102	struct mpc52xx_gpiochip *chip = container_of(mm_gc,
103			struct mpc52xx_gpiochip, mmchip);
104	struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
105	unsigned long flags;
106
107	spin_lock_irqsave(&gpio_lock, flags);
108
109	/* set the direction */
110	chip->shadow_ddr &= ~(1 << (7 - gpio));
111	out_8(&regs->wkup_ddr, chip->shadow_ddr);
112
113	/* and enable the pin */
114	chip->shadow_gpioe |= 1 << (7 - gpio);
115	out_8(&regs->wkup_gpioe, chip->shadow_gpioe);
116
117	spin_unlock_irqrestore(&gpio_lock, flags);
118
119	return 0;
120}
121
122static int
123mpc52xx_wkup_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
124{
125	struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
126	struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
127	struct mpc52xx_gpiochip *chip = container_of(mm_gc,
128			struct mpc52xx_gpiochip, mmchip);
129	unsigned long flags;
130
131	spin_lock_irqsave(&gpio_lock, flags);
132
133	__mpc52xx_wkup_gpio_set(gc, gpio, val);
134
135	/* Then set direction */
136	chip->shadow_ddr |= 1 << (7 - gpio);
137	out_8(&regs->wkup_ddr, chip->shadow_ddr);
138
139	/* Finally enable the pin */
140	chip->shadow_gpioe |= 1 << (7 - gpio);
141	out_8(&regs->wkup_gpioe, chip->shadow_gpioe);
142
143	spin_unlock_irqrestore(&gpio_lock, flags);
144
145	pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
146
147	return 0;
148}
149
150static int __devinit mpc52xx_wkup_gpiochip_probe(struct platform_device *ofdev)
151{
152	struct mpc52xx_gpiochip *chip;
153	struct mpc52xx_gpio_wkup __iomem *regs;
154	struct gpio_chip *gc;
155	int ret;
156
157	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
158	if (!chip)
159		return -ENOMEM;
160
 
 
161	gc = &chip->mmchip.gc;
162
163	gc->ngpio            = 8;
164	gc->direction_input  = mpc52xx_wkup_gpio_dir_in;
165	gc->direction_output = mpc52xx_wkup_gpio_dir_out;
166	gc->get              = mpc52xx_wkup_gpio_get;
167	gc->set              = mpc52xx_wkup_gpio_set;
168
169	ret = of_mm_gpiochip_add(ofdev->dev.of_node, &chip->mmchip);
170	if (ret)
171		return ret;
172
173	regs = chip->mmchip.regs;
174	chip->shadow_gpioe = in_8(&regs->wkup_gpioe);
175	chip->shadow_ddr = in_8(&regs->wkup_ddr);
176	chip->shadow_dvo = in_8(&regs->wkup_dvo);
177
178	return 0;
179}
180
181static int mpc52xx_gpiochip_remove(struct platform_device *ofdev)
182{
183	return -EBUSY;
 
 
184}
185
186static const struct of_device_id mpc52xx_wkup_gpiochip_match[] = {
187	{ .compatible = "fsl,mpc5200-gpio-wkup", },
188	{}
189};
190
191static struct platform_driver mpc52xx_wkup_gpiochip_driver = {
192	.driver = {
193		.name = "mpc5200-gpio-wkup",
194		.owner = THIS_MODULE,
195		.of_match_table = mpc52xx_wkup_gpiochip_match,
196	},
197	.probe = mpc52xx_wkup_gpiochip_probe,
198	.remove = mpc52xx_gpiochip_remove,
199};
200
201/*
202 * GPIO LIB API implementation for simple GPIOs
203 *
204 * There's a maximum of 32 simple GPIOs. Which of these are available
205 * for use depends on your board setup.
206 * The numbering reflects the bit numbering in the port registers:
207 *
208 *  0..1  > reserved
209 *  2..3  > IRDA
210 *  4..7  > ETHR
211 *  8..11 > reserved
212 * 12..15 > USB
213 * 16..17 > reserved
214 * 18..23 > PSC3
215 * 24..27 > PSC2
216 * 28..31 > PSC1
217 */
218static int mpc52xx_simple_gpio_get(struct gpio_chip *gc, unsigned int gpio)
219{
220	struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
221	struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
222	unsigned int ret;
223
224	ret = (in_be32(&regs->simple_ival) >> (31 - gpio)) & 1;
225
226	return ret;
227}
228
229static inline void
230__mpc52xx_simple_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
231{
232	struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
233	struct mpc52xx_gpiochip *chip = container_of(mm_gc,
234			struct mpc52xx_gpiochip, mmchip);
235	struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
236
237	if (val)
238		chip->shadow_dvo |= 1 << (31 - gpio);
239	else
240		chip->shadow_dvo &= ~(1 << (31 - gpio));
241	out_be32(&regs->simple_dvo, chip->shadow_dvo);
242}
243
244static void
245mpc52xx_simple_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
246{
247	unsigned long flags;
248
249	spin_lock_irqsave(&gpio_lock, flags);
250
251	__mpc52xx_simple_gpio_set(gc, gpio, val);
252
253	spin_unlock_irqrestore(&gpio_lock, flags);
254
255	pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
256}
257
258static int mpc52xx_simple_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
259{
260	struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
261	struct mpc52xx_gpiochip *chip = container_of(mm_gc,
262			struct mpc52xx_gpiochip, mmchip);
263	struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
264	unsigned long flags;
265
266	spin_lock_irqsave(&gpio_lock, flags);
267
268	/* set the direction */
269	chip->shadow_ddr &= ~(1 << (31 - gpio));
270	out_be32(&regs->simple_ddr, chip->shadow_ddr);
271
272	/* and enable the pin */
273	chip->shadow_gpioe |= 1 << (31 - gpio);
274	out_be32(&regs->simple_gpioe, chip->shadow_gpioe);
275
276	spin_unlock_irqrestore(&gpio_lock, flags);
277
278	return 0;
279}
280
281static int
282mpc52xx_simple_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
283{
284	struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
285	struct mpc52xx_gpiochip *chip = container_of(mm_gc,
286			struct mpc52xx_gpiochip, mmchip);
287	struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
288	unsigned long flags;
289
290	spin_lock_irqsave(&gpio_lock, flags);
291
292	/* First set initial value */
293	__mpc52xx_simple_gpio_set(gc, gpio, val);
294
295	/* Then set direction */
296	chip->shadow_ddr |= 1 << (31 - gpio);
297	out_be32(&regs->simple_ddr, chip->shadow_ddr);
298
299	/* Finally enable the pin */
300	chip->shadow_gpioe |= 1 << (31 - gpio);
301	out_be32(&regs->simple_gpioe, chip->shadow_gpioe);
302
303	spin_unlock_irqrestore(&gpio_lock, flags);
304
305	pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
306
307	return 0;
308}
309
310static int __devinit mpc52xx_simple_gpiochip_probe(struct platform_device *ofdev)
311{
312	struct mpc52xx_gpiochip *chip;
313	struct gpio_chip *gc;
314	struct mpc52xx_gpio __iomem *regs;
315	int ret;
316
317	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
318	if (!chip)
319		return -ENOMEM;
320
 
 
321	gc = &chip->mmchip.gc;
322
323	gc->ngpio            = 32;
324	gc->direction_input  = mpc52xx_simple_gpio_dir_in;
325	gc->direction_output = mpc52xx_simple_gpio_dir_out;
326	gc->get              = mpc52xx_simple_gpio_get;
327	gc->set              = mpc52xx_simple_gpio_set;
328
329	ret = of_mm_gpiochip_add(ofdev->dev.of_node, &chip->mmchip);
330	if (ret)
331		return ret;
332
333	regs = chip->mmchip.regs;
334	chip->shadow_gpioe = in_be32(&regs->simple_gpioe);
335	chip->shadow_ddr = in_be32(&regs->simple_ddr);
336	chip->shadow_dvo = in_be32(&regs->simple_dvo);
337
338	return 0;
339}
340
341static const struct of_device_id mpc52xx_simple_gpiochip_match[] = {
342	{ .compatible = "fsl,mpc5200-gpio", },
343	{}
344};
345
346static struct platform_driver mpc52xx_simple_gpiochip_driver = {
347	.driver = {
348		.name = "mpc5200-gpio",
349		.owner = THIS_MODULE,
350		.of_match_table = mpc52xx_simple_gpiochip_match,
351	},
352	.probe = mpc52xx_simple_gpiochip_probe,
353	.remove = mpc52xx_gpiochip_remove,
 
 
 
 
 
354};
355
356static int __init mpc52xx_gpio_init(void)
357{
358	if (platform_driver_register(&mpc52xx_wkup_gpiochip_driver))
359		printk(KERN_ERR "Unable to register wakeup GPIO driver\n");
360
361	if (platform_driver_register(&mpc52xx_simple_gpiochip_driver))
362		printk(KERN_ERR "Unable to register simple GPIO driver\n");
363
364	return 0;
365}
366
367
368/* Make sure we get initialised before anyone else tries to use us */
369subsys_initcall(mpc52xx_gpio_init);
370
371/* No exit call at the moment as we cannot unregister of gpio chips */
 
 
 
 
372
373MODULE_DESCRIPTION("Freescale MPC52xx gpio driver");
374MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de");
375MODULE_LICENSE("GPL v2");
376