hsmmc.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * linux/arch/arm/mach-omap2/hsmmc.c
  3. *
  4. * Copyright (C) 2007-2008 Texas Instruments
  5. * Copyright (C) 2008 Nokia Corporation
  6. * Author: Texas Instruments
  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 version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/slab.h>
  14. #include <linux/string.h>
  15. #include <linux/delay.h>
  16. #include <mach/hardware.h>
  17. #include <plat/control.h>
  18. #include <plat/mmc.h>
  19. #include <plat/omap-pm.h>
  20. #include "hsmmc.h"
  21. #if defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
  22. static u16 control_pbias_offset;
  23. static u16 control_devconf1_offset;
  24. #define HSMMC_NAME_LEN 9
  25. static struct hsmmc_controller {
  26. char name[HSMMC_NAME_LEN + 1];
  27. } hsmmc[OMAP34XX_NR_MMC];
  28. #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
  29. static int hsmmc_get_context_loss(struct device *dev)
  30. {
  31. return omap_pm_get_dev_context_loss_count(dev);
  32. }
  33. #else
  34. #define hsmmc_get_context_loss NULL
  35. #endif
  36. static void hsmmc1_before_set_reg(struct device *dev, int slot,
  37. int power_on, int vdd)
  38. {
  39. u32 reg, prog_io;
  40. struct omap_mmc_platform_data *mmc = dev->platform_data;
  41. if (mmc->slots[0].remux)
  42. mmc->slots[0].remux(dev, slot, power_on);
  43. /*
  44. * Assume we power both OMAP VMMC1 (for CMD, CLK, DAT0..3) and the
  45. * card with Vcc regulator (from twl4030 or whatever). OMAP has both
  46. * 1.8V and 3.0V modes, controlled by the PBIAS register.
  47. *
  48. * In 8-bit modes, OMAP VMMC1A (for DAT4..7) needs a supply, which
  49. * is most naturally TWL VSIM; those pins also use PBIAS.
  50. *
  51. * FIXME handle VMMC1A as needed ...
  52. */
  53. if (power_on) {
  54. if (cpu_is_omap2430()) {
  55. reg = omap_ctrl_readl(OMAP243X_CONTROL_DEVCONF1);
  56. if ((1 << vdd) >= MMC_VDD_30_31)
  57. reg |= OMAP243X_MMC1_ACTIVE_OVERWRITE;
  58. else
  59. reg &= ~OMAP243X_MMC1_ACTIVE_OVERWRITE;
  60. omap_ctrl_writel(reg, OMAP243X_CONTROL_DEVCONF1);
  61. }
  62. if (mmc->slots[0].internal_clock) {
  63. reg = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
  64. reg |= OMAP2_MMCSDIO1ADPCLKISEL;
  65. omap_ctrl_writel(reg, OMAP2_CONTROL_DEVCONF0);
  66. }
  67. reg = omap_ctrl_readl(control_pbias_offset);
  68. if (cpu_is_omap3630()) {
  69. /* Set MMC I/O to 52Mhz */
  70. prog_io = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1);
  71. prog_io |= OMAP3630_PRG_SDMMC1_SPEEDCTRL;
  72. omap_ctrl_writel(prog_io, OMAP343X_CONTROL_PROG_IO1);
  73. } else {
  74. reg |= OMAP2_PBIASSPEEDCTRL0;
  75. }
  76. reg &= ~OMAP2_PBIASLITEPWRDNZ0;
  77. omap_ctrl_writel(reg, control_pbias_offset);
  78. } else {
  79. reg = omap_ctrl_readl(control_pbias_offset);
  80. reg &= ~OMAP2_PBIASLITEPWRDNZ0;
  81. omap_ctrl_writel(reg, control_pbias_offset);
  82. }
  83. }
  84. static void hsmmc1_after_set_reg(struct device *dev, int slot,
  85. int power_on, int vdd)
  86. {
  87. u32 reg;
  88. /* 100ms delay required for PBIAS configuration */
  89. msleep(100);
  90. if (power_on) {
  91. reg = omap_ctrl_readl(control_pbias_offset);
  92. reg |= (OMAP2_PBIASLITEPWRDNZ0 | OMAP2_PBIASSPEEDCTRL0);
  93. if ((1 << vdd) <= MMC_VDD_165_195)
  94. reg &= ~OMAP2_PBIASLITEVMODE0;
  95. else
  96. reg |= OMAP2_PBIASLITEVMODE0;
  97. omap_ctrl_writel(reg, control_pbias_offset);
  98. } else {
  99. reg = omap_ctrl_readl(control_pbias_offset);
  100. reg |= (OMAP2_PBIASSPEEDCTRL0 | OMAP2_PBIASLITEPWRDNZ0 |
  101. OMAP2_PBIASLITEVMODE0);
  102. omap_ctrl_writel(reg, control_pbias_offset);
  103. }
  104. }
  105. static void hsmmc23_before_set_reg(struct device *dev, int slot,
  106. int power_on, int vdd)
  107. {
  108. struct omap_mmc_platform_data *mmc = dev->platform_data;
  109. if (mmc->slots[0].remux)
  110. mmc->slots[0].remux(dev, slot, power_on);
  111. if (power_on) {
  112. /* Only MMC2 supports a CLKIN */
  113. if (mmc->slots[0].internal_clock) {
  114. u32 reg;
  115. reg = omap_ctrl_readl(control_devconf1_offset);
  116. reg |= OMAP2_MMCSDIO2ADPCLKISEL;
  117. omap_ctrl_writel(reg, control_devconf1_offset);
  118. }
  119. }
  120. }
  121. static struct omap_mmc_platform_data *hsmmc_data[OMAP34XX_NR_MMC] __initdata;
  122. void __init omap2_hsmmc_init(struct omap2_hsmmc_info *controllers)
  123. {
  124. struct omap2_hsmmc_info *c;
  125. int nr_hsmmc = ARRAY_SIZE(hsmmc_data);
  126. int i;
  127. if (cpu_is_omap2430()) {
  128. control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
  129. control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1;
  130. } else {
  131. control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE;
  132. control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1;
  133. }
  134. for (c = controllers; c->mmc; c++) {
  135. struct hsmmc_controller *hc = hsmmc + c->mmc - 1;
  136. struct omap_mmc_platform_data *mmc = hsmmc_data[c->mmc - 1];
  137. if (!c->mmc || c->mmc > nr_hsmmc) {
  138. pr_debug("MMC%d: no such controller\n", c->mmc);
  139. continue;
  140. }
  141. if (mmc) {
  142. pr_debug("MMC%d: already configured\n", c->mmc);
  143. continue;
  144. }
  145. mmc = kzalloc(sizeof(struct omap_mmc_platform_data),
  146. GFP_KERNEL);
  147. if (!mmc) {
  148. pr_err("Cannot allocate memory for mmc device!\n");
  149. goto done;
  150. }
  151. if (c->name)
  152. strncpy(hc->name, c->name, HSMMC_NAME_LEN);
  153. else
  154. snprintf(hc->name, ARRAY_SIZE(hc->name),
  155. "mmc%islot%i", c->mmc, 1);
  156. mmc->slots[0].name = hc->name;
  157. mmc->nr_slots = 1;
  158. mmc->slots[0].wires = c->wires;
  159. mmc->slots[0].internal_clock = !c->ext_clock;
  160. mmc->dma_mask = 0xffffffff;
  161. mmc->get_context_loss_count = hsmmc_get_context_loss;
  162. mmc->slots[0].switch_pin = c->gpio_cd;
  163. mmc->slots[0].gpio_wp = c->gpio_wp;
  164. mmc->slots[0].remux = c->remux;
  165. if (c->cover_only)
  166. mmc->slots[0].cover = 1;
  167. if (c->nonremovable)
  168. mmc->slots[0].nonremovable = 1;
  169. if (c->power_saving)
  170. mmc->slots[0].power_saving = 1;
  171. if (c->no_off)
  172. mmc->slots[0].no_off = 1;
  173. if (c->vcc_aux_disable_is_sleep)
  174. mmc->slots[0].vcc_aux_disable_is_sleep = 1;
  175. /* NOTE: MMC slots should have a Vcc regulator set up.
  176. * This may be from a TWL4030-family chip, another
  177. * controllable regulator, or a fixed supply.
  178. *
  179. * temporary HACK: ocr_mask instead of fixed supply
  180. */
  181. mmc->slots[0].ocr_mask = c->ocr_mask;
  182. switch (c->mmc) {
  183. case 1:
  184. /* on-chip level shifting via PBIAS0/PBIAS1 */
  185. mmc->slots[0].before_set_reg = hsmmc1_before_set_reg;
  186. mmc->slots[0].after_set_reg = hsmmc1_after_set_reg;
  187. /* Omap3630 HSMMC1 supports only 4-bit */
  188. if (cpu_is_omap3630() && c->wires > 4) {
  189. c->wires = 4;
  190. mmc->slots[0].wires = c->wires;
  191. }
  192. break;
  193. case 2:
  194. if (c->ext_clock)
  195. c->transceiver = 1;
  196. if (c->transceiver && c->wires > 4)
  197. c->wires = 4;
  198. /* FALLTHROUGH */
  199. case 3:
  200. /* off-chip level shifting, or none */
  201. mmc->slots[0].before_set_reg = hsmmc23_before_set_reg;
  202. mmc->slots[0].after_set_reg = NULL;
  203. break;
  204. default:
  205. pr_err("MMC%d configuration not supported!\n", c->mmc);
  206. kfree(mmc);
  207. continue;
  208. }
  209. hsmmc_data[c->mmc - 1] = mmc;
  210. }
  211. omap2_init_mmc(hsmmc_data, OMAP34XX_NR_MMC);
  212. /* pass the device nodes back to board setup code */
  213. for (c = controllers; c->mmc; c++) {
  214. struct omap_mmc_platform_data *mmc = hsmmc_data[c->mmc - 1];
  215. if (!c->mmc || c->mmc > nr_hsmmc)
  216. continue;
  217. c->dev = mmc->dev;
  218. }
  219. done:
  220. for (i = 0; i < nr_hsmmc; i++)
  221. kfree(hsmmc_data[i]);
  222. }
  223. #endif