Linux Audio

Check our new training course

Loading...
v5.9
  1// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
  2// Copyright(c) 2015-17 Intel Corporation.
  3
  4/*
  5 * SDW Intel Init Routines
  6 *
  7 * Initializes and creates SDW devices based on ACPI and Hardware values
  8 */
  9
 10#include <linux/acpi.h>
 11#include <linux/export.h>
 12#include <linux/interrupt.h>
 13#include <linux/io.h>
 14#include <linux/module.h>
 15#include <linux/platform_device.h>
 
 16#include <linux/soundwire/sdw_intel.h>
 17#include "cadence_master.h"
 18#include "intel.h"
 
 19
 20#define SDW_LINK_TYPE		4 /* from Intel ACPI documentation */
 21#define SDW_MAX_LINKS		4
 22#define SDW_SHIM_LCAP		0x0
 23#define SDW_SHIM_BASE		0x2C000
 24#define SDW_ALH_BASE		0x2C800
 25#define SDW_LINK_BASE		0x30000
 26#define SDW_LINK_SIZE		0x10000
 27
 28static int ctrl_link_mask;
 29module_param_named(sdw_link_mask, ctrl_link_mask, int, 0444);
 30MODULE_PARM_DESC(sdw_link_mask, "Intel link mask (one bit per link)");
 31
 32static bool is_link_enabled(struct fwnode_handle *fw_node, int i)
 33{
 34	struct fwnode_handle *link;
 35	char name[32];
 36	u32 quirk_mask = 0;
 37
 38	/* Find master handle */
 39	snprintf(name, sizeof(name),
 40		 "mipi-sdw-link-%d-subproperties", i);
 41
 42	link = fwnode_get_named_child_node(fw_node, name);
 43	if (!link)
 44		return false;
 45
 46	fwnode_property_read_u32(link,
 47				 "intel-quirk-mask",
 48				 &quirk_mask);
 49
 50	if (quirk_mask & SDW_INTEL_QUIRK_MASK_BUS_DISABLE)
 51		return false;
 52
 53	return true;
 54}
 55
 56static int sdw_intel_cleanup(struct sdw_intel_ctx *ctx)
 57{
 58	struct sdw_intel_link_res *link = ctx->links;
 59	u32 link_mask;
 60	int i;
 61
 62	if (!link)
 63		return 0;
 64
 65	link_mask = ctx->link_mask;
 66
 67	for (i = 0; i < ctx->count; i++, link++) {
 68		if (!(link_mask & BIT(i)))
 69			continue;
 70
 71		if (link->pdev)
 72			platform_device_unregister(link->pdev);
 73	}
 74
 75	return 0;
 76}
 77
 78static int
 79sdw_intel_scan_controller(struct sdw_intel_acpi_info *info)
 
 
 
 
 80{
 81	struct acpi_device *adev;
 82	int ret, i;
 83	u8 count;
 
 84
 85	if (acpi_bus_get_device(info->handle, &adev))
 86		return -EINVAL;
 
 
 
 
 
 
 
 87
 88	/* Found controller, find links supported */
 89	count = 0;
 90	ret = fwnode_property_read_u8_array(acpi_fwnode_handle(adev),
 91					    "mipi-sdw-master-count", &count, 1);
 92
 93	/*
 94	 * In theory we could check the number of links supported in
 95	 * hardware, but in that step we cannot assume SoundWire IP is
 96	 * powered.
 97	 *
 98	 * In addition, if the BIOS doesn't even provide this
 99	 * 'master-count' property then all the inits based on link
100	 * masks will fail as well.
101	 *
102	 * We will check the hardware capabilities in the startup() step
103	 */
 
104
105	if (ret) {
106		dev_err(&adev->dev,
107			"Failed to read mipi-sdw-master-count: %d\n", ret);
108		return -EINVAL;
109	}
110
111	/* Check count is within bounds */
112	if (count > SDW_MAX_LINKS) {
113		dev_err(&adev->dev, "Link count %d exceeds max %d\n",
114			count, SDW_MAX_LINKS);
115		return -EINVAL;
 
 
 
 
 
 
 
 
 
 
 
 
 
116	}
117
118	if (!count) {
119		dev_warn(&adev->dev, "No SoundWire links detected\n");
120		return -EINVAL;
 
 
 
 
121	}
122	dev_dbg(&adev->dev, "ACPI reports %d SDW Link devices\n", count);
123
124	info->count = count;
125	info->link_mask = 0;
126
127	for (i = 0; i < count; i++) {
128		if (ctrl_link_mask && !(ctrl_link_mask & BIT(i))) {
129			dev_dbg(&adev->dev,
130				"Link %d masked, will not be enabled\n", i);
131			continue;
132		}
133
134		if (!is_link_enabled(acpi_fwnode_handle(adev), i)) {
135			dev_dbg(&adev->dev,
136				"Link %d not selected in firmware\n", i);
137			continue;
138		}
139
140		info->link_mask |= BIT(i);
141	}
 
 
 
142
143	return 0;
144}
145
146#define HDA_DSP_REG_ADSPIC2             (0x10)
147#define HDA_DSP_REG_ADSPIS2             (0x14)
148#define HDA_DSP_REG_ADSPIC2_SNDW        BIT(5)
149
150/**
151 * sdw_intel_enable_irq() - enable/disable Intel SoundWire IRQ
152 * @mmio_base: The mmio base of the control register
153 * @enable: true if enable
154 */
155void sdw_intel_enable_irq(void __iomem *mmio_base, bool enable)
156{
157	u32 val;
158
159	val = readl(mmio_base + HDA_DSP_REG_ADSPIC2);
 
 
160
161	if (enable)
162		val |= HDA_DSP_REG_ADSPIC2_SNDW;
163	else
164		val &= ~HDA_DSP_REG_ADSPIC2_SNDW;
165
166	writel(val, mmio_base + HDA_DSP_REG_ADSPIC2);
167}
168EXPORT_SYMBOL_NS(sdw_intel_enable_irq, SOUNDWIRE_INTEL_INIT);
169
170irqreturn_t sdw_intel_thread(int irq, void *dev_id)
171{
172	struct sdw_intel_ctx *ctx = dev_id;
173	struct sdw_intel_link_res *link;
174
175	list_for_each_entry(link, &ctx->link_list, list)
176		sdw_cdns_irq(irq, link->cdns);
177
178	sdw_intel_enable_irq(ctx->mmio_base, true);
179	return IRQ_HANDLED;
180}
181EXPORT_SYMBOL_NS(sdw_intel_thread, SOUNDWIRE_INTEL_INIT);
182
183static struct sdw_intel_ctx
184*sdw_intel_probe_controller(struct sdw_intel_res *res)
185{
186	struct platform_device_info pdevinfo;
187	struct platform_device *pdev;
188	struct sdw_intel_link_res *link;
 
189	struct sdw_intel_ctx *ctx;
190	struct acpi_device *adev;
191	struct sdw_slave *slave;
192	struct list_head *node;
193	struct sdw_bus *bus;
194	u32 link_mask;
195	int num_slaves = 0;
196	int count;
197	int i;
198
199	if (!res)
200		return NULL;
201
202	if (acpi_bus_get_device(res->handle, &adev))
 
203		return NULL;
204
205	if (!res->count)
206		return NULL;
207
208	count = res->count;
209	dev_dbg(&adev->dev, "Creating %d SDW Link devices\n", count);
210
211	ctx = devm_kzalloc(&adev->dev, sizeof(*ctx), GFP_KERNEL);
 
 
 
 
 
 
212	if (!ctx)
213		return NULL;
214
215	ctx->count = count;
216	ctx->links = devm_kcalloc(&adev->dev, ctx->count,
217				  sizeof(*ctx->links), GFP_KERNEL);
218	if (!ctx->links)
 
 
 
 
 
 
 
219		return NULL;
 
220
221	ctx->count = count;
222	ctx->mmio_base = res->mmio_base;
 
 
223	ctx->link_mask = res->link_mask;
224	ctx->handle = res->handle;
225	mutex_init(&ctx->shim_lock);
226
227	link = ctx->links;
228	link_mask = ctx->link_mask;
229
230	INIT_LIST_HEAD(&ctx->link_list);
231
232	/* Create SDW Master devices */
233	for (i = 0; i < count; i++, link++) {
234		if (!(link_mask & BIT(i))) {
235			dev_dbg(&adev->dev,
236				"Link %d masked, will not be enabled\n", i);
237			continue;
238		}
239
240		link->mmio_base = res->mmio_base;
241		link->registers = res->mmio_base + SDW_LINK_BASE
242			+ (SDW_LINK_SIZE * i);
243		link->shim = res->mmio_base + SDW_SHIM_BASE;
244		link->alh = res->mmio_base + SDW_ALH_BASE;
245
246		link->ops = res->ops;
247		link->dev = res->dev;
248
249		link->shim_lock = &ctx->shim_lock;
250		link->shim_mask = &ctx->shim_mask;
251
252		memset(&pdevinfo, 0, sizeof(pdevinfo));
253
254		pdevinfo.parent = res->parent;
255		pdevinfo.name = "intel-sdw";
256		pdevinfo.id = i;
257		pdevinfo.fwnode = acpi_fwnode_handle(adev);
258		pdevinfo.data = link;
259		pdevinfo.size_data = sizeof(*link);
260
261		pdev = platform_device_register_full(&pdevinfo);
262		if (IS_ERR(pdev)) {
263			dev_err(&adev->dev,
264				"platform device creation failed: %ld\n",
265				PTR_ERR(pdev));
266			goto err;
267		}
268		link->pdev = pdev;
269		link->cdns = platform_get_drvdata(pdev);
270
 
 
 
 
 
 
 
 
 
 
 
 
271		list_add_tail(&link->list, &ctx->link_list);
272		bus = &link->cdns->bus;
273		/* Calculate number of slaves */
274		list_for_each(node, &bus->slaves)
275			num_slaves++;
276	}
277
278	ctx->ids = devm_kcalloc(&adev->dev, num_slaves,
279				sizeof(*ctx->ids), GFP_KERNEL);
280	if (!ctx->ids)
281		goto err;
282
283	ctx->num_slaves = num_slaves;
284	i = 0;
285	list_for_each_entry(link, &ctx->link_list, list) {
286		bus = &link->cdns->bus;
287		list_for_each_entry(slave, &bus->slaves, node) {
288			ctx->ids[i].id = slave->id;
289			ctx->ids[i].link_id = bus->link_id;
290			i++;
291		}
292	}
293
294	return ctx;
295
296err:
297	ctx->count = i;
298	sdw_intel_cleanup(ctx);
 
 
 
 
 
 
299	return NULL;
300}
301
302static int
303sdw_intel_startup_controller(struct sdw_intel_ctx *ctx)
304{
305	struct acpi_device *adev;
306	struct sdw_intel_link_res *link;
307	u32 caps;
308	u32 link_mask;
309	int i;
310
311	if (acpi_bus_get_device(ctx->handle, &adev))
312		return -EINVAL;
313
314	/* Check SNDWLCAP.LCOUNT */
315	caps = ioread32(ctx->mmio_base + SDW_SHIM_BASE + SDW_SHIM_LCAP);
316	caps &= GENMASK(2, 0);
317
318	/* Check HW supported vs property value */
319	if (caps < ctx->count) {
320		dev_err(&adev->dev,
321			"BIOS master count is larger than hardware capabilities\n");
322		return -EINVAL;
323	}
324
325	if (!ctx->links)
326		return -EINVAL;
327
328	link = ctx->links;
329	link_mask = ctx->link_mask;
330
331	/* Startup SDW Master devices */
332	for (i = 0; i < ctx->count; i++, link++) {
333		if (!(link_mask & BIT(i)))
334			continue;
335
336		intel_master_startup(link->pdev);
337	}
338
339	return 0;
340}
341
342static acpi_status sdw_intel_acpi_cb(acpi_handle handle, u32 level,
343				     void *cdata, void **return_value)
344{
345	struct sdw_intel_acpi_info *info = cdata;
346	struct acpi_device *adev;
347	acpi_status status;
348	u64 adr;
349
350	status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &adr);
351	if (ACPI_FAILURE(status))
352		return AE_OK; /* keep going */
353
354	if (acpi_bus_get_device(handle, &adev)) {
355		pr_err("%s: Couldn't find ACPI handle\n", __func__);
356		return AE_NOT_FOUND;
 
 
357	}
358
359	info->handle = handle;
360
361	/*
362	 * On some Intel platforms, multiple children of the HDAS
363	 * device can be found, but only one of them is the SoundWire
364	 * controller. The SNDW device is always exposed with
365	 * Name(_ADR, 0x40000000), with bits 31..28 representing the
366	 * SoundWire link so filter accordingly
367	 */
368	if ((adr & GENMASK(31, 28)) >> 28 != SDW_LINK_TYPE)
369		return AE_OK; /* keep going */
370
371	/* device found, stop namespace walk */
372	return AE_CTRL_TERMINATE;
373}
374
375/**
376 * sdw_intel_acpi_scan() - SoundWire Intel init routine
377 * @parent_handle: ACPI parent handle
378 * @info: description of what firmware/DSDT tables expose
379 *
380 * This scans the namespace and queries firmware to figure out which
381 * links to enable. A follow-up use of sdw_intel_probe() and
382 * sdw_intel_startup() is required for creation of devices and bus
383 * startup
384 */
385int sdw_intel_acpi_scan(acpi_handle *parent_handle,
386			struct sdw_intel_acpi_info *info)
387{
388	acpi_status status;
389
390	status = acpi_walk_namespace(ACPI_TYPE_DEVICE,
391				     parent_handle, 1,
392				     sdw_intel_acpi_cb,
393				     NULL, info, NULL);
394	if (ACPI_FAILURE(status))
395		return -ENODEV;
396
397	return sdw_intel_scan_controller(info);
398}
399EXPORT_SYMBOL_NS(sdw_intel_acpi_scan, SOUNDWIRE_INTEL_INIT);
400
401/**
402 * sdw_intel_probe() - SoundWire Intel probe routine
403 * @res: resource data
404 *
405 * This registers a platform device for each Master handled by the controller,
406 * and SoundWire Master and Slave devices will be created by the platform
407 * device probe. All the information necessary is stored in the context, and
408 * the res argument pointer can be freed after this step.
409 * This function will be called after sdw_intel_acpi_scan() by SOF probe.
410 */
411struct sdw_intel_ctx
412*sdw_intel_probe(struct sdw_intel_res *res)
413{
414	return sdw_intel_probe_controller(res);
415}
416EXPORT_SYMBOL_NS(sdw_intel_probe, SOUNDWIRE_INTEL_INIT);
417
418/**
419 * sdw_intel_startup() - SoundWire Intel startup
420 * @ctx: SoundWire context allocated in the probe
421 *
422 * Startup Intel SoundWire controller. This function will be called after
423 * Intel Audio DSP is powered up.
424 */
425int sdw_intel_startup(struct sdw_intel_ctx *ctx)
426{
427	return sdw_intel_startup_controller(ctx);
428}
429EXPORT_SYMBOL_NS(sdw_intel_startup, SOUNDWIRE_INTEL_INIT);
430/**
431 * sdw_intel_exit() - SoundWire Intel exit
432 * @ctx: SoundWire context allocated in the probe
433 *
434 * Delete the controller instances created and cleanup
435 */
436void sdw_intel_exit(struct sdw_intel_ctx *ctx)
437{
438	sdw_intel_cleanup(ctx);
 
 
 
439}
440EXPORT_SYMBOL_NS(sdw_intel_exit, SOUNDWIRE_INTEL_INIT);
441
442void sdw_intel_process_wakeen_event(struct sdw_intel_ctx *ctx)
443{
444	struct sdw_intel_link_res *link;
445	u32 link_mask;
446	int i;
447
448	if (!ctx->links)
449		return;
450
451	link = ctx->links;
452	link_mask = ctx->link_mask;
453
454	/* Startup SDW Master devices */
455	for (i = 0; i < ctx->count; i++, link++) {
456		if (!(link_mask & BIT(i)))
457			continue;
458
459		intel_master_process_wakeen_event(link->pdev);
 
 
460	}
461}
462EXPORT_SYMBOL_NS(sdw_intel_process_wakeen_event, SOUNDWIRE_INTEL_INIT);
463
464MODULE_LICENSE("Dual BSD/GPL");
465MODULE_DESCRIPTION("Intel Soundwire Init Library");
v6.2
  1// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
  2// Copyright(c) 2015-17 Intel Corporation.
  3
  4/*
  5 * SDW Intel Init Routines
  6 *
  7 * Initializes and creates SDW devices based on ACPI and Hardware values
  8 */
  9
 10#include <linux/acpi.h>
 11#include <linux/export.h>
 12#include <linux/interrupt.h>
 13#include <linux/io.h>
 14#include <linux/module.h>
 15#include <linux/auxiliary_bus.h>
 16#include <linux/pm_runtime.h>
 17#include <linux/soundwire/sdw_intel.h>
 18#include "cadence_master.h"
 19#include "intel.h"
 20#include "intel_auxdevice.h"
 21
 22static void intel_link_dev_release(struct device *dev)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 23{
 24	struct auxiliary_device *auxdev = to_auxiliary_dev(dev);
 25	struct sdw_intel_link_dev *ldev = auxiliary_dev_to_sdw_intel_link_dev(auxdev);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 26
 27	kfree(ldev);
 28}
 29
 30/* alloc, init and add link devices */
 31static struct sdw_intel_link_dev *intel_link_dev_register(struct sdw_intel_res *res,
 32							  struct sdw_intel_ctx *ctx,
 33							  struct fwnode_handle *fwnode,
 34							  const char *name,
 35							  int link_id)
 36{
 37	struct sdw_intel_link_dev *ldev;
 38	struct sdw_intel_link_res *link;
 39	struct auxiliary_device *auxdev;
 40	int ret;
 41
 42	ldev = kzalloc(sizeof(*ldev), GFP_KERNEL);
 43	if (!ldev)
 44		return ERR_PTR(-ENOMEM);
 45
 46	auxdev = &ldev->auxdev;
 47	auxdev->name = name;
 48	auxdev->dev.parent = res->parent;
 49	auxdev->dev.fwnode = fwnode;
 50	auxdev->dev.release = intel_link_dev_release;
 51
 52	/* we don't use an IDA since we already have a link ID */
 53	auxdev->id = link_id;
 
 
 54
 55	/*
 56	 * keep a handle on the allocated memory, to be used in all other functions.
 57	 * Since the same pattern is used to skip links that are not enabled, there is
 58	 * no need to check if ctx->ldev[i] is NULL later on.
 
 
 
 
 
 
 59	 */
 60	ctx->ldev[link_id] = ldev;
 61
 62	/* Add link information used in the driver probe */
 63	link = &ldev->link_res;
 64	link->hw_ops = res->hw_ops;
 65	link->mmio_base = res->mmio_base;
 66	link->registers = res->mmio_base + SDW_LINK_BASE
 67		+ (SDW_LINK_SIZE * link_id);
 68	link->shim = res->mmio_base + res->shim_base;
 69	link->alh = res->mmio_base + res->alh_base;
 70
 71	link->ops = res->ops;
 72	link->dev = res->dev;
 73
 74	link->clock_stop_quirks = res->clock_stop_quirks;
 75	link->shim_lock = &ctx->shim_lock;
 76	link->shim_mask = &ctx->shim_mask;
 77	link->link_mask = ctx->link_mask;
 78
 79	/* now follow the two-step init/add sequence */
 80	ret = auxiliary_device_init(auxdev);
 81	if (ret < 0) {
 82		dev_err(res->parent, "failed to initialize link dev %s link_id %d\n",
 83			name, link_id);
 84		kfree(ldev);
 85		return ERR_PTR(ret);
 86	}
 87
 88	ret = auxiliary_device_add(&ldev->auxdev);
 89	if (ret < 0) {
 90		dev_err(res->parent, "failed to add link dev %s link_id %d\n",
 91			ldev->auxdev.name, link_id);
 92		/* ldev will be freed with the put_device() and .release sequence */
 93		auxiliary_device_uninit(&ldev->auxdev);
 94		return ERR_PTR(ret);
 95	}
 
 
 
 
 96
 97	return ldev;
 98}
 
 
 
 
 99
