coresight: byte-cntr: stop reading byte-cntr when etr is diasbled

Tmc etr buffer will be read when user runs 'cat /dev/byte-cntr'.
If tmc etr is disabled, the buffer will be released. So exit
byte-cntr-read when etr is disabled.

Change-Id: Ie1a5367a76eec11563e4a5ff36f616ae40b620f2
Signed-off-by: Yuanfang Zhang <zhangyuanfang@codeaurora.org>
diff --git a/drivers/hwtracing/coresight/coresight-byte-cntr.c b/drivers/hwtracing/coresight/coresight-byte-cntr.c
index 9fa3e0f..6f80b60 100644
--- a/drivers/hwtracing/coresight/coresight-byte-cntr.c
+++ b/drivers/hwtracing/coresight/coresight-byte-cntr.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 and
@@ -237,6 +237,7 @@
 
 	mutex_lock(&byte_cntr_data->byte_cntr_lock);
 	byte_cntr_data->enable = false;
+	byte_cntr_data->read_active = false;
 	coresight_csr_set_byte_cntr(byte_cntr_data->csr, 0);
 	mutex_unlock(&byte_cntr_data->byte_cntr_lock);
 
@@ -264,7 +265,7 @@
 
 	mutex_lock(&byte_cntr_data->byte_cntr_lock);
 
-	if (!tmcdrvdata->enable || !byte_cntr_data->block_size) {
+	if (!byte_cntr_data->enable || !byte_cntr_data->block_size) {
 		mutex_unlock(&byte_cntr_data->byte_cntr_lock);
 		return -EINVAL;
 	}
@@ -277,7 +278,6 @@
 
 	fp->private_data = byte_cntr_data;
 	nonseekable_open(in, fp);
-	byte_cntr_data->enable = true;
 	byte_cntr_data->read_active = true;
 	mutex_unlock(&byte_cntr_data->byte_cntr_lock);
 
diff --git a/drivers/hwtracing/coresight/coresight-tmc.c b/drivers/hwtracing/coresight/coresight-tmc.c
index 8aed31a..51c57a4 100644
--- a/drivers/hwtracing/coresight/coresight-tmc.c
+++ b/drivers/hwtracing/coresight/coresight-tmc.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012, 2017-2018, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2012, 2017-2019, The Linux Foundation. All rights reserved.
  *
  * Description: CoreSight Trace Memory Controller driver
  *
@@ -469,6 +469,8 @@
 		coresight_cti_unmap_trigout(drvdata->cti_flush, 3, 0);
 		coresight_cti_unmap_trigin(drvdata->cti_reset, 2, 0);
 
+		tmc_etr_byte_cntr_stop(drvdata->byte_cntr);
+
 		drvdata->usbch = usb_qdss_open("qdss", drvdata,
 					       usb_notifier);
 		if (IS_ERR(drvdata->usbch)) {