Skip to contentSkip to conversation

ASoC: Move IO and kcontrols to the component level

PATCH Superseded Lars-Peter Clausen 1 participant 7 messages Apr 22, 2014

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover ASoC: Move IO and kcontrols to the component level

The only change in v3 is the renaming of the component IO mutex from 'mutex' to 'io_mutex'.

v2 cover letter:

This series contains the remaining patches from the previous series that have not been applied yet. The series has been rebased ontop of asoc/for-next and depends on topic/sta350, topic/core, topic/dapm, topic/cache and topic/component.

Some minor updates were made to the patches and three new patches:
* One new user of snd_kcontrol_chip() showed up, the patch converts it to snd_soc_kcontrol_codec()
* Change return type of snd_soc_write() from unsigned int to int
* Remove ASoC level tracing

Original cover letter:

This series is the first step towards full componentisation of the ASoC core. It moves both the IO abstraction layers within ASoC as well as the standard set of kcontrols to the component level. This for example means we can get rid of constructs like

	if (w->codec)
		snd_soc_read(....)
	else if(w->platform)
		snd_soc_platform_read(...)

Moving the kcontrols to the component level means we can use the same implementation also for other non-CODEC components. E.g. there seems to be an increasing amount of CPU components that have basic signal processing and things like volume controls etc. whose register layout is similar to those used in CODECs. Currently each CPU component driver re-implements these controls by hand.

The first two patches introduce two new helper functions which hide the actual implementation on how the CODEC or platform struct that register a control can be obtained from the control. This means that when the actual implementation is changed only the two helper functions need to be updated and not every single driver. The patches that follow that are just cleanups removing unused IO stuff and move all IO functions to soc-io.c. The next step is to make platforms also components. And then finally first the IO abstraction layers in ASoC are unified at the component level and then on top of that the kcontrol helpers are moved to the component level.

The series depends on quite a few topic branches related to changes to the core and cleanups for individual drivers. It is probably best to place it on top of asoc-v3.15-2. The patch that moves the kcontrols to the component level also has a runtime dependency on the not yet applied patches that move the ams-delta and mfld_machine controls to the card level.

Lars-Peter Clausen (5):
ASoC: Move IO abstraction to the component level
ASoC: Move standard kcontrol helpers to the component level
ASoC: Remove snd_soc_update_bits_locked()
ASoC: dapm: Rename soc_widget_update_bits_locked() to
soc_widget_update_bits()
ASoC: Remove ASoC level IO tracing

 include/sound/soc-dapm.h    |   1 +
 include/sound/soc.h         |  51 +++++--
 include/trace/events/asoc.h |  92 -------------
 sound/soc/omap/omap-hdmi.c  |   1 -
 sound/soc/soc-core.c        | 285 +++++++++++++++++++++++++-------------
 sound/soc/soc-dapm.c        |  91 ++----------
 sound/soc/soc-io.c          | 327 ++++++++++++++++++++++++++------------------
 7 files changed, 447 insertions(+), 401 deletions(-)
Signature · 1 line
1.8.0
#1 lore raw

PATCH v3 1/5 ASoC: Move IO abstraction to the component level

We currently have two very similar IO abstractions in ASoC, one for CODECs, the other for platforms. Moving this to the component level will allow us to unify those two. It will also enable us to move the standard kcontrol helpers as well as DAPM support to the component level.

The new component level abstraction layer is primarily build around regmap. There is a per component pointer for the regmap instance for the underlying device. There are four new function snd_soc_component_read(), snd_soc_component_write(), snd_soc_component_update_bits() and snd_soc_component_update_bits_async(). They have the same signature as their regmap counter-part and will internally forward the call one-to-one to regmap. If the component it not using regmap it will fallback to using the custom IO callbacks. This is done to be able to support drivers that haven't been converted to regmap yet, but it is expected that this will eventually be removed in the future once all component drivers have been converted to regmap.

---
Changes since v2:
* Rename mutex to io_mutex
Changes since v1:
* Rebased onto asoc/for-next
* Add kernel doc for the new functions
* Rename snd_soc_component_set_cache_io() to snd_soc_component_init_io()
* Removed stubbed out version of snd_soc_component_init_io(), the only regmap function in there that we use is regmap_get_val_bytes() and that is already stubbed out perfectly fine by the regmap code (and given that almost all CODECs require regmap chances that we build without regmap support in the first place are quite low).

