blob: fb7fb627b1a564ca920fdb747080988f3fb75551 [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)
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
wanzongshun3f3f1d92009-07-23 08:52:51 +010037#define GPIOG0TO1 (0x03 << 14)
38#define GPIOG2TO3 (0x03 << 16)
wanzongshun3d34a0d2010-05-22 15:23:23 +010039#define GPIOG22TO23 (0x03 << 22)
40
wanzongshun3f3f1d92009-07-23 08:52:51 +010041#define ENSPI (0x0a << 14)
42#define ENI2C0 (0x01 << 14)
43#define ENI2C1 (0x01 << 16)
wanzongshun3d34a0d2010-05-22 15:23:23 +010044#define ENAC97 (0x02 << 22)
wanzongshun3f3f1d92009-07-23 08:52:51 +010045
wanzongshunf346bec2009-08-14 15:37:42 +010046static DEFINE_MUTEX(mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +010047
48void mfp_set_groupf(struct device *dev)
49{
50 unsigned long mfpen;
51 const char *dev_id;
52
53 BUG_ON(!dev);
54
wanzongshunf346bec2009-08-14 15:37:42 +010055 mutex_lock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +010056
57 dev_id = dev_name(dev);
58
59 mfpen = __raw_readl(REG_MFSEL);
60
wanzongshun35c92212009-08-21 07:07:46 +010061 if (strcmp(dev_id, "nuc900-emc") == 0)
wanzongshun27eb9752009-06-11 14:30:07 +010062 mfpen |= GPSELF;/*enable mac*/
63 else
64 mfpen &= ~GPSELF;/*GPIOF[9:0]*/
65
66 __raw_writel(mfpen, REG_MFSEL);
67
wanzongshunf346bec2009-08-14 15:37:42 +010068 mutex_unlock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +010069}
70EXPORT_SYMBOL(mfp_set_groupf);
71
72void mfp_set_groupc(struct device *dev)
73{
74 unsigned long mfpen;
75 const char *dev_id;
76
77 BUG_ON(!dev);
78
wanzongshunf346bec2009-08-14 15:37:42 +010079 mutex_lock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +010080
81 dev_id = dev_name(dev);
82
83 mfpen = __raw_readl(REG_MFSEL);
84
wanzongshun35c92212009-08-21 07:07:46 +010085 if (strcmp(dev_id, "nuc900-lcd") == 0)
wanzongshun27eb9752009-06-11 14:30:07 +010086 mfpen |= GPSELC;/*enable lcd*/
wanzongshun35c92212009-08-21 07:07:46 +010087 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]*/
wanzongshun27eb9752009-06-11 14:30:07 +010095
96 __raw_writel(mfpen, REG_MFSEL);
97
wanzongshunf346bec2009-08-14 15:37:42 +010098 mutex_unlock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +010099}
100EXPORT_SYMBOL(mfp_set_groupc);
101
wanzongshun0abe1852009-07-14 15:12:26 +0100102void mfp_set_groupi(struct device *dev)
wanzongshun27eb9752009-06-11 14:30:07 +0100103{
104 unsigned long mfpen;
105 const char *dev_id;
106
107 BUG_ON(!dev);
108
wanzongshunf346bec2009-08-14 15:37:42 +0100109 mutex_lock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +0100110
111 dev_id = dev_name(dev);
112
113 mfpen = __raw_readl(REG_MFSEL);
114
wanzongshun0abe1852009-07-14 15:12:26 +0100115 mfpen &= ~GPSELEI1;/*default gpio16*/
116
wanzongshun35c92212009-08-21 07:07:46 +0100117 if (strcmp(dev_id, "nuc900-wdog") == 0)
wanzongshun27eb9752009-06-11 14:30:07 +0100118 mfpen |= GPSELEI1;/*enable wdog*/
wanzongshun35c92212009-08-21 07:07:46 +0100119 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*/
wanzongshun27eb9752009-06-11 14:30:07 +0100123
124 __raw_writel(mfpen, REG_MFSEL);
125
wanzongshunf346bec2009-08-14 15:37:42 +0100126 mutex_unlock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +0100127}
128EXPORT_SYMBOL(mfp_set_groupi);
129
wanzongshun3f3f1d92009-07-23 08:52:51 +0100130void mfp_set_groupg(struct device *dev)
131{
132 unsigned long mfpen;
133 const char *dev_id;
134
135 BUG_ON(!dev);
136
wanzongshunf346bec2009-08-14 15:37:42 +0100137 mutex_lock(&mfp_mutex);
wanzongshun3f3f1d92009-07-23 08:52:51 +0100138
139 dev_id = dev_name(dev);
140
141 mfpen = __raw_readl(REG_MFSEL);
142
wanzongshun35c92212009-08-21 07:07:46 +0100143 if (strcmp(dev_id, "nuc900-spi") == 0) {
wanzongshun3f3f1d92009-07-23 08:52:51 +0100144 mfpen &= ~(GPIOG0TO1 | GPIOG2TO3);
145 mfpen |= ENSPI;/*enable spi*/
wanzongshun35c92212009-08-21 07:07:46 +0100146 } else if (strcmp(dev_id, "nuc900-i2c0") == 0) {
wanzongshun3f3f1d92009-07-23 08:52:51 +0100147 mfpen &= ~(GPIOG0TO1);
148 mfpen |= ENI2C0;/*enable i2c0*/
wanzongshun35c92212009-08-21 07:07:46 +0100149 } else if (strcmp(dev_id, "nuc900-i2c1") == 0) {
wanzongshun3f3f1d92009-07-23 08:52:51 +0100150 mfpen &= ~(GPIOG2TO3);
151 mfpen |= ENI2C1;/*enable i2c1*/
wanzongshun3d34a0d2010-05-22 15:23:23 +0100152 } else if (strcmp(dev_id, "nuc900-audio") == 0) {
153 mfpen &= ~(GPIOG22TO23);
154 mfpen |= ENAC97;/*enable AC97*/
wanzongshun3f3f1d92009-07-23 08:52:51 +0100155 } else {
156 mfpen &= ~(GPIOG0TO1 | GPIOG2TO3);/*GPIOG[3:0]*/
157 }
158
159 __raw_writel(mfpen, REG_MFSEL);
160
wanzongshunf346bec2009-08-14 15:37:42 +0100161 mutex_unlock(&mfp_mutex);
wanzongshun3f3f1d92009-07-23 08:52:51 +0100162}
163EXPORT_SYMBOL(mfp_set_groupg);
164