blob: 4ad06e575634d8ee09367caf0e62748e8bf2251d [file] [log] [blame]
Pierre Ossman46f555f2007-05-27 12:57:15 +02001/*
2 * linux/drivers/mmc/core/sdio_io.c
3 *
4 * Copyright 2007 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_func.h>
15
16#include "sdio_ops.h"
17
18/**
19 * sdio_claim_host - exclusively claim a bus for a certain SDIO function
20 * @func: SDIO function that will be accessed
21 *
22 * Claim a bus for a set of operations. The SDIO function given
23 * is used to figure out which bus is relevant.
24 */
25void sdio_claim_host(struct sdio_func *func)
26{
27 BUG_ON(!func);
28 BUG_ON(!func->card);
29
30 mmc_claim_host(func->card->host);
31}
32EXPORT_SYMBOL_GPL(sdio_claim_host);
33
34/**
35 * sdio_release_host - release a bus for a certain SDIO function
36 * @func: SDIO function that was accessed
37 *
38 * Release a bus, allowing others to claim the bus for their
39 * operations.
40 */
41void sdio_release_host(struct sdio_func *func)
42{
43 BUG_ON(!func);
44 BUG_ON(!func->card);
45
46 mmc_release_host(func->card->host);
47}
48EXPORT_SYMBOL_GPL(sdio_release_host);
49
50/**
51 * sdio_readb - read a single byte from a SDIO function
52 * @func: SDIO function to access
53 * @addr: address to read
54 * @err_ret: optional status value from transfer
55 *
56 * Reads a single byte from the address space of a given SDIO
57 * function. If there is a problem reading the address, 0xff
58 * is returned and @err_ret will contain the error code.
59 */
60unsigned char sdio_readb(struct sdio_func *func, unsigned int addr,
61 int *err_ret)
62{
63 int ret;
64 unsigned char val;
65
66 BUG_ON(!func);
67
68 if (err_ret)
69 *err_ret = 0;
70
71 ret = mmc_io_rw_direct(func->card, 0, func->num, addr, 0, &val);
72 if (ret) {
73 if (err_ret)
74 *err_ret = ret;
75 return 0xFF;
76 }
77
78 return val;
79}
80EXPORT_SYMBOL_GPL(sdio_readb);
81
82/**
83 * sdio_writeb - write a single byte to a SDIO function
84 * @func: SDIO function to access
85 * @b: byte to write
86 * @addr: address to write to
87 * @err_ret: optional status value from transfer
88 *
89 * Writes a single byte to the address space of a given SDIO
90 * function. @err_ret will contain the status of the actual
91 * transfer.
92 */
93void sdio_writeb(struct sdio_func *func, unsigned char b, unsigned int addr,
94 int *err_ret)
95{
96 int ret;
97
98 BUG_ON(!func);
99
100 ret = mmc_io_rw_direct(func->card, 1, func->num, addr, b, NULL);
101 if (err_ret)
102 *err_ret = ret;
103}
104EXPORT_SYMBOL_GPL(sdio_writeb);
105