Alsa-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [alsa-devel] [PATCH v2] firmware: vpd: Add an interface to read VPD value
@ 2019-10-08 10:11 Cheng-Yi Chiang
  2019-10-08 12:06 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Cheng-Yi Chiang @ 2019-10-08 10:11 UTC (permalink / raw)
  To: linux-kernel
  Cc: alsa-devel, tzungbi, Greg Kroah-Hartman, Pierre-Louis Bossart,
	Stephen Boyd, Hung-Te Lin, sathya.prakash.m.r, Mark Brown,
	Sean Paul, Shuming Fan, Srinivas Kandagatla, dgreid,
	Guenter Roeck, Cheng-Yi Chiang

Add an interface for other driver to query VPD value.
This will be used for ASoC machine driver to query calibration
data stored in VPD for smart amplifier speaker resistor
calibration.

The example usage in ASoC machine driver is 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...*/
}


Signed-off-by: Cheng-Yi Chiang <cychiang@chromium.org>
---
Change from v1 to v2:
- Use kmemdup to copy data.
- Set value_len according to bin_attr.size.
- Check return value of kmemdup.
- Rename the function to vpd_attribute_read.
- Add docstrings for the function.
- Returns -ENOENT when the key is not found.
- Use EXPORT_SYMBOL_GPL.

Note:

The user of this API is in ASoC machine driver cml_rt1011_rt5682.
It is pending on the initial machine driver change

https://patchwork.kernel.org/patch/11161145/

and the codec driver change to provide API to do calibration.

https://patchwork.kernel.org/patch/11179237/

The draft patch of machine driver change which uses this API is at

https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1838091



 drivers/firmware/google/vpd.c              | 31 ++++++++++++++++++++++
 include/linux/firmware/google/google_vpd.h | 18 +++++++++++++
 2 files changed, 49 insertions(+)
 create mode 100644 include/linux/firmware/google/google_vpd.h

diff --git a/drivers/firmware/google/vpd.c b/drivers/firmware/google/vpd.c
index db0812263d46..c2be0e756402 100644
--- a/drivers/firmware/google/vpd.c
+++ b/drivers/firmware/google/vpd.c
@@ -65,6 +65,37 @@ static ssize_t vpd_attrib_read(struct file *filp, struct kobject *kobp,
 				       info->bin_attr.size);
 }
 
+/**
+ *	vpd_attribute_read - Read VPD value for a key.
+ *	@ro: True for RO section. False for RW section.
+ *	@key: A string for key.
+ *	@value: Where to write the VPD value on success. The caller
+ *	        must free the memory.
+ *	@value_len: The length of value in bytes.
+ *
+ *	Returns 0 on success, -ENOENT when the key is not found, and
+ *	-ENOMEM when failed to allocate memory for value.
+ */
+int vpd_attribute_read(bool ro, const char *key,
+		       u8 **value, u32 *value_len)
+{
+	struct vpd_attrib_info *info;
+	struct vpd_section *sec = ro ? &ro_vpd : &rw_vpd;
+
+	list_for_each_entry(info, &sec->attribs, list) {
+		if (strcmp(info->key, key) == 0) {
+			*value = kmemdup(info->value, info->bin_attr.size,
+					 GFP_KERNEL);
+			if (!*value)
+				return -ENOMEM;
+			*value_len = info->bin_attr.size;
+			return 0;
+		}
+	}
+	return -ENOENT;
+}
+EXPORT_SYMBOL_GPL(vpd_attribute_read);
+
 /*
  * vpd_section_check_key_name()
  *
diff --git a/include/linux/firmware/google/google_vpd.h b/include/linux/firmware/google/google_vpd.h
new file mode 100644
index 000000000000..4364eaa4e1e3
--- /dev/null
+++ b/include/linux/firmware/google/google_vpd.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Google VPD interface.
+ *
+ * Copyright 2019 Google Inc.
+ */
+
+/* Interface for reading VPD value on Chrome platform. */
+
+#ifndef __GOOGLE_VPD_H
+#define __GOOGLE_VPD_H
+
+#include <linux/types.h>
+
+int vpd_attribute_read(bool ro, const char *key,
+		       u8 **value, u32 *value_len);
+
+#endif  /* __GOOGLE_VPD_H */
-- 
2.23.0.581.g78d2f28ef7-goog

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [alsa-devel] [PATCH v2] firmware: vpd: Add an interface to read VPD value
  2019-10-08 10:11 [alsa-devel] [PATCH v2] firmware: vpd: Add an interface to read VPD value Cheng-Yi Chiang
