Skip to content

Commit bec8726

Browse files
girishkscjb
authored andcommitted
mmc: core: Add Power Off Notify Feature eMMC 4.5
This patch adds support for the power off notify feature, available in eMMC 4.5 devices. If the host has support for this feature, then the mmc core will notify the device by setting the POWER_OFF_NOTIFICATION byte in the extended csd register with a value of 1 (POWER_ON). For suspend mode short timeout is used, whereas for the normal poweroff long timeout is used. Signed-off-by: Girish K S <girish.shivananjappa@linaro.org> Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com> Signed-off-by: Chris Ball <cjb@laptop.org>
1 parent 326adda commit bec8726

6 files changed

Lines changed: 81 additions & 2 deletions

File tree

‎drivers/mmc/core/core.c‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,11 +1212,43 @@ static void mmc_power_up(struct mmc_host *host)
12121212

12131213
void mmc_power_off(struct mmc_host *host)
12141214
{
1215+
struct mmc_card *card;
1216+
unsigned int notify_type;
1217+
unsigned int timeout;
1218+
int err;
1219+
12151220
mmc_host_clk_hold(host);
12161221

1222+
card = host->card;
12171223
host->ios.clock = 0;
12181224
host->ios.vdd = 0;
12191225

1226+
if (card && mmc_card_mmc(card) &&
1227+
(card->poweroff_notify_state == MMC_POWERED_ON)) {
1228+
1229+
if (host->power_notify_type == MMC_HOST_PW_NOTIFY_SHORT) {
1230+
notify_type = EXT_CSD_POWER_OFF_SHORT;
1231+
timeout = card->ext_csd.generic_cmd6_time;
1232+
card->poweroff_notify_state = MMC_POWEROFF_SHORT;
1233+
} else {
1234+
notify_type = EXT_CSD_POWER_OFF_LONG;
1235+
timeout = card->ext_csd.power_off_longtime;
1236+
card->poweroff_notify_state = MMC_POWEROFF_LONG;
1237+
}
1238+
1239+
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1240+
EXT_CSD_POWER_OFF_NOTIFICATION,
1241+
notify_type, timeout);
1242+
1243+
if (err && err != -EBADMSG)
1244+
pr_err("Device failed to respond within %d poweroff "
1245+
"time. Forcefully powering down the device\n",
1246+
timeout);
1247+
1248+
/* Set the card state to no notification after the poweroff */
1249+
card->poweroff_notify_state = MMC_NO_POWER_NOTIFICATION;
1250+
}
1251+
12201252
/*
12211253
* Reset ocr mask to be the highest possible voltage supported for
12221254
* this mmc host. This value will be used at next power up.
@@ -2208,6 +2240,7 @@ int mmc_pm_notify(struct notifier_block *notify_block,
22082240

22092241
spin_lock_irqsave(&host->lock, flags);
22102242
host->rescan_disable = 1;
2243+
host->power_notify_type = MMC_HOST_PW_NOTIFY_SHORT;
22112244
spin_unlock_irqrestore(&host->lock, flags);
22122245
cancel_delayed_work_sync(&host->detect);
22132246

@@ -2231,6 +2264,7 @@ int mmc_pm_notify(struct notifier_block *notify_block,
22312264

22322265
spin_lock_irqsave(&host->lock, flags);
22332266
host->rescan_disable = 0;
2267+
host->power_notify_type = MMC_HOST_PW_NOTIFY_LONG;
22342268
spin_unlock_irqrestore(&host->lock, flags);
22352269
mmc_detect_change(host, 0);
22362270

‎drivers/mmc/core/mmc.c‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,12 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
458458
else
459459
card->erased_byte = 0x0;
460460

461-
if (card->ext_csd.rev >= 6)
461+
if (card->ext_csd.rev >= 6) {
462462
card->ext_csd.generic_cmd6_time = 10 *
463463
ext_csd[EXT_CSD_GENERIC_CMD6_TIME];
464-
else
464+
card->ext_csd.power_off_longtime = 10 *
465+
ext_csd[EXT_CSD_POWER_OFF_LONG_TIME];
466+
} else
465467
card->ext_csd.generic_cmd6_time = 0;
466468

467469
out:
@@ -845,6 +847,23 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
845847
goto free_card;
846848
}
847849

850+
/*
851+
* If the host supports the power_off_notify capability then
852+
* set the notification byte in the ext_csd register of device
853+
*/
854+
if ((host->caps2 & MMC_CAP2_POWEROFF_NOTIFY) &&
855+
(card->poweroff_notify_state == MMC_NO_POWER_NOTIFICATION)) {
856+
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
857+
EXT_CSD_POWER_OFF_NOTIFICATION,
858+
EXT_CSD_POWER_ON,
859+
card->ext_csd.generic_cmd6_time);
860+
if (err && err != -EBADMSG)
861+
goto free_card;
862+
}
863+
864+
if (!err)
865+
card->poweroff_notify_state = MMC_POWERED_ON;
866+
848867
/*
849868
* Activate high speed (if supported)
850869
*/

