]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/sound/hdaudio_ext.h
ALSA: hdac: Fix size allocation for ext device allocation
[mirror_ubuntu-bionic-kernel.git] / include / sound / hdaudio_ext.h
CommitLineData
dfe66a18
JK
1#ifndef __SOUND_HDAUDIO_EXT_H
2#define __SOUND_HDAUDIO_EXT_H
3
4#include <sound/hdaudio.h>
5
6/**
7 * hdac_ext_bus: HDAC extended bus for extended HDA caps
8 *
9 * @bus: hdac bus
10 * @num_streams: streams supported
11 * @ppcap: pp capabilities pointer
12 * @spbcap: SPIB capabilities pointer
13 * @mlcap: MultiLink capabilities pointer
14 * @gtscap: gts capabilities pointer
15 * @hlink_list: link list of HDA links
16 */
17struct hdac_ext_bus {
18 struct hdac_bus bus;
19 int num_streams;
20 int idx;
21
22 void __iomem *ppcap;
23 void __iomem *spbcap;
24 void __iomem *mlcap;
25 void __iomem *gtscap;
26
27 struct list_head hlink_list;
28};
29
30int snd_hdac_ext_bus_init(struct hdac_ext_bus *sbus, struct device *dev,
31 const struct hdac_bus_ops *ops,
32 const struct hdac_io_ops *io_ops);
33
34void snd_hdac_ext_bus_exit(struct hdac_ext_bus *sbus);
35int snd_hdac_ext_bus_device_init(struct hdac_ext_bus *sbus, int addr);
36void snd_hdac_ext_bus_device_exit(struct hdac_device *hdev);
ee2d51b3 37void snd_hdac_ext_bus_device_remove(struct hdac_ext_bus *ebus);
dfe66a18
JK
38
39#define ebus_to_hbus(ebus) (&(ebus)->bus)
40#define hbus_to_ebus(_bus) \
41 container_of(_bus, struct hdac_ext_bus, bus)
42
43int snd_hdac_ext_bus_parse_capabilities(struct hdac_ext_bus *sbus);
44void snd_hdac_ext_bus_ppcap_enable(struct hdac_ext_bus *chip, bool enable);
45void snd_hdac_ext_bus_ppcap_int_enable(struct hdac_ext_bus *chip, bool enable);
46
0b00a561
JK
47void snd_hdac_ext_stream_spbcap_enable(struct hdac_ext_bus *chip,
48 bool enable, int index);
49
50int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_ext_bus *bus);
0b00a561
JK
51struct hdac_ext_link *snd_hdac_ext_bus_get_link(struct hdac_ext_bus *bus,
52 const char *codec_name);
53
54enum hdac_ext_stream_type {
55 HDAC_EXT_STREAM_TYPE_COUPLED = 0,
56 HDAC_EXT_STREAM_TYPE_HOST,
57 HDAC_EXT_STREAM_TYPE_LINK
58};
59
df203a4e
JK
60/**
61 * hdac_ext_stream: HDAC extended stream for extended HDA caps
62 *
63 * @hstream: hdac_stream
64 * @pphc_addr: processing pipe host stream pointer
65 * @pplc_addr: processing pipe link stream pointer
ee8bc4df
JK
66 * @spib_addr: software position in buffers stream pointer
67 * @fifo_addr: software position Max fifos stream pointer
df203a4e
JK
68 * @decoupled: stream host and link is decoupled
69 * @link_locked: link is locked
70 * @link_prepared: link is prepared
71 * link_substream: link substream
72 */
73struct hdac_ext_stream {
74 struct hdac_stream hstream;
75
76 void __iomem *pphc_addr;
77 void __iomem *pplc_addr;
78
ee8bc4df
JK
79 void __iomem *spib_addr;
80 void __iomem *fifo_addr;
81
df203a4e
JK
82 bool decoupled:1;
83 bool link_locked:1;
84 bool link_prepared;
85
86 struct snd_pcm_substream *link_substream;
87};
88
89#define hdac_stream(s) (&(s)->hstream)
90#define stream_to_hdac_ext_stream(s) \
91 container_of(s, struct hdac_ext_stream, hstream)
92
93void snd_hdac_ext_stream_init(struct hdac_ext_bus *bus,
94 struct hdac_ext_stream *stream, int idx,
95 int direction, int tag);
e7a3484d
VK
96int snd_hdac_ext_stream_init_all(struct hdac_ext_bus *ebus, int start_idx,
97 int num_stream, int dir);
98void snd_hdac_stream_free_all(struct hdac_ext_bus *ebus);
bab4445f 99void snd_hdac_link_free_all(struct hdac_ext_bus *ebus);
df203a4e
JK
100struct hdac_ext_stream *snd_hdac_ext_stream_assign(struct hdac_ext_bus *bus,
101 struct snd_pcm_substream *substream,
102 int type);
103void snd_hdac_ext_stream_release(struct hdac_ext_stream *azx_dev, int type);
104void snd_hdac_ext_stream_decouple(struct hdac_ext_bus *bus,
105 struct hdac_ext_stream *azx_dev, bool decouple);
106void snd_hdac_ext_stop_streams(struct hdac_ext_bus *sbus);
107
ee8bc4df
JK
108int snd_hdac_ext_stream_set_spib(struct hdac_ext_bus *ebus,
109 struct hdac_ext_stream *stream, u32 value);
110int snd_hdac_ext_stream_set_spbmaxfifo(struct hdac_ext_bus *ebus,
111 struct hdac_ext_stream *stream);
112
df203a4e
JK
113void snd_hdac_ext_link_stream_start(struct hdac_ext_stream *hstream);
114void snd_hdac_ext_link_stream_clear(struct hdac_ext_stream *hstream);
115void snd_hdac_ext_link_stream_reset(struct hdac_ext_stream *hstream);
116int snd_hdac_ext_link_stream_setup(struct hdac_ext_stream *stream, int fmt);
117
0b00a561
JK
118struct hdac_ext_link {
119 struct hdac_bus *bus;
120 int index;
121 void __iomem *ml_addr; /* link output stream reg pointer */
122 u32 lcaps; /* link capablities */
123 u16 lsdiid; /* link sdi identifier */
124 struct list_head list;
125};
126
127int snd_hdac_ext_bus_link_power_up(struct hdac_ext_link *link);
128int snd_hdac_ext_bus_link_power_down(struct hdac_ext_link *link);
c5b0c09b 129int snd_hdac_ext_bus_link_power_down_all(struct hdac_ext_bus *ebus);
0b00a561
JK
130void snd_hdac_ext_link_set_stream_id(struct hdac_ext_link *link,
131 int stream);
132void snd_hdac_ext_link_clear_stream_id(struct hdac_ext_link *link,
133 int stream);
134
135/* update register macro */
136#define snd_hdac_updatel(addr, reg, mask, val) \
137 writel(((readl(addr + reg) & ~(mask)) | (val)), \
138 addr + reg)
139
df203a4e
JK
140#define snd_hdac_updatew(addr, reg, mask, val) \
141 writew(((readw(addr + reg) & ~(mask)) | (val)), \
142 addr + reg)
143
a512f561
VK
144
145struct hdac_ext_device;
146
147/* ops common to all codec drivers */
148struct hdac_ext_codec_ops {
149 int (*build_controls)(struct hdac_ext_device *dev);
150 int (*init)(struct hdac_ext_device *dev);
151 void (*free)(struct hdac_ext_device *dev);
152};
153
154struct hda_dai_map {
155 char *dai_name;
156 hda_nid_t nid;
157 u32 maxbps;
158};
159
160#define HDA_MAX_NIDS 16
161
162/**
163 * struct hdac_ext_device - HDAC Ext device
164 *
165 * @hdac: hdac core device
166 * @nid_list - the dai map which matches the dai-name with the nid
167 * @map_cur_idx - the idx in use in dai_map
168 * @ops - the hda codec ops common to all codec drivers
169 * @pvt_data - private data, for asoc contains asoc codec object
170 */
171struct hdac_ext_device {
172 struct hdac_device hdac;
173 struct hdac_ext_bus *ebus;
174
175 /* soc-dai to nid map */
176 struct hda_dai_map nid_list[HDA_MAX_NIDS];
177 unsigned int map_cur_idx;
178
179 /* codec ops */
180 struct hdac_ext_codec_ops ops;
181
182 void *private_data;
183};
184
185#define to_ehdac_device(dev) (container_of((dev), \
186 struct hdac_ext_device, hdac))
d51783c1
VK
187/*
188 * HD-audio codec base driver
189 */
190struct hdac_ext_driver {
191 struct hdac_driver hdac;
192
193 int (*probe)(struct hdac_ext_device *dev);
194 int (*remove)(struct hdac_ext_device *dev);
195 void (*shutdown)(struct hdac_ext_device *dev);
196};
197
198int snd_hda_ext_driver_register(struct hdac_ext_driver *drv);
199void snd_hda_ext_driver_unregister(struct hdac_ext_driver *drv);
200
201#define to_ehdac_driver(_drv) container_of(_drv, struct hdac_ext_driver, hdac)
a512f561 202
dfe66a18 203#endif /* __SOUND_HDAUDIO_EXT_H */