sdio_io.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. /*
  2. * linux/drivers/mmc/core/sdio_io.c
  3. *
  4. * Copyright 2007-2008 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/export.h>
  12. #include <linux/mmc/host.h>
  13. #include <linux/mmc/card.h>
  14. #include <linux/mmc/sdio.h>
  15. #include <linux/mmc/sdio_func.h>
  16. #include "sdio_ops.h"
  17. /**
  18. * sdio_claim_host - exclusively claim a bus for a certain SDIO function
  19. * @func: SDIO function that will be accessed
  20. *
  21. * Claim a bus for a set of operations. The SDIO function given
  22. * is used to figure out which bus is relevant.
  23. */
  24. void sdio_claim_host(struct sdio_func *func)
  25. {
  26. BUG_ON(!func);
  27. BUG_ON(!func->card);
  28. mmc_claim_host(func->card->host);
  29. }
  30. EXPORT_SYMBOL_GPL(sdio_claim_host);
  31. /**
  32. * sdio_release_host - release a bus for a certain SDIO function
  33. * @func: SDIO function that was accessed
  34. *
  35. * Release a bus, allowing others to claim the bus for their
  36. * operations.
  37. */
  38. void sdio_release_host(struct sdio_func *func)
  39. {
  40. BUG_ON(!func);
  41. BUG_ON(!func->card);
  42. mmc_release_host(func->card->host);
  43. }
  44. EXPORT_SYMBOL_GPL(sdio_release_host);
  45. /**
  46. * sdio_enable_func - enables a SDIO function for usage
  47. * @func: SDIO function to enable
  48. *
  49. * Powers up and activates a SDIO function so that register
  50. * access is possible.
  51. */
  52. int sdio_enable_func(struct sdio_func *func)
  53. {
  54. int ret;
  55. unsigned char reg;
  56. unsigned long timeout;
  57. BUG_ON(!func);
  58. BUG_ON(!func->card);
  59. pr_debug("SDIO: Enabling device %s...\n", sdio_func_id(func));
  60. ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, &reg);
  61. if (ret)
  62. goto err;
  63. reg |= 1 << func->num;
  64. ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL);
  65. if (ret)
  66. goto err;
  67. timeout = jiffies + msecs_to_jiffies(func->enable_timeout);
  68. while (1) {
  69. ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IORx, 0, &reg);
  70. if (ret)
  71. goto err;
  72. if (reg & (1 << func->num))
  73. break;
  74. ret = -ETIME;
  75. if (time_after(jiffies, timeout))
  76. goto err;
  77. }
  78. pr_debug("SDIO: Enabled device %s\n", sdio_func_id(func));
  79. return 0;
  80. err:
  81. pr_debug("SDIO: Failed to enable device %s\n", sdio_func_id(func));
  82. return ret;
  83. }
  84. EXPORT_SYMBOL_GPL(sdio_enable_func);
  85. /**
  86. * sdio_disable_func - disable a SDIO function
  87. * @func: SDIO function to disable
  88. *
  89. * Powers down and deactivates a SDIO function. Register access
  90. * to this function will fail until the function is reenabled.
  91. */
  92. int sdio_disable_func(struct sdio_func *func)
  93. {
  94. int ret;
  95. unsigned char reg;
  96. BUG_ON(!func);
  97. BUG_ON(!func->card);
  98. pr_debug("SDIO: Disabling device %s...\n", sdio_func_id(func));
  99. ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, &reg);
  100. if (ret)
  101. goto err;
  102. reg &= ~(1 << func->num);
  103. ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL);
  104. if (ret)
  105. goto err;
  106. pr_debug("SDIO: Disabled device %s\n", sdio_func_id(func));
  107. return 0;
  108. err:
  109. pr_debug("SDIO: Failed to disable device %s\n", sdio_func_id(func));
  110. return -EIO;
  111. }
  112. EXPORT_SYMBOL_GPL(sdio_disable_func);
  113. /**
  114. * sdio_set_block_size - set the block size of an SDIO function
  115. * @func: SDIO function to change
  116. * @blksz: new block size or 0 to use the default.
  117. *
  118. * The default block size is the largest supported by both the function
  119. * and the host, with a maximum of 512 to ensure that arbitrarily sized
  120. * data transfer use the optimal (least) number of commands.
  121. *
  122. * A driver may call this to override the default block size set by the
  123. * core. This can be used to set a block size greater than the maximum
  124. * that reported by the card; it is the driver's responsibility to ensure
  125. * it uses a value that the card supports.
  126. *
  127. * Returns 0 on success, -EINVAL if the host does not support the
  128. * requested block size, or -EIO (etc.) if one of the resultant FBR block
  129. * size register writes failed.
  130. *
  131. */
  132. int sdio_set_block_size(struct sdio_func *func, unsigned blksz)
  133. {
  134. int ret;
  135. if (blksz > func->card->host->max_blk_size)
  136. return -EINVAL;
  137. if (blksz == 0) {
  138. blksz = min(func->max_blksize, func->card->host->max_blk_size);
  139. blksz = min(blksz, 512u);
  140. }
  141. ret = mmc_io_rw_direct(func->card, 1, 0,
  142. SDIO_FBR_BASE(func->num) + SDIO_FBR_BLKSIZE,
  143. blksz & 0xff, NULL);
  144. if (ret)
  145. return ret;
  146. ret = mmc_io_rw_direct(func->card, 1, 0,
  147. SDIO_FBR_BASE(func->num) + SDIO_FBR_BLKSIZE + 1,
  148. (blksz >> 8) & 0xff, NULL);
  149. if (ret)
  150. return ret;
  151. func->cur_blksize = blksz;
  152. return 0;
  153. }
  154. EXPORT_SYMBOL_GPL(sdio_set_block_size);
  155. /*
  156. * Calculate the maximum byte mode transfer size
  157. */
  158. static inline unsigned int sdio_max_byte_size(struct sdio_func *func)
  159. {
  160. unsigned mval = func->card->host->max_blk_size;
  161. if (mmc_blksz_for_byte_mode(func->card))
  162. mval = min(mval, func->cur_blksize);
  163. else
  164. mval = min(mval, func->max_blksize);
  165. if (mmc_card_broken_byte_mode_512(func->card))
  166. return min(mval, 511u);
  167. return min(mval, 512u); /* maximum size for byte mode */
  168. }
  169. /**
  170. * sdio_align_size - pads a transfer size to a more optimal value
  171. * @func: SDIO function
  172. * @sz: original transfer size
  173. *
  174. * Pads the original data size with a number of extra bytes in
  175. * order to avoid controller bugs and/or performance hits
  176. * (e.g. some controllers revert to PIO for certain sizes).
  177. *
  178. * If possible, it will also adjust the size so that it can be
  179. * handled in just a single request.
  180. *
  181. * Returns the improved size, which might be unmodified.
  182. */
  183. unsigned int sdio_align_size(struct sdio_func *func, unsigned int sz)
  184. {
  185. unsigned int orig_sz;
  186. unsigned int blk_sz, byte_sz;
  187. unsigned chunk_sz;
  188. orig_sz = sz;
  189. /*
  190. * Do a first check with the controller, in case it
  191. * wants to increase the size up to a point where it
  192. * might need more than one block.
  193. */
  194. sz = mmc_align_data_size(func->card, sz);
  195. /*
  196. * If we can still do this with just a byte transfer, then
  197. * we're done.
  198. */
  199. if (sz <= sdio_max_byte_size(func))
  200. return sz;
  201. if (func->card->cccr.multi_block) {
  202. /*
  203. * Check if the transfer is already block aligned
  204. */
  205. if ((sz % func->cur_blksize) == 0)
  206. return sz;
  207. /*
  208. * Realign it so that it can be done with one request,
  209. * and recheck if the controller still likes it.
  210. */
  211. blk_sz = ((sz + func->cur_blksize - 1) /
  212. func->cur_blksize) * func->cur_blksize;
  213. blk_sz = mmc_align_data_size(func->card, blk_sz);
  214. /*
  215. * This value is only good if it is still just
  216. * one request.
  217. */
  218. if ((blk_sz % func->cur_blksize) == 0)
  219. return blk_sz;
  220. /*
  221. * We failed to do one request, but at least try to
  222. * pad the remainder properly.
  223. */
  224. byte_sz = mmc_align_data_size(func->card,
  225. sz % func->cur_blksize);
  226. if (byte_sz <= sdio_max_byte_size(func)) {
  227. blk_sz = sz / func->cur_blksize;
  228. return blk_sz * func->cur_blksize + byte_sz;
  229. }
  230. } else {
  231. /*
  232. * We need multiple requests, so first check that the
  233. * controller can handle the chunk size;
  234. */
  235. chunk_sz = mmc_align_data_size(func->card,
  236. sdio_max_byte_size(func));
  237. if (chunk_sz == sdio_max_byte_size(func)) {
  238. /*
  239. * Fix up the size of the remainder (if any)
  240. */
  241. byte_sz = orig_sz % chunk_sz;
  242. if (byte_sz) {
  243. byte_sz = mmc_align_data_size(func->card,
  244. byte_sz);
  245. }
  246. return (orig_sz / chunk_sz) * chunk_sz + byte_sz;
  247. }
  248. }
  249. /*
  250. * The controller is simply incapable of transferring the size
  251. * we want in decent manner, so just return the original size.
  252. */
  253. return orig_sz;
  254. }
  255. EXPORT_SYMBOL_GPL(sdio_align_size);
  256. /* Split an arbitrarily sized data transfer into several
  257. * IO_RW_EXTENDED commands. */
  258. static int sdio_io_rw_ext_helper(struct sdio_func *func, int write,
  259. unsigned addr, int incr_addr, u8 *buf, unsigned size)
  260. {
  261. unsigned remainder = size;
  262. unsigned max_blocks;
  263. int ret;
  264. /* Do the bulk of the transfer using block mode (if supported). */
  265. if (func->card->cccr.multi_block && (size > sdio_max_byte_size(func))) {
  266. /* Blocks per command is limited by host count, host transfer
  267. * size and the maximum for IO_RW_EXTENDED of 511 blocks. */
  268. max_blocks = min(func->card->host->max_blk_count, 511u);
  269. while (remainder >= func->cur_blksize) {
  270. unsigned blocks;
  271. blocks = remainder / func->cur_blksize;
  272. if (blocks > max_blocks)
  273. blocks = max_blocks;
  274. size = blocks * func->cur_blksize;
  275. ret = mmc_io_rw_extended(func->card, write,
  276. func->num, addr, incr_addr, buf,
  277. blocks, func->cur_blksize);
  278. if (ret)
  279. return ret;
  280. remainder -= size;
  281. buf += size;
  282. if (incr_addr)
  283. addr += size;
  284. }
  285. }
  286. /* Write the remainder using byte mode. */
  287. while (remainder > 0) {
  288. size = min(remainder, sdio_max_byte_size(func));
  289. /* Indicate byte mode by setting "blocks" = 0 */
  290. ret = mmc_io_rw_extended(func->card, write, func->num, addr,
  291. incr_addr, buf, 0, size);
  292. if (ret)
  293. return ret;
  294. remainder -= size;
  295. buf += size;
  296. if (incr_addr)
  297. addr += size;
  298. }
  299. return 0;
  300. }
  301. /**
  302. * sdio_readb - read a single byte from a SDIO function
  303. * @func: SDIO function to access
  304. * @addr: address to read
  305. * @err_ret: optional status value from transfer
  306. *
  307. * Reads a single byte from the address space of a given SDIO
  308. * function. If there is a problem reading the address, 0xff
  309. * is returned and @err_ret will contain the error code.
  310. */
  311. u8 sdio_readb(struct sdio_func *func, unsigned int addr, int *err_ret)
  312. {
  313. int ret;
  314. u8 val;
  315. BUG_ON(!func);
  316. if (err_ret)
  317. *err_ret = 0;
  318. ret = mmc_io_rw_direct(func->card, 0, func->num, addr, 0, &val);
  319. if (ret) {
  320. if (err_ret)
  321. *err_ret = ret;
  322. return 0xFF;
  323. }
  324. return val;
  325. }
  326. EXPORT_SYMBOL_GPL(sdio_readb);
  327. /**
  328. * sdio_writeb - write a single byte to a SDIO function
  329. * @func: SDIO function to access
  330. * @b: byte to write
  331. * @addr: address to write to
  332. * @err_ret: optional status value from transfer
  333. *
  334. * Writes a single byte to the address space of a given SDIO
  335. * function. @err_ret will contain the status of the actual
  336. * transfer.
  337. */
  338. void sdio_writeb(struct sdio_func *func, u8 b, unsigned int addr, int *err_ret)
  339. {
  340. int ret;
  341. BUG_ON(!func);
  342. ret = mmc_io_rw_direct(func->card, 1, func->num, addr, b, NULL);
  343. if (err_ret)
  344. *err_ret = ret;
  345. }
  346. EXPORT_SYMBOL_GPL(sdio_writeb);
  347. /**
  348. * sdio_writeb_readb - write and read a byte from SDIO function
  349. * @func: SDIO function to access
  350. * @write_byte: byte to write
  351. * @addr: address to write to
  352. * @err_ret: optional status value from transfer
  353. *
  354. * Performs a RAW (Read after Write) operation as defined by SDIO spec -
  355. * single byte is written to address space of a given SDIO function and
  356. * response is read back from the same address, both using single request.
  357. * If there is a problem with the operation, 0xff is returned and
  358. * @err_ret will contain the error code.
  359. */
  360. u8 sdio_writeb_readb(struct sdio_func *func, u8 write_byte,
  361. unsigned int addr, int *err_ret)
  362. {
  363. int ret;
  364. u8 val;
  365. ret = mmc_io_rw_direct(func->card, 1, func->num, addr,
  366. write_byte, &val);
  367. if (err_ret)
  368. *err_ret = ret;
  369. if (ret)
  370. val = 0xff;
  371. return val;
  372. }
  373. EXPORT_SYMBOL_GPL(sdio_writeb_readb);
  374. /**
  375. * sdio_memcpy_fromio - read a chunk of memory from a SDIO function
  376. * @func: SDIO function to access
  377. * @dst: buffer to store the data
  378. * @addr: address to begin reading from
  379. * @count: number of bytes to read
  380. *
  381. * Reads from the address space of a given SDIO function. Return
  382. * value indicates if the transfer succeeded or not.
  383. */
  384. int sdio_memcpy_fromio(struct sdio_func *func, void *dst,
  385. unsigned int addr, int count)
  386. {
  387. return sdio_io_rw_ext_helper(func, 0, addr, 1, dst, count);
  388. }
  389. EXPORT_SYMBOL_GPL(sdio_memcpy_fromio);
  390. /**
  391. * sdio_memcpy_toio - write a chunk of memory to a SDIO function
  392. * @func: SDIO function to access
  393. * @addr: address to start writing to
  394. * @src: buffer that contains the data to write
  395. * @count: number of bytes to write
  396. *
  397. * Writes to the address space of a given SDIO function. Return
  398. * value indicates if the transfer succeeded or not.
  399. */
  400. int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr,
  401. void *src, int count)
  402. {
  403. return sdio_io_rw_ext_helper(func, 1, addr, 1, src, count);
  404. }
  405. EXPORT_SYMBOL_GPL(sdio_memcpy_toio);
  406. /**
  407. * sdio_readsb - read from a FIFO on a SDIO function
  408. * @func: SDIO function to access
  409. * @dst: buffer to store the data
  410. * @addr: address of (single byte) FIFO
  411. * @count: number of bytes to read
  412. *
  413. * Reads from the specified FIFO of a given SDIO function. Return
  414. * value indicates if the transfer succeeded or not.
  415. */
  416. int sdio_readsb(struct sdio_func *func, void *dst, unsigned int addr,
  417. int count)
  418. {
  419. return sdio_io_rw_ext_helper(func, 0, addr, 0, dst, count);
  420. }
  421. EXPORT_SYMBOL_GPL(sdio_readsb);
  422. /**
  423. * sdio_writesb - write to a FIFO of a SDIO function
  424. * @func: SDIO function to access
  425. * @addr: address of (single byte) FIFO
  426. * @src: buffer that contains the data to write
  427. * @count: number of bytes to write
  428. *
  429. * Writes to the specified FIFO of a given SDIO function. Return
  430. * value indicates if the transfer succeeded or not.
  431. */
  432. int sdio_writesb(struct sdio_func *func, unsigned int addr, void *src,
  433. int count)
  434. {
  435. return sdio_io_rw_ext_helper(func, 1, addr, 0, src, count);
  436. }
  437. EXPORT_SYMBOL_GPL(sdio_writesb);
  438. /**
  439. * sdio_readw - read a 16 bit integer from a SDIO function
  440. * @func: SDIO function to access
  441. * @addr: address to read
  442. * @err_ret: optional status value from transfer
  443. *
  444. * Reads a 16 bit integer from the address space of a given SDIO
  445. * function. If there is a problem reading the address, 0xffff
  446. * is returned and @err_ret will contain the error code.
  447. */
  448. u16 sdio_readw(struct sdio_func *func, unsigned int addr, int *err_ret)
  449. {
  450. int ret;
  451. if (err_ret)
  452. *err_ret = 0;
  453. ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 2);
  454. if (ret) {
  455. if (err_ret)
  456. *err_ret = ret;
  457. return 0xFFFF;
  458. }
  459. return le16_to_cpup((__le16 *)func->tmpbuf);
  460. }
  461. EXPORT_SYMBOL_GPL(sdio_readw);
  462. /**
  463. * sdio_writew - write a 16 bit integer to a SDIO function
  464. * @func: SDIO function to access
  465. * @b: integer to write
  466. * @addr: address to write to
  467. * @err_ret: optional status value from transfer
  468. *
  469. * Writes a 16 bit integer to the address space of a given SDIO
  470. * function. @err_ret will contain the status of the actual
  471. * transfer.
  472. */
  473. void sdio_writew(struct sdio_func *func, u16 b, unsigned int addr, int *err_ret)
  474. {
  475. int ret;
  476. *(__le16 *)func->tmpbuf = cpu_to_le16(b);
  477. ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 2);
  478. if (err_ret)
  479. *err_ret = ret;
  480. }
  481. EXPORT_SYMBOL_GPL(sdio_writew);
  482. /**
  483. * sdio_readl - read a 32 bit integer from a SDIO function
  484. * @func: SDIO function to access
  485. * @addr: address to read
  486. * @err_ret: optional status value from transfer
  487. *
  488. * Reads a 32 bit integer from the address space of a given SDIO
  489. * function. If there is a problem reading the address,
  490. * 0xffffffff is returned and @err_ret will contain the error
  491. * code.
  492. */
  493. u32 sdio_readl(struct sdio_func *func, unsigned int addr, int *err_ret)
  494. {
  495. int ret;
  496. if (err_ret)
  497. *err_ret = 0;
  498. ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 4);
  499. if (ret) {
  500. if (err_ret)
  501. *err_ret = ret;
  502. return 0xFFFFFFFF;
  503. }
  504. return le32_to_cpup((__le32 *)func->tmpbuf);
  505. }
  506. EXPORT_SYMBOL_GPL(sdio_readl);
  507. /**
  508. * sdio_writel - write a 32 bit integer to a SDIO function
  509. * @func: SDIO function to access
  510. * @b: integer to write
  511. * @addr: address to write to
  512. * @err_ret: optional status value from transfer
  513. *
  514. * Writes a 32 bit integer to the address space of a given SDIO
  515. * function. @err_ret will contain the status of the actual
  516. * transfer.
  517. */
  518. void sdio_writel(struct sdio_func *func, u32 b, unsigned int addr, int *err_ret)
  519. {
  520. int ret;
  521. *(__le32 *)func->tmpbuf = cpu_to_le32(b);
  522. ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 4);
  523. if (err_ret)
  524. *err_ret = ret;
  525. }
  526. EXPORT_SYMBOL_GPL(sdio_writel);
  527. /**
  528. * sdio_f0_readb - read a single byte from SDIO function 0
  529. * @func: an SDIO function of the card
  530. * @addr: address to read
  531. * @err_ret: optional status value from transfer
  532. *
  533. * Reads a single byte from the address space of SDIO function 0.
  534. * If there is a problem reading the address, 0xff is returned
  535. * and @err_ret will contain the error code.
  536. */
  537. unsigned char sdio_f0_readb(struct sdio_func *func, unsigned int addr,
  538. int *err_ret)
  539. {
  540. int ret;
  541. unsigned char val;
  542. BUG_ON(!func);
  543. if (err_ret)
  544. *err_ret = 0;
  545. ret = mmc_io_rw_direct(func->card, 0, 0, addr, 0, &val);
  546. if (ret) {
  547. if (err_ret)
  548. *err_ret = ret;
  549. return 0xFF;
  550. }
  551. return val;
  552. }
  553. EXPORT_SYMBOL_GPL(sdio_f0_readb);
  554. /**
  555. * sdio_f0_writeb - write a single byte to SDIO function 0
  556. * @func: an SDIO function of the card
  557. * @b: byte to write
  558. * @addr: address to write to
  559. * @err_ret: optional status value from transfer
  560. *
  561. * Writes a single byte to the address space of SDIO function 0.
  562. * @err_ret will contain the status of the actual transfer.
  563. *
  564. * Only writes to the vendor specific CCCR registers (0xF0 -
  565. * 0xFF) are permiited; @err_ret will be set to -EINVAL for *
  566. * writes outside this range.
  567. */
  568. void sdio_f0_writeb(struct sdio_func *func, unsigned char b, unsigned int addr,
  569. int *err_ret)
  570. {
  571. int ret;
  572. BUG_ON(!func);
  573. if ((addr < 0xF0 || addr > 0xFF) && (!mmc_card_lenient_fn0(func->card))) {
  574. if (err_ret)
  575. *err_ret = -EINVAL;
  576. return;
  577. }
  578. ret = mmc_io_rw_direct(func->card, 1, 0, addr, b, NULL);
  579. if (err_ret)
  580. *err_ret = ret;
  581. }
  582. EXPORT_SYMBOL_GPL(sdio_f0_writeb);
  583. /**
  584. * sdio_get_host_pm_caps - get host power management capabilities
  585. * @func: SDIO function attached to host
  586. *
  587. * Returns a capability bitmask corresponding to power management
  588. * features supported by the host controller that the card function
  589. * might rely upon during a system suspend. The host doesn't need
  590. * to be claimed, nor the function active, for this information to be
  591. * obtained.
  592. */
  593. mmc_pm_flag_t sdio_get_host_pm_caps(struct sdio_func *func)
  594. {
  595. BUG_ON(!func);
  596. BUG_ON(!func->card);
  597. return func->card->host->pm_caps;
  598. }
  599. EXPORT_SYMBOL_GPL(sdio_get_host_pm_caps);
  600. /**
  601. * sdio_set_host_pm_flags - set wanted host power management capabilities
  602. * @func: SDIO function attached to host
  603. *
  604. * Set a capability bitmask corresponding to wanted host controller
  605. * power management features for the upcoming suspend state.
  606. * This must be called, if needed, each time the suspend method of
  607. * the function driver is called, and must contain only bits that
  608. * were returned by sdio_get_host_pm_caps().
  609. * The host doesn't need to be claimed, nor the function active,
  610. * for this information to be set.
  611. */
  612. int sdio_set_host_pm_flags(struct sdio_func *func, mmc_pm_flag_t flags)
  613. {
  614. struct mmc_host *host;
  615. BUG_ON(!func);
  616. BUG_ON(!func->card);
  617. host = func->card->host;
  618. if (flags & ~host->pm_caps)
  619. return -EINVAL;
  620. /* function suspend methods are serialized, hence no lock needed */
  621. host->pm_flags |= flags;
  622. return 0;
  623. }
  624. EXPORT_SYMBOL_GPL(sdio_set_host_pm_flags);