hsmmc.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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. static u16 control_mmc1;
  25. #define HSMMC_NAME_LEN 9
  26. static struct hsmmc_controller {
  27. char name[HSMMC_NAME_LEN + 1];
  28. } hsmmc[OMAP34XX_NR_MMC];
  29. #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
  30. static int hsmmc_get_context_loss(struct device *dev)
  31. {
  32. return omap_pm_get_dev_context_loss_count(dev);
  33. }
  34. #else
  35. #define hsmmc_get_context_loss NULL
  36. #endif
  37. static void omap_hsmmc1_before_set_reg(struct device *dev, int slot,
  38. int power_on, int vdd)
  39. {
  40. u32 reg, prog_io;
  41. struct omap_mmc_platform_data *mmc = dev->platform_data;
  42. if (mmc->slots[0].remux)
  43. mmc->slots[0].remux(dev, slot, power_on);
  44. /*
  45. * Assume we power both OMAP VMMC1 (for CMD, CLK, DAT0..3) and the
  46. * card with Vcc regulator (from twl4030 or whatever). OMAP has both
  47. * 1.8V and 3.0V modes, controlled by the PBIAS register.
  48. *
  49. * In 8-bit modes, OMAP VMMC1A (for DAT4..7) needs a supply, which
  50. * is most naturally TWL VSIM; those pins also use PBIAS.
  51. *
  52. * FIXME handle VMMC1A as needed ...
  53. */
  54. if (power_on) {
  55. if (cpu_is_omap2430()) {
  56. reg = omap_ctrl_readl(OMAP243X_CONTROL_DEVCONF1);
  57. if ((1 << vdd) >= MMC_VDD_30_31)
  58. reg |= OMAP243X_MMC1_ACTIVE_OVERWRITE;
  59. else
  60. reg &= ~OMAP243X_MMC1_ACTIVE_OVERWRITE;
  61. omap_ctrl_writel(reg, OMAP243X_CONTROL_DEVCONF1);
  62. }
  63. if (mmc->slots[0].internal_clock) {
  64. reg = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
  65. reg |= OMAP2_MMCSDIO1ADPCLKISEL;
  66. omap_ctrl_writel(reg, OMAP2_CONTROL_DEVCONF0);
  67. }
  68. reg = omap_ctrl_readl(control_pbias_offset);
  69. if (cpu_is_omap3630()) {
  70. /* Set MMC I/O to 52Mhz */
  71. prog_io = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1);
  72. prog_io |= OMAP3630_PRG_SDMMC1_SPEEDCTRL;
  73. omap_ctrl_writel(prog_io, OMAP343X_CONTROL_PROG_IO1);
  74. } else {
  75. reg |= OMAP2_PBIASSPEEDCTRL0;
  76. }
  77. reg &= ~OMAP2_PBIASLITEPWRDNZ0;
  78. omap_ctrl_writel(reg, control_pbias_offset);
  79. } else {
  80. reg = omap_ctrl_readl(control_pbias_offset);
  81. reg &= ~OMAP2_PBIASLITEPWRDNZ0;
  82. omap_ctrl_writel(reg, control_pbias_offset);
  83. }
  84. }
  85. static void omap_hsmmc1_after_set_reg(struct device *dev, int slot,
  86. int power_on, int vdd)
  87. {
  88. u32 reg;
  89. /* 100ms delay required for PBIAS configuration */
  90. msleep(100);
  91. if (power_on) {
  92. reg = omap_ctrl_readl(control_pbias_offset);
  93. reg |= (OMAP2_PBIASLITEPWRDNZ0 | OMAP2_PBIASSPEEDCTRL0);
  94. if ((1 << vdd) <= MMC_VDD_165_195)
  95. reg &= ~OMAP2_PBIASLITEVMODE0;
  96. else
  97. reg |= OMAP2_PBIASLITEVMODE0;
  98. omap_ctrl_writel(reg, control_pbias_offset);
  99. } else {
  100. reg = omap_ctrl_readl(control_pbias_offset);
  101. reg |= (OMAP2_PBIASSPEEDCTRL0 | OMAP2_PBIASLITEPWRDNZ0 |
  102. OMAP2_PBIASLITEVMODE0);
  103. omap_ctrl_writel(reg, control_pbias_offset);
  104. }
  105. }
  106. static void omap4_hsmmc1_before_set_reg(struct device *dev, int slot,
  107. int power_on, int vdd)
  108. {
  109. u32 reg;
  110. /*
  111. * Assume we power both OMAP VMMC1 (for CMD, CLK, DAT0..3) and the
  112. * card with Vcc regulator (from twl4030 or whatever). OMAP has both
  113. * 1.8V and 3.0V modes, controlled by the PBIAS register.
  114. *
  115. * In 8-bit modes, OMAP VMMC1A (for DAT4..7) needs a supply, which
  116. * is most naturally TWL VSIM; those pins also use PBIAS.
  117. *
  118. * FIXME handle VMMC1A as needed ...
  119. */
  120. reg = omap_ctrl_readl(control_pbias_offset);
  121. reg &= ~(OMAP4_MMC1_PBIASLITE_PWRDNZ | OMAP4_MMC1_PWRDNZ |
  122. OMAP4_USBC1_ICUSB_PWRDNZ);
  123. omap_ctrl_writel(reg, control_pbias_offset);
  124. }
  125. static void omap4_hsmmc1_after_set_reg(struct device *dev, int slot,
  126. int power_on, int vdd)
  127. {
  128. u32 reg;
  129. if (power_on) {
  130. reg = omap_ctrl_readl(control_pbias_offset);
  131. reg |= OMAP4_MMC1_PBIASLITE_PWRDNZ;
  132. if ((1 << vdd) <= MMC_VDD_165_195)
  133. reg &= ~OMAP4_MMC1_PBIASLITE_VMODE;
  134. else
  135. reg |= OMAP4_MMC1_PBIASLITE_VMODE;
  136. reg |= (OMAP4_MMC1_PBIASLITE_PWRDNZ | OMAP4_MMC1_PWRDNZ |
  137. OMAP4_USBC1_ICUSB_PWRDNZ);
  138. omap_ctrl_writel(reg, control_pbias_offset);
  139. /* 4 microsec delay for comparator to generate an error*/
  140. udelay(4);
  141. reg = omap_ctrl_readl(control_pbias_offset);
  142. if (reg & OMAP4_MMC1_PBIASLITE_VMODE_ERROR) {
  143. pr_err("Pbias Voltage is not same as LDO\n");
  144. /* Caution : On VMODE_ERROR Power Down MMC IO */
  145. reg &= ~(OMAP4_MMC1_PWRDNZ | OMAP4_USBC1_ICUSB_PWRDNZ);
  146. omap_ctrl_writel(reg, control_pbias_offset);
  147. }
  148. } else {
  149. reg = omap_ctrl_readl(control_pbias_offset);
  150. reg |= (OMAP4_MMC1_PBIASLITE_PWRDNZ |
  151. OMAP4_MMC1_PBIASLITE_VMODE | OMAP4_MMC1_PWRDNZ |
  152. OMAP4_USBC1_ICUSB_PWRDNZ);
  153. omap_ctrl_writel(reg, control_pbias_offset);
  154. }
  155. }
  156. static void hsmmc23_before_set_reg(struct device *dev, int slot,
  157. int power_on, int vdd)
  158. {
  159. struct omap_mmc_platform_data *mmc = dev->platform_data;
  160. if (mmc->slots[0].remux)
  161. mmc->slots[0].remux(dev, slot, power_on);
  162. if (power_on) {
  163. /* Only MMC2 supports a CLKIN */
  164. if (mmc->slots[0].internal_clock) {
  165. u32 reg;
  166. reg = omap_ctrl_readl(control_devconf1_offset);
  167. reg |= OMAP2_MMCSDIO2ADPCLKISEL;
  168. omap_ctrl_writel(reg, control_devconf1_offset);
  169. }
  170. }
  171. }
  172. static int nop_mmc_set_power(struct device *dev, int slot, int power_on,
  173. int vdd)
  174. {
  175. return 0;
  176. }
  177. static struct omap_mmc_platform_data *hsmmc_data[OMAP34XX_NR_MMC] __initdata;
  178. void __init omap2_hsmmc_init(struct omap2_hsmmc_info *controllers)
  179. {
  180. struct omap2_hsmmc_info *c;
  181. int nr_hsmmc = ARRAY_SIZE(hsmmc_data);
  182. int i;
  183. u32 reg;
  184. if (!cpu_is_omap44xx()) {
  185. if (cpu_is_omap2430()) {
  186. control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
  187. control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1;
  188. } else {
  189. control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE;
  190. control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1;
  191. }
  192. } else {
  193. control_pbias_offset = OMAP44XX_CONTROL_PBIAS_LITE;
  194. control_mmc1 = OMAP44XX_CONTROL_MMC1;
  195. reg = omap_ctrl_readl(control_mmc1);
  196. reg |= (OMAP4_CONTROL_SDMMC1_PUSTRENGTHGRP0 |
  197. OMAP4_CONTROL_SDMMC1_PUSTRENGTHGRP1);
  198. reg &= ~(OMAP4_CONTROL_SDMMC1_PUSTRENGTHGRP2 |
  199. OMAP4_CONTROL_SDMMC1_PUSTRENGTHGRP3);
  200. reg |= (OMAP4_CONTROL_SDMMC1_DR0_SPEEDCTRL |
  201. OMAP4_CONTROL_SDMMC1_DR1_SPEEDCTRL |
  202. OMAP4_CONTROL_SDMMC1_DR2_SPEEDCTRL);
  203. omap_ctrl_writel(reg, control_mmc1);
  204. }
  205. for (c = controllers; c->mmc; c++) {
  206. struct hsmmc_controller *hc = hsmmc + c->mmc - 1;
  207. struct omap_mmc_platform_data *mmc = hsmmc_data[c->mmc - 1];
  208. if (!c->mmc || c->mmc > nr_hsmmc) {
  209. pr_debug("MMC%d: no such controller\n", c->mmc);
  210. continue;
  211. }
  212. if (mmc) {
  213. pr_debug("MMC%d: already configured\n", c->mmc);
  214. continue;
  215. }
  216. mmc = kzalloc(sizeof(struct omap_mmc_platform_data),
  217. GFP_KERNEL);
  218. if (!mmc) {
  219. pr_err("Cannot allocate memory for mmc device!\n");
  220. goto done;
  221. }
  222. if (c->name)
  223. strncpy(hc->name, c->name, HSMMC_NAME_LEN);
  224. else
  225. snprintf(hc->name, ARRAY_SIZE(hc->name),
  226. "mmc%islot%i", c->mmc, 1);
  227. mmc->slots[0].name = hc->name;
  228. mmc->nr_slots = 1;
  229. mmc->slots[0].wires = c->wires;
  230. mmc->slots[0].internal_clock = !c->ext_clock;
  231. mmc->dma_mask = 0xffffffff;
  232. mmc->get_context_loss_count = hsmmc_get_context_loss;
  233. mmc->slots[0].switch_pin = c->gpio_cd;
  234. mmc->slots[0].gpio_wp = c->gpio_wp;
  235. mmc->slots[0].remux = c->remux;
  236. mmc->slots[0].init_card = c->init_card;
  237. if (c->cover_only)
  238. mmc->slots[0].cover = 1;
  239. if (c->nonremovable)
  240. mmc->slots[0].nonremovable = 1;
  241. if (c->power_saving)
  242. mmc->slots[0].power_saving = 1;
  243. if (c->no_off)
  244. mmc->slots[0].no_off = 1;
  245. if (c->vcc_aux_disable_is_sleep)
  246. mmc->slots[0].vcc_aux_disable_is_sleep = 1;
  247. /* NOTE: MMC slots should have a Vcc regulator set up.
  248. * This may be from a TWL4030-family chip, another
  249. * controllable regulator, or a fixed supply.
  250. *
  251. * temporary HACK: ocr_mask instead of fixed supply
  252. */
  253. mmc->slots[0].ocr_mask = c->ocr_mask;
  254. if (cpu_is_omap3517() || cpu_is_omap3505())
  255. mmc->slots[0].set_power = nop_mmc_set_power;
  256. else
  257. mmc->slots[0].features |= HSMMC_HAS_PBIAS;
  258. switch (c->mmc) {
  259. case 1:
  260. if (mmc->slots[0].features & HSMMC_HAS_PBIAS) {
  261. /* on-chip level shifting via PBIAS0/PBIAS1 */
  262. if (cpu_is_omap44xx()) {
  263. mmc->slots[0].before_set_reg =
  264. omap4_hsmmc1_before_set_reg;
  265. mmc->slots[0].after_set_reg =
  266. omap4_hsmmc1_after_set_reg;
  267. } else {
  268. mmc->slots[0].before_set_reg =
  269. omap_hsmmc1_before_set_reg;
  270. mmc->slots[0].after_set_reg =
  271. omap_hsmmc1_after_set_reg;
  272. }
  273. }
  274. /* Omap3630 HSMMC1 supports only 4-bit */
  275. if (cpu_is_omap3630() && c->wires > 4) {
  276. c->wires = 4;
  277. mmc->slots[0].wires = c->wires;
  278. }
  279. break;
  280. case 2:
  281. if (c->ext_clock)
  282. c->transceiver = 1;
  283. if (c->transceiver && c->wires > 4)
  284. c->wires = 4;
  285. /* FALLTHROUGH */
  286. case 3:
  287. if (mmc->slots[0].features & HSMMC_HAS_PBIAS) {
  288. /* off-chip level shifting, or none */
  289. mmc->slots[0].before_set_reg = hsmmc23_before_set_reg;
  290. mmc->slots[0].after_set_reg = NULL;
  291. }
  292. break;
  293. default:
  294. pr_err("MMC%d configuration not supported!\n", c->mmc);
  295. kfree(mmc);
  296. continue;
  297. }
  298. hsmmc_data[c->mmc - 1] = mmc;
  299. }
  300. omap2_init_mmc(hsmmc_data, OMAP34XX_NR_MMC);
  301. /* pass the device nodes back to board setup code */
  302. for (c = controllers; c->mmc; c++) {
  303. struct omap_mmc_platform_data *mmc = hsmmc_data[c->mmc - 1];
  304. if (!c->mmc || c->mmc > nr_hsmmc)
  305. continue;
  306. c->dev = mmc->dev;
  307. }
  308. done:
  309. for (i = 0; i < nr_hsmmc; i++)
  310. kfree(hsmmc_data[i]);
  311. }
  312. #endif