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