blob: 0a4fc7f657439692c3c5d82f71e70fea87791d34 [file] [log] [blame]
Vinod Koul71bb8a12017-12-14 11:19:43 +05301// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2// Copyright(c) 2015-17 Intel Corporation.
3
4/*
5 * Soundwire Intel Master Driver
6 */
7
8#include <linux/acpi.h>
Pierre-Louis Bossart79ee6632019-08-21 13:58:20 -05009#include <linux/debugfs.h>
Vinod Koul71bb8a12017-12-14 11:19:43 +053010#include <linux/delay.h>
Paul Gortmaker4abbd782019-04-13 11:12:52 -040011#include <linux/module.h>
Vinod Koul71bb8a12017-12-14 11:19:43 +053012#include <linux/interrupt.h>
Pierre-Louis Bossartdf72b712019-09-16 13:57:38 -050013#include <linux/io.h>
Vinod Koul71bb8a12017-12-14 11:19:43 +053014#include <linux/platform_device.h>
Vinod Koul37a2d222018-04-26 18:38:58 +053015#include <sound/pcm_params.h>
16#include <sound/soc.h>
Vinod Koul71bb8a12017-12-14 11:19:43 +053017#include <linux/soundwire/sdw_registers.h>
18#include <linux/soundwire/sdw.h>
19#include <linux/soundwire/sdw_intel.h>
20#include "cadence_master.h"
Pierre-Louis Bossart79ee6632019-08-21 13:58:20 -050021#include "bus.h"
Vinod Koul71bb8a12017-12-14 11:19:43 +053022#include "intel.h"
23
24/* Intel SHIM Registers Definition */
25#define SDW_SHIM_LCAP 0x0
26#define SDW_SHIM_LCTL 0x4
27#define SDW_SHIM_IPPTR 0x8
28#define SDW_SHIM_SYNC 0xC
29
Pierre-Louis Bossart7cc6e312019-05-01 10:57:39 -050030#define SDW_SHIM_CTLSCAP(x) (0x010 + 0x60 * (x))
31#define SDW_SHIM_CTLS0CM(x) (0x012 + 0x60 * (x))
32#define SDW_SHIM_CTLS1CM(x) (0x014 + 0x60 * (x))
33#define SDW_SHIM_CTLS2CM(x) (0x016 + 0x60 * (x))
34#define SDW_SHIM_CTLS3CM(x) (0x018 + 0x60 * (x))
35#define SDW_SHIM_PCMSCAP(x) (0x020 + 0x60 * (x))
Vinod Koul71bb8a12017-12-14 11:19:43 +053036
Pierre-Louis Bossart7cc6e312019-05-01 10:57:39 -050037#define SDW_SHIM_PCMSYCHM(x, y) (0x022 + (0x60 * (x)) + (0x2 * (y)))
38#define SDW_SHIM_PCMSYCHC(x, y) (0x042 + (0x60 * (x)) + (0x2 * (y)))
39#define SDW_SHIM_PDMSCAP(x) (0x062 + 0x60 * (x))
40#define SDW_SHIM_IOCTL(x) (0x06C + 0x60 * (x))
41#define SDW_SHIM_CTMCTL(x) (0x06E + 0x60 * (x))
Vinod Koul71bb8a12017-12-14 11:19:43 +053042
43#define SDW_SHIM_WAKEEN 0x190
44#define SDW_SHIM_WAKESTS 0x192
45
46#define SDW_SHIM_LCTL_SPA BIT(0)
47#define SDW_SHIM_LCTL_CPA BIT(8)
48
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +080049#define SDW_SHIM_SYNC_SYNCPRD_VAL_24 (24000 / SDW_CADENCE_GSYNC_KHZ - 1)
50#define SDW_SHIM_SYNC_SYNCPRD_VAL_38_4 (38400 / SDW_CADENCE_GSYNC_KHZ - 1)
Vinod Koul71bb8a12017-12-14 11:19:43 +053051#define SDW_SHIM_SYNC_SYNCPRD GENMASK(14, 0)
52#define SDW_SHIM_SYNC_SYNCCPU BIT(15)
53#define SDW_SHIM_SYNC_CMDSYNC_MASK GENMASK(19, 16)
54#define SDW_SHIM_SYNC_CMDSYNC BIT(16)
55#define SDW_SHIM_SYNC_SYNCGO BIT(24)
56
57#define SDW_SHIM_PCMSCAP_ISS GENMASK(3, 0)
58#define SDW_SHIM_PCMSCAP_OSS GENMASK(7, 4)
59#define SDW_SHIM_PCMSCAP_BSS GENMASK(12, 8)
60
61#define SDW_SHIM_PCMSYCM_LCHN GENMASK(3, 0)
62#define SDW_SHIM_PCMSYCM_HCHN GENMASK(7, 4)
63#define SDW_SHIM_PCMSYCM_STREAM GENMASK(13, 8)
64#define SDW_SHIM_PCMSYCM_DIR BIT(15)
65
66#define SDW_SHIM_PDMSCAP_ISS GENMASK(3, 0)
67#define SDW_SHIM_PDMSCAP_OSS GENMASK(7, 4)
68#define SDW_SHIM_PDMSCAP_BSS GENMASK(12, 8)
69#define SDW_SHIM_PDMSCAP_CPSS GENMASK(15, 13)
70
71#define SDW_SHIM_IOCTL_MIF BIT(0)
72#define SDW_SHIM_IOCTL_CO BIT(1)
73#define SDW_SHIM_IOCTL_COE BIT(2)
74#define SDW_SHIM_IOCTL_DO BIT(3)
75#define SDW_SHIM_IOCTL_DOE BIT(4)
76#define SDW_SHIM_IOCTL_BKE BIT(5)
77#define SDW_SHIM_IOCTL_WPDD BIT(6)
78#define SDW_SHIM_IOCTL_CIBD BIT(8)
79#define SDW_SHIM_IOCTL_DIBD BIT(9)
80
81#define SDW_SHIM_CTMCTL_DACTQE BIT(0)
82#define SDW_SHIM_CTMCTL_DODS BIT(1)
83#define SDW_SHIM_CTMCTL_DOAIS GENMASK(4, 3)
84
85#define SDW_SHIM_WAKEEN_ENABLE BIT(0)
86#define SDW_SHIM_WAKESTS_STATUS BIT(0)
87
88/* Intel ALH Register definitions */
Pierre-Louis Bossart7cc6e312019-05-01 10:57:39 -050089#define SDW_ALH_STRMZCFG(x) (0x000 + (0x4 * (x)))
Pierre-Louis Bossart79ee6632019-08-21 13:58:20 -050090#define SDW_ALH_NUM_STREAMS 64
Vinod Koul71bb8a12017-12-14 11:19:43 +053091
92#define SDW_ALH_STRMZCFG_DMAT_VAL 0x3
93#define SDW_ALH_STRMZCFG_DMAT GENMASK(7, 0)
94#define SDW_ALH_STRMZCFG_CHN GENMASK(19, 16)
95
Vinod Koulc46302e2018-04-26 18:39:05 +053096enum intel_pdi_type {
97 INTEL_PDI_IN = 0,
98 INTEL_PDI_OUT = 1,
99 INTEL_PDI_BD = 2,
100};
101
Vinod Koul71bb8a12017-12-14 11:19:43 +0530102#define cdns_to_intel(_cdns) container_of(_cdns, struct sdw_intel, cdns)
103
104/*
105 * Read, write helpers for HW registers
106 */
107static inline int intel_readl(void __iomem *base, int offset)
108{
109 return readl(base + offset);
110}
111
112static inline void intel_writel(void __iomem *base, int offset, int value)
113{
114 writel(value, base + offset);
115}
116
117static inline u16 intel_readw(void __iomem *base, int offset)
118{
119 return readw(base + offset);
120}
121
122static inline void intel_writew(void __iomem *base, int offset, u16 value)
123{
124 writew(value, base + offset);
125}
126
Pierre-Louis Bossart7d2845d2020-07-16 23:09:39 +0800127static int intel_wait_bit(void __iomem *base, int offset, u32 mask, u32 target)
Vinod Koul71bb8a12017-12-14 11:19:43 +0530128{
129 int timeout = 10;
130 u32 reg_read;
131
Vinod Koul71bb8a12017-12-14 11:19:43 +0530132 do {
133 reg_read = readl(base + offset);
Pierre-Louis Bossart7d2845d2020-07-16 23:09:39 +0800134 if ((reg_read & mask) == target)
Vinod Koul71bb8a12017-12-14 11:19:43 +0530135 return 0;
136
137 timeout--;
Pierre-Louis Bossart7d2845d2020-07-16 23:09:39 +0800138 usleep_range(50, 100);
Vinod Koul71bb8a12017-12-14 11:19:43 +0530139 } while (timeout != 0);
140
141 return -EAGAIN;
142}
143
Pierre-Louis Bossart7d2845d2020-07-16 23:09:39 +0800144static int intel_clear_bit(void __iomem *base, int offset, u32 value, u32 mask)
145{
146 writel(value, base + offset);
147 return intel_wait_bit(base, offset, mask, 0);
148}
149
Vinod Koul71bb8a12017-12-14 11:19:43 +0530150static int intel_set_bit(void __iomem *base, int offset, u32 value, u32 mask)
151{
Vinod Koul71bb8a12017-12-14 11:19:43 +0530152 writel(value, base + offset);
Pierre-Louis Bossart7d2845d2020-07-16 23:09:39 +0800153 return intel_wait_bit(base, offset, mask, mask);
Vinod Koul71bb8a12017-12-14 11:19:43 +0530154}
155
156/*
Pierre-Louis Bossart79ee6632019-08-21 13:58:20 -0500157 * debugfs
158 */
159#ifdef CONFIG_DEBUG_FS
160
161#define RD_BUF (2 * PAGE_SIZE)
162
163static ssize_t intel_sprintf(void __iomem *mem, bool l,
164 char *buf, size_t pos, unsigned int reg)
165{
166 int value;
167
168 if (l)
169 value = intel_readl(mem, reg);
170 else
171 value = intel_readw(mem, reg);
172
173 return scnprintf(buf + pos, RD_BUF - pos, "%4x\t%4x\n", reg, value);
174}
175
176static int intel_reg_show(struct seq_file *s_file, void *data)
177{
178 struct sdw_intel *sdw = s_file->private;
Pierre-Louis Bossart25234862020-02-14 19:47:36 -0600179 void __iomem *s = sdw->link_res->shim;
180 void __iomem *a = sdw->link_res->alh;
Pierre-Louis Bossart79ee6632019-08-21 13:58:20 -0500181 char *buf;
182 ssize_t ret;
183 int i, j;
184 unsigned int links, reg;
185
186 buf = kzalloc(RD_BUF, GFP_KERNEL);
187 if (!buf)
188 return -ENOMEM;
189
190 links = intel_readl(s, SDW_SHIM_LCAP) & GENMASK(2, 0);
191
192 ret = scnprintf(buf, RD_BUF, "Register Value\n");
193 ret += scnprintf(buf + ret, RD_BUF - ret, "\nShim\n");
194
195 for (i = 0; i < links; i++) {
196 reg = SDW_SHIM_LCAP + i * 4;
197 ret += intel_sprintf(s, true, buf, ret, reg);
198 }
199
200 for (i = 0; i < links; i++) {
201 ret += scnprintf(buf + ret, RD_BUF - ret, "\nLink%d\n", i);
202 ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLSCAP(i));
203 ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLS0CM(i));
204 ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLS1CM(i));
205 ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLS2CM(i));
206 ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLS3CM(i));
207 ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_PCMSCAP(i));
208
209 ret += scnprintf(buf + ret, RD_BUF - ret, "\n PCMSyCH registers\n");
210
211 /*
212 * the value 10 is the number of PDIs. We will need a
213 * cleanup to remove hard-coded Intel configurations
214 * from cadence_master.c
215 */
216 for (j = 0; j < 10; j++) {
217 ret += intel_sprintf(s, false, buf, ret,
218 SDW_SHIM_PCMSYCHM(i, j));
219 ret += intel_sprintf(s, false, buf, ret,
220 SDW_SHIM_PCMSYCHC(i, j));
221 }
222 ret += scnprintf(buf + ret, RD_BUF - ret, "\n PDMSCAP, IOCTL, CTMCTL\n");
223
224 ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_PDMSCAP(i));
225 ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_IOCTL(i));
226 ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTMCTL(i));
227 }
228
229 ret += scnprintf(buf + ret, RD_BUF - ret, "\nWake registers\n");
230 ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_WAKEEN);
231 ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_WAKESTS);
232
233 ret += scnprintf(buf + ret, RD_BUF - ret, "\nALH STRMzCFG\n");
234 for (i = 0; i < SDW_ALH_NUM_STREAMS; i++)
235 ret += intel_sprintf(a, true, buf, ret, SDW_ALH_STRMZCFG(i));
236
237 seq_printf(s_file, "%s", buf);
238 kfree(buf);
239
240 return 0;
241}
242DEFINE_SHOW_ATTRIBUTE(intel_reg);
243
244static void intel_debugfs_init(struct sdw_intel *sdw)
245{
246 struct dentry *root = sdw->cdns.bus.debugfs;
247
248 if (!root)
249 return;
250
251 sdw->debugfs = debugfs_create_dir("intel-sdw", root);
252
253 debugfs_create_file("intel-registers", 0400, sdw->debugfs, sdw,
254 &intel_reg_fops);
255
256 sdw_cdns_debugfs_init(&sdw->cdns, sdw->debugfs);
257}
258
259static void intel_debugfs_exit(struct sdw_intel *sdw)
260{
261 debugfs_remove_recursive(sdw->debugfs);
262}
263#else
264static void intel_debugfs_init(struct sdw_intel *sdw) {}
265static void intel_debugfs_exit(struct sdw_intel *sdw) {}
266#endif /* CONFIG_DEBUG_FS */
267
268/*
Vinod Koul71bb8a12017-12-14 11:19:43 +0530269 * shim ops
270 */
271
272static int intel_link_power_up(struct sdw_intel *sdw)
273{
274 unsigned int link_id = sdw->instance;
Pierre-Louis Bossart25234862020-02-14 19:47:36 -0600275 void __iomem *shim = sdw->link_res->shim;
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +0800276 u32 *shim_mask = sdw->link_res->shim_mask;
277 struct sdw_bus *bus = &sdw->cdns.bus;
278 struct sdw_master_prop *prop = &bus->prop;
Vinod Koul71bb8a12017-12-14 11:19:43 +0530279 int spa_mask, cpa_mask;
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +0800280 int link_control;
281 int ret = 0;
282 u32 syncprd;
283 u32 sync_reg;
284
285 mutex_lock(sdw->link_res->shim_lock);
286
287 /*
288 * The hardware relies on an internal counter, typically 4kHz,
289 * to generate the SoundWire SSP - which defines a 'safe'
290 * synchronization point between commands and audio transport
291 * and allows for multi link synchronization. The SYNCPRD value
292 * is only dependent on the oscillator clock provided to
293 * the IP, so adjust based on _DSD properties reported in DSDT
294 * tables. The values reported are based on either 24MHz
295 * (CNL/CML) or 38.4 MHz (ICL/TGL+).
296 */
297 if (prop->mclk_freq % 6000000)
298 syncprd = SDW_SHIM_SYNC_SYNCPRD_VAL_38_4;
299 else
300 syncprd = SDW_SHIM_SYNC_SYNCPRD_VAL_24;
301
302 if (!*shim_mask) {
303 /* we first need to program the SyncPRD/CPU registers */
304 dev_dbg(sdw->cdns.dev,
305 "%s: first link up, programming SYNCPRD\n", __func__);
306
307 /* set SyncPRD period */
308 sync_reg = intel_readl(shim, SDW_SHIM_SYNC);
309 sync_reg |= (syncprd <<
310 SDW_REG_SHIFT(SDW_SHIM_SYNC_SYNCPRD));
311
312 /* Set SyncCPU bit */
313 sync_reg |= SDW_SHIM_SYNC_SYNCCPU;
314 intel_writel(shim, SDW_SHIM_SYNC, sync_reg);
315 }
Vinod Koul71bb8a12017-12-14 11:19:43 +0530316
317 /* Link power up sequence */
318 link_control = intel_readl(shim, SDW_SHIM_LCTL);
319 spa_mask = (SDW_SHIM_LCTL_SPA << link_id);
320 cpa_mask = (SDW_SHIM_LCTL_CPA << link_id);
321 link_control |= spa_mask;
322
323 ret = intel_set_bit(shim, SDW_SHIM_LCTL, link_control, cpa_mask);
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +0800324 if (ret < 0) {
325 dev_err(sdw->cdns.dev, "Failed to power up link: %d\n", ret);
326 goto out;
327 }
328
329 if (!*shim_mask) {
330 /* SyncCPU will change once link is active */
331 ret = intel_wait_bit(shim, SDW_SHIM_SYNC,
332 SDW_SHIM_SYNC_SYNCCPU, 0);
333 if (ret < 0) {
334 dev_err(sdw->cdns.dev,
335 "Failed to set SHIM_SYNC: %d\n", ret);
336 goto out;
337 }
338 }
339
340 *shim_mask |= BIT(link_id);
Vinod Koul71bb8a12017-12-14 11:19:43 +0530341
342 sdw->cdns.link_up = true;
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +0800343out:
344 mutex_unlock(sdw->link_res->shim_lock);
345
346 return ret;
Vinod Koul71bb8a12017-12-14 11:19:43 +0530347}
348
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +0800349/* this needs to be called with shim_lock */
350static void intel_shim_glue_to_master_ip(struct sdw_intel *sdw)
Vinod Koul71bb8a12017-12-14 11:19:43 +0530351{
Pierre-Louis Bossart25234862020-02-14 19:47:36 -0600352 void __iomem *shim = sdw->link_res->shim;
Vinod Koul71bb8a12017-12-14 11:19:43 +0530353 unsigned int link_id = sdw->instance;
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +0800354 u16 ioctl;
Vinod Koul71bb8a12017-12-14 11:19:43 +0530355
356 /* Switch to MIP from Glue logic */
357 ioctl = intel_readw(shim, SDW_SHIM_IOCTL(link_id));
358
359 ioctl &= ~(SDW_SHIM_IOCTL_DOE);
360 intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl);
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +0800361 usleep_range(10, 15);
Vinod Koul71bb8a12017-12-14 11:19:43 +0530362
363 ioctl &= ~(SDW_SHIM_IOCTL_DO);
364 intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl);
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +0800365 usleep_range(10, 15);
Vinod Koul71bb8a12017-12-14 11:19:43 +0530366
367 ioctl |= (SDW_SHIM_IOCTL_MIF);
368 intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl);
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +0800369 usleep_range(10, 15);
Vinod Koul71bb8a12017-12-14 11:19:43 +0530370
371 ioctl &= ~(SDW_SHIM_IOCTL_BKE);
372 ioctl &= ~(SDW_SHIM_IOCTL_COE);
Vinod Koul71bb8a12017-12-14 11:19:43 +0530373 intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl);
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +0800374 usleep_range(10, 15);
375
376 /* at this point Master IP has full control of the I/Os */
377}
378
379/* this needs to be called with shim_lock */
380static void intel_shim_master_ip_to_glue(struct sdw_intel *sdw)
381{
382 unsigned int link_id = sdw->instance;
383 void __iomem *shim = sdw->link_res->shim;
384 u16 ioctl;
385
386 /* Glue logic */
387 ioctl = intel_readw(shim, SDW_SHIM_IOCTL(link_id));
388 ioctl |= SDW_SHIM_IOCTL_BKE;
389 ioctl |= SDW_SHIM_IOCTL_COE;
390 intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl);
391 usleep_range(10, 15);
392
393 ioctl &= ~(SDW_SHIM_IOCTL_MIF);
394 intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl);
395 usleep_range(10, 15);
396
397 /* at this point Integration Glue has full control of the I/Os */
398}
399
400static int intel_shim_init(struct sdw_intel *sdw, bool clock_stop)
401{
402 void __iomem *shim = sdw->link_res->shim;
403 unsigned int link_id = sdw->instance;
404 int ret = 0;
405 u16 ioctl = 0, act = 0;
406
407 mutex_lock(sdw->link_res->shim_lock);
408
409 /* Initialize Shim */
410 ioctl |= SDW_SHIM_IOCTL_BKE;
411 intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl);
412 usleep_range(10, 15);
413
414 ioctl |= SDW_SHIM_IOCTL_WPDD;
415 intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl);
416 usleep_range(10, 15);
417
418 ioctl |= SDW_SHIM_IOCTL_DO;
419 intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl);
420 usleep_range(10, 15);
421
422 ioctl |= SDW_SHIM_IOCTL_DOE;
423 intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl);
424 usleep_range(10, 15);
425
426 intel_shim_glue_to_master_ip(sdw);
Vinod Koul71bb8a12017-12-14 11:19:43 +0530427
428 act |= 0x1 << SDW_REG_SHIFT(SDW_SHIM_CTMCTL_DOAIS);
429 act |= SDW_SHIM_CTMCTL_DACTQE;
430 act |= SDW_SHIM_CTMCTL_DODS;
431 intel_writew(shim, SDW_SHIM_CTMCTL(link_id), act);
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +0800432 usleep_range(10, 15);
Vinod Koul71bb8a12017-12-14 11:19:43 +0530433
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +0800434 mutex_unlock(sdw->link_res->shim_lock);
Vinod Koul71bb8a12017-12-14 11:19:43 +0530435
436 return ret;
437}
438
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +0800439static void __maybe_unused intel_shim_wake(struct sdw_intel *sdw, bool wake_enable)
440{
441 void __iomem *shim = sdw->link_res->shim;
442 unsigned int link_id = sdw->instance;
443 u16 wake_en, wake_sts;
444
445 mutex_lock(sdw->link_res->shim_lock);
446 wake_en = intel_readw(shim, SDW_SHIM_WAKEEN);
447
448 if (wake_enable) {
449 /* Enable the wakeup */
450 wake_en |= (SDW_SHIM_WAKEEN_ENABLE << link_id);
451 intel_writew(shim, SDW_SHIM_WAKEEN, wake_en);
452 } else {
453 /* Disable the wake up interrupt */
454 wake_en &= ~(SDW_SHIM_WAKEEN_ENABLE << link_id);
455 intel_writew(shim, SDW_SHIM_WAKEEN, wake_en);
456
457 /* Clear wake status */
458 wake_sts = intel_readw(shim, SDW_SHIM_WAKESTS);
459 wake_sts |= (SDW_SHIM_WAKEEN_ENABLE << link_id);
460 intel_writew(shim, SDW_SHIM_WAKESTS_STATUS, wake_sts);
461 }
462 mutex_unlock(sdw->link_res->shim_lock);
463}
464
465static int __maybe_unused intel_link_power_down(struct sdw_intel *sdw)
466{
467 int link_control, spa_mask, cpa_mask;
468 unsigned int link_id = sdw->instance;
469 void __iomem *shim = sdw->link_res->shim;
470 u32 *shim_mask = sdw->link_res->shim_mask;
471 int ret = 0;
472
473 mutex_lock(sdw->link_res->shim_lock);
474
475 intel_shim_master_ip_to_glue(sdw);
476
477 /* Link power down sequence */
478 link_control = intel_readl(shim, SDW_SHIM_LCTL);
479 spa_mask = ~(SDW_SHIM_LCTL_SPA << link_id);
480 cpa_mask = (SDW_SHIM_LCTL_CPA << link_id);
481 link_control &= spa_mask;
482
483 ret = intel_clear_bit(shim, SDW_SHIM_LCTL, link_control, cpa_mask);
484
485 if (!(*shim_mask & BIT(link_id)))
486 dev_err(sdw->cdns.dev,
487 "%s: Unbalanced power-up/down calls\n", __func__);
488
489 *shim_mask &= ~BIT(link_id);
490
491 mutex_unlock(sdw->link_res->shim_lock);
492
493 if (ret < 0)
494 return ret;
495
496 sdw->cdns.link_up = false;
497 return 0;
498}
499
Pierre-Louis Bossart02629e452020-07-16 23:09:41 +0800500static void intel_shim_sync_arm(struct sdw_intel *sdw)
501{
502 void __iomem *shim = sdw->link_res->shim;
503 u32 sync_reg;
504
505 mutex_lock(sdw->link_res->shim_lock);
506
507 /* update SYNC register */
508 sync_reg = intel_readl(shim, SDW_SHIM_SYNC);
509 sync_reg |= (SDW_SHIM_SYNC_CMDSYNC << sdw->instance);
510 intel_writel(shim, SDW_SHIM_SYNC, sync_reg);
511
512 mutex_unlock(sdw->link_res->shim_lock);
513}
514
Pierre-Louis Bossart437e3282020-07-16 23:09:42 +0800515static int intel_shim_sync_go_unlocked(struct sdw_intel *sdw)
516{
517 void __iomem *shim = sdw->link_res->shim;
518 u32 sync_reg;
519 int ret;
520
521 /* Read SYNC register */
522 sync_reg = intel_readl(shim, SDW_SHIM_SYNC);
523
524 /*
525 * Set SyncGO bit to synchronously trigger a bank switch for
526 * all the masters. A write to SYNCGO bit clears CMDSYNC bit for all
527 * the Masters.
528 */
529 sync_reg |= SDW_SHIM_SYNC_SYNCGO;
530
531 ret = intel_clear_bit(shim, SDW_SHIM_SYNC, sync_reg,
532 SDW_SHIM_SYNC_SYNCGO);
533
534 if (ret < 0)
535 dev_err(sdw->cdns.dev, "SyncGO clear failed: %d\n", ret);
536
537 return ret;
538}
539
Vinod Koul37a2d222018-04-26 18:38:58 +0530540/*
541 * PDI routines
542 */
543static void intel_pdi_init(struct sdw_intel *sdw,
Pierre-Louis Bossartd542bc92019-05-01 10:57:38 -0500544 struct sdw_cdns_stream_config *config)
Vinod Koul37a2d222018-04-26 18:38:58 +0530545{
Pierre-Louis Bossart25234862020-02-14 19:47:36 -0600546 void __iomem *shim = sdw->link_res->shim;
Vinod Koul37a2d222018-04-26 18:38:58 +0530547 unsigned int link_id = sdw->instance;
548 int pcm_cap, pdm_cap;
549
550 /* PCM Stream Capability */
551 pcm_cap = intel_readw(shim, SDW_SHIM_PCMSCAP(link_id));
552
553 config->pcm_bd = (pcm_cap & SDW_SHIM_PCMSCAP_BSS) >>
554 SDW_REG_SHIFT(SDW_SHIM_PCMSCAP_BSS);
555 config->pcm_in = (pcm_cap & SDW_SHIM_PCMSCAP_ISS) >>
556 SDW_REG_SHIFT(SDW_SHIM_PCMSCAP_ISS);
557 config->pcm_out = (pcm_cap & SDW_SHIM_PCMSCAP_OSS) >>
558 SDW_REG_SHIFT(SDW_SHIM_PCMSCAP_OSS);
559
Pierre-Louis Bossart121f4362019-05-22 14:47:29 -0500560 dev_dbg(sdw->cdns.dev, "PCM cap bd:%d in:%d out:%d\n",
561 config->pcm_bd, config->pcm_in, config->pcm_out);
562
Vinod Koul37a2d222018-04-26 18:38:58 +0530563 /* PDM Stream Capability */
564 pdm_cap = intel_readw(shim, SDW_SHIM_PDMSCAP(link_id));
565
566 config->pdm_bd = (pdm_cap & SDW_SHIM_PDMSCAP_BSS) >>
567 SDW_REG_SHIFT(SDW_SHIM_PDMSCAP_BSS);
568 config->pdm_in = (pdm_cap & SDW_SHIM_PDMSCAP_ISS) >>
569 SDW_REG_SHIFT(SDW_SHIM_PDMSCAP_ISS);
570 config->pdm_out = (pdm_cap & SDW_SHIM_PDMSCAP_OSS) >>
571 SDW_REG_SHIFT(SDW_SHIM_PDMSCAP_OSS);
Pierre-Louis Bossart121f4362019-05-22 14:47:29 -0500572
573 dev_dbg(sdw->cdns.dev, "PDM cap bd:%d in:%d out:%d\n",
574 config->pdm_bd, config->pdm_in, config->pdm_out);
Vinod Koul37a2d222018-04-26 18:38:58 +0530575}
576
577static int
578intel_pdi_get_ch_cap(struct sdw_intel *sdw, unsigned int pdi_num, bool pcm)
579{
Pierre-Louis Bossart25234862020-02-14 19:47:36 -0600580 void __iomem *shim = sdw->link_res->shim;
Vinod Koul37a2d222018-04-26 18:38:58 +0530581 unsigned int link_id = sdw->instance;
582 int count;
583
584 if (pcm) {
585 count = intel_readw(shim, SDW_SHIM_PCMSYCHC(link_id, pdi_num));
Pierre-Louis Bossart18046332019-08-05 19:55:07 -0500586
587 /*
588 * WORKAROUND: on all existing Intel controllers, pdi
589 * number 2 reports channel count as 1 even though it
590 * supports 8 channels. Performing hardcoding for pdi
591 * number 2.
592 */
593 if (pdi_num == 2)
594 count = 7;
595
Vinod Koul37a2d222018-04-26 18:38:58 +0530596 } else {
597 count = intel_readw(shim, SDW_SHIM_PDMSCAP(link_id));
598 count = ((count & SDW_SHIM_PDMSCAP_CPSS) >>
599 SDW_REG_SHIFT(SDW_SHIM_PDMSCAP_CPSS));
600 }
601
602 /* zero based values for channel count in register */
603 count++;
604
605 return count;
606}
607
608static int intel_pdi_get_ch_update(struct sdw_intel *sdw,
Pierre-Louis Bossartd542bc92019-05-01 10:57:38 -0500609 struct sdw_cdns_pdi *pdi,
610 unsigned int num_pdi,
611 unsigned int *num_ch, bool pcm)
Vinod Koul37a2d222018-04-26 18:38:58 +0530612{
613 int i, ch_count = 0;
614
615 for (i = 0; i < num_pdi; i++) {
616 pdi->ch_count = intel_pdi_get_ch_cap(sdw, pdi->num, pcm);
617 ch_count += pdi->ch_count;
618 pdi++;
619 }
620
621 *num_ch = ch_count;
622 return 0;
623}
624
625static int intel_pdi_stream_ch_update(struct sdw_intel *sdw,
Pierre-Louis Bossartd542bc92019-05-01 10:57:38 -0500626 struct sdw_cdns_streams *stream, bool pcm)
Vinod Koul37a2d222018-04-26 18:38:58 +0530627{
628 intel_pdi_get_ch_update(sdw, stream->bd, stream->num_bd,
Pierre-Louis Bossartd542bc92019-05-01 10:57:38 -0500629 &stream->num_ch_bd, pcm);
Vinod Koul37a2d222018-04-26 18:38:58 +0530630
631 intel_pdi_get_ch_update(sdw, stream->in, stream->num_in,
Pierre-Louis Bossartd542bc92019-05-01 10:57:38 -0500632 &stream->num_ch_in, pcm);
Vinod Koul37a2d222018-04-26 18:38:58 +0530633
634 intel_pdi_get_ch_update(sdw, stream->out, stream->num_out,
Pierre-Louis Bossartd542bc92019-05-01 10:57:38 -0500635 &stream->num_ch_out, pcm);
Vinod Koul37a2d222018-04-26 18:38:58 +0530636
637 return 0;
638}
639
640static int intel_pdi_ch_update(struct sdw_intel *sdw)
641{
642 /* First update PCM streams followed by PDM streams */
643 intel_pdi_stream_ch_update(sdw, &sdw->cdns.pcm, true);
644 intel_pdi_stream_ch_update(sdw, &sdw->cdns.pdm, false);
645
646 return 0;
647}
648
649static void
650intel_pdi_shim_configure(struct sdw_intel *sdw, struct sdw_cdns_pdi *pdi)
651{
Pierre-Louis Bossart25234862020-02-14 19:47:36 -0600652 void __iomem *shim = sdw->link_res->shim;
Vinod Koul37a2d222018-04-26 18:38:58 +0530653 unsigned int link_id = sdw->instance;
654 int pdi_conf = 0;
655
Pierre-Louis Bossartc134f912019-10-22 18:29:48 -0500656 /* the Bulk and PCM streams are not contiguous */
657 pdi->intel_alh_id = (link_id * 16) + pdi->num + 3;
658 if (pdi->num >= 2)
659 pdi->intel_alh_id += 2;
Vinod Koul37a2d222018-04-26 18:38:58 +0530660
661 /*
662 * Program stream parameters to stream SHIM register
663 * This is applicable for PCM stream only.
664 */
665 if (pdi->type != SDW_STREAM_PCM)
666 return;
667
668 if (pdi->dir == SDW_DATA_DIR_RX)
669 pdi_conf |= SDW_SHIM_PCMSYCM_DIR;
670 else
671 pdi_conf &= ~(SDW_SHIM_PCMSYCM_DIR);
672
673 pdi_conf |= (pdi->intel_alh_id <<
674 SDW_REG_SHIFT(SDW_SHIM_PCMSYCM_STREAM));
675 pdi_conf |= (pdi->l_ch_num << SDW_REG_SHIFT(SDW_SHIM_PCMSYCM_LCHN));
676 pdi_conf |= (pdi->h_ch_num << SDW_REG_SHIFT(SDW_SHIM_PCMSYCM_HCHN));
677
678 intel_writew(shim, SDW_SHIM_PCMSYCHM(link_id, pdi->num), pdi_conf);
679}
680
681static void
682intel_pdi_alh_configure(struct sdw_intel *sdw, struct sdw_cdns_pdi *pdi)
683{
Pierre-Louis Bossart25234862020-02-14 19:47:36 -0600684 void __iomem *alh = sdw->link_res->alh;
Vinod Koul37a2d222018-04-26 18:38:58 +0530685 unsigned int link_id = sdw->instance;
686 unsigned int conf;
687
Pierre-Louis Bossartc134f912019-10-22 18:29:48 -0500688 /* the Bulk and PCM streams are not contiguous */
689 pdi->intel_alh_id = (link_id * 16) + pdi->num + 3;
690 if (pdi->num >= 2)
691 pdi->intel_alh_id += 2;
Vinod Koul37a2d222018-04-26 18:38:58 +0530692
693 /* Program Stream config ALH register */
694 conf = intel_readl(alh, SDW_ALH_STRMZCFG(pdi->intel_alh_id));
695
696 conf |= (SDW_ALH_STRMZCFG_DMAT_VAL <<
697 SDW_REG_SHIFT(SDW_ALH_STRMZCFG_DMAT));
698
699 conf |= ((pdi->ch_count - 1) <<
700 SDW_REG_SHIFT(SDW_ALH_STRMZCFG_CHN));
701
702 intel_writel(alh, SDW_ALH_STRMZCFG(pdi->intel_alh_id), conf);
703}
704
Rander Wang4b206d32019-12-11 19:45:02 -0600705static int intel_params_stream(struct sdw_intel *sdw,
Pierre-Louis Bossartd542bc92019-05-01 10:57:38 -0500706 struct snd_pcm_substream *substream,
707 struct snd_soc_dai *dai,
Rander Wang4b206d32019-12-11 19:45:02 -0600708 struct snd_pcm_hw_params *hw_params,
709 int link_id, int alh_stream_id)
Vinod Koulc46302e2018-04-26 18:39:05 +0530710{
Pierre-Louis Bossart25234862020-02-14 19:47:36 -0600711 struct sdw_intel_link_res *res = sdw->link_res;
Rander Wang4b206d32019-12-11 19:45:02 -0600712 struct sdw_intel_stream_params_data params_data;
Pierre-Louis Bossart05c8afe42019-08-05 19:55:06 -0500713
Rander Wang4b206d32019-12-11 19:45:02 -0600714 params_data.substream = substream;
715 params_data.dai = dai;
716 params_data.hw_params = hw_params;
717 params_data.link_id = link_id;
718 params_data.alh_stream_id = alh_stream_id;
Vinod Koulc46302e2018-04-26 18:39:05 +0530719
Rander Wang4b206d32019-12-11 19:45:02 -0600720 if (res->ops && res->ops->params_stream && res->dev)
721 return res->ops->params_stream(res->dev,
722 &params_data);
Vinod Koulc46302e2018-04-26 18:39:05 +0530723 return -EIO;
724}
725
Pierre-Louis Bossarteff346f2020-02-14 19:47:40 -0600726static int intel_free_stream(struct sdw_intel *sdw,
727 struct snd_pcm_substream *substream,
728 struct snd_soc_dai *dai,
729 int link_id)
730{
731 struct sdw_intel_link_res *res = sdw->link_res;
732 struct sdw_intel_stream_free_data free_data;
733
734 free_data.substream = substream;
735 free_data.dai = dai;
736 free_data.link_id = link_id;
737
738 if (res->ops && res->ops->free_stream && res->dev)
739 return res->ops->free_stream(res->dev,
740 &free_data);
741
742 return 0;
743}
744
Vinod Koulc46302e2018-04-26 18:39:05 +0530745/*
Shreyas NC30246e22018-07-27 14:44:17 +0530746 * bank switch routines
747 */
748
749static int intel_pre_bank_switch(struct sdw_bus *bus)
750{
751 struct sdw_cdns *cdns = bus_to_cdns(bus);
752 struct sdw_intel *sdw = cdns_to_intel(cdns);
Shreyas NC30246e22018-07-27 14:44:17 +0530753
754 /* Write to register only for multi-link */
755 if (!bus->multi_link)
756 return 0;
757
Pierre-Louis Bossart02629e452020-07-16 23:09:41 +0800758 intel_shim_sync_arm(sdw);
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +0800759
Shreyas NC30246e22018-07-27 14:44:17 +0530760 return 0;
761}
762
763static int intel_post_bank_switch(struct sdw_bus *bus)
764{
765 struct sdw_cdns *cdns = bus_to_cdns(bus);
766 struct sdw_intel *sdw = cdns_to_intel(cdns);
Pierre-Louis Bossart25234862020-02-14 19:47:36 -0600767 void __iomem *shim = sdw->link_res->shim;
Shreyas NC30246e22018-07-27 14:44:17 +0530768 int sync_reg, ret;
769
770 /* Write to register only for multi-link */
771 if (!bus->multi_link)
772 return 0;
773
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +0800774 mutex_lock(sdw->link_res->shim_lock);
775
Shreyas NC30246e22018-07-27 14:44:17 +0530776 /* Read SYNC register */
777 sync_reg = intel_readl(shim, SDW_SHIM_SYNC);
778
779 /*
780 * post_bank_switch() ops is called from the bus in loop for
781 * all the Masters in the steam with the expectation that
782 * we trigger the bankswitch for the only first Master in the list
783 * and do nothing for the other Masters
784 *
785 * So, set the SYNCGO bit only if CMDSYNC bit is set for any Master.
786 */
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +0800787 if (!(sync_reg & SDW_SHIM_SYNC_CMDSYNC_MASK)) {
788 ret = 0;
789 goto unlock;
790 }
Shreyas NC30246e22018-07-27 14:44:17 +0530791
Pierre-Louis Bossart437e3282020-07-16 23:09:42 +0800792 ret = intel_shim_sync_go_unlocked(sdw);
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +0800793unlock:
794 mutex_unlock(sdw->link_res->shim_lock);
795
Shreyas NC30246e22018-07-27 14:44:17 +0530796 if (ret < 0)
Pierre-Louis Bossart17ed5be2019-05-01 10:57:45 -0500797 dev_err(sdw->cdns.dev, "Post bank switch failed: %d\n", ret);
Shreyas NC30246e22018-07-27 14:44:17 +0530798
799 return ret;
800}
801
802/*
Vinod Koulc46302e2018-04-26 18:39:05 +0530803 * DAI routines
804 */
805
Rander Wang5e7484d2020-02-14 19:47:39 -0600806static int intel_startup(struct snd_pcm_substream *substream,
807 struct snd_soc_dai *dai)
808{
809 /*
810 * TODO: add pm_runtime support here, the startup callback
811 * will make sure the IP is 'active'
812 */
Pierre-Louis Bossartff16d1e2020-07-01 02:43:54 +0800813 return 0;
Rander Wang5e7484d2020-02-14 19:47:39 -0600814}
815
Vinod Koulc46302e2018-04-26 18:39:05 +0530816static int intel_hw_params(struct snd_pcm_substream *substream,
Pierre-Louis Bossartd542bc92019-05-01 10:57:38 -0500817 struct snd_pcm_hw_params *params,
818 struct snd_soc_dai *dai)
Vinod Koulc46302e2018-04-26 18:39:05 +0530819{
820 struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai);
821 struct sdw_intel *sdw = cdns_to_intel(cdns);
822 struct sdw_cdns_dma_data *dma;
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500823 struct sdw_cdns_pdi *pdi;
Vinod Koulc46302e2018-04-26 18:39:05 +0530824 struct sdw_stream_config sconfig;
825 struct sdw_port_config *pconfig;
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500826 int ch, dir;
827 int ret;
Vinod Koulc46302e2018-04-26 18:39:05 +0530828 bool pcm = true;
829
830 dma = snd_soc_dai_get_dma_data(dai, substream);
831 if (!dma)
832 return -EIO;
833
834 ch = params_channels(params);
835 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
836 dir = SDW_DATA_DIR_RX;
837 else
838 dir = SDW_DATA_DIR_TX;
839
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500840 if (dma->stream_type == SDW_STREAM_PDM)
Vinod Koulc46302e2018-04-26 18:39:05 +0530841 pcm = false;
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500842
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500843 if (pcm)
Bard Liao1b53385e2019-09-16 14:23:48 -0500844 pdi = sdw_cdns_alloc_pdi(cdns, &cdns->pcm, ch, dir, dai->id);
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500845 else
Bard Liao1b53385e2019-09-16 14:23:48 -0500846 pdi = sdw_cdns_alloc_pdi(cdns, &cdns->pdm, ch, dir, dai->id);
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500847
848 if (!pdi) {
849 ret = -EINVAL;
850 goto error;
Vinod Koulc46302e2018-04-26 18:39:05 +0530851 }
852
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500853 /* do run-time configurations for SHIM, ALH and PDI/PORT */
854 intel_pdi_shim_configure(sdw, pdi);
855 intel_pdi_alh_configure(sdw, pdi);
856 sdw_cdns_config_stream(cdns, ch, dir, pdi);
Vinod Koulc46302e2018-04-26 18:39:05 +0530857
Vinod Koulc46302e2018-04-26 18:39:05 +0530858
859 /* Inform DSP about PDI stream number */
Rander Wang4b206d32019-12-11 19:45:02 -0600860 ret = intel_params_stream(sdw, substream, dai, params,
861 sdw->instance,
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500862 pdi->intel_alh_id);
863 if (ret)
864 goto error;
Vinod Koulc46302e2018-04-26 18:39:05 +0530865
866 sconfig.direction = dir;
867 sconfig.ch_count = ch;
868 sconfig.frame_rate = params_rate(params);
869 sconfig.type = dma->stream_type;
870
871 if (dma->stream_type == SDW_STREAM_PDM) {
872 sconfig.frame_rate *= 50;
873 sconfig.bps = 1;
874 } else {
875 sconfig.bps = snd_pcm_format_width(params_format(params));
876 }
877
878 /* Port configuration */
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500879 pconfig = kcalloc(1, sizeof(*pconfig), GFP_KERNEL);
Vinod Koulc46302e2018-04-26 18:39:05 +0530880 if (!pconfig) {
881 ret = -ENOMEM;
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500882 goto error;
Vinod Koulc46302e2018-04-26 18:39:05 +0530883 }
884
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500885 pconfig->num = pdi->num;
886 pconfig->ch_mask = (1 << ch) - 1;
Vinod Koulc46302e2018-04-26 18:39:05 +0530887
888 ret = sdw_stream_add_master(&cdns->bus, &sconfig,
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500889 pconfig, 1, dma->stream);
890 if (ret)
Pierre-Louis Bossart17ed5be2019-05-01 10:57:45 -0500891 dev_err(cdns->dev, "add master to stream failed:%d\n", ret);
Vinod Koulc46302e2018-04-26 18:39:05 +0530892
893 kfree(pconfig);
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500894error:
Vinod Koulc46302e2018-04-26 18:39:05 +0530895 return ret;
896}
897
Rander Wang27b198f2020-02-14 19:47:37 -0600898static int intel_prepare(struct snd_pcm_substream *substream,
899 struct snd_soc_dai *dai)
900{
901 struct sdw_cdns_dma_data *dma;
902
903 dma = snd_soc_dai_get_dma_data(dai, substream);
904 if (!dma) {
905 dev_err(dai->dev, "failed to get dma data in %s",
906 __func__);
907 return -EIO;
908 }
909
910 return sdw_prepare_stream(dma->stream);
911}
912
Rander Wang973a8422020-02-14 19:47:38 -0600913static int intel_trigger(struct snd_pcm_substream *substream, int cmd,
914 struct snd_soc_dai *dai)
915{
916 struct sdw_cdns_dma_data *dma;
917 int ret;
918
919 dma = snd_soc_dai_get_dma_data(dai, substream);
920 if (!dma) {
921 dev_err(dai->dev, "failed to get dma data in %s", __func__);
922 return -EIO;
923 }
924
925 switch (cmd) {
926 case SNDRV_PCM_TRIGGER_START:
927 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
928 case SNDRV_PCM_TRIGGER_RESUME:
929 ret = sdw_enable_stream(dma->stream);
930 break;
931
932 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
933 case SNDRV_PCM_TRIGGER_SUSPEND:
934 case SNDRV_PCM_TRIGGER_STOP:
935 ret = sdw_disable_stream(dma->stream);
936 break;
937
938 default:
939 ret = -EINVAL;
940 break;
941 }
942
943 if (ret)
944 dev_err(dai->dev,
945 "%s trigger %d failed: %d",
946 __func__, cmd, ret);
947 return ret;
948}
949
Vinod Koulc46302e2018-04-26 18:39:05 +0530950static int
951intel_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
952{
953 struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai);
Pierre-Louis Bossarteff346f2020-02-14 19:47:40 -0600954 struct sdw_intel *sdw = cdns_to_intel(cdns);
Vinod Koulc46302e2018-04-26 18:39:05 +0530955 struct sdw_cdns_dma_data *dma;
956 int ret;
957
958 dma = snd_soc_dai_get_dma_data(dai, substream);
959 if (!dma)
960 return -EIO;
961
Pierre-Louis Bossarteff346f2020-02-14 19:47:40 -0600962 ret = sdw_deprepare_stream(dma->stream);
963 if (ret) {
964 dev_err(dai->dev, "sdw_deprepare_stream: failed %d", ret);
965 return ret;
966 }
967
Vinod Koulc46302e2018-04-26 18:39:05 +0530968 ret = sdw_stream_remove_master(&cdns->bus, dma->stream);
Pierre-Louis Bossarteff346f2020-02-14 19:47:40 -0600969 if (ret < 0) {
Pierre-Louis Bossart17ed5be2019-05-01 10:57:45 -0500970 dev_err(dai->dev, "remove master from stream %s failed: %d\n",
Pierre-Louis Bossartd542bc92019-05-01 10:57:38 -0500971 dma->stream->name, ret);
Pierre-Louis Bossarteff346f2020-02-14 19:47:40 -0600972 return ret;
973 }
Vinod Koulc46302e2018-04-26 18:39:05 +0530974
Pierre-Louis Bossarteff346f2020-02-14 19:47:40 -0600975 ret = intel_free_stream(sdw, substream, dai, sdw->instance);
976 if (ret < 0) {
977 dev_err(dai->dev, "intel_free_stream: failed %d", ret);
978 return ret;
979 }
980
Pierre-Louis Bossarteff346f2020-02-14 19:47:40 -0600981 return 0;
Vinod Koulc46302e2018-04-26 18:39:05 +0530982}
983
Pierre-Louis Bossart183c7682019-08-05 19:55:22 -0500984static void intel_shutdown(struct snd_pcm_substream *substream,
985 struct snd_soc_dai *dai)
986{
Pierre-Louis Bossart183c7682019-08-05 19:55:22 -0500987
Pierre-Louis Bossart183c7682019-08-05 19:55:22 -0500988}
989
Vinod Koulc46302e2018-04-26 18:39:05 +0530990static int intel_pcm_set_sdw_stream(struct snd_soc_dai *dai,
Pierre-Louis Bossartd542bc92019-05-01 10:57:38 -0500991 void *stream, int direction)
Vinod Koulc46302e2018-04-26 18:39:05 +0530992{
993 return cdns_set_sdw_stream(dai, stream, true, direction);
994}
995
996static int intel_pdm_set_sdw_stream(struct snd_soc_dai *dai,
Pierre-Louis Bossartd542bc92019-05-01 10:57:38 -0500997 void *stream, int direction)
Vinod Koulc46302e2018-04-26 18:39:05 +0530998{
999 return cdns_set_sdw_stream(dai, stream, false, direction);
1000}
1001
Pierre-Louis Bossart09553142020-07-01 02:43:52 +08001002static void *intel_get_sdw_stream(struct snd_soc_dai *dai,
1003 int direction)
1004{
1005 struct sdw_cdns_dma_data *dma;
1006
1007 if (direction == SNDRV_PCM_STREAM_PLAYBACK)
1008 dma = dai->playback_dma_data;
1009 else
1010 dma = dai->capture_dma_data;
1011
1012 if (!dma)
1013 return NULL;
1014
1015 return dma->stream;
1016}
1017
Julia Lawallb1635592018-10-27 15:34:42 +02001018static const struct snd_soc_dai_ops intel_pcm_dai_ops = {
Rander Wang5e7484d2020-02-14 19:47:39 -06001019 .startup = intel_startup,
Vinod Koulc46302e2018-04-26 18:39:05 +05301020 .hw_params = intel_hw_params,
Rander Wang27b198f2020-02-14 19:47:37 -06001021 .prepare = intel_prepare,
Rander Wang973a8422020-02-14 19:47:38 -06001022 .trigger = intel_trigger,
Vinod Koulc46302e2018-04-26 18:39:05 +05301023 .hw_free = intel_hw_free,
Pierre-Louis Bossart183c7682019-08-05 19:55:22 -05001024 .shutdown = intel_shutdown,
Vinod Koulc46302e2018-04-26 18:39:05 +05301025 .set_sdw_stream = intel_pcm_set_sdw_stream,
Pierre-Louis Bossart09553142020-07-01 02:43:52 +08001026 .get_sdw_stream = intel_get_sdw_stream,
Vinod Koulc46302e2018-04-26 18:39:05 +05301027};
1028
Julia Lawallb1635592018-10-27 15:34:42 +02001029static const struct snd_soc_dai_ops intel_pdm_dai_ops = {
Rander Wang5e7484d2020-02-14 19:47:39 -06001030 .startup = intel_startup,
Vinod Koulc46302e2018-04-26 18:39:05 +05301031 .hw_params = intel_hw_params,
Rander Wang27b198f2020-02-14 19:47:37 -06001032 .prepare = intel_prepare,
Rander Wang973a8422020-02-14 19:47:38 -06001033 .trigger = intel_trigger,
Vinod Koulc46302e2018-04-26 18:39:05 +05301034 .hw_free = intel_hw_free,
Pierre-Louis Bossart183c7682019-08-05 19:55:22 -05001035 .shutdown = intel_shutdown,
Vinod Koulc46302e2018-04-26 18:39:05 +05301036 .set_sdw_stream = intel_pdm_set_sdw_stream,
Pierre-Louis Bossart09553142020-07-01 02:43:52 +08001037 .get_sdw_stream = intel_get_sdw_stream,
Vinod Koulc46302e2018-04-26 18:39:05 +05301038};
1039
1040static const struct snd_soc_component_driver dai_component = {
1041 .name = "soundwire",
1042};
1043
1044static int intel_create_dai(struct sdw_cdns *cdns,
Pierre-Louis Bossartd542bc92019-05-01 10:57:38 -05001045 struct snd_soc_dai_driver *dais,
1046 enum intel_pdi_type type,
1047 u32 num, u32 off, u32 max_ch, bool pcm)
Vinod Koulc46302e2018-04-26 18:39:05 +05301048{
1049 int i;
1050
1051 if (num == 0)
1052 return 0;
1053
1054 /* TODO: Read supported rates/formats from hardware */
1055 for (i = off; i < (off + num); i++) {
1056 dais[i].name = kasprintf(GFP_KERNEL, "SDW%d Pin%d",
Pierre-Louis Bossartd542bc92019-05-01 10:57:38 -05001057 cdns->instance, i);
Vinod Koulc46302e2018-04-26 18:39:05 +05301058 if (!dais[i].name)
1059 return -ENOMEM;
1060
1061 if (type == INTEL_PDI_BD || type == INTEL_PDI_OUT) {
Vinod Koulc46302e2018-04-26 18:39:05 +05301062 dais[i].playback.channels_min = 1;
1063 dais[i].playback.channels_max = max_ch;
1064 dais[i].playback.rates = SNDRV_PCM_RATE_48000;
1065 dais[i].playback.formats = SNDRV_PCM_FMTBIT_S16_LE;
1066 }
1067
1068 if (type == INTEL_PDI_BD || type == INTEL_PDI_IN) {
Srinivas Kandagatla39194122019-06-06 12:23:04 +01001069 dais[i].capture.channels_min = 1;
1070 dais[i].capture.channels_max = max_ch;
Vinod Koulc46302e2018-04-26 18:39:05 +05301071 dais[i].capture.rates = SNDRV_PCM_RATE_48000;
1072 dais[i].capture.formats = SNDRV_PCM_FMTBIT_S16_LE;
1073 }
1074
Vinod Koulc46302e2018-04-26 18:39:05 +05301075 if (pcm)
1076 dais[i].ops = &intel_pcm_dai_ops;
1077 else
1078 dais[i].ops = &intel_pdm_dai_ops;
1079 }
1080
1081 return 0;
1082}
1083
1084static int intel_register_dai(struct sdw_intel *sdw)
1085{
1086 struct sdw_cdns *cdns = &sdw->cdns;
1087 struct sdw_cdns_streams *stream;
1088 struct snd_soc_dai_driver *dais;
1089 int num_dai, ret, off = 0;
1090
1091 /* DAIs are created based on total number of PDIs supported */
1092 num_dai = cdns->pcm.num_pdi + cdns->pdm.num_pdi;
1093
1094 dais = devm_kcalloc(cdns->dev, num_dai, sizeof(*dais), GFP_KERNEL);
1095 if (!dais)
1096 return -ENOMEM;
1097
1098 /* Create PCM DAIs */
1099 stream = &cdns->pcm;
1100
Bard Liaocf924962019-09-16 14:23:43 -05001101 ret = intel_create_dai(cdns, dais, INTEL_PDI_IN, cdns->pcm.num_in,
Vinod Koul1215dae2019-05-02 16:29:25 +05301102 off, stream->num_ch_in, true);
Vinod Koulc46302e2018-04-26 18:39:05 +05301103 if (ret)
1104 return ret;
1105
1106 off += cdns->pcm.num_in;
Vinod Koul1215dae2019-05-02 16:29:25 +05301107 ret = intel_create_dai(cdns, dais, INTEL_PDI_OUT, cdns->pcm.num_out,
1108 off, stream->num_ch_out, true);
Vinod Koulc46302e2018-04-26 18:39:05 +05301109 if (ret)
1110 return ret;
1111
1112 off += cdns->pcm.num_out;
Vinod Koul1215dae2019-05-02 16:29:25 +05301113 ret = intel_create_dai(cdns, dais, INTEL_PDI_BD, cdns->pcm.num_bd,
1114 off, stream->num_ch_bd, true);
Vinod Koulc46302e2018-04-26 18:39:05 +05301115 if (ret)
1116 return ret;
1117
1118 /* Create PDM DAIs */
1119 stream = &cdns->pdm;
1120 off += cdns->pcm.num_bd;
Vinod Koul1215dae2019-05-02 16:29:25 +05301121 ret = intel_create_dai(cdns, dais, INTEL_PDI_IN, cdns->pdm.num_in,
1122 off, stream->num_ch_in, false);
Vinod Koulc46302e2018-04-26 18:39:05 +05301123 if (ret)
1124 return ret;
1125
1126 off += cdns->pdm.num_in;
Vinod Koul1215dae2019-05-02 16:29:25 +05301127 ret = intel_create_dai(cdns, dais, INTEL_PDI_OUT, cdns->pdm.num_out,
1128 off, stream->num_ch_out, false);
Vinod Koulc46302e2018-04-26 18:39:05 +05301129 if (ret)
1130 return ret;
1131
Bard Liaocf924962019-09-16 14:23:43 -05001132 off += cdns->pdm.num_out;
Vinod Koul1215dae2019-05-02 16:29:25 +05301133 ret = intel_create_dai(cdns, dais, INTEL_PDI_BD, cdns->pdm.num_bd,
1134 off, stream->num_ch_bd, false);
Vinod Koulc46302e2018-04-26 18:39:05 +05301135 if (ret)
1136 return ret;
1137
1138 return snd_soc_register_component(cdns->dev, &dai_component,
Pierre-Louis Bossartd542bc92019-05-01 10:57:38 -05001139 dais, num_dai);
Vinod Koulc46302e2018-04-26 18:39:05 +05301140}
1141
Pierre-Louis Bossart085f4ac2019-08-05 19:55:16 -05001142static int sdw_master_read_intel_prop(struct sdw_bus *bus)
1143{
1144 struct sdw_master_prop *prop = &bus->prop;
1145 struct fwnode_handle *link;
1146 char name[32];
Pierre-Louis Bossart395713d2019-08-21 13:58:21 -05001147 u32 quirk_mask;
Pierre-Louis Bossart085f4ac2019-08-05 19:55:16 -05001148
1149 /* Find master handle */
1150 snprintf(name, sizeof(name),
1151 "mipi-sdw-link-%d-subproperties", bus->link_id);
1152
1153 link = device_get_named_child_node(bus->dev, name);
1154 if (!link) {
1155 dev_err(bus->dev, "Master node %s not found\n", name);
1156 return -EIO;
1157 }
1158
1159 fwnode_property_read_u32(link,
1160 "intel-sdw-ip-clock",
1161 &prop->mclk_freq);
Pierre-Louis Bossart395713d2019-08-21 13:58:21 -05001162
Bard Liaoa19efb52020-01-13 17:11:29 -06001163 /* the values reported by BIOS are the 2x clock, not the bus clock */
1164 prop->mclk_freq /= 2;
1165
Pierre-Louis Bossart395713d2019-08-21 13:58:21 -05001166 fwnode_property_read_u32(link,
1167 "intel-quirk-mask",
1168 &quirk_mask);
1169
1170 if (quirk_mask & SDW_INTEL_QUIRK_MASK_BUS_DISABLE)
1171 prop->hw_disabled = true;
1172
Pierre-Louis Bossart085f4ac2019-08-05 19:55:16 -05001173 return 0;
1174}
1175
Vinod Koul71bb8a12017-12-14 11:19:43 +05301176static int intel_prop_read(struct sdw_bus *bus)
1177{
1178 /* Initialize with default handler to read all DisCo properties */
1179 sdw_master_read_prop(bus);
1180
Pierre-Louis Bossart085f4ac2019-08-05 19:55:16 -05001181 /* read Intel-specific properties */
1182 sdw_master_read_intel_prop(bus);
1183
Vinod Koul71bb8a12017-12-14 11:19:43 +05301184 return 0;
1185}
1186
Shreyas NCc91605f2018-04-26 18:38:43 +05301187static struct sdw_master_ops sdw_intel_ops = {
1188 .read_prop = sdw_master_read_prop,
1189 .xfer_msg = cdns_xfer_msg,
1190 .xfer_msg_defer = cdns_xfer_msg_defer,
1191 .reset_page_addr = cdns_reset_page_addr,
Vinod Koul07abeff2018-04-26 18:38:48 +05301192 .set_bus_conf = cdns_bus_conf,
Shreyas NC30246e22018-07-27 14:44:17 +05301193 .pre_bank_switch = intel_pre_bank_switch,
1194 .post_bank_switch = intel_post_bank_switch,
Shreyas NCc91605f2018-04-26 18:38:43 +05301195};
1196
Pierre-Louis Bossartdfbe6422019-10-22 18:54:46 -05001197static int intel_init(struct sdw_intel *sdw)
1198{
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +08001199 bool clock_stop;
1200
Pierre-Louis Bossartdfbe6422019-10-22 18:54:46 -05001201 /* Initialize shim and controller */
1202 intel_link_power_up(sdw);
Pierre-Louis Bossart4a17c442020-07-16 23:09:40 +08001203
1204 clock_stop = sdw_cdns_is_clock_stop(&sdw->cdns);
1205
1206 intel_shim_init(sdw, clock_stop);
1207
1208 if (clock_stop)
1209 return 0;
Pierre-Louis Bossartdfbe6422019-10-22 18:54:46 -05001210
Rander Wang7b174f22020-03-17 11:33:14 -05001211 return sdw_cdns_init(&sdw->cdns);
Pierre-Louis Bossartdfbe6422019-10-22 18:54:46 -05001212}
1213
Vinod Koul71bb8a12017-12-14 11:19:43 +05301214/*
1215 * probe and init
1216 */
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001217static int intel_master_probe(struct platform_device *pdev)
Vinod Koul71bb8a12017-12-14 11:19:43 +05301218{
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001219 struct device *dev = &pdev->dev;
Vinod Koul71bb8a12017-12-14 11:19:43 +05301220 struct sdw_intel *sdw;
Pierre-Louis Bossart83e129af2020-06-01 02:20:58 +08001221 struct sdw_cdns *cdns;
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001222 struct sdw_bus *bus;
Vinod Koul71bb8a12017-12-14 11:19:43 +05301223 int ret;
1224
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001225 sdw = devm_kzalloc(dev, sizeof(*sdw), GFP_KERNEL);
Vinod Koul71bb8a12017-12-14 11:19:43 +05301226 if (!sdw)
1227 return -ENOMEM;
1228
Pierre-Louis Bossart83e129af2020-06-01 02:20:58 +08001229 cdns = &sdw->cdns;
1230 bus = &cdns->bus;
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001231
Vinod Koul71bb8a12017-12-14 11:19:43 +05301232 sdw->instance = pdev->id;
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001233 sdw->link_res = dev_get_platdata(dev);
Pierre-Louis Bossart83e129af2020-06-01 02:20:58 +08001234 cdns->dev = dev;
1235 cdns->registers = sdw->link_res->registers;
1236 cdns->instance = sdw->instance;
1237 cdns->msg_count = 0;
1238
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001239 bus->link_id = pdev->id;
Vinod Koul71bb8a12017-12-14 11:19:43 +05301240
Pierre-Louis Bossart83e129af2020-06-01 02:20:58 +08001241 sdw_cdns_probe(cdns);
Vinod Koul71bb8a12017-12-14 11:19:43 +05301242
1243 /* Set property read ops */
Shreyas NCc91605f2018-04-26 18:38:43 +05301244 sdw_intel_ops.read_prop = intel_prop_read;
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001245 bus->ops = &sdw_intel_ops;
Vinod Koul71bb8a12017-12-14 11:19:43 +05301246
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001247 /* set driver data, accessed by snd_soc_dai_get_drvdata() */
Pierre-Louis Bossart83e129af2020-06-01 02:20:58 +08001248 dev_set_drvdata(dev, cdns);
Vinod Koul71bb8a12017-12-14 11:19:43 +05301249
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001250 ret = sdw_bus_master_add(bus, dev, dev->fwnode);
Vinod Koul71bb8a12017-12-14 11:19:43 +05301251 if (ret) {
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001252 dev_err(dev, "sdw_bus_master_add fail: %d\n", ret);
Pierre-Louis Bossart9e3d47f2019-10-22 18:54:47 -05001253 return ret;
Vinod Koul71bb8a12017-12-14 11:19:43 +05301254 }
1255
Pierre-Louis Bossart6d2c6662020-06-01 02:21:02 +08001256 if (bus->prop.hw_disabled)
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001257 dev_info(dev,
1258 "SoundWire master %d is disabled, will be ignored\n",
1259 bus->link_id);
Pierre-Louis Bossart6d2c6662020-06-01 02:21:02 +08001260
1261 /* Acquire IRQ */
1262 ret = request_threaded_irq(sdw->link_res->irq,
1263 sdw_cdns_irq, sdw_cdns_thread,
1264 IRQF_SHARED, KBUILD_MODNAME, cdns);
1265 if (ret < 0) {
1266 dev_err(dev, "unable to grab IRQ %d, disabling device\n",
1267 sdw->link_res->irq);
1268 goto err_init;
1269 }
1270
1271 return 0;
1272
1273err_init:
1274 sdw_bus_master_delete(bus);
1275 return ret;
1276}
1277
1278int intel_master_startup(struct platform_device *pdev)
1279{
1280 struct sdw_cdns_stream_config config;
1281 struct device *dev = &pdev->dev;
1282 struct sdw_cdns *cdns = dev_get_drvdata(dev);
1283 struct sdw_intel *sdw = cdns_to_intel(cdns);
1284 struct sdw_bus *bus = &cdns->bus;
1285 int ret;
1286
1287 if (bus->prop.hw_disabled) {
1288 dev_info(dev,
1289 "SoundWire master %d is disabled, ignoring\n",
1290 sdw->instance);
Pierre-Louis Bossart395713d2019-08-21 13:58:21 -05001291 return 0;
1292 }
1293
Pierre-Louis Bossartdfbe6422019-10-22 18:54:46 -05001294 /* Initialize shim, controller and Cadence IP */
1295 ret = intel_init(sdw);
Vinod Koul71bb8a12017-12-14 11:19:43 +05301296 if (ret)
1297 goto err_init;
1298
Vinod Koul37a2d222018-04-26 18:38:58 +05301299 /* Read the PDI config and initialize cadence PDI */
1300 intel_pdi_init(sdw, &config);
Pierre-Louis Bossart83e129af2020-06-01 02:20:58 +08001301 ret = sdw_cdns_pdi_init(cdns, config);
Vinod Koul71bb8a12017-12-14 11:19:43 +05301302 if (ret)
1303 goto err_init;
1304
Vinod Koul37a2d222018-04-26 18:38:58 +05301305 intel_pdi_ch_update(sdw);
1306
Pierre-Louis Bossart83e129af2020-06-01 02:20:58 +08001307 ret = sdw_cdns_enable_interrupt(cdns, true);
Pierre-Louis Bossart49ea07d2019-10-22 18:54:44 -05001308 if (ret < 0) {
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001309 dev_err(dev, "cannot enable interrupts\n");
Pierre-Louis Bossart49ea07d2019-10-22 18:54:44 -05001310 goto err_init;
1311 }
1312
Pierre-Louis Bossart83e129af2020-06-01 02:20:58 +08001313 ret = sdw_cdns_exit_reset(cdns);
Pierre-Louis Bossart49ea07d2019-10-22 18:54:44 -05001314 if (ret < 0) {
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001315 dev_err(dev, "unable to exit bus reset sequence\n");
Pierre-Louis Bossart9e3d47f2019-10-22 18:54:47 -05001316 goto err_interrupt;
Pierre-Louis Bossart49ea07d2019-10-22 18:54:44 -05001317 }
1318
Vinod Koulc46302e2018-04-26 18:39:05 +05301319 /* Register DAIs */
1320 ret = intel_register_dai(sdw);
1321 if (ret) {
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001322 dev_err(dev, "DAI registration failed: %d\n", ret);
1323 snd_soc_unregister_component(dev);
Pierre-Louis Bossart9e3d47f2019-10-22 18:54:47 -05001324 goto err_interrupt;
Vinod Koulc46302e2018-04-26 18:39:05 +05301325 }
1326
Pierre-Louis Bossart79ee6632019-08-21 13:58:20 -05001327 intel_debugfs_init(sdw);
1328
Vinod Koul71bb8a12017-12-14 11:19:43 +05301329 return 0;
1330
Pierre-Louis Bossart9e3d47f2019-10-22 18:54:47 -05001331err_interrupt:
Pierre-Louis Bossart83e129af2020-06-01 02:20:58 +08001332 sdw_cdns_enable_interrupt(cdns, false);
Vinod Koul71bb8a12017-12-14 11:19:43 +05301333err_init:
Vinod Koul71bb8a12017-12-14 11:19:43 +05301334 return ret;
1335}
1336
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001337static int intel_master_remove(struct platform_device *pdev)
Vinod Koul71bb8a12017-12-14 11:19:43 +05301338{
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001339 struct device *dev = &pdev->dev;
Pierre-Louis Bossart83e129af2020-06-01 02:20:58 +08001340 struct sdw_cdns *cdns = dev_get_drvdata(dev);
1341 struct sdw_intel *sdw = cdns_to_intel(cdns);
1342 struct sdw_bus *bus = &cdns->bus;
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001343
1344 if (!bus->prop.hw_disabled) {
Pierre-Louis Bossart395713d2019-08-21 13:58:21 -05001345 intel_debugfs_exit(sdw);
Pierre-Louis Bossart83e129af2020-06-01 02:20:58 +08001346 sdw_cdns_enable_interrupt(cdns, false);
Pierre-Louis Bossart25234862020-02-14 19:47:36 -06001347 free_irq(sdw->link_res->irq, sdw);
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001348 snd_soc_unregister_component(dev);
Pierre-Louis Bossart395713d2019-08-21 13:58:21 -05001349 }
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001350 sdw_bus_master_delete(bus);
Vinod Koul71bb8a12017-12-14 11:19:43 +05301351
1352 return 0;
1353}
1354
1355static struct platform_driver sdw_intel_drv = {
Pierre-Louis Bossartb6109dd2020-06-01 02:20:57 +08001356 .probe = intel_master_probe,
1357 .remove = intel_master_remove,
Vinod Koul71bb8a12017-12-14 11:19:43 +05301358 .driver = {
Pierre-Louis Bossart6d2c6662020-06-01 02:21:02 +08001359 .name = "intel-sdw",
Vinod Koul71bb8a12017-12-14 11:19:43 +05301360 },
1361};
1362
1363module_platform_driver(sdw_intel_drv);
1364
1365MODULE_LICENSE("Dual BSD/GPL");
Pierre-Louis Bossart6d2c6662020-06-01 02:21:02 +08001366MODULE_ALIAS("platform:intel-sdw");
Vinod Koul71bb8a12017-12-14 11:19:43 +05301367MODULE_DESCRIPTION("Intel Soundwire Master Driver");