Skip to content

Commit

Permalink
drm/i915: Split audio component to a generic type
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tiwai committed Jul 17, 2018
1 parent 9a9b13d commit ae891ab
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 120 deletions.
22 changes: 12 additions & 10 deletions drivers/gpu/drm/i915/intel_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,11 +639,12 @@ void intel_audio_codec_enable(struct intel_encoder *encoder,
dev_priv->av_enc_map[pipe] = encoder;
mutex_unlock(&dev_priv->av_mutex);

if (acomp && acomp->audio_ops && acomp->audio_ops->pin_eld_notify) {
if (acomp && acomp->base.audio_ops &&
acomp->base.audio_ops->pin_eld_notify) {
/* audio drivers expect pipe = -1 to indicate Non-MST cases */
if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST))
pipe = -1;
acomp->audio_ops->pin_eld_notify(acomp->audio_ops->audio_ptr,
acomp->base.audio_ops->pin_eld_notify(acomp->base.audio_ops->audio_ptr,
(int) port, (int) pipe);
}

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

if (acomp && acomp->audio_ops && acomp->audio_ops->pin_eld_notify) {
if (acomp && acomp->base.audio_ops &&
acomp->base.audio_ops->pin_eld_notify) {
/* audio drivers expect pipe = -1 to indicate Non-MST cases */
if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
pipe = -1;
acomp->audio_ops->pin_eld_notify(acomp->audio_ops->audio_ptr,
acomp->base.audio_ops->pin_eld_notify(acomp->base.audio_ops->audio_ptr,
(int) port, (int) pipe);
}

Expand Down Expand Up @@ -880,7 +882,7 @@ static int i915_audio_component_get_eld(struct device *kdev, int port,
return ret;
}

static const struct i915_audio_component_ops i915_audio_component_ops = {
static const struct drm_audio_component_ops i915_audio_component_ops = {
.owner = THIS_MODULE,
.get_power = i915_audio_component_get_power,
.put_power = i915_audio_component_put_power,
Expand All @@ -897,12 +899,12 @@ static int i915_audio_component_bind(struct device *i915_kdev,
struct drm_i915_private *dev_priv = kdev_to_i915(i915_kdev);
int i;

if (WARN_ON(acomp->ops || acomp->dev))
if (WARN_ON(acomp->base.ops || acomp->base.dev))
return -EEXIST;

drm_modeset_lock_all(&dev_priv->drm);
acomp->ops = &i915_audio_component_ops;
acomp->dev = i915_kdev;
acomp->base.ops = &i915_audio_component_ops;
acomp->base.dev = i915_kdev;
BUILD_BUG_ON(MAX_PORTS != I915_MAX_PORTS);
for (i = 0; i < ARRAY_SIZE(acomp->aud_sample_rate); i++)
acomp->aud_sample_rate[i] = 0;
Expand All @@ -919,8 +921,8 @@ static void i915_audio_component_unbind(struct device *i915_kdev,
struct drm_i915_private *dev_priv = kdev_to_i915(i915_kdev);

drm_modeset_lock_all(&dev_priv->drm);
acomp->ops = NULL;
acomp->dev = NULL;
acomp->base.ops = NULL;
acomp->base.dev = NULL;
dev_priv->audio_component = NULL;
drm_modeset_unlock_all(&dev_priv->drm);
}
Expand Down
95 changes: 95 additions & 0 deletions include/drm/drm_audio_component.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// SPDX-License-Identifier: MIT
// Copyright © 2014 Intel Corporation

#ifndef _DRM_AUDIO_COMPONENT_H_
#define _DRM_AUDIO_COMPONENT_H_

/**
* struct drm_audio_component_ops - Ops implemented by DRM driver, called by hda driver
*/
struct drm_audio_component_ops {
/**
* @owner: drm module to pin down
*/
struct module *owner;
/**
* @get_power: get the POWER_DOMAIN_AUDIO power well
*
* Request the power well to be turned on.
*/
void (*get_power)(struct device *);
/**
* @put_power: put the POWER_DOMAIN_AUDIO power well
*
* Allow the power well to be turned off.
*/
void (*put_power)(struct device *);
/**
* @codec_wake_override: Enable/disable codec wake signal
*/
void (*codec_wake_override)(struct device *, bool enable);
/**
* @get_cdclk_freq: Get the Core Display Clock in kHz
*/
int (*get_cdclk_freq)(struct device *);
/**
* @sync_audio_rate: set n/cts based on the sample rate
*
* Called from audio driver. After audio driver sets the
* sample rate, it will call this function to set n/cts
*/
int (*sync_audio_rate)(struct device *, int port, int pipe, int rate);
/**
* @get_eld: fill the audio state and ELD bytes for the given port
*
* Called from audio driver to get the HDMI/DP audio state of the given
* digital port, and also fetch ELD bytes to the given pointer.
*
* It returns the byte size of the original ELD (not the actually
* copied size), zero for an invalid ELD, or a negative error code.
*
* Note that the returned size may be over @max_bytes. Then it
* implies that only a part of ELD has been copied to the buffer.
*/
int (*get_eld)(struct device *, int port, int pipe, bool *enabled,
unsigned char *buf, int max_bytes);
};

/**
* struct drm_audio_component_audio_ops - Ops implemented by hda driver, called by DRM driver
*/
struct drm_audio_component_audio_ops {
/**
* @audio_ptr: Pointer to be used in call to pin_eld_notify
*/
void *audio_ptr;
/**
* @pin_eld_notify: Notify the HDA driver that pin sense and/or ELD information has changed
*
* Called when the DRM driver has set up audio pipeline or has just
* begun to tear it down. This allows the HDA driver to update its
* status accordingly (even when the HDA controller is in power save
* mode).
*/
void (*pin_eld_notify)(void *audio_ptr, int port, int pipe);
};

/**
* struct drm_audio_component - Used for direct communication between DRM and hda drivers
*/
struct drm_audio_component {
/**
* @dev: DRM device, used as parameter for ops
*/
struct device *dev;
/**
* @ops: Ops implemented by DRM driver, called by hda driver
*/
const struct drm_audio_component_ops *ops;
/**
* @audio_ops: Ops implemented by hda driver, called by DRM driver
*/
const struct drm_audio_component_audio_ops *audio_ops;
};

#endif /* _DRM_AUDIO_COMPONENT_H_ */
85 changes: 5 additions & 80 deletions include/drm/i915_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,101 +24,26 @@
#ifndef _I915_COMPONENT_H_
#define _I915_COMPONENT_H_

#include "drm_audio_component.h"

/* MAX_PORT is the number of port
* It must be sync with I915_MAX_PORTS defined i915_drv.h
*/
#define MAX_PORTS 6

/**
* struct i915_audio_component_ops - Ops implemented by i915 driver, called by hda driver
*/
struct i915_audio_component_ops {
/**
* @owner: i915 module
*/
struct module *owner;
/**
* @get_power: get the POWER_DOMAIN_AUDIO power well
*
* Request the power well to be turned on.
*/
void (*get_power)(struct device *);
/**
* @put_power: put the POWER_DOMAIN_AUDIO power well
*
* Allow the power well to be turned off.
*/
void (*put_power)(struct device *);
/**
* @codec_wake_override: Enable/disable codec wake signal
*/
void (*codec_wake_override)(struct device *, bool enable);
/**
* @get_cdclk_freq: Get the Core Display Clock in kHz
*/
int (*get_cdclk_freq)(struct device *);
/**
* @sync_audio_rate: set n/cts based on the sample rate
*
* Called from audio driver. After audio driver sets the
* sample rate, it will call this function to set n/cts
*/
int (*sync_audio_rate)(struct device *, int port, int pipe, int rate);
/**
* @get_eld: fill the audio state and ELD bytes for the given port
*
* Called from audio driver to get the HDMI/DP audio state of the given
* digital port, and also fetch ELD bytes to the given pointer.
*
* It returns the byte size of the original ELD (not the actually
* copied size), zero for an invalid ELD, or a negative error code.
*
* Note that the returned size may be over @max_bytes. Then it
* implies that only a part of ELD has been copied to the buffer.
*/
int (*get_eld)(struct device *, int port, int pipe, bool *enabled,
unsigned char *buf, int max_bytes);
};

/**
* struct i915_audio_component_audio_ops - Ops implemented by hda driver, called by i915 driver
*/
struct i915_audio_component_audio_ops {
/**
* @audio_ptr: Pointer to be used in call to pin_eld_notify
*/
void *audio_ptr;
/**
* @pin_eld_notify: Notify the HDA driver that pin sense and/or ELD information has changed
*
* Called when the i915 driver has set up audio pipeline or has just
* begun to tear it down. This allows the HDA driver to update its
* status accordingly (even when the HDA controller is in power save
* mode).
*/
void (*pin_eld_notify)(void *audio_ptr, int port, int pipe);
};

/**
* struct i915_audio_component - Used for direct communication between i915 and hda drivers
*/
struct i915_audio_component {
/**
* @dev: i915 device, used as parameter for ops
* @base: the drm_audio_component base class
*/
struct device *dev;
struct drm_audio_component base;

/**
* @aud_sample_rate: the array of audio sample rate per port
*/
int aud_sample_rate[MAX_PORTS];
/**
* @ops: Ops implemented by i915 driver, called by hda driver
*/
const struct i915_audio_component_ops *ops;
/**
* @audio_ops: Ops implemented by hda driver, called by i915 driver
*/
const struct i915_audio_component_audio_ops *audio_ops;
};

#endif /* _I915_COMPONENT_H_ */
6 changes: 3 additions & 3 deletions include/sound/hda_i915.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef __SOUND_HDA_I915_H
#define __SOUND_HDA_I915_H

#include <drm/i915_component.h>
#include <drm/drm_audio_component.h>

#ifdef CONFIG_SND_HDA_I915
int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable);
Expand All @@ -17,7 +17,7 @@ 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(const struct i915_audio_component_audio_ops *);
int snd_hdac_i915_register_notifier(const struct drm_audio_component_audio_ops *);
#else
static inline int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable)
{
Expand Down Expand Up @@ -49,7 +49,7 @@ static inline int snd_hdac_i915_exit(struct hdac_bus *bus)
{
return 0;
}
static inline int snd_hdac_i915_register_notifier(const struct i915_audio_component_audio_ops *ops)
static inline int snd_hdac_i915_register_notifier(const struct drm_audio_component_audio_ops *ops)
{
return -ENODEV;
}
Expand Down
6 changes: 3 additions & 3 deletions include/sound/hdaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ struct hdac_bus {
spinlock_t reg_lock;
struct mutex cmd_mutex;

/* i915 component interface */
struct i915_audio_component *audio_component;
int i915_power_refcount;
/* DRM component interface */
struct drm_audio_component *audio_component;
int drm_power_refcount;

/* parameters required for enhanced capabilities */
int num_streams;
Expand Down
Loading

0 comments on commit ae891ab

Please sign in to comment.