alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Ian Minett <ian_minett@creativelabs.com>
To: patch@alsa-project.org
Cc: alsa-devel@alsa-project.org, Ian Minett <ian_minett@creativelabs.com>
Subject: [PATCH 2/4] ALSA: CA0132: Improve the DSP transfer timeout calculations
Date: Fri, 8 Feb 2013 18:31:43 -0800	[thread overview]
Message-ID: <1360377105-2480-3-git-send-email-ian_minett@creativelabs.com> (raw)
In-Reply-To: <1360377105-2480-1-git-send-email-ian_minett@creativelabs.com>

From: Ian Minett <ian_minett@creativelabs.com>

Base the DSP firmware transfer and communication timeouts on jiffy values.

Signed-off-by: Ian Minett <ian_minett@creativelabs.com>

diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index a4b61a9..b52f00c 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -785,7 +785,7 @@ static int chipio_send(struct hda_codec *codec,
 		       unsigned int data)
 {
 	unsigned int res;
-	int retry = 50;
+	unsigned long timeout = jiffies + msecs_to_jiffies(1000);
 
 	/* send bits of data specified by reg */
 	do {
@@ -793,7 +793,9 @@ static int chipio_send(struct hda_codec *codec,
 					 reg, data);
 		if (res == VENDOR_STATUS_CHIPIO_OK)
 			return 0;
-	} while (--retry);
+		msleep(20);
+	} while (time_before(jiffies, timeout));
+
 	return -EIO;
 }
 
@@ -1059,14 +1061,15 @@ static int dspio_send(struct hda_codec *codec, unsigned int reg,
 		      unsigned int data)
 {
 	int res;
-	int retry = 50;
+	unsigned long timeout = jiffies + msecs_to_jiffies(1000);
 
 	/* send bits of data specified by reg to dsp */
 	do {
 		res = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0, reg, data);
 		if ((res >= 0) && (res != VENDOR_STATUS_DSPIO_BUSY))
 			return res;
-	} while (--retry);
+		msleep(20);
+	} while (time_before(jiffies, timeout));
 
 	return -EIO;
 }
@@ -1298,7 +1301,6 @@ static int dspio_send_scp_message(struct hda_codec *codec,
 				  unsigned int *bytes_returned)
 {
 	struct ca0132_spec *spec = codec->spec;
-	int retry;
 	int status = -1;
 	unsigned int scp_send_size = 0;
 	unsigned int total_size;
@@ -1345,13 +1347,13 @@ static int dspio_send_scp_message(struct hda_codec *codec,
 	}
 
 	if (waiting_for_resp) {
+		unsigned long timeout = jiffies + msecs_to_jiffies(1000);
 		memset(return_buf, 0, return_buf_size);
-		retry = 50;
 		do {
 			msleep(20);
-		} while (spec->wait_scp && (--retry != 0));
+		} while (spec->wait_scp && time_before(jiffies, timeout));
 		waiting_for_resp = false;
-		if (retry != 0) {
+		if (!spec->wait_scp) {
 			ret_msg = (struct scp_msg *)return_buf;
 			memcpy(&ret_msg->hdr, &spec->scp_resp_header, 4);
 			memcpy(&ret_msg->data, spec->scp_resp_data,
@@ -2244,7 +2246,8 @@ static int dspxfr_one_seg(struct hda_codec *codec,
 	u32 chip_addx_remainder;
 	unsigned int run_size_words;
 	const struct dsp_image_seg *hci_write = NULL;
-	int retry;
+	unsigned long timeout;
+	bool dma_active;
 
 	if (fls == NULL)
 		return -EINVAL;
@@ -2362,11 +2365,17 @@ static int dspxfr_one_seg(struct hda_codec *codec,
 			status = dspxfr_hci_write(codec, hci_write);
 			hci_write = NULL;
 		}
-		retry = 5000;
-		while (dsp_is_dma_active(codec, dma_chan)) {
-			if (--retry <= 0)
+
+		timeout = jiffies + msecs_to_jiffies(2000);
+		do {
+			dma_active = dsp_is_dma_active(codec, dma_chan);
+			if (!dma_active)
 				break;
-		}
+			msleep(20);
+		} while (time_before(jiffies, timeout));
+		if (dma_active)
+			break;
+
 		snd_printdd(KERN_INFO "+++++ DMA complete");
 		dma_set_state(dma_engine, DMA_STATE_STOP);
 		dma_reset(dma_engine);
@@ -2683,15 +2692,15 @@ static bool dspload_is_loaded(struct hda_codec *codec)
 
 static bool dspload_wait_loaded(struct hda_codec *codec)
 {
-	int retry = 100;
+	unsigned long timeout = jiffies + msecs_to_jiffies(2000);
 
 	do {
-		msleep(20);
 		if (dspload_is_loaded(codec)) {
 			pr_info("ca0132 DOWNLOAD OK :-) DSP IS RUNNING.\n");
 			return true;
 		}
-	} while (--retry);
+		msleep(20);
+	} while (time_before(jiffies, timeout));
 
 	pr_err("ca0132 DOWNLOAD FAILED!!! DSP IS NOT RUNNING.\n");
 	return false;
-- 
1.7.4.1

  parent reply	other threads:[~2013-02-09  2:31 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-09  2:31 [PATCH 0/4] ALSA: Updates for the CA0132 codec Ian Minett
2013-02-09  2:31 ` [PATCH 1/4] ALSA: CA0132: Add SpeakerEQ feature firmware loading Ian Minett
2013-02-10 10:47   ` Takashi Iwai
2013-02-09  2:31 ` Ian Minett [this message]
2013-02-10 10:51   ` [PATCH 2/4] ALSA: CA0132: Improve the DSP transfer timeout calculations Takashi Iwai
2013-02-09  2:31 ` [PATCH 3/4] ALSA: CA0132: Add latency monitoring Ian Minett
2013-02-10 10:51   ` Takashi Iwai
2013-03-25 17:47     ` Dylan Reid
2013-04-02  9:30       ` Takashi Iwai
2013-04-02 20:24         ` Dylan Reid
2013-04-03  5:19           ` Takashi Iwai
2013-02-09  2:31 ` [PATCH 4/4] ALSA: CA0132: Update hp unsol event handler Ian Minett
2013-02-10 10:52   ` Takashi Iwai
2013-02-10 10:57 ` [PATCH 0/4] ALSA: Updates for the CA0132 codec Takashi Iwai
2013-03-15  0:34   ` Dylan Reid
2013-03-15  8:25     ` Takashi Iwai
2013-03-15 18:39       ` Dylan Reid
2013-03-15 20:23         ` Takashi Iwai
2013-03-20 17:21           ` Dylan Reid
2013-03-20 17:39             ` Takashi Iwai

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=1360377105-2480-3-git-send-email-ian_minett@creativelabs.com \
    --to=ian_minett@creativelabs.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=patch@alsa-project.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).