All of lore.kernel.org
 help / color / mirror / Atom feed
* [alsa-devel] [PATCH] ASoC: rt1011: Read and apply r0 and temperature device property
@ 2019-10-16  8:58 shumingf
  2019-10-16 10:49 ` Cheng-yi Chiang
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: shumingf @ 2019-10-16  8:58 UTC (permalink / raw)
  To: broonie, lgirdwood
  Cc: oder_chiou, jack.yu, alsa-devel, lars, cychiang, derek.fang,
	Shuming Fan, flove

From: Shuming Fan <shumingf@realtek.com>

Typically, the r0 (calibration data) and temperature were measured in the factory.
This information is written into the non-volatile area
where keeps data whether factory reset or OS update.
In Chromium OS case, the coreboot will read the info from VPD and create
the device property for each rt1011.

Signed-off-by: Shuming Fan <shumingf@realtek.com>
---
 sound/soc/codecs/rt1011.c | 41 ++++++++++++++++++++++++++++++++++++++-
 sound/soc/codecs/rt1011.h |  1 +
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/rt1011.c b/sound/soc/codecs/rt1011.c
index b927e61b32df..ad049cfddcb0 100644
--- a/sound/soc/codecs/rt1011.c
+++ b/sound/soc/codecs/rt1011.c
@@ -2328,8 +2328,12 @@ static void rt1011_calibration_work(struct work_struct *work)
 	struct rt1011_priv *rt1011 =
 		container_of(work, struct rt1011_priv, cali_work);
 	struct snd_soc_component *component = rt1011->component;
+	unsigned int r0_integer, r0_factor, format;
 
-	rt1011_calibrate(rt1011, 1);
+	if (rt1011->r0_calib)
+		rt1011_calibrate(rt1011, 0);
+	else
+		rt1011_calibrate(rt1011, 1);
 
 	/*
 	 * This flag should reset after booting.
@@ -2340,6 +2344,39 @@ static void rt1011_calibration_work(struct work_struct *work)
 
 	/* initial */
 	rt1011_reg_init(component);
+
+	/* Apply temperature and calibration data from device property */
+	if (rt1011->temperature_calib) {
+		snd_soc_component_update_bits(component,
+			RT1011_STP_INITIAL_RESISTANCE_TEMP, 0x3ff,
+			(rt1011->temperature_calib << 2));
+	}
+
+	if (rt1011->r0_calib) {
+		rt1011->r0_reg = rt1011->r0_calib;
+
+		format = 2147483648U; /* 2^24 * 128 */
+		r0_integer = format / rt1011->r0_reg / 128;
+		r0_factor = ((format / rt1011->r0_reg * 100) / 128)
+						- (r0_integer * 100);
+		dev_info(component->dev,	"DP r0 resistance about %d.%02d ohm, reg=0x%X\n",
+			r0_integer, r0_factor, rt1011->r0_reg);
+
+		rt1011_r0_load(rt1011);
+	}
+}
+
+static int rt1011_parse_dp(struct rt1011_priv *rt1011, struct device *dev)
+{
+	device_property_read_u32(dev, "realtek,temperature_calib",
+		&rt1011->temperature_calib);
+	device_property_read_u32(dev, "realtek,r0_calib",
+		&rt1011->r0_calib);
+
+	dev_dbg(dev, "%s: r0_calib: 0x%x, temperture_calib: 0x%x",
+		__func__, rt1011->r0_calib, rt1011->temperature_calib);
+
+	return 0;
 }
 
 static int rt1011_i2c_probe(struct i2c_client *i2c,
@@ -2356,6 +2393,8 @@ static int rt1011_i2c_probe(struct i2c_client *i2c,
 
 	i2c_set_clientdata(i2c, rt1011);
 
+	rt1011_parse_dp(rt1011, &i2c->dev);
+
 	rt1011->regmap = devm_regmap_init_i2c(i2c, &rt1011_regmap);
 	if (IS_ERR(rt1011->regmap)) {
 		ret = PTR_ERR(rt1011->regmap);
diff --git a/sound/soc/codecs/rt1011.h b/sound/soc/codecs/rt1011.h
index 3f7dea1191ad..68fadc15fa8c 100644
--- a/sound/soc/codecs/rt1011.h
+++ b/sound/soc/codecs/rt1011.h
@@ -690,6 +690,7 @@ struct rt1011_priv {
 
 	int bq_drc_set;
 	unsigned int r0_reg, cali_done;
+	unsigned int r0_calib, temperature_calib;
 	int recv_spk_mode;
 };
 
-- 
2.23.0

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

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

* Re: [alsa-devel] [PATCH] ASoC: rt1011: Read and apply r0 and temperature device property
  2019-10-16  8:58 [alsa-devel] [PATCH] ASoC: rt1011: Read and apply r0 and temperature device property shumingf
@ 2019-10-16 10:49 ` Cheng-yi Chiang
  2019-10-16 11:23 ` Mark Brown
  2019-10-16 12:58 ` [alsa-devel] Applied "ASoC: rt1011: Read and apply r0 and temperature device property" to the asoc tree Mark Brown
  2 siblings, 0 replies; 6+ messages in thread
