2 * Common utility code for GTA02
4 * Copyright (C) 2008 by Openmoko, Inc.
5 * Author: Holger Hans Peter Freyther <freyther@openmoko.org>
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.
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.
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,
25 #include <linux/module.h>
27 #include <linux/irq.h>
30 #include <mach/regs-gpio.h>
31 #include <linux/gta02-shadow.h>
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
37 static unsigned long gpb_mask
;
38 static unsigned long gpb_state
;
40 void gta02_gpb_add_shadow_gpio(unsigned int gpio
)
42 unsigned long offset
= S3C2410_GPIO_OFFSET(gpio
);
45 local_irq_save(flags
);
46 gpb_mask
|= 1L << offset
;
47 local_irq_restore(flags
);
49 EXPORT_SYMBOL(gta02_gpb_add_shadow_gpio
);
51 static void set_shadow_gpio(unsigned long offset
, unsigned int value
)
53 unsigned long state
= value
!= 0;
55 gpb_state
&= ~(1L << offset
);
56 gpb_state
|= state
<< offset
;
59 void gta02_gpb_setpin(unsigned int pin
, unsigned to
)
61 void __iomem
*base
= S3C24XX_GPIO_BASE(S3C2410_GPB0
);
62 unsigned long offset
= S3C2410_GPIO_OFFSET(pin
);
66 BUG_ON(base
!= S3C24XX_GPIO_BASE(pin
));
68 local_irq_save(flags
);
69 dat
= __raw_readl(base
+ 0x04);
71 /* Add the shadow values */
75 /* Do the operation like s3c2410_gpio_setpin */
76 dat
&= ~(1L << offset
);
79 /* Update the shadow state */
80 if ((1L << offset
) & gpb_mask
)
81 set_shadow_gpio(offset
, to
);
83 __raw_writel(dat
, base
+ 0x04);
84 local_irq_restore(flags
);
86 EXPORT_SYMBOL(gta02_gpb_setpin
);