[s3c24xx] bump to 2.6.30-rc6
[openwrt.git] / target / linux / s3c24xx / files-2.6.30 / arch / arm / mach-s3c2442 / gta02-shadow.c
1 /*
2 * Common utility code for GTA02
3 *
4 * Copyright (C) 2008 by Openmoko, Inc.
5 * Author: Holger Hans Peter Freyther <freyther@openmoko.org>
6 * All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 *
23 */
24
25 #include <linux/module.h>
26 #include <linux/io.h>
27 #include <linux/irq.h>
28
29 #include <asm/gpio.h>
30 #include <mach/regs-gpio.h>
31 #include <linux/gta02-shadow.h>
32
33 /**
34 * Shadow GPIO bank B handling. For the LEDs we need to keep track of the state
35 * in software. The s3c2410_gpio_setpin must not be used for GPIOs on bank B
36 */
37 static unsigned long gpb_mask;
38 static unsigned long gpb_state;
39
40 void gta02_gpb_add_shadow_gpio(unsigned int gpio)
41 {
42 unsigned long offset = S3C2410_GPIO_OFFSET(gpio);
43 unsigned long flags;
44
45 local_irq_save(flags);
46 gpb_mask |= 1L << offset;
47 local_irq_restore(flags);
48 }
49 EXPORT_SYMBOL(gta02_gpb_add_shadow_gpio);
50
51 static void set_shadow_gpio(unsigned long offset, unsigned int value)
52 {
53 unsigned long state = value != 0;
54
55 gpb_state &= ~(1L << offset);
56 gpb_state |= state << offset;
57 }
58
59 void gta02_gpb_setpin(unsigned int pin, unsigned to)
60 {
61 void __iomem *base = S3C24XX_GPIO_BASE(S3C2410_GPB0);
62 unsigned long offset = S3C2410_GPIO_OFFSET(pin);
63 unsigned long flags;
64 unsigned long dat;
65
66 BUG_ON(base != S3C24XX_GPIO_BASE(pin));
67
68 local_irq_save(flags);
69 dat = __raw_readl(base + 0x04);
70
71 /* Add the shadow values */
72 dat &= ~gpb_mask;
73 dat |= gpb_state;
74
75 /* Do the operation like s3c2410_gpio_setpin */
76 dat &= ~(1L << offset);
77 dat |= to << offset;
78
79 /* Update the shadow state */
80 if ((1L << offset) & gpb_mask)
81 set_shadow_gpio(offset, to);
82
83 __raw_writel(dat, base + 0x04);
84 local_irq_restore(flags);
85 }
86 EXPORT_SYMBOL(gta02_gpb_setpin);
This page took 0.046251 seconds and 5 git commands to generate.