2 * linux/drivers/mmc/core/sdio_io.c
4 * Copyright 2007 Pierre Ossman
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.
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>
20 * sdio_claim_host - exclusively claim a bus for a certain SDIO function
21 * @func: SDIO function that will be accessed
23 * Claim a bus for a set of operations. The SDIO function given
24 * is used to figure out which bus is relevant.
26 void sdio_claim_host(struct sdio_func
*func
)
31 mmc_claim_host(func
->card
->host
);
33 EXPORT_SYMBOL_GPL(sdio_claim_host
);
36 * sdio_release_host - release a bus for a certain SDIO function
37 * @func: SDIO function that was accessed
39 * Release a bus, allowing others to claim the bus for their
42 void sdio_release_host(struct sdio_func
*func
)
47 mmc_release_host(func
->card
->host
);
49 EXPORT_SYMBOL_GPL(sdio_release_host
);
52 * sdio_enable_func - enables a SDIO function for usage
53 * @func: SDIO function to enable
55 * Powers up and activates a SDIO function so that register
58 int sdio_enable_func(struct sdio_func
*func
)
62 unsigned long timeout
;
67 pr_debug("SDIO: Enabling device %s...\n", sdio_func_id(func
));
69 ret
= mmc_io_rw_direct(func
->card
, 0, 0, SDIO_CCCR_IOEx
, 0, ®
);
73 reg
|= 1 << func
->num
;
75 ret
= mmc_io_rw_direct(func
->card
, 1, 0, SDIO_CCCR_IOEx
, reg
, NULL
);
80 * FIXME: This should timeout based on information in the CIS,
81 * but we don't have card to parse that yet.
83 timeout
= jiffies
+ HZ
;
86 ret
= mmc_io_rw_direct(func
->card
, 0, 0, SDIO_CCCR_IORx
, 0, ®
);
89 if (reg
& (1 << func
->num
))
92 if (time_after(jiffies
, timeout
))
96 pr_debug("SDIO: Enabled device %s\n", sdio_func_id(func
));
101 pr_debug("SDIO: Failed to enable device %s\n", sdio_func_id(func
));
104 EXPORT_SYMBOL_GPL(sdio_enable_func
);
107 * sdio_disable_func - disable a SDIO function
108 * @func: SDIO function to disable
110 * Powers down and deactivates a SDIO function. Register access
111 * to this function will fail until the function is reenabled.
113 int sdio_disable_func(struct sdio_func
*func
)
121 pr_debug("SDIO: Disabling device %s...\n", sdio_func_id(func
));
123 ret
= mmc_io_rw_direct(func
->card
, 0, 0, SDIO_CCCR_IOEx
, 0, ®
);
127 reg
&= ~(1 << func
->num
);
129 ret
= mmc_io_rw_direct(func
->card
, 1, 0, SDIO_CCCR_IOEx
, reg
, NULL
);
133 pr_debug("SDIO: Disabled device %s\n", sdio_func_id(func
));
138 pr_debug("SDIO: Failed to disable device %s\n", sdio_func_id(func
));
141 EXPORT_SYMBOL_GPL(sdio_disable_func
);
144 * sdio_readb - read a single byte from a SDIO function
145 * @func: SDIO function to access
146 * @addr: address to read
147 * @err_ret: optional status value from transfer
149 * Reads a single byte from the address space of a given SDIO
150 * function. If there is a problem reading the address, 0xff
151 * is returned and @err_ret will contain the error code.
153 unsigned char sdio_readb(struct sdio_func
*func
, unsigned int addr
,
164 ret
= mmc_io_rw_direct(func
->card
, 0, func
->num
, addr
, 0, &val
);
173 EXPORT_SYMBOL_GPL(sdio_readb
);
176 * sdio_writeb - write a single byte to a SDIO function
177 * @func: SDIO function to access
179 * @addr: address to write to
180 * @err_ret: optional status value from transfer
182 * Writes a single byte to the address space of a given SDIO
183 * function. @err_ret will contain the status of the actual
186 void sdio_writeb(struct sdio_func
*func
, unsigned char b
, unsigned int addr
,
193 ret
= mmc_io_rw_direct(func
->card
, 1, func
->num
, addr
, b
, NULL
);
197 EXPORT_SYMBOL_GPL(sdio_writeb
);