From 7c59d0b0b3e5a9784a6b17e69e977a567935a9de Mon Sep 17 00:00:00 2001
From: Tom Thomas <tthomas@e-planit.com>
Date: Wed, 07 Jul 2021 14:44:03 -0700
Subject: [PATCH] [TGSX-752] Use Close-Ended Multiblock RW for eMMC 5.1

This change is to cause closed-ended read and write operations
to be used if the eMMC version is JEDEC 5.1, or newer.  Otherwise,
the default logic of open-ended reads and writes is used.

A member is added to struct mmc_host, named denso_extcsdrev.
During mmc_init_card(), called when the target eMMC device
is initialized, the ext_csd is read.  The JEDEC version
indicator is copied from that to denso_extcsdrev in the mmc_host
struct.  In omap_hsmmc_start_command(), the version indicator
is used to determine whether to use closed-ended multiblock
operations.

Enable Ftrace, for eMMC driver.

Check of denso_extcsdrev is done in omap_hsmmc_start_command().

added printk to confirm code path (TODO: REMOVE!).

Enable and expand ftrace

Enables ftrace in the kernel config, and expands its mmc data set
to include 'sbc' (set block count) commands, if set.

Change-Id: I64365773032e372b189e675797da6471150b2117
---

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 144e3d7..826ae86 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -163,6 +163,7 @@
 void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
 {
 	struct mmc_command *cmd = mrq->cmd;
+	unsigned int sbc_op = mrq->sbc ? mrq->sbc->opcode : 0;
 	int err = cmd->error;
 
 	if (err && cmd->retries && mmc_host_is_spi(host)) {
@@ -191,7 +192,7 @@
 			pr_debug("%s:     %d bytes transferred: %d\n",
 				mmc_hostname(host),
 				mrq->data->bytes_xfered, mrq->data->error);
-			trace_mmc_blk_rw_end(cmd->opcode, cmd->arg, mrq->data);
+			trace_mmc_blk_rw_end(cmd->opcode, cmd->arg, mrq->data, sbc_op);
 		}
 
 		if (mrq->stop) {
@@ -548,6 +549,7 @@
 {
 	int err = 0;
 	int start_err = 0;
+	unsigned int sbc_op = 0;
 	struct mmc_async_req *data = host->areq;
 
 	/* Prepare a new request */
@@ -576,9 +578,10 @@
 	}
 
 	if (!err && areq) {
+		sbc_op = areq->mrq->sbc ? areq->mrq->sbc->opcode : 0;
 		trace_mmc_blk_rw_start(areq->mrq->cmd->opcode,
 				       areq->mrq->cmd->arg,
-				       areq->mrq->data);
+				       areq->mrq->data, sbc_op);
 		start_err = __mmc_start_data_req(host, areq->mrq);
 	}
 
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 7abe6fe..d1dbe5a 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -1363,6 +1363,13 @@
 		}
 	}
 
+    /*
+     * DENSO - Use closed-ended multi-block read and write operations if
+     * the JEDEC version is >= 5.1 (ext_csd.rev >= 8).
+     */
+	host->denso_extcsdrev = card->ext_csd.rev;
+	printk(KERN_INFO "denso_extcsdrev=%u", host->denso_extcsdrev);
+
 	if (!oldcard)
 		host->card = card;
 
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index 0136f1d..cdea4b1 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -183,6 +183,7 @@
 #define SD_SDR50_MAX_FREQ	104000000
 
 #define AUTO_CMD23		(1 << 1)	/* Auto CMD23 support */
+
 /*
  * One controller can have multiple slots, like on some omap boards using
  * omap.c controller driver. Luckily this is not currently done on any known
@@ -1568,10 +1569,19 @@
 
 	cmdreg = (cmd->opcode << 24) | (resptype << 16) | (cmdtype << 22);
 
+	if (host->mmc->denso_extcsdrev >= 8){
+		host->mmc->caps |= MMC_CAP_CMD23;
+		host->flags = AUTO_CMD23;
+		//printk_ratelimited(KERN_INFO ".%s() CMD23 Denso extCSDrev = %u", __func__, host->mmc->denso_extcsdrev);
+	}
+
+	printk_ratelimited(KERN_INFO ".%s() Denso host.flags:%u, cmd.opcode:%u, host.mrq.sbc.arg:%u", __func__, host->flags, cmd->opcode, host->mrq->sbc? host->mrq->sbc->arg: 0);
+
 	if ((host->flags & AUTO_CMD23) && mmc_op_multi(cmd->opcode) &&
 	    host->mrq->sbc) {
 		cmdreg |= ACEN_ACMD23;
 		OMAP_HSMMC_WRITE(host->base, SDMASA, host->mrq->sbc->arg);
+		printk_ratelimited(KERN_INFO ".%s() CMD23 (set block count) = %u", __func__, host->mrq->sbc->arg);
 	}
 	if (data) {
 		cmdreg |= DP_SELECT | MSBS | BCE;
@@ -3420,6 +3430,7 @@
 	host->pbias_enabled = 0;
 	host->regulator_enabled = 0;
 	host->last_cmd = 0;
+
 	__setup_timer(&host->timer, omap_hsmmc_soft_timeout,
 		    (unsigned long) host, TIMER_IRQSAFE);
 
@@ -3635,6 +3646,7 @@
 	pm_runtime_mark_last_busy(host->dev);
 	pm_runtime_put_autosuspend(host->dev);
 
+
 #if 1 /* Murata */
 	pr_info("exiting omap_hsmmc_probe successfully!!!!!!!!!!!!!!!!!!!!!\n");
 #endif
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index edf1111..a23f0ce 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -372,6 +372,9 @@
 	} embedded_sdio_data;
 #endif
 
