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