1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <linux/module.h>
21#include <linux/slab.h>
22#include <linux/io.h>
23#include <sound/hdaudio_ext.h>
24
25MODULE_DESCRIPTION("HDA extended core");
26MODULE_LICENSE("GPL v2");
27
28static void hdac_ext_writel(u32 value, u32 __iomem *addr)
29{
30 writel(value, addr);
31}
32
33static u32 hdac_ext_readl(u32 __iomem *addr)
34{
35 return readl(addr);
36}
37
38static void hdac_ext_writew(u16 value, u16 __iomem *addr)
39{
40 writew(value, addr);
41}
42
43static u16 hdac_ext_readw(u16 __iomem *addr)
44{
45 return readw(addr);
46}
47
48static void hdac_ext_writeb(u8 value, u8 __iomem *addr)
49{
50 writeb(value, addr);
51}
52
53static u8 hdac_ext_readb(u8 __iomem *addr)
54{
55 return readb(addr);
56}
57
58static int hdac_ext_dma_alloc_pages(struct hdac_bus *bus, int type,
59 size_t size, struct snd_dma_buffer *buf)
60{
61 return snd_dma_alloc_pages(type, bus->dev, size, buf);
62}
63
64static void hdac_ext_dma_free_pages(struct hdac_bus *bus, struct snd_dma_buffer *buf)
65{
66 snd_dma_free_pages(buf);
67}
68
69static const struct hdac_io_ops hdac_ext_default_io = {
70 .reg_writel = hdac_ext_writel,
71 .reg_readl = hdac_ext_readl,
72 .reg_writew = hdac_ext_writew,
73 .reg_readw = hdac_ext_readw,
74 .reg_writeb = hdac_ext_writeb,
75 .reg_readb = hdac_ext_readb,
76 .dma_alloc_pages = hdac_ext_dma_alloc_pages,
77 .dma_free_pages = hdac_ext_dma_free_pages,
78};
79
80
81
82
83
84
85
86
87
88
89
90int snd_hdac_ext_bus_init(struct hdac_bus *bus, struct device *dev,
91 const struct hdac_bus_ops *ops,
92 const struct hdac_io_ops *io_ops,
93 const struct hdac_ext_bus_ops *ext_ops)
94{
95 int ret;
96 static int idx;
97
98
99 if (io_ops == NULL)
100 io_ops = &hdac_ext_default_io;
101
102 ret = snd_hdac_bus_init(bus, dev, ops, io_ops);
103 if (ret < 0)
104 return ret;
105
106 bus->ext_ops = ext_ops;
107 bus->idx = idx++;
108 bus->cmd_dma_state = true;
109
110 return 0;
111}
112EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_init);
113
114
115
116
117
118void snd_hdac_ext_bus_exit(struct hdac_bus *bus)
119{
120 snd_hdac_bus_exit(bus);
121 WARN_ON(!list_empty(&bus->hlink_list));
122}
123EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_exit);
124
125static void default_release(struct device *dev)
126{
127 snd_hdac_ext_bus_device_exit(container_of(dev, struct hdac_device, dev));
128}
129
130
131
132
133
134
135
136
137int snd_hdac_ext_bus_device_init(struct hdac_bus *bus, int addr,
138 struct hdac_device *hdev)
139{
140 char name[15];
141 int ret;
142
143 hdev->bus = bus;
144
145 snprintf(name, sizeof(name), "ehdaudio%dD%d", bus->idx, addr);
146
147 ret = snd_hdac_device_init(hdev, bus, name, addr);
148 if (ret < 0) {
149 dev_err(bus->dev, "device init failed for hdac device\n");
150 return ret;
151 }
152 hdev->type = HDA_DEV_ASOC;
153 hdev->dev.release = default_release;
154
155 ret = snd_hdac_device_register(hdev);
156 if (ret) {
157 dev_err(bus->dev, "failed to register hdac device\n");
158 snd_hdac_ext_bus_device_exit(hdev);
159 return ret;
160 }
161
162 return 0;
163}
164EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_device_init);
165
166
167
168
169
170void snd_hdac_ext_bus_device_exit(struct hdac_device *hdev)
171{
172 snd_hdac_device_exit(hdev);
173 kfree(hdev);
174}
175EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_device_exit);
176
177
178
179
180
181
182void snd_hdac_ext_bus_device_remove(struct hdac_bus *bus)
183{
184 struct hdac_device *codec, *__codec;
185
186
187
188
189 list_for_each_entry_safe(codec, __codec, &bus->codec_list, list) {
190 snd_hdac_device_unregister(codec);
191 put_device(&codec->dev);
192 }
193}
194EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_device_remove);
195#define dev_to_hdac(dev) (container_of((dev), \
196 struct hdac_device, dev))
197
198static inline struct hdac_driver *get_hdrv(struct device *dev)
199{
200 struct hdac_driver *hdrv = drv_to_hdac_driver(dev->driver);
201 return hdrv;
202}
203
204static inline struct hdac_device *get_hdev(struct device *dev)
205{
206 struct hdac_device *hdev = dev_to_hdac_dev(dev);
207 return hdev;
208}
209
210static int hda_ext_drv_probe(struct device *dev)
211{
212 return (get_hdrv(dev))->probe(get_hdev(dev));
213}
214
215static int hdac_ext_drv_remove(struct device *dev)
216{
217 return (get_hdrv(dev))->remove(get_hdev(dev));
218}
219
220static void hdac_ext_drv_shutdown(struct device *dev)
221{
222 return (get_hdrv(dev))->shutdown(get_hdev(dev));
223}
224
225
226
227
228
229
230int snd_hda_ext_driver_register(struct hdac_driver *drv)
231{
232 drv->type = HDA_DEV_ASOC;
233 drv->driver.bus = &snd_hda_bus_type;
234
235
236 if (drv->probe)
237 drv->driver.probe = hda_ext_drv_probe;
238 if (drv->remove)
239 drv->driver.remove = hdac_ext_drv_remove;
240 if (drv->shutdown)
241 drv->driver.shutdown = hdac_ext_drv_shutdown;
242
243 return driver_register(&drv->driver);
244}
245EXPORT_SYMBOL_GPL(snd_hda_ext_driver_register);
246
247
248
249
250
251
252void snd_hda_ext_driver_unregister(struct hdac_driver *drv)
253{
254 driver_unregister(&drv->driver);
255}
256EXPORT_SYMBOL_GPL(snd_hda_ext_driver_unregister);
257