Skip to content

Commit ae891ab

Browse files
committed
drm/i915: Split audio component to a generic type
For allowing other drivers to use the DRM audio component, rename the i915_audio_component_* with drm_audio_component_*, and split the generic part into drm_audio_component.h. The i915 specific stuff remains in struct i915_audio_component, which contains drm_audio_component as the base. The license of drm_audio_component.h is kept to MIT as same as the the original i915_component.h. This is a preliminary change for further development, and no functional changes by this patch itself, merely code-split and renames. v1->v2: Use SPDX for drm_audio_component.h, fix remaining i915 argument in drm_audio_component.h Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 9a9b13d commit ae891ab

8 files changed

Lines changed: 144 additions & 120 deletions

File tree

‎drivers/gpu/drm/i915/intel_audio.c‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -639,11 +639,12 @@ void intel_audio_codec_enable(struct intel_encoder *encoder,
639639
dev_priv->av_enc_map[pipe] = encoder;
640640
mutex_unlock(&dev_priv->av_mutex);
641641

642-
if (acomp && acomp->audio_ops && acomp->audio_ops->pin_eld_notify) {
642+
if (acomp && acomp->base.audio_ops &&
643+
acomp->base.audio_ops->pin_eld_notify) {
643644
/* audio drivers expect pipe = -1 to indicate Non-MST cases */
644645
if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST))
645646
pipe = -1;
646-
acomp->audio_ops->pin_eld_notify(acomp->audio_ops->audio_ptr,
647+
acomp->base.audio_ops->pin_eld_notify(acomp->base.audio_ops->audio_ptr,
647648
(int) port, (int) pipe);
648649
}
649650

@@ -681,11 +682,12 @@ void intel_audio_codec_disable(struct intel_encoder *encoder,
681682
dev_priv->av_enc_map[pipe] = NULL;
682683
mutex_unlock(&dev_priv->av_mutex);
683684

684-
if (acomp && acomp->audio_ops && acomp->audio_ops->pin_eld_notify) {
685+
if (acomp && acomp->base.audio_ops &&
686+
acomp->base.audio_ops->pin_eld_notify) {
685687
/* audio drivers expect pipe = -1 to indicate Non-MST cases */
686688
if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
687689
pipe = -1;
688-
acomp->audio_ops->pin_eld_notify(acomp->audio_ops->audio_ptr,
690+
acomp->base.audio_ops->pin_eld_notify(acomp->base.audio_ops->audio_ptr,
689691
(int) port, (int) pipe);
690692
}
691693

@@ -880,7 +882,7 @@ static int i915_audio_component_get_eld(struct device *kdev, int port,
880882
return ret;
881883
}
882884

883-
static const struct i915_audio_component_ops i915_audio_component_ops = {
885+
static const struct drm_audio_component_ops i915_audio_component_ops = {
884886
.owner = THIS_MODULE,
885887
.get_power = i915_audio_component_get_power,
886888
.put_power = i915_audio_component_put_power,
@@ -897,12 +899,12 @@ static int i915_audio_component_bind(struct device *i915_kdev,
897899
struct drm_i915_private *dev_priv = kdev_to_i915(i915_kdev);
898900
int i;
899901

900-
if (WARN_ON(acomp->ops || acomp->dev))
902+
if (WARN_ON(acomp->base.ops || acomp->base.dev))
901903
return -EEXIST;
902904

903905
drm_modeset_lock_all(&dev_priv->drm);
904-
acomp->ops = &i915_audio_component_ops;
905-
acomp->dev = i915_kdev;
906+
acomp->base.ops = &i915_audio_component_ops;
907+
acomp->base.dev = i915_kdev;
906908
BUILD_BUG_ON(MAX_PORTS != I915_MAX_PORTS);
907909
for (i = 0; i < ARRAY_SIZE(acomp->aud_sample_rate); i++)
908910
acomp->aud_sample_rate[i] = 0;
@@ -919,8 +921,8 @@ static void i915_audio_component_unbind(struct device *i915_kdev,
919921
struct drm_i915_private *dev_priv = kdev_to_i915(i915_kdev);
920922

921923
drm_modeset_lock_all(&dev_priv->drm);
922-
acomp->ops = NULL;
923-
acomp->dev = NULL;
924+
acomp->base.ops = NULL;
925+
acomp->base.dev = NULL;
924926
dev_priv->audio_component = NULL;
925927
drm_modeset_unlock_all(&dev_priv->drm);
926928
}

‎include/drm/drm_audio_component.h‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright © 2014 Intel Corporation
3+
4+
#ifndef _DRM_AUDIO_COMPONENT_H_
5+
#define _DRM_AUDIO_COMPONENT_H_
6+
7+
/**
8+
* struct drm_audio_component_ops - Ops implemented by DRM driver, called by hda driver
9+
*/
10+
struct drm_audio_component_ops {
11+
/**
12+
* @owner: drm module to pin down
13+
*/
14+
struct module *owner;
15+
/**
16+
* @get_power: get the POWER_DOMAIN_AUDIO power well
17+
*
18+
* Request the power well to be turned on.
19+
*/
20+
void (*get_power)(struct device *);
21+
/**
22+
* @put_power: put the POWER_DOMAIN_AUDIO power well
23+
*
24+
* Allow the power well to be turned off.
25+
*/
26+
void (*put_power)(struct device *);
27+
/**
28+
* @codec_wake_override: Enable/disable codec wake signal
29+
*/
30+
void (*codec_wake_override)(struct device *, bool enable);
31+
/**
32+
* @get_cdclk_freq: Get the Core Display Clock in kHz
33+
*/
34+
int (*get_cdclk_freq)(struct device *);
35+
/**
36+
* @sync_audio_rate: set n/cts based on the sample rate
37+
*
38+
* Called from audio driver. After audio driver sets the
39+
* sample rate, it will call this function to set n/cts
40+
*/
41+
int (*sync_audio_rate)(struct device *, int port, int pipe, int rate);
42+
/**
43+
* @get_eld: fill the audio state and ELD bytes for the given port
44+
*
45+
* Called from audio driver to get the HDMI/DP audio state of the given
46+
* digital port, and also fetch ELD bytes to the given pointer.
47+
*
48+
* It returns the byte size of the original ELD (not the actually
49+
* copied size), zero for an invalid ELD, or a negative error code.
50+
*
51+
* Note that the returned size may be over @max_bytes. Then it
52+
* implies that only a part of ELD has been copied to the buffer.
53+
*/
54+
int (*get_eld)(struct device *, int port, int pipe, bool *enabled,
55+
unsigned char *buf, int max_bytes);
56+
};
57+
58+
/**
59+
* struct drm_audio_component_audio_ops - Ops implemented by hda driver, called by DRM driver
60+
*/
61+
struct drm_audio_component_audio_ops {
62+
/**
63+
* @audio_ptr: Pointer to be used in call to pin_eld_notify
64+
*/
65+
void *audio_ptr;
66+
/**
67+
* @pin_eld_notify: Notify the HDA driver that pin sense and/or ELD information has changed
68+
*
69+
* Called when the DRM driver has set up audio pipeline or has just
70+
* begun to tear it down. This allows the HDA driver to update its
71+
* status accordingly (even when the HDA controller is in power save
72+
* mode).
73+
*/
74+
void (*pin_eld_notify)(void *audio_ptr, int port, int pipe);
75+
};
76+
77+
/**
78+
* struct drm_audio_component - Used for direct communication between DRM and hda drivers
79+
*/
80+
struct drm_audio_component {
81+
/**
82+
* @dev: DRM device, used as parameter for ops
83+
*/
84+
struct device *dev;
85+
/**
86+
* @ops: Ops implemented by DRM driver, called by hda driver
87+
*/
88+
const struct drm_audio_component_ops *ops;
89+
/**
90+
* @audio_ops: Ops implemented by hda driver, called by DRM driver
91+
*/
92+
const struct drm_audio_component_audio_ops *audio_ops;
93+
};
94+
95+
#endif /* _DRM_AUDIO_COMPONENT_H_ */

‎include/drm/i915_component.h‎

Lines changed: 5 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -24,101 +24,26 @@
2424
#ifndef _I915_COMPONENT_H_
2525
#define _I915_COMPONENT_H_
2626

27+
#include "drm_audio_component.h"
28+
2729
/* MAX_PORT is the number of port
2830
* It must be sync with I915_MAX_PORTS defined i915_drv.h
2931
*/
3032
#define MAX_PORTS 6
3133

32-
/**
33-
* struct i915_audio_component_ops - Ops implemented by i915 driver, called by hda driver
34-
*/
35-
struct i915_audio_component_ops {
36-
/**
37-
* @owner: i915 module
38-
*/
39-
struct module *owner;
40-
/**
41-
* @get_power: get the POWER_DOMAIN_AUDIO power well
42-
*
43-
* Request the power well to be turned on.
44-
*/
45-
void (*get_power)(struct device *);
46-
/**
47-
* @put_power: put the POWER_DOMAIN_AUDIO power well
48-
*
49-
* Allow the power well to be turned off.
50-
*/
51-
void (*put_power)(struct device *);
52-
/**
53-
* @codec_wake_override: Enable/disable codec wake signal
54-
*/
55-
void (*codec_wake_override)(struct device *, bool enable);
56-
/**
57-
* @get_cdclk_freq: Get the Core Display Clock in kHz
58-
*/
59-
int (*get_cdclk_freq)(struct device *);
60-
/**
61-
* @sync_audio_rate: set n/cts based on the sample rate
62-
*
63-
* Called from audio driver. After audio driver sets the
64-
* sample rate, it will call this function to set n/cts
65-
*/
66-
int (*sync_audio_rate)(struct device *, int port, int pipe, int rate);
67-
/**
68-
* @get_eld: fill the audio state and ELD bytes for the given port
69-
*
70-
* Called from audio driver to get the HDMI/DP audio state of the given
71-
* digital port, and also fetch ELD bytes to the given pointer.
72-
*
73-
* It returns the byte size of the original ELD (not the actually
74-
* copied size), zero for an invalid ELD, or a negative error code.
75-
*
76-
* Note that the returned size may be over @max_bytes. Then it
77-
* implies that only a part of ELD has been copied to the buffer.
78-
*/
79-
int (*get_eld)(struct device *, int port, int pipe, bool *enabled,
80-
unsigned char *buf, int max_bytes);
81-
};
82-
83-
/**
84-
* struct i915_audio_component_audio_ops - Ops implemented by hda driver, called by i915 driver
85-
*/
86-
struct i915_audio_component_audio_ops {
87-
/**
88-
* @audio_ptr: Pointer to be used in call to pin_eld_notify
89-
*/
90-
void *audio_ptr;
91-
/**
92-
* @pin_eld_notify: Notify the HDA driver that pin sense and/or ELD information has changed
93-
*
94-
* Called when the i915 driver has set up audio pipeline or has just
95-
* begun to tear it down. This allows the HDA driver to update its
96-
* status accordingly (even when the HDA controller is in power save
97-
* mode).
98-
*/
99-
void (*pin_eld_notify)(void *audio_ptr, int port, int pipe);
100-
};
101-
10234
/**
10335
* struct i915_audio_component - Used for direct communication between i915 and hda drivers
10436
*/
10537
struct i915_audio_component {
10638
/**
107-
* @dev: i915 device, used as parameter for ops
39+
* @base: the drm_audio_component base class
10840
*/
109-
struct device *dev;
41+
struct drm_audio_component base;
42+
11043
/**
11144
* @aud_sample_rate: the array of audio sample rate per port
11245
*/
11346
int aud_sample_rate[MAX_PORTS];
114-
/**
115-
* @ops: Ops implemented by i915 driver, called by hda driver
116-
*/
117-
const struct i915_audio_component_ops *ops;
118-
/**
119-
* @audio_ops: Ops implemented by hda driver, called by i915 driver
120-
*/
121-
const struct i915_audio_component_audio_ops *audio_ops;
12247
};
12348

12449
#endif /* _I915_COMPONENT_H_ */

‎include/sound/hda_i915.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifndef __SOUND_HDA_I915_H
66
#define __SOUND_HDA_I915_H
77

8-
#include <drm/i915_component.h>
8+
#include <drm/drm_audio_component.h>
99

1010
#ifdef CONFIG_SND_HDA_I915
1111
int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable);
@@ -17,7 +17,7 @@ int snd_hdac_acomp_get_eld(struct hdac_device *codec, hda_nid_t nid, int dev_id,
1717
bool *audio_enabled, char *buffer, int max_bytes);
1818
int snd_hdac_i915_init(struct hdac_bus *bus);
1919
int snd_hdac_i915_exit(struct hdac_bus *bus);
20-
int snd_hdac_i915_register_notifier(const struct i915_audio_component_audio_ops *);
20+
int snd_hdac_i915_register_notifier(const struct drm_audio_component_audio_ops *);
2121
#else
2222
static inline int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable)
2323
{
@@ -49,7 +49,7 @@ static inline int snd_hdac_i915_exit(struct hdac_bus *bus)
4949
{
5050
return 0;
5151
}
52-
static inline int snd_hdac_i915_register_notifier(const struct i915_audio_component_audio_ops *ops)
52+
static inline int snd_hdac_i915_register_notifier(const struct drm_audio_component_audio_ops *ops)
5353
{
5454
return -ENODEV;
5555
}

‎include/sound/hdaudio.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ struct hdac_bus {
333333
spinlock_t reg_lock;
334334
struct mutex cmd_mutex;
335335

336-
/* i915 component interface */
337-
struct i915_audio_component *audio_component;
338-
int i915_power_refcount;
336+
/* DRM component interface */
337+
struct drm_audio_component *audio_component;
338+
int drm_power_refcount;
339339

340340
/* parameters required for enhanced capabilities */
341341
int num_streams;

0 commit comments

Comments
 (0)