aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeungwon Jeon <tgih.jun@samsung.com>2011-10-14 01:03:21 -0400
committerChris Ball <cjb@laptop.org>2011-10-26 16:32:28 -0400
commit881d1c25f765938a95def5afe39486ce39f9fc96 (patch)
tree694d5ea1b3fba2c28cc110123f2ca50b4408f309
parent71fe3eb0d006861bdae57e93975b6ae3d9b55e99 (diff)
mmc: core: Add cache control for eMMC4.5 device
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>
-rw-r--r--drivers/mmc/card/block.c14
-rw-r--r--drivers/mmc/core/core.c63
-rw-r--r--drivers/mmc/core/mmc.c23
-rw-r--r--include/linux/mmc/card.h2
-rw-r--r--include/linux/mmc/core.h2
-rw-r--r--include/linux/mmc/host.h3
-rw-r--r--include/linux/mmc/mmc.h3
7 files changed, 104 insertions, 6 deletions
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 370472797fff..c0cb225bbb47 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -851,16 +851,18 @@ out:
851static int mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req) 851static int mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req)
852{ 852{
853 struct mmc_blk_data *md = mq->data; 853 struct mmc_blk_data *md = mq->data;
854 struct mmc_card *card = md->queue.card;
855 int ret = 0;
856
857 ret = mmc_flush_cache(card);
858 if (ret)
859 ret = -EIO;
854 860
855 /*
856 * No-op, only service this because we need REQ_FUA for reliable
857 * writes.
858 */
859 spin_lock_irq(&md->lock); 861 spin_lock_irq(&md->lock);
860 __blk_end_request_all(req, 0); 862 __blk_end_request_all(req, ret);
861 spin_unlock_irq(&md->lock); 863 spin_unlock_irq(&md->lock);
862 864
863 return 1; 865 return ret ? 0 : 1;
864} 866}
865 867
866/* 868/*
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 772de2cdfd1d..235bb6a1f973 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -2158,6 +2158,65 @@ int mmc_card_can_sleep(struct mmc_host *host)
2158} 2158}
2159EXPORT_SYMBOL(mmc_card_can_sleep); 2159EXPORT_SYMBOL(mmc_card_can_sleep);
2160 2160
2161/*
2162 * Flush the cache to the non-volatile storage.
2163 */
2164int mmc_flush_cache(struct mmc_card *card)
2165{
2166 struct mmc_host *host = card->host;
2167 int err = 0;
2168
2169 if (!(host->caps2 & MMC_CAP2_CACHE_CTRL))
2170 return err;
2171
2172 if (mmc_card_mmc(card) &&
2173 (card->ext_csd.cache_size > 0) &&
2174 (card->ext_csd.cache_ctrl & 1)) {
2175 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
2176 EXT_CSD_FLUSH_CACHE, 1, 0);
2177 if (err)
2178 pr_err("%s: cache flush error %d\n",
2179 mmc_hostname(card->host), err);
2180 }
2181
2182 return err;
2183}
2184EXPORT_SYMBOL(mmc_flush_cache);
2185
2186/*
2187 * Turn the cache ON/OFF.
2188 * Turning the cache OFF shall trigger flushing of the data
2189 * to the non-volatile storage.
2190 */
2191int mmc_cache_ctrl(struct mmc_host *host, u8 enable)
2192{
2193 struct mmc_card *card = host->card;
2194 int err = 0;
2195
2196 if (!(host->caps2 & MMC_CAP2_CACHE_CTRL) ||
2197 mmc_card_is_removable(host))
2198 return err;
2199
2200 if (card && mmc_card_mmc(card) &&
2201 (card->ext_csd.cache_size > 0)) {
2202 enable = !!enable;
2203
2204 if (card->ext_csd.cache_ctrl ^ enable)
2205 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
2206 EXT_CSD_CACHE_CTRL, enable, 0);
2207 if (err)
2208 pr_err("%s: cache %s error %d\n",
2209 mmc_hostname(card->host),
2210 enable ? "on" : "off",
2211 err);
2212 else
2213 card->ext_csd.cache_ctrl = enable;
2214 }
2215
2216 return err;
2217}
2218EXPORT_SYMBOL(mmc_cache_ctrl);
2219
2161#ifdef CONFIG_PM 2220#ifdef CONFIG_PM
2162 2221
2163/** 2222/**
@@ -2172,6 +2231,9 @@ int mmc_suspend_host(struct mmc_host *host)
2172 cancel_delayed_work(&host->disable); 2231 cancel_delayed_work(&host->disable);
2173 cancel_delayed_work(&host->detect); 2232 cancel_delayed_work(&host->detect);
2174 mmc_flush_scheduled_work(); 2233 mmc_flush_scheduled_work();
2234 err = mmc_cache_ctrl(host, 0);
2235 if (err)
2236 goto out;
2175 2237
2176 mmc_bus_get(host); 2238 mmc_bus_get(host);
2177 if (host->bus_ops && !host->bus_dead) { 2239 if (host->bus_ops && !host->bus_dead) {
@@ -2197,6 +2259,7 @@ int mmc_suspend_host(struct mmc_host *host)
2197 if (!err && !mmc_card_keep_power(host)) 2259 if (!err && !mmc_card_keep_power(host))
2198 mmc_power_off(host); 2260 mmc_power_off(host);
2199 2261
2262out:
2200 return err; 2263 return err;
2201} 2264}
2202 2265
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 793901519208..de5900aa81cd 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -470,6 +470,12 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
470 } else 470 } else
471 card->ext_csd.generic_cmd6_time = 0; 471 card->ext_csd.generic_cmd6_time = 0;
472 472
473 card->ext_csd.cache_size =
474 ext_csd[EXT_CSD_CACHE_SIZE + 0] << 0 |
475 ext_csd[EXT_CSD_CACHE_SIZE + 1] << 8 |
476 ext_csd[EXT_CSD_CACHE_SIZE + 2] << 16 |
477 ext_csd[EXT_CSD_CACHE_SIZE + 3] << 24;
478
473out: 479out:
474 return err; 480 return err;
475} 481}
@@ -1020,6 +1026,23 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1020 } 1026 }
1021 } 1027 }
1022 1028
1029 /*
1030 * If cache size is higher than 0, this indicates
1031 * the existence of cache and it can be turned on.
1032 */
1033 if ((host->caps2 & MMC_CAP2_CACHE_CTRL) &&
1034 card->ext_csd.cache_size > 0) {
1035 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1036 EXT_CSD_CACHE_CTRL, 1, 0);
1037 if (err && err != -EBADMSG)
1038 goto free_card;
1039
1040 /*
1041 * Only if no error, cache is turned on successfully.
1042 */
1043 card->ext_csd.cache_ctrl = err ? 0 : 1;
1044 }
1045
1023 if (!oldcard) 1046 if (!oldcard)
1024 host->card = card; 1047 host->card = card;
1025 1048
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index 551378508784..32492b78aed6 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -51,6 +51,7 @@ struct mmc_ext_csd {
51 u8 rel_sectors; 51 u8 rel_sectors;
52 u8 rel_param; 52 u8 rel_param;
53 u8 part_config; 53 u8 part_config;
54 u8 cache_ctrl;
54 u8 rst_n_function; 55 u8 rst_n_function;
55 unsigned int part_time; /* Units: ms */ 56 unsigned int part_time; /* Units: ms */
56 unsigned int sa_timeout; /* Units: 100ns */ 57 unsigned int sa_timeout; /* Units: 100ns */
@@ -67,6 +68,7 @@ struct mmc_ext_csd {
67 bool enhanced_area_en; /* enable bit */ 68 bool enhanced_area_en; /* enable bit */
68 unsigned long long enhanced_area_offset; /* Units: Byte */ 69 unsigned long long enhanced_area_offset; /* Units: Byte */
69 unsigned int enhanced_area_size; /* Units: KB */ 70 unsigned int enhanced_area_size; /* Units: KB */
71 unsigned int cache_size; /* Units: KB */
70 u8 raw_partition_support; /* 160 */ 72 u8 raw_partition_support; /* 160 */
71 u8 raw_erased_mem_count; /* 181 */ 73 u8 raw_erased_mem_count; /* 181 */
72 u8 raw_ext_csd_structure; /* 194 */ 74 u8 raw_ext_csd_structure; /* 194 */
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index e918120235bd..67bac374d122 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -177,6 +177,8 @@ extern void mmc_release_host(struct mmc_host *host);
177extern void mmc_do_release_host(struct mmc_host *host); 177extern void mmc_do_release_host(struct mmc_host *host);
178extern int mmc_try_claim_host(struct mmc_host *host); 178extern int mmc_try_claim_host(struct mmc_host *host);
179 179
180extern int mmc_flush_cache(struct mmc_card *);
181
180/** 182/**
181 * mmc_claim_host - exclusively claim a host 183 * mmc_claim_host - exclusively claim a host
182 * @host: mmc host to claim 184 * @host: mmc host to claim
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index cd10208d9a06..16e9338944e8 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -239,6 +239,7 @@ struct mmc_host {
239 unsigned int caps2; /* More host capabilities */ 239 unsigned int caps2; /* More host capabilities */
240 240
241#define MMC_CAP2_BOOTPART_NOACC (1 << 0) /* Boot partition no access */ 241#define MMC_CAP2_BOOTPART_NOACC (1 << 0) /* Boot partition no access */
242#define MMC_CAP2_CACHE_CTRL (1 << 1) /* Allow cache control */
242#define MMC_CAP2_POWEROFF_NOTIFY (1 << 2) /* Notify poweroff supported */ 243#define MMC_CAP2_POWEROFF_NOTIFY (1 << 2) /* Notify poweroff supported */
243 244
244 mmc_pm_flag_t pm_caps; /* supported pm features */ 245 mmc_pm_flag_t pm_caps; /* supported pm features */
@@ -349,6 +350,8 @@ extern int mmc_power_restore_host(struct mmc_host *host);
349extern void mmc_detect_change(struct mmc_host *, unsigned long delay); 350extern void mmc_detect_change(struct mmc_host *, unsigned long delay);
350extern void mmc_request_done(struct mmc_host *, struct mmc_request *); 351extern void mmc_request_done(struct mmc_host *, struct mmc_request *);
351 352
353extern int mmc_cache_ctrl(struct mmc_host *, u8);
354
352static inline void mmc_signal_sdio_irq(struct mmc_host *host) 355static inline void mmc_signal_sdio_irq(struct mmc_host *host)
353{ 356{
354 host->ops->enable_sdio_irq(host, 0); 357 host->ops->enable_sdio_irq(host, 0);
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index 8a05a21fc7c3..160e4c5bdae0 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -270,6 +270,8 @@ struct _mmc_csd {
270 * EXT_CSD fields 270 * EXT_CSD fields
271 */ 271 */
272 272
273#define EXT_CSD_FLUSH_CACHE 32 /* W */
274#define EXT_CSD_CACHE_CTRL 33 /* R/W */
273#define EXT_CSD_POWER_OFF_NOTIFICATION 34 /* R/W */ 275#define EXT_CSD_POWER_OFF_NOTIFICATION 34 /* R/W */
274#define EXT_CSD_GP_SIZE_MULT 143 /* R/W */ 276#define EXT_CSD_GP_SIZE_MULT 143 /* R/W */
275#define EXT_CSD_PARTITION_ATTRIBUTE 156 /* R/W */ 277#define EXT_CSD_PARTITION_ATTRIBUTE 156 /* R/W */
@@ -308,6 +310,7 @@ struct _mmc_csd {
308#define EXT_CSD_PWR_CL_DDR_52_360 239 /* RO */ 310#define EXT_CSD_PWR_CL_DDR_52_360 239 /* RO */
309#define EXT_CSD_POWER_OFF_LONG_TIME 247 /* RO */ 311#define EXT_CSD_POWER_OFF_LONG_TIME 247 /* RO */
310#define EXT_CSD_GENERIC_CMD6_TIME 248 /* RO */ 312#define EXT_CSD_GENERIC_CMD6_TIME 248 /* RO */
313#define EXT_CSD_CACHE_SIZE 249 /* RO, 4 bytes */
311 314
312/* 315/*
313 * EXT_CSD field definitions 316 * EXT_CSD field definitions