@ 2019-10-08 12:06 ` Greg Kroah-Hartman
  2019-10-08 12:10   ` Cheng-yi Chiang
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2019-10-08 12:06 UTC (permalink / raw)
  To: Cheng-Yi Chiang
  Cc: Pierre-Louis Bossart, alsa-devel, tzungbi, linux-kernel,
	Stephen Boyd, Hung-Te Lin, sathya.prakash.m.r, Mark Brown,
	Sean Paul, Shuming Fan, Srinivas Kandagatla, dgreid,
	Guenter Roeck

On Tue, Oct 08, 2019 at 06:11:44PM +0800, Cheng-Yi Chiang wrote:
> Add an interface for other driver to query VPD value.
> This will be used for ASoC machine driver to query calibration
> data stored in VPD for smart amplifier speaker resistor
> calibration.
> 
> The example usage in ASoC machine driver is 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...*/
> }
> 
> 
> Signed-off-by: Cheng-Yi Chiang <cychiang@chromium.org>
> ---

I can't take this patch without a real user of this function in the
kernel tree at the same time.  Please submit it as part of a patch
series with that change as well.

thanks,

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [alsa-devel] [PATCH v2] firmware: vpd: Add an interface to read VPD value
  2019-10-08 12:06 ` Greg Kroah-Hartman
@ 2019-10-08 12:10   ` Cheng-yi Chiang
  0 siblings, 0 replies; 3+ messages in thread
From: Cheng-yi Chiang @ 2019-10-08 12:10 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Pierre-Louis Bossart,
	moderated list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...,
	Tzung-Bi Shih, linux-kernel, Stephen Boyd, Hung-Te Lin, M R,
	Sathya Prakash, Mark Brown, Sean Paul, Shuming Fan,
	Srinivas Kandagatla, Dylan Reid, Guenter Roeck

On Tue, Oct 8, 2019 at 8:06 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Tue, Oct 08, 2019 at 06:11:44PM +0800, Cheng-Yi Chiang wrote:
> > Add an interface for other driver to query VPD value.
> > This will be used for ASoC machine driver to query calibration
> > data stored in VPD for smart amplifier speaker resistor
> > calibration.
> >
> > The example usage in ASoC machine driver is 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...*/
> > }
> >
> >
> > Signed-off-by: Cheng-Yi Chiang <cychiang@chromium.org>
> > ---
>
> I can't take this patch without a real user of this function in the
> kernel tree at the same time.  Please submit it as part of a patch
> series with that change as well.
>

Hi Greg,
I see.
There is an ongoing discussion with Mark in

https://patchwork.kernel.org/patch/11179237/

I will resend this after machine driver is merged, and after codec
driver change get sorted out there.
Thanks!

> thanks,
>
> greg k-h
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-08 10:11 [alsa-devel] [PATCH v2] firmware: vpd: Add an interface to read VPD value Cheng-Yi Chiang
2019-10-08 12:06 ` Greg Kroah-Hartman
2019-10-08 12:10   ` Cheng-yi Chiang

Alsa-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/alsa-devel/0 alsa-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 alsa-devel alsa-devel/ https://lore.kernel.org/alsa-devel \
		alsa-devel@alsa-project.org alsa-devel@archiver.kernel.org
	public-inbox-index alsa-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.alsa-project.alsa-devel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox