From: Takashi Iwai Subject: Re: [PATCH 1/1 v2] ALSA: CA0132 - Handle endianness of SCP buffer data Date: Sat, 01 Dec 2012 12:05:41 +0100 Message-ID: References: <1354335768-2288-1-git-send-email-ian_minett@creativelabs.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id D414B261600 for ; Sat, 1 Dec 2012 12:05:43 +0100 (CET) In-Reply-To: <1354335768-2288-1-git-send-email-ian_minett@creativelabs.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Ian Minett Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org At Fri, 30 Nov 2012 20:22:48 -0800, Ian Minett wrote: > > From: Ian Minett > > Thanks for the info - we've changed the previous unaligned access calls to > use cpu_to_le32() and le32_to_cpu() instead for the swapping operations. > > - Ian Thanks! But... looking again at the current code, I'm no longer sure whether we need this conversion. Basically in the hda controller driver itself, the endianness is corrected before writing and after reading the raw value. So, for these, I don't think it's really needed. And the firmware byte stream should have been already set in LE, as it's fed directly... Takashi > > -- > Handle endianness of the SCP buffer being sent to or from the > DSP chip on big-endian host architectures. > The SCP buffer is prepared in dspio_scp(), and bytes are swapped > before being transferred by the codec in dspio_send(). > > Signed-off-by: Ian Minett > > diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c > index 2fd3121..fa19219 100644 > --- a/sound/pci/hda/patch_ca0132.c > +++ b/sound/pci/hda/patch_ca0132.c > @@ -701,11 +701,15 @@ static int dspio_send(struct hda_codec *codec, unsigned int reg, > unsigned int res; > int retry = 50; > > + /* Handling for Big Endian machine */ > + unsigned int val = cpu_to_le32(data); > + > /* 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; > + res = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0, reg, val); > + val = le32_to_cpu(res); > + if ((val >= 0) && (val != VENDOR_STATUS_DSPIO_BUSY)) > + return val; > } while (--retry); > > return -EIO; > @@ -719,11 +723,15 @@ static void dspio_write_wait(struct hda_codec *codec) > int status; > unsigned long timeout = jiffies + msecs_to_jiffies(1000); > > + /* Handling for Big Endian machine */ > + unsigned int val; > + > do { > 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)) > + val = le32_to_cpu(status); > + if ((val == VENDOR_STATUS_DSPIO_OK) || > + (val == VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY)) > break; > msleep(1); > } while (time_before(jiffies, timeout)); > @@ -736,6 +744,8 @@ static int dspio_write(struct hda_codec *codec, unsigned int scp_data) > { > struct ca0132_spec *spec = codec->spec; > int status; > + /* Handling for Big Endian machine */ > + unsigned int val = 0; > > dspio_write_wait(codec); > > @@ -751,8 +761,10 @@ static int dspio_write(struct hda_codec *codec, unsigned int scp_data) > goto error; > > /* OK, now check if the write itself has executed*/ > - status = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0, > + val = snd_hda_codec_read(codec, WIDGET_DSP_CTRL, 0, > VENDOR_DSPIO_STATUS, 0); > + status = le32_to_cpu(val); > + > error: > mutex_unlock(&spec->chipio_mutex); > > -- > 1.7.4.1 >