hsmmc.c 6.5 KB

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