xref: /netbsd-src/sys/external/bsd/drm2/dist/include/drm/drm_audio_component.h (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: drm_audio_component.h,v 1.2 2021/12/18 23:45:45 riastradh Exp $	*/
2 
3 // SPDX-License-Identifier: MIT
4 // Copyright © 2014 Intel Corporation
5 
6 #ifndef _DRM_AUDIO_COMPONENT_H_
7 #define _DRM_AUDIO_COMPONENT_H_
8 
9 struct drm_audio_component;
10 struct device;
11 
12 /**
13  * struct drm_audio_component_ops - Ops implemented by DRM driver, called by hda driver
14  */
15 struct drm_audio_component_ops {
16 	/**
17 	 * @owner: drm module to pin down
18 	 */
19 	struct module *owner;
20 	/**
21 	 * @get_power: get the POWER_DOMAIN_AUDIO power well
22 	 *
23 	 * Request the power well to be turned on.
24 	 *
25 	 * Returns a wakeref cookie to be passed back to the corresponding
26 	 * call to @put_power.
27 	 */
28 	unsigned long (*get_power)(struct device *);
29 	/**
30 	 * @put_power: put the POWER_DOMAIN_AUDIO power well
31 	 *
32 	 * Allow the power well to be turned off.
33 	 */
34 	void (*put_power)(struct device *, unsigned long);
35 	/**
36 	 * @codec_wake_override: Enable/disable codec wake signal
37 	 */
38 	void (*codec_wake_override)(struct device *, bool enable);
39 	/**
40 	 * @get_cdclk_freq: Get the Core Display Clock in kHz
41 	 */
42 	int (*get_cdclk_freq)(struct device *);
43 	/**
44 	 * @sync_audio_rate: set n/cts based on the sample rate
45 	 *
46 	 * Called from audio driver. After audio driver sets the
47 	 * sample rate, it will call this function to set n/cts
48 	 */
49 	int (*sync_audio_rate)(struct device *, int port, int pipe, int rate);
50 	/**
51 	 * @get_eld: fill the audio state and ELD bytes for the given port
52 	 *
53 	 * Called from audio driver to get the HDMI/DP audio state of the given
54 	 * digital port, and also fetch ELD bytes to the given pointer.
55 	 *
56 	 * It returns the byte size of the original ELD (not the actually
57 	 * copied size), zero for an invalid ELD, or a negative error code.
58 	 *
59 	 * Note that the returned size may be over @max_bytes.  Then it
60 	 * implies that only a part of ELD has been copied to the buffer.
61 	 */
62 	int (*get_eld)(struct device *, int port, int pipe, bool *enabled,
63 		       unsigned char *buf, int max_bytes);
64 };
65 
66 /**
67  * struct drm_audio_component_audio_ops - Ops implemented by hda driver, called by DRM driver
68  */
69 struct drm_audio_component_audio_ops {
70 	/**
71 	 * @audio_ptr: Pointer to be used in call to pin_eld_notify
72 	 */
73 	void *audio_ptr;
74 	/**
75 	 * @pin_eld_notify: Notify the HDA driver that pin sense and/or ELD information has changed
76 	 *
77 	 * Called when the DRM driver has set up audio pipeline or has just
78 	 * begun to tear it down. This allows the HDA driver to update its
79 	 * status accordingly (even when the HDA controller is in power save
80 	 * mode).
81 	 */
82 	void (*pin_eld_notify)(void *audio_ptr, int port, int pipe);
83 	/**
84 	 * @pin2port: Check and convert from pin node to port number
85 	 *
86 	 * Called by HDA driver to check and convert from the pin widget node
87 	 * number to a port number in the graphics side.
88 	 */
89 	int (*pin2port)(void *audio_ptr, int pin);
90 	/**
91 	 * @master_bind: (Optional) component master bind callback
92 	 *
93 	 * Called at binding master component, for HDA codec-specific
94 	 * handling of dynamic binding.
95 	 */
96 	int (*master_bind)(struct device *dev, struct drm_audio_component *);
97 	/**
98 	 * @master_unbind: (Optional) component master unbind callback
99 	 *
100 	 * Called at unbinding master component, for HDA codec-specific
101 	 * handling of dynamic unbinding.
102 	 */
103 	void (*master_unbind)(struct device *dev, struct drm_audio_component *);
104 };
105 
106 /**
107  * struct drm_audio_component - Used for direct communication between DRM and hda drivers
108  */
109 struct drm_audio_component {
110 	/**
111 	 * @dev: DRM device, used as parameter for ops
112 	 */
113 	struct device *dev;
114 	/**
115 	 * @ops: Ops implemented by DRM driver, called by hda driver
116 	 */
117 	const struct drm_audio_component_ops *ops;
118 	/**
119 	 * @audio_ops: Ops implemented by hda driver, called by DRM driver
120 	 */
121 	const struct drm_audio_component_audio_ops *audio_ops;
122 };
123 
124 #endif /* _DRM_AUDIO_COMPONENT_H_ */
125