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