From 10444c1630a1958658f45dcf176cb1e268e98dcb Mon Sep 17 00:00:00 2001
From: Sathyanarayana Nujella <sathyanarayana.nujella@intel.com>
Date: Mon, 23 Oct 2017 19:48:31 -0700
Subject: [PATCH] TEST: Read CDCLK, PW2 and other reg from Audio driver

Add Infrastructure to read i915 PW2/CDCLK and rest of reg from audio

Signed-off-by: Sathyanarayana Nujella <sathyanarayana.nujella@intel.com>
Signed-off-by: Subhransu S. Prusty <subhransu.s.prusty@intel.com>
---
 drivers/gpu/drm/i915/intel_audio.c | 18 ++++++++++++++++++
 include/drm/i915_component.h       |  2 ++
 include/sound/hda_i915.h           |  3 +++
 sound/hda/hdac_i915.c              | 16 ++++++++++++++++
 sound/pci/hda/hda_controller.c     |  3 +++
 sound/soc/intel/skylake/skl.c      |  4 ++++
 6 files changed, 46 insertions(+)

diff --git a/drivers/gpu/drm/i915/intel_audio.c b/drivers/gpu/drm/i915/intel_audio.c
index 27743be5b768..864f0430a95c 100644
--- a/drivers/gpu/drm/i915/intel_audio.c
+++ b/drivers/gpu/drm/i915/intel_audio.c
@@ -698,6 +698,23 @@ static void i915_audio_component_put_power(struct device *kdev)
 	intel_display_power_put(kdev_to_i915(kdev), POWER_DOMAIN_AUDIO);
 }
 
+#define HSW_PWR_WELL_DRIVER                     _MMIO(0x45404)
+
+static int i915_audio_readmisc(struct device *kdev)
+{
+	struct drm_i915_private *dev_priv = kdev_to_i915(kdev);
+	uint32_t cdclk_tmp = I915_READ(CDCLK_CTL);
+	uint32_t AudChickenbit = I915_READ(HSW_AUD_CHICKENBIT);
+	uint32_t PwCtl2 = I915_READ(HSW_PWR_WELL_DRIVER);
+
+	printk("%s %d\n",__func__,__LINE__);
+	printk("%s HSW_AUD_CHICKENBIT=0x%x\n",__func__,AudChickenbit);
+	printk("%s cdclk_ctl =0x%x\n",__func__,cdclk_tmp );
+	printk("%s  cdclk_freq=0x%x\n",__func__, I915_READ(CDCLK_FREQ));
+	printk("%s PWR_WELL_CTL2 =0x%x\n",__func__, PwCtl2 );
+	return 0;
+}
+
 static void i915_audio_component_codec_wake_override(struct device *kdev,
 						     bool enable)
 {
@@ -868,6 +885,7 @@ static int i915_audio_component_get_eld(struct device *kdev, int port,
 	.get_cdclk_freq	= i915_audio_component_get_cdclk_freq,
 	.sync_audio_rate = i915_audio_component_sync_audio_rate,
 	.get_eld	= i915_audio_component_get_eld,
+	.readmisc	= i915_audio_readmisc,
 };
 
 static int i915_audio_component_bind(struct device *i915_kdev,
diff --git a/include/drm/i915_component.h b/include/drm/i915_component.h
index 545c6e0fea7d..08d055b17d4f 100644
--- a/include/drm/i915_component.h
+++ b/include/drm/i915_component.h
@@ -79,6 +79,8 @@ struct i915_audio_component_ops {
 	 */
 	int (*get_eld)(struct device *, int port, int pipe, bool *enabled,
 		       unsigned char *buf, int max_bytes);
+
+	int (*readmisc)(struct device *);
 };
 
 /**
diff --git a/include/sound/hda_i915.h b/include/sound/hda_i915.h
index 5ab972e116ec..18b98caddef6 100644
--- a/include/sound/hda_i915.h
+++ b/include/sound/hda_i915.h
@@ -17,6 +17,9 @@ int snd_hdac_acomp_get_eld(struct hdac_device *codec, hda_nid_t nid, int dev_id,
 int snd_hdac_i915_init(struct hdac_bus *bus);
 int snd_hdac_i915_exit(struct hdac_bus *bus);
 int snd_hdac_i915_register_notifier(const struct i915_audio_component_audio_ops *);
+
+int snd_hdac_readmisc(struct hdac_bus *bus);
+
 #else
 static inline int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable)
 {
diff --git a/sound/hda/hdac_i915.c b/sound/hda/hdac_i915.c
index 038a180d3f81..ddd3d555e849 100644
--- a/sound/hda/hdac_i915.c
+++ b/sound/hda/hdac_i915.c
@@ -59,6 +59,22 @@ int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable)
 }
 EXPORT_SYMBOL_GPL(snd_hdac_set_codec_wakeup);
 
+int snd_hdac_readmisc(struct hdac_bus *bus)
+{
+	struct i915_audio_component *acomp = bus->audio_component;
+
+	if (!acomp || !acomp->ops)
+	{
+		printk("%s %d\n",__func__,__LINE__);
+		return -ENODEV;
+	}
+	acomp->ops->readmisc(acomp->dev);
+	printk("%s %d\n",__func__,__LINE__);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_hdac_readmisc);
+
 /**
  * snd_hdac_display_power - Power up / down the power refcount
  * @bus: HDA core bus
diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c
index d1eb14842340..af5b8ec8372a 100644
--- a/sound/pci/hda/hda_controller.c
+++ b/sound/pci/hda/hda_controller.c
@@ -36,6 +36,7 @@
 #include <sound/core.h>
 #include <sound/initval.h>
 #include "hda_controller.h"
+#include <sound/hda_i915.h>
 
 #define CREATE_TRACE_POINTS
 #include "hda_controller_trace.h"
@@ -1194,6 +1195,8 @@ static int probe_codec(struct azx *chip, int addr)
 	int err;
 	unsigned int res = -1;
 
+	snd_hdac_readmisc(bus);
+
 	mutex_lock(&bus->cmd_mutex);
 	chip->probing = 1;
 	azx_send_cmd(bus, cmd);
diff --git a/sound/soc/intel/skylake/skl.c b/sound/soc/intel/skylake/skl.c
index d6b01ae165d3..874f3e83f51c 100644
--- a/sound/soc/intel/skylake/skl.c
+++ b/sound/soc/intel/skylake/skl.c
@@ -743,6 +743,9 @@ static int probe_codec(struct hdac_ext_bus *ebus, int addr)
 		(AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
 	unsigned int res = -1;
 
+	printk("%s %d\n",__func__,__LINE__);
+	snd_hdac_readmisc(bus);
+
 	mutex_lock(&bus->cmd_mutex);
 	snd_hdac_bus_send_cmd(bus, cmd);
 	snd_hdac_bus_get_response(bus, addr, &res);
@@ -750,6 +753,7 @@ static int probe_codec(struct hdac_ext_bus *ebus, int addr)
 	if (res == -1)
 		return -EIO;
 	dev_dbg(bus->dev, "codec #%d probed OK\n", addr);
+	printk("%s %d\n",__func__,__LINE__);
 
 	return snd_hdac_ext_bus_device_init(ebus, addr);
 }
-- 
1.9.1

