1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2 // Copyright(c) 2015-2023 Intel Corporation
4 #include <linux/acpi.h>
5 #include <linux/soundwire/sdw_registers.h>
6 #include <linux/soundwire/sdw.h>
7 #include <linux/soundwire/sdw_intel.h>
8 #include "cadence_master.h"
12 int intel_start_bus(struct sdw_intel
*sdw
)
14 struct device
*dev
= sdw
->cdns
.dev
;
15 struct sdw_cdns
*cdns
= &sdw
->cdns
;
16 struct sdw_bus
*bus
= &cdns
->bus
;
20 * follow recommended programming flows to avoid timeouts when
24 sdw_intel_sync_arm(sdw
);
26 ret
= sdw_cdns_init(cdns
);
28 dev_err(dev
, "%s: unable to initialize Cadence IP: %d\n", __func__
, ret
);
32 sdw_cdns_config_update(cdns
);
34 if (bus
->multi_link
) {
35 ret
= sdw_intel_sync_go(sdw
);
37 dev_err(dev
, "%s: sync go failed: %d\n", __func__
, ret
);
42 ret
= sdw_cdns_config_update_set_wait(cdns
);
44 dev_err(dev
, "%s: CONFIG_UPDATE BIT still set\n", __func__
);
48 ret
= sdw_cdns_enable_interrupt(cdns
, true);
50 dev_err(dev
, "%s: cannot enable interrupts: %d\n", __func__
, ret
);
54 ret
= sdw_cdns_exit_reset(cdns
);
56 dev_err(dev
, "%s: unable to exit bus reset sequence: %d\n", __func__
, ret
);
60 sdw_cdns_check_self_clearing_bits(cdns
, __func__
,
61 true, INTEL_MASTER_RESET_ITERATIONS
);
63 schedule_delayed_work(&cdns
->attach_dwork
,
64 msecs_to_jiffies(SDW_INTEL_DELAYED_ENUMERATION_MS
));
69 int intel_start_bus_after_reset(struct sdw_intel
*sdw
)
71 struct device
*dev
= sdw
->cdns
.dev
;
72 struct sdw_cdns
*cdns
= &sdw
->cdns
;
73 struct sdw_bus
*bus
= &cdns
->bus
;
79 * An exception condition occurs for the CLK_STOP_BUS_RESET
80 * case if one or more masters remain active. In this condition,
81 * all the masters are powered on for they are in the same power
82 * domain. Master can preserve its context for clock stop0, so
83 * there is no need to clear slave status and reset bus.
85 clock_stop0
= sdw_cdns_is_clock_stop(&sdw
->cdns
);
90 * make sure all Slaves are tagged as UNATTACHED and
91 * provide reason for reinitialization
94 status
= SDW_UNATTACH_REQUEST_MASTER_RESET
;
95 sdw_clear_slave_status(bus
, status
);
98 * follow recommended programming flows to avoid
99 * timeouts when gsync is enabled
102 sdw_intel_sync_arm(sdw
);
105 * Re-initialize the IP since it was powered-off
107 sdw_cdns_init(&sdw
->cdns
);
110 ret
= sdw_cdns_enable_interrupt(cdns
, true);
112 dev_err(dev
, "cannot enable interrupts during resume\n");
117 ret
= sdw_cdns_clock_restart(cdns
, !clock_stop0
);
119 dev_err(dev
, "unable to restart clock during resume\n");
121 sdw_cdns_enable_interrupt(cdns
, false);
126 sdw_cdns_config_update(cdns
);
128 if (bus
->multi_link
) {
129 ret
= sdw_intel_sync_go(sdw
);
131 dev_err(sdw
->cdns
.dev
, "sync go failed during resume\n");
136 ret
= sdw_cdns_config_update_set_wait(cdns
);
138 dev_err(dev
, "%s: CONFIG_UPDATE BIT still set\n", __func__
);
142 ret
= sdw_cdns_enable_interrupt(cdns
, true);
144 dev_err(dev
, "cannot enable interrupts during resume\n");
148 ret
= sdw_cdns_exit_reset(cdns
);
150 dev_err(dev
, "unable to exit bus reset sequence during resume\n");
155 sdw_cdns_check_self_clearing_bits(cdns
, __func__
, true, INTEL_MASTER_RESET_ITERATIONS
);
157 schedule_delayed_work(&cdns
->attach_dwork
,
158 msecs_to_jiffies(SDW_INTEL_DELAYED_ENUMERATION_MS
));
163 void intel_check_clock_stop(struct sdw_intel
*sdw
)
165 struct device
*dev
= sdw
->cdns
.dev
;
168 clock_stop0
= sdw_cdns_is_clock_stop(&sdw
->cdns
);
170 dev_err(dev
, "%s: invalid configuration, clock was not stopped\n", __func__
);
173 int intel_start_bus_after_clock_stop(struct sdw_intel
*sdw
)
175 struct device
*dev
= sdw
->cdns
.dev
;
176 struct sdw_cdns
*cdns
= &sdw
->cdns
;
179 ret
= sdw_cdns_clock_restart(cdns
, false);
181 dev_err(dev
, "%s: unable to restart clock: %d\n", __func__
, ret
);
185 ret
= sdw_cdns_enable_interrupt(cdns
, true);
187 dev_err(dev
, "%s: cannot enable interrupts: %d\n", __func__
, ret
);
191 sdw_cdns_check_self_clearing_bits(cdns
, __func__
, true, INTEL_MASTER_RESET_ITERATIONS
);
193 schedule_delayed_work(&cdns
->attach_dwork
,
194 msecs_to_jiffies(SDW_INTEL_DELAYED_ENUMERATION_MS
));
199 int intel_stop_bus(struct sdw_intel
*sdw
, bool clock_stop
)
201 struct device
*dev
= sdw
->cdns
.dev
;
202 struct sdw_cdns
*cdns
= &sdw
->cdns
;
203 bool wake_enable
= false;
206 cancel_delayed_work_sync(&cdns
->attach_dwork
);
209 ret
= sdw_cdns_clock_stop(cdns
, true);
211 dev_err(dev
, "%s: cannot stop clock: %d\n", __func__
, ret
);
216 ret
= sdw_cdns_enable_interrupt(cdns
, false);
218 dev_err(dev
, "%s: cannot disable interrupts: %d\n", __func__
, ret
);
222 ret
= sdw_intel_link_power_down(sdw
);
224 dev_err(dev
, "%s: Link power down failed: %d\n", __func__
, ret
);
228 sdw_intel_shim_wake(sdw
, wake_enable
);
234 * bank switch routines
237 int intel_pre_bank_switch(struct sdw_intel
*sdw
)
239 struct sdw_cdns
*cdns
= &sdw
->cdns
;
240 struct sdw_bus
*bus
= &cdns
->bus
;
242 /* Write to register only for multi-link */
243 if (!bus
->multi_link
)
246 sdw_intel_sync_arm(sdw
);
251 int intel_post_bank_switch(struct sdw_intel
*sdw
)
253 struct sdw_cdns
*cdns
= &sdw
->cdns
;
254 struct sdw_bus
*bus
= &cdns
->bus
;
257 /* Write to register only for multi-link */
258 if (!bus
->multi_link
)
261 mutex_lock(sdw
->link_res
->shim_lock
);
264 * post_bank_switch() ops is called from the bus in loop for
265 * all the Masters in the steam with the expectation that
266 * we trigger the bankswitch for the only first Master in the list
267 * and do nothing for the other Masters
269 * So, set the SYNCGO bit only if CMDSYNC bit is set for any Master.
271 if (sdw_intel_sync_check_cmdsync_unlocked(sdw
))
272 ret
= sdw_intel_sync_go_unlocked(sdw
);
274 mutex_unlock(sdw
->link_res
->shim_lock
);
277 dev_err(sdw
->cdns
.dev
, "Post bank switch failed: %d\n", ret
);