---
 include/sound/soc-dapm.h   |   1 +
 include/sound/soc.h        |  31 ++++-
 sound/soc/omap/omap-hdmi.c |   1 -
 sound/soc/soc-core.c       |  96 ++++++++++----
 sound/soc/soc-dapm.c       |  84 ++----------
 sound/soc/soc-io.c         | 322 +++++++++++++++++++++++++++++----------------
 6 files changed, 317 insertions(+), 218 deletions(-)
include/sound/soc-dapm.h +1 -0
index 5ec03b5..b041fc6 100644
@@ -594,6 +594,7 @@ struct snd_soc_dapm_context {
 			     enum snd_soc_dapm_type, int);
 
 	struct device *dev; /* from parent - for debug */
+	struct snd_soc_component *component; /* parent component */
 	struct snd_soc_codec *codec; /* parent codec */
 	struct snd_soc_platform *platform; /* parent platform */
 	struct snd_soc_card *card; /* parent card */
include/sound/soc.h +24 -7
index de62475..554c650 100644
@@ -393,8 +393,6 @@ int devm_snd_soc_register_component(struct device *dev,
 			 const struct snd_soc_component_driver *cmpnt_drv,
 			 struct snd_soc_dai_driver *dai_drv, int num_dai);
 void snd_soc_unregister_component(struct device *dev);
-int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
-			       struct regmap *regmap);
 int snd_soc_cache_sync(struct snd_soc_codec *codec);
 int snd_soc_cache_init(struct snd_soc_codec *codec);
 int snd_soc_cache_exit(struct snd_soc_codec *codec);
@@ -672,6 +670,14 @@ struct snd_soc_component {
 	const struct snd_soc_component_driver *driver;
 
 	struct list_head dai_list;
+
+	int (*read)(struct snd_soc_component *, unsigned int, unsigned int *);
+	int (*write)(struct snd_soc_component *, unsigned int, unsigned int);
+
+	struct regmap *regmap;
+	int val_bytes;
+
+	struct mutex io_mutex;
 };
 
 /* SoC Audio Codec device */
@@ -696,18 +702,14 @@ struct snd_soc_codec {
 	unsigned int ac97_registered:1; /* Codec has been AC97 registered */
 	unsigned int ac97_created:1; /* Codec has been created by SoC */
 	unsigned int cache_init:1; /* codec cache has been initialized */
-	unsigned int using_regmap:1; /* using regmap access */
 	u32 cache_only;  /* Suppress writes to hardware */
 	u32 cache_sync; /* Cache needs to be synced to hardware */
 
 	/* codec IO */
 	void *control_data; /* codec control (i2c/3wire) data */
 	hw_write_t hw_write;
-	unsigned int (*read)(struct snd_soc_codec *, unsigned int);
-	int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
 	void *reg_cache;
 	struct mutex cache_rw_mutex;
-	int val_bytes;
 
 	/* component */
 	struct snd_soc_component component;
@@ -824,7 +826,6 @@ struct snd_soc_platform {
 	int id;
 	struct device *dev;
 	const struct snd_soc_platform_driver *driver;
-	struct mutex mutex;
 
 	unsigned int suspended:1; /* platform is suspended */
 	unsigned int probed:1;
@@ -1129,6 +1130,22 @@ unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg);
 int snd_soc_write(struct snd_soc_codec *codec, unsigned int reg,
 	unsigned int val);
 
+/* component IO */
+int snd_soc_component_read(struct snd_soc_component *component,
+	unsigned int reg, unsigned int *val);
+int snd_soc_component_write(struct snd_soc_component *component,
+	unsigned int reg, unsigned int val);
+int snd_soc_component_update_bits(struct snd_soc_component *component,
+	unsigned int reg, unsigned int mask, unsigned int val);
+int snd_soc_component_update_bits_async(struct snd_soc_component *component,
+	unsigned int reg, unsigned int mask, unsigned int val);
+void snd_soc_component_async_complete(struct snd_soc_component *component);
+int snd_soc_component_test_bits(struct snd_soc_component *component,
+	unsigned int reg, unsigned int mask, unsigned int value);
+
+int snd_soc_component_init_io(struct snd_soc_component *component,
+	struct regmap *regmap);
+
 /* device driver data */
 
 static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card,
sound/soc/omap/omap-hdmi.c +0 -1
index 32614b4..537a1ec 100644
@@ -330,7 +330,6 @@ static int omap_hdmi_probe(struct platform_device *pdev)
 
 	return omap_pcm_platform_register(&pdev->dev);
 }
