sdio_io.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  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 = min(func->card->host->max_seg_size,
  161. func->card->host->max_blk_size);
  162. if (mmc_blksz_for_byte_mode(func->card))
  163. mval = min(mval, func->cur_blksize);
  164. else
  165. mval = min(mval, func->max_blksize);
  166. if (mmc_card_broken_byte_mode_512(func->card))
  167. return min(mval, 511u);
  168. return min(mval, 512u); /* maximum size for byte mode */
  169. }
  170. /**
  171. * sdio_align_size - pads a transfer size to a more optimal value
  172. * @func: SDIO function
  173. * @sz: original transfer size
  174. *
  175. * Pads the original data size with a number of extra bytes in
  176. * order to avoid controller bugs and/or performance hits
  177. * (e.g. some controllers revert to PIO for certain sizes).
  178. *
  179. * If possible, it will also adjust the size so that it can be
  180. * handled in just a single request.
  181. *
  182. * Returns the improved size, which might be unmodified.
  183. */
  184. unsigned int sdio_align_size(struct sdio_func *func, unsigned int sz)
  185. {
  186. unsigned int orig_sz;
  187. unsigned int blk_sz, byte_sz;
  188. unsigned chunk_sz;
  189. orig_sz = sz;
  190. /*
  191. * Do a first check with the controller, in case it
  192. * wants to increase the size up to a point where it
  193. * might need more than one block.
  194. */
  195. sz = mmc_align_data_size(func->card, sz);
  196. /*
  197. * If we can still do this with just a byte transfer, then
  198. * we're done.
  199. */
  200. if (sz <= sdio_max_byte_size(func))
  201. return sz;
  202. if (func->card->cccr.multi_block) {
  203. /*
  204. * Check if the transfer is already block aligned
  205. */
  206. if ((sz % func->cur_blksize) == 0)
  207. return sz;
  208. /*
  209. * Realign it so that it can be done with one request,
  210. * and recheck if the controller still likes it.
  211. */
  212. blk_sz = ((sz + func->cur_blksize - 1) /
  213. func->cur_blksize) * func->cur_blksize;
  214. blk_sz = mmc_align_data_size(func->card, blk_sz);
  215. /*
  216. * This value is only good if it is still just
  217. * one request.
  218. */
  219. if ((blk_sz % func->cur_blksize) == 0)
  220. return blk_sz;
  221. /*
  222. * We failed to do one request, but at least try to
  223. * pad the remainder properly.
  224. */
  225. byte_sz = mmc_align_data_size(func->card,
  226. sz % func->cur_blksize);
  227. if (byte_sz <= sdio_max_byte_size(func)) {
  228. blk_sz = sz / func->cur_blksize;
  229. return blk_sz * func->cur_blksize + byte_sz;
  230. }
  231. } else {
  232. /*
  233. * We need multiple requests, so first check that the
  234. * controller can handle the chunk size;
  235. */
  236. chunk_sz = mmc_align_data_size(func->card,
  237. sdio_max_byte_size(func));
  238. if (chunk_sz == sdio_max_byte_size(func)) {
  239. /*
  240. * Fix up the size of the remainder (if any)
  241. */
  242. byte_sz = orig_sz % chunk_sz;
  243. if (byte_sz) {
  244. byte_sz = mmc_align_data_size(func->card,
  245. byte_sz);
  246. }
  247. return (orig_sz / chunk_sz) * chunk_sz + byte_sz;
  248. }
  249. }
  250. /*
  251. * The controller is simply incapable of transferring the size
  252. * we want in decent manner, so just return the original size.
  253. */
  254. return orig_sz;
  255. }
  256. EXPORT_SYMBOL_GPL(sdio_align_size);
  257. /* Split an arbitrarily sized data transfer into several
  258. * IO_RW_EXTENDED commands. */
  259. static int sdio_io_rw_ext_helper(struct sdio_func *func, int write,
  260. unsigned addr, int incr_addr, u8 *buf, unsigned size)
  261. {
  262. unsigned remainder = size;
  263. unsigned max_blocks;
  264. int ret;
  265. /* Do the bulk of the transfer using block mode (if supported). */
  266. if (func->card->cccr.multi_block && (size > sdio_max_byte_size(func))) {
  267. /* Blocks per command is limited by host count, host transfer
  268. * size (we only use a single sg entry) and the maximum for
  269. * IO_RW_EXTENDED of 511 blocks. */
  270. max_blocks = min(func->card->host->max_blk_count,
  271. func->card->host->max_seg_size / func->cur_blksize);
  272. max_blocks = min(max_blocks, 511u);
  273. while (remainder >= func->cur_blksize) {
  274. unsigned blocks;
  275. blocks = remainder / func->cur_blksize;
  276. if (blocks > max_blocks)
  277. blocks = max_blocks;
  278. size = blocks * func->cur_blksize;
  279. ret = mmc_io_rw_extended(func->card, write,
  280. func->num, addr, incr_addr, buf,
  281. blocks, func->cur_blksize);
  282. if (ret)
  283. return ret;
  284. remainder -= size;
  285. buf += size;
  286. if (incr_addr)
  287. addr += size;
  288. }
  289. }
  290. /* Write the remainder using byte mode. */
  291. while (remainder > 0) {
  292. size = min(remainder, sdio_max_byte_size(func));
  293. /* Indicate byte mode by setting "blocks" = 0 */
  294. ret = mmc_io_rw_extended(func->card, write, func->num, addr,
  295. incr_addr, buf, 0, size);
  296. if (ret)
  297. return ret;
  298. remainder -= size;
  299. buf += size;
  300. if (incr_addr)
  301. addr += size;
  302. }
  303. return 0;
  304. }
  305. /**
  306. * sdio_readb - read a single byte from a SDIO function
  307. * @func: SDIO function to access
  308. * @addr: address to read
  309. * @err_ret: optional status value from transfer
  310. *
  311. * Reads a single byte from the address space of a given SDIO
  312. * function. If there is a problem reading the address, 0xff
  313. * is returned and @err_ret will contain the error code.
  314. */
  315. u8 sdio_readb(struct sdio_func *func, unsigned int addr, int *err_ret)
  316. {
  317. int ret;
  318. u8 val;
  319. BUG_ON(!func);
  320. if (err_ret)
  321. *err_ret = 0;
  322. ret = mmc_io_rw_direct(func->card, 0, func->num, addr, 0, &val);
  323. if (ret) {
  324. if (err_ret)
  325. *err_ret = ret;
  326. return 0xFF;
  327. }
  328. return val;
  329. }
  330. EXPORT_SYMBOL_GPL(sdio_readb);
  331. /**
  332. * sdio_writeb - write a single byte to a SDIO function
  333. * @func: SDIO function to access
  334. * @b: byte to write
  335. * @addr: address to write to
  336. * @err_ret: optional status value from transfer
  337. *
  338. * Writes a single byte to the address space of a given SDIO
  339. * function. @err_ret will contain the status of the actual
  340. * transfer.
  341. */
  342. void sdio_writeb(struct sdio_func *func, u8 b, unsigned int addr, int *err_ret)
  343. {
  344. int ret;
  345. BUG_ON(!func);
  346. ret = mmc_io_rw_direct(func->card, 1, func->num, addr, b, NULL);
  347. if (err_ret)
  348. *err_ret = ret;
  349. }
  350. EXPORT_SYMBOL_GPL(sdio_writeb);
  351. /**
  352. * sdio_writeb_readb - write and read a byte from SDIO function
  353. * @func: SDIO function to access
  354. * @write_byte: byte to write
  355. * @addr: address to write to
  356. * @err_ret: optional status value from transfer
  357. *
  358. * Performs a RAW (Read after Write) operation as defined by SDIO spec -
  359. * single byte is written to address space of a given SDIO function and
  360. * response is read back from the same address, both using single request.
  361. * If there is a problem with the operation, 0xff is returned and
  362. * @err_ret will contain the error code.
  363. */
  364. u8 sdio_writeb_readb(struct sdio_func *func, u8 write_byte,
  365. unsigned int addr, int *err_ret)
  366. {
  367. int ret;
  368. u8 val;
  369. ret = mmc_io_rw_direct(func->card, 1, func->num, addr,
  370. write_byte, &val);
  371. if (err_ret)
  372. *err_ret = ret;
  373. if (ret)
  374. val = 0xff;
  375. return val;
  376. }
  377. EXPORT_SYMBOL_GPL(sdio_writeb_readb);
  378. /**
  379. * sdio_memcpy_fromio - read a chunk of memory from a SDIO function
  380. * @func: SDIO function to access
  381. * @dst: buffer to store the data
  382. * @addr: address to begin reading from
  383. * @count: number of bytes to read
  384. *
  385. * Reads from the address space of a given SDIO function. Return
  386. * value indicates if the transfer succeeded or not.
  387. */
  388. int sdio_memcpy_fromio(struct sdio_func *func, void *dst,
  389. unsigned int addr, int count)
  390. {
  391. return sdio_io_rw_ext_helper(func, 0, addr, 1, dst, count);
  392. }
  393. EXPORT_SYMBOL_GPL(sdio_memcpy_fromio);
  394. /**
  395. * sdio_memcpy_toio - write a chunk of memory to a SDIO function
  396. * @func: SDIO function to access
  397. * @addr: address to start writing to
  398. * @src: buffer that contains the data to write
  399. * @count: number of bytes to write
  400. *
  401. * Writes to the address space of a given SDIO function. Return
  402. * value indicates if the transfer succeeded or not.
  403. */
  404. int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr,
  405. void *src, int count)
  406. {
  407. return sdio_io_rw_ext_helper(func, 1, addr, 1, src, count);
  408. }
  409. EXPORT_SYMBOL_GPL(sdio_memcpy_toio);
  410. /**
  411. * sdio_readsb - read from a FIFO on a SDIO function
  412. * @func: SDIO function to access
  413. * @dst: buffer to store the data
  414. * @addr: address of (single byte) FIFO
  415. * @count: number of bytes to read
  416. *
  417. * Reads from the specified FIFO of a given SDIO function. Return
  418. * value indicates if the transfer succeeded or not.
  419. */
  420. int sdio_readsb(struct sdio_func *func, void *dst, unsigned int addr,
  421. int count)
  422. {
  423. return sdio_io_rw_ext_helper(func, 0, addr, 0, dst, count);
  424. }
  425. EXPORT_SYMBOL_GPL(sdio_readsb);
  426. /**
  427. * sdio_writesb - write to a FIFO of a SDIO function
  428. * @func: SDIO function to access
  429. * @addr: address of (single byte) FIFO
  430. * @src: buffer that contains the data to write
  431. * @count: number of bytes to write
  432. *
  433. * Writes to the specified FIFO of a given SDIO function. Return
  434. * value indicates if the transfer succeeded or not.
  435. */
  436. int sdio_writesb(struct sdio_func *func, unsigned int addr, void *src,
  437. int count)
  438. {
  439. return sdio_io_rw_ext_helper(func, 1, addr, 0, src, count);
  440. }
  441. EXPORT_SYMBOL_GPL(sdio_writesb);
  442. /**
  443. * sdio_readw - read a 16 bit integer from a SDIO function
  444. * @func: SDIO function to access
  445. * @addr: address to read
  446. * @err_ret: optional status value from transfer
  447. *
  448. * Reads a 16 bit integer from the address space of a given SDIO
  449. * function. If there is a problem reading the address, 0xffff
  450. * is returned and @err_ret will contain the error code.
  451. */
  452. u16 sdio_readw(struct sdio_func *func, unsigned int addr, int *err_ret)
  453. {
  454. int ret;
  455. if (err_ret)
  456. *err_ret = 0;
  457. ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 2);
  458. if (ret) {
  459. if (err_ret)
  460. *err_ret = ret;
  461. return 0xFFFF;
  462. }
  463. return le16_to_cpup((__le16 *)func->tmpbuf);
  464. }
  465. EXPORT_SYMBOL_GPL(sdio_readw);
  466. /**
  467. * sdio_writew - write a 16 bit integer to a SDIO function
  468. * @func: SDIO function to access
  469. * @b: integer to write
  470. * @addr: address to write to
  471. * @err_ret: optional status value from transfer
  472. *
  473. * Writes a 16 bit integer to the address space of a given SDIO
  474. * function. @err_ret will contain the status of the actual
  475. * transfer.
  476. */
  477. void sdio_writew(struct sdio_func *func, u16 b, unsigned int addr, int *err_ret)
  478. {
  479. int ret;
  480. *(__le16 *)func->tmpbuf = cpu_to_le16(b);
  481. ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 2);
  482. if (err_ret)
  483. *err_ret = ret;
  484. }
  485. EXPORT_SYMBOL_GPL(sdio_writew);
  486. /**
  487. * sdio_readl - read a 32 bit integer from a SDIO function
  488. * @func: SDIO function to access
  489. * @addr: address to read
  490. * @err_ret: optional status value from transfer
  491. *
  492. * Reads a 32 bit integer from the address space of a given SDIO
  493. * function. If there is a problem reading the address,
  494. * 0xffffffff is returned and @err_ret will contain the error
  495. * code.
  496. */
  497. u32 sdio_readl(struct sdio_func *func, unsigned int addr, int *err_ret)
  498. {
  499. int ret;
  500. if (err_ret)
  501. *err_ret = 0;
  502. ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 4);
  503. if (ret) {
  504. if (err_ret)
  505. *err_ret = ret;
  506. return 0xFFFFFFFF;
  507. }
  508. return le32_to_cpup((__le32 *)func->tmpbuf);
  509. }
  510. EXPORT_SYMBOL_GPL(sdio_readl);
  511. /**
  512. * sdio_writel - write a 32 bit integer to a SDIO function
  513. * @func: SDIO function to access
  514. * @b: integer to write
  515. * @addr: address to write to
  516. * @err_ret: optional status value from transfer
  517. *
  518. * Writes a 32 bit integer to the address space of a given SDIO
  519. * function. @err_ret will contain the status of the actual
  520. * transfer.
  521. */
  522. void sdio_writel(struct sdio_func *func, u32 b, unsigned int addr, int *err_ret)
  523. {
  524. int ret;
  525. *(__le32 *)func->tmpbuf = cpu_to_le32(b);
  526. ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 4);
  527. if (err_ret)
  528. *err_ret = ret;
  529. }
  530. EXPORT_SYMBOL_GPL(sdio_writel);
  531. /**
  532. * sdio_f0_readb - read a single byte from SDIO function 0
  533. * @func: an SDIO function of the card
  534. * @addr: address to read
  535. * @err_ret: optional status value from transfer
  536. *
  537. * Reads a single byte from the address space of SDIO function 0.
  538. * If there is a problem reading the address, 0xff is returned
  539. * and @err_ret will contain the error code.
  540. */
  541. unsigned char sdio_f0_readb(struct sdio_func *func, unsigned int addr,
  542. int *err_ret)
  543. {
  544. int ret;
  545. unsigned char val;
  546. BUG_ON(!func);
  547. if (err_ret)
  548. *err_ret = 0;
  549. ret = mmc_io_rw_direct(func->card, 0, 0, addr, 0, &val);
  550. if (ret) {
  551. if (err_ret)
  552. *err_ret = ret;
  553. return 0xFF;
  554. }
  555. return val;
  556. }
  557. EXPORT_SYMBOL_GPL(sdio_f0_readb);
  558. /**
  559. * sdio_f0_writeb - write a single byte to SDIO function 0
  560. * @func: an SDIO function of the card
  561. * @b: byte to write
  562. * @addr: address to write to
  563. * @err_ret: optional status value from transfer
  564. *
  565. * Writes a single byte to the address space of SDIO function 0.
  566. * @err_ret will contain the status of the actual transfer.
  567. *
  568. * Only writes to the vendor specific CCCR registers (0xF0 -
  569. * 0xFF) are permiited; @err_ret will be set to -EINVAL for *
  570. * writes outside this range.
  571. */
  572. void sdio_f0_writeb(struct sdio_func *func, unsigned char b, unsigned int addr,
  573. int *err_ret)
  574. {
  575. int ret;
  576. BUG_ON(!func);
  577. if ((addr < 0xF0 || addr > 0xFF) && (!mmc_card_lenient_fn0(func->card))) {
  578. if (err_ret)
  579. *err_ret = -EINVAL;
  580. return;
  581. }
  582. ret = mmc_io_rw_direct(func->card, 1, 0, addr, b, NULL);
  583. if (err_ret)
  584. *err_ret = ret;
  585. }
  586. EXPORT_SYMBOL_GPL(sdio_f0_writeb);
  587. /**
  588. * sdio_get_host_pm_caps - get host power management capabilities
  589. * @func: SDIO function attached to host
  590. *
  591. * Returns a capability bitmask corresponding to power management
  592. * features supported by the host controller that the card function
  593. * might rely upon during a system suspend. The host doesn't need
  594. * to be claimed, nor the function active, for this information to be
  595. * obtained.
  596. */
  597. mmc_pm_flag_t sdio_get_host_pm_caps(struct sdio_func *func)
  598. {
  599. BUG_ON(!func);
  600. BUG_ON(!func->card);
  601. return func->card->host->pm_caps;
  602. }
  603. EXPORT_SYMBOL_GPL(sdio_get_host_pm_caps);
  604. /**
  605. * sdio_set_host_pm_flags - set wanted host power management capabilities
  606. * @func: SDIO function attached to host
  607. *
  608. * Set a capability bitmask corresponding to wanted host controller
  609. * power management features for the upcoming suspend state.
  610. * This must be called, if needed, each time the suspend method of
  611. * the function driver is called, and must contain only bits that
  612. * were returned by sdio_get_host_pm_caps().
  613. * The host doesn't need to be claimed, nor the function active,
  614. * for this information to be set.
  615. */
  616. int sdio_set_host_pm_flags(struct sdio_func *func, mmc_pm_flag_t flags)
  617. {
  618. struct mmc_host *host;
  619. BUG_ON(!func);
  620. BUG_ON(!func->card);
  621. host = func->card->host;
  622. if (flags & ~host->pm_caps)
  623. return -EINVAL;
  624. /* function suspend methods are serialized, hence no lock needed */
  625. host->pm_flags |= flags;
  626. return 0;
  627. }
  628. EXPORT_SYMBOL_GPL(sdio_set_host_pm_flags);