Skip to contentSkip to conversation

ALSA - hda: Add support for link audio time reporting

PATCH Applied Vinod Koul 2 participants 21 messages Jul 11, 2016 – Jul 15, 2016 1 message not in the archive

Subsystems (2)

v1 of 4 Applied Latest is v4 →

lore
Share & tools
lore

Vinod Koul

author
#0 lore raw

cover ALSA - hda: Add support for link audio time reporting

Skylake onwards we support GTS capability and thus can report audio link time. This series adds support for parsing the capability and then reports link time.

While at it, fix the timestamping Documentation.

Guneshwor Singh (2):
ALSA - hda: Add support for GTS capability ALSA - hda: Add support for link audio time reporting

Vinod Koul (1):
ALSA - hda: Fix timestamping documentation

 Documentation/sound/alsa/timestamping.txt |  12 +-
 include/sound/hda_register.h              |  23 ++++
 sound/pci/hda/hda_controller.c            | 192 +++++++++++++++++++++++++++++-
 sound/pci/hda/hda_controller.h            |  27 +++++
 sound/pci/hda/hda_intel.c                 |   1 +
 5 files changed, 248 insertions(+), 7 deletions(-)
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 1/3 ALSA - hda: Add support for GTS capability

From: Guneshwor Singh <[email protected]>

Skylake onwards HDA controller supports Global Time Stamping (GTS) capability. So add support to parse this capability in HDA driver.

---
 include/sound/hda_register.h   | 23 +++++++++++++++++++++++
 sound/pci/hda/hda_controller.c | 33 +++++++++++++++++++++++++++++++++
 sound/pci/hda/hda_controller.h | 27 +++++++++++++++++++++++++++
 sound/pci/hda/hda_intel.c      |  1 +
 4 files changed, 84 insertions(+)
include/sound/hda_register.h +23 -0
index ff1aecf325e8..e4178328e8c8 100644
@@ -242,6 +242,29 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
 /* Interval used to calculate the iterating register offset */
 #define AZX_DRSM_INTERVAL		0x08
 
+/* Global time synchronization registers */
+#define GTSCC_TSCCD_MASK		0x80000000
+#define GTSCC_TSCCD_SHIFT		31
+#define GTSCC_TSCCI_MASK		0x20
+#define GTSCC_CDMAS_DMA_DIR_SHIFT	4
+
+#define WALFCC_CIF_MASK			0x1FF
+#define WALFCC_FN_SHIFT			9
+#define HDA_CLK_CYCLES_PER_FRAME	512
+
+/*
+ * An error occurs near frame "rollover". The clocks in frame value indicates
+ * whether this error may have occurred. Here we use the value of 10. Please
+ * see the errata for the right number [<10]
+ */
+#define HDA_MAX_CYCLE_VALUE		499
+#define HDA_MAX_CYCLE_OFFSET		10
+#define HDA_MAX_CYCLE_READ_RETRY	10
+
+#define TSCCU_CCU_SHIFT			32
+#define LLPC_CCU_SHIFT			32
+
+
 /*
  * helpers to read the stream position
  */
sound/pci/hda/hda_controller.c +33 -0
index 27de8015717d..9833666c6108 100644
@@ -393,6 +393,34 @@ static struct snd_pcm_hardware azx_pcm_hw = {
 	.fifo_size =		0,
 };
 
+void azx_parse_capabilities(struct azx *chip)
+{
+	unsigned int cur_cap;
+	unsigned int offset;
+
+	offset = azx_readl(chip, LLCH);
+
+	/* Lets walk the linked capabilities list */
+	do {
+		cur_cap = _snd_hdac_chip_read(l, azx_bus(chip), offset);
+
+		switch ((cur_cap & CAP_HDR_ID_MASK) >> CAP_HDR_ID_OFF) {
+		case GTS_CAP_ID:
+			dev_dbg(chip->card->dev, "Found GTS capability");
+			chip->gts_present = 1;
+			break;
+
+		default:
+			break;
+		}
+
+		/* read the offset of next capabiity */
+		offset = cur_cap & CAP_HDR_NXT_PTR_MASK;
+	} while (offset);
+
+}
+EXPORT_SYMBOL_GPL(azx_parse_capabilities);
+
 static int azx_pcm_open(struct snd_pcm_substream *substream)
 {
 	struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
@@ -412,6 +440,11 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
 		goto unlock;
 	}
 	runtime->private_data = azx_dev;
+
+	/* CPU must have ART for reporting link synchronized time */
+	if (chip->gts_present && boot_cpu_has(X86_FEATURE_ART))
+		azx_pcm_hw.info = azx_pcm_hw.info |
+			SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME;
 	runtime->hw = azx_pcm_hw;
 	runtime->hw.channels_min = hinfo->channels_min;
 	runtime->hw.channels_max = hinfo->channels_max;
sound/pci/hda/hda_controller.h +27 -0
index ec63bbf1ec6d..fc57eef9fd88 100644
@@ -159,9 +159,14 @@ struct azx {
 	unsigned int region_requested:1;
 	unsigned int disabled:1; /* disabled by vga_switcheroo */
 
+	/* GTS present */
+	unsigned int gts_present:1;
+
 #ifdef CONFIG_SND_HDA_DSP_LOADER
 	struct azx_dev saved_azx_dev;
 #endif
+	unsigned int link_count;
+	unsigned int mlcap_offset;
 };
 
 #define azx_bus(chip)	(&(chip)->bus.core)