100static void intel_link_dev_unregister(struct sdw_intel_link_dev *ldev)
101{
102	auxiliary_device_delete(&ldev->auxdev);
103	auxiliary_device_uninit(&ldev->auxdev);
104}
105
106static int sdw_intel_cleanup(struct sdw_intel_ctx *ctx)
107{
108	struct sdw_intel_link_dev *ldev;
109	u32 link_mask;
110	int i;
111
112	link_mask = ctx->link_mask;
 
113
114	for (i = 0; i < ctx->count; i++) {
115		if (!(link_mask & BIT(i)))
116			continue;
117
118		ldev = ctx->ldev[i];
 
 
 
 
 
 
 
119
120		pm_runtime_disable(&ldev->auxdev.dev);
121		if (!ldev->link_res.clock_stop_quirks)
122			pm_runtime_put_noidle(ldev->link_res.dev);
123
124		intel_link_dev_unregister(ldev);
125	}
 
 
126
127	return 0;
128}
 
129
130irqreturn_t sdw_intel_thread(int irq, void *dev_id)
131{
132	struct sdw_intel_ctx *ctx = dev_id;
133	struct sdw_intel_link_res *link;
134
135	list_for_each_entry(link, &ctx->link_list, list)
136		sdw_cdns_irq(irq, link->cdns);
137
 
138	return IRQ_HANDLED;
139}
140EXPORT_SYMBOL_NS(sdw_intel_thread, SOUNDWIRE_INTEL_INIT);
141
142static struct sdw_intel_ctx
143*sdw_intel_probe_controller(struct sdw_intel_res *res)
144{
 
 
145	struct sdw_intel_link_res *link;
146	struct sdw_intel_link_dev *ldev;
147	struct sdw_intel_ctx *ctx;
148	struct acpi_device *adev;
149	struct sdw_slave *slave;
150	struct list_head *node;
151	struct sdw_bus *bus;
152	u32 link_mask;
153	int num_slaves = 0;
154	int count;
155	int i;
156
157	if (!res)
158		return NULL;
159
160	adev = acpi_fetch_acpi_dev(res->handle);
161	if (!adev)
162		return NULL;
163
164	if (!res->count)
165		return NULL;
166
167	count = res->count;
168	dev_dbg(&adev->dev, "Creating %d SDW Link devices\n", count);
169
170	/*
171	 * we need to alloc/free memory manually and can't use devm:
172	 * this routine may be called from a workqueue, and not from
173	 * the parent .probe.
174	 * If devm_ was used, the memory might never be freed on errors.
175	 */
176	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
177	if (!ctx)
178		return NULL;
179
180	ctx->count = count;
181
182	/*
183	 * allocate the array of pointers. The link-specific data is allocated
184	 * as part of the first loop below and released with the auxiliary_device_uninit().
185	 * If some links are disabled, the link pointer will remain NULL. Given that the
186	 * number of links is small, this is simpler than using a list to keep track of links.
187	 */
188	ctx->ldev = kcalloc(ctx->count, sizeof(*ctx->ldev), GFP_KERNEL);
189	if (!ctx->ldev) {
190		kfree(ctx);
191		return NULL;
192	}
193
 
194	ctx->mmio_base = res->mmio_base;
195	ctx->shim_base = res->shim_base;
196	ctx->alh_base = res->alh_base;
197	ctx->link_mask = res->link_mask;
198	ctx->handle = res->handle;
199	mutex_init(&ctx->shim_lock);
200
 
201	link_mask = ctx->link_mask;
202
203	INIT_LIST_HEAD(&ctx->link_list);
204
205	for (i = 0; i < count; i++) {
206		if (!(link_mask & BIT(i)))
 
 
 
207			continue;
 
208
209		/*
210		 * init and add a device for each link
211		 *
212		 * The name of the device will be soundwire_intel.link.[i],
213		 * with the "soundwire_intel" module prefix automatically added
214		 * by the auxiliary bus core.
215		 */
216		ldev = intel_link_dev_register(res,
217					       ctx,
218					       acpi_fwnode_handle(adev),
219					       "link",
220					       i);
221		if (IS_ERR(ldev))
 
 
 
 
 
 
 
 
 
 
 
 
 
222			goto err;
 
 
 
223
224		link = &ldev->link_res;
225		link->cdns = auxiliary_get_drvdata(&ldev->auxdev);
226
227		if (!link->cdns) {
228			dev_err(&adev->dev, "failed to get link->cdns\n");
229			/*
230			 * 1 will be subtracted from i in the err label, but we need to call
231			 * intel_link_dev_unregister for this ldev, so plus 1 now
232			 */
233			i++;
234			goto err;
235		}
236		list_add_tail(&link->list, &ctx->link_list);
237		bus = &link->cdns->bus;
238		/* Calculate number of slaves */
239		list_for_each(node, &bus->slaves)
240			num_slaves++;
241	}
242
243	ctx->ids = kcalloc(num_slaves, sizeof(*ctx->ids), GFP_KERNEL);
 
244	if (!ctx->ids)
245		goto err;
246
247	ctx->num_slaves = num_slaves;
248	i = 0;
249	list_for_each_entry(link, &ctx->link_list, list) {
250		bus = &link->cdns->bus;
251		list_for_each_entry(slave, &bus->slaves, node) {
252			ctx->ids[i].id = slave->id;
253			ctx->ids[i].link_id = bus->link_id;
254			i++;
255		}
256	}
257
258	return ctx;
259
260err:
261	while (i--) {
262		if (!(link_mask & BIT(i)))
263			continue;
264		ldev = ctx->ldev[i];
265		intel_link_dev_unregister(ldev);
266	}
267	kfree(ctx->ldev);
268	kfree(ctx);
269	return NULL;
270}
271
272static int
273sdw_intel_startup_controller(struct sdw_intel_ctx *ctx)
274{
275	struct acpi_device *adev = acpi_fetch_acpi_dev(ctx->handle);
276	struct sdw_intel_link_dev *ldev;
 
277	u32 link_mask;
278	int i;
279
280	if (!adev)
281		return -EINVAL;
282
283	if (!ctx->ldev)
 
 
 
 
 
 
 
284		return -EINVAL;
 
285
 
 
 
 
286	link_mask = ctx->link_mask;
287
288	/* Startup SDW Master devices */
289	for (i = 0; i < ctx->count; i++) {
290		if (!(link_mask & BIT(i)))
291			continue;
292
293		ldev = ctx->ldev[i];
 
 
 
 
294
295		intel_link_startup(&ldev->auxdev);
 
 
 
 
 
 
296
297		if (!ldev->link_res.clock_stop_quirks) {
298			/*
299			 * we need to prevent the parent PCI device
300			 * from entering pm_runtime suspend, so that
301			 * power rails to the SoundWire IP are not
302			 * turned off.
303			 */
304			pm_runtime_get_noresume(ldev->link_res.dev);
305		}
306	}
307
308	return 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309}
 
