wanzongshun | 27eb975 | 2009-06-11 14:30:07 +0100 | [diff] [blame] | 1 | /* |
wanzongshun | 35c9221 | 2009-08-21 07:07:46 +0100 | [diff] [blame] | 2 | * linux/arch/arm/mach-w90x900/mfp.c |
wanzongshun | 27eb975 | 2009-06-11 14:30:07 +0100 | [diff] [blame] | 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 | |
wanzongshun | 3f3f1d9 | 2009-07-23 08:52:51 +0100 | [diff] [blame] | 37 | #define GPIOG0TO1 (0x03 << 14) |
| 38 | #define GPIOG2TO3 (0x03 << 16) |
wanzongshun | 3d34a0d | 2010-05-22 15:23:23 +0100 | [diff] [blame] | 39 | #define GPIOG22TO23 (0x03 << 22) |
| 40 | |
wanzongshun | 3f3f1d9 | 2009-07-23 08:52:51 +0100 | [diff] [blame] | 41 | #define ENSPI (0x0a << 14) |
| 42 | #define ENI2C0 (0x01 << 14) |
| 43 | #define ENI2C1 (0x01 << 16) |
wanzongshun | 3d34a0d | 2010-05-22 15:23:23 +0100 | [diff] [blame] | 44 | #define ENAC97 (0x02 << 22) |
wanzongshun | 3f3f1d9 | 2009-07-23 08:52:51 +0100 | [diff] [blame] | 45 | |
wanzongshun | f346bec | 2009-08-14 15:37:42 +0100 | [diff] [blame] | 46 | static DEFINE_MUTEX(mfp_mutex); |
wanzongshun | 27eb975 | 2009-06-11 14:30:07 +0100 | [diff] [blame] | 47 | |
| 48 | void mfp_set_groupf(struct device *dev) |
| 49 | { |
| 50 | unsigned long mfpen; |
| 51 | const char *dev_id; |
| 52 | |
| 53 | BUG_ON(!dev); |
| 54 | |
wanzongshun | f346bec | 2009-08-14 15:37:42 +0100 | [diff] [blame] | 55 | mutex_lock(&mfp_mutex); |
wanzongshun | 27eb975 | 2009-06-11 14:30:07 +0100 | [diff] [blame] | 56 | |
| 57 | dev_id = dev_name(dev); |
| 58 | |
| 59 | mfpen = __raw_readl(REG_MFSEL); |
| 60 | |
wanzongshun | 35c9221 | 2009-08-21 07:07:46 +0100 | [diff] [blame] | 61 | if (strcmp(dev_id, "nuc900-emc") == 0) |
wanzongshun | 27eb975 | 2009-06-11 14:30:07 +0100 | [diff] [blame] | 62 | mfpen |= GPSELF;/*enable mac*/ |
| 63 | else |
| 64 | mfpen &= ~GPSELF;/*GPIOF[9:0]*/ |
| 65 | |
| 66 | __raw_writel(mfpen, REG_MFSEL); |
| 67 | |
wanzongshun | f346bec | 2009-08-14 15:37:42 +0100 | [diff] [blame] | 68 | mutex_unlock(&mfp_mutex); |
wanzongshun | 27eb975 | 2009-06-11 14:30:07 +0100 | [diff] [blame] | 69 | } |
| 70 | EXPORT_SYMBOL(mfp_set_groupf); |
| 71 | |
| 72 | void mfp_set_groupc(struct device *dev) |
| 73 | { |
| 74 | unsigned long mfpen; |
| 75 | const char *dev_id; |
| 76 | |
| 77 | BUG_ON(!dev); |
| 78 | |
wanzongshun | f346bec | 2009-08-14 15:37:42 +0100 | [diff] [blame] | 79 | mutex_lock(&mfp_mutex); |
wanzongshun | 27eb975 | 2009-06-11 14:30:07 +0100 | [diff] [blame] | 80 | |
| 81 | dev_id = dev_name(dev); |
| 82 | |
| 83 | mfpen = __raw_readl(REG_MFSEL); |
| 84 | |
wanzongshun | 35c9221 | 2009-08-21 07:07:46 +0100 | [diff] [blame] | 85 | if (strcmp(dev_id, "nuc900-lcd") == 0) |
wanzongshun | 27eb975 | 2009-06-11 14:30:07 +0100 | [diff] [blame] | 86 | mfpen |= GPSELC;/*enable lcd*/ |
wanzongshun | 35c9221 | 2009-08-21 07:07:46 +0100 | [diff] [blame] | 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]*/ |
wanzongshun | 27eb975 | 2009-06-11 14:30:07 +0100 | [diff] [blame] | 95 | |
| 96 | __raw_writel(mfpen, REG_MFSEL); |
| 97 | |
wanzongshun | f346bec | 2009-08-14 15:37:42 +0100 | [diff] [blame] | 98 | mutex_unlock(&mfp_mutex); |
wanzongshun | 27eb975 | 2009-06-11 14:30:07 +0100 | [diff] [blame] | 99 | } |
| 100 | EXPORT_SYMBOL(mfp_set_groupc); |
| 101 | |
wanzongshun | 0abe185 | 2009-07-14 15:12:26 +0100 | [diff] [blame] | 102 | void mfp_set_groupi(struct device *dev) |
wanzongshun | 27eb975 | 2009-06-11 14:30:07 +0100 | [diff] [blame] | 103 | { |
| 104 | unsigned long mfpen; |
| 105 | const char *dev_id; |
| 106 | |
| 107 | BUG_ON(!dev); |
| 108 | |
wanzongshun | f346bec | 2009-08-14 15:37:42 +0100 | [diff] [blame] | 109 | mutex_lock(&mfp_mutex); |
wanzongshun | 27eb975 | 2009-06-11 14:30:07 +0100 | [diff] [blame] | 110 | |
| 111 | dev_id = dev_name(dev); |
| 112 | |
| 113 | mfpen = __raw_readl(REG_MFSEL); |
| 114 | |
wanzongshun | 0abe185 | 2009-07-14 15:12:26 +0100 | [diff] [blame] | 115 | mfpen &= ~GPSELEI1;/*default gpio16*/ |
| 116 | |
wanzongshun | 35c9221 | 2009-08-21 07:07:46 +0100 | [diff] [blame] | 117 | if (strcmp(dev_id, "nuc900-wdog") == 0) |
wanzongshun | 27eb975 | 2009-06-11 14:30:07 +0100 | [diff] [blame] | 118 | mfpen |= GPSELEI1;/*enable wdog*/ |
wanzongshun | 35c9221 | 2009-08-21 07:07:46 +0100 | [diff] [blame] | 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*/ |
wanzongshun | 27eb975 | 2009-06-11 14:30:07 +0100 | [diff] [blame] | 123 | |
| 124 | __raw_writel(mfpen, REG_MFSEL); |
| 125 | |
wanzongshun | f346bec | 2009-08-14 15:37:42 +0100 | [diff] [blame] | 126 | mutex_unlock(&mfp_mutex); |
wanzongshun | 27eb975 | 2009-06-11 14:30:07 +0100 | [diff] [blame] | 127 | } |
| 128 | EXPORT_SYMBOL(mfp_set_groupi); |
| 129 | |
wanzongshun | 3f3f1d9 | 2009-07-23 08:52:51 +0100 | [diff] [blame] | 130 | void mfp_set_groupg(struct device *dev) |
| 131 | { |
| 132 | unsigned long mfpen; |
| 133 | const char *dev_id; |
| 134 | |
| 135 | BUG_ON(!dev); |
| 136 | |
wanzongshun | f346bec | 2009-08-14 15:37:42 +0100 | [diff] [blame] | 137 | mutex_lock(&mfp_mutex); |
wanzongshun | 3f3f1d9 | 2009-07-23 08:52:51 +0100 | [diff] [blame] | 138 | |
| 139 | dev_id = dev_name(dev); |
| 140 | |
| 141 | mfpen = __raw_readl(REG_MFSEL); |
| 142 | |
wanzongshun | 35c9221 | 2009-08-21 07:07:46 +0100 | [diff] [blame] | 143 | if (strcmp(dev_id, "nuc900-spi") == 0) { |
wanzongshun | 3f3f1d9 | 2009-07-23 08:52:51 +0100 | [diff] [blame] | 144 | mfpen &= ~(GPIOG0TO1 | GPIOG2TO3); |
| 145 | mfpen |= ENSPI;/*enable spi*/ |
wanzongshun | 35c9221 | 2009-08-21 07:07:46 +0100 | [diff] [blame] | 146 | } else if (strcmp(dev_id, "nuc900-i2c0") == 0) { |
wanzongshun | 3f3f1d9 | 2009-07-23 08:52:51 +0100 | [diff] [blame] | 147 | mfpen &= ~(GPIOG0TO1); |
| 148 | mfpen |= ENI2C0;/*enable i2c0*/ |
wanzongshun | 35c9221 | 2009-08-21 07:07:46 +0100 | [diff] [blame] | 149 | } else if (strcmp(dev_id, "nuc900-i2c1") == 0) { |
wanzongshun | 3f3f1d9 | 2009-07-23 08:52:51 +0100 | [diff] [blame] | 150 | mfpen &= ~(GPIOG2TO3); |
| 151 | mfpen |= ENI2C1;/*enable i2c1*/ |
wanzongshun | 3d34a0d | 2010-05-22 15:23:23 +0100 | [diff] [blame] | 152 | } else if (strcmp(dev_id, "nuc900-audio") == 0) { |
| 153 | mfpen &= ~(GPIOG22TO23); |
| 154 | mfpen |= ENAC97;/*enable AC97*/ |
wanzongshun | 3f3f1d9 | 2009-07-23 08:52:51 +0100 | [diff] [blame] | 155 | } else { |
| 156 | mfpen &= ~(GPIOG0TO1 | GPIOG2TO3);/*GPIOG[3:0]*/ |
| 157 | } |
| 158 | |
| 159 | __raw_writel(mfpen, REG_MFSEL); |
| 160 | |
wanzongshun | f346bec | 2009-08-14 15:37:42 +0100 | [diff] [blame] | 161 | mutex_unlock(&mfp_mutex); |
wanzongshun | 3f3f1d9 | 2009-07-23 08:52:51 +0100 | [diff] [blame] | 162 | } |
| 163 | EXPORT_SYMBOL(mfp_set_groupg); |
| 164 | |