Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp437520ybg; Sun, 26 Jul 2020 09:17:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjxe9L19IqQvNIePR7SAzsqfrVmxzWp0qqK//wQx5aSiDSRA2oA7LYgv1ZcEO/WNmaJVsw X-Received: by 2002:a17:906:38d8:: with SMTP id r24mr3103584ejd.341.1595780225086; Sun, 26 Jul 2020 09:17:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595780225; cv=none; d=google.com; s=arc-20160816; b=PVWZ+rOjUVs1eO7ydi3G6SXrh2ZaZO/l4I/uFy9eAPq4dfVfG/cOOvCBKHMPQ3a7Zp K3ZVdC7tKd0ENuyVpmOdpyzJNTtDYgjKCcZMo6Ai6W3MUPCd4siSOAfOlqeIAbt+L2qZ gjuDh8VMEFPFAub3yMTQzFBlmL3jdGIiTqAOS26b6XW7Fzlb+wZ7eaYy6/uJ8kNeG0dH PGbpEAdpH7ARjRv6+rsXMFpVwX9hPRJrLI4gxzp0GlGPcT9jsmDoxtNHZ5yme2zJqlGP d50zwWD9yQ8n9geoPGbiwNGbrxaCKcgud/GLT/xExlKb4Ki7ko8xSjrQ1wMnJ7Pcv7dR H8ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=zya+CsBYJD7v4rtGCQP5sswenBeiYddhCjHVKbbwBrI=; b=LlCjCEjAwox/Cwo5pHK7EQNJ2+I4iiYZ3xrN5vE/ItQkmP/knba8nKPHNYYt9z5WO/ dUzdewwh1NmvGYdwXBsZw6jcvKHzi95q3MDyfJktcxCcm77a4XKfd7RHU8dczANaZdi/ r3l0feQdHgWUrAYcB06drtVUKryEaAoqqCK85ftlZROel1kNjDL9M9G3ZsyGRJzZxCo9 ZwJXmMTXPfB5Z5yVd3lKE+9xUMTY+UDW7cU/xLD/rRTcIvfAEFnSSjtHThwVxnscDGiz 5QQcUr9RdStd7FgEjY8jjlXGq/+iAIW0f3MJvcceigFyv6UyI1j18pL3b5ELn7K7SFcU jeLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l3si4207089ejd.17.2020.07.26.09.16.42; Sun, 26 Jul 2020 09:17:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726799AbgGZQNb (ORCPT + 99 others); Sun, 26 Jul 2020 12:13:31 -0400 Received: from mga06.intel.com ([134.134.136.31]:38650 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726044AbgGZQNb (ORCPT ); Sun, 26 Jul 2020 12:13:31 -0400 IronPort-SDR: gOPy6rNDnLt5QTCDYPnIFqs/BDrVESrejTS/z1MWUql4XTtWkLYDkBasgdaNweBCGie/YITFyU rZCJ4EbIVuYg== X-IronPort-AV: E=McAfee;i="6000,8403,9694"; a="212439391" X-IronPort-AV: E=Sophos;i="5.75,399,1589266800"; d="scan'208";a="212439391" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jul 2020 09:13:30 -0700 IronPort-SDR: yY+zWewQlmIQQ4SZm4+Nwpo6JVvW6PCWzRkaV6S7B8WFSsqloF5rtBvgtjoH2MxNNHuoXi08YD rVQppWcFXqng== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,399,1589266800"; d="scan'208";a="319798585" Received: from brentlu-desk0.itwn.intel.com ([10.5.253.11]) by orsmga008.jf.intel.com with ESMTP; 26 Jul 2020 09:13:28 -0700 From: Brent Lu To: alsa-devel@alsa-project.org Cc: Cezary Rojewski , Pierre-Louis Bossart , Liam Girdwood , Jie Yang , Mark Brown , Jaroslav Kysela , Takashi Iwai , Brent Lu , linux-kernel@vger.kernel.org Subject: [PATCH] ASoC: Intel: Atom: use hardware counter to update hw_ptr Date: Mon, 27 Jul 2020 00:08:47 +0800 Message-Id: <1595779727-31404-1-git-send-email-brent.lu@intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The ring buffer counter runs faster than hardware counter if the period size in hw_param is larger than 240. Although the differce is not much (around 2k frames), it causes false underrun in CRAS sometimes because it's using 256 frames as period size in hw_param. Using the hardware counter could provide precise hw_ptr to user space and avoid the false underrun in CRAS. Signed-off-by: Brent Lu --- sound/soc/intel/atom/sst/sst_drv_interface.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/sound/soc/intel/atom/sst/sst_drv_interface.c b/sound/soc/intel/atom/sst/sst_drv_interface.c index 7624953..1949ad9 100644 --- a/sound/soc/intel/atom/sst/sst_drv_interface.c +++ b/sound/soc/intel/atom/sst/sst_drv_interface.c @@ -485,7 +485,6 @@ static inline int sst_calc_tstamp(struct intel_sst_drv *ctx, struct snd_pcm_substream *substream, struct snd_sst_tstamp *fw_tstamp) { - size_t delay_bytes, delay_frames; size_t buffer_sz; u32 pointer_bytes, pointer_samples; @@ -493,22 +492,14 @@ static inline int sst_calc_tstamp(struct intel_sst_drv *ctx, fw_tstamp->ring_buffer_counter); dev_dbg(ctx->dev, "mrfld hardware_counter %llu in bytes\n", fw_tstamp->hardware_counter); - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) - delay_bytes = (size_t) (fw_tstamp->ring_buffer_counter - - fw_tstamp->hardware_counter); - else - delay_bytes = (size_t) (fw_tstamp->hardware_counter - - fw_tstamp->ring_buffer_counter); - delay_frames = bytes_to_frames(substream->runtime, delay_bytes); + buffer_sz = snd_pcm_lib_buffer_bytes(substream); - div_u64_rem(fw_tstamp->ring_buffer_counter, buffer_sz, &pointer_bytes); + div_u64_rem(fw_tstamp->hardware_counter, buffer_sz, &pointer_bytes); pointer_samples = bytes_to_samples(substream->runtime, pointer_bytes); - dev_dbg(ctx->dev, "pcm delay %zu in bytes\n", delay_bytes); - info->buffer_ptr = pointer_samples / substream->runtime->channels; + info->pcm_delay = 0; - info->pcm_delay = delay_frames; dev_dbg(ctx->dev, "buffer ptr %llu pcm_delay rep: %llu\n", info->buffer_ptr, info->pcm_delay); return 0; -- 2.7.4