@@ -173,6 +178,27 @@ struct azx {
 #define azx_snoop(chip)		true
 #endif
 
+#define AZX_REG_LLCH 0x14
+
+#define AZX_REG_GTS_BASE 0x520
+
+#define AZX_REG_GTSCC	(AZX_REG_GTS_BASE + 0x00)
+#define AZX_REG_WALFCC	(AZX_REG_GTS_BASE + 0x04)
+#define AZX_REG_TSCCL	(AZX_REG_GTS_BASE + 0x08)
+#define AZX_REG_TSCCU	(AZX_REG_GTS_BASE + 0x0C)
+#define AZX_REG_LLPFOC	(AZX_REG_GTS_BASE + 0x14)
+#define AZX_REG_LLPCL	(AZX_REG_GTS_BASE + 0x18)
+#define AZX_REG_LLPCU	(AZX_REG_GTS_BASE + 0x1C)
+
+#define CAP_HDR_VER_OFF                 28
+#define CAP_HDR_VER_MASK                (0xF << CAP_HDR_VER_OFF)
+
+#define CAP_HDR_ID_OFF                  16
+#define CAP_HDR_ID_MASK                 (0xFFF << CAP_HDR_ID_OFF)
+
+#define GTS_CAP_ID                 0x1
+#define CAP_HDR_NXT_PTR_MASK    0xFFFF
+
 /*
  * macros for easy use
  */
@@ -201,6 +227,7 @@ static inline struct azx_dev *get_azx_dev(struct snd_pcm_substream *substream)
 unsigned int azx_get_position(struct azx *chip, struct azx_dev *azx_dev);
 unsigned int azx_get_pos_lpib(struct azx *chip, struct azx_dev *azx_dev);
 unsigned int azx_get_pos_posbuf(struct azx *chip, struct azx_dev *azx_dev);
+void azx_parse_capabilities(struct azx *chip);
 
 /* Stream control. */
 void azx_stop_all_streams(struct azx *chip);
sound/pci/hda/hda_intel.c +1 -0
index 9a0d1445ca5c..b4ebdde59398 100644
@@ -1649,6 +1649,7 @@ static int azx_first_init(struct azx *chip)
 		return -ENXIO;
 	}
 
