From f84e456b211ea5ca965d918722b7d62c36d847f8 Mon Sep 17 00:00:00 2001
From: Tom Thomas <tthomas@e-planit.com>
Date: Wed, 13 Jan 2021 14:34:30 -0800
Subject: [PATCH] [TGSX-752] DO NOT MERGE - Testing eMMC R/W mode

Testing if the MMC driver supports Auto CMD23 (to prevent
open-ended multi-block operations).

Setting MMC_CAP_CMD23 in mmc->caps in hsmmc_probe(), AUTO_CMD23
in host flags.

Also testing 16KB chunk size.

Change-Id: Ib8479c39280ba6ddb37428fea3c0301fb825e921
---

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/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index 0136f1d..64af438 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -3420,6 +3420,7 @@
 	host->pbias_enabled = 0;
 	host->regulator_enabled = 0;
 	host->last_cmd = 0;
+	host->flags = AUTO_CMD23;
 	__setup_timer(&host->timer, omap_hsmmc_soft_timeout,
 		    (unsigned long) host, TIMER_IRQSAFE);
 
@@ -3491,7 +3492,7 @@
 	mmc->max_seg_size = mmc->max_req_size;
 
 	mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED |
-		     MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_ERASE;
+		     MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_ERASE | MMC_CAP_CMD23;
 
 	mmc->caps |= mmc_slot(host).caps;
 	if (mmc->caps & MMC_CAP_8_BIT_DATA)
@@ -3634,6 +3635,7 @@
 	omap_hsmmc_debugfs(host);
 	pm_runtime_mark_last_busy(host->dev);
 	pm_runtime_put_autosuspend(host->dev);
+	printk(KERN_WARNING "%s: host->flags=x%x, AutoCMD23=%d", __func__, host->flags, host->flags & AUTO_CMD23);
 
 #if 1 /* Murata */
 	pr_info("exiting omap_hsmmc_probe successfully!!!!!!!!!!!!!!!!!!!!!\n");
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
