sdio_io.c 19 KB

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