All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Boyd <swboyd@chromium.org>
To: Cheng-yi Chiang <cychiang@chromium.org>
Cc: Guenter Roeck <linux@roeck-us.net>,
	Tzung-Bi Shih <tzungbi@google.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	ALSA development <alsa-devel@alsa-project.org>,
	Hung-Te Lin <hungte@chromium.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sean Paul <seanpaul@chromium.org>,
	Mark Brown <broonie@kernel.org>, Dylan Reid <dgreid@chromium.org>,
	Tzung-Bi Shih <tzungbi@chromium.org>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Subject: Re: [PATCH] firmware: vpd: Add an interface to read VPD value
Date: Tue, 08 Oct 2019 08:14:43 -0700	[thread overview]
Message-ID: <5d9ca7e4.1c69fb81.7f8fa.3f7d@mx.google.com> (raw)
In-Reply-To: <CAFv8Nw+x6V-995ijyws1Q36W1MpaP=kNJeiVtNakH-uC3Vgg9Q@mail.gmail.com>

Quoting Cheng-yi Chiang (2019-10-07 11:50:31)
> On Mon, Oct 7, 2019 at 11:35 PM Stephen Boyd <swboyd@chromium.org> wrote:
> >
> > Quoting Cheng-yi Chiang (2019-10-07 06:58:41)
> > >
> > > Hi Guenter,
> > > Thanks for the quick review.
> > > I'll update accordingly in v2.
> >
> > I'd prefer this use the nvmem framework which already handles many of
> > the requirements discussed here. Implement an nvmem provider and figure
> > out how to wire that up to the kernel users. Also, please include a user
> > of the added support, otherwise it is impossible to understand how this
> > code is used.
> >
> Hi Stephen,
> Thanks for the suggestion.
> My usage is for Intel machine driver to read a string for speaker calibration.
> 
> https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1838091/4/sound/soc/intel/boards/cml_rt1011_rt5682.c#325
> 
> Based on the comments in this thread, its usage would look like
> 
> #define DSM_CALIB_KEY "dsm_calib"
> static int load_calibration_data(struct cml_card_private *ctx) {
>           char *data = NULL;
>           int ret;
>           u32 value_len;
> 
>           /* Read calibration data from VPD. */
>           ret = vpd_attribute_read(1, DSM_CALIB_KEY,
>                                          (u8 **)&data, &value_len);
> 
>           /* Parsing of this string...*/
> }
> 
> It is currently pending on unmerged machine driver cml_rt1011_rt5682.c
> in ASoC so I can not post it for review for now.
> 
> As for nvmem approach, I looked into examples of nvmem usage, and have
> a rough idea how to do this.
> 
> 1) In vpd.c, as it parses key and value in the VPD section, add nvmem cell  with
> {
> .name=key,
> .offset=consumed,   // need some change in vpd_decodec.c to get the
> offset of value in the section.
> .bytes=value
> }
> Implement read function with vpd_section as context.
> 
> 2) In vpd.c, register an nvm_device using devm_nvmem_register in
> coreboot_driver's probe function vpd_probe.
> 
> 3) As my use case does not use device tree, it is hard for ASoC
> machine to access nvmem device. I am wondering if I can use
> nvm_cell_lookup so machine driver can find the nvmem device using a
> con_id. But currently the cell lookup API requires a matched device,
> which does not fit my usage because there will be different machine
> drivers requesting the value.
> I think I can still workaround this by adding the lookup table in
> machine driver. This would seem to be a bit weird because I found that
> most lookup table is added in provider side, not consumer side. Not
> sure if this is logically correct.

Maybe Srini has some input here. It looks like your main concern is
consumer to provider mapping?

> 
> IMO the nvmem approach would create more complexity to support this
> simple usage. Plus, the underlying assumption of accessing data with
> offset in a buffer does not fit well with the already parsed VPD
> values in a list of vpd_attrib_info. But if you strongly feel that
> this is a better approach I can work toward this.
> 

