sdio.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  1. /*
  2. * linux/drivers/mmc/sdio.c
  3. *
  4. * Copyright 2006-2007 Pierre Ossman
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or (at
  9. * your option) any later version.
  10. */
  11. #include <linux/err.h>
  12. #include <linux/module.h>
  13. #include <linux/pm_runtime.h>
  14. #include <linux/mmc/host.h>
  15. #include <linux/mmc/card.h>
  16. #include <linux/mmc/mmc.h>
  17. #include <linux/mmc/sdio.h>
  18. #include <linux/mmc/sdio_func.h>
  19. #include <linux/mmc/sdio_ids.h>
  20. #include "core.h"
  21. #include "bus.h"
  22. #include "sd.h"
  23. #include "sdio_bus.h"
  24. #include "mmc_ops.h"
  25. #include "sd_ops.h"
  26. #include "sdio_ops.h"
  27. #include "sdio_cis.h"
  28. #ifdef CONFIG_MMC_EMBEDDED_SDIO
  29. #include <linux/mmc/sdio_ids.h>
  30. #endif
  31. static int sdio_read_fbr(struct sdio_func *func)
  32. {
  33. int ret;
  34. unsigned char data;
  35. if (mmc_card_nonstd_func_interface(func->card)) {
  36. func->class = SDIO_CLASS_NONE;
  37. return 0;
  38. }
  39. ret = mmc_io_rw_direct(func->card, 0, 0,
  40. SDIO_FBR_BASE(func->num) + SDIO_FBR_STD_IF, 0, &data);
  41. if (ret)
  42. goto out;
  43. data &= 0x0f;
  44. if (data == 0x0f) {
  45. ret = mmc_io_rw_direct(func->card, 0, 0,
  46. SDIO_FBR_BASE(func->num) + SDIO_FBR_STD_IF_EXT, 0, &data);
  47. if (ret)
  48. goto out;
  49. }
  50. func->class = data;
  51. out:
  52. return ret;
  53. }
  54. static int sdio_init_func(struct mmc_card *card, unsigned int fn)
  55. {
  56. int ret;
  57. struct sdio_func *func;
  58. BUG_ON(fn > SDIO_MAX_FUNCS);
  59. func = sdio_alloc_func(card);
  60. if (IS_ERR(func))
  61. return PTR_ERR(func);
  62. func->num = fn;
  63. if (!(card->quirks & MMC_QUIRK_NONSTD_SDIO)) {
  64. ret = sdio_read_fbr(func);
  65. if (ret)
  66. goto fail;
  67. ret = sdio_read_func_cis(func);
  68. if (ret)
  69. goto fail;
  70. } else {
  71. func->vendor = func->card->cis.vendor;
  72. func->device = func->card->cis.device;
  73. func->max_blksize = func->card->cis.blksize;
  74. }
  75. card->sdio_func[fn - 1] = func;
  76. return 0;
  77. fail:
  78. /*
  79. * It is okay to remove the function here even though we hold
  80. * the host lock as we haven't registered the device yet.
  81. */
  82. sdio_remove_func(func);
  83. return ret;
  84. }
  85. static int sdio_read_cccr(struct mmc_card *card, u32 ocr)
  86. {
  87. int ret;
  88. int cccr_vsn;
  89. int uhs = ocr & R4_18V_PRESENT;
  90. unsigned char data;
  91. unsigned char speed;
  92. memset(&card->cccr, 0, sizeof(struct sdio_cccr));
  93. ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_CCCR, 0, &data);
  94. if (ret)
  95. goto out;
  96. cccr_vsn = data & 0x0f;
  97. if (cccr_vsn > SDIO_CCCR_REV_3_00) {
  98. pr_err("%s: unrecognised CCCR structure version %d\n",
  99. mmc_hostname(card->host), cccr_vsn);
  100. return -EINVAL;
  101. }
  102. card->cccr.sdio_vsn = (data & 0xf0) >> 4;
  103. ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_CAPS, 0, &data);
  104. if (ret)
  105. goto out;
  106. if (data & SDIO_CCCR_CAP_SMB)
  107. card->cccr.multi_block = 1;
  108. if (data & SDIO_CCCR_CAP_LSC)
  109. card->cccr.low_speed = 1;
  110. if (data & SDIO_CCCR_CAP_4BLS)
  111. card->cccr.wide_bus = 1;
  112. if (cccr_vsn >= SDIO_CCCR_REV_1_10) {
  113. ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_POWER, 0, &data);
  114. if (ret)
  115. goto out;
  116. if (data & SDIO_POWER_SMPC)
  117. card->cccr.high_power = 1;
  118. }
  119. if (cccr_vsn >= SDIO_CCCR_REV_1_20) {
  120. ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_SPEED, 0, &speed);
  121. if (ret)
  122. goto out;
  123. card->scr.sda_spec3 = 0;
  124. card->sw_caps.sd3_bus_mode = 0;
  125. card->sw_caps.sd3_drv_type = 0;
  126. if (cccr_vsn >= SDIO_CCCR_REV_3_00 && uhs) {
  127. card->scr.sda_spec3 = 1;
  128. ret = mmc_io_rw_direct(card, 0, 0,
  129. SDIO_CCCR_UHS, 0, &data);
  130. if (ret)
  131. goto out;
  132. if (mmc_host_uhs(card->host)) {
  133. if (data & SDIO_UHS_DDR50)
  134. card->sw_caps.sd3_bus_mode
  135. |= SD_MODE_UHS_DDR50;
  136. if (data & SDIO_UHS_SDR50)
  137. card->sw_caps.sd3_bus_mode
  138. |= SD_MODE_UHS_SDR50;
  139. if (data & SDIO_UHS_SDR104)
  140. card->sw_caps.sd3_bus_mode
  141. |= SD_MODE_UHS_SDR104;
  142. }
  143. ret = mmc_io_rw_direct(card, 0, 0,
  144. SDIO_CCCR_DRIVE_STRENGTH, 0, &data);
  145. if (ret)
  146. goto out;
  147. if (data & SDIO_DRIVE_SDTA)
  148. card->sw_caps.sd3_drv_type |= SD_DRIVER_TYPE_A;
  149. if (data & SDIO_DRIVE_SDTC)
  150. card->sw_caps.sd3_drv_type |= SD_DRIVER_TYPE_C;
  151. if (data & SDIO_DRIVE_SDTD)
  152. card->sw_caps.sd3_drv_type |= SD_DRIVER_TYPE_D;
  153. ret = mmc_io_rw_direct(card, 0, 0,
  154. SDIO_CCCR_INTERRUPT_EXTENSION, 0, &data);
  155. if (ret)
  156. goto out;
  157. if (data & SDIO_SUPPORT_ASYNC_INTR) {
  158. if (card->host->caps2 &
  159. MMC_CAP2_ASYNC_SDIO_IRQ_4BIT_MODE) {
  160. data |= SDIO_ENABLE_ASYNC_INTR;
  161. ret = mmc_io_rw_direct(card, 1, 0,
  162. SDIO_CCCR_INTERRUPT_EXTENSION,
  163. data, NULL);
  164. if (ret)
  165. goto out;
  166. card->cccr.async_intr_sup = 1;
  167. }
  168. }
  169. }
  170. /* if no uhs mode ensure we check for high speed */
  171. if (!card->sw_caps.sd3_bus_mode) {
  172. if (speed & SDIO_SPEED_SHS) {
  173. card->cccr.high_speed = 1;
  174. card->sw_caps.hs_max_dtr = 50000000;
  175. } else {
  176. card->cccr.high_speed = 0;
  177. card->sw_caps.hs_max_dtr = 25000000;
  178. }
  179. }
  180. }
  181. out:
  182. return ret;
  183. }
  184. static int sdio_enable_wide(struct mmc_card *card)
  185. {
  186. int ret;
  187. u8 ctrl;
  188. if (!(card->host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)))
  189. return 0;
  190. if (card->cccr.low_speed && !card->cccr.wide_bus)
  191. return 0;
  192. ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_IF, 0, &ctrl);
  193. if (ret)
  194. return ret;
  195. if (card->host->caps & MMC_CAP_8_BIT_DATA)
  196. ctrl |= SDIO_BUS_WIDTH_8BIT;
  197. else if (card->host->caps & MMC_CAP_4_BIT_DATA)
  198. ctrl |= SDIO_BUS_WIDTH_4BIT;
  199. ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_IF, ctrl, NULL);
  200. if (ret)
  201. return ret;
  202. return 1;
  203. }
  204. /*
  205. * If desired, disconnect the pull-up resistor on CD/DAT[3] (pin 1)
  206. * of the card. This may be required on certain setups of boards,
  207. * controllers and embedded sdio device which do not need the card's
  208. * pull-up. As a result, card detection is disabled and power is saved.
  209. */
  210. static int sdio_disable_cd(struct mmc_card *card)
  211. {
  212. int ret;
  213. u8 ctrl;
  214. if (!mmc_card_disable_cd(card))
  215. return 0;
  216. ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_IF, 0, &ctrl);
  217. if (ret)
  218. return ret;
  219. ctrl |= SDIO_BUS_CD_DISABLE;
  220. return mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_IF, ctrl, NULL);
  221. }
  222. /*
  223. * Devices that remain active during a system suspend are
  224. * put back into 1-bit mode.
  225. */
  226. static int sdio_disable_wide(struct mmc_card *card)
  227. {
  228. int ret;
  229. u8 ctrl;
  230. if (!(card->host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)))
  231. return 0;
  232. if (card->cccr.low_speed && !card->cccr.wide_bus)
  233. return 0;
  234. ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_IF, 0, &ctrl);
  235. if (ret)
  236. return ret;
  237. if (!(ctrl & (SDIO_BUS_WIDTH_4BIT | SDIO_BUS_WIDTH_8BIT)))
  238. return 0;
  239. ctrl &= ~(SDIO_BUS_WIDTH_4BIT | SDIO_BUS_WIDTH_8BIT);
  240. ctrl |= SDIO_BUS_ASYNC_INT;
  241. ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_IF, ctrl, NULL);
  242. if (ret)
  243. return ret;
  244. mmc_set_bus_width(card->host, MMC_BUS_WIDTH_1);
  245. return 0;
  246. }
  247. static int sdio_enable_4bit_bus(struct mmc_card *card)
  248. {
  249. int err;
  250. if (card->type == MMC_TYPE_SDIO)
  251. return sdio_enable_wide(card);
  252. if ((card->host->caps & MMC_CAP_4_BIT_DATA) &&
  253. (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
  254. err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4);
  255. if (err)
  256. return err;
  257. } else
  258. return 0;
  259. err = sdio_enable_wide(card);
  260. if (err <= 0)
  261. mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1);
  262. return err;
  263. }
  264. /*
  265. * Test if the card supports high-speed mode and, if so, switch to it.
  266. */
  267. static int mmc_sdio_switch_hs(struct mmc_card *card, int enable)
  268. {
  269. int ret;
  270. u8 speed;
  271. if (!(card->host->caps & MMC_CAP_SD_HIGHSPEED))
  272. return 0;
  273. if (!card->cccr.high_speed)
  274. return 0;
  275. ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_SPEED, 0, &speed);
  276. if (ret)
  277. return ret;
  278. if (enable)
  279. speed |= SDIO_SPEED_EHS;
  280. else
  281. speed &= ~SDIO_SPEED_EHS;
  282. ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_SPEED, speed, NULL);
  283. if (ret)
  284. return ret;
  285. return 1;
  286. }
  287. /*
  288. * Enable SDIO/combo card's high-speed mode. Return 0/1 if [not]supported.
  289. */
  290. static int sdio_enable_hs(struct mmc_card *card)
  291. {
  292. int ret;
  293. ret = mmc_sdio_switch_hs(card, true);
  294. if (ret <= 0 || card->type == MMC_TYPE_SDIO)
  295. return ret;
  296. ret = mmc_sd_switch_hs(card);
  297. if (ret <= 0)
  298. mmc_sdio_switch_hs(card, false);
  299. return ret;
  300. }
  301. static unsigned mmc_sdio_get_max_clock(struct mmc_card *card)
  302. {
  303. unsigned max_dtr;
  304. if (mmc_card_highspeed(card)) {
  305. /*
  306. * The SDIO specification doesn't mention how
  307. * the CIS transfer speed register relates to
  308. * high-speed, but it seems that 50 MHz is
  309. * mandatory.
  310. */
  311. max_dtr = 50000000;
  312. } else {
  313. max_dtr = card->cis.max_dtr;
  314. }
  315. if (card->type == MMC_TYPE_SD_COMBO)
  316. max_dtr = min(max_dtr, mmc_sd_get_max_clock(card));
  317. return max_dtr;
  318. }
  319. static unsigned char host_drive_to_sdio_drive(int host_strength)
  320. {
  321. switch (host_strength) {
  322. case MMC_SET_DRIVER_TYPE_A:
  323. return SDIO_DTSx_SET_TYPE_A;
  324. case MMC_SET_DRIVER_TYPE_B:
  325. return SDIO_DTSx_SET_TYPE_B;
  326. case MMC_SET_DRIVER_TYPE_C:
  327. return SDIO_DTSx_SET_TYPE_C;
  328. case MMC_SET_DRIVER_TYPE_D:
  329. return SDIO_DTSx_SET_TYPE_D;
  330. default:
  331. return SDIO_DTSx_SET_TYPE_B;
  332. }
  333. }
  334. static void sdio_select_driver_type(struct mmc_card *card)
  335. {
  336. int host_drv_type = SD_DRIVER_TYPE_B;
  337. int card_drv_type = SD_DRIVER_TYPE_B;
  338. int drive_strength;
  339. unsigned char card_strength;
  340. int err;
  341. /*
  342. * If the host doesn't support any of the Driver Types A,C or D,
  343. * or there is no board specific handler then default Driver
  344. * Type B is used.
  345. */
  346. if (!(card->host->caps &
  347. (MMC_CAP_DRIVER_TYPE_A |
  348. MMC_CAP_DRIVER_TYPE_C |
  349. MMC_CAP_DRIVER_TYPE_D)))
  350. return;
  351. if (!card->host->ops->select_drive_strength)
  352. return;
  353. if (card->host->caps & MMC_CAP_DRIVER_TYPE_A)
  354. host_drv_type |= SD_DRIVER_TYPE_A;
  355. if (card->host->caps & MMC_CAP_DRIVER_TYPE_C)
  356. host_drv_type |= SD_DRIVER_TYPE_C;
  357. if (card->host->caps & MMC_CAP_DRIVER_TYPE_D)
  358. host_drv_type |= SD_DRIVER_TYPE_D;
  359. if (card->sw_caps.sd3_drv_type & SD_DRIVER_TYPE_A)
  360. card_drv_type |= SD_DRIVER_TYPE_A;
  361. if (card->sw_caps.sd3_drv_type & SD_DRIVER_TYPE_C)
  362. card_drv_type |= SD_DRIVER_TYPE_C;
  363. if (card->sw_caps.sd3_drv_type & SD_DRIVER_TYPE_D)
  364. card_drv_type |= SD_DRIVER_TYPE_D;
  365. /*
  366. * The drive strength that the hardware can support
  367. * depends on the board design. Pass the appropriate
  368. * information and let the hardware specific code
  369. * return what is possible given the options
  370. */
  371. drive_strength = card->host->ops->select_drive_strength(
  372. card->sw_caps.uhs_max_dtr,
  373. host_drv_type, card_drv_type);
  374. /* if error just use default for drive strength B */
  375. err = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_DRIVE_STRENGTH, 0,
  376. &card_strength);
  377. if (err)
  378. return;
  379. card_strength &= ~(SDIO_DRIVE_DTSx_MASK<<SDIO_DRIVE_DTSx_SHIFT);
  380. card_strength |= host_drive_to_sdio_drive(drive_strength);
  381. err = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_DRIVE_STRENGTH,
  382. card_strength, NULL);
  383. /* if error default to drive strength B */
  384. if (!err)
  385. mmc_set_driver_type(card->host, drive_strength);
  386. }
  387. static int sdio_set_bus_speed_mode(struct mmc_card *card)
  388. {
  389. unsigned int bus_speed, timing;
  390. int err;
  391. unsigned char speed;
  392. /*
  393. * If the host doesn't support any of the UHS-I modes, fallback on
  394. * default speed.
  395. */
  396. if (!mmc_host_uhs(card->host))
  397. return 0;
  398. bus_speed = SDIO_SPEED_SDR12;
  399. timing = MMC_TIMING_UHS_SDR12;
  400. if ((card->host->caps & MMC_CAP_UHS_SDR104) &&
  401. (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR104)) {
  402. bus_speed = SDIO_SPEED_SDR104;
  403. timing = MMC_TIMING_UHS_SDR104;
  404. card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR;
  405. card->sd_bus_speed = UHS_SDR104_BUS_SPEED;
  406. } else if ((card->host->caps & MMC_CAP_UHS_DDR50) &&
  407. (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_DDR50)) {
  408. bus_speed = SDIO_SPEED_DDR50;
  409. timing = MMC_TIMING_UHS_DDR50;
  410. card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR;
  411. card->sd_bus_speed = UHS_DDR50_BUS_SPEED;
  412. } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
  413. MMC_CAP_UHS_SDR50)) && (card->sw_caps.sd3_bus_mode &
  414. SD_MODE_UHS_SDR50)) {
  415. bus_speed = SDIO_SPEED_SDR50;
  416. timing = MMC_TIMING_UHS_SDR50;
  417. card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR;
  418. card->sd_bus_speed = UHS_SDR50_BUS_SPEED;
  419. } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
  420. MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25)) &&
  421. (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR25)) {
  422. bus_speed = SDIO_SPEED_SDR25;
  423. timing = MMC_TIMING_UHS_SDR25;
  424. card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR;
  425. card->sd_bus_speed = UHS_SDR25_BUS_SPEED;
  426. } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
  427. MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25 |
  428. MMC_CAP_UHS_SDR12)) && (card->sw_caps.sd3_bus_mode &
  429. SD_MODE_UHS_SDR12)) {
  430. bus_speed = SDIO_SPEED_SDR12;
  431. timing = MMC_TIMING_UHS_SDR12;
  432. card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR;
  433. card->sd_bus_speed = UHS_SDR12_BUS_SPEED;
  434. }
  435. err = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_SPEED, 0, &speed);
  436. if (err)
  437. return err;
  438. speed &= ~SDIO_SPEED_BSS_MASK;
  439. speed |= bus_speed;
  440. err = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_SPEED, speed, NULL);
  441. if (err)
  442. return err;
  443. if (bus_speed) {
  444. mmc_set_timing(card->host, timing);
  445. mmc_set_clock(card->host, card->sw_caps.uhs_max_dtr);
  446. }
  447. return 0;
  448. }
  449. /*
  450. * UHS-I specific initialization procedure
  451. */
  452. static int mmc_sdio_init_uhs_card(struct mmc_card *card)
  453. {
  454. int err;
  455. if (!card->scr.sda_spec3)
  456. return 0;
  457. /*
  458. * Switch to wider bus (if supported).
  459. */
  460. if (card->host->caps & MMC_CAP_4_BIT_DATA) {
  461. err = sdio_enable_4bit_bus(card);
  462. if (err > 0) {
  463. mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
  464. err = 0;
  465. }
  466. }
  467. /* Set the driver strength for the card */
  468. sdio_select_driver_type(card);
  469. /* Set bus speed mode of the card */
  470. err = sdio_set_bus_speed_mode(card);
  471. if (err)
  472. goto out;
  473. // #if defined(CONFIG_BCM4335) || defined(CONFIG_BCM4335_MODULE) || defined(CONFIG_BCM4339) || defined(CONFIG_BCM4339_MODULE)
  474. #if 0
  475. /*
  476. * Prevent tuning operation when init a card
  477. * for WiFi operation with sdmmc.
  478. */
  479. if (!strcmp(mmc_hostname(card->host), "mmc1"))
  480. printk("%s: remove initialize and start re-tuning timer"
  481. "to prevent CMD53 request timeout \n", mmc_hostname(card->host));
  482. else
  483. #endif
  484. /* Initialize and start re-tuning timer */
  485. if (!mmc_host_is_spi(card->host) && card->host->ops->execute_tuning)
  486. err = card->host->ops->execute_tuning(card->host,
  487. MMC_SEND_TUNING_BLOCK);
  488. out:
  489. return err;
  490. }
  491. /*
  492. * Handle the detection and initialisation of a card.
  493. *
  494. * In the case of a resume, "oldcard" will contain the card
  495. * we're trying to reinitialise.
  496. */
  497. static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
  498. struct mmc_card *oldcard, int powered_resume)
  499. {
  500. struct mmc_card *card;
  501. int err;
  502. BUG_ON(!host);
  503. WARN_ON(!host->claimed);
  504. #if defined(CONFIG_BCM4335) || defined(CONFIG_BCM4335_MODULE) || \
  505. defined(CONFIG_BCM4339) || defined(CONFIG_BCM4339_MODULE) || \
  506. defined(CONFIG_BCM4354) || defined(CONFIG_BCM4354_MODULE)
  507. /* If host that supports UHS-I sets S18R to 1 in arg of CMD5 to request
  508. * change of signaling level to 1.8V
  509. */
  510. if (host->caps &
  511. (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
  512. MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 |
  513. MMC_CAP_UHS_DDR50))
  514. host->ocr |= R4_18V_PRESENT;
  515. #endif
  516. /*
  517. * Inform the card of the voltage
  518. */
  519. if (!powered_resume) {
  520. /* The initialization should be done at 3.3 V I/O voltage. */
  521. mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0);
  522. err = mmc_send_io_op_cond(host, host->ocr, &ocr);
  523. if (err)
  524. goto err;
  525. }
  526. /*
  527. * For SPI, enable CRC as appropriate.
  528. */
  529. if (mmc_host_is_spi(host)) {
  530. err = mmc_spi_set_crc(host, use_spi_crc);
  531. if (err)
  532. goto err;
  533. }
  534. /*
  535. * Allocate card structure.
  536. */
  537. card = mmc_alloc_card(host, NULL);
  538. if (IS_ERR(card)) {
  539. err = PTR_ERR(card);
  540. goto err;
  541. }
  542. if ((ocr & R4_MEMORY_PRESENT) &&
  543. mmc_sd_get_cid(host, host->ocr & ocr, card->raw_cid, NULL) == 0) {
  544. card->type = MMC_TYPE_SD_COMBO;
  545. if (oldcard && (oldcard->type != MMC_TYPE_SD_COMBO ||
  546. memcmp(card->raw_cid, oldcard->raw_cid, sizeof(card->raw_cid)) != 0)) {
  547. mmc_remove_card(card);
  548. return -ENOENT;
  549. }
  550. } else {
  551. card->type = MMC_TYPE_SDIO;
  552. if (oldcard && oldcard->type != MMC_TYPE_SDIO) {
  553. mmc_remove_card(card);
  554. return -ENOENT;
  555. }
  556. }
  557. /*
  558. * Call the optional HC's init_card function to handle quirks.
  559. */
  560. if (host->ops->init_card) {
  561. mmc_host_clk_hold(host);
  562. host->ops->init_card(host, card);
  563. mmc_host_clk_release(host);
  564. }
  565. /*
  566. * If the host and card support UHS-I mode request the card
  567. * to switch to 1.8V signaling level. No 1.8v signalling if
  568. * UHS mode is not enabled to maintain compatibilty and some
  569. * systems that claim 1.8v signalling in fact do not support
  570. * it.
  571. */
  572. if ((ocr & R4_18V_PRESENT) && mmc_host_uhs(host)) {
  573. err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180,
  574. true);
  575. if (err) {
  576. ocr &= ~R4_18V_PRESENT;
  577. host->ocr &= ~R4_18V_PRESENT;
  578. }
  579. err = 0;
  580. } else {
  581. ocr &= ~R4_18V_PRESENT;
  582. host->ocr &= ~R4_18V_PRESENT;
  583. }
  584. /*
  585. * For native busses: set card RCA and quit open drain mode.
  586. */
  587. if (!powered_resume && !mmc_host_is_spi(host)) {
  588. err = mmc_send_relative_addr(host, &card->rca);
  589. if (err)
  590. goto remove;
  591. /*
  592. * Update oldcard with the new RCA received from the SDIO
  593. * device -- we're doing this so that it's updated in the
  594. * "card" struct when oldcard overwrites that later.
  595. */
  596. if (oldcard)
  597. oldcard->rca = card->rca;
  598. }
  599. /*
  600. * Read CSD, before selecting the card
  601. */
  602. if (!oldcard && card->type == MMC_TYPE_SD_COMBO) {
  603. err = mmc_sd_get_csd(host, card);
  604. if (err)
  605. return err;
  606. mmc_decode_cid(card);
  607. }
  608. /*
  609. * Select card, as all following commands rely on that.
  610. */
  611. if (!powered_resume && !mmc_host_is_spi(host)) {
  612. err = mmc_select_card(card);
  613. if (err)
  614. goto remove;
  615. }
  616. if (card->quirks & MMC_QUIRK_NONSTD_SDIO) {
  617. /*
  618. * This is non-standard SDIO device, meaning it doesn't
  619. * have any CIA (Common I/O area) registers present.
  620. * It's host's responsibility to fill cccr and cis
  621. * structures in init_card().
  622. */
  623. mmc_set_clock(host, card->cis.max_dtr);
  624. if (card->cccr.high_speed) {
  625. mmc_card_set_highspeed(card);
  626. mmc_set_timing(card->host, MMC_TIMING_SD_HS);
  627. }
  628. goto finish;
  629. }
  630. #ifdef CONFIG_MMC_EMBEDDED_SDIO
  631. if (host->embedded_sdio_data.cccr)
  632. memcpy(&card->cccr, host->embedded_sdio_data.cccr, sizeof(struct sdio_cccr));
  633. else {
  634. #endif
  635. /*
  636. * Read the common registers.
  637. */
  638. err = sdio_read_cccr(card, ocr);
  639. if (err)
  640. goto remove;
  641. #ifdef CONFIG_MMC_EMBEDDED_SDIO
  642. }
  643. #endif
  644. #ifdef CONFIG_MMC_EMBEDDED_SDIO
  645. if (host->embedded_sdio_data.cis)
  646. memcpy(&card->cis, host->embedded_sdio_data.cis, sizeof(struct sdio_cis));
  647. else {
  648. #endif
  649. /*
  650. * Read the common CIS tuples.
  651. */
  652. err = sdio_read_common_cis(card);
  653. if (err)
  654. goto remove;
  655. #ifdef CONFIG_MMC_EMBEDDED_SDIO
  656. }
  657. #endif
  658. if (oldcard) {
  659. int same = (card->cis.vendor == oldcard->cis.vendor &&
  660. card->cis.device == oldcard->cis.device);
  661. mmc_remove_card(card);
  662. if (!same)
  663. return -ENOENT;
  664. card = oldcard;
  665. }
  666. mmc_fixup_device(card, NULL);
  667. if (card->type == MMC_TYPE_SD_COMBO) {
  668. err = mmc_sd_setup_card(host, card, oldcard != NULL);
  669. /* handle as SDIO-only card if memory init failed */
  670. if (err) {
  671. mmc_go_idle(host);
  672. if (mmc_host_is_spi(host))
  673. /* should not fail, as it worked previously */
  674. mmc_spi_set_crc(host, use_spi_crc);
  675. card->type = MMC_TYPE_SDIO;
  676. } else
  677. card->dev.type = &sd_type;
  678. }
  679. /*
  680. * If needed, disconnect card detection pull-up resistor.
  681. */
  682. err = sdio_disable_cd(card);
  683. if (err)
  684. goto remove;
  685. /* Initialization sequence for UHS-I cards */
  686. /* Only if card supports 1.8v and UHS signaling */
  687. if ((ocr & R4_18V_PRESENT) && card->sw_caps.sd3_bus_mode) {
  688. err = mmc_sdio_init_uhs_card(card);
  689. if (err)
  690. goto remove;
  691. /* Card is an ultra-high-speed card */
  692. mmc_card_set_uhs(card);
  693. } else {
  694. /*
  695. * Switch to high-speed (if supported).
  696. */
  697. err = sdio_enable_hs(card);
  698. if (err > 0)
  699. mmc_sd_go_highspeed(card);
  700. else if (err)
  701. goto remove;
  702. /*
  703. * Change to the card's maximum speed.
  704. */
  705. mmc_set_clock(host, mmc_sdio_get_max_clock(card));
  706. /*
  707. * Switch to wider bus (if supported).
  708. */
  709. err = sdio_enable_4bit_bus(card);
  710. if (err > 0) {
  711. if (card->host->caps & MMC_CAP_8_BIT_DATA)
  712. mmc_set_bus_width(card->host, MMC_BUS_WIDTH_8);
  713. else if (card->host->caps & MMC_CAP_4_BIT_DATA)
  714. mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
  715. } else if (err)
  716. goto remove;
  717. }
  718. finish:
  719. if (!oldcard)
  720. host->card = card;
  721. return 0;
  722. remove:
  723. if (!oldcard)
  724. mmc_remove_card(card);
  725. err:
  726. return err;
  727. }
  728. /*
  729. * Host is being removed. Free up the current card.
  730. */
  731. static void mmc_sdio_remove(struct mmc_host *host)
  732. {
  733. int i;
  734. BUG_ON(!host);
  735. BUG_ON(!host->card);
  736. for (i = 0;i < host->card->sdio_funcs;i++) {
  737. if (host->card->sdio_func[i]) {
  738. sdio_remove_func(host->card->sdio_func[i]);
  739. host->card->sdio_func[i] = NULL;
  740. }
  741. }
  742. mmc_remove_card(host->card);
  743. host->card = NULL;
  744. }
  745. /*
  746. * Card detection - card is alive.
  747. */
  748. static int mmc_sdio_alive(struct mmc_host *host)
  749. {
  750. return mmc_select_card(host->card);
  751. }
  752. /*
  753. * Card detection callback from host.
  754. */
  755. static void mmc_sdio_detect(struct mmc_host *host)
  756. {
  757. int err;
  758. BUG_ON(!host);
  759. BUG_ON(!host->card);
  760. /* Make sure card is powered before detecting it */
  761. if (host->caps & MMC_CAP_POWER_OFF_CARD) {
  762. err = pm_runtime_get_sync(&host->card->dev);
  763. if (err < 0)
  764. goto out;
  765. }
  766. mmc_claim_host(host);
  767. /*
  768. * Just check if our card has been removed.
  769. */
  770. err = _mmc_detect_card_removed(host);
  771. mmc_release_host(host);
  772. /*
  773. * Tell PM core it's OK to power off the card now.
  774. *
  775. * The _sync variant is used in order to ensure that the card
  776. * is left powered off in case an error occurred, and the card
  777. * is going to be removed.
  778. *
  779. * Since there is no specific reason to believe a new user
  780. * is about to show up at this point, the _sync variant is
  781. * desirable anyway.
  782. */
  783. if (host->caps & MMC_CAP_POWER_OFF_CARD)
  784. pm_runtime_put_sync(&host->card->dev);
  785. out:
  786. if (err) {
  787. mmc_sdio_remove(host);
  788. mmc_claim_host(host);
  789. mmc_detach_bus(host);
  790. mmc_power_off(host);
  791. mmc_release_host(host);
  792. }
  793. }
  794. /*
  795. * SDIO suspend. We need to suspend all functions separately.
  796. * Therefore all registered functions must have drivers with suspend
  797. * and resume methods. Failing that we simply remove the whole card.
  798. */
  799. static int mmc_sdio_suspend(struct mmc_host *host)
  800. {
  801. int i, err = 0;
  802. for (i = 0; i < host->card->sdio_funcs; i++) {
  803. struct sdio_func *func = host->card->sdio_func[i];
  804. if (func && sdio_func_present(func) && func->dev.driver) {
  805. const struct dev_pm_ops *pmops = func->dev.driver->pm;
  806. if (!pmops || !pmops->suspend || !pmops->resume) {
  807. /* force removal of entire card in that case */
  808. err = -ENOSYS;
  809. } else
  810. err = pmops->suspend(&func->dev);
  811. if (err)
  812. break;
  813. }
  814. }
  815. while (err && --i >= 0) {
  816. struct sdio_func *func = host->card->sdio_func[i];
  817. if (func && sdio_func_present(func) && func->dev.driver) {
  818. const struct dev_pm_ops *pmops = func->dev.driver->pm;
  819. pmops->resume(&func->dev);
  820. }
  821. }
  822. if (!err && mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) {
  823. mmc_claim_host(host);
  824. sdio_disable_wide(host->card);
  825. mmc_release_host(host);
  826. }
  827. return err;
  828. }
  829. static int mmc_sdio_resume(struct mmc_host *host)
  830. {
  831. int i, err = 0;
  832. BUG_ON(!host);
  833. BUG_ON(!host->card);
  834. /* Basic card reinitialization. */
  835. mmc_claim_host(host);
  836. /* No need to reinitialize powered-resumed nonremovable cards */
  837. if (mmc_card_is_removable(host) || !mmc_card_keep_power(host)) {
  838. sdio_reset(host);
  839. mmc_go_idle(host);
  840. err = mmc_sdio_init_card(host, host->ocr, host->card,
  841. mmc_card_keep_power(host));
  842. } else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) {
  843. /* We may have switched to 1-bit mode during suspend */
  844. err = sdio_enable_4bit_bus(host->card);
  845. if (err > 0) {
  846. if (host->caps & MMC_CAP_8_BIT_DATA)
  847. mmc_set_bus_width(host, MMC_BUS_WIDTH_8);
  848. else if (host->caps & MMC_CAP_4_BIT_DATA)
  849. mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
  850. err = 0;
  851. }
  852. }
  853. if (!err && host->sdio_irqs)
  854. wake_up_process(host->sdio_irq_thread);
  855. mmc_release_host(host);
  856. /*
  857. * If the card looked to be the same as before suspending, then
  858. * we proceed to resume all card functions. If one of them returns
  859. * an error then we simply return that error to the core and the
  860. * card will be redetected as new. It is the responsibility of
  861. * the function driver to perform further tests with the extra
  862. * knowledge it has of the card to confirm the card is indeed the
  863. * same as before suspending (same MAC address for network cards,
  864. * etc.) and return an error otherwise.
  865. */
  866. for (i = 0; !err && i < host->card->sdio_funcs; i++) {
  867. struct sdio_func *func = host->card->sdio_func[i];
  868. if (func && sdio_func_present(func) && func->dev.driver) {
  869. const struct dev_pm_ops *pmops = func->dev.driver->pm;
  870. err = pmops->resume(&func->dev);
  871. }
  872. }
  873. return err;
  874. }
  875. static int mmc_sdio_power_restore(struct mmc_host *host)
  876. {
  877. int ret;
  878. u32 ocr;
  879. BUG_ON(!host);
  880. BUG_ON(!host->card);
  881. mmc_claim_host(host);
  882. /*
  883. * Reset the card by performing the same steps that are taken by
  884. * mmc_rescan_try_freq() and mmc_attach_sdio() during a "normal" probe.
  885. *
  886. * sdio_reset() is technically not needed. Having just powered up the
  887. * hardware, it should already be in reset state. However, some
  888. * platforms (such as SD8686 on OLPC) do not instantly cut power,
  889. * meaning that a reset is required when restoring power soon after
  890. * powering off. It is harmless in other cases.
  891. *
  892. * The CMD5 reset (mmc_send_io_op_cond()), according to the SDIO spec,
  893. * is not necessary for non-removable cards. However, it is required
  894. * for OLPC SD8686 (which expects a [CMD5,5,3,7] init sequence), and
  895. * harmless in other situations.
  896. *
  897. * With these steps taken, mmc_select_voltage() is also required to
  898. * restore the correct voltage setting of the card.
  899. */
  900. /* The initialization should be done at 3.3 V I/O voltage. */
  901. if (!mmc_card_keep_power(host))
  902. mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0);
  903. sdio_reset(host);
  904. mmc_go_idle(host);
  905. mmc_send_if_cond(host, host->ocr_avail);
  906. ret = mmc_send_io_op_cond(host, 0, &ocr);
  907. if (ret)
  908. goto out;
  909. if (host->ocr_avail_sdio)
  910. host->ocr_avail = host->ocr_avail_sdio;
  911. host->ocr = mmc_select_voltage(host, ocr & ~0x7F);
  912. if (!host->ocr) {
  913. ret = -EINVAL;
  914. goto out;
  915. }
  916. if (mmc_host_uhs(host))
  917. /* to query card if 1.8V signalling is supported */
  918. host->ocr |= R4_18V_PRESENT;
  919. ret = mmc_sdio_init_card(host, host->ocr, host->card,
  920. mmc_card_keep_power(host));
  921. if (!ret && host->sdio_irqs)
  922. mmc_signal_sdio_irq(host);
  923. out:
  924. mmc_release_host(host);
  925. return ret;
  926. }
  927. static const struct mmc_bus_ops mmc_sdio_ops = {
  928. .remove = mmc_sdio_remove,
  929. .detect = mmc_sdio_detect,
  930. .suspend = mmc_sdio_suspend,
  931. .resume = mmc_sdio_resume,
  932. .power_restore = mmc_sdio_power_restore,
  933. .alive = mmc_sdio_alive,
  934. };
  935. /*
  936. * Starting point for SDIO card init.
  937. */
  938. int mmc_attach_sdio(struct mmc_host *host)
  939. {
  940. int err, i, funcs;
  941. u32 ocr;
  942. struct mmc_card *card;
  943. BUG_ON(!host);
  944. WARN_ON(!host->claimed);
  945. err = mmc_send_io_op_cond(host, 0, &ocr);
  946. if (err)
  947. return err;
  948. mmc_attach_bus(host, &mmc_sdio_ops);
  949. if (host->ocr_avail_sdio)
  950. host->ocr_avail = host->ocr_avail_sdio;
  951. /*
  952. * Sanity check the voltages that the card claims to
  953. * support.
  954. */
  955. if (ocr & 0x7F) {
  956. pr_warning("%s: card claims to support voltages "
  957. "below the defined range. These will be ignored.\n",
  958. mmc_hostname(host));
  959. ocr &= ~0x7F;
  960. }
  961. host->ocr = mmc_select_voltage(host, ocr);
  962. /*
  963. * Can we support the voltage(s) of the card(s)?
  964. */
  965. if (!host->ocr) {
  966. err = -EINVAL;
  967. goto err;
  968. }
  969. /*
  970. * Detect and init the card.
  971. */
  972. if (mmc_host_uhs(host))
  973. /* to query card if 1.8V signalling is supported */
  974. host->ocr |= R4_18V_PRESENT;
  975. err = mmc_sdio_init_card(host, host->ocr, NULL, 0);
  976. if (err) {
  977. if (err == -EAGAIN) {
  978. /*
  979. * Retry initialization with S18R set to 0.
  980. */
  981. host->ocr &= ~R4_18V_PRESENT;
  982. err = mmc_sdio_init_card(host, host->ocr, NULL, 0);
  983. }
  984. if (err)
  985. goto err;
  986. }
  987. card = host->card;
  988. /*
  989. * Enable runtime PM only if supported by host+card+board
  990. */
  991. if (host->caps & MMC_CAP_POWER_OFF_CARD) {
  992. /*
  993. * Let runtime PM core know our card is active
  994. */
  995. err = pm_runtime_set_active(&card->dev);
  996. if (err)
  997. goto remove;
  998. /*
  999. * Enable runtime PM for this card
  1000. */
  1001. pm_runtime_enable(&card->dev);
  1002. }
  1003. /*
  1004. * The number of functions on the card is encoded inside
  1005. * the ocr.
  1006. */
  1007. funcs = (ocr & 0x70000000) >> 28;
  1008. card->sdio_funcs = 0;
  1009. #ifdef CONFIG_MMC_EMBEDDED_SDIO
  1010. if (host->embedded_sdio_data.funcs)
  1011. card->sdio_funcs = funcs = host->embedded_sdio_data.num_funcs;
  1012. #endif
  1013. /*
  1014. * Initialize (but don't add) all present functions.
  1015. */
  1016. for (i = 0; i < funcs; i++, card->sdio_funcs++) {
  1017. #ifdef CONFIG_MMC_EMBEDDED_SDIO
  1018. if (host->embedded_sdio_data.funcs) {
  1019. struct sdio_func *tmp;
  1020. tmp = sdio_alloc_func(host->card);
  1021. if (IS_ERR(tmp))
  1022. goto remove;
  1023. tmp->num = (i + 1);
  1024. card->sdio_func[i] = tmp;
  1025. tmp->class = host->embedded_sdio_data.funcs[i].f_class;
  1026. tmp->max_blksize = host->embedded_sdio_data.funcs[i].f_maxblksize;
  1027. tmp->vendor = card->cis.vendor;
  1028. tmp->device = card->cis.device;
  1029. } else {
  1030. #endif
  1031. err = sdio_init_func(host->card, i + 1);
  1032. if (err)
  1033. goto remove;
  1034. #ifdef CONFIG_MMC_EMBEDDED_SDIO
  1035. }
  1036. #endif
  1037. /*
  1038. * Enable Runtime PM for this func (if supported)
  1039. */
  1040. if (host->caps & MMC_CAP_POWER_OFF_CARD)
  1041. pm_runtime_enable(&card->sdio_func[i]->dev);
  1042. }
  1043. /*
  1044. * First add the card to the driver model...
  1045. */
  1046. mmc_release_host(host);
  1047. err = mmc_add_card(host->card);
  1048. if (err)
  1049. goto remove_added;
  1050. /*
  1051. * ...then the SDIO functions.
  1052. */
  1053. for (i = 0;i < funcs;i++) {
  1054. err = sdio_add_func(host->card->sdio_func[i]);
  1055. if (err)
  1056. goto remove_added;
  1057. }
  1058. mmc_claim_host(host);
  1059. return 0;
  1060. remove_added:
  1061. /* Remove without lock if the device has been added. */
  1062. mmc_sdio_remove(host);
  1063. mmc_claim_host(host);
  1064. remove:
  1065. /* And with lock if it hasn't been added. */
  1066. mmc_release_host(host);
  1067. if (host->card)
  1068. mmc_sdio_remove(host);
  1069. mmc_claim_host(host);
  1070. err:
  1071. mmc_detach_bus(host);
  1072. pr_err("%s: error %d whilst initialising SDIO card\n",
  1073. mmc_hostname(host), err);
  1074. return err;
  1075. }
  1076. int sdio_reset_comm(struct mmc_card *card)
  1077. {
  1078. #if defined(CONFIG_BCM4339) || defined(CONFIG_BCM4335) || defined(CONFIG_BCM4354)
  1079. struct mmc_host *host = card->host;
  1080. u32 ocr;
  1081. int err;
  1082. printk("%s():\n", __func__);
  1083. mmc_claim_host(host);
  1084. mmc_set_timing(host, MMC_TIMING_LEGACY);
  1085. mmc_set_clock(host, host->f_init);
  1086. sdio_reset(host);
  1087. mmc_go_idle(host);
  1088. mmc_send_if_cond(host, host->ocr_avail);
  1089. err = mmc_send_io_op_cond(host, 0, &ocr);
  1090. if (err)
  1091. goto err;
  1092. if (host->ocr_avail_sdio)
  1093. host->ocr_avail = host->ocr_avail_sdio;
  1094. host->ocr = mmc_select_voltage(host, ocr & ~0x7F);
  1095. if (!host->ocr) {
  1096. err = -EINVAL;
  1097. printk("%s(): voltage err\n", __func__);
  1098. goto err;
  1099. }
  1100. if (mmc_host_uhs(host))
  1101. /* to query card if 1.8V signalling is supported */
  1102. host->ocr |= R4_18V_PRESENT;
  1103. err = mmc_sdio_init_card(host, host->ocr, card, 0);
  1104. if (err)
  1105. goto err;
  1106. mmc_release_host(host);
  1107. return 0;
  1108. err:
  1109. printk("%s: Error resetting SDIO communications (%d)\n",
  1110. mmc_hostname(host), err);
  1111. mmc_release_host(host);
  1112. return err;
  1113. #else
  1114. return mmc_power_restore_host(card->host);
  1115. #endif /* CONFIG_BCM4339 || CONFIG_BCM4335 || CONFIG_BCM4354 */
  1116. }
  1117. EXPORT_SYMBOL(sdio_reset_comm);
  1118. #if defined(CONFIG_BCM4339) || defined(CONFIG_BCM4335) || defined(CONFIG_BCM4354)
  1119. void sdio_ctrl_power(struct mmc_host *host, bool onoff)
  1120. {
  1121. mmc_claim_host(host);
  1122. if (onoff)
  1123. mmc_power_up(host);
  1124. else
  1125. mmc_power_off(host);
  1126. /* Wait at least 1 ms according to SD spec */
  1127. mmc_delay(1);
  1128. mmc_release_host(host);
  1129. }
  1130. EXPORT_SYMBOL(sdio_ctrl_power);
  1131. #endif /* CONFIG_BCM4339 || CONFIG_BCM4335 || CONFIG_BCM4354 */