forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/aoa/soundbus/i2sbus/core.c
....@@ -1,9 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * i2sbus driver
34 *
45 * Copyright 2006-2008 Johannes Berg <johannes@sipsolutions.net>
5
- *
6
- * GPL v2, can be found in COPYING.
76 */
87
98 #include <linux/module.h>
....@@ -47,8 +46,8 @@
4746 /* We use the PCI APIs for now until the generic one gets fixed
4847 * enough or until we get some macio-specific versions
4948 */
50
- r->space = dma_zalloc_coherent(&macio_get_pci_dev(i2sdev->macio)->dev,
51
- r->size, &r->bus_addr, GFP_KERNEL);
49
+ r->space = dma_alloc_coherent(&macio_get_pci_dev(i2sdev->macio)->dev,
50
+ r->size, &r->bus_addr, GFP_KERNEL);
5251 if (!r->space)
5352 return -ENOMEM;
5453
....@@ -148,27 +147,29 @@
148147 return rc;
149148 }
150149
150
+/* Returns 1 if added, 0 for otherwise; don't return a negative value! */
151151 /* FIXME: look at device node refcounting */
152152 static int i2sbus_add_dev(struct macio_dev *macio,
153153 struct i2sbus_control *control,
154154 struct device_node *np)
155155 {
156156 struct i2sbus_dev *dev;
157
- struct device_node *child = NULL, *sound = NULL;
157
+ struct device_node *child, *sound = NULL;
158158 struct resource *r;
159159 int i, layout = 0, rlen, ok = force;
160
- static const char *rnames[] = { "i2sbus: %s (control)",
161
- "i2sbus: %s (tx)",
162
- "i2sbus: %s (rx)" };
163
- static irq_handler_t ints[] = {
160
+ char node_name[6];
161
+ static const char *rnames[] = { "i2sbus: %pOFn (control)",
162
+ "i2sbus: %pOFn (tx)",
163
+ "i2sbus: %pOFn (rx)" };
164
+ static const irq_handler_t ints[] = {
164165 i2sbus_bus_intr,
165166 i2sbus_tx_intr,
166167 i2sbus_rx_intr
167168 };
168169
169
- if (strlen(np->name) != 5)
170
+ if (snprintf(node_name, sizeof(node_name), "%pOFn", np) != 5)
170171 return 0;
171
- if (strncmp(np->name, "i2s-", 4))
172
+ if (strncmp(node_name, "i2s-", 4))
172173 return 0;
173174
174175 dev = kzalloc(sizeof(struct i2sbus_dev), GFP_KERNEL);
....@@ -176,8 +177,8 @@
176177 return 0;
177178
178179 i = 0;
179
- while ((child = of_get_next_child(np, child))) {
180
- if (strcmp(child->name, "sound") == 0) {
180
+ for_each_child_of_node(np, child) {
181
+ if (of_node_name_eq(child, "sound")) {
181182 i++;
182183 sound = child;
183184 }
....@@ -213,7 +214,7 @@
213214 * either as the second one in that case is just a modem. */
214215 if (!ok) {
215216 kfree(dev);
216
- return -ENODEV;
217
+ return 0;
217218 }
218219
219220 mutex_init(&dev->lock);
....@@ -228,13 +229,13 @@
228229 dev->sound.pcmid = -1;
229230 dev->macio = macio;
230231 dev->control = control;
231
- dev->bus_number = np->name[4] - 'a';
232
+ dev->bus_number = node_name[4] - 'a';
232233 INIT_LIST_HEAD(&dev->sound.codec_list);
233234
234235 for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++) {
235236 dev->interrupts[i] = -1;
236237 snprintf(dev->rnames[i], sizeof(dev->rnames[i]),
237
- rnames[i], np->name);
238
+ rnames[i], np);
238239 }
239240 for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++) {
240241 int irq = irq_of_parse_and_map(np, i);
....@@ -302,6 +303,10 @@
302303
303304 if (soundbus_add_one(&dev->sound)) {
304305 printk(KERN_DEBUG "i2sbus: device registration error!\n");
306
+ if (dev->sound.ofdev.dev.kobj.state_initialized) {
307
+ soundbus_dev_put(&dev->sound);
308
+ return 0;
309
+ }
305310 goto err;
306311 }
307312
....@@ -379,10 +384,6 @@
379384 int err, ret = 0;
380385
381386 list_for_each_entry(i2sdev, &control->list, item) {
382
- /* Notify Alsa */
383
- /* Suspend PCM streams */
384
- snd_pcm_suspend_all(i2sdev->sound.pcm);
385
-
386387 /* Notify codecs */
387388 list_for_each_entry(cii, &i2sdev->sound.codec_list, list) {
388389 err = 0;