From: "Ding, Shenghao" <shenghao-ding@ti.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: "broonie@kernel.org" <broonie@kernel.org>,
"andriy.shevchenko@linux.intel.com"
<andriy.shevchenko@linux.intel.com>,
"13564923607@139.com" <13564923607@139.com>,
"13916275206@139.com" <13916275206@139.com>,
"alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Xu, Baojun" <baojun.xu@ti.com>,
"Baojun.Xu@fpt.com" <Baojun.Xu@fpt.com>
Subject: RE: [EXTERNAL] Re: [PATCH v2] ALSA: hda/tas2781: Fix the order of TAS2781 calibrated-data
Date: Wed, 3 Sep 2025 22:06:50 +0000 [thread overview]
Message-ID: <d032c064b5324641b19b3c0b31dcd2e2@ti.com> (raw)
In-Reply-To: <875xdzx5nn.wl-tiwai@suse.de>
Thanks for your ref code
> > +/*
> > + * The order of calibrated-data writing is a bit different from the
> > +order
> > + * in UEFI. Here is the conversion to match the order of
> > +calibrated-data
> > + * writing.
> > + */
> > +static void cali_cnv(unsigned char *data, unsigned int base, int
> > +offset) {
> > + __be32 bedata[TASDEV_CALIB_N];
> > + int i;
> > +
> > + /* r0_reg */
> > + bedata[0] = cpu_to_be32(*(uint32_t *)&data[base]);
> > + /* r0_low_reg */
> > + bedata[1] = cpu_to_be32(*(uint32_t *)&data[base + 8]);
> > + /* invr0_reg */
> > + bedata[2] = cpu_to_be32(*(uint32_t *)&data[base + 4]);
> > + /* pow_reg */
> > + bedata[3] = cpu_to_be32(*(uint32_t *)&data[base + 12]);
> > + /* tlimit_reg */
> > + bedata[4] = cpu_to_be32(*(uint32_t *)&data[base + 16]);
> > +
> > + for (i = 0; i < TASDEV_CALIB_N; i++)
> > + memcpy(&data[offset + i * 4 + 1], &bedata[i],
> > + sizeof(bedata[i]));
> > +}
>
> IMO, this can be more readable when you use struct calidata, e.g.
>
> static void cali_cnv(unsigned char *data, unsigned int base, int offset) {
> struct calidata reg;
>
> reg.r0_reg = *(u32 *)&data[base]
> reg.r0_low_reg = *(u32 *)&data[base + 8]
> reg.invr0_reg = *(u32 *)&data[base + 4]
> reg.pow_reg = *(u32 *)&data[base + 12];
> reg.tlimit_reg = *(u32 *)&data[base + 16]);
>
> cpu_to_be32_array((__force __be32 *)(data + offset + 1), ®,
> TASDEV_CALIB_N);
> }
>
> ... or even simpler like:
>
> static void cali_cnv(unsigned char *data, unsigned int base, int offset) {
> struct calidata reg;
>
> memcpy(®, data, sizeof(reg));
> /* the data order has to be swapped between r0_low_reg and inv0_reg
> */
> swap(reg.r0_low_reg, reg.invr0_reg);
>
> cpu_to_be32_array((__force __be32 *)(data + offset + 1), ®,
> TASDEV_CALIB_N);
> }
I like this code so much. It's elegant simplicity.
Thanks,
Shenghao Ding
prev parent reply other threads:[~2025-09-03 22:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-03 4:13 [PATCH v2] ALSA: hda/tas2781: Fix the order of TAS2781 calibrated-data Shenghao Ding
2025-09-03 7:21 ` Takashi Iwai
2025-09-03 8:21 ` [EXTERNAL] " Ding, Shenghao
2025-09-03 9:10 ` Takashi Iwai
2025-09-03 22:06 ` Ding, Shenghao [this message]
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=d032c064b5324641b19b3c0b31dcd2e2@ti.com \
--to=shenghao-ding@ti.com \
--cc=13564923607@139.com \
--cc=13916275206@139.com \
--cc=Baojun.Xu@fpt.com \
--cc=alsa-devel@alsa-project.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=baojun.xu@ti.com \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tiwai@suse.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.