CHROMIUM: ALSA: hda/ca0132 - make initialization faster.
authorChih-Chung Chang <chihchung@chromium.org>
Fri, 31 Aug 2012 08:19:15 +0000 (16:19 +0800)
committerGerrit <chrome-bot@google.com>
Mon, 3 Sep 2012 13:32:00 +0000 (06:32 -0700)
Remove unnecessary dspio_send() from dspio_write_wait().
Check dsp status before sleep and sleep for shorter periods.

BUG=chrome-os-partner:12307
TEST=build and install, check dmesg.

Signed-off-by: Chih-Chung Chang <chihchung@chromium.org>
Change-Id: I0e1d5b0d29c446f29beea704c1b2cca22524c142
Reviewed-on: https://gerrit.chromium.org/gerrit/32023
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Chih-Chung Chang <chihchung@chromium.org>
Commit-Ready: Chih-Chung Chang <chihchung@chromium.org>

sound/pci/hda/patch_ca0132.c

index 817d090..0d77bf6 100644 (file)
@@ -1028,18 +1028,17 @@ static int dspio_send(struct hda_codec *codec, unsigned int reg,
 
 static void dspio_write_wait(struct hda_codec *codec)
 {
-       int cur_val, prv_val;
-       int retry = 50;
+       int status;
+       unsigned long timeout = jiffies + msecs_to_jiffies(1000);
 
-       cur_val = 0;
        do {
-               prv_val = cur_val;
-               msleep(20);
-               dspio_send(codec, VENDOR_DSPIO_SCP_POST_COUNT_QUERY, 1);
-               dspio_send(codec, VENDOR_DSPIO_STATUS, 0);
-               cur_val = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
-                                          VENDOR_DSPIO_SCP_READ_COUNT, 0);
-       } while (cur_val && (cur_val == prv_val) && --retry);
+               status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
+                                               VENDOR_DSPIO_STATUS, 0);
+               if ((status == VENDOR_STATUS_DSPIO_OK) ||
+                   (status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY))
+                       break;
+               msleep(1);
+       } while (time_before(jiffies, timeout));
 }
 
 static int dspio_write(struct hda_codec *codec, unsigned int scp_data)
@@ -1285,13 +1284,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));
+                       msleep(1);
+               } 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,
@@ -2674,15 +2673,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("DOWNLOAD OK :-) DSP IS RUNNING.\n");
                        return true;
                }
-       } while (--retry);
+               msleep(1);
+       } while (time_before(jiffies, timeout));
 
        pr_err("DOWNLOAD FAILED!!! DSP IS NOT RUNNING.\n");
        return false;