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/delay.h>
10 #include <linux/device.h>
11 #include <linux/interrupt.h>
12 #include <linux/module.h>
13 #include <linux/mod_devicetable.h>
14 #include <linux/soundwire/sdw_registers.h>
15 #include <linux/soundwire/sdw.h>
17 #include "cadence_master.h"
19 #define CDNS_MCP_CONFIG 0x0
21 #define CDNS_MCP_CONFIG_MCMD_RETRY GENMASK(27, 24)
22 #define CDNS_MCP_CONFIG_MPREQ_DELAY GENMASK(20, 16)
23 #define CDNS_MCP_CONFIG_MMASTER BIT(7)
24 #define CDNS_MCP_CONFIG_BUS_REL BIT(6)
25 #define CDNS_MCP_CONFIG_SNIFFER BIT(5)
26 #define CDNS_MCP_CONFIG_SSPMOD BIT(4)
27 #define CDNS_MCP_CONFIG_CMD BIT(3)
28 #define CDNS_MCP_CONFIG_OP GENMASK(2, 0)
29 #define CDNS_MCP_CONFIG_OP_NORMAL 0
31 #define CDNS_MCP_CONTROL 0x4
33 #define CDNS_MCP_CONTROL_RST_DELAY GENMASK(10, 8)
34 #define CDNS_MCP_CONTROL_CMD_RST BIT(7)
35 #define CDNS_MCP_CONTROL_SOFT_RST BIT(6)
36 #define CDNS_MCP_CONTROL_SW_RST BIT(5)
37 #define CDNS_MCP_CONTROL_HW_RST BIT(4)
38 #define CDNS_MCP_CONTROL_CLK_PAUSE BIT(3)
39 #define CDNS_MCP_CONTROL_CLK_STOP_CLR BIT(2)
40 #define CDNS_MCP_CONTROL_CMD_ACCEPT BIT(1)
41 #define CDNS_MCP_CONTROL_BLOCK_WAKEUP BIT(0)
44 #define CDNS_MCP_CMDCTRL 0x8
45 #define CDNS_MCP_SSPSTAT 0xC
46 #define CDNS_MCP_FRAME_SHAPE 0x10
47 #define CDNS_MCP_FRAME_SHAPE_INIT 0x14
49 #define CDNS_MCP_CONFIG_UPDATE 0x18
50 #define CDNS_MCP_CONFIG_UPDATE_BIT BIT(0)
52 #define CDNS_MCP_PHYCTRL 0x1C
53 #define CDNS_MCP_SSP_CTRL0 0x20
54 #define CDNS_MCP_SSP_CTRL1 0x28
55 #define CDNS_MCP_CLK_CTRL0 0x30
56 #define CDNS_MCP_CLK_CTRL1 0x38
58 #define CDNS_MCP_STAT 0x40
60 #define CDNS_MCP_STAT_ACTIVE_BANK BIT(20)
61 #define CDNS_MCP_STAT_CLK_STOP BIT(16)
63 #define CDNS_MCP_INTSTAT 0x44
64 #define CDNS_MCP_INTMASK 0x48
66 #define CDNS_MCP_INT_IRQ BIT(31)
67 #define CDNS_MCP_INT_WAKEUP BIT(16)
68 #define CDNS_MCP_INT_SLAVE_RSVD BIT(15)
69 #define CDNS_MCP_INT_SLAVE_ALERT BIT(14)
70 #define CDNS_MCP_INT_SLAVE_ATTACH BIT(13)
71 #define CDNS_MCP_INT_SLAVE_NATTACH BIT(12)
72 #define CDNS_MCP_INT_SLAVE_MASK GENMASK(15, 12)
73 #define CDNS_MCP_INT_DPINT BIT(11)
74 #define CDNS_MCP_INT_CTRL_CLASH BIT(10)
75 #define CDNS_MCP_INT_DATA_CLASH BIT(9)
76 #define CDNS_MCP_INT_CMD_ERR BIT(7)
77 #define CDNS_MCP_INT_RX_WL BIT(2)
78 #define CDNS_MCP_INT_TXE BIT(1)
80 #define CDNS_MCP_INTSET 0x4C
82 #define CDNS_SDW_SLAVE_STAT 0x50
83 #define CDNS_MCP_SLAVE_STAT_MASK BIT(1, 0)
85 #define CDNS_MCP_SLAVE_INTSTAT0 0x54
86 #define CDNS_MCP_SLAVE_INTSTAT1 0x58
87 #define CDNS_MCP_SLAVE_INTSTAT_NPRESENT BIT(0)
88 #define CDNS_MCP_SLAVE_INTSTAT_ATTACHED BIT(1)
89 #define CDNS_MCP_SLAVE_INTSTAT_ALERT BIT(2)
90 #define CDNS_MCP_SLAVE_INTSTAT_RESERVED BIT(3)
91 #define CDNS_MCP_SLAVE_STATUS_BITS GENMASK(3, 0)
92 #define CDNS_MCP_SLAVE_STATUS_NUM 4
94 #define CDNS_MCP_SLAVE_INTMASK0 0x5C
95 #define CDNS_MCP_SLAVE_INTMASK1 0x60
97 #define CDNS_MCP_SLAVE_INTMASK0_MASK GENMASK(30, 0)
98 #define CDNS_MCP_SLAVE_INTMASK1_MASK GENMASK(16, 0)
100 #define CDNS_MCP_PORT_INTSTAT 0x64
101 #define CDNS_MCP_PDI_STAT 0x6C
103 #define CDNS_MCP_FIFOLEVEL 0x78
104 #define CDNS_MCP_FIFOSTAT 0x7C
105 #define CDNS_MCP_RX_FIFO_AVAIL GENMASK(5, 0)
107 #define CDNS_MCP_CMD_BASE 0x80
108 #define CDNS_MCP_RESP_BASE 0x80
109 #define CDNS_MCP_CMD_LEN 0x20
110 #define CDNS_MCP_CMD_WORD_LEN 0x4
112 #define CDNS_MCP_CMD_SSP_TAG BIT(31)
113 #define CDNS_MCP_CMD_COMMAND GENMASK(30, 28)
114 #define CDNS_MCP_CMD_DEV_ADDR GENMASK(27, 24)
115 #define CDNS_MCP_CMD_REG_ADDR_H GENMASK(23, 16)
116 #define CDNS_MCP_CMD_REG_ADDR_L GENMASK(15, 8)
117 #define CDNS_MCP_CMD_REG_DATA GENMASK(7, 0)
119 #define CDNS_MCP_CMD_READ 2
120 #define CDNS_MCP_CMD_WRITE 3
122 #define CDNS_MCP_RESP_RDATA GENMASK(15, 8)
123 #define CDNS_MCP_RESP_ACK BIT(0)
124 #define CDNS_MCP_RESP_NACK BIT(1)
126 #define CDNS_DP_SIZE 128
128 #define CDNS_DPN_B0_CONFIG(n) (0x100 + CDNS_DP_SIZE * (n))
129 #define CDNS_DPN_B0_CH_EN(n) (0x104 + CDNS_DP_SIZE * (n))
130 #define CDNS_DPN_B0_SAMPLE_CTRL(n) (0x108 + CDNS_DP_SIZE * (n))
131 #define CDNS_DPN_B0_OFFSET_CTRL(n) (0x10C + CDNS_DP_SIZE * (n))
132 #define CDNS_DPN_B0_HCTRL(n) (0x110 + CDNS_DP_SIZE * (n))
133 #define CDNS_DPN_B0_ASYNC_CTRL(n) (0x114 + CDNS_DP_SIZE * (n))
135 #define CDNS_DPN_B1_CONFIG(n) (0x118 + CDNS_DP_SIZE * (n))
136 #define CDNS_DPN_B1_CH_EN(n) (0x11C + CDNS_DP_SIZE * (n))
137 #define CDNS_DPN_B1_SAMPLE_CTRL(n) (0x120 + CDNS_DP_SIZE * (n))
138 #define CDNS_DPN_B1_OFFSET_CTRL(n) (0x124 + CDNS_DP_SIZE * (n))
139 #define CDNS_DPN_B1_HCTRL(n) (0x128 + CDNS_DP_SIZE * (n))
140 #define CDNS_DPN_B1_ASYNC_CTRL(n) (0x12C + CDNS_DP_SIZE * (n))
142 #define CDNS_DPN_CONFIG_BPM BIT(18)
143 #define CDNS_DPN_CONFIG_BGC GENMASK(17, 16)
144 #define CDNS_DPN_CONFIG_WL GENMASK(12, 8)
145 #define CDNS_DPN_CONFIG_PORT_DAT GENMASK(3, 2)
146 #define CDNS_DPN_CONFIG_PORT_FLOW GENMASK(1, 0)
148 #define CDNS_DPN_SAMPLE_CTRL_SI GENMASK(15, 0)
150 #define CDNS_DPN_OFFSET_CTRL_1 GENMASK(7, 0)
151 #define CDNS_DPN_OFFSET_CTRL_2 GENMASK(15, 8)
153 #define CDNS_DPN_HCTRL_HSTOP GENMASK(3, 0)
154 #define CDNS_DPN_HCTRL_HSTART GENMASK(7, 4)
155 #define CDNS_DPN_HCTRL_LCTRL GENMASK(10, 8)
157 #define CDNS_PORTCTRL 0x130
158 #define CDNS_PORTCTRL_DIRN BIT(7)
159 #define CDNS_PORTCTRL_BANK_INVERT BIT(8)
161 #define CDNS_PORT_OFFSET 0x80
163 #define CDNS_PDI_CONFIG(n) (0x1100 + (n) * 16)
165 #define CDNS_PDI_CONFIG_SOFT_RESET BIT(24)
166 #define CDNS_PDI_CONFIG_CHANNEL GENMASK(15, 8)
167 #define CDNS_PDI_CONFIG_PORT GENMASK(4, 0)
169 /* Driver defaults */
171 #define CDNS_DEFAULT_CLK_DIVIDER 0
172 #define CDNS_DEFAULT_FRAME_SHAPE 0x30
173 #define CDNS_DEFAULT_SSP_INTERVAL 0x18
174 #define CDNS_TX_TIMEOUT 2000
176 #define CDNS_PCM_PDI_OFFSET 0x2
177 #define CDNS_PDM_PDI_OFFSET 0x6
179 #define CDNS_SCP_RX_FIFOLEVEL 0x2
182 * register accessor helpers
184 static inline u32
cdns_readl(struct sdw_cdns
*cdns
, int offset
)
186 return readl(cdns
->registers
+ offset
);
189 static inline void cdns_writel(struct sdw_cdns
*cdns
, int offset
, u32 value
)
191 writel(value
, cdns
->registers
+ offset
);
194 static inline void cdns_updatel(struct sdw_cdns
*cdns
,
195 int offset
, u32 mask
, u32 val
)
199 tmp
= cdns_readl(cdns
, offset
);
200 tmp
= (tmp
& ~mask
) | val
;
201 cdns_writel(cdns
, offset
, tmp
);
204 static int cdns_clear_bit(struct sdw_cdns
*cdns
, int offset
, u32 value
)
209 writel(value
, cdns
->registers
+ offset
);
211 /* Wait for bit to be self cleared */
213 reg_read
= readl(cdns
->registers
+ offset
);
214 if ((reg_read
& value
) == 0)
219 } while (timeout
!= 0);
227 static enum sdw_command_response
cdns_fill_msg_resp(
228 struct sdw_cdns
*cdns
,
229 struct sdw_msg
*msg
, int count
, int offset
)
231 int nack
= 0, no_ack
= 0;
234 /* check message response */
235 for (i
= 0; i
< count
; i
++) {
236 if (!(cdns
->response_buf
[i
] & CDNS_MCP_RESP_ACK
)) {
238 dev_dbg(cdns
->dev
, "Msg Ack not received\n");
239 if (cdns
->response_buf
[i
] & CDNS_MCP_RESP_NACK
) {
241 dev_err(cdns
->dev
, "Msg NACK received\n");
247 dev_err(cdns
->dev
, "Msg NACKed for Slave %d\n", msg
->dev_num
);
250 dev_dbg(cdns
->dev
, "Msg ignored for Slave %d\n", msg
->dev_num
);
251 return SDW_CMD_IGNORED
;
255 for (i
= 0; i
< count
; i
++)
256 msg
->buf
[i
+ offset
] = cdns
->response_buf
[i
] >>
257 SDW_REG_SHIFT(CDNS_MCP_RESP_RDATA
);
262 static enum sdw_command_response
263 _cdns_xfer_msg(struct sdw_cdns
*cdns
, struct sdw_msg
*msg
, int cmd
,
264 int offset
, int count
, bool defer
)
270 /* Program the watermark level for RX FIFO */
271 if (cdns
->msg_count
!= count
) {
272 cdns_writel(cdns
, CDNS_MCP_FIFOLEVEL
, count
);
273 cdns
->msg_count
= count
;
276 base
= CDNS_MCP_CMD_BASE
;
279 for (i
= 0; i
< count
; i
++) {
280 data
= msg
->dev_num
<< SDW_REG_SHIFT(CDNS_MCP_CMD_DEV_ADDR
);
281 data
|= cmd
<< SDW_REG_SHIFT(CDNS_MCP_CMD_COMMAND
);
282 data
|= addr
++ << SDW_REG_SHIFT(CDNS_MCP_CMD_REG_ADDR_L
);
284 if (msg
->flags
== SDW_MSG_FLAG_WRITE
)
285 data
|= msg
->buf
[i
+ offset
];
287 data
|= msg
->ssp_sync
<< SDW_REG_SHIFT(CDNS_MCP_CMD_SSP_TAG
);
288 cdns_writel(cdns
, base
, data
);
289 base
+= CDNS_MCP_CMD_WORD_LEN
;
295 /* wait for timeout or response */
296 time
= wait_for_completion_timeout(&cdns
->tx_complete
,
297 msecs_to_jiffies(CDNS_TX_TIMEOUT
));
299 dev_err(cdns
->dev
, "IO transfer timed out\n");
301 return SDW_CMD_TIMEOUT
;
304 return cdns_fill_msg_resp(cdns
, msg
, count
, offset
);
307 static enum sdw_command_response
cdns_program_scp_addr(
308 struct sdw_cdns
*cdns
, struct sdw_msg
*msg
)
310 int nack
= 0, no_ack
= 0;
315 /* Program the watermark level for RX FIFO */
316 if (cdns
->msg_count
!= CDNS_SCP_RX_FIFOLEVEL
) {
317 cdns_writel(cdns
, CDNS_MCP_FIFOLEVEL
, CDNS_SCP_RX_FIFOLEVEL
);
318 cdns
->msg_count
= CDNS_SCP_RX_FIFOLEVEL
;
321 data
[0] = msg
->dev_num
<< SDW_REG_SHIFT(CDNS_MCP_CMD_DEV_ADDR
);
322 data
[0] |= 0x3 << SDW_REG_SHIFT(CDNS_MCP_CMD_COMMAND
);
325 data
[0] |= SDW_SCP_ADDRPAGE1
<< SDW_REG_SHIFT(CDNS_MCP_CMD_REG_ADDR_L
);
326 data
[1] |= SDW_SCP_ADDRPAGE2
<< SDW_REG_SHIFT(CDNS_MCP_CMD_REG_ADDR_L
);
328 data
[0] |= msg
->addr_page1
;
329 data
[1] |= msg
->addr_page2
;
331 base
= CDNS_MCP_CMD_BASE
;
332 cdns_writel(cdns
, base
, data
[0]);
333 base
+= CDNS_MCP_CMD_WORD_LEN
;
334 cdns_writel(cdns
, base
, data
[1]);
336 time
= wait_for_completion_timeout(&cdns
->tx_complete
,
337 msecs_to_jiffies(CDNS_TX_TIMEOUT
));
339 dev_err(cdns
->dev
, "SCP Msg trf timed out\n");
341 return SDW_CMD_TIMEOUT
;
344 /* check response the writes */
345 for (i
= 0; i
< 2; i
++) {
346 if (!(cdns
->response_buf
[i
] & CDNS_MCP_RESP_ACK
)) {
348 dev_err(cdns
->dev
, "Program SCP Ack not received");
349 if (cdns
->response_buf
[i
] & CDNS_MCP_RESP_NACK
) {
351 dev_err(cdns
->dev
, "Program SCP NACK received");
356 /* For NACK, NO ack, don't return err if we are in Broadcast mode */
359 "SCP_addrpage NACKed for Slave %d", msg
->dev_num
);
363 "SCP_addrpage ignored for Slave %d", msg
->dev_num
);
364 return SDW_CMD_IGNORED
;
370 static int cdns_prep_msg(struct sdw_cdns
*cdns
, struct sdw_msg
*msg
, int *cmd
)
375 ret
= cdns_program_scp_addr(cdns
, msg
);
382 switch (msg
->flags
) {
383 case SDW_MSG_FLAG_READ
:
384 *cmd
= CDNS_MCP_CMD_READ
;
387 case SDW_MSG_FLAG_WRITE
:
388 *cmd
= CDNS_MCP_CMD_WRITE
;
392 dev_err(cdns
->dev
, "Invalid msg cmd: %d\n", msg
->flags
);
399 static enum sdw_command_response
400 cdns_xfer_msg(struct sdw_bus
*bus
, struct sdw_msg
*msg
)
402 struct sdw_cdns
*cdns
= bus_to_cdns(bus
);
405 ret
= cdns_prep_msg(cdns
, msg
, &cmd
);
407 return SDW_CMD_FAIL_OTHER
;
409 for (i
= 0; i
< msg
->len
/ CDNS_MCP_CMD_LEN
; i
++) {
410 ret
= _cdns_xfer_msg(cdns
, msg
, cmd
, i
* CDNS_MCP_CMD_LEN
,
411 CDNS_MCP_CMD_LEN
, false);
416 if (!(msg
->len
% CDNS_MCP_CMD_LEN
))
419 ret
= _cdns_xfer_msg(cdns
, msg
, cmd
, i
* CDNS_MCP_CMD_LEN
,
420 msg
->len
% CDNS_MCP_CMD_LEN
, false);
426 static enum sdw_command_response
427 cdns_xfer_msg_defer(struct sdw_bus
*bus
,
428 struct sdw_msg
*msg
, struct sdw_defer
*defer
)
430 struct sdw_cdns
*cdns
= bus_to_cdns(bus
);
433 /* for defer only 1 message is supported */
437 ret
= cdns_prep_msg(cdns
, msg
, &cmd
);
439 return SDW_CMD_FAIL_OTHER
;
442 cdns
->defer
->length
= msg
->len
;
444 return _cdns_xfer_msg(cdns
, msg
, cmd
, 0, msg
->len
, true);
447 static enum sdw_command_response
448 cdns_reset_page_addr(struct sdw_bus
*bus
, unsigned int dev_num
)
450 struct sdw_cdns
*cdns
= bus_to_cdns(bus
);
453 /* Create dummy message with valid device number */
454 memset(&msg
, 0, sizeof(msg
));
455 msg
.dev_num
= dev_num
;
457 return cdns_program_scp_addr(cdns
, &msg
);
464 static void cdns_read_response(struct sdw_cdns
*cdns
)
466 u32 num_resp
, cmd_base
;
469 num_resp
= cdns_readl(cdns
, CDNS_MCP_FIFOSTAT
);
470 num_resp
&= CDNS_MCP_RX_FIFO_AVAIL
;
472 cmd_base
= CDNS_MCP_CMD_BASE
;
474 for (i
= 0; i
< num_resp
; i
++) {
475 cdns
->response_buf
[i
] = cdns_readl(cdns
, cmd_base
);
476 cmd_base
+= CDNS_MCP_CMD_WORD_LEN
;
480 static int cdns_update_slave_status(struct sdw_cdns
*cdns
,
481 u32 slave0
, u32 slave1
)
483 enum sdw_slave_status status
[SDW_MAX_DEVICES
+ 1];
484 bool is_slave
= false;
488 /* combine the two status */
489 slave
= ((u64
)slave1
<< 32) | slave0
;
490 memset(status
, 0, sizeof(status
));
492 for (i
= 0; i
<= SDW_MAX_DEVICES
; i
++) {
493 mask
= (slave
>> (i
* CDNS_MCP_SLAVE_STATUS_NUM
)) &
494 CDNS_MCP_SLAVE_STATUS_BITS
;
501 if (mask
& CDNS_MCP_SLAVE_INTSTAT_RESERVED
) {
502 status
[i
] = SDW_SLAVE_RESERVED
;
506 if (mask
& CDNS_MCP_SLAVE_INTSTAT_ATTACHED
) {
507 status
[i
] = SDW_SLAVE_ATTACHED
;
511 if (mask
& CDNS_MCP_SLAVE_INTSTAT_ALERT
) {
512 status
[i
] = SDW_SLAVE_ALERT
;
516 if (mask
& CDNS_MCP_SLAVE_INTSTAT_NPRESENT
) {
517 status
[i
] = SDW_SLAVE_UNATTACHED
;
521 /* first check if Slave reported multiple status */
522 if (set_status
> 1) {
524 "Slave reported multiple Status: %d\n",
527 * TODO: we need to reread the status here by
534 return sdw_handle_slave_status(&cdns
->bus
, status
);
540 * sdw_cdns_irq() - Cadence interrupt handler
542 * @dev_id: irq context
544 irqreturn_t
sdw_cdns_irq(int irq
, void *dev_id
)
546 struct sdw_cdns
*cdns
= dev_id
;
548 int ret
= IRQ_HANDLED
;
550 /* Check if the link is up */
554 int_status
= cdns_readl(cdns
, CDNS_MCP_INTSTAT
);
556 if (!(int_status
& CDNS_MCP_INT_IRQ
))
559 if (int_status
& CDNS_MCP_INT_RX_WL
) {
560 cdns_read_response(cdns
);
563 cdns_fill_msg_resp(cdns
, cdns
->defer
->msg
,
564 cdns
->defer
->length
, 0);
565 complete(&cdns
->defer
->complete
);
568 complete(&cdns
->tx_complete
);
571 if (int_status
& CDNS_MCP_INT_CTRL_CLASH
) {
573 /* Slave is driving bit slot during control word */
574 dev_err_ratelimited(cdns
->dev
, "Bus clash for control word\n");
575 int_status
|= CDNS_MCP_INT_CTRL_CLASH
;
578 if (int_status
& CDNS_MCP_INT_DATA_CLASH
) {
580 * Multiple slaves trying to drive bit slot, or issue with
581 * ownership of data bits or Slave gone bonkers
583 dev_err_ratelimited(cdns
->dev
, "Bus clash for data word\n");
584 int_status
|= CDNS_MCP_INT_DATA_CLASH
;
587 if (int_status
& CDNS_MCP_INT_SLAVE_MASK
) {
588 /* Mask the Slave interrupt and wake thread */
589 cdns_updatel(cdns
, CDNS_MCP_INTMASK
,
590 CDNS_MCP_INT_SLAVE_MASK
, 0);
592 int_status
&= ~CDNS_MCP_INT_SLAVE_MASK
;
593 ret
= IRQ_WAKE_THREAD
;
596 cdns_writel(cdns
, CDNS_MCP_INTSTAT
, int_status
);
599 EXPORT_SYMBOL(sdw_cdns_irq
);
602 * sdw_cdns_thread() - Cadence irq thread handler
604 * @dev_id: irq context
606 irqreturn_t
sdw_cdns_thread(int irq
, void *dev_id
)
608 struct sdw_cdns
*cdns
= dev_id
;
611 dev_dbg(cdns
->dev
, "Slave status change\n");
613 slave0
= cdns_readl(cdns
, CDNS_MCP_SLAVE_INTSTAT0
);
614 slave1
= cdns_readl(cdns
, CDNS_MCP_SLAVE_INTSTAT1
);
616 cdns_update_slave_status(cdns
, slave0
, slave1
);
617 cdns_writel(cdns
, CDNS_MCP_SLAVE_INTSTAT0
, slave0
);
618 cdns_writel(cdns
, CDNS_MCP_SLAVE_INTSTAT1
, slave1
);
620 /* clear and unmask Slave interrupt now */
621 cdns_writel(cdns
, CDNS_MCP_INTSTAT
, CDNS_MCP_INT_SLAVE_MASK
);
622 cdns_updatel(cdns
, CDNS_MCP_INTMASK
,
623 CDNS_MCP_INT_SLAVE_MASK
, CDNS_MCP_INT_SLAVE_MASK
);
627 EXPORT_SYMBOL(sdw_cdns_thread
);
632 static int _cdns_enable_interrupt(struct sdw_cdns
*cdns
)
636 cdns_writel(cdns
, CDNS_MCP_SLAVE_INTMASK0
,
637 CDNS_MCP_SLAVE_INTMASK0_MASK
);
638 cdns_writel(cdns
, CDNS_MCP_SLAVE_INTMASK1
,
639 CDNS_MCP_SLAVE_INTMASK1_MASK
);
641 mask
= CDNS_MCP_INT_SLAVE_RSVD
| CDNS_MCP_INT_SLAVE_ALERT
|
642 CDNS_MCP_INT_SLAVE_ATTACH
| CDNS_MCP_INT_SLAVE_NATTACH
|
643 CDNS_MCP_INT_CTRL_CLASH
| CDNS_MCP_INT_DATA_CLASH
|
644 CDNS_MCP_INT_RX_WL
| CDNS_MCP_INT_IRQ
| CDNS_MCP_INT_DPINT
;
646 cdns_writel(cdns
, CDNS_MCP_INTMASK
, mask
);
652 * sdw_cdns_enable_interrupt() - Enable SDW interrupts and update config
653 * @cdns: Cadence instance
655 int sdw_cdns_enable_interrupt(struct sdw_cdns
*cdns
)
659 _cdns_enable_interrupt(cdns
);
660 ret
= cdns_clear_bit(cdns
, CDNS_MCP_CONFIG_UPDATE
,
661 CDNS_MCP_CONFIG_UPDATE_BIT
);
663 dev_err(cdns
->dev
, "Config update timedout");
667 EXPORT_SYMBOL(sdw_cdns_enable_interrupt
);
670 * sdw_cdns_init() - Cadence initialization
671 * @cdns: Cadence instance
673 int sdw_cdns_init(struct sdw_cdns
*cdns
)
678 /* Exit clock stop */
679 ret
= cdns_clear_bit(cdns
, CDNS_MCP_CONTROL
,
680 CDNS_MCP_CONTROL_CLK_STOP_CLR
);
682 dev_err(cdns
->dev
, "Couldn't exit from clock stop\n");
686 /* Set clock divider */
687 val
= cdns_readl(cdns
, CDNS_MCP_CLK_CTRL0
);
688 val
|= CDNS_DEFAULT_CLK_DIVIDER
;
689 cdns_writel(cdns
, CDNS_MCP_CLK_CTRL0
, val
);
691 /* Set the default frame shape */
692 cdns_writel(cdns
, CDNS_MCP_FRAME_SHAPE_INIT
, CDNS_DEFAULT_FRAME_SHAPE
);
694 /* Set SSP interval to default value */
695 cdns_writel(cdns
, CDNS_MCP_SSP_CTRL0
, CDNS_DEFAULT_SSP_INTERVAL
);
696 cdns_writel(cdns
, CDNS_MCP_SSP_CTRL1
, CDNS_DEFAULT_SSP_INTERVAL
);
698 /* Set cmd accept mode */
699 cdns_updatel(cdns
, CDNS_MCP_CONTROL
, CDNS_MCP_CONTROL_CMD_ACCEPT
,
700 CDNS_MCP_CONTROL_CMD_ACCEPT
);
702 /* Configure mcp config */
703 val
= cdns_readl(cdns
, CDNS_MCP_CONFIG
);
705 /* Set Max cmd retry to 15 */
706 val
|= CDNS_MCP_CONFIG_MCMD_RETRY
;
708 /* Set frame delay between PREQ and ping frame to 15 frames */
709 val
|= 0xF << SDW_REG_SHIFT(CDNS_MCP_CONFIG_MPREQ_DELAY
);
711 /* Disable auto bus release */
712 val
&= ~CDNS_MCP_CONFIG_BUS_REL
;
714 /* Disable sniffer mode */
715 val
&= ~CDNS_MCP_CONFIG_SNIFFER
;
717 /* Set cmd mode for Tx and Rx cmds */
718 val
&= ~CDNS_MCP_CONFIG_CMD
;
720 /* Set operation to normal */
721 val
&= ~CDNS_MCP_CONFIG_OP
;
722 val
|= CDNS_MCP_CONFIG_OP_NORMAL
;
724 cdns_writel(cdns
, CDNS_MCP_CONFIG
, val
);
728 EXPORT_SYMBOL(sdw_cdns_init
);
730 struct sdw_master_ops sdw_cdns_master_ops
= {
731 .read_prop
= sdw_master_read_prop
,
732 .xfer_msg
= cdns_xfer_msg
,
733 .xfer_msg_defer
= cdns_xfer_msg_defer
,
734 .reset_page_addr
= cdns_reset_page_addr
,
736 EXPORT_SYMBOL(sdw_cdns_master_ops
);
739 * sdw_cdns_probe() - Cadence probe routine
740 * @cdns: Cadence instance
742 int sdw_cdns_probe(struct sdw_cdns
*cdns
)
744 init_completion(&cdns
->tx_complete
);
748 EXPORT_SYMBOL(sdw_cdns_probe
);
750 MODULE_LICENSE("Dual BSD/GPL");
751 MODULE_DESCRIPTION("Cadence Soundwire Library");