]> rtime.felk.cvut.cz Git - linux-imx.git/commitdiff
mmc: core: Add cache control for eMMC4.5 device
authorSeungwon Jeon <tgih.jun@samsung.com>
Fri, 14 Oct 2011 05:03:21 +0000 (14:03 +0900)
committerChris Ball <cjb@laptop.org>
Wed, 26 Oct 2011 20:32:28 +0000 (16:32 -0400)
This patch adds cache feature of eMMC4.5 Spec.
If device supports cache capability, host can utilize some specific
operations.

Signed-off-by: Seungwon Jeon <tgih.jun@samsung.com>
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Chris Ball <cjb@laptop.org>
drivers/mmc/card/block.c
drivers/mmc/core/core.c
drivers/mmc/core/mmc.c
include/linux/mmc/card.h
include/linux/mmc/core.h
include/linux/mmc/host.h
include/linux/mmc/mmc.h

index 370472797ffffc766a07f0d5f04d3a05b42c48b6..c0cb225bbb4734171322be462f86d4d5f725216e 100644 (file)
@@ -851,16 +851,18 @@ out:
 static int mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req)
 {
        struct mmc_blk_data *md = mq->data;
+       struct mmc_card *card = md->queue.card;
+       int ret = 0;
+
+       ret = mmc_flush_cache(card);
+       if (ret)
+               ret = -EIO;
 
-       /*
-        * No-op, only service this because we need REQ_FUA for reliable
-        * writes.
-        */
        spin_lock_irq(&md->lock);
-       __blk_end_request_all(req, 0);
+       __blk_end_request_all(req, ret);
        spin_unlock_irq(&md->lock);
 
-       return 1;
+       return ret ? 0 : 1;
 }
 
 /*
index 772de2cdfd1d089712caad30832bad455a60f530..235bb6a1f9730bc687e5c82a4d2fb8fcab023acb 100644 (file)
@@ -2158,6 +2158,65 @@ int mmc_card_can_sleep(struct mmc_host *host)
 }
 EXPORT_SYMBOL(mmc_card_can_sleep);
 
+/*
+ * Flush the cache to the non-volatile storage.
+ */
+int mmc_flush_cache(struct mmc_card *card)
+{
+       struct mmc_host *host = card->host;
+       int err = 0;
+
+       if (!(host->caps2 & MMC_CAP2_CACHE_CTRL))
+               return err;
+
+       if (mmc_card_mmc(card) &&
+                       (card->ext_csd.cache_size > 0) &&
+                       (card->ext_csd.cache_ctrl & 1)) {
+               err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
+                               EXT_CSD_FLUSH_CACHE, 1, 0);
+               if (err)
+                       pr_err("%s: cache flush error %d\n",
+                                       mmc_hostname(card->host), err);
+       }
+
+       return err;
+}
+EXPORT_SYMBOL(mmc_flush_cache);
+
+/*
+ * Turn the cache ON/OFF.
+ * Turning the cache OFF shall trigger flushing of the data
+ * to the non-volatile storage.
+ */
+int mmc_cache_ctrl(struct mmc_host *host, u8 enable)
+{
+       struct mmc_card *card = host->card;
+       int err = 0;
+
+       if (!(host->caps2 & MMC_CAP2_CACHE_CTRL) ||
+                       mmc_card_is_removable(host))
+               return err;
+
+       if (card && mmc_card_mmc(card) &&
+                       (card->ext_csd.cache_size > 0)) {
+               enable = !!enable;
+
+               if (card->ext_csd.cache_ctrl ^ enable)
+                       err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
+                                       EXT_CSD_CACHE_CTRL, enable, 0);
+               if (err)
+                       pr_err("%s: cache %s error %d\n",
+                                       mmc_hostname(card->host),
+                                       enable ? "on" : "off",
+                                       err);
+               else
+                       card->ext_csd.cache_ctrl = enable;
+       }
+
+       return err;
+}
+EXPORT_SYMBOL(mmc_cache_ctrl);
+
 #ifdef CONFIG_PM
 
 /**
@@ -2172,6 +2231,9 @@ int mmc_suspend_host(struct mmc_host *host)
                cancel_delayed_work(&host->disable);
        cancel_delayed_work(&host->detect);
        mmc_flush_scheduled_work();
+       err = mmc_cache_ctrl(host, 0);
+       if (err)
+               goto out;
 
        mmc_bus_get(host);
        if (host->bus_ops && !host->bus_dead) {
@@ -2197,6 +2259,7 @@ int mmc_suspend_host(struct mmc_host *host)
        if (!err && !mmc_card_keep_power(host))
                mmc_power_off(host);
 
+out:
        return err;
 }
 
index 7939015192086953211019839787d4180ef963f0..de5900aa81cd2a0710d83399fc8fc5b344c9dd7b 100644 (file)
@@ -470,6 +470,12 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
        } else
                card->ext_csd.generic_cmd6_time = 0;
 
+       card->ext_csd.cache_size =
+               ext_csd[EXT_CSD_CACHE_SIZE + 0] << 0 |
+               ext_csd[EXT_CSD_CACHE_SIZE + 1] << 8 |
+               ext_csd[EXT_CSD_CACHE_SIZE + 2] << 16 |
+               ext_csd[EXT_CSD_CACHE_SIZE + 3] << 24;
+
 out:
        return err;
 }
@@ -1020,6 +1026,23 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
                }
        }
 
+       /*
+        * If cache size is higher than 0, this indicates
+        * the existence of cache and it can be turned on.
+        */
+       if ((host->caps2 & MMC_CAP2_CACHE_CTRL) &&
+                       card->ext_csd.cache_size > 0) {
+               err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
+                               EXT_CSD_CACHE_CTRL, 1, 0);
+               if (err && err != -EBADMSG)
+                       goto free_card;
+
+               /*
+                * Only if no error, cache is turned on successfully.
+                */
+               card->ext_csd.cache_ctrl = err ? 0 : 1;
+       }
+
        if (!oldcard)
                host->card = card;
 