+	azx_parse_capabilities(chip);
 	if (chip->msi) {
 		if (chip->driver_caps & AZX_DCAPS_NO_MSI64) {
 			dev_dbg(card->dev, "Disabling 64bit MSI\n");
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH 1/3] ALSA - hda: Add support for GTS capability

Quoted 56 lines · Vinod Koul

From: Guneshwor Singh <[email protected]>

Skylake onwards HDA controller supports Global Time Stamping (GTS) capability. So add support to parse this capability in HDA driver.

---
 include/sound/hda_register.h   | 23 +++++++++++++++++++++++
 sound/pci/hda/hda_controller.c | 33 +++++++++++++++++++++++++++++++++
 sound/pci/hda/hda_controller.h | 27 +++++++++++++++++++++++++++
 sound/pci/hda/hda_intel.c      |  1 +
 4 files changed, 84 insertions(+)
include/sound/hda_register.h +23 -0
index ff1aecf325e8..e4178328e8c8 100644
@@ -242,6 +242,29 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
 /* Interval used to calculate the iterating register offset */
 #define AZX_DRSM_INTERVAL		0x08
 
+/* Global time synchronization registers */
+#define GTSCC_TSCCD_MASK		0x80000000
+#define GTSCC_TSCCD_SHIFT		31
+#define GTSCC_TSCCI_MASK		0x20
+#define GTSCC_CDMAS_DMA_DIR_SHIFT	4
+
+#define WALFCC_CIF_MASK			0x1FF
+#define WALFCC_FN_SHIFT			9
+#define HDA_CLK_CYCLES_PER_FRAME	512
+
+/*
+ * An error occurs near frame "rollover". The clocks in frame value indicates
+ * whether this error may have occurred. Here we use the value of 10. Please
+ * see the errata for the right number [<10]
+ */
+#define HDA_MAX_CYCLE_VALUE		499
+#define HDA_MAX_CYCLE_OFFSET		10
+#define HDA_MAX_CYCLE_READ_RETRY	10
+
+#define TSCCU_CCU_SHIFT			32
+#define LLPC_CCU_SHIFT			32
+
+
 /*
  * helpers to read the stream position
  */
sound/pci/hda/hda_controller.c +0 -0
index 27de8015717d..9833666c6108 100644

sound/pci/hda/hda_controller.c static struct snd_pcm_hardware azx_pcm_hw = { · line 396

Quoted 4 lines
sound/pci/hda/hda_controller.c +1 -0
@@ -393,6 +393,34 @@ static struct snd_pcm_hardware azx_pcm_hw = {
 	.fifo_size =		0,
 };
 
+void azx_parse_capabilities(struct azx *chip)

Please give a bit more comments about the function.

Quoted 13 lines
sound/pci/hda/hda_controller.c +13 -0
+{
+	unsigned int cur_cap;
+	unsigned int offset;
+
+	offset = azx_readl(chip, LLCH);
+
+	/* Lets walk the linked capabilities list */
+	do {
+		cur_cap = _snd_hdac_chip_read(l, azx_bus(chip), offset);
+
+		switch ((cur_cap & CAP_HDR_ID_MASK) >> CAP_HDR_ID_OFF) {
+		case GTS_CAP_ID:
+			dev_dbg(chip->card->dev, "Found GTS capability");

sound/pci/hda/hda_controller.c static struct snd_pcm_hardware azx_pcm_hw = { · line 419

Quoted 10 lines
sound/pci/hda/hda_controller.c +10 -0
+			chip->gts_present = 1;
+			break;
+
+		default:
+			break;
+		}
+
+		/* read the offset of next capabiity */
+		offset = cur_cap & CAP_HDR_NXT_PTR_MASK;
+	} while (offset);

It's be safer to have a counter not to go over the endless loop.

Quoted 8 lines
sound/pci/hda/hda_controller.c +4 -0
+
+}
+EXPORT_SYMBOL_GPL(azx_parse_capabilities);
+
 static int azx_pcm_open(struct snd_pcm_substream *substream)
 {
 	struct azx_pcm *apcm = snd_pcm_substream_chip(substream);

sound/pci/hda/hda_controller.c static int azx_pcm_open(struct snd_pcm_substream *substream) · line 445

Quoted 6 lines
sound/pci/hda/hda_controller.c +3 -0
@@ -412,6 +440,11 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
 		goto unlock;
 	}
 	runtime->private_data = azx_dev;
+
+	/* CPU must have ART for reporting link synchronized time */
+	if (chip->gts_present && boot_cpu_has(X86_FEATURE_ART))

This comes out of sudden. It needs more explanation.

Quoted 65 lines
sound/pci/hda/hda_controller.c +2 -0
+		azx_pcm_hw.info = azx_pcm_hw.info |
+			SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME;
 	runtime->hw = azx_pcm_hw;
 	runtime->hw.channels_min = hinfo->channels_min;
 	runtime->hw.channels_max = hinfo->channels_max;
sound/pci/hda/hda_controller.h +27 -0
index ec63bbf1ec6d..fc57eef9fd88 100644
@@ -159,9 +159,14 @@ struct azx {
 	unsigned int region_requested:1;
 	unsigned int disabled:1; /* disabled by vga_switcheroo */
 
+	/* GTS present */
+	unsigned int gts_present:1;
+
 #ifdef CONFIG_SND_HDA_DSP_LOADER
 	struct azx_dev saved_azx_dev;
 #endif
+	unsigned int link_count;
+	unsigned int mlcap_offset;
 };
 
 #define azx_bus(chip)	(&(chip)->bus.core)
@@ -173,6 +178,27 @@ struct azx {
 #define azx_snoop(chip)		true
 #endif
 
+#define AZX_REG_LLCH 0x14
+
+#define AZX_REG_GTS_BASE 0x520
+
+#define AZX_REG_GTSCC	(AZX_REG_GTS_BASE + 0x00)
+#define AZX_REG_WALFCC	(AZX_REG_GTS_BASE + 0x04)
+#define AZX_REG_TSCCL	(AZX_REG_GTS_BASE + 0x08)
+#define AZX_REG_TSCCU	(AZX_REG_GTS_BASE + 0x0C)
+#define AZX_REG_LLPFOC	(AZX_REG_GTS_BASE + 0x14)
+#define AZX_REG_LLPCL	(AZX_REG_GTS_BASE + 0x18)
+#define AZX_REG_LLPCU	(AZX_REG_GTS_BASE + 0x1C)
+
+#define CAP_HDR_VER_OFF                 28
+#define CAP_HDR_VER_MASK                (0xF << CAP_HDR_VER_OFF)
+
+#define CAP_HDR_ID_OFF                  16
+#define CAP_HDR_ID_MASK                 (0xFFF << CAP_HDR_ID_OFF)
+
+#define GTS_CAP_ID                 0x1
+#define CAP_HDR_NXT_PTR_MASK    0xFFFF
+
 /*
  * macros for easy use
  */
@@ -201,6 +227,7 @@ static inline struct azx_dev *get_azx_dev(struct snd_pcm_substream *substream)
 unsigned int azx_get_position(struct azx *chip, struct azx_dev *azx_dev);
 unsigned int azx_get_pos_lpib(struct azx *chip, struct azx_dev *azx_dev);
 unsigned int azx_get_pos_posbuf(struct azx *chip, struct azx_dev *azx_dev);
+void azx_parse_capabilities(struct azx *chip);
 
 /* Stream control. */
 void azx_stop_all_streams(struct azx *chip);
sound/pci/hda/hda_intel.c +0 -0
index 9a0d1445ca5c..b4ebdde59398 100644

sound/pci/hda/hda_intel.c static int azx_first_init(struct azx *chip) · line 1652

Quoted 4 lines
sound/pci/hda/hda_intel.c +1 -0
@@ -1649,6 +1649,7 @@ static int azx_first_init(struct azx *chip)
 		return -ENXIO;
 	}
 
+	azx_parse_capabilities(chip);

Is it really safe to call the function no matter which chip?

thanks,

Takashi

author
#3 lore raw

Re: [PATCH 1/3] ALSA - hda: Add support for GTS capability

Quoted 7 lines · Takashi Iwai
Quoted 3 lines · Vinod Koul

+void azx_parse_capabilities(struct azx *chip)

Please give a bit more comments about the function.

Sure thing, will add.

Quoted 11 lines
Quoted 11 lines
sound/pci/hda/hda_controller.c +11 -0
+	/* Lets walk the linked capabilities list */
+	do {
+		cur_cap = _snd_hdac_chip_read(l, azx_bus(chip), offset);
+
+		switch ((cur_cap & CAP_HDR_ID_MASK) >> CAP_HDR_ID_OFF) {
+		case GTS_CAP_ID:
+			dev_dbg(chip->card->dev, "Found GTS capability");
+			chip->gts_present = 1;
+			break;
+
+		default:
Quoted 8 lines

sound/pci/hda/hda_controller.c static struct snd_pcm_hardware azx_pcm_hw = { · line 419

Quoted 6 lines
sound/pci/hda/hda_controller.c +6 -0
+			break;
+		}
+
+		/* read the offset of next capabiity */
+		offset = cur_cap & CAP_HDR_NXT_PTR_MASK;
+	} while (offset);

It's be safer to have a counter not to go over the endless loop.

I do agree a broken hw can cause issues, so will add that as well.

Quoted 6 lines

sound/pci/hda/hda_controller.c static int azx_pcm_open(struct snd_pcm_substream *substream) · line 445

Quoted 4 lines
sound/pci/hda/hda_controller.c +3 -0
 	runtime->private_data = azx_dev;
+
+	/* CPU must have ART for reporting link synchronized time */
+	if (chip->gts_present && boot_cpu_has(X86_FEATURE_ART))

This comes out of sudden. It needs more explanation.

Ah, this was merged in last window. We cna check of cpu is capable of ART, and in these cases only we cna report these timestamps

Quoted 11 lines

sound/pci/hda/hda_intel.c static int azx_first_init(struct azx *chip) · line 1652

Quoted 9 lines
sound/pci/hda/hda_intel.c +1 -0
index 9a0d1445ca5c..b4ebdde59398 100644
@@ -1649,6 +1649,7 @@ static int azx_first_init(struct azx *chip)
 		return -ENXIO;
 	}
 
+	azx_parse_capabilities(chip);

Is it really safe to call the function no matter which chip?

I think so, since we read base HDA registers for capablity. For older hw the next capablity will not be there.

But yes I will verify this on older machines.

Signature · 1 line
~Vinod
#4 lore raw

Re: [PATCH 1/3] ALSA - hda: Add support for GTS capability

Quoted 9 lines · Vinod Koul
Quoted 9 lines
Quoted 9 lines
sound/pci/hda/hda_intel.c +0 -0
index 9a0d1445ca5c..b4ebdde59398 100644
@@ -1649,6 +1649,7 @@ static int azx_first_init(struct azx *chip)
 		return -ENXIO;
 	}
 
Quoted 8 lines
Quoted 3 lines

sound/pci/hda/hda_intel.c static int azx_first_init(struct azx *chip) · line 1652

Quoted 1 line
sound/pci/hda/hda_intel.c +1 -0
+	azx_parse_capabilities(chip);

Is it really safe to call the function no matter which chip?

I think so, since we read base HDA registers for capablity. For older hw the next capablity will not be there.

But yes I will verify this on older machines.

I checked the spec 1.0 and 1.0a, and there is no definition for the register offset 0x14. So, it's likely unsafe to use it unconditionally.

Takashi

author
#5 lore raw

Re: [PATCH 1/3] ALSA - hda: Add support for GTS capability

Quoted 15 lines · Takashi Iwai
Quoted 13 lines · Vinod Koul
Quoted 12 lines

sound/pci/hda/hda_intel.c static int azx_first_init(struct azx *chip) · line 1652

Quoted 10 lines
sound/pci/hda/hda_intel.c +1 -0
index 9a0d1445ca5c..b4ebdde59398 100644
@@ -1649,6 +1649,7 @@ static int azx_first_init(struct azx *chip)
 		return -ENXIO;
 	}
 
+	azx_parse_capabilities(chip);

Is it really safe to call the function no matter which chip?

Quoted 8 lines
Quoted 4 lines

I think so, since we read base HDA registers for capablity. For older hw the next capablity will not be there.

But yes I will verify this on older machines.

I checked the spec 1.0 and 1.0a, and there is no definition for the register offset 0x14. So, it's likely unsafe to use it unconditionally.

Ah okay, let me check.

Worst case we cna use SKL_PLUS for this as it is defined for SKL and beyond.

Signature · 1 line
~Vinod
#6 lore raw

Re: [PATCH 1/3] ALSA - hda: Add support for GTS capability

Quoted 22 lines · Vinod Koul
Quoted 20 lines · Takashi Iwai
Quoted 17 lines · Vinod Koul
Quoted 9 lines
Quoted 9 lines
sound/pci/hda/hda_intel.c +0 -0
index 9a0d1445ca5c..b4ebdde59398 100644
@@ -1649,6 +1649,7 @@ static int azx_first_init(struct azx *chip)
 		return -ENXIO;
 	}
 
