hsmmc.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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/mmc.h>
  18. #include <plat/omap-pm.h>
  19. #include "hsmmc.h"
  20. #include "control.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 = omap4_ctrl_pad_readl(control_pbias_offset);
  121. reg &= ~(OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK |
  122. OMAP4_MMC1_PWRDNZ_MASK |
  123. OMAP4_USBC1_ICUSB_PWRDNZ_MASK);
  124. omap4_ctrl_pad_writel(reg, control_pbias_offset);
  125. }
  126. static void omap4_hsmmc1_after_set_reg(struct device *dev, int slot,
  127. int power_on, int vdd)
  128. {
  129. u32 reg;
  130. if (power_on) {
  131. reg = omap4_ctrl_pad_readl(control_pbias_offset);
  132. reg |= OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK;
  133. if ((1 << vdd) <= MMC_VDD_165_195)
  134. reg &= ~OMAP4_MMC1_PBIASLITE_VMODE_MASK;
  135. else
  136. reg |= OMAP4_MMC1_PBIASLITE_VMODE_MASK;
  137. reg |= (OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK |
  138. OMAP4_MMC1_PWRDNZ_MASK |
  139. OMAP4_USBC1_ICUSB_PWRDNZ_MASK);
  140. omap4_ctrl_pad_writel(reg, control_pbias_offset);
  141. /* 4 microsec delay for comparator to generate an error*/
  142. udelay(4);
  143. reg = omap4_ctrl_pad_readl(control_pbias_offset);
  144. if (reg & OMAP4_MMC1_PBIASLITE_VMODE_ERROR_MASK) {
  145. pr_err("Pbias Voltage is not same as LDO\n");
  146. /* Caution : On VMODE_ERROR Power Down MMC IO */
  147. reg &= ~(OMAP4_MMC1_PWRDNZ_MASK |
  148. OMAP4_USBC1_ICUSB_PWRDNZ_MASK);
  149. omap4_ctrl_pad_writel(reg, control_pbias_offset);
  150. }
  151. } else {
  152. reg = omap4_ctrl_pad_readl(control_pbias_offset);
  153. reg |= (OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK |
  154. OMAP4_MMC1_PWRDNZ_MASK |
  155. OMAP4_MMC1_PBIASLITE_VMODE_MASK |
  156. OMAP4_USBC1_ICUSB_PWRDNZ_MASK);
  157. omap4_ctrl_pad_writel(reg, control_pbias_offset);
  158. }
  159. }
  160. static void hsmmc23_before_set_reg(struct device *dev, int slot,
  161. int power_on, int vdd)
  162. {
  163. struct omap_mmc_platform_data *mmc = dev->platform_data;
  164. if (mmc->slots[0].remux)
  165. mmc->slots[0].remux(dev, slot, power_on);
  166. if (power_on) {
  167. /* Only MMC2 supports a CLKIN */
  168. if (mmc->slots[0].internal_clock) {
  169. u32 reg;
  170. reg = omap_ctrl_readl(control_devconf1_offset);
  171. reg |= OMAP2_MMCSDIO2ADPCLKISEL;
  172. omap_ctrl_writel(reg, control_devconf1_offset);
  173. }
  174. }
  175. }
  176. static int nop_mmc_set_power(struct device *dev, int slot, int power_on,
  177. int vdd)
  178. {
  179. return 0;
  180. }
  181. static struct omap_mmc_platform_data *hsmmc_data[OMAP34XX_NR_MMC] __initdata;
  182. void __init omap2_hsmmc_init(struct omap2_hsmmc_info *controllers)
  183. {
  184. struct omap2_hsmmc_info *c;
  185. int nr_hsmmc = ARRAY_SIZE(hsmmc_data);
  186. int i;
  187. u32 reg;
  188. if (!cpu_is_omap44xx()) {
  189. if (cpu_is_omap2430()) {
  190. control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
  191. control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1;
  192. } else {
  193. control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE;
  194. control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1;
  195. }
  196. } else {
  197. control_pbias_offset =
  198. OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_PBIASLITE;
  199. control_mmc1 = OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_MMC1;
  200. reg = omap4_ctrl_pad_readl(control_mmc1);
  201. reg |= (OMAP4_SDMMC1_PUSTRENGTH_GRP0_MASK |
  202. OMAP4_SDMMC1_PUSTRENGTH_GRP1_MASK);
  203. reg &= ~(OMAP4_SDMMC1_PUSTRENGTH_GRP2_MASK |
  204. OMAP4_SDMMC1_PUSTRENGTH_GRP3_MASK);
  205. reg |= (OMAP4_USBC1_DR0_SPEEDCTRL_MASK|
  206. OMAP4_SDMMC1_DR1_SPEEDCTRL_MASK |
  207. OMAP4_SDMMC1_DR2_SPEEDCTRL_MASK);
  208. omap4_ctrl_pad_writel(reg, control_mmc1);
  209. }
  210. for (c = controllers; c->mmc; c++) {
  211. struct hsmmc_controller *hc = hsmmc + c->mmc - 1;
  212. struct omap_mmc_platform_data *mmc = hsmmc_data[c->mmc - 1];
  213. if (!c->mmc || c->mmc > nr_hsmmc) {
  214. pr_debug("MMC%d: no such controller\n", c->mmc);
  215. continue;
  216. }
  217. if (mmc) {
  218. pr_debug("MMC%d: already configured\n", c->mmc);
  219. continue;
  220. }
  221. mmc = kzalloc(sizeof(struct omap_mmc_platform_data),
  222. GFP_KERNEL);
  223. if (!mmc) {
  224. pr_err("Cannot allocate memory for mmc device!\n");
  225. goto done;
  226. }
  227. if (c->name)
  228. strncpy(hc->name, c->name, HSMMC_NAME_LEN);
  229. else
  230. snprintf(hc->name, ARRAY_SIZE(hc->name),
  231. "mmc%islot%i", c->mmc, 1);
  232. mmc->slots[0].name = hc->name;
  233. mmc->nr_slots = 1;
  234. mmc->slots[0].caps = c->caps;
  235. mmc->slots[0].internal_clock = !c->ext_clock;
  236. mmc->dma_mask = 0xffffffff;
  237. if (cpu_is_omap44xx())
  238. mmc->reg_offset = OMAP4_MMC_REG_OFFSET;
  239. else
  240. mmc->reg_offset = 0;
  241. mmc->get_context_loss_count = hsmmc_get_context_loss;
  242. mmc->slots[0].switch_pin = c->gpio_cd;
  243. mmc->slots[0].gpio_wp = c->gpio_wp;
  244. mmc->slots[0].remux = c->remux;
  245. mmc->slots[0].init_card = c->init_card;
  246. if (c->cover_only)
  247. mmc->slots[0].cover = 1;
  248. if (c->nonremovable)
  249. mmc->slots[0].nonremovable = 1;
  250. if (c->power_saving)
  251. mmc->slots[0].power_saving = 1;
  252. if (c->no_off)
  253. mmc->slots[0].no_off = 1;
  254. if (c->vcc_aux_disable_is_sleep)
  255. mmc->slots[0].vcc_aux_disable_is_sleep = 1;
  256. /* NOTE: MMC slots should have a Vcc regulator set up.
  257. * This may be from a TWL4030-family chip, another
  258. * controllable regulator, or a fixed supply.
  259. *
  260. * temporary HACK: ocr_mask instead of fixed supply
  261. */
  262. mmc->slots[0].ocr_mask = c->ocr_mask;
  263. if (cpu_is_omap3517() || cpu_is_omap3505())
  264. mmc->slots[0].set_power = nop_mmc_set_power;
  265. else
  266. mmc->slots[0].features |= HSMMC_HAS_PBIAS;
  267. if (cpu_is_omap44xx() && (omap_rev() > OMAP4430_REV_ES1_0))
  268. mmc->slots[0].features |= HSMMC_HAS_UPDATED_RESET;
  269. switch (c->mmc) {
  270. case 1:
  271. if (mmc->slots[0].features & HSMMC_HAS_PBIAS) {
  272. /* on-chip level shifting via PBIAS0/PBIAS1 */
  273. if (cpu_is_omap44xx()) {
  274. mmc->slots[0].before_set_reg =
  275. omap4_hsmmc1_before_set_reg;
  276. mmc->slots[0].after_set_reg =
  277. omap4_hsmmc1_after_set_reg;
  278. } else {
  279. mmc->slots[0].before_set_reg =
  280. omap_hsmmc1_before_set_reg;
  281. mmc->slots[0].after_set_reg =
  282. omap_hsmmc1_after_set_reg;
  283. }
  284. }
  285. /* Omap3630 HSMMC1 supports only 4-bit */
  286. if (cpu_is_omap3630() &&
  287. (c->caps & MMC_CAP_8_BIT_DATA)) {
  288. c->caps &= ~MMC_CAP_8_BIT_DATA;
  289. c->caps |= MMC_CAP_4_BIT_DATA;
  290. mmc->slots[0].caps = c->caps;
  291. }
  292. break;
  293. case 2:
  294. if (c->ext_clock)
  295. c->transceiver = 1;
  296. if (c->transceiver && (c->caps & MMC_CAP_8_BIT_DATA)) {
  297. c->caps &= ~MMC_CAP_8_BIT_DATA;
  298. c->caps |= MMC_CAP_4_BIT_DATA;
  299. }
  300. /* FALLTHROUGH */
  301. case 3:
  302. if (mmc->slots[0].features & HSMMC_HAS_PBIAS) {
  303. /* off-chip level shifting, or none */
  304. mmc->slots[0].before_set_reg = hsmmc23_before_set_reg;
  305. mmc->slots[0].after_set_reg = NULL;
  306. }
  307. break;
  308. default:
  309. pr_err("MMC%d configuration not supported!\n", c->mmc);
  310. kfree(mmc);
  311. continue;
  312. }
  313. hsmmc_data[c->mmc - 1] = mmc;
  314. }
  315. omap2_init_mmc(hsmmc_data, OMAP34XX_NR_MMC);
  316. /* pass the device nodes back to board setup code */
  317. for (c = controllers; c->mmc; c++) {
  318. struct omap_mmc_platform_data *mmc = hsmmc_data[c->mmc - 1];
  319. if (!c->mmc || c->mmc > nr_hsmmc)
  320. continue;
  321. c->dev = mmc->dev;
  322. }
  323. done:
  324. for (i = 0; i < nr_hsmmc; i++)
  325. kfree(hsmmc_data[i]);
  326. }
  327. #endif