hsmmc.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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 <plat/mux.h>
  20. #include "mux.h"
  21. #include "hsmmc.h"
  22. #include "control.h"
  23. #if defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
  24. static u16 control_pbias_offset;
  25. static u16 control_devconf1_offset;
  26. static u16 control_mmc1;
  27. #define HSMMC_NAME_LEN 9
  28. static struct hsmmc_controller {
  29. char name[HSMMC_NAME_LEN + 1];
  30. } hsmmc[OMAP34XX_NR_MMC];
  31. #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
  32. static int hsmmc_get_context_loss(struct device *dev)
  33. {
  34. return omap_pm_get_dev_context_loss_count(dev);
  35. }
  36. #else
  37. #define hsmmc_get_context_loss NULL
  38. #endif
  39. static void omap_hsmmc1_before_set_reg(struct device *dev, int slot,
  40. int power_on, int vdd)
  41. {
  42. u32 reg, prog_io;
  43. struct omap_mmc_platform_data *mmc = dev->platform_data;
  44. if (mmc->slots[0].remux)
  45. mmc->slots[0].remux(dev, slot, power_on);
  46. /*
  47. * Assume we power both OMAP VMMC1 (for CMD, CLK, DAT0..3) and the
  48. * card with Vcc regulator (from twl4030 or whatever). OMAP has both
  49. * 1.8V and 3.0V modes, controlled by the PBIAS register.
  50. *
  51. * In 8-bit modes, OMAP VMMC1A (for DAT4..7) needs a supply, which
  52. * is most naturally TWL VSIM; those pins also use PBIAS.
  53. *
  54. * FIXME handle VMMC1A as needed ...
  55. */
  56. if (power_on) {
  57. if (cpu_is_omap2430()) {
  58. reg = omap_ctrl_readl(OMAP243X_CONTROL_DEVCONF1);
  59. if ((1 << vdd) >= MMC_VDD_30_31)
  60. reg |= OMAP243X_MMC1_ACTIVE_OVERWRITE;
  61. else
  62. reg &= ~OMAP243X_MMC1_ACTIVE_OVERWRITE;
  63. omap_ctrl_writel(reg, OMAP243X_CONTROL_DEVCONF1);
  64. }
  65. if (mmc->slots[0].internal_clock) {
  66. reg = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
  67. reg |= OMAP2_MMCSDIO1ADPCLKISEL;
  68. omap_ctrl_writel(reg, OMAP2_CONTROL_DEVCONF0);
  69. }
  70. reg = omap_ctrl_readl(control_pbias_offset);
  71. if (cpu_is_omap3630()) {
  72. /* Set MMC I/O to 52Mhz */
  73. prog_io = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1);
  74. prog_io |= OMAP3630_PRG_SDMMC1_SPEEDCTRL;
  75. omap_ctrl_writel(prog_io, OMAP343X_CONTROL_PROG_IO1);
  76. } else {
  77. reg |= OMAP2_PBIASSPEEDCTRL0;
  78. }
  79. reg &= ~OMAP2_PBIASLITEPWRDNZ0;
  80. omap_ctrl_writel(reg, control_pbias_offset);
  81. } else {
  82. reg = omap_ctrl_readl(control_pbias_offset);
  83. reg &= ~OMAP2_PBIASLITEPWRDNZ0;
  84. omap_ctrl_writel(reg, control_pbias_offset);
  85. }
  86. }
  87. static void omap_hsmmc1_after_set_reg(struct device *dev, int slot,
  88. int power_on, int vdd)
  89. {
  90. u32 reg;
  91. /* 100ms delay required for PBIAS configuration */
  92. msleep(100);
  93. if (power_on) {
  94. reg = omap_ctrl_readl(control_pbias_offset);
  95. reg |= (OMAP2_PBIASLITEPWRDNZ0 | OMAP2_PBIASSPEEDCTRL0);
  96. if ((1 << vdd) <= MMC_VDD_165_195)
  97. reg &= ~OMAP2_PBIASLITEVMODE0;
  98. else
  99. reg |= OMAP2_PBIASLITEVMODE0;
  100. omap_ctrl_writel(reg, control_pbias_offset);
  101. } else {
  102. reg = omap_ctrl_readl(control_pbias_offset);
  103. reg |= (OMAP2_PBIASSPEEDCTRL0 | OMAP2_PBIASLITEPWRDNZ0 |
  104. OMAP2_PBIASLITEVMODE0);
  105. omap_ctrl_writel(reg, control_pbias_offset);
  106. }
  107. }
  108. static void omap4_hsmmc1_before_set_reg(struct device *dev, int slot,
  109. int power_on, int vdd)
  110. {
  111. u32 reg;
  112. /*
  113. * Assume we power both OMAP VMMC1 (for CMD, CLK, DAT0..3) and the
  114. * card with Vcc regulator (from twl4030 or whatever). OMAP has both
  115. * 1.8V and 3.0V modes, controlled by the PBIAS register.
  116. *
  117. * In 8-bit modes, OMAP VMMC1A (for DAT4..7) needs a supply, which
  118. * is most naturally TWL VSIM; those pins also use PBIAS.
  119. *
  120. * FIXME handle VMMC1A as needed ...
  121. */
  122. reg = omap4_ctrl_pad_readl(control_pbias_offset);
  123. reg &= ~(OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK |
  124. OMAP4_MMC1_PWRDNZ_MASK |
  125. OMAP4_USBC1_ICUSB_PWRDNZ_MASK);
  126. omap4_ctrl_pad_writel(reg, control_pbias_offset);
  127. }
  128. static void omap4_hsmmc1_after_set_reg(struct device *dev, int slot,
  129. int power_on, int vdd)
  130. {
  131. u32 reg;
  132. if (power_on) {
  133. reg = omap4_ctrl_pad_readl(control_pbias_offset);
  134. reg |= OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK;
  135. if ((1 << vdd) <= MMC_VDD_165_195)
  136. reg &= ~OMAP4_MMC1_PBIASLITE_VMODE_MASK;
  137. else
  138. reg |= OMAP4_MMC1_PBIASLITE_VMODE_MASK;
  139. reg |= (OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK |
  140. OMAP4_MMC1_PWRDNZ_MASK |
  141. OMAP4_USBC1_ICUSB_PWRDNZ_MASK);
  142. omap4_ctrl_pad_writel(reg, control_pbias_offset);
  143. /* 4 microsec delay for comparator to generate an error*/
  144. udelay(4);
  145. reg = omap4_ctrl_pad_readl(control_pbias_offset);
  146. if (reg & OMAP4_MMC1_PBIASLITE_VMODE_ERROR_MASK) {
  147. pr_err("Pbias Voltage is not same as LDO\n");
  148. /* Caution : On VMODE_ERROR Power Down MMC IO */
  149. reg &= ~(OMAP4_MMC1_PWRDNZ_MASK |
  150. OMAP4_USBC1_ICUSB_PWRDNZ_MASK);
  151. omap4_ctrl_pad_writel(reg, control_pbias_offset);
  152. }
  153. } else {
  154. reg = omap4_ctrl_pad_readl(control_pbias_offset);
  155. reg |= (OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK |
  156. OMAP4_MMC1_PWRDNZ_MASK |
  157. OMAP4_MMC1_PBIASLITE_VMODE_MASK |
  158. OMAP4_USBC1_ICUSB_PWRDNZ_MASK);
  159. omap4_ctrl_pad_writel(reg, control_pbias_offset);
  160. }
  161. }
  162. static void hsmmc23_before_set_reg(struct device *dev, int slot,
  163. int power_on, int vdd)
  164. {
  165. struct omap_mmc_platform_data *mmc = dev->platform_data;
  166. if (mmc->slots[0].remux)
  167. mmc->slots[0].remux(dev, slot, power_on);
  168. if (power_on) {
  169. /* Only MMC2 supports a CLKIN */
  170. if (mmc->slots[0].internal_clock) {
  171. u32 reg;
  172. reg = omap_ctrl_readl(control_devconf1_offset);
  173. reg |= OMAP2_MMCSDIO2ADPCLKISEL;
  174. omap_ctrl_writel(reg, control_devconf1_offset);
  175. }
  176. }
  177. }
  178. static int nop_mmc_set_power(struct device *dev, int slot, int power_on,
  179. int vdd)
  180. {
  181. return 0;
  182. }
  183. static inline void omap_hsmmc_mux(struct omap_mmc_platform_data *mmc_controller,
  184. int controller_nr)
  185. {
  186. if ((mmc_controller->slots[0].switch_pin > 0) && \
  187. (mmc_controller->slots[0].switch_pin < OMAP_MAX_GPIO_LINES))
  188. omap_mux_init_gpio(mmc_controller->slots[0].switch_pin,
  189. OMAP_PIN_INPUT_PULLUP);
  190. if ((mmc_controller->slots[0].gpio_wp > 0) && \
  191. (mmc_controller->slots[0].gpio_wp < OMAP_MAX_GPIO_LINES))
  192. omap_mux_init_gpio(mmc_controller->slots[0].gpio_wp,
  193. OMAP_PIN_INPUT_PULLUP);
  194. if (cpu_is_omap34xx()) {
  195. if (controller_nr == 0) {
  196. omap_mux_init_signal("sdmmc1_clk",
  197. OMAP_PIN_INPUT_PULLUP);
  198. omap_mux_init_signal("sdmmc1_cmd",
  199. OMAP_PIN_INPUT_PULLUP);
  200. omap_mux_init_signal("sdmmc1_dat0",
  201. OMAP_PIN_INPUT_PULLUP);
  202. if (mmc_controller->slots[0].caps &
  203. (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) {
  204. omap_mux_init_signal("sdmmc1_dat1",
  205. OMAP_PIN_INPUT_PULLUP);
  206. omap_mux_init_signal("sdmmc1_dat2",
  207. OMAP_PIN_INPUT_PULLUP);
  208. omap_mux_init_signal("sdmmc1_dat3",
  209. OMAP_PIN_INPUT_PULLUP);
  210. }
  211. if (mmc_controller->slots[0].caps &
  212. MMC_CAP_8_BIT_DATA) {
  213. omap_mux_init_signal("sdmmc1_dat4",
  214. OMAP_PIN_INPUT_PULLUP);
  215. omap_mux_init_signal("sdmmc1_dat5",
  216. OMAP_PIN_INPUT_PULLUP);
  217. omap_mux_init_signal("sdmmc1_dat6",
  218. OMAP_PIN_INPUT_PULLUP);
  219. omap_mux_init_signal("sdmmc1_dat7",
  220. OMAP_PIN_INPUT_PULLUP);
  221. }
  222. }
  223. if (controller_nr == 1) {
  224. /* MMC2 */
  225. omap_mux_init_signal("sdmmc2_clk",
  226. OMAP_PIN_INPUT_PULLUP);
  227. omap_mux_init_signal("sdmmc2_cmd",
  228. OMAP_PIN_INPUT_PULLUP);
  229. omap_mux_init_signal("sdmmc2_dat0",
  230. OMAP_PIN_INPUT_PULLUP);
  231. /*
  232. * For 8 wire configurations, Lines DAT4, 5, 6 and 7
  233. * need to be muxed in the board-*.c files
  234. */
  235. if (mmc_controller->slots[0].caps &
  236. (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) {
  237. omap_mux_init_signal("sdmmc2_dat1",
  238. OMAP_PIN_INPUT_PULLUP);
  239. omap_mux_init_signal("sdmmc2_dat2",
  240. OMAP_PIN_INPUT_PULLUP);
  241. omap_mux_init_signal("sdmmc2_dat3",
  242. OMAP_PIN_INPUT_PULLUP);
  243. }
  244. if (mmc_controller->slots[0].caps &
  245. MMC_CAP_8_BIT_DATA) {
  246. omap_mux_init_signal("sdmmc2_dat4.sdmmc2_dat4",
  247. OMAP_PIN_INPUT_PULLUP);
  248. omap_mux_init_signal("sdmmc2_dat5.sdmmc2_dat5",
  249. OMAP_PIN_INPUT_PULLUP);
  250. omap_mux_init_signal("sdmmc2_dat6.sdmmc2_dat6",
  251. OMAP_PIN_INPUT_PULLUP);
  252. omap_mux_init_signal("sdmmc2_dat7.sdmmc2_dat7",
  253. OMAP_PIN_INPUT_PULLUP);
  254. }
  255. }
  256. /*
  257. * For MMC3 the pins need to be muxed in the board-*.c files
  258. */
  259. }
  260. }
  261. static struct omap_mmc_platform_data *hsmmc_data[OMAP34XX_NR_MMC] __initdata;
  262. void __init omap2_hsmmc_init(struct omap2_hsmmc_info *controllers)
  263. {
  264. struct omap2_hsmmc_info *c;
  265. int nr_hsmmc = ARRAY_SIZE(hsmmc_data);
  266. int i;
  267. u32 reg;
  268. if (!cpu_is_omap44xx()) {
  269. if (cpu_is_omap2430()) {
  270. control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
  271. control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1;
  272. } else {
  273. control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE;
  274. control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1;
  275. }
  276. } else {
  277. control_pbias_offset =
  278. OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_PBIASLITE;
  279. control_mmc1 = OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_MMC1;
  280. reg = omap4_ctrl_pad_readl(control_mmc1);
  281. reg |= (OMAP4_SDMMC1_PUSTRENGTH_GRP0_MASK |
  282. OMAP4_SDMMC1_PUSTRENGTH_GRP1_MASK);
  283. reg &= ~(OMAP4_SDMMC1_PUSTRENGTH_GRP2_MASK |
  284. OMAP4_SDMMC1_PUSTRENGTH_GRP3_MASK);
  285. reg |= (OMAP4_USBC1_DR0_SPEEDCTRL_MASK|
  286. OMAP4_SDMMC1_DR1_SPEEDCTRL_MASK |
  287. OMAP4_SDMMC1_DR2_SPEEDCTRL_MASK);
  288. omap4_ctrl_pad_writel(reg, control_mmc1);
  289. }
  290. for (c = controllers; c->mmc; c++) {
  291. struct hsmmc_controller *hc = hsmmc + c->mmc - 1;
  292. struct omap_mmc_platform_data *mmc = hsmmc_data[c->mmc - 1];
  293. if (!c->mmc || c->mmc > nr_hsmmc) {
  294. pr_debug("MMC%d: no such controller\n", c->mmc);
  295. continue;
  296. }
  297. if (mmc) {
  298. pr_debug("MMC%d: already configured\n", c->mmc);
  299. continue;
  300. }
  301. mmc = kzalloc(sizeof(struct omap_mmc_platform_data),
  302. GFP_KERNEL);
  303. if (!mmc) {
  304. pr_err("Cannot allocate memory for mmc device!\n");
  305. goto done;
  306. }
  307. if (c->name)
  308. strncpy(hc->name, c->name, HSMMC_NAME_LEN);
  309. else
  310. snprintf(hc->name, ARRAY_SIZE(hc->name),
  311. "mmc%islot%i", c->mmc, 1);
  312. mmc->slots[0].name = hc->name;
  313. mmc->nr_slots = 1;
  314. mmc->slots[0].caps = c->caps;
  315. mmc->slots[0].internal_clock = !c->ext_clock;
  316. mmc->dma_mask = 0xffffffff;
  317. if (cpu_is_omap44xx())
  318. mmc->reg_offset = OMAP4_MMC_REG_OFFSET;
  319. else
  320. mmc->reg_offset = 0;
  321. mmc->get_context_loss_count = hsmmc_get_context_loss;
  322. mmc->slots[0].switch_pin = c->gpio_cd;
  323. mmc->slots[0].gpio_wp = c->gpio_wp;
  324. mmc->slots[0].remux = c->remux;
  325. mmc->slots[0].init_card = c->init_card;
  326. if (c->cover_only)
  327. mmc->slots[0].cover = 1;
  328. if (c->nonremovable)
  329. mmc->slots[0].nonremovable = 1;
  330. if (c->power_saving)
  331. mmc->slots[0].power_saving = 1;
  332. if (c->no_off)
  333. mmc->slots[0].no_off = 1;
  334. if (c->vcc_aux_disable_is_sleep)
  335. mmc->slots[0].vcc_aux_disable_is_sleep = 1;
  336. /* NOTE: MMC slots should have a Vcc regulator set up.
  337. * This may be from a TWL4030-family chip, another
  338. * controllable regulator, or a fixed supply.
  339. *
  340. * temporary HACK: ocr_mask instead of fixed supply
  341. */
  342. mmc->slots[0].ocr_mask = c->ocr_mask;
  343. if (cpu_is_omap3517() || cpu_is_omap3505())
  344. mmc->slots[0].set_power = nop_mmc_set_power;
  345. else
  346. mmc->slots[0].features |= HSMMC_HAS_PBIAS;
  347. if (cpu_is_omap44xx() && (omap_rev() > OMAP4430_REV_ES1_0))
  348. mmc->slots[0].features |= HSMMC_HAS_UPDATED_RESET;
  349. switch (c->mmc) {
  350. case 1:
  351. if (mmc->slots[0].features & HSMMC_HAS_PBIAS) {
  352. /* on-chip level shifting via PBIAS0/PBIAS1 */
  353. if (cpu_is_omap44xx()) {
  354. mmc->slots[0].before_set_reg =
  355. omap4_hsmmc1_before_set_reg;
  356. mmc->slots[0].after_set_reg =
  357. omap4_hsmmc1_after_set_reg;
  358. } else {
  359. mmc->slots[0].before_set_reg =
  360. omap_hsmmc1_before_set_reg;
  361. mmc->slots[0].after_set_reg =
  362. omap_hsmmc1_after_set_reg;
  363. }
  364. }
  365. /* Omap3630 HSMMC1 supports only 4-bit */
  366. if (cpu_is_omap3630() &&
  367. (c->caps & MMC_CAP_8_BIT_DATA)) {
  368. c->caps &= ~MMC_CAP_8_BIT_DATA;
  369. c->caps |= MMC_CAP_4_BIT_DATA;
  370. mmc->slots[0].caps = c->caps;
  371. }
  372. break;
  373. case 2:
  374. if (c->ext_clock)
  375. c->transceiver = 1;
  376. if (c->transceiver && (c->caps & MMC_CAP_8_BIT_DATA)) {
  377. c->caps &= ~MMC_CAP_8_BIT_DATA;
  378. c->caps |= MMC_CAP_4_BIT_DATA;
  379. }
  380. /* FALLTHROUGH */
  381. case 3:
  382. if (mmc->slots[0].features & HSMMC_HAS_PBIAS) {
  383. /* off-chip level shifting, or none */
  384. mmc->slots[0].before_set_reg = hsmmc23_before_set_reg;
  385. mmc->slots[0].after_set_reg = NULL;
  386. }
  387. break;
  388. case 4:
  389. case 5:
  390. mmc->slots[0].before_set_reg = NULL;
  391. mmc->slots[0].after_set_reg = NULL;
  392. break;
  393. default:
  394. pr_err("MMC%d configuration not supported!\n", c->mmc);
  395. kfree(mmc);
  396. continue;
  397. }
  398. hsmmc_data[c->mmc - 1] = mmc;
  399. omap_hsmmc_mux(hsmmc_data[c->mmc - 1], (c->mmc - 1));
  400. }
  401. omap2_init_mmc(hsmmc_data, OMAP34XX_NR_MMC);
  402. /* pass the device nodes back to board setup code */
  403. for (c = controllers; c->mmc; c++) {
  404. struct omap_mmc_platform_data *mmc = hsmmc_data[c->mmc - 1];
  405. if (!c->mmc || c->mmc > nr_hsmmc)
  406. continue;
  407. c->dev = mmc->dev;
  408. }
  409. done:
  410. for (i = 0; i < nr_hsmmc; i++)
  411. kfree(hsmmc_data[i]);
  412. }
  413. #endif