blob: c58d142b8a467134d193d2252ce52a361e314fcf [file] [log] [blame]
wanzongshun27eb9752009-06-11 14:30:07 +01001/*
wanzongshun35c92212009-08-21 07:07:46 +01002 * linux/arch/arm/mach-w90x900/mfp.c
wanzongshun27eb9752009-06-11 14:30:07 +01003 *
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)
wanzongshun27eb9752009-06-11 14:30:07 +010029#define GPSELC (0x03 << 2)
wanzongshun798681b2011-11-10 07:06:29 +010030#define GPSELD (0x0f << 4)
wanzongshun27eb9752009-06-11 14:30:07 +010031
32#define GPSELEI0 (0x01 << 26)
33#define GPSELEI1 (0x01 << 27)
34
wanzongshun3f3f1d92009-07-23 08:52:51 +010035#define GPIOG0TO1 (0x03 << 14)
36#define GPIOG2TO3 (0x03 << 16)
wanzongshun3d34a0d2010-05-22 15:23:23 +010037#define GPIOG22TO23 (0x03 << 22)
wanzongshun798681b2011-11-10 07:06:29 +010038#define GPIOG18TO20 (0x07 << 18)
wanzongshun3d34a0d2010-05-22 15:23:23 +010039
wanzongshun3f3f1d92009-07-23 08:52:51 +010040#define ENSPI (0x0a << 14)
41#define ENI2C0 (0x01 << 14)
42#define ENI2C1 (0x01 << 16)
wanzongshun3d34a0d2010-05-22 15:23:23 +010043#define ENAC97 (0x02 << 22)
wanzongshun798681b2011-11-10 07:06:29 +010044#define ENSD1 (0x02 << 18)
45#define ENSD0 (0x0a << 4)
46#define ENKPI (0x02 << 2)
47#define ENNAND (0x01 << 2)
wanzongshun3f3f1d92009-07-23 08:52:51 +010048
wanzongshunf346bec2009-08-14 15:37:42 +010049static DEFINE_MUTEX(mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +010050
51void mfp_set_groupf(struct device *dev)
52{
53 unsigned long mfpen;
54 const char *dev_id;
55
56 BUG_ON(!dev);
57
wanzongshunf346bec2009-08-14 15:37:42 +010058 mutex_lock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +010059
60 dev_id = dev_name(dev);
61
62 mfpen = __raw_readl(REG_MFSEL);
63
wanzongshun35c92212009-08-21 07:07:46 +010064 if (strcmp(dev_id, "nuc900-emc") == 0)
wanzongshun27eb9752009-06-11 14:30:07 +010065 mfpen |= GPSELF;/*enable mac*/
66 else
67 mfpen &= ~GPSELF;/*GPIOF[9:0]*/
68
69 __raw_writel(mfpen, REG_MFSEL);
70
wanzongshunf346bec2009-08-14 15:37:42 +010071 mutex_unlock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +010072}
73EXPORT_SYMBOL(mfp_set_groupf);
74
75void mfp_set_groupc(struct device *dev)
76{
77 unsigned long mfpen;
78 const char *dev_id;
79
80 BUG_ON(!dev);
81
wanzongshunf346bec2009-08-14 15:37:42 +010082 mutex_lock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +010083
84 dev_id = dev_name(dev);
85
86 mfpen = __raw_readl(REG_MFSEL);
87
wanzongshun35c92212009-08-21 07:07:46 +010088 if (strcmp(dev_id, "nuc900-lcd") == 0)
wanzongshun27eb9752009-06-11 14:30:07 +010089 mfpen |= GPSELC;/*enable lcd*/
wanzongshun35c92212009-08-21 07:07:46 +010090 else if (strcmp(dev_id, "nuc900-kpi") == 0) {
91 mfpen &= (~GPSELC);/*enable kpi*/
92 mfpen |= ENKPI;
93 } else if (strcmp(dev_id, "nuc900-nand") == 0) {
94 mfpen &= (~GPSELC);/*enable nand*/
95 mfpen |= ENNAND;
96 } else
97 mfpen &= (~GPSELC);/*GPIOC[14:0]*/
wanzongshun27eb9752009-06-11 14:30:07 +010098
99 __raw_writel(mfpen, REG_MFSEL);
100
wanzongshunf346bec2009-08-14 15:37:42 +0100101 mutex_unlock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +0100102}
103EXPORT_SYMBOL(mfp_set_groupc);
104
wanzongshun0abe1852009-07-14 15:12:26 +0100105void mfp_set_groupi(struct device *dev)
wanzongshun27eb9752009-06-11 14:30:07 +0100106{
107 unsigned long mfpen;
108 const char *dev_id;
109
110 BUG_ON(!dev);
111
wanzongshunf346bec2009-08-14 15:37:42 +0100112 mutex_lock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +0100113
114 dev_id = dev_name(dev);
115
116 mfpen = __raw_readl(REG_MFSEL);
117
wanzongshun0abe1852009-07-14 15:12:26 +0100118 mfpen &= ~GPSELEI1;/*default gpio16*/
119
wanzongshun35c92212009-08-21 07:07:46 +0100120 if (strcmp(dev_id, "nuc900-wdog") == 0)
wanzongshun27eb9752009-06-11 14:30:07 +0100121 mfpen |= GPSELEI1;/*enable wdog*/
wanzongshun35c92212009-08-21 07:07:46 +0100122 else if (strcmp(dev_id, "nuc900-atapi") == 0)
123 mfpen |= GPSELEI0;/*enable atapi*/
124 else if (strcmp(dev_id, "nuc900-keypad") == 0)
125 mfpen &= ~GPSELEI0;/*enable keypad*/
wanzongshun27eb9752009-06-11 14:30:07 +0100126
127 __raw_writel(mfpen, REG_MFSEL);
128
wanzongshunf346bec2009-08-14 15:37:42 +0100129 mutex_unlock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +0100130}
131EXPORT_SYMBOL(mfp_set_groupi);
132
wanzongshun798681b2011-11-10 07:06:29 +0100133void mfp_set_groupg(struct device *dev, const char *subname)
wanzongshun3f3f1d92009-07-23 08:52:51 +0100134{
135 unsigned long mfpen;
136 const char *dev_id;
137
wanzongshun798681b2011-11-10 07:06:29 +0100138 BUG_ON((!dev) && (!subname));
wanzongshun3f3f1d92009-07-23 08:52:51 +0100139
wanzongshunf346bec2009-08-14 15:37:42 +0100140 mutex_lock(&mfp_mutex);
wanzongshun3f3f1d92009-07-23 08:52:51 +0100141
wanzongshun798681b2011-11-10 07:06:29 +0100142 if (subname != NULL)
143 dev_id = subname;
144 else
145 dev_id = dev_name(dev);
wanzongshun3f3f1d92009-07-23 08:52:51 +0100146
147 mfpen = __raw_readl(REG_MFSEL);
148
wanzongshun35c92212009-08-21 07:07:46 +0100149 if (strcmp(dev_id, "nuc900-spi") == 0) {
wanzongshun3f3f1d92009-07-23 08:52:51 +0100150 mfpen &= ~(GPIOG0TO1 | GPIOG2TO3);
151 mfpen |= ENSPI;/*enable spi*/
wanzongshun35c92212009-08-21 07:07:46 +0100152 } else if (strcmp(dev_id, "nuc900-i2c0") == 0) {
wanzongshun3f3f1d92009-07-23 08:52:51 +0100153 mfpen &= ~(GPIOG0TO1);
154 mfpen |= ENI2C0;/*enable i2c0*/
wanzongshun35c92212009-08-21 07:07:46 +0100155 } else if (strcmp(dev_id, "nuc900-i2c1") == 0) {
wanzongshun3f3f1d92009-07-23 08:52:51 +0100156 mfpen &= ~(GPIOG2TO3);
157 mfpen |= ENI2C1;/*enable i2c1*/
Axel Line37051d2012-01-09 10:54:59 +0100158 } else if (strcmp(dev_id, "nuc900-ac97") == 0) {
wanzongshun3d34a0d2010-05-22 15:23:23 +0100159 mfpen &= ~(GPIOG22TO23);
160 mfpen |= ENAC97;/*enable AC97*/
wanzongshun798681b2011-11-10 07:06:29 +0100161 } else if (strcmp(dev_id, "nuc900-mmc-port1") == 0) {
162 mfpen &= ~(GPIOG18TO20);
163 mfpen |= (ENSD1 | 0x01);/*enable sd1*/
wanzongshun3f3f1d92009-07-23 08:52:51 +0100164 } else {
165 mfpen &= ~(GPIOG0TO1 | GPIOG2TO3);/*GPIOG[3:0]*/
166 }
167
168 __raw_writel(mfpen, REG_MFSEL);
169
wanzongshunf346bec2009-08-14 15:37:42 +0100170 mutex_unlock(&mfp_mutex);
wanzongshun3f3f1d92009-07-23 08:52:51 +0100171}
172EXPORT_SYMBOL(mfp_set_groupg);
173
wanzongshun798681b2011-11-10 07:06:29 +0100174void mfp_set_groupd(struct device *dev, const char *subname)
175{
176 unsigned long mfpen;
177 const char *dev_id;
178
179 BUG_ON((!dev) && (!subname));
180
181 mutex_lock(&mfp_mutex);
182
183 if (subname != NULL)
184 dev_id = subname;
185 else
186 dev_id = dev_name(dev);
187
188 mfpen = __raw_readl(REG_MFSEL);
189
190 if (strcmp(dev_id, "nuc900-mmc-port0") == 0) {
191 mfpen &= ~GPSELD;/*enable sd0*/
192 mfpen |= ENSD0;
193 } else
194 mfpen &= (~GPSELD);
195
196 __raw_writel(mfpen, REG_MFSEL);
197
198 mutex_unlock(&mfp_mutex);
199}
200EXPORT_SYMBOL(mfp_set_groupd);