sdio_io.c 18 KB

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