Quoted 3 lines

sound/pci/hda/hda_intel.c static int azx_first_init(struct azx *chip) · line 1652

Quoted 1 line
sound/pci/hda/hda_intel.c +1 -0
+	azx_parse_capabilities(chip);

Is it really safe to call the function no matter which chip?

I think so, since we read base HDA registers for capablity. For older hw the next capablity will not be there.

But yes I will verify this on older machines.

Quoted 7 lines
Quoted 3 lines

I checked the spec 1.0 and 1.0a, and there is no definition for the register offset 0x14. So, it's likely unsafe to use it unconditionally.

Ah okay, let me check.

Worst case we cna use SKL_PLUS for this as it is defined for SKL and beyond.

Yes.

Takashi

author
#7 lore raw

PATCH 2/3 ALSA - hda: Add support for link audio time reporting

In reply to Vinod Koul

From: Guneshwor Singh <[email protected]>

Skylake onwards HDA controller supports reprting link audio time, so add support for that.

---
 sound/pci/hda/hda_controller.c | 159 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 158 insertions(+), 1 deletion(-)
sound/pci/hda/hda_controller.c +158 -1
index 9833666c6108..5613a403d720 100644
@@ -27,6 +27,7 @@
 #include <linux/module.h>
 #include <linux/pm_runtime.h>
 #include <linux/slab.h>
+#include <asm/tsc.h>
 #include <sound/core.h>
 #include <sound/initval.h>
 #include "hda_controller.h"
@@ -34,6 +35,8 @@
 #define CREATE_TRACE_POINTS
 #include "hda_controller_trace.h"
 
+#define SEC_TO_NSEC	1000000000LL
+
 /* DSP lock helpers */
 #define dsp_lock(dev)		snd_hdac_dsp_lock(azx_stream(dev))
 #define dsp_unlock(dev)		snd_hdac_dsp_unlock(azx_stream(dev))
@@ -337,12 +340,136 @@ static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
 			       azx_get_position(chip, azx_dev));
 }
 
