1 /*
2  * linux/arch/arm/mach-w90x900/mfp.c
3  *
4  * Copyright (c) 2008 Nuvoton technology corporation
5  *
6  * Wan ZongShun <mcuos.com@gmail.com>
7  *
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.
11  */
12 
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>
23 
24 #include <mach/hardware.h>
25 
26 #define REG_MFSEL	(W90X900_VA_GCR + 0xC)
27 
28 #define GPSELF		(0x01 << 1)
29 
30 #define GPSELC		(0x03 << 2)
31 #define ENKPI		(0x02 << 2)
32 #define ENNAND		(0x01 << 2)
33 
34 #define GPSELEI0	(0x01 << 26)
35 #define GPSELEI1	(0x01 << 27)
36 
37 #define GPIOG0TO1	(0x03 << 14)
38 #define GPIOG2TO3	(0x03 << 16)
39 #define GPIOG22TO23	(0x03 << 22)
40 
41 #define ENSPI		(0x0a << 14)
42 #define ENI2C0		(0x01 << 14)
43 #define ENI2C1		(0x01 << 16)
44 #define ENAC97		(0x02 << 22)
45 
46 static DEFINE_MUTEX(mfp_mutex);
47 
mfp_set_groupf(struct device * dev)48 void mfp_set_groupf(struct device *dev)
49 {
50 	unsigned long mfpen;
51 	const char *dev_id;
52 
53 	BUG_ON(!dev);
54 
55 	mutex_lock(&mfp_mutex);
56 
57 	dev_id = dev_name(dev);
58 
59 	mfpen = __raw_readl(REG_MFSEL);
60 
61 	if (strcmp(dev_id, "nuc900-emc") == 0)
62 		mfpen |= GPSELF;/*enable mac*/
63 	else
64 		mfpen &= ~GPSELF;/*GPIOF[9:0]*/
65 
66 	__raw_writel(mfpen, REG_MFSEL);
67 
68 	mutex_unlock(&mfp_mutex);
69 }
70 EXPORT_SYMBOL(mfp_set_groupf);
71 
mfp_set_groupc(struct device * dev)72 void mfp_set_groupc(struct device *dev)
73 {
74 	unsigned long mfpen;
75 	const char *dev_id;
76 
77 	BUG_ON(!dev);
78 
79 	mutex_lock(&mfp_mutex);
80 
81 	dev_id = dev_name(dev);
82 
83 	mfpen = __raw_readl(REG_MFSEL);
84 
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]*/
95 
96 	__raw_writel(mfpen, REG_MFSEL);
97 
98 	mutex_unlock(&mfp_mutex);
99 }
100 EXPORT_SYMBOL(mfp_set_groupc);
101 
mfp_set_groupi(struct device * dev)102 void mfp_set_groupi(struct device *dev)
103 {
104 	unsigned long mfpen;
105 	const char *dev_id;
106 
107 	BUG_ON(!dev);
108 
109 	mutex_lock(&mfp_mutex);
110 
111 	dev_id = dev_name(dev);
112 
113 	mfpen = __raw_readl(REG_MFSEL);
114 
115 	mfpen &= ~GPSELEI1;/*default gpio16*/
116 
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*/
123 
124 	__raw_writel(mfpen, REG_MFSEL);
125 
126 	mutex_unlock(&mfp_mutex);
127 }
128 EXPORT_SYMBOL(mfp_set_groupi);
129 
mfp_set_groupg(struct device * dev)130 void mfp_set_groupg(struct device *dev)
131 {
132 	unsigned long mfpen;
133 	const char *dev_id;
134 
135 	BUG_ON(!dev);
136 
137 	mutex_lock(&mfp_mutex);
138 
139 	dev_id = dev_name(dev);
140 
141 	mfpen = __raw_readl(REG_MFSEL);
142 
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]*/
157 	}
158 
159 	__raw_writel(mfpen, REG_MFSEL);
160 
161 	mutex_unlock(&mfp_mutex);
162 }
163 EXPORT_SYMBOL(mfp_set_groupg);
164 
165