Skip to content

Commit 4861af8

Browse files
ikminetttiwai
authored andcommitted
ALSA: hda - Update chipio functions and DSP write wait timeout
Tidy up and condense chipio_write_address|addx() functions. Improve dspio_write_wait() to use jiffies for timeout calc. Signed-off-by: Ian Minett <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent a3af480 commit 4861af8

File tree

1 file changed

+16
-36
lines changed

1 file changed

+16
-36
lines changed

sound/pci/hda/patch_ca0132.c

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,12 @@ static int chipio_send(struct hda_codec *codec,
460460
static int chipio_write_address(struct hda_codec *codec,
461461
unsigned int chip_addx)
462462
{
463+
struct ca0132_spec *spec = codec->spec;
463464
int res;
464465

466+
if (spec->curr_chip_addx == chip_addx)
467+
return 0;
468+
465469
/* send low 16 bits of the address */
466470
res = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_LOW,
467471
chip_addx & 0xffff);
@@ -472,37 +476,14 @@ static int chipio_write_address(struct hda_codec *codec,
472476
chip_addx >> 16);
473477
}
474478

475-
return res;
476-
}
477-
478-
static int chipio_write_addx(struct hda_codec *codec, u32 chip_addx)
479-
{
480-
struct ca0132_spec *spec = codec->spec;
481-
int status;
482-
483-
if (spec->curr_chip_addx == chip_addx)
484-
return 0;
485-
486-
/* send low 16 bits of the address */
487-
status = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_LOW,
488-
chip_addx & 0xffff);
489-
490-
if (status < 0)
491-
return status;
492-
493-
/* send high 16 bits of the address */
494-
status = chipio_send(codec, VENDOR_CHIPIO_ADDRESS_HIGH,
495-
chip_addx >> 16);
496-
497-
spec->curr_chip_addx = (status < 0) ? ~0UL : chip_addx;
479+
spec->curr_chip_addx = (res < 0) ? ~0UL : chip_addx;
498480

499-
return status;
481+
return res;
500482
}
501483

502484
/*
503485
* Write data through the vendor widget -- NOT protected by the Mutex!
504486
*/
505-
506487
static int chipio_write_data(struct hda_codec *codec, unsigned int data)
507488
{
508489
int res;
@@ -604,7 +585,7 @@ static int chipio_write_multiple(struct hda_codec *codec,
604585
int status;
605586

606587
mutex_lock(&spec->chipio_mutex);
607-
status = chipio_write_addx(codec, chip_addx);
588+
status = chipio_write_address(codec, chip_addx);
608589
if (status < 0)
609590
goto error;
610591

@@ -742,18 +723,17 @@ static int dspio_send(struct hda_codec *codec, unsigned int reg,
742723
*/
743724
static void dspio_write_wait(struct hda_codec *codec)
744725
{
745-
int cur_val, prv_val;
746-
int retry = 50;
726+
int status;
727+
unsigned long timeout = jiffies + msecs_to_jiffies(1000);
747728

748-
cur_val = 0;
749729
do {
750-
prv_val = cur_val;
751-
msleep(20);
752-
dspio_send(codec, VENDOR_DSPIO_SCP_POST_COUNT_QUERY, 1);
753-
dspio_send(codec, VENDOR_DSPIO_STATUS, 0);
754-
cur_val = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
755-
VENDOR_DSPIO_SCP_READ_COUNT, 0);
756-
} while (cur_val && (cur_val == prv_val) && --retry);
730+
status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0,
731+
VENDOR_DSPIO_STATUS, 0);
732+
if ((status == VENDOR_STATUS_DSPIO_OK) ||
733+
(status == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY))
734+
break;
735+
msleep(1);
736+
} while (time_before(jiffies, timeout));
757737
}
758738

759739
/*

0 commit comments

Comments
 (0)