310
311/**
312 * sdw_intel_probe() - SoundWire Intel probe routine
313 * @res: resource data
314 *
315 * This registers an auxiliary device for each Master handled by the controller,
316 * and SoundWire Master and Slave devices will be created by the auxiliary
317 * device probe. All the information necessary is stored in the context, and
318 * the res argument pointer can be freed after this step.
319 * This function will be called after sdw_intel_acpi_scan() by SOF probe.
320 */
321struct sdw_intel_ctx
322*sdw_intel_probe(struct sdw_intel_res *res)
323{
324	return sdw_intel_probe_controller(res);
325}
326EXPORT_SYMBOL_NS(sdw_intel_probe, SOUNDWIRE_INTEL_INIT);
327
328/**
329 * sdw_intel_startup() - SoundWire Intel startup
330 * @ctx: SoundWire context allocated in the probe
331 *
332 * Startup Intel SoundWire controller. This function will be called after
333 * Intel Audio DSP is powered up.
334 */
335int sdw_intel_startup(struct sdw_intel_ctx *ctx)
336{
337	return sdw_intel_startup_controller(ctx);
338}
339EXPORT_SYMBOL_NS(sdw_intel_startup, SOUNDWIRE_INTEL_INIT);
340/**
341 * sdw_intel_exit() - SoundWire Intel exit
342 * @ctx: SoundWire context allocated in the probe
343 *
344 * Delete the controller instances created and cleanup
345 */
346void sdw_intel_exit(struct sdw_intel_ctx *ctx)
347{
348	sdw_intel_cleanup(ctx);
349	kfree(ctx->ids);
350	kfree(ctx->ldev);
351	kfree(ctx);
352}
353EXPORT_SYMBOL_NS(sdw_intel_exit, SOUNDWIRE_INTEL_INIT);
354
355void sdw_intel_process_wakeen_event(struct sdw_intel_ctx *ctx)
356{
357	struct sdw_intel_link_dev *ldev;
358	u32 link_mask;
359	int i;
360
361	if (!ctx->ldev)
362		return;
363
 
364	link_mask = ctx->link_mask;
365
366	/* Startup SDW Master devices */
367	for (i = 0; i < ctx->count; i++) {
368		if (!(link_mask & BIT(i)))
369			continue;
370
371		ldev = ctx->ldev[i];
372
373		intel_link_process_wakeen_event(&ldev->auxdev);
374	}
375}
376EXPORT_SYMBOL_NS(sdw_intel_process_wakeen_event, SOUNDWIRE_INTEL_INIT);
377
378MODULE_LICENSE("Dual BSD/GPL");
379MODULE_DESCRIPTION("Intel Soundwire Init Library");