-}
 
 static int omap_hdmi_remove(struct platform_device *pdev)
 {
sound/soc/soc-core.c +71 -25

229 lines not on this page · raw message

sound/soc/soc-dapm.c +11 -73

97 lines not on this page · raw message

sound/soc/soc-io.c +210 -112

391 lines not on this page · raw message

Signature · 1 line
1.8.0
#2 lore raw

Re: [PATCH v3 1/5] ASoC: Move IO abstraction to the component level

Quoted 1 line · Lars-Peter Clausen
  sound/soc/omap/omap-hdmi.c |   1 -

Argh... this was of course not supposed to be in here...

#3 lore raw

PATCH v3 2/5 ASoC: Move standard kcontrol helpers to the component level

In reply to Lars-Peter Clausen

After moving the IO layer inside ASoC to the component level we can now easily move the standard control helpers also to the component level. This allows to reuse the same standard helper control implementations for other components.

---
 include/sound/soc.h  |  20 ++++-
 sound/soc/soc-core.c | 221 ++++++++++++++++++++++++++++++++-------------------
 2 files changed, 156 insertions(+), 85 deletions(-)
include/sound/soc.h +18 -2
index 554c650..19a82ce 100644
@@ -1250,6 +1250,22 @@ static inline bool snd_soc_codec_is_active(struct snd_soc_codec *codec)
 }
 
 /**
+ * snd_soc_kcontrol_component() - Returns the component that registered the
+ *  control
+ * @kcontrol: The control for which to get the component
+ *
+ * Note: This function will work correctly if the control has been registered
+ * for a component. Either with snd_soc_add_codec_controls() or
+ * snd_soc_add_platform_controls() or via  table based setup for either a
+ * CODEC, a platform or component driver. Otherwise the behavior is undefined.
+ */
+static inline struct snd_soc_component *snd_soc_kcontrol_component(
+	struct snd_kcontrol *kcontrol)
+{
+	return snd_kcontrol_chip(kcontrol);
+}
+
+/**
  * snd_soc_kcontrol_codec() - Returns the CODEC that registered the control
  * @kcontrol: The control for which to get the CODEC
  *
@@ -1260,7 +1276,7 @@ static inline bool snd_soc_codec_is_active(struct snd_soc_codec *codec)
 static inline struct snd_soc_codec *snd_soc_kcontrol_codec(
 	struct snd_kcontrol *kcontrol)
 {
-	return snd_kcontrol_chip(kcontrol);
+	return snd_soc_component_to_codec(snd_soc_kcontrol_component(kcontrol));
 }
 
 /**
@@ -1274,7 +1290,7 @@ static inline struct snd_soc_codec *snd_soc_kcontrol_codec(
 static inline struct snd_soc_platform *snd_soc_kcontrol_platform(
 	struct snd_kcontrol *kcontrol)
 {
-	return snd_kcontrol_chip(kcontrol);
+	return snd_soc_component_to_platform(snd_soc_kcontrol_component(kcontrol));
 }
 
 int snd_soc_util_init(void);
sound/soc/soc-core.c +138 -83

562 lines not on this page · raw message

Signature · 1 line
1.8.0
#4 lore raw

PATCH v3 3/5 ASoC: Remove snd_soc_update_bits_locked()

In reply to Lars-Peter Clausen

There are no users of snd_soc_update_bits_locked() left and it is identical to snd_soc_update_bits(). So it can be removed.

---
 sound/soc/soc-io.c | 20 --------------------
 1 file changed, 20 deletions(-)
sound/soc/soc-io.c +0 -20
index ac64fd7..2ead9ed 100644
@@ -241,26 +241,6 @@ int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned int reg,
 EXPORT_SYMBOL_GPL(snd_soc_update_bits);
 
 /**
- * snd_soc_update_bits_locked - update codec register bits
- * @codec: audio codec
- * @reg: codec register
- * @mask: register mask
- * @value: new value
- *
- * Writes new register value, and takes the codec mutex.
- *
- * Returns 1 for change else 0.
- */
-int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
-			       unsigned int reg, unsigned int mask,
-			       unsigned int value)
-{
-	return snd_soc_component_update_bits(&codec->component, reg, mask,
-		value);
-}
-EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
-
-/**
  * snd_soc_test_bits - test register for change
  * @codec: audio codec
  * @reg: codec register
Signature · 1 line
1.8.0
#5 lore raw

PATCH v3 4/5 ASoC: dapm: Rename soc_widget_update_bits_locked() to soc_widget_update_bits()

In reply to Lars-Peter Clausen

There is no unlocked version of soc_widget_update_bits_locked() and there is no plan to introduce it in the near future, so drop the _locked suffix.

---
 sound/soc/soc-dapm.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
sound/soc/soc-dapm.c +4 -5
index 85a594f..a2475e1 100644
@@ -383,7 +383,7 @@ static int soc_widget_read(struct snd_soc_dapm_widget *w, int reg,
 	return snd_soc_component_read(w->dapm->component, reg, value);
 }
 
-static int soc_widget_update_bits_locked(struct snd_soc_dapm_widget *w,
+static int soc_widget_update_bits(struct snd_soc_dapm_widget *w,
 	int reg, unsigned int mask, unsigned int value)
 {
 	if (!w->dapm->component)
@@ -1070,7 +1070,7 @@ int dapm_reg_event(struct snd_soc_dapm_widget *w,
 	else
 		val = w->off_val;
 
-	soc_widget_update_bits_locked(w, -(w->reg + 1),
+	soc_widget_update_bits(w, -(w->reg + 1),
 			    w->mask << w->shift, val << w->shift);
 
 	return 0;
@@ -1366,7 +1366,7 @@ static void dapm_seq_run_coalesced(struct snd_soc_card *card,
 			"pop test : Applying 0x%x/0x%x to %x in %dms\n",
 			value, mask, reg, card->pop_time);
 		pop_wait(card->pop_time);
-		soc_widget_update_bits_locked(w, reg, mask, value);
+		soc_widget_update_bits(w, reg, mask, value);
 	}
 
 	list_for_each_entry(w, pending, power_list) {
@@ -1512,8 +1512,7 @@ static void dapm_widget_update(struct snd_soc_card *card)
 	if (!w)
 		return;
 
-	ret = soc_widget_update_bits_locked(w, update->reg, update->mask,
-				  update->val);
+	ret = soc_widget_update_bits(w, update->reg, update->mask, update->val);
 	if (ret < 0)
 		dev_err(w->dapm->dev, "ASoC: %s DAPM update failed: %d\n",
 			w->name, ret);
Signature · 1 line
1.8.0
#6 lore raw

PATCH v3 5/5 ASoC: Remove ASoC level IO tracing

In reply to Lars-Peter Clausen

The ASoC framework is in the process of migrating all IO operations to regmap. regmap has its own more sophisticated tracing infrastructure for IO operations, which means that the ASoC level IO tracing becomes redundant, hence this patch removes them. There are still a handful of ASoC drivers left that do not use regmap yet, but hopefully the removal of the ASoC IO tracing will be an additional incentive to switch to regmap.

---
New in v2

---
 include/trace/events/asoc.h | 92 ---------------------------------------------
 sound/soc/soc-io.c          | 11 ------
 2 files changed, 103 deletions(-)
include/trace/events/asoc.h +0 -92
index 03996b2..c75c795 100644
@@ -11,102 +11,10 @@
 
 struct snd_soc_jack;
 struct snd_soc_codec;
-struct snd_soc_platform;
 struct snd_soc_card;
 struct snd_soc_dapm_widget;
 struct snd_soc_dapm_path;
 
-/*
- * Log register events
- */
-DECLARE_EVENT_CLASS(snd_soc_reg,
-
-	TP_PROTO(struct snd_soc_codec *codec, unsigned int reg,
-		 unsigned int val),
-
-	TP_ARGS(codec, reg, val),
-
-	TP_STRUCT__entry(
-		__string(	name,		codec->name	)
-		__field(	int,		id		)
-		__field(	unsigned int,	reg		)
-		__field(	unsigned int,	val		)
-	),
-
-	TP_fast_assign(
-		__assign_str(name, codec->name);
-		__entry->id = codec->id;
-		__entry->reg = reg;
-		__entry->val = val;
-	),
-
-	TP_printk("codec=%s.%d reg=%x val=%x", __get_str(name),
-		  (int)__entry->id, (unsigned int)__entry->reg,
-		  (unsigned int)__entry->val)
-);
-
-DEFINE_EVENT(snd_soc_reg, snd_soc_reg_write,
-
-	TP_PROTO(struct snd_soc_codec *codec, unsigned int reg,
-		 unsigned int val),
-
-	TP_ARGS(codec, reg, val)
-
-);
-
-DEFINE_EVENT(snd_soc_reg, snd_soc_reg_read,
-
-	TP_PROTO(struct snd_soc_codec *codec, unsigned int reg,
-		 unsigned int val),
-
-	TP_ARGS(codec, reg, val)
-
-);
-
-DECLARE_EVENT_CLASS(snd_soc_preg,
-
-	TP_PROTO(struct snd_soc_platform *platform, unsigned int reg,
-		 unsigned int val),
-
-	TP_ARGS(platform, reg, val),
-
-	TP_STRUCT__entry(
-		__string(	name,		platform->name	)
-		__field(	int,		id		)
-		__field(	unsigned int,	reg		)
-		__field(	unsigned int,	val		)
-	),
-
-	TP_fast_assign(
-		__assign_str(name, platform->name);
-		__entry->id = platform->id;
-		__entry->reg = reg;
-		__entry->val = val;
-	),
-
-	TP_printk("platform=%s.%d reg=%x val=%x", __get_str(name),
-		  (int)__entry->id, (unsigned int)__entry->reg,
-		  (unsigned int)__entry->val)
-);
-
-DEFINE_EVENT(snd_soc_preg, snd_soc_preg_write,
-
-	TP_PROTO(struct snd_soc_platform *platform, unsigned int reg,
-		 unsigned int val),
-
-	TP_ARGS(platform, reg, val)
-
-);
-
-DEFINE_EVENT(snd_soc_preg, snd_soc_preg_read,
-
-	TP_PROTO(struct snd_soc_platform *platform, unsigned int reg,
-		 unsigned int val),
-
-	TP_ARGS(platform, reg, val)
-
-);
-
 DECLARE_EVENT_CLASS(snd_soc_card,
 
 	TP_PROTO(struct snd_soc_card *card, int val),
sound/soc/soc-io.c +0 -11
index 2ead9ed..7767fbd 100644
@@ -17,8 +17,6 @@
 #include <linux/export.h>
 #include <sound/soc.h>
 
-#include <trace/events/asoc.h>
-
 /**
  * snd_soc_component_read() - Read register value
  * @component: Component to read from
@@ -39,8 +37,6 @@ int snd_soc_component_read(struct snd_soc_component *component,
 	else
 		ret = -EIO;
 
-	dev_dbg(component->dev, "read %x => %x\n", reg, *val);
-
 	return ret;
 }
 EXPORT_SYMBOL_GPL(snd_soc_component_read);
@@ -56,8 +52,6 @@ EXPORT_SYMBOL_GPL(snd_soc_component_read);
 int snd_soc_component_write(struct snd_soc_component *component,
 	unsigned int reg, unsigned int val)
 {
-	dev_dbg(component->dev, "write %x = %x\n", reg, val);
-
 	if (component->regmap)
 		return regmap_write(component->regmap, reg, val);
 	else if (component->write)
@@ -207,7 +201,6 @@ unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
 	ret = snd_soc_component_read(&codec->component, reg, &val);
 	if (ret < 0)
 		return -1;
-	trace_snd_soc_reg_read(codec, reg, val);
 
 	return val;
 }
@@ -216,7 +209,6 @@ EXPORT_SYMBOL_GPL(snd_soc_read);
 int snd_soc_write(struct snd_soc_codec *codec, unsigned int reg,
 	unsigned int val)
 {
-	trace_snd_soc_reg_write(codec, reg, val);
 	return snd_soc_component_write(&codec->component, reg, val);
 }
 EXPORT_SYMBOL_GPL(snd_soc_write);
@@ -269,8 +261,6 @@ int snd_soc_platform_read(struct snd_soc_platform *platform,
 	if (ret < 0)
 		return -1;
 
-	trace_snd_soc_preg_read(platform, reg, val);
-
 	return val;
 }
 EXPORT_SYMBOL_GPL(snd_soc_platform_read);
@@ -278,7 +268,6 @@ EXPORT_SYMBOL_GPL(snd_soc_platform_read);
 int snd_soc_platform_write(struct snd_soc_platform *platform,
 					 unsigned int reg, unsigned int val)
 {
-	trace_snd_soc_preg_write(platform, reg, val);
 	return snd_soc_component_write(&platform->component, reg, val);
 }
 EXPORT_SYMBOL_GPL(snd_soc_platform_write);
Signature · 1 line
1.8.0