Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+144 -120
+12 -10
drivers/gpu/drm/i915/intel_audio.c
··· 639 639 dev_priv->av_enc_map[pipe] = encoder; 640 640 mutex_unlock(&dev_priv->av_mutex); 641 641 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) { 643 644 /* audio drivers expect pipe = -1 to indicate Non-MST cases */ 644 645 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) 645 646 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, 647 648 (int) port, (int) pipe); 648 649 } 649 650 ··· 682 681 dev_priv->av_enc_map[pipe] = NULL; 683 682 mutex_unlock(&dev_priv->av_mutex); 684 683 685 - if (acomp && acomp->audio_ops && acomp->audio_ops->pin_eld_notify) { 684 + if (acomp && acomp->base.audio_ops && 685 + acomp->base.audio_ops->pin_eld_notify) { 686 686 /* audio drivers expect pipe = -1 to indicate Non-MST cases */ 687 687 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST)) 688 688 pipe = -1; 689 - acomp->audio_ops->pin_eld_notify(acomp->audio_ops->audio_ptr, 689 + acomp->base.audio_ops->pin_eld_notify(acomp->base.audio_ops->audio_ptr, 690 690 (int) port, (int) pipe); 691 691 } 692 692 ··· 882 880 return ret; 883 881 } 884 882 885 - static const struct i915_audio_component_ops i915_audio_component_ops = { 883 + static const struct drm_audio_component_ops i915_audio_component_ops = { 886 884 .owner = THIS_MODULE, 887 885 .get_power = i915_audio_component_get_power, 888 886 .put_power = i915_audio_component_put_power, ··· 899 897 struct drm_i915_private *dev_priv = kdev_to_i915(i915_kdev); 900 898 int i; 901 899 902 - if (WARN_ON(acomp->ops || acomp->dev)) 900 + if (WARN_ON(acomp->base.ops || acomp->base.dev)) 903 901 return -EEXIST; 904 902 905 903 drm_modeset_lock_all(&dev_priv->drm); 906 - acomp->ops = &i915_audio_component_ops; 907 - acomp->dev = i915_kdev; 904 + acomp->base.ops = &i915_audio_component_ops; 905 + acomp->base.dev = i915_kdev; 908 906 BUILD_BUG_ON(MAX_PORTS != I915_MAX_PORTS); 909 907 for (i = 0; i < ARRAY_SIZE(acomp->aud_sample_rate); i++) 910 908 acomp->aud_sample_rate[i] = 0; ··· 921 919 struct drm_i915_private *dev_priv = kdev_to_i915(i915_kdev); 922 920 923 921 drm_modeset_lock_all(&dev_priv->drm); 924 - acomp->ops = NULL; 925 - acomp->dev = NULL; 922 + acomp->base.ops = NULL; 923 + acomp->base.dev = NULL; 926 924 dev_priv->audio_component = NULL; 927 925 drm_modeset_unlock_all(&dev_priv->drm); 928 926 }
+95
include/drm/drm_audio_component.h
··· 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_ */
+5 -80
include/drm/i915_component.h
··· 24 24 #ifndef _I915_COMPONENT_H_ 25 25 #define _I915_COMPONENT_H_ 26 26 27 + #include "drm_audio_component.h" 28 + 27 29 /* MAX_PORT is the number of port 28 30 * It must be sync with I915_MAX_PORTS defined i915_drv.h 29 31 */ 30 32 #define MAX_PORTS 6 31 33 32 34 /** 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 - 102 - /** 103 35 * struct i915_audio_component - Used for direct communication between i915 and hda drivers 104 36 */ 105 37 struct i915_audio_component { 106 38 /** 107 - * @dev: i915 device, used as parameter for ops 39 + * @base: the drm_audio_component base class 108 40 */ 109 - struct device *dev; 41 + struct drm_audio_component base; 42 + 110 43 /** 111 44 * @aud_sample_rate: the array of audio sample rate per port 112 45 */ 113 46 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; 122 47 }; 123 48 124 49 #endif /* _I915_COMPONENT_H_ */
+3 -3
include/sound/hda_i915.h
··· 5 5 #ifndef __SOUND_HDA_I915_H 6 6 #define __SOUND_HDA_I915_H 7 7 8 - #include <drm/i915_component.h> 8 + #include <drm/drm_audio_component.h> 9 9 10 10 #ifdef CONFIG_SND_HDA_I915 11 11 int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable); ··· 17 17 bool *audio_enabled, char *buffer, int max_bytes); 18 18 int snd_hdac_i915_init(struct hdac_bus *bus); 19 19 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 *); 21 21 #else 22 22 static inline int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable) 23 23 { ··· 49 49 { 50 50 return 0; 51 51 } 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) 53 53 { 54 54 return -ENODEV; 55 55 }
+3 -3
include/sound/hdaudio.h
··· 333 333 spinlock_t reg_lock; 334 334 struct mutex cmd_mutex; 335 335 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; 339 339 340 340 /* parameters required for enhanced capabilities */ 341 341 int num_streams;
+21 -19
sound/hda/hdac_i915.c
··· 16 16 #include <linux/module.h> 17 17 #include <linux/pci.h> 18 18 #include <linux/component.h> 19 - #include <drm/i915_component.h> 19 + #include <drm/drm_audio_component.h> 20 20 #include <sound/core.h> 21 21 #include <sound/hdaudio.h> 22 22 #include <sound/hda_i915.h> 23 23 #include <sound/hda_register.h> 24 24 25 - static struct i915_audio_component *hdac_acomp; 25 + static struct drm_audio_component *hdac_acomp; 26 26 27 27 /** 28 28 * snd_hdac_set_codec_wakeup - Enable / disable HDMI/DP codec wakeup ··· 39 39 */ 40 40 int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable) 41 41 { 42 - struct i915_audio_component *acomp = bus->audio_component; 42 + struct drm_audio_component *acomp = bus->audio_component; 43 43 44 44 if (!acomp || !acomp->ops) 45 45 return -ENODEV; ··· 74 74 */ 75 75 int snd_hdac_display_power(struct hdac_bus *bus, bool enable) 76 76 { 77 - struct i915_audio_component *acomp = bus->audio_component; 77 + struct drm_audio_component *acomp = bus->audio_component; 78 78 79 79 if (!acomp || !acomp->ops) 80 80 return -ENODEV; ··· 83 83 enable ? "enable" : "disable"); 84 84 85 85 if (enable) { 86 - if (!bus->i915_power_refcount++) { 86 + if (!bus->drm_power_refcount++) { 87 87 acomp->ops->get_power(acomp->dev); 88 88 snd_hdac_set_codec_wakeup(bus, true); 89 89 snd_hdac_set_codec_wakeup(bus, false); 90 90 } 91 91 } else { 92 - WARN_ON(!bus->i915_power_refcount); 93 - if (!--bus->i915_power_refcount) 92 + WARN_ON(!bus->drm_power_refcount); 93 + if (!--bus->drm_power_refcount) 94 94 acomp->ops->put_power(acomp->dev); 95 95 } 96 96 ··· 119 119 */ 120 120 void snd_hdac_i915_set_bclk(struct hdac_bus *bus) 121 121 { 122 - struct i915_audio_component *acomp = bus->audio_component; 122 + struct drm_audio_component *acomp = bus->audio_component; 123 123 struct pci_dev *pci = to_pci_dev(bus->dev); 124 124 int cdclk_freq; 125 125 unsigned int bclk_m, bclk_n; ··· 206 206 int dev_id, int rate) 207 207 { 208 208 struct hdac_bus *bus = codec->bus; 209 - struct i915_audio_component *acomp = bus->audio_component; 209 + struct drm_audio_component *acomp = bus->audio_component; 210 210 int port, pipe; 211 211 212 212 if (!acomp || !acomp->ops || !acomp->ops->sync_audio_rate) ··· 244 244 bool *audio_enabled, char *buffer, int max_bytes) 245 245 { 246 246 struct hdac_bus *bus = codec->bus; 247 - struct i915_audio_component *acomp = bus->audio_component; 247 + struct drm_audio_component *acomp = bus->audio_component; 248 248 int port, pipe; 249 249 250 250 if (!acomp || !acomp->ops || !acomp->ops->get_eld) ··· 262 262 263 263 static int hdac_component_master_bind(struct device *dev) 264 264 { 265 - struct i915_audio_component *acomp = hdac_acomp; 265 + struct drm_audio_component *acomp = hdac_acomp; 266 266 int ret; 267 267 268 268 ret = component_bind_all(dev, acomp); ··· 294 294 295 295 static void hdac_component_master_unbind(struct device *dev) 296 296 { 297 - struct i915_audio_component *acomp = hdac_acomp; 297 + struct drm_audio_component *acomp = hdac_acomp; 298 298 299 299 module_put(acomp->ops->owner); 300 300 component_unbind_all(dev, acomp); ··· 323 323 * 324 324 * Returns zero for success or a negative error code. 325 325 */ 326 - int snd_hdac_i915_register_notifier(const struct i915_audio_component_audio_ops *aops) 326 + int snd_hdac_i915_register_notifier(const struct drm_audio_component_audio_ops *aops) 327 327 { 328 328 if (!hdac_acomp) 329 329 return -ENODEV; ··· 361 361 { 362 362 struct component_match *match = NULL; 363 363 struct device *dev = bus->dev; 364 - struct i915_audio_component *acomp; 364 + struct i915_audio_component *i915_acomp; 365 + struct drm_audio_component *acomp; 365 366 int ret; 366 367 367 368 if (WARN_ON(hdac_acomp)) ··· 371 370 if (!i915_gfx_present()) 372 371 return -ENODEV; 373 372 374 - acomp = kzalloc(sizeof(*acomp), GFP_KERNEL); 375 - if (!acomp) 373 + i915_acomp = kzalloc(sizeof(*i915_acomp), GFP_KERNEL); 374 + if (!i915_acomp) 376 375 return -ENOMEM; 376 + acomp = &i915_acomp->base; 377 377 bus->audio_component = acomp; 378 378 hdac_acomp = acomp; 379 379 ··· 423 421 int snd_hdac_i915_exit(struct hdac_bus *bus) 424 422 { 425 423 struct device *dev = bus->dev; 426 - struct i915_audio_component *acomp = bus->audio_component; 424 + struct drm_audio_component *acomp = bus->audio_component; 427 425 428 426 if (!acomp) 429 427 return 0; 430 428 431 - WARN_ON(bus->i915_power_refcount); 432 - if (bus->i915_power_refcount > 0 && acomp->ops) 429 + WARN_ON(bus->drm_power_refcount); 430 + if (bus->drm_power_refcount > 0 && acomp->ops) 433 431 acomp->ops->put_power(acomp->dev); 434 432 435 433 component_master_del(dev, &hdac_component_master_ops);
+4 -4
sound/pci/hda/patch_hdmi.c
··· 177 177 178 178 /* i915/powerwell (Haswell+/Valleyview+) specific */ 179 179 bool use_acomp_notifier; /* use i915 eld_notify callback for hotplug */ 180 - struct i915_audio_component_audio_ops i915_audio_ops; 180 + struct drm_audio_component_audio_ops drm_audio_ops; 181 181 182 182 struct hdac_chmap chmap; 183 183 hda_nid_t vendor_nid; ··· 2511 2511 struct hdmi_spec *spec = codec->spec; 2512 2512 2513 2513 spec->use_acomp_notifier = true; 2514 - spec->i915_audio_ops.audio_ptr = codec; 2514 + spec->drm_audio_ops.audio_ptr = codec; 2515 2515 /* intel_audio_codec_enable() or intel_audio_codec_disable() 2516 2516 * will call pin_eld_notify with using audio_ptr pointer 2517 2517 * We need make sure audio_ptr is really setup 2518 2518 */ 2519 2519 wmb(); 2520 - spec->i915_audio_ops.pin_eld_notify = intel_pin_eld_notify; 2521 - snd_hdac_i915_register_notifier(&spec->i915_audio_ops); 2520 + spec->drm_audio_ops.pin_eld_notify = intel_pin_eld_notify; 2521 + snd_hdac_i915_register_notifier(&spec->drm_audio_ops); 2522 2522 } 2523 2523 2524 2524 /* setup_stream ops override for HSW+ */
+1 -1
sound/soc/codecs/hdac_hdmi.c
··· 1583 1583 1584 1584 } 1585 1585 1586 - static struct i915_audio_component_audio_ops aops = { 1586 + static struct drm_audio_component_audio_ops aops = { 1587 1587 .pin_eld_notify = hdac_hdmi_eld_notify_cb, 1588 1588 }; 1589 1589