aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/mmc/core/sdio_io.c93
-rw-r--r--include/linux/mmc/sdio.h92
-rw-r--r--include/linux/mmc/sdio_func.h3
3 files changed, 188 insertions, 0 deletions
diff --git a/drivers/mmc/core/sdio_io.c b/drivers/mmc/core/sdio_io.c
index 4ad06e575634..eb6c20935cef 100644
--- a/drivers/mmc/core/sdio_io.c
+++ b/drivers/mmc/core/sdio_io.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/mmc/host.h> 12#include <linux/mmc/host.h>
13#include <linux/mmc/card.h> 13#include <linux/mmc/card.h>
14#include <linux/mmc/sdio.h>
14#include <linux/mmc/sdio_func.h> 15#include <linux/mmc/sdio_func.h>
15 16
16#include "sdio_ops.h" 17#include "sdio_ops.h"
@@ -48,6 +49,98 @@ void sdio_release_host(struct sdio_func *func)
48EXPORT_SYMBOL_GPL(sdio_release_host); 49EXPORT_SYMBOL_GPL(sdio_release_host);
49 50
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 */
58int 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 /*
80 * FIXME: This should timeout based on information in the CIS,
81 * but we don't have card to parse that yet.
82 */
83 timeout = jiffies + HZ;
84
85 while (1) {
86 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IORx, 0, &reg);
87 if (ret)
88 goto err;
89 if (reg & (1 << func->num))
90 break;
91 ret = -ETIME;
92 if (time_after(jiffies, timeout))
93 goto err;
94 }
95
96 pr_debug("SDIO: Enabled device %s\n", sdio_func_id(func));
97
98 return 0;
99
100err:
101 pr_debug("SDIO: Failed to enable device %s\n", sdio_func_id(func));
102 return ret;
103}
104EXPORT_SYMBOL_GPL(sdio_enable_func);
105
106/**
107 * sdio_disable_func - disable a SDIO function
108 * @func: SDIO function to disable
109 *
110 * Powers down and deactivates a SDIO function. Register access
111 * to this function will fail until the function is reenabled.
112 */
113int sdio_disable_func(struct sdio_func *func)
114{
115 int ret;
116 unsigned char reg;
117
118 BUG_ON(!func);
119 BUG_ON(!func->card);
120
121 pr_debug("SDIO: Disabling device %s...\n", sdio_func_id(func));
122
123 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, &reg);
124 if (ret)
125 goto err;
126
127 reg &= ~(1 << func->num);
128
129 ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL);
130 if (ret)
131 goto err;
132
133 pr_debug("SDIO: Disabled device %s\n", sdio_func_id(func));
134
135 return 0;
136
137err:
138 pr_debug("SDIO: Failed to disable device %s\n", sdio_func_id(func));
139 return -EIO;
140}
141EXPORT_SYMBOL_GPL(sdio_disable_func);
142
143/**
51 * sdio_readb - read a single byte from a SDIO function 144 * sdio_readb - read a single byte from a SDIO function
52 * @func: SDIO function to access 145 * @func: SDIO function to access
53 * @addr: address to read 146 * @addr: address to read
diff --git a/include/linux/mmc/sdio.h b/include/linux/mmc/sdio.h
index e5f06de7d527..56239f4aab04 100644
--- a/include/linux/mmc/sdio.h
+++ b/include/linux/mmc/sdio.h
@@ -49,5 +49,97 @@
49#define R5_STATUS(x) (x & 0xCB00) 49#define R5_STATUS(x) (x & 0xCB00)
50#define R5_IO_CURRENT_STATE(x) ((x & 0x3000) >> 12) /* s, b */ 50#define R5_IO_CURRENT_STATE(x) ((x & 0x3000) >> 12) /* s, b */
51 51
52/*
53 * Card Common Control Registers (CCCR)
54 */
55
56#define SDIO_CCCR_CCCR 0x00
57
58#define SDIO_CCCR_REV_1_00 0 /* CCCR/FBR Version 1.00 */
59#define SDIO_CCCR_REV_1_10 1 /* CCCR/FBR Version 1.10 */
60#define SDIO_CCCR_REV_1_20 2 /* CCCR/FBR Version 1.20 */
61
62#define SDIO_SDIO_REV_1_00 0 /* SDIO Spec Version 1.00 */
63#define SDIO_SDIO_REV_1_10 1 /* SDIO Spec Version 1.10 */
64#define SDIO_SDIO_REV_1_20 2 /* SDIO Spec Version 1.20 */
65#define SDIO_SDIO_REV_2_00 3 /* SDIO Spec Version 2.00 */
66
67#define SDIO_CCCR_SD 0x01
68
69#define SDIO_SD_REV_1_01 0 /* SD Physical Spec Version 1.01 */
70#define SDIO_SD_REV_1_10 1 /* SD Physical Spec Version 1.10 */
71#define SDIO_SD_REV_2_00 2 /* SD Physical Spec Version 2.00 */
72
73#define SDIO_CCCR_IOEx 0x02
74#define SDIO_CCCR_IORx 0x03
75
76#define SDIO_CCCR_IENx 0x04 /* Function/Master Interrupt Enable */
77#define SDIO_CCCR_INTx 0x05 /* Function Interrupt Pending */
78
79#define SDIO_CCCR_ABORT 0x06 /* function abort/card reset */
80
81#define SDIO_CCCR_IF 0x07 /* bus interface controls */
82
83#define SDIO_BUS_WIDTH_1BIT 0x00
84#define SDIO_BUS_WIDTH_4BIT 0x02
85
86#define SDIO_BUS_CD_DISABLE 0x80 /* disable pull-up on DAT3 (pin 1) */
87
88#define SDIO_CCCR_CAPS 0x08
89
90#define SDIO_CCCR_CAP_SDC 0x01 /* can do CMD52 while data transfer */
91#define SDIO_CCCR_CAP_SMB 0x02 /* can do multi-block xfers (CMD53) */
92#define SDIO_CCCR_CAP_SRW 0x04 /* supports read-wait protocol */
93#define SDIO_CCCR_CAP_SBS 0x08 /* supports suspend/resume */
94#define SDIO_CCCR_CAP_S4MI 0x10 /* interrupt during 4-bit CMD53 */
95#define SDIO_CCCR_CAP_E4MI 0x20 /* enable ints during 4-bit CMD53 */
96#define SDIO_CCCR_CAP_LSC 0x40 /* low speed card */
97#define SDIO_CCCR_CAP_4BLS 0x80 /* 4 bit low speed card */
98
99#define SDIO_CCCR_CIS 0x09 /* common CIS pointer (3 bytes) */
100
101/* Following 4 regs are valid only if SBS is set */
102#define SDIO_CCCR_SUSPEND 0x0c
103#define SDIO_CCCR_SELx 0x0d
104#define SDIO_CCCR_EXECx 0x0e
105#define SDIO_CCCR_READYx 0x0f
106
107#define SDIO_CCCR_BLKSIZE 0x10
108
109#define SDIO_CCCR_POWER 0x12
110
111#define SDIO_POWER_SMPC 0x01 /* Supports Master Power Control */
112#define SDIO_POWER_EMPC 0x02 /* Enable Master Power Control */
113
114#define SDIO_CCCR_SPEED 0x13
115
116#define SDIO_SPEED_SHS 0x01 /* Supports High-Speed mode */
117#define SDIO_SPEED_EHS 0x02 /* Enable High-Speed mode */
118
119/*
120 * Function Basic Registers (FBR)
121 */
122
123#define SDIO_FBR_STD_IF 0x00
124
125#define SDIO_FBR_SUPPORTS_CSA 0x40 /* supports Code Storage Area */
126#define SDIO_FBR_ENABLE_CSA 0x80 /* enable Code Storage Area */
127
128#define SDIO_FBR_STD_IF_EXT 0x01
129
130#define SDIO_FBR_POWER 0x02
131
132#define SDIO_FBR_POWER_SPS 0x01 /* Supports Power Selection */
133#define SDIO_FBR_POWER_EPS 0x02 /* Enable (low) Power Selection */
134
135#define SDIO_FBR_CIS 0x09 /* CIS pointer (3 bytes) */
136
137
138#define SDIO_FBR_CSA 0x0C /* CSA pointer (3 bytes) */
139
140#define SDIO_FBR_CSA_DATA 0x0F
141
142#define SDIO_FBR_BLKSIZE 0x10 /* block size (2 bytes) */
143
52#endif 144#endif
53 145
diff --git a/include/linux/mmc/sdio_func.h b/include/linux/mmc/sdio_func.h
index 5c56df196287..3365fef5f713 100644
--- a/include/linux/mmc/sdio_func.h
+++ b/include/linux/mmc/sdio_func.h
@@ -55,6 +55,9 @@ extern void sdio_unregister_driver(struct sdio_driver *);
55extern void sdio_claim_host(struct sdio_func *func); 55extern void sdio_claim_host(struct sdio_func *func);
56extern void sdio_release_host(struct sdio_func *func); 56extern void sdio_release_host(struct sdio_func *func);
57 57
58extern int sdio_enable_func(struct sdio_func *func);
59extern int sdio_disable_func(struct sdio_func *func);
60
58extern unsigned char sdio_readb(struct sdio_func *func, 61extern unsigned char sdio_readb(struct sdio_func *func,
59 unsigned int addr, int *err_ret); 62 unsigned int addr, int *err_ret);
60 63