Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __SOUND_HDAUDIO_EXT_H
3#define __SOUND_HDAUDIO_EXT_H
4
5#include <sound/hdaudio.h>
6
7int snd_hdac_ext_bus_init(struct hdac_bus *bus, struct device *dev,
8 const struct hdac_bus_ops *ops,
9 const struct hdac_ext_bus_ops *ext_ops);
10
11void snd_hdac_ext_bus_exit(struct hdac_bus *bus);
12int snd_hdac_ext_bus_device_init(struct hdac_bus *bus, int addr,
13 struct hdac_device *hdev);
14void snd_hdac_ext_bus_device_exit(struct hdac_device *hdev);
15void snd_hdac_ext_bus_device_remove(struct hdac_bus *bus);
16
17#define HDA_CODEC_REV_EXT_ENTRY(_vid, _rev, _name, drv_data) \
18 { .vendor_id = (_vid), .rev_id = (_rev), .name = (_name), \
19 .api_version = HDA_DEV_ASOC, \
20 .driver_data = (unsigned long)(drv_data) }
21#define HDA_CODEC_EXT_ENTRY(_vid, _revid, _name, _drv_data) \
22 HDA_CODEC_REV_EXT_ENTRY(_vid, _revid, _name, _drv_data)
23
24void snd_hdac_ext_bus_ppcap_enable(struct hdac_bus *chip, bool enable);
25void snd_hdac_ext_bus_ppcap_int_enable(struct hdac_bus *chip, bool enable);
26
27void snd_hdac_ext_stream_spbcap_enable(struct hdac_bus *chip,
28 bool enable, int index);
29
30int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_bus *bus);
31struct hdac_ext_link *snd_hdac_ext_bus_get_link(struct hdac_bus *bus,
32 const char *codec_name);
33
34enum hdac_ext_stream_type {
35 HDAC_EXT_STREAM_TYPE_COUPLED = 0,
36 HDAC_EXT_STREAM_TYPE_HOST,
37 HDAC_EXT_STREAM_TYPE_LINK
38};
39
40/**
41 * hdac_ext_stream: HDAC extended stream for extended HDA caps
42 *
43 * @hstream: hdac_stream
44 * @pphc_addr: processing pipe host stream pointer
45 * @pplc_addr: processing pipe link stream pointer
46 * @spib_addr: software position in buffers stream pointer
47 * @fifo_addr: software position Max fifos stream pointer
48 * @dpibr_addr: DMA position in buffer resume pointer
49 * @dpib: DMA position in buffer
50 * @lpib: Linear position in buffer
51 * @decoupled: stream host and link is decoupled
52 * @link_locked: link is locked
53 * @link_prepared: link is prepared
54 * link_substream: link substream
55 */
56struct hdac_ext_stream {
57 struct hdac_stream hstream;
58
59 void __iomem *pphc_addr;
60 void __iomem *pplc_addr;
61
62 void __iomem *spib_addr;
63 void __iomem *fifo_addr;
64
65 void __iomem *dpibr_addr;
66
67 u32 dpib;
68 u32 lpib;
69 bool decoupled:1;
70 bool link_locked:1;
71 bool link_prepared;
72
73 struct snd_pcm_substream *link_substream;
74};
75
76#define hdac_stream(s) (&(s)->hstream)
77#define stream_to_hdac_ext_stream(s) \
78 container_of(s, struct hdac_ext_stream, hstream)
79
80void snd_hdac_ext_stream_init(struct hdac_bus *bus,
81 struct hdac_ext_stream *stream, int idx,
82 int direction, int tag);
83int snd_hdac_ext_stream_init_all(struct hdac_bus *bus, int start_idx,
84 int num_stream, int dir);
85void snd_hdac_stream_free_all(struct hdac_bus *bus);
86void snd_hdac_link_free_all(struct hdac_bus *bus);
87struct hdac_ext_stream *snd_hdac_ext_stream_assign(struct hdac_bus *bus,
88 struct snd_pcm_substream *substream,
89 int type);
90void snd_hdac_ext_stream_release(struct hdac_ext_stream *azx_dev, int type);
91void snd_hdac_ext_stream_decouple(struct hdac_bus *bus,
92 struct hdac_ext_stream *azx_dev, bool decouple);
93void snd_hdac_ext_stop_streams(struct hdac_bus *bus);
94
95int snd_hdac_ext_stream_set_spib(struct hdac_bus *bus,
96 struct hdac_ext_stream *stream, u32 value);
97int snd_hdac_ext_stream_get_spbmaxfifo(struct hdac_bus *bus,
98 struct hdac_ext_stream *stream);
99void snd_hdac_ext_stream_drsm_enable(struct hdac_bus *bus,
100 bool enable, int index);
101int snd_hdac_ext_stream_set_dpibr(struct hdac_bus *bus,
102 struct hdac_ext_stream *stream, u32 value);
103int snd_hdac_ext_stream_set_lpib(struct hdac_ext_stream *stream, u32 value);
104
105void snd_hdac_ext_link_stream_start(struct hdac_ext_stream *hstream);
106void snd_hdac_ext_link_stream_clear(struct hdac_ext_stream *hstream);
107void snd_hdac_ext_link_stream_reset(struct hdac_ext_stream *hstream);
108int snd_hdac_ext_link_stream_setup(struct hdac_ext_stream *stream, int fmt);
109
110struct hdac_ext_link {
111 struct hdac_bus *bus;
112 int index;
113 void __iomem *ml_addr; /* link output stream reg pointer */
114 u32 lcaps; /* link capablities */
115 u16 lsdiid; /* link sdi identifier */
116
117 int ref_count;
118
119 struct list_head list;
120};
121
122int snd_hdac_ext_bus_link_power_up(struct hdac_ext_link *link);
123int snd_hdac_ext_bus_link_power_down(struct hdac_ext_link *link);
124int snd_hdac_ext_bus_link_power_up_all(struct hdac_bus *bus);
125int snd_hdac_ext_bus_link_power_down_all(struct hdac_bus *bus);
126void snd_hdac_ext_link_set_stream_id(struct hdac_ext_link *link,
127 int stream);
128void snd_hdac_ext_link_clear_stream_id(struct hdac_ext_link *link,
129 int stream);
130
131int snd_hdac_ext_bus_link_get(struct hdac_bus *bus, struct hdac_ext_link *link);
132int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *link);
133
134/* update register macro */
135#define snd_hdac_updatel(addr, reg, mask, val) \
136 writel(((readl(addr + reg) & ~(mask)) | (val)), \
137 addr + reg)
138
139#define snd_hdac_updatew(addr, reg, mask, val) \
140 writew(((readw(addr + reg) & ~(mask)) | (val)), \
141 addr + reg)
142
143
144struct hdac_ext_device;
145
146/* ops common to all codec drivers */
147struct hdac_ext_codec_ops {
148 int (*build_controls)(struct hdac_ext_device *dev);
149 int (*init)(struct hdac_ext_device *dev);
150 void (*free)(struct hdac_ext_device *dev);
151};
152
153struct hda_dai_map {
154 char *dai_name;
155 hda_nid_t nid;
156 u32 maxbps;
157};
158
159struct hdac_ext_dma_params {
160 u32 format;
161 u8 stream_tag;
162};
163
164int snd_hda_ext_driver_register(struct hdac_driver *drv);
165void snd_hda_ext_driver_unregister(struct hdac_driver *drv);
166
167#endif /* __SOUND_HDAUDIO_EXT_H */
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __SOUND_HDAUDIO_EXT_H
3#define __SOUND_HDAUDIO_EXT_H
4
5#include <linux/io-64-nonatomic-lo-hi.h>
6#include <linux/iopoll.h>
7#include <sound/hdaudio.h>
8
9int snd_hdac_ext_bus_init(struct hdac_bus *bus, struct device *dev,
10 const struct hdac_bus_ops *ops,
11 const struct hdac_ext_bus_ops *ext_ops);
12
13void snd_hdac_ext_bus_exit(struct hdac_bus *bus);
14void snd_hdac_ext_bus_device_remove(struct hdac_bus *bus);
15
16#define HDA_CODEC_REV_EXT_ENTRY(_vid, _rev, _name, drv_data) \
17 { .vendor_id = (_vid), .rev_id = (_rev), .name = (_name), \
18 .api_version = HDA_DEV_ASOC, \
19 .driver_data = (unsigned long)(drv_data) }
20#define HDA_CODEC_EXT_ENTRY(_vid, _revid, _name, _drv_data) \
21 HDA_CODEC_REV_EXT_ENTRY(_vid, _revid, _name, _drv_data)
22
23void snd_hdac_ext_bus_ppcap_enable(struct hdac_bus *chip, bool enable);
24void snd_hdac_ext_bus_ppcap_int_enable(struct hdac_bus *chip, bool enable);
25
26int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_bus *bus);
27struct hdac_ext_link *snd_hdac_ext_bus_get_hlink_by_addr(struct hdac_bus *bus, int addr);
28struct hdac_ext_link *snd_hdac_ext_bus_get_hlink_by_name(struct hdac_bus *bus,
29 const char *codec_name);
30
31enum hdac_ext_stream_type {
32 HDAC_EXT_STREAM_TYPE_COUPLED = 0,
33 HDAC_EXT_STREAM_TYPE_HOST,
34 HDAC_EXT_STREAM_TYPE_LINK
35};
36
37/**
38 * hdac_ext_stream: HDAC extended stream for extended HDA caps
39 *
40 * @hstream: hdac_stream
41 * @pphc_addr: processing pipe host stream pointer
42 * @pplc_addr: processing pipe link stream pointer
43 * @decoupled: stream host and link is decoupled
44 * @link_locked: link is locked
45 * @link_prepared: link is prepared
46 * @link_substream: link substream
47 */
48struct hdac_ext_stream {
49 struct hdac_stream hstream;
50
51 void __iomem *pphc_addr;
52 void __iomem *pplc_addr;
53
54 u32 pphcllpl;
55 u32 pphcllpu;
56 u32 pphcldpl;
57 u32 pphcldpu;
58
59 bool decoupled:1;
60 bool link_locked:1;
61 bool link_prepared;
62
63 struct snd_pcm_substream *link_substream;
64};
65
66#define hdac_stream(s) (&(s)->hstream)
67#define stream_to_hdac_ext_stream(s) \
68 container_of(s, struct hdac_ext_stream, hstream)
69
70int snd_hdac_ext_stream_init_all(struct hdac_bus *bus, int start_idx,
71 int num_stream, int dir);
72void snd_hdac_ext_stream_free_all(struct hdac_bus *bus);
73void snd_hdac_ext_link_free_all(struct hdac_bus *bus);
74struct hdac_ext_stream *snd_hdac_ext_stream_assign(struct hdac_bus *bus,
75 struct snd_pcm_substream *substream,
76 int type);
77void snd_hdac_ext_stream_release(struct hdac_ext_stream *hext_stream, int type);
78struct hdac_ext_stream *snd_hdac_ext_cstream_assign(struct hdac_bus *bus,
79 struct snd_compr_stream *cstream);
80void snd_hdac_ext_stream_decouple_locked(struct hdac_bus *bus,
81 struct hdac_ext_stream *hext_stream, bool decouple);
82void snd_hdac_ext_stream_decouple(struct hdac_bus *bus,
83 struct hdac_ext_stream *azx_dev, bool decouple);
84
85void snd_hdac_ext_stream_start(struct hdac_ext_stream *hext_stream);
86void snd_hdac_ext_stream_clear(struct hdac_ext_stream *hext_stream);
87void snd_hdac_ext_stream_reset(struct hdac_ext_stream *hext_stream);
88int snd_hdac_ext_stream_setup(struct hdac_ext_stream *hext_stream, int fmt);
89
90struct hdac_ext_link {
91 struct hdac_bus *bus;
92 int index;
93 void __iomem *ml_addr; /* link output stream reg pointer */
94 u32 lcaps; /* link capablities */
95 u16 lsdiid; /* link sdi identifier */
96
97 int ref_count;
98
99 struct list_head list;
100};
101
102int snd_hdac_ext_bus_link_power_up(struct hdac_ext_link *hlink);
103int snd_hdac_ext_bus_link_power_down(struct hdac_ext_link *hlink);
104int snd_hdac_ext_bus_link_power_up_all(struct hdac_bus *bus);
105int snd_hdac_ext_bus_link_power_down_all(struct hdac_bus *bus);
106void snd_hdac_ext_bus_link_set_stream_id(struct hdac_ext_link *hlink,
107 int stream);
108void snd_hdac_ext_bus_link_clear_stream_id(struct hdac_ext_link *hlink,
109 int stream);
110
111int snd_hdac_ext_bus_link_get(struct hdac_bus *bus, struct hdac_ext_link *hlink);
112int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *hlink);
113
114void snd_hdac_ext_bus_link_power(struct hdac_device *codec, bool enable);
115
116#define snd_hdac_adsp_writeb(chip, reg, value) \
117 snd_hdac_reg_writeb(chip, (chip)->dsp_ba + (reg), value)
118#define snd_hdac_adsp_readb(chip, reg) \
119 snd_hdac_reg_readb(chip, (chip)->dsp_ba + (reg))
120#define snd_hdac_adsp_writew(chip, reg, value) \
121 snd_hdac_reg_writew(chip, (chip)->dsp_ba + (reg), value)
122#define snd_hdac_adsp_readw(chip, reg) \
123 snd_hdac_reg_readw(chip, (chip)->dsp_ba + (reg))
124#define snd_hdac_adsp_writel(chip, reg, value) \
125 snd_hdac_reg_writel(chip, (chip)->dsp_ba + (reg), value)
126#define snd_hdac_adsp_readl(chip, reg) \
127 snd_hdac_reg_readl(chip, (chip)->dsp_ba + (reg))
128#define snd_hdac_adsp_writeq(chip, reg, value) \
129 snd_hdac_reg_writeq(chip, (chip)->dsp_ba + (reg), value)
130#define snd_hdac_adsp_readq(chip, reg) \
131 snd_hdac_reg_readq(chip, (chip)->dsp_ba + (reg))
132
133#define snd_hdac_adsp_updateb(chip, reg, mask, val) \
134 snd_hdac_adsp_writeb(chip, reg, \
135 (snd_hdac_adsp_readb(chip, reg) & ~(mask)) | (val))
136#define snd_hdac_adsp_updatew(chip, reg, mask, val) \
137 snd_hdac_adsp_writew(chip, reg, \
138 (snd_hdac_adsp_readw(chip, reg) & ~(mask)) | (val))
139#define snd_hdac_adsp_updatel(chip, reg, mask, val) \
140 snd_hdac_adsp_writel(chip, reg, \
141 (snd_hdac_adsp_readl(chip, reg) & ~(mask)) | (val))
142#define snd_hdac_adsp_updateq(chip, reg, mask, val) \
143 snd_hdac_adsp_writeq(chip, reg, \
144 (snd_hdac_adsp_readq(chip, reg) & ~(mask)) | (val))
145
146#define snd_hdac_adsp_readb_poll(chip, reg, val, cond, delay_us, timeout_us) \
147 readb_poll_timeout((chip)->dsp_ba + (reg), val, cond, \
148 delay_us, timeout_us)
149#define snd_hdac_adsp_readw_poll(chip, reg, val, cond, delay_us, timeout_us) \
150 readw_poll_timeout((chip)->dsp_ba + (reg), val, cond, \
151 delay_us, timeout_us)
152#define snd_hdac_adsp_readl_poll(chip, reg, val, cond, delay_us, timeout_us) \
153 readl_poll_timeout((chip)->dsp_ba + (reg), val, cond, \
154 delay_us, timeout_us)
155#define snd_hdac_adsp_readq_poll(chip, reg, val, cond, delay_us, timeout_us) \
156 readq_poll_timeout((chip)->dsp_ba + (reg), val, cond, \
157 delay_us, timeout_us)
158
159struct hdac_ext_device;
160
161/* ops common to all codec drivers */
162struct hdac_ext_codec_ops {
163 int (*build_controls)(struct hdac_ext_device *dev);
164 int (*init)(struct hdac_ext_device *dev);
165 void (*free)(struct hdac_ext_device *dev);
166};
167
168struct hda_dai_map {
169 char *dai_name;
170 hda_nid_t nid;
171 u32 maxbps;
172};
173
174struct hdac_ext_dma_params {
175 u32 format;
176 u8 stream_tag;
177};
178
179int snd_hda_ext_driver_register(struct hdac_driver *drv);
180void snd_hda_ext_driver_unregister(struct hdac_driver *drv);
181
182#endif /* __SOUND_HDAUDIO_EXT_H */