Daniel Walker | 42a2c21 | 2010-03-30 16:11:57 -0700 | [diff] [blame^] | 1 | /* linux/arch/arm/mach-msm/board-trout-mmc.c |
| 2 | ** Author: Brian Swetland <swetland@google.com> |
| 3 | */ |
| 4 | |
| 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> |
| 13 | |
| 14 | #include <asm/gpio.h> |
| 15 | #include <asm/io.h> |
| 16 | |
| 17 | #include <mach/vreg.h> |
| 18 | |
| 19 | #include <mach/mmc.h> |
| 20 | |
| 21 | #include "devices.h" |
| 22 | |
| 23 | #include "board-trout.h" |
| 24 | |
| 25 | #include "proc_comm.h" |
| 26 | |
| 27 | #define DEBUG_SDSLOT_VDD 1 |
| 28 | |
| 29 | extern int msm_add_sdcc(unsigned int controller, struct mmc_platform_data *plat, |
| 30 | unsigned int stat_irq, unsigned long stat_irq_flags); |
| 31 | |
| 32 | /* ---- COMMON ---- */ |
| 33 | static void config_gpio_table(uint32_t *table, int len) |
| 34 | { |
| 35 | int n; |
| 36 | unsigned id; |
| 37 | for(n = 0; n < len; n++) { |
| 38 | id = table[n]; |
| 39 | msm_proc_comm(PCOM_RPC_GPIO_TLMM_CONFIG_EX, &id, 0); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /* ---- SDCARD ---- */ |
| 44 | |
| 45 | static uint32_t sdcard_on_gpio_table[] = { |
| 46 | PCOM_GPIO_CFG(62, 2, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_8MA), /* CLK */ |
| 47 | PCOM_GPIO_CFG(63, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_8MA), /* CMD */ |
| 48 | PCOM_GPIO_CFG(64, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_8MA), /* DAT3 */ |
| 49 | PCOM_GPIO_CFG(65, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_8MA), /* DAT2 */ |
| 50 | PCOM_GPIO_CFG(66, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_4MA), /* DAT1 */ |
| 51 | PCOM_GPIO_CFG(67, 2, GPIO_OUTPUT, GPIO_PULL_UP, GPIO_4MA), /* DAT0 */ |
| 52 | }; |
| 53 | |
| 54 | static uint32_t sdcard_off_gpio_table[] = { |
| 55 | PCOM_GPIO_CFG(62, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* CLK */ |
| 56 | PCOM_GPIO_CFG(63, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* CMD */ |
| 57 | PCOM_GPIO_CFG(64, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT3 */ |
| 58 | PCOM_GPIO_CFG(65, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT2 */ |
| 59 | PCOM_GPIO_CFG(66, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT1 */ |
| 60 | PCOM_GPIO_CFG(67, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_4MA), /* DAT0 */ |
| 61 | }; |
| 62 | |
| 63 | static uint opt_disable_sdcard; |
| 64 | |
| 65 | static int __init trout_disablesdcard_setup(char *str) |
| 66 | { |
| 67 | int cal = simple_strtol(str, NULL, 0); |
| 68 | |
| 69 | opt_disable_sdcard = cal; |
| 70 | return 1; |
| 71 | } |
| 72 | |
| 73 | __setup("board_trout.disable_sdcard=", trout_disablesdcard_setup); |
| 74 | |
| 75 | static struct vreg *vreg_sdslot; /* SD slot power */ |
| 76 | |
| 77 | struct mmc_vdd_xlat { |
| 78 | int mask; |
| 79 | int level; |
| 80 | }; |
| 81 | |
| 82 | static struct mmc_vdd_xlat mmc_vdd_table[] = { |
| 83 | { MMC_VDD_165_195, 1800 }, |
| 84 | { MMC_VDD_20_21, 2050 }, |
| 85 | { MMC_VDD_21_22, 2150 }, |
| 86 | { MMC_VDD_22_23, 2250 }, |
| 87 | { MMC_VDD_23_24, 2350 }, |
| 88 | { MMC_VDD_24_25, 2450 }, |
| 89 | { MMC_VDD_25_26, 2550 }, |
| 90 | { MMC_VDD_26_27, 2650 }, |
| 91 | { MMC_VDD_27_28, 2750 }, |
| 92 | { MMC_VDD_28_29, 2850 }, |
| 93 | { MMC_VDD_29_30, 2950 }, |
| 94 | }; |
| 95 | |
| 96 | static unsigned int sdslot_vdd = 0xffffffff; |
| 97 | static unsigned int sdslot_vreg_enabled; |
| 98 | |
| 99 | static uint32_t trout_sdslot_switchvdd(struct device *dev, unsigned int vdd) |
| 100 | { |
| 101 | int i, rc; |
| 102 | |
| 103 | BUG_ON(!vreg_sdslot); |
| 104 | |
| 105 | if (vdd == sdslot_vdd) |
| 106 | return 0; |
| 107 | |
| 108 | sdslot_vdd = vdd; |
| 109 | |
| 110 | if (vdd == 0) { |
| 111 | #if DEBUG_SDSLOT_VDD |
| 112 | printk("%s: Disabling SD slot power\n", __func__); |
| 113 | #endif |
| 114 | config_gpio_table(sdcard_off_gpio_table, |
| 115 | ARRAY_SIZE(sdcard_off_gpio_table)); |
| 116 | vreg_disable(vreg_sdslot); |
| 117 | sdslot_vreg_enabled = 0; |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | if (!sdslot_vreg_enabled) { |
| 122 | rc = vreg_enable(vreg_sdslot); |
| 123 | if (rc) { |
| 124 | printk(KERN_ERR "%s: Error enabling vreg (%d)\n", |
| 125 | __func__, rc); |
| 126 | } |
| 127 | config_gpio_table(sdcard_on_gpio_table, |
| 128 | ARRAY_SIZE(sdcard_on_gpio_table)); |
| 129 | sdslot_vreg_enabled = 1; |
| 130 | } |
| 131 | |
| 132 | for (i = 0; i < ARRAY_SIZE(mmc_vdd_table); i++) { |
| 133 | if (mmc_vdd_table[i].mask == (1 << vdd)) { |
| 134 | #if DEBUG_SDSLOT_VDD |
| 135 | printk("%s: Setting level to %u\n", |
| 136 | __func__, mmc_vdd_table[i].level); |
| 137 | #endif |
| 138 | rc = vreg_set_level(vreg_sdslot, |
| 139 | mmc_vdd_table[i].level); |
| 140 | if (rc) { |
| 141 | printk(KERN_ERR |
| 142 | "%s: Error setting vreg level (%d)\n", |
| 143 | __func__, rc); |
| 144 | } |
| 145 | return 0; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | printk(KERN_ERR "%s: Invalid VDD %d specified\n", __func__, vdd); |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | static unsigned int trout_sdslot_status(struct device *dev) |
| 154 | { |
| 155 | unsigned int status; |
| 156 | |
| 157 | status = (unsigned int) gpio_get_value(TROUT_GPIO_SDMC_CD_N); |
| 158 | return (!status); |
| 159 | } |
| 160 | |
| 161 | #define TROUT_MMC_VDD MMC_VDD_165_195 | MMC_VDD_20_21 | MMC_VDD_21_22 \ |
| 162 | | MMC_VDD_22_23 | MMC_VDD_23_24 | MMC_VDD_24_25 \ |
| 163 | | MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 \ |
| 164 | | MMC_VDD_28_29 | MMC_VDD_29_30 |
| 165 | |
| 166 | static struct mmc_platform_data trout_sdslot_data = { |
| 167 | .ocr_mask = TROUT_MMC_VDD, |
| 168 | .status = trout_sdslot_status, |
| 169 | .translate_vdd = trout_sdslot_switchvdd, |
| 170 | }; |
| 171 | |
| 172 | int __init trout_init_mmc(unsigned int sys_rev) |
| 173 | { |
| 174 | sdslot_vreg_enabled = 0; |
| 175 | |
| 176 | vreg_sdslot = vreg_get(0, "gp6"); |
| 177 | if (IS_ERR(vreg_sdslot)) |
| 178 | return PTR_ERR(vreg_sdslot); |
| 179 | |
| 180 | set_irq_wake(TROUT_GPIO_TO_INT(TROUT_GPIO_SDMC_CD_N), 1); |
| 181 | |
| 182 | if (!opt_disable_sdcard) |
| 183 | msm_add_sdcc(2, &trout_sdslot_data, |
| 184 | TROUT_GPIO_TO_INT(TROUT_GPIO_SDMC_CD_N), 0); |
| 185 | else |
| 186 | printk(KERN_INFO "trout: SD-Card interface disabled\n"); |
| 187 | return 0; |
| 188 | } |
| 189 | |