sdio_io.c 18 KB

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