Skip to content

Commit b249951

Browse files
ahunter6cjb
authored andcommitted
mmc: core: add eMMC hardware reset support
eMMC's may have a hardware reset line. This patch provides a host controller operation to implement hardware reset and a function to reset and reinitialize the card. Also, for MMC, the reset is always performed before initialization. The host must set the new host capability MMC_CAP_HW_RESET to enable hardware reset. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Signed-off-by: Chris Ball <cjb@laptop.org>
1 parent 8e3336b commit b249951

6 files changed

Lines changed: 107 additions & 1 deletion

File tree

‎drivers/mmc/core/core.c‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,94 @@ int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen)
17761776
}
17771777
EXPORT_SYMBOL(mmc_set_blocklen);
17781778

1779+
static void mmc_hw_reset_for_init(struct mmc_host *host)
1780+
{
1781+
if (!(host->caps & MMC_CAP_HW_RESET) || !host->ops->hw_reset)
1782+
return;
1783+
mmc_host_clk_hold(host);
1784+
host->ops->hw_reset(host);
1785+
mmc_host_clk_release(host);
1786+
}
1787+
1788+
int mmc_can_reset(struct mmc_card *card)
1789+
{
1790+
u8 rst_n_function;
1791+
1792+
if (!mmc_card_mmc(card))
1793+
return 0;
1794+
rst_n_function = card->ext_csd.rst_n_function;
1795+
if ((rst_n_function & EXT_CSD_RST_N_EN_MASK) != EXT_CSD_RST_N_ENABLED)
1796+
return 0;
1797+
return 1;
1798+
}
1799+
EXPORT_SYMBOL(mmc_can_reset);
1800+
1801+
static int mmc_do_hw_reset(struct mmc_host *host, int check)
1802+
{
1803+
struct mmc_card *card = host->card;
1804+
1805+
if (!host->bus_ops->power_restore)
1806+
return -EOPNOTSUPP;
1807+
1808+
if (!(host->caps & MMC_CAP_HW_RESET) || !host->ops->hw_reset)
1809+
return -EOPNOTSUPP;
1810+
1811+
if (!card)
1812+
return -EINVAL;
1813+
1814+
if (!mmc_can_reset(card))
1815+
return -EOPNOTSUPP;
1816+
1817+
mmc_host_clk_hold(host);
1818+
mmc_set_clock(host, host->f_init);
1819+
1820+
host->ops->hw_reset(host);
1821+
1822+
/* If the reset has happened, then a status command will fail */
1823+
if (check) {
1824+
struct mmc_command cmd = {0};
1825+
int err;
1826+
1827+
cmd.opcode = MMC_SEND_STATUS;
1828+
if (!mmc_host_is_spi(card->host))
1829+
cmd.arg = card->rca << 16;
1830+
cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
1831+
err = mmc_wait_for_cmd(card->host, &cmd, 0);
1832+
if (!err) {
1833+
mmc_host_clk_release(host);
1834+
return -ENOSYS;
1835+
}
1836+
}
1837+
1838+
host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_DDR);
1839+
if (mmc_host_is_spi(host)) {
1840+
host->ios.chip_select = MMC_CS_HIGH;
1841+
host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
1842+
} else {
1843+
host->ios.chip_select = MMC_CS_DONTCARE;
1844+
host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
1845+
}
1846+
host->ios.bus_width = MMC_BUS_WIDTH_1;
1847+
host->ios.timing = MMC_TIMING_LEGACY;
1848+
mmc_set_ios(host);
1849+
1850+
mmc_host_clk_release(host);
1851+
1852+
return host->bus_ops->power_restore(host);
1853+
}
1854+
1855+
int mmc_hw_reset(struct mmc_host *host)
1856+
{
1857+
return mmc_do_hw_reset(host, 0);
1858+
}
1859+
EXPORT_SYMBOL(mmc_hw_reset);
1860+
1861+
int mmc_hw_reset_check(struct mmc_host *host)
1862+
{
1863+
return mmc_do_hw_reset(host, 1);
1864+
}
1865+
EXPORT_SYMBOL(mmc_hw_reset_check);
1866+
17791867
static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
17801868
{
17811869
host->f_init = freq;
@@ -1786,6 +1874,12 @@ static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
17861874
#endif
17871875
mmc_power_up(host);
17881876

1877+
/*
1878+
* Some eMMCs (with VCCQ always on) may not be reset after power up, so
1879+
* do a hardware reset if possible.
1880+
*/
1881+
mmc_hw_reset_for_init(host);
1882+
17891883
/*
17901884
* sdio_reset sends CMD52 to reset card. Since we do not know
17911885
* if the card is being re-initialized, just send it. CMD52

‎drivers/mmc/core/mmc.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,10 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
402402
ext_csd[EXT_CSD_TRIM_MULT];
403403
}
404404

405-
if (card->ext_csd.rev >= 5)
405+
if (card->ext_csd.rev >= 5) {
406406
card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM];
407+
card->ext_csd.rst_n_function = ext_csd[EXT_CSD_RST_N_FUNCTION];
408+
}
407409

408410
if (ext_csd[EXT_CSD_ERASED_MEM_CONT])
409411
card->erased_byte = 0xFF;

‎include/linux/mmc/card.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct mmc_ext_csd {
5050
u8 rel_sectors;
5151
u8 rel_param;
5252
u8 part_config;
53+
u8 rst_n_function;
5354
unsigned int part_time; /* Units: ms */
5455
unsigned int sa_timeout; /* Units: 100ns */
5556
unsigned int hs_max_dtr;

‎include/linux/mmc/core.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ extern int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
162162
extern unsigned int mmc_calc_max_discard(struct mmc_card *card);
163163

164164
extern int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen);
165+
extern int mmc_hw_reset(struct mmc_host *host);
166+
extern int mmc_hw_reset_check(struct mmc_host *host);
167+
extern int mmc_can_reset(struct mmc_card *card);
165168

