1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2 // Copyright(c) 2015-22 Intel Corporation.
3 
4 /*
5  * Soundwire Intel Manager Driver
6  */
7 
8 #include <linux/acpi.h>
9 #include <linux/debugfs.h>
10 #include <linux/delay.h>
11 #include <linux/module.h>
12 #include <linux/interrupt.h>
13 #include <linux/io.h>
14 #include <linux/auxiliary_bus.h>
15 #include <sound/pcm_params.h>
16 #include <linux/pm_runtime.h>
17 #include <sound/soc.h>
18 #include <linux/soundwire/sdw_registers.h>
19 #include <linux/soundwire/sdw.h>
20 #include <linux/soundwire/sdw_intel.h>
21 #include "cadence_master.h"
22 #include "bus.h"
23 #include "intel.h"
24 #include "intel_auxdevice.h"
25 
26 /* IDA min selected to avoid conflicts with HDaudio/iDISP SDI values */
27 #define INTEL_DEV_NUM_IDA_MIN           4
28 
29 #define INTEL_MASTER_SUSPEND_DELAY_MS	3000
30 
31 /*
32  * debug/config flags for the Intel SoundWire Master.
33  *
34  * Since we may have multiple masters active, we can have up to 8
35  * flags reused in each byte, with master0 using the ls-byte, etc.
36  */
37 
38 #define SDW_INTEL_MASTER_DISABLE_PM_RUNTIME		BIT(0)
39 #define SDW_INTEL_MASTER_DISABLE_CLOCK_STOP		BIT(1)
40 #define SDW_INTEL_MASTER_DISABLE_PM_RUNTIME_IDLE	BIT(2)
41 #define SDW_INTEL_MASTER_DISABLE_MULTI_LINK		BIT(3)
42 
43 static int md_flags;
44 module_param_named(sdw_md_flags, md_flags, int, 0444);
45 MODULE_PARM_DESC(sdw_md_flags, "SoundWire Intel Master device flags (0x0 all off)");
46 
47 static int generic_pre_bank_switch(struct sdw_bus *bus)
48 {
49 	struct sdw_cdns *cdns = bus_to_cdns(bus);
50 	struct sdw_intel *sdw = cdns_to_intel(cdns);
51 
52 	return sdw->link_res->hw_ops->pre_bank_switch(sdw);
53 }
54 
55 static int generic_post_bank_switch(struct sdw_bus *bus)
56 {
57 	struct sdw_cdns *cdns = bus_to_cdns(bus);
58 	struct sdw_intel *sdw = cdns_to_intel(cdns);
59 
60 	return sdw->link_res->hw_ops->post_bank_switch(sdw);
61 }
62 
63 static void generic_new_peripheral_assigned(struct sdw_bus *bus, int dev_num)
64 {
65 	struct sdw_cdns *cdns = bus_to_cdns(bus);
66 	struct sdw_intel *sdw = cdns_to_intel(cdns);
67 
68 	/* paranoia check, this should never happen */
69 	if (dev_num < INTEL_DEV_NUM_IDA_MIN || dev_num > SDW_MAX_DEVICES)  {
70 		dev_err(bus->dev, "%s: invalid dev_num %d\n", __func__, dev_num);
71 		return;
72 	}
73 
74 	if (sdw->link_res->hw_ops->program_sdi)
75 		sdw->link_res->hw_ops->program_sdi(sdw, dev_num);
76 }
77 
78 static int sdw_master_read_intel_prop(struct sdw_bus *bus)
79 {
80 	struct sdw_master_prop *prop = &bus->prop;
81 	struct fwnode_handle *link;
82 	char name[32];
83 	u32 quirk_mask;
84 
85 	/* Find master handle */
86 	snprintf(name, sizeof(name),
87 		 "mipi-sdw-link-%d-subproperties", bus->link_id);
88 
89 	link = device_get_named_child_node(bus->dev, name);
90 	if (!link) {
91 		dev_err(bus->dev, "Master node %s not found\n", name);
92 		return -EIO;
93 	}
94 
95 	fwnode_property_read_u32(link,
96 				 "intel-sdw-ip-clock",
97 				 &prop->mclk_freq);
98 
99 	/* the values reported by BIOS are the 2x clock, not the bus clock */
100 	prop->mclk_freq /= 2;
101 
102 	fwnode_property_read_u32(link,
103 				 "intel-quirk-mask",
104 				 &quirk_mask);
105 
106 	if (quirk_mask & SDW_INTEL_QUIRK_MASK_BUS_DISABLE)
107 		prop->hw_disabled = true;
108 
109 	prop->quirks = SDW_MASTER_QUIRKS_CLEAR_INITIAL_CLASH |
110 		SDW_MASTER_QUIRKS_CLEAR_INITIAL_PARITY;
111 
112 	return 0;
113 }
114 
115 static int intel_prop_read(struct sdw_bus *bus)
116 {
117 	/* Initialize with default handler to read all DisCo properties */
118 	sdw_master_read_prop(bus);
119 
120 	/* read Intel-specific properties */
121 	sdw_master_read_intel_prop(bus);
122 
123 	return 0;
124 }
125 
126 static struct sdw_master_ops sdw_intel_ops = {
127 	.read_prop = intel_prop_read,
128 	.override_adr = sdw_dmi_override_adr,
129 	.xfer_msg = cdns_xfer_msg,
130 	.xfer_msg_defer = cdns_xfer_msg_defer,
131 	.set_bus_conf = cdns_bus_conf,
132 	.pre_bank_switch = generic_pre_bank_switch,
133 	.post_bank_switch = generic_post_bank_switch,
134 	.read_ping_status = cdns_read_ping_status,
135 	.new_peripheral_assigned = generic_new_peripheral_assigned,
136 };
137 
138 /*
139  * probe and init (aux_dev_id argument is required by function prototype but not used)
140  */
141 static int intel_link_probe(struct auxiliary_device *auxdev,
142 			    const struct auxiliary_device_id *aux_dev_id)
143 
144 {
145 	struct device *dev = &auxdev->dev;
146 	struct sdw_intel_link_dev *ldev = auxiliary_dev_to_sdw_intel_link_dev(auxdev);
147 	struct sdw_intel *sdw;
148 	struct sdw_cdns *cdns;
149 	struct sdw_bus *bus;
150 	int ret;
151 
152 	sdw = devm_kzalloc(dev, sizeof(*sdw), GFP_KERNEL);
153 	if (!sdw)
154 		return -ENOMEM;
155 
156 	cdns = &sdw->cdns;
157 	bus = &cdns->bus;
158 
159 	sdw->instance = auxdev->id;
160 	sdw->link_res = &ldev->link_res;
161 	cdns->dev = dev;
162 	cdns->registers = sdw->link_res->registers;
163 	cdns->ip_offset = sdw->link_res->ip_offset;
164 	cdns->instance = sdw->instance;
165 	cdns->msg_count = 0;
166 
167 	bus->link_id = auxdev->id;
168 	bus->dev_num_ida_min = INTEL_DEV_NUM_IDA_MIN;
169 	bus->clk_stop_timeout = 1;
170 
171 	sdw_cdns_probe(cdns);
172 
173 	/* Set ops */
174 	bus->ops = &sdw_intel_ops;
175 
176 	/* set driver data, accessed by snd_soc_dai_get_drvdata() */
177 	auxiliary_set_drvdata(auxdev, cdns);
178 
179 	/* use generic bandwidth allocation algorithm */
180 	sdw->cdns.bus.compute_params = sdw_compute_params;
181 
182 	/* avoid resuming from pm_runtime suspend if it's not required */
183 	dev_pm_set_driver_flags(dev, DPM_FLAG_SMART_SUSPEND);
184 
185 	ret = sdw_bus_master_add(bus, dev, dev->fwnode);
186 	if (ret) {
187 		dev_err(dev, "sdw_bus_master_add fail: %d\n", ret);
188 		return ret;
189 	}
190 
191 	if (bus->prop.hw_disabled)
192 		dev_info(dev,
193 			 "SoundWire master %d is disabled, will be ignored\n",
194 			 bus->link_id);
195 	/*
196 	 * Ignore BIOS err_threshold, it's a really bad idea when dealing
197 	 * with multiple hardware synchronized links
198 	 */
199 	bus->prop.err_threshold = 0;
200 
201 	return 0;
202 }
203 
204 int intel_link_startup(struct auxiliary_device *auxdev)
205 {
206 	struct device *dev = &auxdev->dev;
207 	struct sdw_cdns *cdns = auxiliary_get_drvdata(auxdev);
208 	struct sdw_intel *sdw = cdns_to_intel(cdns);
209 	struct sdw_bus *bus = &cdns->bus;
210 	int link_flags;
211 	bool multi_link;
212 	u32 clock_stop_quirks;
213 	int ret;
214 
215 	if (bus->prop.hw_disabled) {
216 		dev_info(dev,
217 			 "SoundWire master %d is disabled, ignoring\n",
218 			 sdw->instance);
219 		return 0;
220 	}
221 
222 	link_flags = md_flags >> (bus->link_id * 8);
223 	multi_link = !(link_flags & SDW_INTEL_MASTER_DISABLE_MULTI_LINK);
224 	if (!multi_link) {
225 		dev_dbg(dev, "Multi-link is disabled\n");
226 	} else {
227 		/*
228 		 * hardware-based synchronization is required regardless
229 		 * of the number of segments used by a stream: SSP-based
230 		 * synchronization is gated by gsync when the multi-master
231 		 * mode is set.
232 		 */
233 		bus->hw_sync_min_links = 1;
234 	}
235 	bus->multi_link = multi_link;
236 
237 	/* Initialize shim, controller */
238 	ret = sdw_intel_link_power_up(sdw);
239 	if (ret)
240 		goto err_init;
241 
242 	/* Register DAIs */
243 	ret = sdw_intel_register_dai(sdw);
244 	if (ret) {
245 		dev_err(dev, "DAI registration failed: %d\n", ret);
246 		goto err_power_up;
247 	}
248 
249 	sdw_intel_debugfs_init(sdw);
250 
251 	/* start bus */
252 	ret = sdw_intel_start_bus(sdw);
253 	if (ret) {
254 		dev_err(dev, "bus start failed: %d\n", ret);
255 		goto err_power_up;
256 	}
257 
258 	/* Enable runtime PM */
259 	if (!(link_flags & SDW_INTEL_MASTER_DISABLE_PM_RUNTIME)) {
260 		pm_runtime_set_autosuspend_delay(dev,
261 						 INTEL_MASTER_SUSPEND_DELAY_MS);
262 		pm_runtime_use_autosuspend(dev);
263 		pm_runtime_mark_last_busy(dev);
264 
265 		pm_runtime_set_active(dev);
266 		pm_runtime_enable(dev);
267 	}
268 
269 	clock_stop_quirks = sdw->link_res->clock_stop_quirks;
270 	if (clock_stop_quirks & SDW_INTEL_CLK_STOP_NOT_ALLOWED) {
271 		/*
272 		 * To keep the clock running we need to prevent
273 		 * pm_runtime suspend from happening by increasing the
274 		 * reference count.
275 		 * This quirk is specified by the parent PCI device in
276 		 * case of specific latency requirements. It will have
277 		 * no effect if pm_runtime is disabled by the user via
278 		 * a module parameter for testing purposes.
279 		 */
280 		pm_runtime_get_noresume(dev);
281 	}
282 
283 	/*
284 	 * The runtime PM status of Slave devices is "Unsupported"
285 	 * until they report as ATTACHED. If they don't, e.g. because
286 	 * there are no Slave devices populated or if the power-on is
287 	 * delayed or dependent on a power switch, the Master will
288 	 * remain active and prevent its parent from suspending.
289 	 *
290 	 * Conditionally force the pm_runtime core to re-evaluate the
291 	 * Master status in the absence of any Slave activity. A quirk
292 	 * is provided to e.g. deal with Slaves that may be powered on
293 	 * with a delay. A more complete solution would require the
294 	 * definition of Master properties.
295 	 */
296 	if (!(link_flags & SDW_INTEL_MASTER_DISABLE_PM_RUNTIME_IDLE))
297 		pm_runtime_idle(dev);
298 
299 	sdw->startup_done = true;
300 	return 0;
301 
302 err_power_up:
303 	sdw_intel_link_power_down(sdw);
304 err_init:
305 	return ret;
306 }
307 
308 static void intel_link_remove(struct auxiliary_device *auxdev)
309 {
310 	struct sdw_cdns *cdns = auxiliary_get_drvdata(auxdev);
311 	struct sdw_intel *sdw = cdns_to_intel(cdns);
312 	struct sdw_bus *bus = &cdns->bus;
313 
314 	/*
315 	 * Since pm_runtime is already disabled, we don't decrease
316 	 * the refcount when the clock_stop_quirk is
317 	 * SDW_INTEL_CLK_STOP_NOT_ALLOWED
318 	 */
319 	if (!bus->prop.hw_disabled) {
320 		sdw_intel_debugfs_exit(sdw);
321 		sdw_cdns_enable_interrupt(cdns, false);
322 	}
323 	sdw_bus_master_delete(bus);
324 }
325 
326 int intel_link_process_wakeen_event(struct auxiliary_device *auxdev)
327 {
328 	struct device *dev = &auxdev->dev;
329 	struct sdw_intel *sdw;
330 	struct sdw_bus *bus;
331 
332 	sdw = auxiliary_get_drvdata(auxdev);
333 	bus = &sdw->cdns.bus;
334 
335 	if (bus->prop.hw_disabled || !sdw->startup_done) {
336 		dev_dbg(dev, "SoundWire master %d is disabled or not-started, ignoring\n",
337 			bus->link_id);
338 		return 0;
339 	}
340 
341 	if (!sdw_intel_shim_check_wake(sdw))
342 		return 0;
343 
344 	/* disable WAKEEN interrupt ASAP to prevent interrupt flood */
345 	sdw_intel_shim_wake(sdw, false);
346 
347 	/*
348 	 * resume the Master, which will generate a bus reset and result in
349 	 * Slaves re-attaching and be re-enumerated. The SoundWire physical
350 	 * device which generated the wake will trigger an interrupt, which
351 	 * will in turn cause the corresponding Linux Slave device to be
352 	 * resumed and the Slave codec driver to check the status.
353 	 */
354 	pm_request_resume(dev);
355 
356 	return 0;
357 }
358 
359 /*
360  * PM calls
361  */
362 
363 static int intel_resume_child_device(struct device *dev, void *data)
364 {
365 	int ret;
366 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
367 
368 	if (!slave->probed) {
369 		dev_dbg(dev, "skipping device, no probed driver\n");
370 		return 0;
371 	}
372 	if (!slave->dev_num_sticky) {
373 		dev_dbg(dev, "skipping device, never detected on bus\n");
374 		return 0;
375 	}
376 
377 	ret = pm_request_resume(dev);
378 	if (ret < 0) {
379 		dev_err(dev, "%s: pm_request_resume failed: %d\n", __func__, ret);
380 		return ret;
381 	}
382 
383 	return 0;
384 }
385 
386 static int __maybe_unused intel_pm_prepare(struct device *dev)
387 {
388 	struct sdw_cdns *cdns = dev_get_drvdata(dev);
389 	struct sdw_intel *sdw = cdns_to_intel(cdns);
390 	struct sdw_bus *bus = &cdns->bus;
391 	u32 clock_stop_quirks;
392 	int ret;
393 
394 	if (bus->prop.hw_disabled || !sdw->startup_done) {
395 		dev_dbg(dev, "SoundWire master %d is disabled or not-started, ignoring\n",
396 			bus->link_id);
397 		return 0;
398 	}
399 
400 	clock_stop_quirks = sdw->link_res->clock_stop_quirks;
401 
402 	if (pm_runtime_suspended(dev) &&
403 	    pm_runtime_suspended(dev->parent) &&
404 	    ((clock_stop_quirks & SDW_INTEL_CLK_STOP_BUS_RESET) ||
405 	     !clock_stop_quirks)) {
406 		/*
407 		 * if we've enabled clock stop, and the parent is suspended, the SHIM registers
408 		 * are not accessible and the shim wake cannot be disabled.
409 		 * The only solution is to resume the entire bus to full power
410 		 */
411 
412 		/*
413 		 * If any operation in this block fails, we keep going since we don't want
414 		 * to prevent system suspend from happening and errors should be recoverable
415 		 * on resume.
416 		 */
417 
418 		/*
419 		 * first resume the device for this link. This will also by construction
420 		 * resume the PCI parent device.
421 		 */
422 		ret = pm_request_resume(dev);
423 		if (ret < 0) {
424 			dev_err(dev, "%s: pm_request_resume failed: %d\n", __func__, ret);
425 			return 0;
426 		}
427 
428 		/*
429 		 * Continue resuming the entire bus (parent + child devices) to exit
430 		 * the clock stop mode. If there are no devices connected on this link
431 		 * this is a no-op.
432 		 * The resume to full power could have been implemented with a .prepare
433 		 * step in SoundWire codec drivers. This would however require a lot
434 		 * of code to handle an Intel-specific corner case. It is simpler in
435 		 * practice to add a loop at the link level.
436 		 */
437 		ret = device_for_each_child(bus->dev, NULL, intel_resume_child_device);
438 
439 		if (ret < 0)
440 			dev_err(dev, "%s: intel_resume_child_device failed: %d\n", __func__, ret);
441 	}
442 
443 	return 0;
444 }
445 
446 static int __maybe_unused intel_suspend(struct device *dev)
447 {
448 	struct sdw_cdns *cdns = dev_get_drvdata(dev);
449 	struct sdw_intel *sdw = cdns_to_intel(cdns);
450 	struct sdw_bus *bus = &cdns->bus;
451 	u32 clock_stop_quirks;
452 	int ret;
453 
454 	if (bus->prop.hw_disabled || !sdw->startup_done) {
455 		dev_dbg(dev, "SoundWire master %d is disabled or not-started, ignoring\n",
456 			bus->link_id);
457 		return 0;
458 	}
459 
460 	if (pm_runtime_suspended(dev)) {
461 		dev_dbg(dev, "pm_runtime status: suspended\n");
462 
463 		clock_stop_quirks = sdw->link_res->clock_stop_quirks;
464 
465 		if ((clock_stop_quirks & SDW_INTEL_CLK_STOP_BUS_RESET) ||
466 		    !clock_stop_quirks) {
467 
468 			if (pm_runtime_suspended(dev->parent)) {
469 				/*
470 				 * paranoia check: this should not happen with the .prepare
471 				 * resume to full power
472 				 */
473 				dev_err(dev, "%s: invalid config: parent is suspended\n", __func__);
474 			} else {
475 				sdw_intel_shim_wake(sdw, false);
476 			}
477 		}
478 
479 		return 0;
480 	}
481 
482 	ret = sdw_intel_stop_bus(sdw, false);
483 	if (ret < 0) {
484 		dev_err(dev, "%s: cannot stop bus: %d\n", __func__, ret);
485 		return ret;
486 	}
487 
488 	return 0;
489 }
490 
491 static int __maybe_unused intel_suspend_runtime(struct device *dev)
492 {
493 	struct sdw_cdns *cdns = dev_get_drvdata(dev);
494 	struct sdw_intel *sdw = cdns_to_intel(cdns);
495 	struct sdw_bus *bus = &cdns->bus;
496 	u32 clock_stop_quirks;
497 	int ret;
498 
499 	if (bus->prop.hw_disabled || !sdw->startup_done) {
500 		dev_dbg(dev, "SoundWire master %d is disabled or not-started, ignoring\n",
501 			bus->link_id);
502 		return 0;
503 	}
504 
505 	clock_stop_quirks = sdw->link_res->clock_stop_quirks;
506 
507 	if (clock_stop_quirks & SDW_INTEL_CLK_STOP_TEARDOWN) {
508 		ret = sdw_intel_stop_bus(sdw, false);
509 		if (ret < 0) {
510 			dev_err(dev, "%s: cannot stop bus during teardown: %d\n",
511 				__func__, ret);
512 			return ret;
513 		}
514 	} else if (clock_stop_quirks & SDW_INTEL_CLK_STOP_BUS_RESET || !clock_stop_quirks) {
515 		ret = sdw_intel_stop_bus(sdw, true);
516 		if (ret < 0) {
517 			dev_err(dev, "%s: cannot stop bus during clock_stop: %d\n",
518 				__func__, ret);
519 			return ret;
520 		}
521 	} else {
522 		dev_err(dev, "%s clock_stop_quirks %x unsupported\n",
523 			__func__, clock_stop_quirks);
524 		ret = -EINVAL;
525 	}
526 
527 	return ret;
528 }
529 
530 static int __maybe_unused intel_resume(struct device *dev)
531 {
532 	struct sdw_cdns *cdns = dev_get_drvdata(dev);
533 	struct sdw_intel *sdw = cdns_to_intel(cdns);
534 	struct sdw_bus *bus = &cdns->bus;
535 	int link_flags;
536 	int ret;
537 
538 	if (bus->prop.hw_disabled || !sdw->startup_done) {
539 		dev_dbg(dev, "SoundWire master %d is disabled or not-started, ignoring\n",
540 			bus->link_id);
541 		return 0;
542 	}
543 
544 	link_flags = md_flags >> (bus->link_id * 8);
545 
546 	if (pm_runtime_suspended(dev)) {
547 		dev_dbg(dev, "pm_runtime status was suspended, forcing active\n");
548 
549 		/* follow required sequence from runtime_pm.rst */
550 		pm_runtime_disable(dev);
551 		pm_runtime_set_active(dev);
552 		pm_runtime_mark_last_busy(dev);
553 		pm_runtime_enable(dev);
554 
555 		link_flags = md_flags >> (bus->link_id * 8);
556 
557 		if (!(link_flags & SDW_INTEL_MASTER_DISABLE_PM_RUNTIME_IDLE))
558 			pm_runtime_idle(dev);
559 	}
560 
561 	ret = sdw_intel_link_power_up(sdw);
562 	if (ret) {
563 		dev_err(dev, "%s failed: %d\n", __func__, ret);
564 		return ret;
565 	}
566 
567 	/*
568 	 * make sure all Slaves are tagged as UNATTACHED and provide
569 	 * reason for reinitialization
570 	 */
571 	sdw_clear_slave_status(bus, SDW_UNATTACH_REQUEST_MASTER_RESET);
572 
573 	ret = sdw_intel_start_bus(sdw);
574 	if (ret < 0) {
575 		dev_err(dev, "cannot start bus during resume\n");
576 		sdw_intel_link_power_down(sdw);
577 		return ret;
578 	}
579 
580 	/*
581 	 * after system resume, the pm_runtime suspend() may kick in
582 	 * during the enumeration, before any children device force the
583 	 * master device to remain active.  Using pm_runtime_get()
584 	 * routines is not really possible, since it'd prevent the
585 	 * master from suspending.
586 	 * A reasonable compromise is to update the pm_runtime
587 	 * counters and delay the pm_runtime suspend by several
588 	 * seconds, by when all enumeration should be complete.
589 	 */
590 	pm_runtime_mark_last_busy(dev);
591 
592 	return 0;
593 }
594 
595 static int __maybe_unused intel_resume_runtime(struct device *dev)
596 {
597 	struct sdw_cdns *cdns = dev_get_drvdata(dev);
598 	struct sdw_intel *sdw = cdns_to_intel(cdns);
599 	struct sdw_bus *bus = &cdns->bus;
600 	u32 clock_stop_quirks;
601 	int ret;
602 
603 	if (bus->prop.hw_disabled || !sdw->startup_done) {
604 		dev_dbg(dev, "SoundWire master %d is disabled or not-started, ignoring\n",
605 			bus->link_id);
606 		return 0;
607 	}
608 
609 	/* unconditionally disable WAKEEN interrupt */
610 	sdw_intel_shim_wake(sdw, false);
611 
612 	clock_stop_quirks = sdw->link_res->clock_stop_quirks;
613 
614 	if (clock_stop_quirks & SDW_INTEL_CLK_STOP_TEARDOWN) {
615 		ret = sdw_intel_link_power_up(sdw);
616 		if (ret) {
617 			dev_err(dev, "%s: power_up failed after teardown: %d\n", __func__, ret);
618 			return ret;
619 		}
620 
621 		/*
622 		 * make sure all Slaves are tagged as UNATTACHED and provide
623 		 * reason for reinitialization
624 		 */
625 		sdw_clear_slave_status(bus, SDW_UNATTACH_REQUEST_MASTER_RESET);
626 
627 		ret = sdw_intel_start_bus(sdw);
628 		if (ret < 0) {
629 			dev_err(dev, "%s: cannot start bus after teardown: %d\n", __func__, ret);
630 			sdw_intel_link_power_down(sdw);
631 			return ret;
632 		}
633 
634 	} else if (clock_stop_quirks & SDW_INTEL_CLK_STOP_BUS_RESET) {
635 		ret = sdw_intel_link_power_up(sdw);
636 		if (ret) {
637 			dev_err(dev, "%s: power_up failed after bus reset: %d\n", __func__, ret);
638 			return ret;
639 		}
640 
641 		ret = sdw_intel_start_bus_after_reset(sdw);
642 		if (ret < 0) {
643 			dev_err(dev, "%s: cannot start bus after reset: %d\n", __func__, ret);
644 			sdw_intel_link_power_down(sdw);
645 			return ret;
646 		}
647 	} else if (!clock_stop_quirks) {
648 
649 		sdw_intel_check_clock_stop(sdw);
650 
651 		ret = sdw_intel_link_power_up(sdw);
652 		if (ret) {
653 			dev_err(dev, "%s: power_up failed: %d\n", __func__, ret);
654 			return ret;
655 		}
656 
657 		ret = sdw_intel_start_bus_after_clock_stop(sdw);
658 		if (ret < 0) {
659 			dev_err(dev, "%s: cannot start bus after clock stop: %d\n", __func__, ret);
660 			sdw_intel_link_power_down(sdw);
661 			return ret;
662 		}
663 	} else {
664 		dev_err(dev, "%s: clock_stop_quirks %x unsupported\n",
665 			__func__, clock_stop_quirks);
666 		ret = -EINVAL;
667 	}
668 
669 	return ret;
670 }
671 
672 static const struct dev_pm_ops intel_pm = {
673 	.prepare = intel_pm_prepare,
674 	SET_SYSTEM_SLEEP_PM_OPS(intel_suspend, intel_resume)
675 	SET_RUNTIME_PM_OPS(intel_suspend_runtime, intel_resume_runtime, NULL)
676 };
677 
678 static const struct auxiliary_device_id intel_link_id_table[] = {
679 	{ .name = "soundwire_intel.link" },
680 	{},
681 };
682 MODULE_DEVICE_TABLE(auxiliary, intel_link_id_table);
683 
684 static struct auxiliary_driver sdw_intel_drv = {
685 	.probe = intel_link_probe,
686 	.remove = intel_link_remove,
687 	.driver = {
688 		/* auxiliary_driver_register() sets .name to be the modname */
689 		.pm = &intel_pm,
690 	},
691 	.id_table = intel_link_id_table
692 };
693 module_auxiliary_driver(sdw_intel_drv);
694 
695 MODULE_LICENSE("Dual BSD/GPL");
696 MODULE_DESCRIPTION("Intel Soundwire Link Driver");
697