+static u64 azx_scale64(u64 base, u32 num, u32 den)
+{
+	u64 rem;
+
+	rem = do_div(base, den);
+
+	base *= num;
+	rem *= num;
+
+	do_div(rem, den);
+
+	return base + rem;
+}
+
+static int azx_get_sync_time(ktime_t *device,
+		struct system_counterval_t *system, void *ctx)
+{
+	struct snd_pcm_substream *substream = (struct snd_pcm_substream *)ctx;
+	struct azx_dev *azx_dev = get_azx_dev(substream);
+	struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
+	struct azx *chip = apcm->chip;
+	struct snd_pcm_runtime *runtime;
+	u64 ll_counter, ll_counter_l, ll_counter_h;
+	u64 tsc_counter, tsc_counter_l, tsc_counter_h;
+	u32 wallclk_ctr, wallclk_cycles;
+	bool direction;
+	u32 dma_select;
+	u32 timeout = 200;
+	u32 retry_count = 0;
+
+	runtime = substream->runtime;
+
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		direction = 1;
+	else
+		direction = 0;
+
+	/* 0th stream tag is not used, so DMA ch 0 is for 1st stream tag */
+	do {
+		timeout = 100;
+		dma_select = (direction << GTSCC_CDMAS_DMA_DIR_SHIFT) |
+					(azx_dev->core.stream_tag - 1);
+		_snd_hdac_chip_write(l, azx_bus(chip), AZX_REG_GTSCC,
+						dma_select);
+		/* Enable the capture */
+		_snd_hdac_chip_write(l, azx_bus(chip), AZX_REG_GTSCC,
+				     _snd_hdac_chip_read(l, azx_bus(chip),
+					AZX_REG_GTSCC) | GTSCC_TSCCI_MASK);
+
+		while (timeout) {
+			if (_snd_hdac_chip_read(l, azx_bus(chip),
+				AZX_REG_GTSCC) & GTSCC_TSCCD_MASK)
+				break;
+			timeout--;
+		}
+
+		if (!timeout) {
+			dev_err(chip->card->dev, "GTSCC capture Timedout!\n");
+			return -EIO;
+		}
+
+		/* Read wall clock counter */
+		wallclk_ctr = _snd_hdac_chip_read(l, azx_bus(chip),
+						  AZX_REG_WALFCC);
+
+		/* Read TSC counter */
+		tsc_counter_l = _snd_hdac_chip_read(l, azx_bus(chip),
+						    AZX_REG_TSCCL);
+		tsc_counter_h = _snd_hdac_chip_read(l, azx_bus(chip),
+						    AZX_REG_TSCCU);
+
+		/* Read Link counter */
+		ll_counter_l = _snd_hdac_chip_read(l, azx_bus(chip),
+						   AZX_REG_LLPCL);
+		ll_counter_h = _snd_hdac_chip_read(l, azx_bus(chip),
+						   AZX_REG_LLPCU);
+
+		/* Ack: registers read done */
+		_snd_hdac_chip_write(l, azx_bus(chip),
+				     AZX_REG_GTSCC,
+				     (0x1 << GTSCC_TSCCD_SHIFT));
+
+		tsc_counter = (tsc_counter_h << TSCCU_CCU_SHIFT) |
+						tsc_counter_l;
+
+		ll_counter = (ll_counter_h << LLPC_CCU_SHIFT) |	ll_counter_l;
+		wallclk_cycles = wallclk_ctr & WALFCC_CIF_MASK;
+
+		if (wallclk_cycles < HDA_MAX_CYCLE_VALUE - HDA_MAX_CYCLE_OFFSET
+		    && wallclk_cycles > HDA_MAX_CYCLE_OFFSET)
+			break;
+
+		/*
+		 * Sleep before we read again, else we may again get
+		 * value near to MAX_CYCLE. Try to sleep for different
+		 * amount of time so we dont hit the same number again
+		 */
+		udelay(retry_count++);
+	} while (retry_count != HDA_MAX_CYCLE_READ_RETRY);
+
+	if (retry_count == HDA_MAX_CYCLE_READ_RETRY) {
+		dev_err(chip->card->dev, "Error in WALFCC cycle count\n");
+		return -EIO;
+	}
+
+	*device = ns_to_ktime(azx_scale64(ll_counter,
+				SEC_TO_NSEC, runtime->rate));
+	*device = ktime_add_ns(*device, (wallclk_cycles * SEC_TO_NSEC) /
+			       ((HDA_MAX_CYCLE_VALUE+1) * runtime->rate));
+
+	*system = convert_art_to_tsc(tsc_counter);
+
+	return 0;
+}
+
+static int azx_get_crosststamp(struct snd_pcm_substream *substream,
+			      struct system_device_crosststamp *xtstamp)
+{
+	return get_device_system_crosststamp(azx_get_sync_time,
+					substream, NULL, xtstamp);
+}
+
 static int azx_get_time_info(struct snd_pcm_substream *substream,
 			struct timespec *system_ts, struct timespec *audio_ts,
 			struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
 			struct snd_pcm_audio_tstamp_report *audio_tstamp_report)
 {
 	struct azx_dev *azx_dev = get_azx_dev(substream);
+	struct snd_pcm_runtime *runtime = substream->runtime;
+	struct system_device_crosststamp xtstamp;
 	u64 nsec;
 
 	if ((substream->runtime->hw.info & SNDRV_PCM_INFO_HAS_LINK_ATIME) &&
@@ -361,8 +488,38 @@ static int azx_get_time_info(struct snd_pcm_substream *substream,
 		audio_tstamp_report->accuracy_report = 1; /* rest of structure is valid */
 		audio_tstamp_report->accuracy = 42; /* 24 MHz WallClock == 42ns resolution */
 
-	} else
+	} else if ((runtime->hw.info &
+			SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME) &&
+			(audio_tstamp_config->type_requested ==
+			SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED)) {
+
+		azx_get_crosststamp(substream, &xtstamp);
+
+		switch (runtime->tstamp_type) {
+		case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC:
+			return -EINVAL;
+
+		case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW:
+			*system_ts = ktime_to_timespec(xtstamp.sys_monoraw);
+			break;
+
+		default:
+			*system_ts = ktime_to_timespec(xtstamp.sys_realtime);
+			break;
+
+		}
+
+		*audio_ts = ktime_to_timespec(xtstamp.device);
+
+		audio_tstamp_report->actual_type =
+			SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED;
+		audio_tstamp_report->accuracy_report = 1;
+		/* 24 MHz WallClock == 42ns resolution */
+		audio_tstamp_report->accuracy = 42;
+
+	} else {
 		audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT;
+	}
 
 	return 0;
 }
Signature · 1 line
1.9.1
#8 lore raw
Quoted 5 lines · Vinod Koul

From: Guneshwor Singh <[email protected]>

Skylake onwards HDA controller supports reprting link audio time, so add support for that.

It's way too few description, the text is almost same as the previous patch. Please give more information.

Quoted 21 lines
---
 sound/pci/hda/hda_controller.c | 159 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 158 insertions(+), 1 deletion(-)
sound/pci/hda/hda_controller.c +1 -0
index 9833666c6108..5613a403d720 100644
@@ -27,6 +27,7 @@
 #include <linux/module.h>
 #include <linux/pm_runtime.h>
 #include <linux/slab.h>
+#include <asm/tsc.h>
 #include <sound/core.h>
 #include <sound/initval.h>
 #include "hda_controller.h"

sound/pci/hda/hda_controller.c line 38

Quoted 4 lines
sound/pci/hda/hda_controller.c +1 -0
@@ -34,6 +35,8 @@
 #define CREATE_TRACE_POINTS
 #include "hda_controller_trace.h"
 
+#define SEC_TO_NSEC	1000000000LL

Can we use a definition in time64.h?

Quoted 10 lines
sound/pci/hda/hda_controller.c +3 -0
 /* DSP lock helpers */
 #define dsp_lock(dev)		snd_hdac_dsp_lock(azx_stream(dev))
 #define dsp_unlock(dev)		snd_hdac_dsp_unlock(azx_stream(dev))
@@ -337,12 +340,136 @@ static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
 			       azx_get_position(chip, azx_dev));
 }
 
+static u64 azx_scale64(u64 base, u32 num, u32 den)
+{
+	u64 rem;

sound/pci/hda/hda_controller.c static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream) · line 355

Quoted 10 lines
sound/pci/hda/hda_controller.c +10 -0
+
+	rem = do_div(base, den);
+
+	base *= num;
+	rem *= num;
+
+	do_div(rem, den);
+
+	return base + rem;
+}

What is this function supposed to do?

