board-trout-mmc.c 4.6 KB

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