I'm not sure how an ACPI system like this would work because my exposure
to ACPI is extremely limited. I would expect there to be some sort of
firmware property indicating that an nvmem should be used and it's
provided by VPD or for firmware to parse VPD itself and put the
information into the ACPI table for this device.

Has either of those things been done? If it is a reference/property in
firmware then it should be possible to connect consumer devices like the
audio device you mention to VPD via the nvmem APIs with some changes to
the nvmem framework assuming there's an approach for nvmem in ACPI in
some "standard" way. 

I'd like to use nvmem for two reasons. First, it is a kernel framework
for reading non-volatile memories, which is fairly close to what VPD is
for. Second, it makes a standard, i.e. non-vpd/coreboot specific, API
that drivers can use to read memories. Of course in ASoC the machine
driver is already very platform specific, but the idea is to avoid
platform specific APIs so that drivers are loosely coupled with the rest
of the kernel. We shouldn't push against that goal by introducing more
platform specific APIs.


WARNING: multiple messages have this Message-ID (diff)
From: Stephen Boyd <swboyd@chromium.org>
To: Cheng-yi Chiang <cychiang@chromium.org>
Cc: ALSA development <alsa-devel@alsa-project.org>,
	Tzung-Bi Shih <tzungbi@chromium.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Hung-Te Lin <hungte@chromium.org>,
	Tzung-Bi Shih <tzungbi@google.com>,
	Mark Brown <broonie@kernel.org>,
	Sean Paul <seanpaul@chromium.org>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
	Dylan Reid <dgreid@chromium.org>,
	Guenter Roeck <linux@roeck-us.net>
Subject: Re: [alsa-devel] [PATCH] firmware: vpd: Add an interface to read VPD value
Date: Tue, 08 Oct 2019 08:14:43 -0700	[thread overview]
Message-ID: <5d9ca7e4.1c69fb81.7f8fa.3f7d@mx.google.com> (raw)
In-Reply-To: <CAFv8Nw+x6V-995ijyws1Q36W1MpaP=kNJeiVtNakH-uC3Vgg9Q@mail.gmail.com>

Quoting Cheng-yi Chiang (2019-10-07 11:50:31)
> On Mon, Oct 7, 2019 at 11:35 PM Stephen Boyd <swboyd@chromium.org> wrote:
> >
> > Quoting Cheng-yi Chiang (2019-10-07 06:58:41)
> > >
> > > Hi Guenter,
> > > Thanks for the quick review.
> > > I'll update accordingly in v2.
> >
> > I'd prefer this use the nvmem framework which already handles many of
> > the requirements discussed here. Implement an nvmem provider and figure
> > out how to wire that up to the kernel users. Also, please include a user
> > of the added support, otherwise it is impossible to understand how this
> > code is used.
> >
> Hi Stephen,
> Thanks for the suggestion.
> My usage is for Intel machine driver to read a string for speaker calibration.
> 
> https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1838091/4/sound/soc/intel/boards/cml_rt1011_rt5682.c#325
> 
> Based on the comments in this thread, its usage would look like
> 
> #define DSM_CALIB_KEY "dsm_calib"
> static int load_calibration_data(struct cml_card_private *ctx) {
>           char *data = NULL;
>           int ret;
>           u32 value_len;
> 
>           /* Read calibration data from VPD. */
>           ret = vpd_attribute_read(1, DSM_CALIB_KEY,
>                                          (u8 **)&data, &value_len);
> 
>           /* Parsing of this string...*/
> }
> 
> It is currently pending on unmerged machine driver cml_rt1011_rt5682.c
> in ASoC so I can not post it for review for now.
> 
> As for nvmem approach, I looked into examples of nvmem usage, and have
> a rough idea how to do this.
> 
> 1) In vpd.c, as it parses key and value in the VPD section, add nvmem cell  with
> {
> .name=key,
> .offset=consumed,   // need some change in vpd_decodec.c to get the
> offset of value in the section.
> .bytes=value
> }
> Implement read function with vpd_section as context.
> 
> 2) In vpd.c, register an nvm_device using devm_nvmem_register in
> coreboot_driver's probe function vpd_probe.
> 
> 3) As my use case does not use device tree, it is hard for ASoC
> machine to access nvmem device. I am wondering if I can use
> nvm_cell_lookup so machine driver can find the nvmem device using a
> con_id. But currently the cell lookup API requires a matched device,
> which does not fit my usage because there will be different machine
> drivers requesting the value.
> I think I can still workaround this by adding the lookup table in
> machine driver. This would seem to be a bit weird because I found that
> most lookup table is added in provider side, not consumer side. Not
> sure if this is logically correct.