166169
extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *);
167170
extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int);

‎include/linux/mmc/host.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ struct mmc_host_ops {
151151
int (*execute_tuning)(struct mmc_host *host);
152152
void (*enable_preset_value)(struct mmc_host *host, bool enable);
153153
int (*select_drive_strength)(unsigned int max_dtr, int host_drv, int card_drv);
154+
void (*hw_reset)(struct mmc_host *host);
154155
};
155156

156157
struct mmc_card;
@@ -233,6 +234,7 @@ struct mmc_host {
233234
#define MMC_CAP_MAX_CURRENT_600 (1 << 28) /* Host max current limit is 600mA */
234235
#define MMC_CAP_MAX_CURRENT_800 (1 << 29) /* Host max current limit is 800mA */
235236
#define MMC_CAP_CMD23 (1 << 30) /* CMD23 supported. */
237+
#define MMC_CAP_HW_RESET (1 << 31) /* Hardware reset */
236238

237239
mmc_pm_flag_t pm_caps; /* supported pm features */
238240

‎include/linux/mmc/mmc.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ struct _mmc_csd {
272272

273273
#define EXT_CSD_PARTITION_ATTRIBUTE 156 /* R/W */
274274
#define EXT_CSD_PARTITION_SUPPORT 160 /* RO */
275+
#define EXT_CSD_RST_N_FUNCTION 162 /* R/W */
275276
#define EXT_CSD_WR_REL_PARAM 166 /* RO */
276277
#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */
277278
#define EXT_CSD_PART_CONFIG 179 /* R/W */
@@ -328,6 +329,9 @@ struct _mmc_csd {
328329
#define EXT_CSD_SEC_BD_BLK_EN BIT(2)
329330
#define EXT_CSD_SEC_GB_CL_EN BIT(4)
330331

332+
#define EXT_CSD_RST_N_EN_MASK 0x3
333+
#define EXT_CSD_RST_N_ENABLED 1 /* RST_n is enabled on card */
334+
331335
/*
332336
* MMC_SWITCH access modes
333337
*/

0 commit comments

Comments
 (0)