+	/* the value of ext_csd.rev */
+	u8			denso_extcsdrev;
+
 	unsigned long		private[0] ____cacheline_aligned;
 };
 
diff --git a/include/trace/events/mmc.h b/include/trace/events/mmc.h
index 82b368d..73eda37 100644
--- a/include/trace/events/mmc.h
+++ b/include/trace/events/mmc.h
@@ -56,32 +56,34 @@
  * including cmd, address, size
  */
 DECLARE_EVENT_CLASS(mmc_blk_rw_class,
-	TP_PROTO(unsigned int cmd, unsigned int addr, struct mmc_data *data),
-	TP_ARGS(cmd, addr, data),
+	TP_PROTO(unsigned int cmd, unsigned int addr, struct mmc_data *data, unsigned int sbcop),
+	TP_ARGS(cmd, addr, data, sbcop),
 	TP_STRUCT__entry(
 		__field(unsigned int, cmd)
 		__field(unsigned int, addr)
 		__field(unsigned int, size)
+		__field(unsigned int, sbcop)
 	),
 	TP_fast_assign(
 		__entry->cmd = cmd;
 		__entry->addr = addr;
 		__entry->size = data->blocks;
+		__entry->sbcop = sbcop;
 	),
-	TP_printk("cmd=%u,addr=0x%08x,size=0x%08x",
-		  __entry->cmd, __entry->addr, __entry->size)
+	TP_printk("cmd=%u,addr=0x%08x,size=0x%08x,sbc_op=%u",
+		  __entry->cmd, __entry->addr, __entry->size, __entry->sbcop)
 );
 
 DEFINE_EVENT_CONDITION(mmc_blk_rw_class, mmc_blk_rw_start,
-	TP_PROTO(unsigned int cmd, unsigned int addr, struct mmc_data *data),
-	TP_ARGS(cmd, addr, data),
+	TP_PROTO(unsigned int cmd, unsigned int addr, struct mmc_data *data, unsigned int sbcop),
+	TP_ARGS(cmd, addr, data, sbcop),
 	TP_CONDITION(((cmd == MMC_READ_MULTIPLE_BLOCK) ||
 		      (cmd == MMC_WRITE_MULTIPLE_BLOCK)) &&
 		      data));
 
 DEFINE_EVENT_CONDITION(mmc_blk_rw_class, mmc_blk_rw_end,
-	TP_PROTO(unsigned int cmd, unsigned int addr, struct mmc_data *data),
-	TP_ARGS(cmd, addr, data),
+	TP_PROTO(unsigned int cmd, unsigned int addr, struct mmc_data *data, unsigned int sbcop),
+	TP_ARGS(cmd, addr, data, sbcop),
 	TP_CONDITION(((cmd == MMC_READ_MULTIPLE_BLOCK) ||
 		      (cmd == MMC_WRITE_MULTIPLE_BLOCK)) &&
 		      data));
diff --git a/ti_config_fragments/gen1CBB_HS.cfg b/ti_config_fragments/gen1CBB_HS.cfg
index ea2cccf..0a9891f9 100644
--- a/ti_config_fragments/gen1CBB_HS.cfg
+++ b/ti_config_fragments/gen1CBB_HS.cfg
@@ -2,3 +2,9 @@
 CONFIG_HRB_DISPLAY_SUPPORT=n
 
 CONFIG_DRA7XX_OMIT_HIGH_OPP=y
+
+CONFIG_DYNAMIC_FTRACE=y
+CONFIG_FTRACE=y
+CONFIG_FUNCTION_TRACER=y
+CONFIG_FUNCTION_GRAPH_TRACER=y
+CONFIG_STACK_TRACER=y