Quoted 67 lines
sound/pci/hda/hda_controller.c +67 -0
+static int azx_get_sync_time(ktime_t *device,
+		struct system_counterval_t *system, void *ctx)
+{
+	struct snd_pcm_substream *substream = (struct snd_pcm_substream *)ctx;
+	struct azx_dev *azx_dev = get_azx_dev(substream);
+	struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
+	struct azx *chip = apcm->chip;
+	struct snd_pcm_runtime *runtime;
+	u64 ll_counter, ll_counter_l, ll_counter_h;
+	u64 tsc_counter, tsc_counter_l, tsc_counter_h;
+	u32 wallclk_ctr, wallclk_cycles;
+	bool direction;
+	u32 dma_select;
+	u32 timeout = 200;
+	u32 retry_count = 0;
+
+	runtime = substream->runtime;
+
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		direction = 1;
+	else
+		direction = 0;
+
+	/* 0th stream tag is not used, so DMA ch 0 is for 1st stream tag */
+	do {
+		timeout = 100;
+		dma_select = (direction << GTSCC_CDMAS_DMA_DIR_SHIFT) |
+					(azx_dev->core.stream_tag - 1);
+		_snd_hdac_chip_write(l, azx_bus(chip), AZX_REG_GTSCC,
+						dma_select);
+		/* Enable the capture */
+		_snd_hdac_chip_write(l, azx_bus(chip), AZX_REG_GTSCC,
+				     _snd_hdac_chip_read(l, azx_bus(chip),
+					AZX_REG_GTSCC) | GTSCC_TSCCI_MASK);
+
+		while (timeout) {
+			if (_snd_hdac_chip_read(l, azx_bus(chip),
+				AZX_REG_GTSCC) & GTSCC_TSCCD_MASK)
+				break;
+			timeout--;
+		}
+
+		if (!timeout) {
+			dev_err(chip->card->dev, "GTSCC capture Timedout!\n");
+			return -EIO;
+		}
+
+		/* Read wall clock counter */
+		wallclk_ctr = _snd_hdac_chip_read(l, azx_bus(chip),
+						  AZX_REG_WALFCC);
+
+		/* Read TSC counter */
+		tsc_counter_l = _snd_hdac_chip_read(l, azx_bus(chip),
+						    AZX_REG_TSCCL);
+		tsc_counter_h = _snd_hdac_chip_read(l, azx_bus(chip),
+						    AZX_REG_TSCCU);
+
+		/* Read Link counter */
+		ll_counter_l = _snd_hdac_chip_read(l, azx_bus(chip),
+						   AZX_REG_LLPCL);
+		ll_counter_h = _snd_hdac_chip_read(l, azx_bus(chip),
+						   AZX_REG_LLPCU);
+
+		/* Ack: registers read done */
+		_snd_hdac_chip_write(l, azx_bus(chip),
+				     AZX_REG_GTSCC,
+				     (0x1 << GTSCC_TSCCD_SHIFT));

sound/pci/hda/hda_controller.c static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream) · line 433

Quoted 10 lines
sound/pci/hda/hda_controller.c +10 -0
+
+		tsc_counter = (tsc_counter_h << TSCCU_CCU_SHIFT) |
+						tsc_counter_l;
+
+		ll_counter = (ll_counter_h << LLPC_CCU_SHIFT) |	ll_counter_l;
+		wallclk_cycles = wallclk_ctr & WALFCC_CIF_MASK;
+
+		if (wallclk_cycles < HDA_MAX_CYCLE_VALUE - HDA_MAX_CYCLE_OFFSET
+		    && wallclk_cycles > HDA_MAX_CYCLE_OFFSET)
+			break;

Is this condition really correct...? It's hard to understand.

Quoted 8 lines
sound/pci/hda/hda_controller.c +8 -0
+
+		/*
+		 * Sleep before we read again, else we may again get
+		 * value near to MAX_CYCLE. Try to sleep for different
+		 * amount of time so we dont hit the same number again
+		 */
+		udelay(retry_count++);
+	} while (retry_count != HDA_MAX_CYCLE_READ_RETRY);

sound/pci/hda/hda_controller.c static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream) · line 451

Quoted 10 lines
sound/pci/hda/hda_controller.c +10 -0
+
+	if (retry_count == HDA_MAX_CYCLE_READ_RETRY) {
+		dev_err(chip->card->dev, "Error in WALFCC cycle count\n");
+		return -EIO;
+	}
+
+	*device = ns_to_ktime(azx_scale64(ll_counter,
+				SEC_TO_NSEC, runtime->rate));
+	*device = ktime_add_ns(*device, (wallclk_cycles * SEC_TO_NSEC) /
+			       ((HDA_MAX_CYCLE_VALUE+1) * runtime->rate));

Hmm, the calculation here looks as if there can be an optimization...

thanks,

Takashi

Quoted 66 lines
sound/pci/hda/hda_controller.c +45 -1
+	*system = convert_art_to_tsc(tsc_counter);
+
+	return 0;
+}
+
+static int azx_get_crosststamp(struct snd_pcm_substream *substream,
+			      struct system_device_crosststamp *xtstamp)
+{
+	return get_device_system_crosststamp(azx_get_sync_time,
+					substream, NULL, xtstamp);
+}
+
 static int azx_get_time_info(struct snd_pcm_substream *substream,
 			struct timespec *system_ts, struct timespec *audio_ts,
 			struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
 			struct snd_pcm_audio_tstamp_report *audio_tstamp_report)
 {
 	struct azx_dev *azx_dev = get_azx_dev(substream);
+	struct snd_pcm_runtime *runtime = substream->runtime;
+	struct system_device_crosststamp xtstamp;
 	u64 nsec;
 
 	if ((substream->runtime->hw.info & SNDRV_PCM_INFO_HAS_LINK_ATIME) &&
@@ -361,8 +488,38 @@ static int azx_get_time_info(struct snd_pcm_substream *substream,
 		audio_tstamp_report->accuracy_report = 1; /* rest of structure is valid */
 		audio_tstamp_report->accuracy = 42; /* 24 MHz WallClock == 42ns resolution */
 
-	} else
+	} else if ((runtime->hw.info &
+			SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME) &&
+			(audio_tstamp_config->type_requested ==
+			SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED)) {
+
+		azx_get_crosststamp(substream, &xtstamp);
+
+		switch (runtime->tstamp_type) {
+		case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC:
+			return -EINVAL;
+
+		case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW:
+			*system_ts = ktime_to_timespec(xtstamp.sys_monoraw);
+			break;
+
+		default:
+			*system_ts = ktime_to_timespec(xtstamp.sys_realtime);
+			break;
+
+		}
+
+		*audio_ts = ktime_to_timespec(xtstamp.device);
+
+		audio_tstamp_report->actual_type =
+			SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED;
+		audio_tstamp_report->accuracy_report = 1;
+		/* 24 MHz WallClock == 42ns resolution */
+		audio_tstamp_report->accuracy = 42;
+
+	} else {
 		audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT;
+	}
 
 	return 0;
 }
Signature · 1 line
1.9.1
author
#9 lore raw
Quoted 10 lines · Takashi Iwai
Quoted 5 lines · Vinod Koul

From: Guneshwor Singh <[email protected]>