From: Cheng-yi Chiang @ 2019-10-16 10:49 UTC (permalink / raw)
  To: Shuming [范書銘]
  Cc: Oder Chiou, Jack Yu,
	moderated list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...,
	lars, Liam Girdwood, Mark Brown, Derek [方德義],
	Flove(HsinFu)

On Wed, Oct 16, 2019 at 4:59 PM <shumingf@realtek.com> wrote:
>
> From: Shuming Fan <shumingf@realtek.com>
>
> Typically, the r0 (calibration data) and temperature were measured in the factory.
> This information is written into the non-volatile area
> where keeps data whether factory reset or OS update.
> In Chromium OS case, the coreboot will read the info from VPD and create
> the device property for each rt1011.
>
> Signed-off-by: Shuming Fan <shumingf@realtek.com>
> ---
>  sound/soc/codecs/rt1011.c | 41 ++++++++++++++++++++++++++++++++++++++-
>  sound/soc/codecs/rt1011.h |  1 +
>  2 files changed, 41 insertions(+), 1 deletion(-)
>
> diff --git a/sound/soc/codecs/rt1011.c b/sound/soc/codecs/rt1011.c
> index b927e61b32df..ad049cfddcb0 100644
> --- a/sound/soc/codecs/rt1011.c
> +++ b/sound/soc/codecs/rt1011.c
> @@ -2328,8 +2328,12 @@ static void rt1011_calibration_work(struct work_struct *work)
>         struct rt1011_priv *rt1011 =
>                 container_of(work, struct rt1011_priv, cali_work);
>         struct snd_soc_component *component = rt1011->component;
> +       unsigned int r0_integer, r0_factor, format;
>
> -       rt1011_calibrate(rt1011, 1);
> +       if (rt1011->r0_calib)
> +               rt1011_calibrate(rt1011, 0);
> +       else
> +               rt1011_calibrate(rt1011, 1);
>
>         /*
>          * This flag should reset after booting.
> @@ -2340,6 +2344,39 @@ static void rt1011_calibration_work(struct work_struct *work)
>
>         /* initial */
>         rt1011_reg_init(component);
> +
> +       /* Apply temperature and calibration data from device property */
> +       if (rt1011->temperature_calib) {
> +               snd_soc_component_update_bits(component,
> +                       RT1011_STP_INITIAL_RESISTANCE_TEMP, 0x3ff,
> +                       (rt1011->temperature_calib << 2));
> +       }
> +
> +       if (rt1011->r0_calib) {
> +               rt1011->r0_reg = rt1011->r0_calib;
> +
> +               format = 2147483648U; /* 2^24 * 128 */
> +               r0_integer = format / rt1011->r0_reg / 128;
> +               r0_factor = ((format / rt1011->r0_reg * 100) / 128)
> +                                               - (r0_integer * 100);
> +               dev_info(component->dev,        "DP r0 resistance about %d.%02d ohm, reg=0x%X\n",
> +                       r0_integer, r0_factor, rt1011->r0_reg);
> +
> +               rt1011_r0_load(rt1011);
> +       }
> +}
> +
> +static int rt1011_parse_dp(struct rt1011_priv *rt1011, struct device *dev)
> +{
> +       device_property_read_u32(dev, "realtek,temperature_calib",
> +               &rt1011->temperature_calib);
> +       device_property_read_u32(dev, "realtek,r0_calib",
> +               &rt1011->r0_calib);
> +
> +       dev_dbg(dev, "%s: r0_calib: 0x%x, temperture_calib: 0x%x",
> +               __func__, rt1011->r0_calib, rt1011->temperature_calib);
> +
> +       return 0;
>  }
>
>  static int rt1011_i2c_probe(struct i2c_client *i2c,
> @@ -2356,6 +2393,8 @@ static int rt1011_i2c_probe(struct i2c_client *i2c,
>
>         i2c_set_clientdata(i2c, rt1011);
>
> +       rt1011_parse_dp(rt1011, &i2c->dev);
> +
>         rt1011->regmap = devm_regmap_init_i2c(i2c, &rt1011_regmap);
>         if (IS_ERR(rt1011->regmap)) {
>                 ret = PTR_ERR(rt1011->regmap);
> diff --git a/sound/soc/codecs/rt1011.h b/sound/soc/codecs/rt1011.h
> index 3f7dea1191ad..68fadc15fa8c 100644
> --- a/sound/soc/codecs/rt1011.h
> +++ b/sound/soc/codecs/rt1011.h
> @@ -690,6 +690,7 @@ struct rt1011_priv {
>
>         int bq_drc_set;
>         unsigned int r0_reg, cali_done;
> +       unsigned int r0_calib, temperature_calib;
>         int recv_spk_mode;
>  };
>
> --
> 2.23.0
>
FYI, the relevant coreboot patch series is at
https://review.coreboot.org/c/coreboot/+/36031
I have tested it with coreboot changes.

Tested-By: Cheng-Yi Chiang <cychiang@chromium.org>
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: rt1011: Read and apply r0 and temperature device property
  2019-10-16  8:58 [alsa-devel] [PATCH] ASoC: rt1011: Read and apply r0 and temperature device property shumingf
  2019-10-16 10:49 ` Cheng-yi Chiang
@ 2019-10-16 11:23 ` Mark Brown
       [not found]   ` <fb55fba1f6e8441983fbd563e4b89e45@realtek.com>
  2019-10-16 12:58 ` [alsa-devel] Applied "ASoC: rt1011: Read and apply r0 and temperature device property" to the asoc tree Mark Brown
  2 siblings, 1 reply; 6+ messages in thread
From: Mark Brown @ 2019-10-16 11:23 UTC (permalink / raw)
  To: shumingf
  Cc: oder_chiou, jack.yu, alsa-devel, lars, cychiang, lgirdwood,
	derek.fang, flove


[-- Attachment #1.1: Type: text/plain, Size: 403 bytes --]

On Wed, Oct 16, 2019 at 04:58:45PM +0800, shumingf@realtek.com wrote:

> +static int rt1011_parse_dp(struct rt1011_priv *rt1011, struct device *dev)
> +{
> +	device_property_read_u32(dev, "realtek,temperature_calib",
> +		&rt1011->temperature_calib);
> +	device_property_read_u32(dev, "realtek,r0_calib",
> +		&rt1011->r0_calib);

These are new DT bindings and need to be added to the binding document.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 161 bytes --]

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

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

* Re: [alsa-devel] [PATCH] ASoC: rt1011: Read and apply r0 and temperature device property
       [not found]   ` <fb55fba1f6e8441983fbd563e4b89e45@realtek.com>
@ 2019-10-16 11:30     ` Cheng-yi Chiang
  2019-10-16 11:38     ` Mark Brown
  1 sibling, 0 replies; 6+ messages in thread
From: Cheng-yi Chiang @ 2019-10-16 11:30 UTC (permalink / raw)
  To: Shuming [范書銘]
  Cc: Oder Chiou, Jack Yu, alsa-devel, lars, lgirdwood, Mark Brown,
	Derek [方德義], Flove(HsinFu)

On Wed, Oct 16, 2019 at 7:29 PM Shuming [范書銘] <shumingf@realtek.com> wrote:
>
> > On Wed, Oct 16, 2019 at 04:58:45PM +0800, shumingf@realtek.com wrote:
> >
> > > +static int rt1011_parse_dp(struct rt1011_priv *rt1011, struct device
> > > +*dev) {
> > > +   device_property_read_u32(dev, "realtek,temperature_calib",
> > > +           &rt1011->temperature_calib);
> > > +   device_property_read_u32(dev, "realtek,r0_calib",
> > > +           &rt1011->r0_calib);
> >
> > These are new DT bindings and need to be added to the binding document.
>
> Sure, could I send another patch for it?
>
> > ------Please consider the environment before printing this e-mail.
Hi Shuming,
Yes, you will need a patch before this one to add the binding documentation.
Thanks!
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: rt1011: Read and apply r0 and temperature device property
       [not found]   ` <fb55fba1f6e8441983fbd563e4b89e45@realtek.com>
  2019-10-16 11:30     ` Cheng-yi Chiang
@ 2019-10-16 11:38     ` Mark Brown
  1 sibling, 0 replies; 6+ messages in thread
From: Mark Brown @ 2019-10-16 11:38 UTC (permalink / raw)
  To: Shuming [范書銘]
  Cc: Oder Chiou, Jack Yu, alsa-devel, lars, cychiang, lgirdwood,
	Derek [方德義], Flove(HsinFu)


[-- Attachment #1.1: Type: text/plain, Size: 257 bytes --]

On Wed, Oct 16, 2019 at 11:28:47AM +0000, Shuming [范書銘] wrote:

> > These are new DT bindings and need to be added to the binding document.

> Sure, could I send another patch for it?

Yes, the DT bindings should go in a separate patch anyway.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 161 bytes --]

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

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

* [alsa-devel] Applied "ASoC: rt1011: Read and apply r0 and temperature device property" to the asoc tree
  2019-10-16  8:58 [alsa-devel] [PATCH] ASoC: rt1011: Read and apply r0 and temperature device property shumingf
  2019-10-16 10:49 ` Cheng-yi Chiang
  2019-10-16 11:23 ` Mark Brown
@ 2019-10-16 12:58 ` Mark Brown
  2 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2019-10-16 12:58 UTC (permalink / raw)
  To: Shuming Fan
  Cc: oder_chiou, jack.yu, alsa-devel, lars, cychiang, lgirdwood,
	Mark Brown, derek.fang, flove

The patch

   ASoC: rt1011: Read and apply r0 and temperature device property

has been applied to the asoc tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.5

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

From 8de6e755069fbfaefae67d3abff2b2e3d83db986 Mon Sep 17 00:00:00 2001
From: Shuming Fan <shumingf@realtek.com>
Date: Wed, 16 Oct 2019 16:58:45 +0800
Subject: [PATCH] ASoC: rt1011: Read and apply r0 and temperature device
 property

Typically, the r0 (calibration data) and temperature were measured in the factory.
This information is written into the non-volatile area
where keeps data whether factory reset or OS update.
In Chromium OS case, the coreboot will read the info from VPD and create
the device property for each rt1011.

Signed-off-by: Shuming Fan <shumingf@realtek.com>
Tested-By: Cheng-Yi Chiang <cychiang@chromium.org>
Link: https://lore.kernel.org/r/20191016085845.11672-1-shumingf@realtek.com
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/codecs/rt1011.c | 41 ++++++++++++++++++++++++++++++++++++++-
 sound/soc/codecs/rt1011.h |  1 +
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/rt1011.c b/sound/soc/codecs/rt1011.c
index b927e61b32df..ad049cfddcb0 100644
--- a/sound/soc/codecs/rt1011.c
+++ b/sound/soc/codecs/rt1011.c
@@ -2328,8 +2328,12 @@ static void rt1011_calibration_work(struct work_struct *work)
 	struct rt1011_priv *rt1011 =
 		container_of(work, struct rt1011_priv, cali_work);
 	struct snd_soc_component *component = rt1011->component;
+	unsigned int r0_integer, r0_factor, format;
 
-	rt1011_calibrate(rt1011, 1);
+	if (rt1011->r0_calib)
+		rt1011_calibrate(rt1011, 0);
+	else
+		rt1011_calibrate(rt1011, 1);
 
 	/*
 	 * This flag should reset after booting.
@@ -2340,6 +2344,39 @@ static void rt1011_calibration_work(struct work_struct *work)
 
 	/* initial */
 	rt1011_reg_init(component);
+
+	/* Apply temperature and calibration data from device property */
+	if (rt1011->temperature_calib) {
+		snd_soc_component_update_bits(component,
+			RT1011_STP_INITIAL_RESISTANCE_TEMP, 0x3ff,
+			(rt1011->temperature_calib << 2));
+	}
+
+	if (rt1011->r0_calib) {
+		rt1011->r0_reg = rt1011->r0_calib;
+
+		format = 2147483648U; /* 2^24 * 128 */
+		r0_integer = format / rt1011->r0_reg / 128;
+		r0_factor = ((format / rt1011->r0_reg * 100) / 128)
+						- (r0_integer * 100);
+		dev_info(component->dev,	"DP r0 resistance about %d.%02d ohm, reg=0x%X\n",
+			r0_integer, r0_factor, rt1011->r0_reg);
+
+		rt1011_r0_load(rt1011);
+	}
+}
+
+static int rt1011_parse_dp(struct rt1011_priv *rt1011, struct device *dev)
+{
+	device_property_read_u32(dev, "realtek,temperature_calib",
+		&rt1011->temperature_calib);
+	device_property_read_u32(dev, "realtek,r0_calib",
+		&rt1011->r0_calib);
+
+	dev_dbg(dev, "%s: r0_calib: 0x%x, temperture_calib: 0x%x",
+		__func__, rt1011->r0_calib, rt1011->temperature_calib);
+
+	return 0;
 }
 
 static int rt1011_i2c_probe(struct i2c_client *i2c,
@@ -2356,6 +2393,8 @@ static int rt1011_i2c_probe(struct i2c_client *i2c,
 
 	i2c_set_clientdata(i2c, rt1011);
 
+	rt1011_parse_dp(rt1011, &i2c->dev);
+
 	rt1011->regmap = devm_regmap_init_i2c(i2c, &rt1011_regmap);
 	if (IS_ERR(rt1011->regmap)) {
 		ret = PTR_ERR(rt1011->regmap);
diff --git a/sound/soc/codecs/rt1011.h b/sound/soc/codecs/rt1011.h
index 3f7dea1191ad..68fadc15fa8c 100644
--- a/sound/soc/codecs/rt1011.h
+++ b/sound/soc/codecs/rt1011.h
@@ -690,6 +690,7 @@ struct rt1011_priv {
 
 	int bq_drc_set;
 	unsigned int r0_reg, cali_done;
+	unsigned int r0_calib, temperature_calib;
 	int recv_spk_mode;
 };
 
-- 
2.20.1

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

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

end of thread, other threads:[~2019-10-16 12:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-16  8:58 [alsa-devel] [PATCH] ASoC: rt1011: Read and apply r0 and temperature device property shumingf
2019-10-16 10:49 ` Cheng-yi Chiang
2019-10-16 11:23 ` Mark Brown
     [not found]   ` <fb55fba1f6e8441983fbd563e4b89e45@realtek.com>
2019-10-16 11:30     ` Cheng-yi Chiang
2019-10-16 11:38     ` Mark Brown
2019-10-16 12:58 ` [alsa-devel] Applied "ASoC: rt1011: Read and apply r0 and temperature device property" to the asoc tree Mark Brown

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.