Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b37f1d12 authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Mark Brown
Browse files

ASoC: Let snd_soc_platform subclass snd_soc_component



There is an increasing amount of code that is very similar between platforms,
CODECS and other components. Making platforms a component will allow us to
share this code. For now the patch just adds component and component_driver
fields to the platform and platform_driver structs and registers the platform as
a component. Followup patches will be used to consolidate code between the
different types of components.

Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent 98e639fb
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -778,6 +778,7 @@ struct snd_soc_platform_driver {
	int (*remove)(struct snd_soc_platform *);
	int (*suspend)(struct snd_soc_dai *dai);
	int (*resume)(struct snd_soc_dai *dai);
	struct snd_soc_component_driver component_driver;

	/* pcm creation and destruction */
	int (*pcm_new)(struct snd_soc_pcm_runtime *);
@@ -831,6 +832,8 @@ struct snd_soc_platform {
	struct list_head list;
	struct list_head card_list;

	struct snd_soc_component component;

	struct snd_soc_dapm_context dapm;

#ifdef CONFIG_DEBUG_FS
@@ -1107,6 +1110,19 @@ static inline struct snd_soc_codec *snd_soc_component_to_codec(
	return container_of(component, struct snd_soc_codec, component);
}

/**
 * snd_soc_component_to_platform() - Casts a component to the platform it is embedded in
 * @component: The component to cast to a platform
 *
 * This function must only be used on components that are known to be platforms.
 * Otherwise the behavior is undefined.
 */
static inline struct snd_soc_platform *snd_soc_component_to_platform(
	struct snd_soc_component *component)
{
	return container_of(component, struct snd_soc_platform, component);
}

/* codec IO */
unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg);
unsigned int snd_soc_write(struct snd_soc_codec *codec,
+14 −0
Original line number Diff line number Diff line
@@ -3921,6 +3921,8 @@ EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
		const struct snd_soc_platform_driver *platform_drv)
{
	int ret;

	/* create platform component name */
	platform->name = fmt_single_name(dev, &platform->id);
	if (platform->name == NULL)
@@ -3933,6 +3935,16 @@ int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
	platform->dapm.stream_event = platform_drv->stream_event;
	mutex_init(&platform->mutex);

	/* register component */
	ret = __snd_soc_register_component(dev, &platform->component,
					   &platform_drv->component_driver,
					   NULL, NULL, 0, false);
	if (ret < 0) {
		dev_err(platform->component.dev,
			"ASoC: Failed to register component: %d\n", ret);
		return ret;
	}

	mutex_lock(&client_mutex);
	list_add(&platform->list, &platform_list);
	mutex_unlock(&client_mutex);
@@ -3974,6 +3986,8 @@ EXPORT_SYMBOL_GPL(snd_soc_register_platform);
 */
void snd_soc_remove_platform(struct snd_soc_platform *platform)
{
	snd_soc_unregister_component(platform->dev);

	mutex_lock(&client_mutex);
	list_del(&platform->list);
	mutex_unlock(&client_mutex);