Skylake onwards HDA controller supports reprting link audio time, so add support for that.

It's way too few description, the text is almost same as the previous patch. Please give more information.

Sure will add.

Quoted 6 lines
Quoted 4 lines

#define CREATE_TRACE_POINTS
#include "hda_controller_trace.h"

+#define SEC_TO_NSEC 1000000000LL

Can we use a definition in time64.h?

Yes NSEC_PER_SEC seems right, will update. Thanks for pointing

Quoted 16 lines
Quoted 4 lines
sound/pci/hda/hda_controller.c +3 -0
+static u64 azx_scale64(u64 base, u32 num, u32 den)
+{
+	u64 rem;

sound/pci/hda/hda_controller.c static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream) · line 355

Quoted 10 lines
sound/pci/hda/hda_controller.c +10 -0
+
+	rem = do_div(base, den);
+
+	base *= num;
+	rem *= num;
+
+	do_div(rem, den);
+
+	return base + rem;
+}

What is this function supposed to do?

It is supposed to scale the timestamp values. Will try to add more comments on this one.

Quoted 8 lines

sound/pci/hda/hda_controller.c static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream) · line 433

Quoted 6 lines
sound/pci/hda/hda_controller.c +6 -0
+		ll_counter = (ll_counter_h << LLPC_CCU_SHIFT) |	ll_counter_l;
+		wallclk_cycles = wallclk_ctr & WALFCC_CIF_MASK;
+
+		if (wallclk_cycles < HDA_MAX_CYCLE_VALUE - HDA_MAX_CYCLE_OFFSET
+		    && wallclk_cycles > HDA_MAX_CYCLE_OFFSET)
+			break;

Is this condition really correct...? It's hard to understand.

Looks so, i will double check

Quoted 4 lines

sound/pci/hda/hda_controller.c static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream) · line 451

Quoted 2 lines
sound/pci/hda/hda_controller.c +2 -0
+	*device = ktime_add_ns(*device, (wallclk_cycles * SEC_TO_NSEC) /
+			       ((HDA_MAX_CYCLE_VALUE+1) * runtime->rate));

Hmm, the calculation here looks as if there can be an optimization...

Hmmm, let me try to optimize this bit

Signature · 1 line
~Vinod

A message that is not in the archive (sent off-list or not yet received): 201607111916.R5HdrB76%[email protected]

author
#11 lore raw
Quoted 16 lines · kbuild test robot

Hi,

[auto build test ERROR on sound/for-next]
[also build test ERROR on v4.7-rc7 next-20160711]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Vinod-Koul/ALSA-hda-Add-support-for-link-audio-time-reporting/20160711-180949
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
config: arm-multi_v7_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 5.3.1-8) 5.3.1 20160205

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm

Quoted 4 lines

All errors (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

sound/pci/hda/hda_controller.c:30:21: fatal error: asm/tsc.h: No such file or directory

compilation terminated.

Okay i think I need to move this bit into the intel code.

Takashi, I didnt see any X86 depends on SND_HDA_INTEL. I think we should add this now. Are you okay with that?

Thanks

Quoted 10 lines
    24	#include <linux/delay.h>
    25	#include <linux/interrupt.h>
    26	#include <linux/kernel.h>
    27	#include <linux/module.h>
    28	#include <linux/pm_runtime.h>
    29	#include <linux/slab.h>
Quoted 1 line

30 #include <asm/tsc.h>

    31	#include <sound/core.h>
    32	#include <sound/initval.h>
    33	#include "hda_controller.h"
Signature · 1 line
~Vinod
#12 lore raw
Quoted 20 lines · Vinod Koul
Quoted 18 lines · kbuild test robot

Hi,

[auto build test ERROR on sound/for-next]
[also build test ERROR on v4.7-rc7 next-20160711]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Vinod-Koul/ALSA-hda-Add-support-for-link-audio-time-reporting/20160711-180949
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
config: arm-multi_v7_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 5.3.1-8) 5.3.1 20160205

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm

All errors (new ones prefixed by >>):

Quoted 7 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line

sound/pci/hda/hda_controller.c:30:21: fatal error: asm/tsc.h: No such file or directory

compilation terminated.

Okay i think I need to move this bit into the intel code.

Takashi, I didnt see any X86 depends on SND_HDA_INTEL. I think we should add this now. Are you okay with that?

Better to have an explicit ifdef CONFIG_X86 around it. It's not only for x86.

Takashi

author
#13 lore raw
Quoted 25 lines · Takashi Iwai
Quoted 23 lines · Vinod Koul
Quoted 20 lines · kbuild test robot

Hi,

[auto build test ERROR on sound/for-next]
[also build test ERROR on v4.7-rc7 next-20160711]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Vinod-Koul/ALSA-hda-Add-support-for-link-audio-time-reporting/20160711-180949
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
config: arm-multi_v7_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 5.3.1-8) 5.3.1 20160205

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm

All errors (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

sound/pci/hda/hda_controller.c:30:21: fatal error: asm/tsc.h: No such file or directory

compilation terminated.

Quoted 7 lines
Quoted 4 lines

Okay i think I need to move this bit into the intel code.

Takashi, I didnt see any X86 depends on SND_HDA_INTEL. I think we should add this now. Are you okay with that?

Better to have an explicit ifdef CONFIG_X86 around it. It's not only for x86.

Need it around the whole of the timestamp code as well then..

Yes the HDA controller is not x86 specfic, but the hda-intel should be, right? This would make me move all this code into hda_intel.c as well..

Signature · 1 line
~Vinod
#14 lore raw
Quoted 29 lines · Vinod Koul
Quoted 27 lines · Takashi Iwai
Quoted 25 lines · Vinod Koul
Quoted 16 lines · kbuild test robot

Hi,

[auto build test ERROR on sound/for-next]
[also build test ERROR on v4.7-rc7 next-20160711]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Vinod-Koul/ALSA-hda-Add-support-for-link-audio-time-reporting/20160711-180949
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
config: arm-multi_v7_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 5.3.1-8) 5.3.1 20160205

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm

Quoted 4 lines

