kvm tools, setup: Create private directory
[linux-2.6/next.git] / arch / arm / mach-w90x900 / mfp.c
blobfb7fb627b1a564ca920fdb747080988f3fb75551
1 /*
2 * linux/arch/arm/mach-w90x900/mfp.c
4 * Copyright (c) 2008 Nuvoton technology corporation
6 * Wan ZongShun <mcuos.com@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation;version 2 of the License.
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/device.h>
16 #include <linux/list.h>
17 #include <linux/errno.h>
18 #include <linux/err.h>
19 #include <linux/string.h>
20 #include <linux/clk.h>
21 #include <linux/mutex.h>
22 #include <linux/io.h>
24 #include <mach/hardware.h>
26 #define REG_MFSEL (W90X900_VA_GCR + 0xC)
28 #define GPSELF (0x01 << 1)
30 #define GPSELC (0x03 << 2)
31 #define ENKPI (0x02 << 2)
32 #define ENNAND (0x01 << 2)
34 #define GPSELEI0 (0x01 << 26)
35 #define GPSELEI1 (0x01 << 27)
37 #define GPIOG0TO1 (0x03 << 14)
38 #define GPIOG2TO3 (0x03 << 16)
39 #define GPIOG22TO23 (0x03 << 22)
41 #define ENSPI (0x0a << 14)
42 #define ENI2C0 (0x01 << 14)
43 #define ENI2C1 (0x01 << 16)
44 #define ENAC97 (0x02 << 22)
46 static DEFINE_MUTEX(mfp_mutex);
48 void mfp_set_groupf(struct device *dev)
50 unsigned long mfpen;
51 const char *dev_id;
53 BUG_ON(!dev);
55 mutex_lock(&mfp_mutex);
57 dev_id = dev_name(dev);
59 mfpen = __raw_readl(REG_MFSEL);
61 if (strcmp(dev_id, "nuc900-emc") == 0)
62 mfpen |= GPSELF;/*enable mac*/
63 else
64 mfpen &= ~GPSELF;/*GPIOF[9:0]*/
66 __raw_writel(mfpen, REG_MFSEL);
68 mutex_unlock(&mfp_mutex);
70 EXPORT_SYMBOL(mfp_set_groupf);
72 void mfp_set_groupc(struct device *dev)
74 unsigned long mfpen;
75 const char *dev_id;
77 BUG_ON(!dev);
79 mutex_lock(&mfp_mutex);
81 dev_id = dev_name(dev);
83 mfpen = __raw_readl(REG_MFSEL);
85 if (strcmp(dev_id, "nuc900-lcd") == 0)
86 mfpen |= GPSELC;/*enable lcd*/
87 else if (strcmp(dev_id, "nuc900-kpi") == 0) {
88 mfpen &= (~GPSELC);/*enable kpi*/
89 mfpen |= ENKPI;
90 } else if (strcmp(dev_id, "nuc900-nand") == 0) {
91 mfpen &= (~GPSELC);/*enable nand*/
92 mfpen |= ENNAND;
93 } else
94 mfpen &= (~GPSELC);/*GPIOC[14:0]*/
96 __raw_writel(mfpen, REG_MFSEL);
98 mutex_unlock(&mfp_mutex);
100 EXPORT_SYMBOL(mfp_set_groupc);
102 void mfp_set_groupi(struct device *dev)
104 unsigned long mfpen;
105 const char *dev_id;
107 BUG_ON(!dev);
109 mutex_lock(&mfp_mutex);
111 dev_id = dev_name(dev);
113 mfpen = __raw_readl(REG_MFSEL);
115 mfpen &= ~GPSELEI1;/*default gpio16*/
117 if (strcmp(dev_id, "nuc900-wdog") == 0)
118 mfpen |= GPSELEI1;/*enable wdog*/
119 else if (strcmp(dev_id, "nuc900-atapi") == 0)
120 mfpen |= GPSELEI0;/*enable atapi*/
121 else if (strcmp(dev_id, "nuc900-keypad") == 0)
122 mfpen &= ~GPSELEI0;/*enable keypad*/
124 __raw_writel(mfpen, REG_MFSEL);
126 mutex_unlock(&mfp_mutex);
128 EXPORT_SYMBOL(mfp_set_groupi);
130 void mfp_set_groupg(struct device *dev)
132 unsigned long mfpen;
133 const char *dev_id;
135 BUG_ON(!dev);
137 mutex_lock(&mfp_mutex);
139 dev_id = dev_name(dev);
141 mfpen = __raw_readl(REG_MFSEL);
143 if (strcmp(dev_id, "nuc900-spi") == 0) {
144 mfpen &= ~(GPIOG0TO1 | GPIOG2TO3);
145 mfpen |= ENSPI;/*enable spi*/
146 } else if (strcmp(dev_id, "nuc900-i2c0") == 0) {
147 mfpen &= ~(GPIOG0TO1);
148 mfpen |= ENI2C0;/*enable i2c0*/
149 } else if (strcmp(dev_id, "nuc900-i2c1") == 0) {
150 mfpen &= ~(GPIOG2TO3);
151 mfpen |= ENI2C1;/*enable i2c1*/
152 } else if (strcmp(dev_id, "nuc900-audio") == 0) {
153 mfpen &= ~(GPIOG22TO23);
154 mfpen |= ENAC97;/*enable AC97*/
155 } else {
156 mfpen &= ~(GPIOG0TO1 | GPIOG2TO3);/*GPIOG[3:0]*/
159 __raw_writel(mfpen, REG_MFSEL);
161 mutex_unlock(&mfp_mutex);
163 EXPORT_SYMBOL(mfp_set_groupg);