hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/sound/hda/hdac_bus.c
....@@ -1,15 +1,18 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * HD-audio core bus driver
34 */
45
56 #include <linux/init.h>
7
+#include <linux/io.h>
68 #include <linux/device.h>
79 #include <linux/module.h>
810 #include <linux/export.h>
911 #include <sound/hdaudio.h>
12
+#include "local.h"
1013 #include "trace.h"
1114
12
-static void process_unsol_events(struct work_struct *work);
15
+static void snd_hdac_bus_process_unsol_events(struct work_struct *work);
1316
1417 static const struct hdac_bus_ops default_ops = {
1518 .command = snd_hdac_bus_send_cmd,
....@@ -19,14 +22,13 @@
1922 /**
2023 * snd_hdac_bus_init - initialize a HD-audio bas bus
2124 * @bus: the pointer to bus object
25
+ * @dev: device pointer
2226 * @ops: bus verb operators
23
- * @io_ops: lowlevel I/O operators
2427 *
2528 * Returns 0 if successful, or a negative error code.
2629 */
2730 int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev,
28
- const struct hdac_bus_ops *ops,
29
- const struct hdac_io_ops *io_ops)
31
+ const struct hdac_bus_ops *ops)
3032 {
3133 memset(bus, 0, sizeof(*bus));
3234 bus->dev = dev;
....@@ -34,13 +36,28 @@
3436 bus->ops = ops;
3537 else
3638 bus->ops = &default_ops;
37
- bus->io_ops = io_ops;
39
+ bus->dma_type = SNDRV_DMA_TYPE_DEV;
3840 INIT_LIST_HEAD(&bus->stream_list);
3941 INIT_LIST_HEAD(&bus->codec_list);
40
- INIT_WORK(&bus->unsol_work, process_unsol_events);
42
+ INIT_WORK(&bus->unsol_work, snd_hdac_bus_process_unsol_events);
4143 spin_lock_init(&bus->reg_lock);
4244 mutex_init(&bus->cmd_mutex);
45
+ mutex_init(&bus->lock);
46
+ INIT_LIST_HEAD(&bus->hlink_list);
47
+ init_waitqueue_head(&bus->rirb_wq);
4348 bus->irq = -1;
49
+
50
+ /*
51
+ * Default value of '8' is as per the HD audio specification (Rev 1.0a).
52
+ * Following relation is used to derive STRIPE control value.
53
+ * For sample rate <= 48K:
54
+ * { ((num_channels * bits_per_sample) / number of SDOs) >= 8 }
55
+ * For sample rate > 48K:
56
+ * { ((num_channels * bits_per_sample * rate/48000) /
57
+ * number of SDOs) >= 8 }
58
+ */
59
+ bus->sdo_limit = 8;
60
+
4461 return 0;
4562 }
4663 EXPORT_SYMBOL_GPL(snd_hdac_bus_init);
....@@ -60,6 +77,7 @@
6077 /**
6178 * snd_hdac_bus_exec_verb - execute a HD-audio verb on the given bus
6279 * @bus: bus object
80
+ * @addr: the HDAC device address
6381 * @cmd: HD-audio encoded verb
6482 * @res: pointer to store the response, NULL if performing asynchronously
6583 *
....@@ -75,11 +93,11 @@
7593 mutex_unlock(&bus->cmd_mutex);
7694 return err;
7795 }
78
-EXPORT_SYMBOL_GPL(snd_hdac_bus_exec_verb);
7996
8097 /**
8198 * snd_hdac_bus_exec_verb_unlocked - unlocked version
8299 * @bus: bus object
100
+ * @addr: the HDAC device address
83101 * @cmd: HD-audio encoded verb
84102 * @res: pointer to store the response, NULL if performing asynchronously
85103 *
....@@ -143,12 +161,11 @@
143161
144162 schedule_work(&bus->unsol_work);
145163 }
146
-EXPORT_SYMBOL_GPL(snd_hdac_bus_queue_event);
147164
148165 /*
149166 * process queued unsolicited events
150167 */
151
-static void process_unsol_events(struct work_struct *work)
168
+static void snd_hdac_bus_process_unsol_events(struct work_struct *work)
152169 {
153170 struct hdac_bus *bus = container_of(work, struct hdac_bus, unsol_work);
154171 struct hdac_device *codec;
....@@ -199,7 +216,6 @@
199216 bus->num_codecs++;
200217 return 0;
201218 }
202
-EXPORT_SYMBOL_GPL(snd_hdac_bus_add_device);
203219
204220 /**
205221 * snd_hdac_bus_remove_device - Remove a codec from bus
....@@ -218,4 +234,33 @@
218234 bus->num_codecs--;
219235 flush_work(&bus->unsol_work);
220236 }
221
-EXPORT_SYMBOL_GPL(snd_hdac_bus_remove_device);
237
+
238
+#ifdef CONFIG_SND_HDA_ALIGNED_MMIO
239
+/* Helpers for aligned read/write of mmio space, for Tegra */
240
+unsigned int snd_hdac_aligned_read(void __iomem *addr, unsigned int mask)
241
+{
242
+ void __iomem *aligned_addr =
243
+ (void __iomem *)((unsigned long)(addr) & ~0x3);
244
+ unsigned int shift = ((unsigned long)(addr) & 0x3) << 3;
245
+ unsigned int v;
246
+
247
+ v = readl(aligned_addr);
248
+ return (v >> shift) & mask;
249
+}
250
+EXPORT_SYMBOL_GPL(snd_hdac_aligned_read);
251
+
252
+void snd_hdac_aligned_write(unsigned int val, void __iomem *addr,
253
+ unsigned int mask)
254
+{
255
+ void __iomem *aligned_addr =
256
+ (void __iomem *)((unsigned long)(addr) & ~0x3);
257
+ unsigned int shift = ((unsigned long)(addr) & 0x3) << 3;
258
+ unsigned int v;
259
+
260
+ v = readl(aligned_addr);
261
+ v &= ~(mask << shift);
262
+ v |= val << shift;
263
+ writel(v, aligned_addr);
264
+}
265
+EXPORT_SYMBOL_GPL(snd_hdac_aligned_write);
266
+#endif /* CONFIG_SND_HDA_ALIGNED_MMIO */