Merge tag 'locks-v3.16-2' of git://git.samba.org/jlayton/linux
[linux/fpc-iii.git] / arch / arm / mach-msm / board-trout-mmc.c
blob3723e55819d603a3279791fbc6200ba617a13d1a
1 /* linux/arch/arm/mach-msm/board-trout-mmc.c
2 ** Author: Brian Swetland <swetland@google.com>
3 */
4 #include <linux/gpio.h>
5 #include <linux/kernel.h>
6 #include <linux/init.h>
7 #include <linux/platform_device.h>
8 #include <linux/delay.h>
9 #include <linux/mmc/host.h>
10 #include <linux/mmc/sdio_ids.h>
11 #include <linux/err.h>
12 #include <linux/debugfs.h>
14 #include <asm/io.h>
16 #include <mach/vreg.h>
18 #include <linux/platform_data/mmc-msm_sdcc.h>
20 #include "devices.h"
22 #include "board-trout.h"
24 #include "proc_comm.h"
26 #define DEBUG_SDSLOT_VDD 1
28 /* ---- COMMON ---- */
29 static void config_gpio_table(uint32_t *table, int len)
31 int n;
32 unsigned id;
33 for(n = 0; n < len; n++) {
34 id = table[n];
35 msm_proc_comm(PCOM_RPC_GPIO_TLMM_CONFIG_EX, &id, 0);
39 /* ---- SDCARD ---- */
41 static uint32_t sdcard_on_gpio_table[] = {
42 PCOM_GPIO_CFG(62, 2, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_8MA), /* CLK */
43 PCOM_GPIO_CFG(63, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_8MA), /* CMD */
44 PCOM_GPIO_CFG(64, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_8MA), /* DAT3 */
45 PCOM_GPIO_CFG(65, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_8MA), /* DAT2 */
46 PCOM_GPIO_CFG(66, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_4MA), /* DAT1 */
47 PCOM_GPIO_CFG(67, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_4MA), /* DAT0 */
50 static uint32_t sdcard_off_gpio_table[] = {
51 PCOM_GPIO_CFG(62, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* CLK */
52 PCOM_GPIO_CFG(63, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* CMD */
53 PCOM_GPIO_CFG(64, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT3 */
54 PCOM_GPIO_CFG(65, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT2 */
55 PCOM_GPIO_CFG(66, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT1 */
56 PCOM_GPIO_CFG(67, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT0 */
59 static uint opt_disable_sdcard;
61 static int __init trout_disablesdcard_setup(char *str)
63 int cal = simple_strtol(str, NULL, 0);
65 opt_disable_sdcard = cal;
66 return 1;
69 __setup("board_trout.disable_sdcard=", trout_disablesdcard_setup);
71 static struct vreg *vreg_sdslot; /* SD slot power */
73 struct mmc_vdd_xlat {
74 int mask;
75 int level;
78 static struct mmc_vdd_xlat mmc_vdd_table[] = {
79 { MMC_VDD_165_195, 1800 },
80 { MMC_VDD_20_21, 2050 },
81 { MMC_VDD_21_22, 2150 },
82 { MMC_VDD_22_23, 2250 },
83 { MMC_VDD_23_24, 2350 },
84 { MMC_VDD_24_25, 2450 },
85 { MMC_VDD_25_26, 2550 },
86 { MMC_VDD_26_27, 2650 },
87 { MMC_VDD_27_28, 2750 },
88 { MMC_VDD_28_29, 2850 },
89 { MMC_VDD_29_30, 2950 },
92 static unsigned int sdslot_vdd = 0xffffffff;
93 static unsigned int sdslot_vreg_enabled;
95 static uint32_t trout_sdslot_switchvdd(struct device *dev, unsigned int vdd)
97 int i, rc;
99 BUG_ON(!vreg_sdslot);
101 if (vdd == sdslot_vdd)
102 return 0;
104 sdslot_vdd = vdd;
106 if (vdd == 0) {
107 #if DEBUG_SDSLOT_VDD
108 printk("%s: Disabling SD slot power\n", __func__);
109 #endif
110 config_gpio_table(sdcard_off_gpio_table,
111 ARRAY_SIZE(sdcard_off_gpio_table));
112 vreg_disable(vreg_sdslot);
113 sdslot_vreg_enabled = 0;
114 return 0;
117 if (!sdslot_vreg_enabled) {
118 rc = vreg_enable(vreg_sdslot);
119 if (rc) {
120 printk(KERN_ERR "%s: Error enabling vreg (%d)\n",
121 __func__, rc);
123 config_gpio_table(sdcard_on_gpio_table,
124 ARRAY_SIZE(sdcard_on_gpio_table));
125 sdslot_vreg_enabled = 1;
128 for (i = 0; i < ARRAY_SIZE(mmc_vdd_table); i++) {
129 if (mmc_vdd_table[i].mask == (1 << vdd)) {
130 #if DEBUG_SDSLOT_VDD
131 printk("%s: Setting level to %u\n",
132 __func__, mmc_vdd_table[i].level);
133 #endif
134 rc = vreg_set_level(vreg_sdslot,
135 mmc_vdd_table[i].level);
136 if (rc) {
137 printk(KERN_ERR
138 "%s: Error setting vreg level (%d)\n",
139 __func__, rc);
141 return 0;
145 printk(KERN_ERR "%s: Invalid VDD %d specified\n", __func__, vdd);
146 return 0;
149 static unsigned int trout_sdslot_status(struct device *dev)
151 unsigned int status;
153 status = (unsigned int) gpio_get_value(TROUT_GPIO_SDMC_CD_N);
154 return (!status);
157 #define TROUT_MMC_VDD MMC_VDD_165_195 | MMC_VDD_20_21 | MMC_VDD_21_22 \
158 | MMC_VDD_22_23 | MMC_VDD_23_24 | MMC_VDD_24_25 \
159 | MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 \
160 | MMC_VDD_28_29 | MMC_VDD_29_30
162 static struct msm_mmc_platform_data trout_sdslot_data = {
163 .ocr_mask = TROUT_MMC_VDD,
164 .status = trout_sdslot_status,
165 .translate_vdd = trout_sdslot_switchvdd,
168 int __init trout_init_mmc(unsigned int sys_rev)
170 sdslot_vreg_enabled = 0;
172 vreg_sdslot = vreg_get(0, "gp6");
173 if (IS_ERR(vreg_sdslot))
174 return PTR_ERR(vreg_sdslot);
176 irq_set_irq_wake(TROUT_GPIO_TO_INT(TROUT_GPIO_SDMC_CD_N), 1);
178 if (!opt_disable_sdcard)
179 msm_add_sdcc(2, &trout_sdslot_data,
180 TROUT_GPIO_TO_INT(TROUT_GPIO_SDMC_CD_N), 0);
181 else
182 printk(KERN_INFO "trout: SD-Card interface disabled\n");
183 return 0;