1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2 // Copyright(c) 2015-17 Intel Corporation.
5 * Cadence SoundWire Master module
6 * Used by Master driver
9 #include <linux/cleanup.h>
10 #include <linux/delay.h>
11 #include <linux/device.h>
12 #include <linux/debugfs.h>
13 #include <linux/interrupt.h>
15 #include <linux/module.h>
16 #include <linux/mod_devicetable.h>
17 #include <linux/pm_runtime.h>
18 #include <linux/soundwire/sdw_registers.h>
19 #include <linux/soundwire/sdw.h>
20 #include <sound/pcm_params.h>
21 #include <sound/soc.h>
22 #include <linux/workqueue.h>
24 #include "cadence_master.h"
26 static int interrupt_mask
;
27 module_param_named(cnds_mcp_int_mask
, interrupt_mask
, int, 0444);
28 MODULE_PARM_DESC(cdns_mcp_int_mask
, "Cadence MCP IntMask");
30 #define CDNS_MCP_CONFIG 0x0
31 #define CDNS_MCP_CONFIG_BUS_REL BIT(6)
33 #define CDNS_IP_MCP_CONFIG 0x0 /* IP offset added at run-time */
35 #define CDNS_IP_MCP_CONFIG_MCMD_RETRY GENMASK(27, 24)
36 #define CDNS_IP_MCP_CONFIG_MPREQ_DELAY GENMASK(20, 16)
37 #define CDNS_IP_MCP_CONFIG_MMASTER BIT(7)
38 #define CDNS_IP_MCP_CONFIG_SNIFFER BIT(5)
39 #define CDNS_IP_MCP_CONFIG_CMD BIT(3)
40 #define CDNS_IP_MCP_CONFIG_OP GENMASK(2, 0)
41 #define CDNS_IP_MCP_CONFIG_OP_NORMAL 0
43 #define CDNS_MCP_CONTROL 0x4
45 #define CDNS_MCP_CONTROL_CMD_RST BIT(7)
46 #define CDNS_MCP_CONTROL_SOFT_RST BIT(6)
47 #define CDNS_MCP_CONTROL_HW_RST BIT(4)
48 #define CDNS_MCP_CONTROL_CLK_STOP_CLR BIT(2)
50 #define CDNS_IP_MCP_CONTROL 0x4 /* IP offset added at run-time */
52 #define CDNS_IP_MCP_CONTROL_RST_DELAY GENMASK(10, 8)
53 #define CDNS_IP_MCP_CONTROL_SW_RST BIT(5)
54 #define CDNS_IP_MCP_CONTROL_CLK_PAUSE BIT(3)
55 #define CDNS_IP_MCP_CONTROL_CMD_ACCEPT BIT(1)
56 #define CDNS_IP_MCP_CONTROL_BLOCK_WAKEUP BIT(0)
58 #define CDNS_IP_MCP_CMDCTRL 0x8 /* IP offset added at run-time */
60 #define CDNS_IP_MCP_CMDCTRL_INSERT_PARITY_ERR BIT(2)
62 #define CDNS_MCP_SSPSTAT 0xC
63 #define CDNS_MCP_FRAME_SHAPE 0x10
64 #define CDNS_MCP_FRAME_SHAPE_INIT 0x14
65 #define CDNS_MCP_FRAME_SHAPE_COL_MASK GENMASK(2, 0)
66 #define CDNS_MCP_FRAME_SHAPE_ROW_MASK GENMASK(7, 3)
68 #define CDNS_MCP_CONFIG_UPDATE 0x18
69 #define CDNS_MCP_CONFIG_UPDATE_BIT BIT(0)
71 #define CDNS_MCP_PHYCTRL 0x1C
72 #define CDNS_MCP_SSP_CTRL0 0x20
73 #define CDNS_MCP_SSP_CTRL1 0x28
74 #define CDNS_MCP_CLK_CTRL0 0x30
75 #define CDNS_MCP_CLK_CTRL1 0x38
76 #define CDNS_MCP_CLK_MCLKD_MASK GENMASK(7, 0)
78 #define CDNS_MCP_STAT 0x40
80 #define CDNS_MCP_STAT_ACTIVE_BANK BIT(20)
81 #define CDNS_MCP_STAT_CLK_STOP BIT(16)
83 #define CDNS_MCP_INTSTAT 0x44
84 #define CDNS_MCP_INTMASK 0x48
86 #define CDNS_MCP_INT_IRQ BIT(31)
87 #define CDNS_MCP_INT_RESERVED1 GENMASK(30, 17)
88 #define CDNS_MCP_INT_WAKEUP BIT(16)
89 #define CDNS_MCP_INT_SLAVE_RSVD BIT(15)
90 #define CDNS_MCP_INT_SLAVE_ALERT BIT(14)
91 #define CDNS_MCP_INT_SLAVE_ATTACH BIT(13)
92 #define CDNS_MCP_INT_SLAVE_NATTACH BIT(12)
93 #define CDNS_MCP_INT_SLAVE_MASK GENMASK(15, 12)
94 #define CDNS_MCP_INT_DPINT BIT(11)
95 #define CDNS_MCP_INT_CTRL_CLASH BIT(10)
96 #define CDNS_MCP_INT_DATA_CLASH BIT(9)
97 #define CDNS_MCP_INT_PARITY BIT(8)
98 #define CDNS_MCP_INT_CMD_ERR BIT(7)
99 #define CDNS_MCP_INT_RESERVED2 GENMASK(6, 4)
100 #define CDNS_MCP_INT_RX_NE BIT(3)
101 #define CDNS_MCP_INT_RX_WL BIT(2)
102 #define CDNS_MCP_INT_TXE BIT(1)
103 #define CDNS_MCP_INT_TXF BIT(0)
104 #define CDNS_MCP_INT_RESERVED (CDNS_MCP_INT_RESERVED1 | CDNS_MCP_INT_RESERVED2)
106 #define CDNS_MCP_INTSET 0x4C
108 #define CDNS_MCP_SLAVE_STAT 0x50
109 #define CDNS_MCP_SLAVE_STAT_MASK GENMASK(1, 0)
111 #define CDNS_MCP_SLAVE_INTSTAT0 0x54
112 #define CDNS_MCP_SLAVE_INTSTAT1 0x58
113 #define CDNS_MCP_SLAVE_INTSTAT_NPRESENT BIT(0)
114 #define CDNS_MCP_SLAVE_INTSTAT_ATTACHED BIT(1)
115 #define CDNS_MCP_SLAVE_INTSTAT_ALERT BIT(2)
116 #define CDNS_MCP_SLAVE_INTSTAT_RESERVED BIT(3)
117 #define CDNS_MCP_SLAVE_STATUS_BITS GENMASK(3, 0)
118 #define CDNS_MCP_SLAVE_STATUS_NUM 4
120 #define CDNS_MCP_SLAVE_INTMASK0 0x5C
121 #define CDNS_MCP_SLAVE_INTMASK1 0x60
123 #define CDNS_MCP_SLAVE_INTMASK0_MASK GENMASK(31, 0)
124 #define CDNS_MCP_SLAVE_INTMASK1_MASK GENMASK(15, 0)
126 #define CDNS_MCP_PORT_INTSTAT 0x64
127 #define CDNS_MCP_PDI_STAT 0x6C
129 #define CDNS_MCP_FIFOLEVEL 0x78
130 #define CDNS_MCP_FIFOSTAT 0x7C
131 #define CDNS_MCP_RX_FIFO_AVAIL GENMASK(5, 0)
133 #define CDNS_IP_MCP_CMD_BASE 0x80 /* IP offset added at run-time */
134 #define CDNS_IP_MCP_RESP_BASE 0x80 /* IP offset added at run-time */
135 /* FIFO can hold 8 commands */
136 #define CDNS_MCP_CMD_LEN 8
137 #define CDNS_MCP_CMD_WORD_LEN 0x4
139 #define CDNS_MCP_CMD_SSP_TAG BIT(31)
140 #define CDNS_MCP_CMD_COMMAND GENMASK(30, 28)
141 #define CDNS_MCP_CMD_DEV_ADDR GENMASK(27, 24)
142 #define CDNS_MCP_CMD_REG_ADDR GENMASK(23, 8)
143 #define CDNS_MCP_CMD_REG_DATA GENMASK(7, 0)
145 #define CDNS_MCP_CMD_READ 2
146 #define CDNS_MCP_CMD_WRITE 3
148 #define CDNS_MCP_RESP_RDATA GENMASK(15, 8)
149 #define CDNS_MCP_RESP_ACK BIT(0)
150 #define CDNS_MCP_RESP_NACK BIT(1)
152 #define CDNS_DP_SIZE 128
154 #define CDNS_DPN_B0_CONFIG(n) (0x100 + CDNS_DP_SIZE * (n))
155 #define CDNS_DPN_B0_CH_EN(n) (0x104 + CDNS_DP_SIZE * (n))
156 #define CDNS_DPN_B0_SAMPLE_CTRL(n) (0x108 + CDNS_DP_SIZE * (n))
157 #define CDNS_DPN_B0_OFFSET_CTRL(n) (0x10C + CDNS_DP_SIZE * (n))
158 #define CDNS_DPN_B0_HCTRL(n) (0x110 + CDNS_DP_SIZE * (n))
159 #define CDNS_DPN_B0_ASYNC_CTRL(n) (0x114 + CDNS_DP_SIZE * (n))
161 #define CDNS_DPN_B1_CONFIG(n) (0x118 + CDNS_DP_SIZE * (n))
162 #define CDNS_DPN_B1_CH_EN(n) (0x11C + CDNS_DP_SIZE * (n))
163 #define CDNS_DPN_B1_SAMPLE_CTRL(n) (0x120 + CDNS_DP_SIZE * (n))
164 #define CDNS_DPN_B1_OFFSET_CTRL(n) (0x124 + CDNS_DP_SIZE * (n))
165 #define CDNS_DPN_B1_HCTRL(n) (0x128 + CDNS_DP_SIZE * (n))
166 #define CDNS_DPN_B1_ASYNC_CTRL(n) (0x12C + CDNS_DP_SIZE * (n))
168 #define CDNS_DPN_CONFIG_BPM BIT(18)
169 #define CDNS_DPN_CONFIG_BGC GENMASK(17, 16)
170 #define CDNS_DPN_CONFIG_WL GENMASK(12, 8)
171 #define CDNS_DPN_CONFIG_PORT_DAT GENMASK(3, 2)
172 #define CDNS_DPN_CONFIG_PORT_FLOW GENMASK(1, 0)
174 #define CDNS_DPN_SAMPLE_CTRL_SI GENMASK(15, 0)
176 #define CDNS_DPN_OFFSET_CTRL_1 GENMASK(7, 0)
177 #define CDNS_DPN_OFFSET_CTRL_2 GENMASK(15, 8)
179 #define CDNS_DPN_HCTRL_HSTOP GENMASK(3, 0)
180 #define CDNS_DPN_HCTRL_HSTART GENMASK(7, 4)
181 #define CDNS_DPN_HCTRL_LCTRL GENMASK(10, 8)
183 #define CDNS_PORTCTRL 0x130
184 #define CDNS_PORTCTRL_TEST_FAILED BIT(1)
185 #define CDNS_PORTCTRL_DIRN BIT(7)
186 #define CDNS_PORTCTRL_BANK_INVERT BIT(8)
188 #define CDNS_PORT_OFFSET 0x80
190 #define CDNS_PDI_CONFIG(n) (0x1100 + (n) * 16)
192 #define CDNS_PDI_CONFIG_SOFT_RESET BIT(24)
193 #define CDNS_PDI_CONFIG_CHANNEL GENMASK(15, 8)
194 #define CDNS_PDI_CONFIG_PORT GENMASK(4, 0)
196 /* Driver defaults */
197 #define CDNS_TX_TIMEOUT 500
199 #define CDNS_SCP_RX_FIFOLEVEL 0x2
202 * register accessor helpers
204 static inline u32
cdns_readl(struct sdw_cdns
*cdns
, int offset
)
206 return readl(cdns
->registers
+ offset
);
209 static inline void cdns_writel(struct sdw_cdns
*cdns
, int offset
, u32 value
)
211 writel(value
, cdns
->registers
+ offset
);
214 static inline u32
cdns_ip_readl(struct sdw_cdns
*cdns
, int offset
)
216 return cdns_readl(cdns
, cdns
->ip_offset
+ offset
);
219 static inline void cdns_ip_writel(struct sdw_cdns
*cdns
, int offset
, u32 value
)
221 return cdns_writel(cdns
, cdns
->ip_offset
+ offset
, value
);
224 static inline void cdns_updatel(struct sdw_cdns
*cdns
,
225 int offset
, u32 mask
, u32 val
)
229 tmp
= cdns_readl(cdns
, offset
);
230 tmp
= (tmp
& ~mask
) | val
;
231 cdns_writel(cdns
, offset
, tmp
);
234 static inline void cdns_ip_updatel(struct sdw_cdns
*cdns
,
235 int offset
, u32 mask
, u32 val
)
237 cdns_updatel(cdns
, cdns
->ip_offset
+ offset
, mask
, val
);
240 static int cdns_set_wait(struct sdw_cdns
*cdns
, int offset
, u32 mask
, u32 value
)
245 /* Wait for bit to be set */
247 reg_read
= readl(cdns
->registers
+ offset
);
248 if ((reg_read
& mask
) == value
)
252 usleep_range(50, 100);
253 } while (timeout
!= 0);
258 static int cdns_clear_bit(struct sdw_cdns
*cdns
, int offset
, u32 value
)
260 writel(value
, cdns
->registers
+ offset
);
262 /* Wait for bit to be self cleared */
263 return cdns_set_wait(cdns
, offset
, value
, 0);
267 * all changes to the MCP_CONFIG, MCP_CONTROL, MCP_CMDCTRL and MCP_PHYCTRL
268 * need to be confirmed with a write to MCP_CONFIG_UPDATE
270 static int cdns_config_update(struct sdw_cdns
*cdns
)
274 if (sdw_cdns_is_clock_stop(cdns
)) {
275 dev_err(cdns
->dev
, "Cannot program MCP_CONFIG_UPDATE in ClockStopMode\n");
279 ret
= cdns_clear_bit(cdns
, CDNS_MCP_CONFIG_UPDATE
,
280 CDNS_MCP_CONFIG_UPDATE_BIT
);
282 dev_err(cdns
->dev
, "Config update timedout\n");
288 * sdw_cdns_config_update() - Update configurations
289 * @cdns: Cadence instance
291 void sdw_cdns_config_update(struct sdw_cdns
*cdns
)
294 cdns_writel(cdns
, CDNS_MCP_CONFIG_UPDATE
, CDNS_MCP_CONFIG_UPDATE_BIT
);
296 EXPORT_SYMBOL(sdw_cdns_config_update
);
299 * sdw_cdns_config_update_set_wait() - wait until configuration update bit is self-cleared
300 * @cdns: Cadence instance
302 int sdw_cdns_config_update_set_wait(struct sdw_cdns
*cdns
)
304 /* the hardware recommendation is to wait at least 300us */
305 return cdns_set_wait(cdns
, CDNS_MCP_CONFIG_UPDATE
,
306 CDNS_MCP_CONFIG_UPDATE_BIT
, 0);
308 EXPORT_SYMBOL(sdw_cdns_config_update_set_wait
);
313 #ifdef CONFIG_DEBUG_FS
315 #define RD_BUF (2 * PAGE_SIZE)
317 static ssize_t
cdns_sprintf(struct sdw_cdns
*cdns
,
318 char *buf
, size_t pos
, unsigned int reg
)
320 return scnprintf(buf
+ pos
, RD_BUF
- pos
,
321 "%4x\t%8x\n", reg
, cdns_readl(cdns
, reg
));
324 static int cdns_reg_show(struct seq_file
*s
, void *data
)
326 struct sdw_cdns
*cdns
= s
->private;
331 char *buf
__free(kfree
) = kzalloc(RD_BUF
, GFP_KERNEL
);
335 ret
= scnprintf(buf
, RD_BUF
, "Register Value\n");
336 ret
+= scnprintf(buf
+ ret
, RD_BUF
- ret
, "\nMCP Registers\n");
337 /* 8 MCP registers */
338 for (i
= CDNS_MCP_CONFIG
; i
<= CDNS_MCP_PHYCTRL
; i
+= sizeof(u32
))
339 ret
+= cdns_sprintf(cdns
, buf
, ret
, i
);
341 ret
+= scnprintf(buf
+ ret
, RD_BUF
- ret
,
342 "\nStatus & Intr Registers\n");
343 /* 13 Status & Intr registers (offsets 0x70 and 0x74 not defined) */
344 for (i
= CDNS_MCP_STAT
; i
<= CDNS_MCP_FIFOSTAT
; i
+= sizeof(u32
))
345 ret
+= cdns_sprintf(cdns
, buf
, ret
, i
);
347 ret
+= scnprintf(buf
+ ret
, RD_BUF
- ret
,
348 "\nSSP & Clk ctrl Registers\n");
349 ret
+= cdns_sprintf(cdns
, buf
, ret
, CDNS_MCP_SSP_CTRL0
);
350 ret
+= cdns_sprintf(cdns
, buf
, ret
, CDNS_MCP_SSP_CTRL1
);
351 ret
+= cdns_sprintf(cdns
, buf
, ret
, CDNS_MCP_CLK_CTRL0
);
352 ret
+= cdns_sprintf(cdns
, buf
, ret
, CDNS_MCP_CLK_CTRL1
);
354 ret
+= scnprintf(buf
+ ret
, RD_BUF
- ret
,
355 "\nDPn B0 Registers\n");
357 num_ports
= cdns
->num_ports
;
359 for (i
= 0; i
< num_ports
; i
++) {
360 ret
+= scnprintf(buf
+ ret
, RD_BUF
- ret
,
362 for (j
= CDNS_DPN_B0_CONFIG(i
);
363 j
< CDNS_DPN_B0_ASYNC_CTRL(i
); j
+= sizeof(u32
))
364 ret
+= cdns_sprintf(cdns
, buf
, ret
, j
);
367 ret
+= scnprintf(buf
+ ret
, RD_BUF
- ret
,
368 "\nDPn B1 Registers\n");
369 for (i
= 0; i
< num_ports
; i
++) {
370 ret
+= scnprintf(buf
+ ret
, RD_BUF
- ret
,
373 for (j
= CDNS_DPN_B1_CONFIG(i
);
374 j
< CDNS_DPN_B1_ASYNC_CTRL(i
); j
+= sizeof(u32
))
375 ret
+= cdns_sprintf(cdns
, buf
, ret
, j
);
378 ret
+= scnprintf(buf
+ ret
, RD_BUF
- ret
,
379 "\nDPn Control Registers\n");
380 for (i
= 0; i
< num_ports
; i
++)
381 ret
+= cdns_sprintf(cdns
, buf
, ret
,
382 CDNS_PORTCTRL
+ i
* CDNS_PORT_OFFSET
);
384 ret
+= scnprintf(buf
+ ret
, RD_BUF
- ret
,
385 "\nPDIn Config Registers\n");
387 /* number of PDI and ports is interchangeable */
388 for (i
= 0; i
< num_ports
; i
++)
389 ret
+= cdns_sprintf(cdns
, buf
, ret
, CDNS_PDI_CONFIG(i
));
391 seq_printf(s
, "%s", buf
);
395 DEFINE_SHOW_ATTRIBUTE(cdns_reg
);
397 static int cdns_hw_reset(void *data
, u64 value
)
399 struct sdw_cdns
*cdns
= data
;
405 /* Userspace changed the hardware state behind the kernel's back */
406 add_taint(TAINT_USER
, LOCKDEP_STILL_OK
);
408 ret
= sdw_cdns_exit_reset(cdns
);
410 dev_dbg(cdns
->dev
, "link hw_reset done: %d\n", ret
);
415 DEFINE_DEBUGFS_ATTRIBUTE(cdns_hw_reset_fops
, NULL
, cdns_hw_reset
, "%llu\n");
417 static int cdns_parity_error_injection(void *data
, u64 value
)
419 struct sdw_cdns
*cdns
= data
;
429 * Resume Master device. If this results in a bus reset, the
430 * Slave devices will re-attach and be re-enumerated.
432 ret
= pm_runtime_resume_and_get(bus
->dev
);
433 if (ret
< 0 && ret
!= -EACCES
) {
434 dev_err_ratelimited(cdns
->dev
,
435 "pm_runtime_resume_and_get failed in %s, ret %d\n",
441 * wait long enough for Slave(s) to be in steady state. This
442 * does not need to be super precise.
447 * Take the bus lock here to make sure that any bus transactions
448 * will be queued while we inject a parity error on a dummy read
450 mutex_lock(&bus
->bus_lock
);
452 /* program hardware to inject parity error */
453 cdns_ip_updatel(cdns
, CDNS_IP_MCP_CMDCTRL
,
454 CDNS_IP_MCP_CMDCTRL_INSERT_PARITY_ERR
,
455 CDNS_IP_MCP_CMDCTRL_INSERT_PARITY_ERR
);
458 ret
= cdns_clear_bit(cdns
, CDNS_MCP_CONFIG_UPDATE
, CDNS_MCP_CONFIG_UPDATE_BIT
);
462 /* do a broadcast dummy read to avoid bus clashes */
463 ret
= sdw_bread_no_pm_unlocked(&cdns
->bus
, 0xf, SDW_SCP_DEVID_0
);
464 dev_info(cdns
->dev
, "parity error injection, read: %d\n", ret
);
466 /* program hardware to disable parity error */
467 cdns_ip_updatel(cdns
, CDNS_IP_MCP_CMDCTRL
,
468 CDNS_IP_MCP_CMDCTRL_INSERT_PARITY_ERR
,
472 ret
= cdns_clear_bit(cdns
, CDNS_MCP_CONFIG_UPDATE
, CDNS_MCP_CONFIG_UPDATE_BIT
);
476 /* Userspace changed the hardware state behind the kernel's back */
477 add_taint(TAINT_USER
, LOCKDEP_STILL_OK
);
480 /* Continue bus operation with parity error injection disabled */
481 mutex_unlock(&bus
->bus_lock
);
484 * allow Master device to enter pm_runtime suspend. This may
485 * also result in Slave devices suspending.
487 pm_runtime_mark_last_busy(bus
->dev
);
488 pm_runtime_put_autosuspend(bus
->dev
);
493 DEFINE_DEBUGFS_ATTRIBUTE(cdns_parity_error_fops
, NULL
,
494 cdns_parity_error_injection
, "%llu\n");
496 static int cdns_set_pdi_loopback_source(void *data
, u64 value
)
498 struct sdw_cdns
*cdns
= data
;
499 unsigned int pdi_out_num
= cdns
->pcm
.num_bd
+ cdns
->pcm
.num_out
;
501 if (value
> pdi_out_num
)
504 /* Userspace changed the hardware state behind the kernel's back */
505 add_taint(TAINT_USER
, LOCKDEP_STILL_OK
);
507 cdns
->pdi_loopback_source
= value
;
511 DEFINE_DEBUGFS_ATTRIBUTE(cdns_pdi_loopback_source_fops
, NULL
, cdns_set_pdi_loopback_source
, "%llu\n");
513 static int cdns_set_pdi_loopback_target(void *data
, u64 value
)
515 struct sdw_cdns
*cdns
= data
;
516 unsigned int pdi_in_num
= cdns
->pcm
.num_bd
+ cdns
->pcm
.num_in
;
518 if (value
> pdi_in_num
)
521 /* Userspace changed the hardware state behind the kernel's back */
522 add_taint(TAINT_USER
, LOCKDEP_STILL_OK
);
524 cdns
->pdi_loopback_target
= value
;
528 DEFINE_DEBUGFS_ATTRIBUTE(cdns_pdi_loopback_target_fops
, NULL
, cdns_set_pdi_loopback_target
, "%llu\n");
531 * sdw_cdns_debugfs_init() - Cadence debugfs init
532 * @cdns: Cadence instance
533 * @root: debugfs root
535 void sdw_cdns_debugfs_init(struct sdw_cdns
*cdns
, struct dentry
*root
)
537 debugfs_create_file("cdns-registers", 0400, root
, cdns
, &cdns_reg_fops
);
539 debugfs_create_file("cdns-hw-reset", 0200, root
, cdns
,
540 &cdns_hw_reset_fops
);
542 debugfs_create_file("cdns-parity-error-injection", 0200, root
, cdns
,
543 &cdns_parity_error_fops
);
545 cdns
->pdi_loopback_source
= -1;
546 cdns
->pdi_loopback_target
= -1;
548 debugfs_create_file("cdns-pdi-loopback-source", 0200, root
, cdns
,
549 &cdns_pdi_loopback_source_fops
);
551 debugfs_create_file("cdns-pdi-loopback-target", 0200, root
, cdns
,
552 &cdns_pdi_loopback_target_fops
);
555 EXPORT_SYMBOL_GPL(sdw_cdns_debugfs_init
);
557 #endif /* CONFIG_DEBUG_FS */
562 static enum sdw_command_response
563 cdns_fill_msg_resp(struct sdw_cdns
*cdns
,
564 struct sdw_msg
*msg
, int count
, int offset
)
566 int nack
= 0, no_ack
= 0;
569 /* check message response */
570 for (i
= 0; i
< count
; i
++) {
571 if (!(cdns
->response_buf
[i
] & CDNS_MCP_RESP_ACK
)) {
573 dev_vdbg(cdns
->dev
, "Msg Ack not received, cmd %d\n", i
);
575 if (cdns
->response_buf
[i
] & CDNS_MCP_RESP_NACK
) {
577 dev_err_ratelimited(cdns
->dev
, "Msg NACK received, cmd %d\n", i
);
582 dev_err_ratelimited(cdns
->dev
, "Msg NACKed for Slave %d\n", msg
->dev_num
);
587 dev_dbg_ratelimited(cdns
->dev
, "Msg ignored for Slave %d\n", msg
->dev_num
);
588 return SDW_CMD_IGNORED
;
591 if (msg
->flags
== SDW_MSG_FLAG_READ
) {
593 for (i
= 0; i
< count
; i
++)
594 msg
->buf
[i
+ offset
] = FIELD_GET(CDNS_MCP_RESP_RDATA
,
595 cdns
->response_buf
[i
]);
601 static void cdns_read_response(struct sdw_cdns
*cdns
)
603 u32 num_resp
, cmd_base
;
606 /* RX_FIFO_AVAIL can be 2 entries more than the FIFO size */
607 BUILD_BUG_ON(ARRAY_SIZE(cdns
->response_buf
) < CDNS_MCP_CMD_LEN
+ 2);
609 num_resp
= cdns_readl(cdns
, CDNS_MCP_FIFOSTAT
);
610 num_resp
&= CDNS_MCP_RX_FIFO_AVAIL
;
611 if (num_resp
> ARRAY_SIZE(cdns
->response_buf
)) {
612 dev_warn(cdns
->dev
, "RX AVAIL %d too long\n", num_resp
);
613 num_resp
= ARRAY_SIZE(cdns
->response_buf
);
616 cmd_base
= CDNS_IP_MCP_CMD_BASE
;
618 for (i
= 0; i
< num_resp
; i
++) {
619 cdns
->response_buf
[i
] = cdns_ip_readl(cdns
, cmd_base
);
620 cmd_base
+= CDNS_MCP_CMD_WORD_LEN
;
624 static enum sdw_command_response
625 _cdns_xfer_msg(struct sdw_cdns
*cdns
, struct sdw_msg
*msg
, int cmd
,
626 int offset
, int count
, bool defer
)
632 /* Program the watermark level for RX FIFO */
633 if (cdns
->msg_count
!= count
) {
634 cdns_writel(cdns
, CDNS_MCP_FIFOLEVEL
, count
);
635 cdns
->msg_count
= count
;
638 base
= CDNS_IP_MCP_CMD_BASE
;
639 addr
= msg
->addr
+ offset
;
641 for (i
= 0; i
< count
; i
++) {
642 data
= FIELD_PREP(CDNS_MCP_CMD_DEV_ADDR
, msg
->dev_num
);
643 data
|= FIELD_PREP(CDNS_MCP_CMD_COMMAND
, cmd
);
644 data
|= FIELD_PREP(CDNS_MCP_CMD_REG_ADDR
, addr
);
647 if (msg
->flags
== SDW_MSG_FLAG_WRITE
)
648 data
|= msg
->buf
[i
+ offset
];
650 data
|= FIELD_PREP(CDNS_MCP_CMD_SSP_TAG
, msg
->ssp_sync
);
651 cdns_ip_writel(cdns
, base
, data
);
652 base
+= CDNS_MCP_CMD_WORD_LEN
;
658 /* wait for timeout or response */
659 time
= wait_for_completion_timeout(&cdns
->tx_complete
,
660 msecs_to_jiffies(CDNS_TX_TIMEOUT
));
662 dev_err(cdns
->dev
, "IO transfer timed out, cmd %d device %d addr %x len %d\n",
663 cmd
, msg
->dev_num
, msg
->addr
, msg
->len
);
666 /* Drain anything in the RX_FIFO */
667 cdns_read_response(cdns
);
669 return SDW_CMD_TIMEOUT
;
672 return cdns_fill_msg_resp(cdns
, msg
, count
, offset
);
675 static enum sdw_command_response
676 cdns_program_scp_addr(struct sdw_cdns
*cdns
, struct sdw_msg
*msg
)
678 int nack
= 0, no_ack
= 0;
683 /* Program the watermark level for RX FIFO */
684 if (cdns
->msg_count
!= CDNS_SCP_RX_FIFOLEVEL
) {
685 cdns_writel(cdns
, CDNS_MCP_FIFOLEVEL
, CDNS_SCP_RX_FIFOLEVEL
);
686 cdns
->msg_count
= CDNS_SCP_RX_FIFOLEVEL
;
689 data
[0] = FIELD_PREP(CDNS_MCP_CMD_DEV_ADDR
, msg
->dev_num
);
690 data
[0] |= FIELD_PREP(CDNS_MCP_CMD_COMMAND
, 0x3);
693 data
[0] |= FIELD_PREP(CDNS_MCP_CMD_REG_ADDR
, SDW_SCP_ADDRPAGE1
);
694 data
[1] |= FIELD_PREP(CDNS_MCP_CMD_REG_ADDR
, SDW_SCP_ADDRPAGE2
);
696 data
[0] |= msg
->addr_page1
;
697 data
[1] |= msg
->addr_page2
;
699 base
= CDNS_IP_MCP_CMD_BASE
;
700 cdns_ip_writel(cdns
, base
, data
[0]);
701 base
+= CDNS_MCP_CMD_WORD_LEN
;
702 cdns_ip_writel(cdns
, base
, data
[1]);
704 time
= wait_for_completion_timeout(&cdns
->tx_complete
,
705 msecs_to_jiffies(CDNS_TX_TIMEOUT
));
707 dev_err(cdns
->dev
, "SCP Msg trf timed out\n");
709 return SDW_CMD_TIMEOUT
;
712 /* check response the writes */
713 for (i
= 0; i
< 2; i
++) {
714 if (!(cdns
->response_buf
[i
] & CDNS_MCP_RESP_ACK
)) {
716 dev_err(cdns
->dev
, "Program SCP Ack not received\n");
717 if (cdns
->response_buf
[i
] & CDNS_MCP_RESP_NACK
) {
719 dev_err(cdns
->dev
, "Program SCP NACK received\n");
724 /* For NACK, NO ack, don't return err if we are in Broadcast mode */
726 dev_err_ratelimited(cdns
->dev
,
727 "SCP_addrpage NACKed for Slave %d\n", msg
->dev_num
);
732 dev_dbg_ratelimited(cdns
->dev
,
733 "SCP_addrpage ignored for Slave %d\n", msg
->dev_num
);
734 return SDW_CMD_IGNORED
;
740 static int cdns_prep_msg(struct sdw_cdns
*cdns
, struct sdw_msg
*msg
, int *cmd
)
745 ret
= cdns_program_scp_addr(cdns
, msg
);
752 switch (msg
->flags
) {
753 case SDW_MSG_FLAG_READ
:
754 *cmd
= CDNS_MCP_CMD_READ
;
757 case SDW_MSG_FLAG_WRITE
:
758 *cmd
= CDNS_MCP_CMD_WRITE
;
762 dev_err(cdns
->dev
, "Invalid msg cmd: %d\n", msg
->flags
);
769 enum sdw_command_response
770 cdns_xfer_msg(struct sdw_bus
*bus
, struct sdw_msg
*msg
)
772 struct sdw_cdns
*cdns
= bus_to_cdns(bus
);
775 ret
= cdns_prep_msg(cdns
, msg
, &cmd
);
777 return SDW_CMD_FAIL_OTHER
;
779 for (i
= 0; i
< msg
->len
/ CDNS_MCP_CMD_LEN
; i
++) {
780 ret
= _cdns_xfer_msg(cdns
, msg
, cmd
, i
* CDNS_MCP_CMD_LEN
,
781 CDNS_MCP_CMD_LEN
, false);
782 if (ret
!= SDW_CMD_OK
)
786 if (!(msg
->len
% CDNS_MCP_CMD_LEN
))
789 return _cdns_xfer_msg(cdns
, msg
, cmd
, i
* CDNS_MCP_CMD_LEN
,
790 msg
->len
% CDNS_MCP_CMD_LEN
, false);
792 EXPORT_SYMBOL(cdns_xfer_msg
);
794 enum sdw_command_response
795 cdns_xfer_msg_defer(struct sdw_bus
*bus
)
797 struct sdw_cdns
*cdns
= bus_to_cdns(bus
);
798 struct sdw_defer
*defer
= &bus
->defer_msg
;
799 struct sdw_msg
*msg
= defer
->msg
;
802 /* for defer only 1 message is supported */
806 ret
= cdns_prep_msg(cdns
, msg
, &cmd
);
808 return SDW_CMD_FAIL_OTHER
;
810 return _cdns_xfer_msg(cdns
, msg
, cmd
, 0, msg
->len
, true);
812 EXPORT_SYMBOL(cdns_xfer_msg_defer
);
814 u32
cdns_read_ping_status(struct sdw_bus
*bus
)
816 struct sdw_cdns
*cdns
= bus_to_cdns(bus
);
818 return cdns_readl(cdns
, CDNS_MCP_SLAVE_STAT
);
820 EXPORT_SYMBOL(cdns_read_ping_status
);
826 static int cdns_update_slave_status(struct sdw_cdns
*cdns
,
829 enum sdw_slave_status status
[SDW_MAX_DEVICES
+ 1];
830 bool is_slave
= false;
835 memset(status
, 0, sizeof(status
));
837 for (i
= 0; i
<= SDW_MAX_DEVICES
; i
++) {
838 mask
= (slave_intstat
>> (i
* CDNS_MCP_SLAVE_STATUS_NUM
)) &
839 CDNS_MCP_SLAVE_STATUS_BITS
;
846 if (mask
& CDNS_MCP_SLAVE_INTSTAT_RESERVED
) {
847 status
[i
] = SDW_SLAVE_RESERVED
;
851 if (mask
& CDNS_MCP_SLAVE_INTSTAT_ATTACHED
) {
852 status
[i
] = SDW_SLAVE_ATTACHED
;
856 if (mask
& CDNS_MCP_SLAVE_INTSTAT_ALERT
) {
857 status
[i
] = SDW_SLAVE_ALERT
;
861 if (mask
& CDNS_MCP_SLAVE_INTSTAT_NPRESENT
) {
862 status
[i
] = SDW_SLAVE_UNATTACHED
;
868 * check that there was a single reported Slave status and when
869 * there is not use the latest status extracted from PING commands
871 if (set_status
!= 1) {
872 val
= cdns_readl(cdns
, CDNS_MCP_SLAVE_STAT
);
877 status
[i
] = SDW_SLAVE_UNATTACHED
;
880 status
[i
] = SDW_SLAVE_ATTACHED
;
883 status
[i
] = SDW_SLAVE_ALERT
;
887 status
[i
] = SDW_SLAVE_RESERVED
;
896 mutex_lock(&cdns
->status_update_lock
);
897 ret
= sdw_handle_slave_status(&cdns
->bus
, status
);
898 mutex_unlock(&cdns
->status_update_lock
);
906 * sdw_cdns_irq() - Cadence interrupt handler
908 * @dev_id: irq context
910 irqreturn_t
sdw_cdns_irq(int irq
, void *dev_id
)
912 struct sdw_cdns
*cdns
= dev_id
;
915 /* Check if the link is up */
919 int_status
= cdns_readl(cdns
, CDNS_MCP_INTSTAT
);
921 /* check for reserved values read as zero */
922 if (int_status
& CDNS_MCP_INT_RESERVED
)
925 if (!(int_status
& CDNS_MCP_INT_IRQ
))
928 if (int_status
& CDNS_MCP_INT_RX_WL
) {
929 struct sdw_bus
*bus
= &cdns
->bus
;
930 struct sdw_defer
*defer
= &bus
->defer_msg
;
932 cdns_read_response(cdns
);
934 if (defer
&& defer
->msg
) {
935 cdns_fill_msg_resp(cdns
, defer
->msg
,
937 complete(&defer
->complete
);
939 complete(&cdns
->tx_complete
);
943 if (int_status
& CDNS_MCP_INT_PARITY
) {
944 /* Parity error detected by Master */
945 dev_err_ratelimited(cdns
->dev
, "Parity error\n");
948 if (int_status
& CDNS_MCP_INT_CTRL_CLASH
) {
949 /* Slave is driving bit slot during control word */
950 dev_err_ratelimited(cdns
->dev
, "Bus clash for control word\n");
953 if (int_status
& CDNS_MCP_INT_DATA_CLASH
) {
955 * Multiple slaves trying to drive bit slot, or issue with
956 * ownership of data bits or Slave gone bonkers
958 dev_err_ratelimited(cdns
->dev
, "Bus clash for data word\n");
961 if (cdns
->bus
.params
.m_data_mode
!= SDW_PORT_DATA_MODE_NORMAL
&&
962 int_status
& CDNS_MCP_INT_DPINT
) {
965 /* just log which ports report an error */
966 port_intstat
= cdns_readl(cdns
, CDNS_MCP_PORT_INTSTAT
);
967 dev_err_ratelimited(cdns
->dev
, "DP interrupt: PortIntStat %8x\n",
970 /* clear status w/ write1 */
971 cdns_writel(cdns
, CDNS_MCP_PORT_INTSTAT
, port_intstat
);
974 if (int_status
& CDNS_MCP_INT_SLAVE_MASK
) {
975 /* Mask the Slave interrupt and wake thread */
976 cdns_updatel(cdns
, CDNS_MCP_INTMASK
,
977 CDNS_MCP_INT_SLAVE_MASK
, 0);
979 int_status
&= ~CDNS_MCP_INT_SLAVE_MASK
;
982 * Deal with possible race condition between interrupt
983 * handling and disabling interrupts on suspend.
985 * If the master is in the process of disabling
986 * interrupts, don't schedule a workqueue
988 if (cdns
->interrupt_enabled
)
989 schedule_work(&cdns
->work
);
992 cdns_writel(cdns
, CDNS_MCP_INTSTAT
, int_status
);
995 EXPORT_SYMBOL(sdw_cdns_irq
);
997 static void cdns_check_attached_status_dwork(struct work_struct
*work
)
999 struct sdw_cdns
*cdns
=
1000 container_of(work
, struct sdw_cdns
, attach_dwork
.work
);
1001 enum sdw_slave_status status
[SDW_MAX_DEVICES
+ 1];
1006 val
= cdns_readl(cdns
, CDNS_MCP_SLAVE_STAT
);
1008 for (i
= 0; i
<= SDW_MAX_DEVICES
; i
++) {
1009 status
[i
] = val
& 0x3;
1011 dev_dbg(cdns
->dev
, "Peripheral %d status: %d\n", i
, status
[i
]);
1015 mutex_lock(&cdns
->status_update_lock
);
1016 ret
= sdw_handle_slave_status(&cdns
->bus
, status
);
1017 mutex_unlock(&cdns
->status_update_lock
);
1019 dev_err(cdns
->dev
, "%s: sdw_handle_slave_status failed: %d\n", __func__
, ret
);
1023 * cdns_update_slave_status_work - update slave status in a work since we will need to handle
1024 * other interrupts eg. CDNS_MCP_INT_RX_WL during the update slave
1026 * @work: cdns worker thread
1028 static void cdns_update_slave_status_work(struct work_struct
*work
)
1030 struct sdw_cdns
*cdns
=
1031 container_of(work
, struct sdw_cdns
, work
);
1035 int retry_count
= 0;
1038 * Clear main interrupt first so we don't lose any assertions
1039 * that happen during this function.
1041 cdns_writel(cdns
, CDNS_MCP_INTSTAT
, CDNS_MCP_INT_SLAVE_MASK
);
1043 slave0
= cdns_readl(cdns
, CDNS_MCP_SLAVE_INTSTAT0
);
1044 slave1
= cdns_readl(cdns
, CDNS_MCP_SLAVE_INTSTAT1
);
1047 * Clear the bits before handling so we don't lose any
1048 * bits that re-assert.
1050 cdns_writel(cdns
, CDNS_MCP_SLAVE_INTSTAT0
, slave0
);
1051 cdns_writel(cdns
, CDNS_MCP_SLAVE_INTSTAT1
, slave1
);
1053 /* combine the two status */
1054 slave_intstat
= ((u64
)slave1
<< 32) | slave0
;
1056 dev_dbg_ratelimited(cdns
->dev
, "Slave status change: 0x%llx\n", slave_intstat
);
1059 cdns_update_slave_status(cdns
, slave_intstat
);
1062 * When there is more than one peripheral per link, it's
1063 * possible that a deviceB becomes attached after we deal with
1064 * the attachment of deviceA. Since the hardware does a
1065 * logical AND, the attachment of the second device does not
1066 * change the status seen by the driver.
1068 * In that case, clearing the registers above would result in
1069 * the deviceB never being detected - until a change of status
1070 * is observed on the bus.
1072 * To avoid this race condition, re-check if any device0 needs
1073 * attention with PING commands. There is no need to check for
1074 * ALERTS since they are not allowed until a non-zero
1075 * device_number is assigned.
1077 * Do not clear the INTSTAT0/1. While looping to enumerate devices on
1078 * #0 there could be status changes on other devices - these must
1079 * be kept in the INTSTAT so they can be handled when all #0 devices
1080 * have been handled.
1083 device0_status
= cdns_readl(cdns
, CDNS_MCP_SLAVE_STAT
);
1084 device0_status
&= 3;
1086 if (device0_status
== SDW_SLAVE_ATTACHED
) {
1087 if (retry_count
++ < SDW_MAX_DEVICES
) {
1088 dev_dbg_ratelimited(cdns
->dev
,
1089 "Device0 detected after clearing status, iteration %d\n",
1091 slave_intstat
= CDNS_MCP_SLAVE_INTSTAT_ATTACHED
;
1094 dev_err_ratelimited(cdns
->dev
,
1095 "Device0 detected after %d iterations\n",
1100 /* unmask Slave interrupt now */
1101 cdns_updatel(cdns
, CDNS_MCP_INTMASK
,
1102 CDNS_MCP_INT_SLAVE_MASK
, CDNS_MCP_INT_SLAVE_MASK
);
1106 /* paranoia check to make sure self-cleared bits are indeed cleared */
1107 void sdw_cdns_check_self_clearing_bits(struct sdw_cdns
*cdns
, const char *string
,
1108 bool initial_delay
, int reset_iterations
)
1112 u32 mcp_config_update
;
1116 usleep_range(1000, 1500);
1118 ip_mcp_control
= cdns_ip_readl(cdns
, CDNS_IP_MCP_CONTROL
);
1120 /* the following bits should be cleared immediately */
1121 if (ip_mcp_control
& CDNS_IP_MCP_CONTROL_SW_RST
)
1122 dev_err(cdns
->dev
, "%s failed: IP_MCP_CONTROL_SW_RST is not cleared\n", string
);
1124 mcp_control
= cdns_readl(cdns
, CDNS_MCP_CONTROL
);
1126 /* the following bits should be cleared immediately */
1127 if (mcp_control
& CDNS_MCP_CONTROL_CMD_RST
)
1128 dev_err(cdns
->dev
, "%s failed: MCP_CONTROL_CMD_RST is not cleared\n", string
);
1129 if (mcp_control
& CDNS_MCP_CONTROL_SOFT_RST
)
1130 dev_err(cdns
->dev
, "%s failed: MCP_CONTROL_SOFT_RST is not cleared\n", string
);
1131 if (mcp_control
& CDNS_MCP_CONTROL_CLK_STOP_CLR
)
1132 dev_err(cdns
->dev
, "%s failed: MCP_CONTROL_CLK_STOP_CLR is not cleared\n", string
);
1134 mcp_config_update
= cdns_readl(cdns
, CDNS_MCP_CONFIG_UPDATE
);
1135 if (mcp_config_update
& CDNS_MCP_CONFIG_UPDATE_BIT
)
1136 dev_err(cdns
->dev
, "%s failed: MCP_CONFIG_UPDATE_BIT is not cleared\n", string
);
1139 while (mcp_control
& CDNS_MCP_CONTROL_HW_RST
) {
1140 if (i
== reset_iterations
) {
1141 dev_err(cdns
->dev
, "%s failed: MCP_CONTROL_HW_RST is not cleared\n", string
);
1145 dev_dbg(cdns
->dev
, "%s: MCP_CONTROL_HW_RST is not cleared at iteration %d\n", string
, i
);
1148 usleep_range(1000, 1500);
1149 mcp_control
= cdns_readl(cdns
, CDNS_MCP_CONTROL
);
1153 EXPORT_SYMBOL(sdw_cdns_check_self_clearing_bits
);
1160 * sdw_cdns_exit_reset() - Program reset parameters and start bus operations
1161 * @cdns: Cadence instance
1163 int sdw_cdns_exit_reset(struct sdw_cdns
*cdns
)
1165 /* keep reset delay unchanged to 4096 cycles */
1167 /* use hardware generated reset */
1168 cdns_updatel(cdns
, CDNS_MCP_CONTROL
,
1169 CDNS_MCP_CONTROL_HW_RST
,
1170 CDNS_MCP_CONTROL_HW_RST
);
1172 /* commit changes */
1173 return cdns_config_update(cdns
);
1175 EXPORT_SYMBOL(sdw_cdns_exit_reset
);
1178 * cdns_enable_slave_interrupts() - Enable SDW slave interrupts
1179 * @cdns: Cadence instance
1180 * @state: boolean for true/false
1182 static void cdns_enable_slave_interrupts(struct sdw_cdns
*cdns
, bool state
)
1186 mask
= cdns_readl(cdns
, CDNS_MCP_INTMASK
);
1188 mask
|= CDNS_MCP_INT_SLAVE_MASK
;
1190 mask
&= ~CDNS_MCP_INT_SLAVE_MASK
;
1192 cdns_writel(cdns
, CDNS_MCP_INTMASK
, mask
);
1196 * sdw_cdns_enable_interrupt() - Enable SDW interrupts
1197 * @cdns: Cadence instance
1198 * @state: True if we are trying to enable interrupt.
1200 int sdw_cdns_enable_interrupt(struct sdw_cdns
*cdns
, bool state
)
1202 u32 slave_intmask0
= 0;
1203 u32 slave_intmask1
= 0;
1209 slave_intmask0
= CDNS_MCP_SLAVE_INTMASK0_MASK
;
1210 slave_intmask1
= CDNS_MCP_SLAVE_INTMASK1_MASK
;
1212 /* enable detection of all slave state changes */
1213 mask
= CDNS_MCP_INT_SLAVE_MASK
;
1215 /* enable detection of bus issues */
1216 mask
|= CDNS_MCP_INT_CTRL_CLASH
| CDNS_MCP_INT_DATA_CLASH
|
1217 CDNS_MCP_INT_PARITY
;
1219 /* port interrupt limited to test modes for now */
1220 if (cdns
->bus
.params
.m_data_mode
!= SDW_PORT_DATA_MODE_NORMAL
)
1221 mask
|= CDNS_MCP_INT_DPINT
;
1223 /* enable detection of RX fifo level */
1224 mask
|= CDNS_MCP_INT_RX_WL
;
1227 * CDNS_MCP_INT_IRQ needs to be set otherwise all previous
1228 * settings are irrelevant
1230 mask
|= CDNS_MCP_INT_IRQ
;
1232 if (interrupt_mask
) /* parameter override */
1233 mask
= interrupt_mask
;
1236 /* clear slave interrupt status before enabling interrupt */
1240 slave_state
= cdns_readl(cdns
, CDNS_MCP_SLAVE_INTSTAT0
);
1241 cdns_writel(cdns
, CDNS_MCP_SLAVE_INTSTAT0
, slave_state
);
1242 slave_state
= cdns_readl(cdns
, CDNS_MCP_SLAVE_INTSTAT1
);
1243 cdns_writel(cdns
, CDNS_MCP_SLAVE_INTSTAT1
, slave_state
);
1245 cdns
->interrupt_enabled
= state
;
1248 * Complete any on-going status updates before updating masks,
1249 * and cancel queued status updates.
1251 * There could be a race with a new interrupt thrown before
1252 * the 3 mask updates below are complete, so in the interrupt
1253 * we use the 'interrupt_enabled' status to prevent new work
1254 * from being queued.
1257 cancel_work_sync(&cdns
->work
);
1259 cdns_writel(cdns
, CDNS_MCP_SLAVE_INTMASK0
, slave_intmask0
);
1260 cdns_writel(cdns
, CDNS_MCP_SLAVE_INTMASK1
, slave_intmask1
);
1261 cdns_writel(cdns
, CDNS_MCP_INTMASK
, mask
);
1265 EXPORT_SYMBOL(sdw_cdns_enable_interrupt
);
1267 static int cdns_allocate_pdi(struct sdw_cdns
*cdns
,
1268 struct sdw_cdns_pdi
**stream
,
1271 struct sdw_cdns_pdi
*pdi
;
1277 pdi
= devm_kcalloc(cdns
->dev
, num
, sizeof(*pdi
), GFP_KERNEL
);
1281 for (i
= 0; i
< num
; i
++) {
1290 * sdw_cdns_pdi_init() - PDI initialization routine
1292 * @cdns: Cadence instance
1293 * @config: Stream configurations
1295 int sdw_cdns_pdi_init(struct sdw_cdns
*cdns
,
1296 struct sdw_cdns_stream_config config
)
1298 struct sdw_cdns_streams
*stream
;
1301 cdns
->pcm
.num_bd
= config
.pcm_bd
;
1302 cdns
->pcm
.num_in
= config
.pcm_in
;
1303 cdns
->pcm
.num_out
= config
.pcm_out
;
1305 /* Allocate PDIs for PCMs */
1306 stream
= &cdns
->pcm
;
1308 /* we allocate PDI0 and PDI1 which are used for Bulk */
1309 ret
= cdns_allocate_pdi(cdns
, &stream
->bd
, stream
->num_bd
);
1313 ret
= cdns_allocate_pdi(cdns
, &stream
->in
, stream
->num_in
);
1317 ret
= cdns_allocate_pdi(cdns
, &stream
->out
, stream
->num_out
);
1321 /* Update total number of PCM PDIs */
1322 stream
->num_pdi
= stream
->num_bd
+ stream
->num_in
+ stream
->num_out
;
1323 cdns
->num_ports
= stream
->num_pdi
;
1327 EXPORT_SYMBOL(sdw_cdns_pdi_init
);
1329 static u32
cdns_set_initial_frame_shape(int n_rows
, int n_cols
)
1335 r
= sdw_find_row_index(n_rows
);
1336 c
= sdw_find_col_index(n_cols
);
1338 val
= FIELD_PREP(CDNS_MCP_FRAME_SHAPE_ROW_MASK
, r
);
1339 val
|= FIELD_PREP(CDNS_MCP_FRAME_SHAPE_COL_MASK
, c
);
1344 static void cdns_init_clock_ctrl(struct sdw_cdns
*cdns
)
1346 struct sdw_bus
*bus
= &cdns
->bus
;
1347 struct sdw_master_prop
*prop
= &bus
->prop
;
1352 dev_dbg(cdns
->dev
, "mclk %d max %d row %d col %d\n",
1358 /* Set clock divider */
1359 divider
= (prop
->mclk_freq
/ prop
->max_clk_freq
) - 1;
1361 cdns_updatel(cdns
, CDNS_MCP_CLK_CTRL0
,
1362 CDNS_MCP_CLK_MCLKD_MASK
, divider
);
1363 cdns_updatel(cdns
, CDNS_MCP_CLK_CTRL1
,
1364 CDNS_MCP_CLK_MCLKD_MASK
, divider
);
1367 * Frame shape changes after initialization have to be done
1368 * with the bank switch mechanism
1370 val
= cdns_set_initial_frame_shape(prop
->default_row
,
1372 cdns_writel(cdns
, CDNS_MCP_FRAME_SHAPE_INIT
, val
);
1374 /* Set SSP interval to default value */
1375 ssp_interval
= prop
->default_frame_rate
/ SDW_CADENCE_GSYNC_HZ
;
1376 cdns_writel(cdns
, CDNS_MCP_SSP_CTRL0
, ssp_interval
);
1377 cdns_writel(cdns
, CDNS_MCP_SSP_CTRL1
, ssp_interval
);
1381 * sdw_cdns_soft_reset() - Cadence soft-reset
1382 * @cdns: Cadence instance
1384 int sdw_cdns_soft_reset(struct sdw_cdns
*cdns
)
1388 cdns_updatel(cdns
, CDNS_MCP_CONTROL
, CDNS_MCP_CONTROL_SOFT_RST
,
1389 CDNS_MCP_CONTROL_SOFT_RST
);
1391 ret
= cdns_config_update(cdns
);
1393 dev_err(cdns
->dev
, "%s: config update failed\n", __func__
);
1397 ret
= cdns_set_wait(cdns
, CDNS_MCP_CONTROL
, CDNS_MCP_CONTROL_SOFT_RST
, 0);
1399 dev_err(cdns
->dev
, "%s: Soft Reset timed out\n", __func__
);
1403 EXPORT_SYMBOL(sdw_cdns_soft_reset
);
1406 * sdw_cdns_init() - Cadence initialization
1407 * @cdns: Cadence instance
1409 int sdw_cdns_init(struct sdw_cdns
*cdns
)
1413 cdns_init_clock_ctrl(cdns
);
1415 sdw_cdns_check_self_clearing_bits(cdns
, __func__
, false, 0);
1417 /* reset msg_count to default value of FIFOLEVEL */
1418 cdns
->msg_count
= cdns_readl(cdns
, CDNS_MCP_FIFOLEVEL
);
1420 /* flush command FIFOs */
1421 cdns_updatel(cdns
, CDNS_MCP_CONTROL
, CDNS_MCP_CONTROL_CMD_RST
,
1422 CDNS_MCP_CONTROL_CMD_RST
);
1424 /* Set cmd accept mode */
1425 cdns_ip_updatel(cdns
, CDNS_IP_MCP_CONTROL
, CDNS_IP_MCP_CONTROL_CMD_ACCEPT
,
1426 CDNS_IP_MCP_CONTROL_CMD_ACCEPT
);
1428 /* disable wakeup */
1429 cdns_ip_updatel(cdns
, CDNS_IP_MCP_CONTROL
,
1430 CDNS_IP_MCP_CONTROL_BLOCK_WAKEUP
,
1433 /* Configure mcp config */
1434 val
= cdns_readl(cdns
, CDNS_MCP_CONFIG
);
1436 /* Disable auto bus release */
1437 val
&= ~CDNS_MCP_CONFIG_BUS_REL
;
1439 cdns_writel(cdns
, CDNS_MCP_CONFIG
, val
);
1441 /* Configure IP mcp config */
1442 val
= cdns_ip_readl(cdns
, CDNS_IP_MCP_CONFIG
);
1444 /* enable bus operations with clock and data */
1445 val
&= ~CDNS_IP_MCP_CONFIG_OP
;
1446 val
|= CDNS_IP_MCP_CONFIG_OP_NORMAL
;
1448 /* Set cmd mode for Tx and Rx cmds */
1449 val
&= ~CDNS_IP_MCP_CONFIG_CMD
;
1451 /* Disable sniffer mode */
1452 val
&= ~CDNS_IP_MCP_CONFIG_SNIFFER
;
1454 if (cdns
->bus
.multi_link
)
1455 /* Set Multi-master mode to take gsync into account */
1456 val
|= CDNS_IP_MCP_CONFIG_MMASTER
;
1458 /* leave frame delay to hardware default of 0x1F */
1460 /* leave command retry to hardware default of 0 */
1462 cdns_ip_writel(cdns
, CDNS_IP_MCP_CONFIG
, val
);
1464 /* changes will be committed later */
1467 EXPORT_SYMBOL(sdw_cdns_init
);
1469 int cdns_bus_conf(struct sdw_bus
*bus
, struct sdw_bus_params
*params
)
1471 struct sdw_master_prop
*prop
= &bus
->prop
;
1472 struct sdw_cdns
*cdns
= bus_to_cdns(bus
);
1473 int mcp_clkctrl_off
;
1476 if (!params
->curr_dr_freq
) {
1477 dev_err(cdns
->dev
, "NULL curr_dr_freq\n");
1481 divider
= prop
->mclk_freq
* SDW_DOUBLE_RATE_FACTOR
/
1482 params
->curr_dr_freq
;
1483 divider
--; /* divider is 1/(N+1) */
1485 if (params
->next_bank
)
1486 mcp_clkctrl_off
= CDNS_MCP_CLK_CTRL1
;
1488 mcp_clkctrl_off
= CDNS_MCP_CLK_CTRL0
;
1490 cdns_updatel(cdns
, mcp_clkctrl_off
, CDNS_MCP_CLK_MCLKD_MASK
, divider
);
1494 EXPORT_SYMBOL(cdns_bus_conf
);
1496 static int cdns_port_params(struct sdw_bus
*bus
,
1497 struct sdw_port_params
*p_params
, unsigned int bank
)
1499 struct sdw_cdns
*cdns
= bus_to_cdns(bus
);
1500 int dpn_config_off_source
;
1501 int dpn_config_off_target
;
1502 int target_num
= p_params
->num
;
1503 int source_num
= p_params
->num
;
1504 bool override
= false;
1507 if (target_num
== cdns
->pdi_loopback_target
&&
1508 cdns
->pdi_loopback_source
!= -1) {
1509 source_num
= cdns
->pdi_loopback_source
;
1514 dpn_config_off_source
= CDNS_DPN_B1_CONFIG(source_num
);
1515 dpn_config_off_target
= CDNS_DPN_B1_CONFIG(target_num
);
1517 dpn_config_off_source
= CDNS_DPN_B0_CONFIG(source_num
);
1518 dpn_config_off_target
= CDNS_DPN_B0_CONFIG(target_num
);
1521 dpn_config
= cdns_readl(cdns
, dpn_config_off_source
);
1523 /* use port params if there is no loopback, otherwise use source as is */
1525 u32p_replace_bits(&dpn_config
, p_params
->bps
- 1, CDNS_DPN_CONFIG_WL
);
1526 u32p_replace_bits(&dpn_config
, p_params
->flow_mode
, CDNS_DPN_CONFIG_PORT_FLOW
);
1527 u32p_replace_bits(&dpn_config
, p_params
->data_mode
, CDNS_DPN_CONFIG_PORT_DAT
);
1530 cdns_writel(cdns
, dpn_config_off_target
, dpn_config
);
1535 static int cdns_transport_params(struct sdw_bus
*bus
,
1536 struct sdw_transport_params
*t_params
,
1537 enum sdw_reg_bank bank
)
1539 struct sdw_cdns
*cdns
= bus_to_cdns(bus
);
1541 int dpn_config_off_source
;
1542 int dpn_config_off_target
;
1544 int dpn_hctrl_off_source
;
1545 int dpn_hctrl_off_target
;
1547 int dpn_offsetctrl_off_source
;
1548 int dpn_offsetctrl_off_target
;
1550 int dpn_samplectrl_off_source
;
1551 int dpn_samplectrl_off_target
;
1552 int source_num
= t_params
->port_num
;
1553 int target_num
= t_params
->port_num
;
1554 bool override
= false;
1556 if (target_num
== cdns
->pdi_loopback_target
&&
1557 cdns
->pdi_loopback_source
!= -1) {
1558 source_num
= cdns
->pdi_loopback_source
;
1563 * Note: Only full data port is supported on the Master side for
1564 * both PCM and PDM ports.
1568 dpn_config_off_source
= CDNS_DPN_B1_CONFIG(source_num
);
1569 dpn_hctrl_off_source
= CDNS_DPN_B1_HCTRL(source_num
);
1570 dpn_offsetctrl_off_source
= CDNS_DPN_B1_OFFSET_CTRL(source_num
);
1571 dpn_samplectrl_off_source
= CDNS_DPN_B1_SAMPLE_CTRL(source_num
);
1573 dpn_config_off_target
= CDNS_DPN_B1_CONFIG(target_num
);
1574 dpn_hctrl_off_target
= CDNS_DPN_B1_HCTRL(target_num
);
1575 dpn_offsetctrl_off_target
= CDNS_DPN_B1_OFFSET_CTRL(target_num
);
1576 dpn_samplectrl_off_target
= CDNS_DPN_B1_SAMPLE_CTRL(target_num
);
1579 dpn_config_off_source
= CDNS_DPN_B0_CONFIG(source_num
);
1580 dpn_hctrl_off_source
= CDNS_DPN_B0_HCTRL(source_num
);
1581 dpn_offsetctrl_off_source
= CDNS_DPN_B0_OFFSET_CTRL(source_num
);
1582 dpn_samplectrl_off_source
= CDNS_DPN_B0_SAMPLE_CTRL(source_num
);
1584 dpn_config_off_target
= CDNS_DPN_B0_CONFIG(target_num
);
1585 dpn_hctrl_off_target
= CDNS_DPN_B0_HCTRL(target_num
);
1586 dpn_offsetctrl_off_target
= CDNS_DPN_B0_OFFSET_CTRL(target_num
);
1587 dpn_samplectrl_off_target
= CDNS_DPN_B0_SAMPLE_CTRL(target_num
);
1590 dpn_config
= cdns_readl(cdns
, dpn_config_off_source
);
1592 u32p_replace_bits(&dpn_config
, t_params
->blk_grp_ctrl
, CDNS_DPN_CONFIG_BGC
);
1593 u32p_replace_bits(&dpn_config
, t_params
->blk_pkg_mode
, CDNS_DPN_CONFIG_BPM
);
1595 cdns_writel(cdns
, dpn_config_off_target
, dpn_config
);
1599 u32p_replace_bits(&dpn_offsetctrl
, t_params
->offset1
, CDNS_DPN_OFFSET_CTRL_1
);
1600 u32p_replace_bits(&dpn_offsetctrl
, t_params
->offset2
, CDNS_DPN_OFFSET_CTRL_2
);
1602 dpn_offsetctrl
= cdns_readl(cdns
, dpn_offsetctrl_off_source
);
1604 cdns_writel(cdns
, dpn_offsetctrl_off_target
, dpn_offsetctrl
);
1608 u32p_replace_bits(&dpn_hctrl
, t_params
->hstart
, CDNS_DPN_HCTRL_HSTART
);
1609 u32p_replace_bits(&dpn_hctrl
, t_params
->hstop
, CDNS_DPN_HCTRL_HSTOP
);
1610 u32p_replace_bits(&dpn_hctrl
, t_params
->lane_ctrl
, CDNS_DPN_HCTRL_LCTRL
);
1612 dpn_hctrl
= cdns_readl(cdns
, dpn_hctrl_off_source
);
1614 cdns_writel(cdns
, dpn_hctrl_off_target
, dpn_hctrl
);
1617 dpn_samplectrl
= t_params
->sample_interval
- 1;
1619 dpn_samplectrl
= cdns_readl(cdns
, dpn_samplectrl_off_source
);
1620 cdns_writel(cdns
, dpn_samplectrl_off_target
, dpn_samplectrl
);
1625 static int cdns_port_enable(struct sdw_bus
*bus
,
1626 struct sdw_enable_ch
*enable_ch
, unsigned int bank
)
1628 struct sdw_cdns
*cdns
= bus_to_cdns(bus
);
1629 int dpn_chnen_off
, ch_mask
;
1632 dpn_chnen_off
= CDNS_DPN_B1_CH_EN(enable_ch
->port_num
);
1634 dpn_chnen_off
= CDNS_DPN_B0_CH_EN(enable_ch
->port_num
);
1636 ch_mask
= enable_ch
->ch_mask
* enable_ch
->enable
;
1637 cdns_writel(cdns
, dpn_chnen_off
, ch_mask
);
1642 static const struct sdw_master_port_ops cdns_port_ops
= {
1643 .dpn_set_port_params
= cdns_port_params
,
1644 .dpn_set_port_transport_params
= cdns_transport_params
,
1645 .dpn_port_enable_ch
= cdns_port_enable
,
1649 * sdw_cdns_is_clock_stop: Check clock status
1651 * @cdns: Cadence instance
1653 bool sdw_cdns_is_clock_stop(struct sdw_cdns
*cdns
)
1655 return !!(cdns_readl(cdns
, CDNS_MCP_STAT
) & CDNS_MCP_STAT_CLK_STOP
);
1657 EXPORT_SYMBOL(sdw_cdns_is_clock_stop
);
1660 * sdw_cdns_clock_stop: Cadence clock stop configuration routine
1662 * @cdns: Cadence instance
1663 * @block_wake: prevent wakes if required by the platform
1665 int sdw_cdns_clock_stop(struct sdw_cdns
*cdns
, bool block_wake
)
1667 bool slave_present
= false;
1668 struct sdw_slave
*slave
;
1671 sdw_cdns_check_self_clearing_bits(cdns
, __func__
, false, 0);
1673 /* Check suspend status */
1674 if (sdw_cdns_is_clock_stop(cdns
)) {
1675 dev_dbg(cdns
->dev
, "Clock is already stopped\n");
1680 * Before entering clock stop we mask the Slave
1681 * interrupts. This helps avoid having to deal with e.g. a
1682 * Slave becoming UNATTACHED while the clock is being stopped
1684 cdns_enable_slave_interrupts(cdns
, false);
1687 * For specific platforms, it is required to be able to put
1688 * master into a state in which it ignores wake-up trials
1689 * in clock stop state
1692 cdns_ip_updatel(cdns
, CDNS_IP_MCP_CONTROL
,
1693 CDNS_IP_MCP_CONTROL_BLOCK_WAKEUP
,
1694 CDNS_IP_MCP_CONTROL_BLOCK_WAKEUP
);
1696 list_for_each_entry(slave
, &cdns
->bus
.slaves
, node
) {
1697 if (slave
->status
== SDW_SLAVE_ATTACHED
||
1698 slave
->status
== SDW_SLAVE_ALERT
) {
1699 slave_present
= true;
1704 /* commit changes */
1705 ret
= cdns_config_update(cdns
);
1707 dev_err(cdns
->dev
, "%s: config_update failed\n", __func__
);
1711 /* Prepare slaves for clock stop */
1712 if (slave_present
) {
1713 ret
= sdw_bus_prep_clk_stop(&cdns
->bus
);
1714 if (ret
< 0 && ret
!= -ENODATA
) {
1715 dev_err(cdns
->dev
, "prepare clock stop failed %d\n", ret
);
1721 * Enter clock stop mode and only report errors if there are
1722 * Slave devices present (ALERT or ATTACHED)
1724 ret
= sdw_bus_clk_stop(&cdns
->bus
);
1725 if (ret
< 0 && slave_present
&& ret
!= -ENODATA
) {
1726 dev_err(cdns
->dev
, "bus clock stop failed %d\n", ret
);
1730 ret
= cdns_set_wait(cdns
, CDNS_MCP_STAT
,
1731 CDNS_MCP_STAT_CLK_STOP
,
1732 CDNS_MCP_STAT_CLK_STOP
);
1734 dev_err(cdns
->dev
, "Clock stop failed %d\n", ret
);
1738 EXPORT_SYMBOL(sdw_cdns_clock_stop
);
1741 * sdw_cdns_clock_restart: Cadence PM clock restart configuration routine
1743 * @cdns: Cadence instance
1744 * @bus_reset: context may be lost while in low power modes and the bus
1745 * may require a Severe Reset and re-enumeration after a wake.
1747 int sdw_cdns_clock_restart(struct sdw_cdns
*cdns
, bool bus_reset
)
1751 /* unmask Slave interrupts that were masked when stopping the clock */
1752 cdns_enable_slave_interrupts(cdns
, true);
1754 ret
= cdns_clear_bit(cdns
, CDNS_MCP_CONTROL
,
1755 CDNS_MCP_CONTROL_CLK_STOP_CLR
);
1757 dev_err(cdns
->dev
, "Couldn't exit from clock stop\n");
1761 ret
= cdns_set_wait(cdns
, CDNS_MCP_STAT
, CDNS_MCP_STAT_CLK_STOP
, 0);
1763 dev_err(cdns
->dev
, "clock stop exit failed %d\n", ret
);
1767 cdns_ip_updatel(cdns
, CDNS_IP_MCP_CONTROL
,
1768 CDNS_IP_MCP_CONTROL_BLOCK_WAKEUP
, 0);
1770 cdns_ip_updatel(cdns
, CDNS_IP_MCP_CONTROL
, CDNS_IP_MCP_CONTROL_CMD_ACCEPT
,
1771 CDNS_IP_MCP_CONTROL_CMD_ACCEPT
);
1775 /* enable bus operations with clock and data */
1776 cdns_ip_updatel(cdns
, CDNS_IP_MCP_CONFIG
,
1777 CDNS_IP_MCP_CONFIG_OP
,
1778 CDNS_IP_MCP_CONFIG_OP_NORMAL
);
1780 ret
= cdns_config_update(cdns
);
1782 dev_err(cdns
->dev
, "%s: config_update failed\n", __func__
);
1786 ret
= sdw_bus_exit_clk_stop(&cdns
->bus
);
1788 dev_err(cdns
->dev
, "bus failed to exit clock stop %d\n", ret
);
1793 EXPORT_SYMBOL(sdw_cdns_clock_restart
);
1796 * sdw_cdns_probe() - Cadence probe routine
1797 * @cdns: Cadence instance
1799 int sdw_cdns_probe(struct sdw_cdns
*cdns
)
1801 init_completion(&cdns
->tx_complete
);
1802 cdns
->bus
.port_ops
= &cdns_port_ops
;
1804 mutex_init(&cdns
->status_update_lock
);
1806 INIT_WORK(&cdns
->work
, cdns_update_slave_status_work
);
1807 INIT_DELAYED_WORK(&cdns
->attach_dwork
, cdns_check_attached_status_dwork
);
1811 EXPORT_SYMBOL(sdw_cdns_probe
);
1813 int cdns_set_sdw_stream(struct snd_soc_dai
*dai
,
1814 void *stream
, int direction
)
1816 struct sdw_cdns
*cdns
= snd_soc_dai_get_drvdata(dai
);
1817 struct sdw_cdns_dai_runtime
*dai_runtime
;
1819 dai_runtime
= cdns
->dai_runtime_array
[dai
->id
];
1822 /* first paranoia check */
1825 "dai_runtime already allocated for dai %s\n",
1830 /* allocate and set dai_runtime info */
1831 dai_runtime
= kzalloc(sizeof(*dai_runtime
), GFP_KERNEL
);
1835 dai_runtime
->stream_type
= SDW_STREAM_PCM
;
1837 dai_runtime
->bus
= &cdns
->bus
;
1838 dai_runtime
->link_id
= cdns
->instance
;
1840 dai_runtime
->stream
= stream
;
1841 dai_runtime
->direction
= direction
;
1843 cdns
->dai_runtime_array
[dai
->id
] = dai_runtime
;
1845 /* second paranoia check */
1848 "dai_runtime not allocated for dai %s\n",
1853 /* for NULL stream we release allocated dai_runtime */
1855 cdns
->dai_runtime_array
[dai
->id
] = NULL
;
1859 EXPORT_SYMBOL(cdns_set_sdw_stream
);
1862 * cdns_find_pdi() - Find a free PDI
1864 * @cdns: Cadence instance
1865 * @num: Number of PDIs
1866 * @pdi: PDI instances
1869 * Find a PDI for a given PDI array. The PDI num and dai_id are
1870 * expected to match, return NULL otherwise.
1872 static struct sdw_cdns_pdi
*cdns_find_pdi(struct sdw_cdns
*cdns
,
1874 struct sdw_cdns_pdi
*pdi
,
1879 for (i
= 0; i
< num
; i
++)
1880 if (pdi
[i
].num
== dai_id
)
1887 * sdw_cdns_config_stream: Configure a stream
1889 * @cdns: Cadence instance
1890 * @ch: Channel count
1891 * @dir: Data direction
1892 * @pdi: PDI to be used
1894 void sdw_cdns_config_stream(struct sdw_cdns
*cdns
,
1895 u32 ch
, u32 dir
, struct sdw_cdns_pdi
*pdi
)
1897 u32 offset
, val
= 0;
1899 if (dir
== SDW_DATA_DIR_RX
) {
1900 val
= CDNS_PORTCTRL_DIRN
;
1902 if (cdns
->bus
.params
.m_data_mode
!= SDW_PORT_DATA_MODE_NORMAL
)
1903 val
|= CDNS_PORTCTRL_TEST_FAILED
;
1905 offset
= CDNS_PORTCTRL
+ pdi
->num
* CDNS_PORT_OFFSET
;
1906 cdns_updatel(cdns
, offset
,
1907 CDNS_PORTCTRL_DIRN
| CDNS_PORTCTRL_TEST_FAILED
,
1911 val
|= CDNS_PDI_CONFIG_SOFT_RESET
;
1912 val
|= FIELD_PREP(CDNS_PDI_CONFIG_CHANNEL
, (1 << ch
) - 1);
1913 cdns_writel(cdns
, CDNS_PDI_CONFIG(pdi
->num
), val
);
1915 EXPORT_SYMBOL(sdw_cdns_config_stream
);
1918 * sdw_cdns_alloc_pdi() - Allocate a PDI
1920 * @cdns: Cadence instance
1921 * @stream: Stream to be allocated
1922 * @ch: Channel count
1923 * @dir: Data direction
1926 struct sdw_cdns_pdi
*sdw_cdns_alloc_pdi(struct sdw_cdns
*cdns
,
1927 struct sdw_cdns_streams
*stream
,
1928 u32 ch
, u32 dir
, int dai_id
)
1930 struct sdw_cdns_pdi
*pdi
= NULL
;
1932 if (dir
== SDW_DATA_DIR_RX
)
1933 pdi
= cdns_find_pdi(cdns
, stream
->num_in
, stream
->in
,
1936 pdi
= cdns_find_pdi(cdns
, stream
->num_out
, stream
->out
,
1939 /* check if we found a PDI, else find in bi-directional */
1941 pdi
= cdns_find_pdi(cdns
, stream
->num_bd
, stream
->bd
,
1946 pdi
->h_ch_num
= ch
- 1;
1953 EXPORT_SYMBOL(sdw_cdns_alloc_pdi
);
1955 MODULE_LICENSE("Dual BSD/GPL");
1956 MODULE_DESCRIPTION("Cadence Soundwire Library");