Skip to content

Commit fa64efa

Browse files
author
Pierre Ossman
committed
mmc: enable/disable functions for SDIO
Like many other buses, the devices (functions) on the SDIO bus must be enabled before they can be used. Add functions that allow drivers to do so. Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
1 parent 46f555f commit fa64efa

3 files changed

Lines changed: 188 additions & 0 deletions

File tree

‎drivers/mmc/core/sdio_io.c‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <linux/mmc/host.h>
1313
#include <linux/mmc/card.h>
14+
#include <linux/mmc/sdio.h>
1415
#include <linux/mmc/sdio_func.h>
1516

1617
#include "sdio_ops.h"
@@ -47,6 +48,98 @@ void sdio_release_host(struct sdio_func *func)
4748
}
4849
EXPORT_SYMBOL_GPL(sdio_release_host);
4950

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+
/*
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+
100+
err:
101+
pr_debug("SDIO: Failed to enable device %s\n", sdio_func_id(func));
102+
return ret;
103+
}
104+
EXPORT_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+
*/
113+
int 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+
137+
err:
138+
pr_debug("SDIO: Failed to disable device %s\n", sdio_func_id(func));
139+
return -EIO;
140+
}
141+
EXPORT_SYMBOL_GPL(sdio_disable_func);
142+
50143
/**
51144
* sdio_readb - read a single byte from a SDIO function
52145
* @func: SDIO function to access

‎include/linux/mmc/sdio.h‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,97 @@
4949
#define R5_STATUS(x) (x & 0xCB00)
5050
#define R5_IO_CURRENT_STATE(x) ((x & 0x3000) >> 12) /* s, b */
5151

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+
52144
#endif
53145

‎include/linux/mmc/sdio_func.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ extern void sdio_unregister_driver(struct sdio_driver *);
5555
extern void sdio_claim_host(struct sdio_func *func);
5656
extern void sdio_release_host(struct sdio_func *func);
5757

58+
extern int sdio_enable_func(struct sdio_func *func);
59+
extern int sdio_disable_func(struct sdio_func *func);
60+
5861
extern unsigned char sdio_readb(struct sdio_func *func,
5962
unsigned int addr, int *err_ret);
6063

0 commit comments

Comments
 (0)