Maybe Srini has some input here. It looks like your main concern is
consumer to provider mapping?

> 
> IMO the nvmem approach would create more complexity to support this
> simple usage. Plus, the underlying assumption of accessing data with
> offset in a buffer does not fit well with the already parsed VPD
> values in a list of vpd_attrib_info. But if you strongly feel that
> this is a better approach I can work toward this.
> 

I'm not sure how an ACPI system like this would work because my exposure
to ACPI is extremely limited. I would expect there to be some sort of
firmware property indicating that an nvmem should be used and it's
provided by VPD or for firmware to parse VPD itself and put the
information into the ACPI table for this device.

Has either of those things been done? If it is a reference/property in
firmware then it should be possible to connect consumer devices like the
audio device you mention to VPD via the nvmem APIs with some changes to
the nvmem framework assuming there's an approach for nvmem in ACPI in
some "standard" way. 

I'd like to use nvmem for two reasons. First, it is a kernel framework
for reading non-volatile memories, which is fairly close to what VPD is
for. Second, it makes a standard, i.e. non-vpd/coreboot specific, API
that drivers can use to read memories. Of course in ASoC the machine
driver is already very platform specific, but the idea is to avoid
platform specific APIs so that drivers are loosely coupled with the rest
of the kernel. We shouldn't push against that goal by introducing more
platform specific APIs.

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

  reply	other threads:[~2019-10-08 15:14 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-07  7:16 [PATCH] firmware: vpd: Add an interface to read VPD value Cheng-Yi Chiang
2019-10-07  7:16 ` [alsa-devel] " Cheng-Yi Chiang
2019-10-07  8:03 ` Tzung-Bi Shih
2019-10-07  8:03   ` [alsa-devel] " Tzung-Bi Shih
2019-10-07  8:52   ` Cheng-yi Chiang
2019-10-07  8:52     ` [alsa-devel] " Cheng-yi Chiang
2019-10-07 12:27   ` Guenter Roeck
2019-10-07 12:27     ` [alsa-devel] " Guenter Roeck
2019-10-07 13:58     ` Cheng-yi Chiang
2019-10-07 13:58       ` [alsa-devel] " Cheng-yi Chiang
2019-10-07 15:35       ` Stephen Boyd
2019-10-07 15:35         ` [alsa-devel] " Stephen Boyd
2019-10-07 18:50         ` Cheng-yi Chiang
2019-10-07 18:50           ` [alsa-devel] " Cheng-yi Chiang
2019-10-08 15:14           ` Stephen Boyd [this message]
2019-10-08 15:14             ` Stephen Boyd
2019-10-09 13:37             ` Mark Brown
2019-10-09 13:37               ` [alsa-devel] " Mark Brown
2019-10-09 14:05             ` Srinivas Kandagatla
2019-10-09 14:05               ` [alsa-devel] " Srinivas Kandagatla
2019-10-14  3:21               ` Cheng-yi Chiang
2019-10-14  3:21                 ` [alsa-devel] " Cheng-yi Chiang

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=5d9ca7e4.1c69fb81.7f8fa.3f7d@mx.google.com \
    --to=swboyd@chromium.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=cychiang@chromium.org \
    --cc=dgreid@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hungte@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=seanpaul@chromium.org \
    --cc=srinivas.kandagatla@linaro.org \
    --cc=tzungbi@chromium.org \
    --cc=tzungbi@google.com \
    /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.