sdio_io.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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. if (WARN_ON(!func))
  27. return;
  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. if (WARN_ON(!func))
  41. return;
  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. if (!func)
  58. return -EINVAL;
  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. if (!func)
  97. return -EINVAL;
  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. if (!func || (func->num > 7))
  265. return -EINVAL;
  266. /* Do the bulk of the transfer using block mode (if supported). */
  267. if (func->card->cccr.multi_block && (size > sdio_max_byte_size(func))) {
  268. /* Blocks per command is limited by host count, host transfer
  269. * size and the maximum for IO_RW_EXTENDED of 511 blocks. */
  270. max_blocks = min(func->card->host->max_blk_count, 511u);
  271. while (remainder >= func->cur_blksize) {
  272. unsigned blocks;
  273. blocks = remainder / func->cur_blksize;
  274. if (blocks > max_blocks)
  275. blocks = max_blocks;
  276. size = blocks * func->cur_blksize;
  277. ret = mmc_io_rw_extended(func->card, write,
  278. func->num, addr, incr_addr, buf,
  279. blocks, func->cur_blksize);
  280. if (ret)
  281. return ret;
  282. remainder -= size;
  283. buf += size;
  284. if (incr_addr)
  285. addr += size;
  286. }
  287. }
  288. /* Write the remainder using byte mode. */
  289. while (remainder > 0) {
  290. size = min(remainder, sdio_max_byte_size(func));
  291. /* Indicate byte mode by setting "blocks" = 0 */
  292. ret = mmc_io_rw_extended(func->card, write, func->num, addr,
  293. incr_addr, buf, 0, size);
  294. if (ret)
  295. return ret;
  296. remainder -= size;
  297. buf += size;
  298. if (incr_addr)
  299. addr += size;
  300. }
  301. return 0;
  302. }
  303. /**
  304. * sdio_readb - read a single byte from a SDIO function
  305. * @func: SDIO function to access
  306. * @addr: address to read
  307. * @err_ret: optional status value from transfer
  308. *
  309. * Reads a single byte from the address space of a given SDIO
  310. * function. If there is a problem reading the address, 0xff
  311. * is returned and @err_ret will contain the error code.
  312. */
  313. u8 sdio_readb(struct sdio_func *func, unsigned int addr, int *err_ret)
  314. {
  315. int ret;
  316. u8 val;
  317. if (!func) {
  318. *err_ret = -EINVAL;
  319. return 0xFF;
  320. }
  321. if (err_ret)
  322. *err_ret = 0;
  323. ret = mmc_io_rw_direct(func->card, 0, func->num, addr, 0, &val);
  324. if (ret) {
  325. if (err_ret)
  326. *err_ret = ret;
  327. return 0xFF;
  328. }
  329. return val;
  330. }
  331. EXPORT_SYMBOL_GPL(sdio_readb);
  332. /**
  333. * sdio_writeb - write a single byte to a SDIO function
  334. * @func: SDIO function to access
  335. * @b: byte to write
  336. * @addr: address to write to
  337. * @err_ret: optional status value from transfer
  338. *
  339. * Writes a single byte to the address space of a given SDIO
  340. * function. @err_ret will contain the status of the actual
  341. * transfer.
  342. */
  343. void sdio_writeb(struct sdio_func *func, u8 b, unsigned int addr, int *err_ret)
  344. {
  345. int ret;
  346. if (!func) {
  347. *err_ret = -EINVAL;
  348. return;
  349. }
  350. ret = mmc_io_rw_direct(func->card, 1, func->num, addr, b, NULL);
  351. if (err_ret)
  352. *err_ret = ret;
  353. }
  354. EXPORT_SYMBOL_GPL(sdio_writeb);
  355. /**
  356. * sdio_writeb_readb - write and read a byte from SDIO function
  357. * @func: SDIO function to access
  358. * @write_byte: byte to write
  359. * @addr: address to write to
  360. * @err_ret: optional status value from transfer
  361. *
  362. * Performs a RAW (Read after Write) operation as defined by SDIO spec -
  363. * single byte is written to address space of a given SDIO function and
  364. * response is read back from the same address, both using single request.
  365. * If there is a problem with the operation, 0xff is returned and
  366. * @err_ret will contain the error code.
  367. */
  368. u8 sdio_writeb_readb(struct sdio_func *func, u8 write_byte,
  369. unsigned int addr, int *err_ret)
  370. {
  371. int ret;
  372. u8 val;
  373. ret = mmc_io_rw_direct(func->card, 1, func->num, addr,
  374. write_byte, &val);
  375. if (err_ret)
  376. *err_ret = ret;
  377. if (ret)
  378. val = 0xff;
  379. return val;
  380. }
  381. EXPORT_SYMBOL_GPL(sdio_writeb_readb);
  382. /**
  383. * sdio_memcpy_fromio - read a chunk of memory from a SDIO function
  384. * @func: SDIO function to access
  385. * @dst: buffer to store the data
  386. * @addr: address to begin reading from
  387. * @count: number of bytes to read
  388. *
  389. * Reads from the address space of a given SDIO function. Return
  390. * value indicates if the transfer succeeded or not.
  391. */
  392. int sdio_memcpy_fromio(struct sdio_func *func, void *dst,
  393. unsigned int addr, int count)
  394. {
  395. return sdio_io_rw_ext_helper(func, 0, addr, 1, dst, count);
  396. }
  397. EXPORT_SYMBOL_GPL(sdio_memcpy_fromio);
  398. /**
  399. * sdio_memcpy_toio - write a chunk of memory to a SDIO function
  400. * @func: SDIO function to access
  401. * @addr: address to start writing to
  402. * @src: buffer that contains the data to write
  403. * @count: number of bytes to write
  404. *
  405. * Writes to the address space of a given SDIO function. Return
  406. * value indicates if the transfer succeeded or not.
  407. */
  408. int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr,
  409. void *src, int count)
  410. {
  411. return sdio_io_rw_ext_helper(func, 1, addr, 1, src, count);
  412. }
  413. EXPORT_SYMBOL_GPL(sdio_memcpy_toio);
  414. /**
  415. * sdio_readsb - read from a FIFO on a SDIO function
  416. * @func: SDIO function to access
  417. * @dst: buffer to store the data
  418. * @addr: address of (single byte) FIFO
  419. * @count: number of bytes to read
  420. *
  421. * Reads from the specified FIFO of a given SDIO function. Return
  422. * value indicates if the transfer succeeded or not.
  423. */
  424. int sdio_readsb(struct sdio_func *func, void *dst, unsigned int addr,
  425. int count)
  426. {
  427. return sdio_io_rw_ext_helper(func, 0, addr, 0, dst, count);
  428. }
  429. EXPORT_SYMBOL_GPL(sdio_readsb);
  430. /**
  431. * sdio_writesb - write to a FIFO of a SDIO function
  432. * @func: SDIO function to access
  433. * @addr: address of (single byte) FIFO
  434. * @src: buffer that contains the data to write
  435. * @count: number of bytes to write
  436. *
  437. * Writes to the specified FIFO of a given SDIO function. Return
  438. * value indicates if the transfer succeeded or not.
  439. */
  440. int sdio_writesb(struct sdio_func *func, unsigned int addr, void *src,
  441. int count)
  442. {
  443. return sdio_io_rw_ext_helper(func, 1, addr, 0, src, count);
  444. }
  445. EXPORT_SYMBOL_GPL(sdio_writesb);
  446. /**
  447. * sdio_readw - read a 16 bit integer from a SDIO function
  448. * @func: SDIO function to access
  449. * @addr: address to read
  450. * @err_ret: optional status value from transfer
  451. *
  452. * Reads a 16 bit integer from the address space of a given SDIO
  453. * function. If there is a problem reading the address, 0xffff
  454. * is returned and @err_ret will contain the error code.
  455. */
  456. u16 sdio_readw(struct sdio_func *func, unsigned int addr, int *err_ret)
  457. {
  458. int ret;
  459. if (err_ret)
  460. *err_ret = 0;
  461. ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 2);
  462. if (ret) {
  463. if (err_ret)
  464. *err_ret = ret;
  465. return 0xFFFF;
  466. }
  467. return le16_to_cpup((__le16 *)func->tmpbuf);
  468. }
  469. EXPORT_SYMBOL_GPL(sdio_readw);
  470. /**
  471. * sdio_writew - write a 16 bit integer to a SDIO function
  472. * @func: SDIO function to access
  473. * @b: integer to write
  474. * @addr: address to write to
  475. * @err_ret: optional status value from transfer
  476. *
  477. * Writes a 16 bit integer to the address space of a given SDIO
  478. * function. @err_ret will contain the status of the actual
  479. * transfer.
  480. */
  481. void sdio_writew(struct sdio_func *func, u16 b, unsigned int addr, int *err_ret)
  482. {
  483. int ret;
  484. *(__le16 *)func->tmpbuf = cpu_to_le16(b);
  485. ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 2);
  486. if (err_ret)
  487. *err_ret = ret;
  488. }
  489. EXPORT_SYMBOL_GPL(sdio_writew);
  490. /**
  491. * sdio_readl - read a 32 bit integer from a SDIO function
  492. * @func: SDIO function to access
  493. * @addr: address to read
  494. * @err_ret: optional status value from transfer
  495. *
  496. * Reads a 32 bit integer from the address space of a given SDIO
  497. * function. If there is a problem reading the address,
  498. * 0xffffffff is returned and @err_ret will contain the error
  499. * code.
  500. */
  501. u32 sdio_readl(struct sdio_func *func, unsigned int addr, int *err_ret)
  502. {
  503. int ret;
  504. if (err_ret)
  505. *err_ret = 0;
  506. ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 4);
  507. if (ret) {
  508. if (err_ret)
  509. *err_ret = ret;
  510. return 0xFFFFFFFF;
  511. }
  512. return le32_to_cpup((__le32 *)func->tmpbuf);
  513. }
  514. EXPORT_SYMBOL_GPL(sdio_readl);
  515. /**
  516. * sdio_writel - write a 32 bit integer to a SDIO function
  517. * @func: SDIO function to access
  518. * @b: integer to write
  519. * @addr: address to write to
  520. * @err_ret: optional status value from transfer
  521. *
  522. * Writes a 32 bit integer to the address space of a given SDIO
  523. * function. @err_ret will contain the status of the actual
  524. * transfer.
  525. */
  526. void sdio_writel(struct sdio_func *func, u32 b, unsigned int addr, int *err_ret)
  527. {
  528. int ret;
  529. *(__le32 *)func->tmpbuf = cpu_to_le32(b);
  530. ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 4);
  531. if (err_ret)
  532. *err_ret = ret;
  533. }
  534. EXPORT_SYMBOL_GPL(sdio_writel);
  535. /**
  536. * sdio_f0_readb - read a single byte from SDIO function 0
  537. * @func: an SDIO function of the card
  538. * @addr: address to read
  539. * @err_ret: optional status value from transfer
  540. *
  541. * Reads a single byte from the address space of SDIO function 0.
  542. * If there is a problem reading the address, 0xff is returned
  543. * and @err_ret will contain the error code.
  544. */
  545. unsigned char sdio_f0_readb(struct sdio_func *func, unsigned int addr,
  546. int *err_ret)
  547. {
  548. int ret;
  549. unsigned char val;
  550. if (!func) {
  551. *err_ret = -EINVAL;
  552. return 0xFF;
  553. }
  554. if (err_ret)
  555. *err_ret = 0;
  556. ret = mmc_io_rw_direct(func->card, 0, 0, addr, 0, &val);
  557. if (ret) {
  558. if (err_ret)
  559. *err_ret = ret;
  560. return 0xFF;
  561. }
  562. return val;
  563. }
  564. EXPORT_SYMBOL_GPL(sdio_f0_readb);
  565. /**
  566. * sdio_f0_writeb - write a single byte to SDIO function 0
  567. * @func: an SDIO function of the card
  568. * @b: byte to write
  569. * @addr: address to write to
  570. * @err_ret: optional status value from transfer
  571. *
  572. * Writes a single byte to the address space of SDIO function 0.
  573. * @err_ret will contain the status of the actual transfer.
  574. *
  575. * Only writes to the vendor specific CCCR registers (0xF0 -
  576. * 0xFF) are permiited; @err_ret will be set to -EINVAL for *
  577. * writes outside this range.
  578. */
  579. void sdio_f0_writeb(struct sdio_func *func, unsigned char b, unsigned int addr,
  580. int *err_ret)
  581. {
  582. int ret;
  583. if (!func) {
  584. *err_ret = -EINVAL;
  585. return;
  586. }
  587. if ((addr < 0xF0 || addr > 0xFF) && (!mmc_card_lenient_fn0(func->card))) {
  588. if (err_ret)
  589. *err_ret = -EINVAL;
  590. return;
  591. }
  592. ret = mmc_io_rw_direct(func->card, 1, 0, addr, b, NULL);
  593. if (err_ret)
  594. *err_ret = ret;
  595. }
  596. EXPORT_SYMBOL_GPL(sdio_f0_writeb);
  597. /**
  598. * sdio_get_host_pm_caps - get host power management capabilities
  599. * @func: SDIO function attached to host
  600. *
  601. * Returns a capability bitmask corresponding to power management
  602. * features supported by the host controller that the card function
  603. * might rely upon during a system suspend. The host doesn't need
  604. * to be claimed, nor the function active, for this information to be
  605. * obtained.
  606. */
  607. mmc_pm_flag_t sdio_get_host_pm_caps(struct sdio_func *func)
  608. {
  609. if (!func)
  610. return 0;
  611. return func->card->host->pm_caps;
  612. }
  613. EXPORT_SYMBOL_GPL(sdio_get_host_pm_caps);
  614. /**
  615. * sdio_set_host_pm_flags - set wanted host power management capabilities
  616. * @func: SDIO function attached to host
  617. *
  618. * Set a capability bitmask corresponding to wanted host controller
  619. * power management features for the upcoming suspend state.
  620. * This must be called, if needed, each time the suspend method of
  621. * the function driver is called, and must contain only bits that
  622. * were returned by sdio_get_host_pm_caps().
  623. * The host doesn't need to be claimed, nor the function active,
  624. * for this information to be set.
  625. */
  626. int sdio_set_host_pm_flags(struct sdio_func *func, mmc_pm_flag_t flags)
  627. {
  628. struct mmc_host *host;
  629. if (!func)
  630. return -EINVAL;
  631. host = func->card->host;
  632. if (flags & ~host->pm_caps)
  633. return -EINVAL;
  634. /* function suspend methods are serialized, hence no lock needed */
  635. host->pm_flags |= flags;
  636. return 0;
  637. }
  638. EXPORT_SYMBOL_GPL(sdio_set_host_pm_flags);