blob: a47dc9a708ee0a29aaa4c62009f0344c07c9e93b [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)
39#define ENSPI (0x0a << 14)
40#define ENI2C0 (0x01 << 14)
41#define ENI2C1 (0x01 << 16)
42
wanzongshunf346bec2009-08-14 15:37:42 +010043static DEFINE_MUTEX(mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +010044
45void mfp_set_groupf(struct device *dev)
46{
47 unsigned long mfpen;
48 const char *dev_id;
49
50 BUG_ON(!dev);
51
wanzongshunf346bec2009-08-14 15:37:42 +010052 mutex_lock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +010053
54 dev_id = dev_name(dev);
55
56 mfpen = __raw_readl(REG_MFSEL);
57
wanzongshun35c92212009-08-21 07:07:46 +010058 if (strcmp(dev_id, "nuc900-emc") == 0)
wanzongshun27eb9752009-06-11 14:30:07 +010059 mfpen |= GPSELF;/*enable mac*/
60 else
61 mfpen &= ~GPSELF;/*GPIOF[9:0]*/
62
63 __raw_writel(mfpen, REG_MFSEL);
64
wanzongshunf346bec2009-08-14 15:37:42 +010065 mutex_unlock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +010066}
67EXPORT_SYMBOL(mfp_set_groupf);
68
69void mfp_set_groupc(struct device *dev)
70{
71 unsigned long mfpen;
72 const char *dev_id;
73
74 BUG_ON(!dev);
75
wanzongshunf346bec2009-08-14 15:37:42 +010076 mutex_lock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +010077
78 dev_id = dev_name(dev);
79
80 mfpen = __raw_readl(REG_MFSEL);
81
wanzongshun35c92212009-08-21 07:07:46 +010082 if (strcmp(dev_id, "nuc900-lcd") == 0)
wanzongshun27eb9752009-06-11 14:30:07 +010083 mfpen |= GPSELC;/*enable lcd*/
wanzongshun35c92212009-08-21 07:07:46 +010084 else if (strcmp(dev_id, "nuc900-kpi") == 0) {
85 mfpen &= (~GPSELC);/*enable kpi*/
86 mfpen |= ENKPI;
87 } else if (strcmp(dev_id, "nuc900-nand") == 0) {
88 mfpen &= (~GPSELC);/*enable nand*/
89 mfpen |= ENNAND;
90 } else
91 mfpen &= (~GPSELC);/*GPIOC[14:0]*/
wanzongshun27eb9752009-06-11 14:30:07 +010092
93 __raw_writel(mfpen, REG_MFSEL);
94
wanzongshunf346bec2009-08-14 15:37:42 +010095 mutex_unlock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +010096}
97EXPORT_SYMBOL(mfp_set_groupc);
98
wanzongshun0abe1852009-07-14 15:12:26 +010099void mfp_set_groupi(struct device *dev)
wanzongshun27eb9752009-06-11 14:30:07 +0100100{
101 unsigned long mfpen;
102 const char *dev_id;
103
104 BUG_ON(!dev);
105
wanzongshunf346bec2009-08-14 15:37:42 +0100106 mutex_lock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +0100107
108 dev_id = dev_name(dev);
109
110 mfpen = __raw_readl(REG_MFSEL);
111
wanzongshun0abe1852009-07-14 15:12:26 +0100112 mfpen &= ~GPSELEI1;/*default gpio16*/
113
wanzongshun35c92212009-08-21 07:07:46 +0100114 if (strcmp(dev_id, "nuc900-wdog") == 0)
wanzongshun27eb9752009-06-11 14:30:07 +0100115 mfpen |= GPSELEI1;/*enable wdog*/
wanzongshun35c92212009-08-21 07:07:46 +0100116 else if (strcmp(dev_id, "nuc900-atapi") == 0)
117 mfpen |= GPSELEI0;/*enable atapi*/
118 else if (strcmp(dev_id, "nuc900-keypad") == 0)
119 mfpen &= ~GPSELEI0;/*enable keypad*/
wanzongshun27eb9752009-06-11 14:30:07 +0100120
121 __raw_writel(mfpen, REG_MFSEL);
122
wanzongshunf346bec2009-08-14 15:37:42 +0100123 mutex_unlock(&mfp_mutex);
wanzongshun27eb9752009-06-11 14:30:07 +0100124}
125EXPORT_SYMBOL(mfp_set_groupi);
126
wanzongshun3f3f1d92009-07-23 08:52:51 +0100127void mfp_set_groupg(struct device *dev)
128{
129 unsigned long mfpen;
130 const char *dev_id;
131
132 BUG_ON(!dev);
133
wanzongshunf346bec2009-08-14 15:37:42 +0100134 mutex_lock(&mfp_mutex);
wanzongshun3f3f1d92009-07-23 08:52:51 +0100135
136 dev_id = dev_name(dev);
137
138 mfpen = __raw_readl(REG_MFSEL);
139
wanzongshun35c92212009-08-21 07:07:46 +0100140 if (strcmp(dev_id, "nuc900-spi") == 0) {
wanzongshun3f3f1d92009-07-23 08:52:51 +0100141 mfpen &= ~(GPIOG0TO1 | GPIOG2TO3);
142 mfpen |= ENSPI;/*enable spi*/
wanzongshun35c92212009-08-21 07:07:46 +0100143 } else if (strcmp(dev_id, "nuc900-i2c0") == 0) {
wanzongshun3f3f1d92009-07-23 08:52:51 +0100144 mfpen &= ~(GPIOG0TO1);
145 mfpen |= ENI2C0;/*enable i2c0*/
wanzongshun35c92212009-08-21 07:07:46 +0100146 } else if (strcmp(dev_id, "nuc900-i2c1") == 0) {
wanzongshun3f3f1d92009-07-23 08:52:51 +0100147 mfpen &= ~(GPIOG2TO3);
148 mfpen |= ENI2C1;/*enable i2c1*/
149 } else {
150 mfpen &= ~(GPIOG0TO1 | GPIOG2TO3);/*GPIOG[3:0]*/
151 }
152
153 __raw_writel(mfpen, REG_MFSEL);
154
wanzongshunf346bec2009-08-14 15:37:42 +0100155 mutex_unlock(&mfp_mutex);
wanzongshun3f3f1d92009-07-23 08:52:51 +0100156}
157EXPORT_SYMBOL(mfp_set_groupg);
158