index 551378508784049de39278da603685d076184428..32492b78aed6ebcfa86132128bc54090067db997 100644 (file)
@@ -51,6 +51,7 @@ struct mmc_ext_csd {
        u8                      rel_sectors;
        u8                      rel_param;
        u8                      part_config;
+       u8                      cache_ctrl;
        u8                      rst_n_function;
        unsigned int            part_time;              /* Units: ms */
        unsigned int            sa_timeout;             /* Units: 100ns */
@@ -67,6 +68,7 @@ struct mmc_ext_csd {
        bool                    enhanced_area_en;       /* enable bit */
        unsigned long long      enhanced_area_offset;   /* Units: Byte */
        unsigned int            enhanced_area_size;     /* Units: KB */
+       unsigned int            cache_size;             /* Units: KB */
        u8                      raw_partition_support;  /* 160 */
        u8                      raw_erased_mem_count;   /* 181 */
        u8                      raw_ext_csd_structure;  /* 194 */
index e918120235bdd689854bd02ea8299e0626a8564f..67bac374d122ddd51a762fcb154bc4301f0a5ced 100644 (file)
@@ -177,6 +177,8 @@ extern void mmc_release_host(struct mmc_host *host);
 extern void mmc_do_release_host(struct mmc_host *host);
 extern int mmc_try_claim_host(struct mmc_host *host);
 
+extern int mmc_flush_cache(struct mmc_card *);
+
 /**
  *     mmc_claim_host - exclusively claim a host
  *     @host: mmc host to claim
index cd10208d9a06943e957c72bf7e7c83bc4cb1f2f5..16e9338944e82354d3d8e0d866619db98c61f1ee 100644 (file)
@@ -239,6 +239,7 @@ struct mmc_host {
        unsigned int            caps2;          /* More host capabilities */
 
 #define MMC_CAP2_BOOTPART_NOACC        (1 << 0)        /* Boot partition no access */
+#define MMC_CAP2_CACHE_CTRL    (1 << 1)        /* Allow cache control */
 #define MMC_CAP2_POWEROFF_NOTIFY (1 << 2)      /* Notify poweroff supported */
 
        mmc_pm_flag_t           pm_caps;        /* supported pm features */
@@ -349,6 +350,8 @@ extern int mmc_power_restore_host(struct mmc_host *host);
 extern void mmc_detect_change(struct mmc_host *, unsigned long delay);
 extern void mmc_request_done(struct mmc_host *, struct mmc_request *);
 
+extern int mmc_cache_ctrl(struct mmc_host *, u8);
+
 static inline void mmc_signal_sdio_irq(struct mmc_host *host)
 {
        host->ops->enable_sdio_irq(host, 0);
index 8a05a21fc7c33be4cfbcc25cb67fc86b5052fec1..160e4c5bdae02d945ecd1e912228bffc92ca92f0 100644 (file)
@@ -270,6 +270,8 @@ struct _mmc_csd {
  * EXT_CSD fields
  */
 
+#define EXT_CSD_FLUSH_CACHE            32      /* W */
+#define EXT_CSD_CACHE_CTRL             33      /* R/W */
 #define EXT_CSD_POWER_OFF_NOTIFICATION 34      /* R/W */
 #define EXT_CSD_GP_SIZE_MULT           143     /* R/W */
 #define EXT_CSD_PARTITION_ATTRIBUTE    156     /* R/W */
@@ -308,6 +310,7 @@ struct _mmc_csd {
 #define EXT_CSD_PWR_CL_DDR_52_360      239     /* RO */
 #define EXT_CSD_POWER_OFF_LONG_TIME    247     /* RO */
 #define EXT_CSD_GENERIC_CMD6_TIME      248     /* RO */
+#define EXT_CSD_CACHE_SIZE             249     /* RO, 4 bytes */
 
 /*
  * EXT_CSD field definitions