All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Vinod Koul <vinod.koul@intel.com>
Cc: alsa-devel@alsa-project.org, patches.audio@intel.com,
	Hardik T Shah <hardik.t.shah@intel.com>,
	Guneshwor Singh <guneshwor.o.singh@intel.com>,
	liam.r.girdwood@linux.intel.com, broonie@kernel.org
Subject: Re: [PATCH v3 5/5] ALSA - hda: Add support for link audio time reporting
Date: Wed, 03 Aug 2016 18:21:07 +0200	[thread overview]
Message-ID: <s5hh9b19630.wl-tiwai@suse.de> (raw)
In-Reply-To: <1470240374-20018-6-git-send-email-vinod.koul@intel.com>

On Wed, 03 Aug 2016 18:06:14 +0200,
Vinod Koul wrote:
> +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;

Superfluous cast.

> +	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);

You can use
		snd_hdac_chip_writel(azx_bus(chip), GTSCC, dma_select);

The use of _snd_hdac_chip_write() is for non-constant registers.  When
you pass AZX_REG_XXX, you can use the standard macro.  For example:


> +		/* 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);

This can be simplified with snd_hdac_chip_updatel().

> +
> +		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;
> +
> +		/*
> +		 * 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 i.e.,
> +		 * HDA_MAX_CYCLE_OFFSET
> +		 */
> +		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");

Hrm, this has a danger to spew huge amount of error messages, since
this gets called so often.


> +		return -EIO;
> +	}
> +
> +	*device = ns_to_ktime(azx_scale64(ll_counter,
> +				NSEC_PER_SEC, runtime->rate));
> +	*device = ktime_add_ns(*device, (wallclk_cycles * NSEC_PER_SEC) /
> +			       ((HDA_MAX_CYCLE_VALUE + 1) * runtime->rate));
> +
> +	*system = convert_art_to_tsc(tsc_counter);
> +
> +	return 0;
> +}
> +
> +#else
> +static int azx_get_sync_time(ktime_t *device,
> +		struct system_counterval_t *system, void *ctx)
> +{
> +	return -ENXIO;
> +}
> +#endif
> +
> +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 +524,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)) {

The indentation is hard to follow here...

> +
> +		azx_get_crosststamp(substream, &xtstamp);

No error check?


thanks,

Takashi

> +
> +		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;
>  }
> -- 
> 1.9.1
> 

  reply	other threads:[~2016-08-03 16:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-03 16:06 [PATCH v3 0/5] ALSA - hda: Add support for link audio time reporting Vinod Koul
2016-08-03 16:06 ` [PATCH v3 1/5] ALSA: hda - move bus_parse_capabilities to core Vinod Koul
2016-08-03 16:09   ` Takashi Iwai
2016-08-04  1:56     ` Vinod Koul
2016-08-03 16:06 ` [PATCH v3 2/5] ALSA: convert users to core bus_parse_capabilities Vinod Koul
2016-08-09 12:44   ` Applied "ALSA: convert users to core bus_parse_capabilities" to the asoc tree Mark Brown
2016-08-03 16:06 ` [PATCH v3 3/5] ALSA - Ext hda: remove bus_parse_capabilities Vinod Koul
2016-08-09 12:44   ` Applied "ALSA - Ext hda: remove bus_parse_capabilities" to the asoc tree Mark Brown
2016-08-03 16:06 ` [PATCH v3 4/5] ALSA - hda: Add support for parsing new HDA capabilities Vinod Koul
2016-08-03 16:11   ` Takashi Iwai
2016-08-04  2:00     ` Vinod Koul
2016-08-04  5:51       ` Vinod Koul
2016-08-04  5:46         ` Takashi Iwai
2016-08-03 16:06 ` [PATCH v3 5/5] ALSA - hda: Add support for link audio time reporting Vinod Koul
2016-08-03 16:21   ` Takashi Iwai [this message]
2016-08-04  2:00     ` Vinod Koul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5hh9b19630.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=guneshwor.o.singh@intel.com \
    --cc=hardik.t.shah@intel.com \
    --cc=liam.r.girdwood@linux.intel.com \
    --cc=patches.audio@intel.com \
    --cc=vinod.koul@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.