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

Commit a57942bf authored by Takashi Iwai's avatar Takashi Iwai
Browse files

ALSA: hda: Make audio component support more generic



This is the final step for more generic support of DRM audio
component.  The generic audio component code is now moved to its own
file, and the symbols are renamed from snd_hac_i915_* to
snd_hdac_acomp_*, respectively.  The generic code is enabled via the
new kconfig, CONFIG_SND_HDA_COMPONENT, while CONFIG_SND_HDA_I915 is
kept as the super-class.

Along with the split, three new callbacks are added to audio_ops:
pin2port is for providing the conversion between the pin number and
the widget id, and master_bind/master_unbin are called at binding /
unbinding the master component, respectively.  All these are optional,
but used in i915 implementation and also other later implementations.

A note about the new snd_hdac_acomp_init() function: there is a slight
difference between this and the old snd_hdac_i915_init().  The latter
(still) synchronizes with the master component binding, i.e. it
assures that the relevant DRM component gets bound when it returns, or
gives a negative error.  Meanwhile the new function doesn't
synchronize but just leaves as is.  It's the responsibility by the
caller's side to synchronize, or the caller may accept the
asynchronous binding on the fly.

v1->v2: Fix missing NULL check in master_bind/unbind

Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 82887c0b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ config DRM_I915
	select SYNC_FILE
	select IOSF_MBI
	select CRC32
	select SND_HDA_I915 if SND_HDA_CORE
	help
	  Choose this option if you have a system that has "Intel Graphics
	  Media Accelerator" or "HD Graphics" integrated graphics,
+23 −0
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@
#ifndef _DRM_AUDIO_COMPONENT_H_
#define _DRM_AUDIO_COMPONENT_H_

struct drm_audio_component;

/**
 * struct drm_audio_component_ops - Ops implemented by DRM driver, called by hda driver
 */
@@ -72,6 +74,27 @@ struct drm_audio_component_audio_ops {
	 * mode).
	 */
	void (*pin_eld_notify)(void *audio_ptr, int port, int pipe);
	/**
	 * @pin2port: Check and convert from pin node to port number
	 *
	 * Called by HDA driver to check and convert from the pin widget node
	 * number to a port number in the graphics side.
	 */
	int (*pin2port)(void *audio_ptr, int pin);
	/**
	 * @master_bind: (Optional) component master bind callback
	 *
	 * Called at binding master component, for HDA codec-specific
	 * handling of dynamic binding.
	 */
	int (*master_bind)(struct device *dev, struct drm_audio_component *);
	/**
	 * @master_unbind: (Optional) component master unbind callback
	 *
	 * Called at unbinding master component, for HDA codec-specific
	 * handling of dynamic unbinding.
	 */
	void (*master_unbind)(struct device *dev, struct drm_audio_component *);
};

/**
+61 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
// HD-Audio helpers to sync with DRM driver

#ifndef __SOUND_HDA_COMPONENT_H
#define __SOUND_HDA_COMPONENT_H

#include <drm/drm_audio_component.h>

#ifdef CONFIG_SND_HDA_COMPONENT
int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable);
int snd_hdac_display_power(struct hdac_bus *bus, bool enable);
int snd_hdac_sync_audio_rate(struct hdac_device *codec, hda_nid_t nid,
			     int dev_id, int rate);
int snd_hdac_acomp_get_eld(struct hdac_device *codec, hda_nid_t nid, int dev_id,
			   bool *audio_enabled, char *buffer, int max_bytes);
int snd_hdac_acomp_init(struct hdac_bus *bus,
			const struct drm_audio_component_audio_ops *aops,
			int (*match_master)(struct device *, void *),
			size_t extra_size);
int snd_hdac_acomp_exit(struct hdac_bus *bus);
int snd_hdac_acomp_register_notifier(struct hdac_bus *bus,
				    const struct drm_audio_component_audio_ops *ops);
#else
static inline int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable)
{
	return 0;
}
static inline int snd_hdac_display_power(struct hdac_bus *bus, bool enable)
{
	return 0;
}
static inline int snd_hdac_sync_audio_rate(struct hdac_device *codec,
					   hda_nid_t nid, int dev_id, int rate)
{
	return 0;
}
static inline int snd_hdac_acomp_get_eld(struct hdac_device *codec, hda_nid_t nid,
					 int dev_id, bool *audio_enabled,
					 char *buffer, int max_bytes)
{
	return -ENODEV;
}
static inline int snd_hdac_acomp_init(struct hdac_bus *bus,
				      const struct drm_audio_component_audio_ops *aops,
				      int (*match_master)(struct device *, void *),
				      size_t extra_size)
{
	return -ENODEV;
}
static inline int snd_hdac_acomp_exit(struct hdac_bus *bus)
{
	return 0;
}
static inline int snd_hdac_acomp_register_notifier(struct hdac_bus *bus,
						  const struct drm_audio_component_audio_ops *ops)
{
	return -ENODEV;
}
#endif

#endif /* __SOUND_HDA_COMPONENT_H */
+3 −36
Original line number Diff line number Diff line
@@ -5,56 +5,23 @@
#ifndef __SOUND_HDA_I915_H
#define __SOUND_HDA_I915_H

#include <drm/drm_audio_component.h>
#include "hda_component.h"

#ifdef CONFIG_SND_HDA_I915
int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable);
int snd_hdac_display_power(struct hdac_bus *bus, bool enable);
void snd_hdac_i915_set_bclk(struct hdac_bus *bus);
int snd_hdac_sync_audio_rate(struct hdac_device *codec, hda_nid_t nid,
			     int dev_id, int rate);
int snd_hdac_acomp_get_eld(struct hdac_device *codec, hda_nid_t nid, int dev_id,
			   bool *audio_enabled, char *buffer, int max_bytes);
int snd_hdac_i915_init(struct hdac_bus *bus);
int snd_hdac_i915_exit(struct hdac_bus *bus);
int snd_hdac_i915_register_notifier(struct hdac_bus *bus,
				    const struct drm_audio_component_audio_ops *ops);
#else
static inline int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable)
{
	return 0;
}
static inline int snd_hdac_display_power(struct hdac_bus *bus, bool enable)
{
	return 0;
}
static inline void snd_hdac_i915_set_bclk(struct hdac_bus *bus)
{
}
static inline int snd_hdac_sync_audio_rate(struct hdac_device *codec,
					   hda_nid_t nid, int dev_id, int rate)
{
	return 0;
}
static inline int snd_hdac_acomp_get_eld(struct hdac_device *codec, hda_nid_t nid,
					 int dev_id, bool *audio_enabled,
					 char *buffer, int max_bytes)
{
	return -ENODEV;
}
static inline int snd_hdac_i915_init(struct hdac_bus *bus)
{
	return -ENODEV;
}
#endif
static inline int snd_hdac_i915_exit(struct hdac_bus *bus)
{
	return 0;
	return snd_hdac_acomp_exit(bus);
}
static inline int snd_hdac_i915_register_notifier(struct hdac_bus *bus,
						  const struct drm_audio_component_audio_ops *ops)
{
	return -ENODEV;
}
#endif

#endif /* __SOUND_HDA_I915_H */
+4 −3
Original line number Diff line number Diff line
@@ -5,11 +5,12 @@ config SND_HDA_CORE
config SND_HDA_DSP_LOADER
	bool

config SND_HDA_COMPONENT
	bool

config SND_HDA_I915
	bool
	default y
	depends on DRM_I915
	depends on SND_HDA_CORE
	select SND_HDA_COMPONENT

config SND_HDA_EXT_CORE
       tristate
Loading