‎drivers/mmc/host/sdhci.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2739,6 +2739,15 @@ int sdhci_add_host(struct sdhci_host *host)
27392739
if (caps[1] & SDHCI_DRIVER_TYPE_D)
27402740
mmc->caps |= MMC_CAP_DRIVER_TYPE_D;
27412741

2742+
/*
2743+
* If Power Off Notify capability is enabled by the host,
2744+
* set notify to short power off notify timeout value.
2745+
*/
2746+
if (mmc->caps2 & MMC_CAP2_POWEROFF_NOTIFY)
2747+
mmc->power_notify_type = MMC_HOST_PW_NOTIFY_SHORT;
2748+
else
2749+
mmc->power_notify_type = MMC_HOST_PW_NOTIFY_NONE;
2750+
27422751
/* Initial value for re-tuning timer count */
27432752
host->tuning_count = (caps[1] & SDHCI_RETUNING_TIMER_COUNT_MASK) >>
27442753
SDHCI_RETUNING_TIMER_COUNT_SHIFT;

‎include/linux/mmc/card.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct mmc_ext_csd {
5555
unsigned int part_time; /* Units: ms */
5656
unsigned int sa_timeout; /* Units: 100ns */
5757
unsigned int generic_cmd6_time; /* Units: 10ms */
58+
unsigned int power_off_longtime; /* Units: ms */
5859
unsigned int hs_max_dtr;
5960
unsigned int sectors;
6061
unsigned int card_type;
@@ -209,6 +210,11 @@ struct mmc_card {
209210
#define MMC_QUIRK_BLK_NO_CMD23 (1<<7) /* Avoid CMD23 for regular multiblock */
210211
#define MMC_QUIRK_BROKEN_BYTE_MODE_512 (1<<8) /* Avoid sending 512 bytes in */
211212
/* byte mode */
213+
unsigned int poweroff_notify_state; /* eMMC4.5 notify feature */
214+
#define MMC_NO_POWER_NOTIFICATION 0
215+
#define MMC_POWERED_ON 1
216+
#define MMC_POWEROFF_SHORT 2
217+
#define MMC_POWEROFF_LONG 3
212218

213219
unsigned int erase_size; /* erase size in sectors */
214220
unsigned int erase_shift; /* if erase unit is power 2 */

‎include/linux/mmc/host.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,13 @@ struct mmc_host {
239239
unsigned int caps2; /* More host capabilities */
240240

241241
#define MMC_CAP2_BOOTPART_NOACC (1 << 0) /* Boot partition no access */
242+
#define MMC_CAP2_POWEROFF_NOTIFY (1 << 2) /* Notify poweroff supported */
242243

243244
mmc_pm_flag_t pm_caps; /* supported pm features */
245+
unsigned int power_notify_type;
246+
#define MMC_HOST_PW_NOTIFY_NONE 0
247+
#define MMC_HOST_PW_NOTIFY_SHORT 1
248+
#define MMC_HOST_PW_NOTIFY_LONG 2
244249

245250
#ifdef CONFIG_MMC_CLKGATE
246251
int clk_requests; /* internal reference counter */

‎include/linux/mmc/mmc.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ struct _mmc_csd {
270270
* EXT_CSD fields
271271
*/
272272

273+
#define EXT_CSD_POWER_OFF_NOTIFICATION 34 /* R/W */
273274
#define EXT_CSD_GP_SIZE_MULT 143 /* R/W */
274275
#define EXT_CSD_PARTITION_ATTRIBUTE 156 /* R/W */
275276
#define EXT_CSD_PARTITION_SUPPORT 160 /* RO */
@@ -346,6 +347,11 @@ struct _mmc_csd {
346347
#define EXT_CSD_RST_N_EN_MASK 0x3
347348
#define EXT_CSD_RST_N_ENABLED 1 /* RST_n is enabled on card */
348349

350+
#define EXT_CSD_NO_POWER_NOTIFICATION 0
351+
#define EXT_CSD_POWER_ON 1
352+
#define EXT_CSD_POWER_OFF_SHORT 2
353+
#define EXT_CSD_POWER_OFF_LONG 3
354+
349355
#define EXT_CSD_PWR_CL_8BIT_MASK 0xF0 /* 8 bit PWR CLS */
350356
#define EXT_CSD_PWR_CL_4BIT_MASK 0x0F /* 8 bit PWR CLS */
351357
#define EXT_CSD_PWR_CL_8BIT_SHIFT 4

0 commit comments

Comments
 (0)