All errors (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

sound/pci/hda/hda_controller.c:30:21: fatal error: asm/tsc.h: No such file or directory

compilation terminated.

Okay i think I need to move this bit into the intel code.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Takashi, I didnt see any X86 depends on SND_HDA_INTEL. I think we should add this now. Are you okay with that?

Better to have an explicit ifdef CONFIG_X86 around it. It's not only for x86.

Need it around the whole of the timestamp code as well then..

Yes. But why TSC is mandatory? There is no explanation in your patch.

Quoted 2 lines

Yes the HDA controller is not x86 specfic, but the hda-intel should be, right?

No, the driver depends on PCI, but not on CPU.

thanks,

Takashi

author
#15 lore raw
Quoted 10 lines · Takashi Iwai
Quoted 8 lines · Vinod Koul
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line

sound/pci/hda/hda_controller.c:30:21: fatal error: asm/tsc.h: No such file or directory

compilation terminated.

Okay i think I need to move this bit into the intel code.

Takashi, I didnt see any X86 depends on SND_HDA_INTEL. I think we should add this now. Are you okay with that?

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Better to have an explicit ifdef CONFIG_X86 around it. It's not only for x86.

Need it around the whole of the timestamp code as well then..

Yes. But why TSC is mandatory? There is no explanation in your patch.

HW reports ART values and we need to convert these to TSC.

The callflow is that the azx_get_crosststamp is called which invokes get_device_system_crosststamp() and calls azx_get_sync_time callback.

So dependency is around convert_art_to_tsc() which is x86 API.

Thanks

Signature · 1 line
~Vinod
#16 lore raw
Quoted 20 lines · Vinod Koul
Quoted 10 lines · Takashi Iwai
Quoted 8 lines · Vinod Koul
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line

sound/pci/hda/hda_controller.c:30:21: fatal error: asm/tsc.h: No such file or directory

compilation terminated.

Okay i think I need to move this bit into the intel code.

Takashi, I didnt see any X86 depends on SND_HDA_INTEL. I think we should add this now. Are you okay with that?

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Better to have an explicit ifdef CONFIG_X86 around it. It's not only for x86.

Need it around the whole of the timestamp code as well then..

Yes. But why TSC is mandatory? There is no explanation in your patch.

Quoted 6 lines

HW reports ART values and we need to convert these to TSC.

The callflow is that the azx_get_crosststamp is called which invokes get_device_system_crosststamp() and calls azx_get_sync_time callback.

So dependency is around convert_art_to_tsc() which is x86 API.

How is defined in the spec? I wonder it because HD-audio spec itself is usually CPU-neutral.

Takashi

author
#17 lore raw
Quoted 5 lines · Takashi Iwai
Quoted 2 lines

So dependency is around convert_art_to_tsc() which is x86 API.

How is defined in the spec? I wonder it because HD-audio spec itself is usually CPU-neutral.

You are right. HDA spec is not x86 specfic. HDA counter report the value of ART counter for a time snapshot.

The problem is we do not get TSC value from HDA controller :(

So we need to use asm code for conversion..

Thanks

Signature · 1 line
~Vinod
#18 lore raw
Quoted 8 lines · Vinod Koul
Quoted 5 lines · Takashi Iwai
Quoted 2 lines

So dependency is around convert_art_to_tsc() which is x86 API.

How is defined in the spec? I wonder it because HD-audio spec itself is usually CPU-neutral.

Quoted 6 lines

You are right. HDA spec is not x86 specfic. HDA counter report the value of ART counter for a time snapshot.

The problem is we do not get TSC value from HDA controller :(

So we need to use asm code for conversion..

OK, then let's cover the relevant code with ifdef CONFIG_X86 as a temporary workaround until we get a more universal solution.

Takashi

author
#19 lore raw

PATCH 3/3 ALSA - hda: Fix timestamping documentation

In reply to Vinod Koul

Some typos in the documentation, so fix them up.

---
 Documentation/sound/alsa/timestamping.txt | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Documentation/sound/alsa/timestamping.txt +6 -6
index 1b6473f393a8..9d579aefbffd 100644
@@ -14,7 +14,7 @@ provides a refined estimate with a delay.
 event or application query.
 The difference (tstamp - trigger_tstamp) defines the elapsed time.
 
-The ALSA API provides reports two basic pieces of information, avail
+The ALSA API provides two basic pieces of information, avail
 and delay, which combined with the trigger and current system
 timestamps allow for applications to keep track of the 'fullness' of
 the ring buffer and the amount of queued samples.
@@ -53,21 +53,21 @@ case):
 The analog time is taken at the last stage of the playback, as close
 as possible to the actual transducer
 
-The link time is taken at the output of the SOC/chipset as the samples
+The link time is taken at the output of the SoC/chipset as the samples
 are pushed on a link. The link time can be directly measured if
 supported in hardware by sample counters or wallclocks (e.g. with
 HDAudio 24MHz or PTP clock for networked solutions) or indirectly
 estimated (e.g. with the frame counter in USB).
 
 The DMA time is measured using counters - typically the least reliable
-of all measurements due to the bursty natured of DMA transfers.
+of all measurements due to the bursty nature of DMA transfers.
 
 The app time corresponds to the time tracked by an application after
 writing in the ring buffer.
 
-The application can query what the hardware supports, define which
+The application can query the hardware capabilities, define which
 audio time it wants reported by selecting the relevant settings in
-audio_tstamp_config fields, get an estimate of the timestamp
+audio_tstamp_config fields, thus get an estimate of the timestamp
 accuracy. It can also request the delay-to-analog be included in the
 measurement. Direct access to the link time is very interesting on
 platforms that provide an embedded DSP; measuring directly the link
@@ -169,7 +169,7 @@ playback: systime: 938107562 nsec, audio time 938112708 nsec, 	systime delta -51
 Example 1 shows that the timestamp at the DMA level is close to 1ms
 ahead of the actual playback time (as a side time this sort of
 measurement can help define rewind safeguards). Compensating for the
-DMA-link delay in example 2 helps remove the hardware buffering abut
+DMA-link delay in example 2 helps remove the hardware buffering but
 the information is still very jittery, with up to one sample of
 error. In example 3 where the timestamps are measured with the link
 wallclock, the timestamps show a monotonic behavior and a lower
Signature · 1 line
1.9.1
Applied
#20 lore raw

Re: [PATCH 3/3] ALSA - hda: Fix timestamping documentation

Quoted 4 lines · Vinod Koul

Some typos in the documentation, so fix them up.

Applied this one, thanks.

Takashi

author
#21 lore raw

Re: [PATCH 3/3] ALSA - hda: Fix timestamping documentation

Quoted 8 lines · Takashi Iwai
Quoted 4 lines · Vinod Koul

Some typos in the documentation, so fix them up.

Applied this one, thanks.

Thanks :)

Signature · 1 line
~Vinod