1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
3 * SoundWire AMD Manager driver
5 * Copyright 2023-24 Advanced Micro Devices, Inc.
8 #include <linux/completion.h>
9 #include <linux/cleanup.h>
10 #include <linux/device.h>
12 #include <linux/jiffies.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/soundwire/sdw.h>
17 #include <linux/soundwire/sdw_registers.h>
18 #include <linux/pm_runtime.h>
19 #include <linux/wait.h>
20 #include <sound/pcm_params.h>
21 #include <sound/soc.h>
24 #include "amd_manager.h"
26 #define DRV_NAME "amd_sdw_manager"
28 #define to_amd_sdw(b) container_of(b, struct amd_sdw_manager, bus)
30 static int amd_init_sdw_manager(struct amd_sdw_manager
*amd_manager
)
35 writel(AMD_SDW_ENABLE
, amd_manager
->mmio
+ ACP_SW_EN
);
36 ret
= readl_poll_timeout(amd_manager
->mmio
+ ACP_SW_EN_STATUS
, val
, val
, ACP_DELAY_US
,
41 /* SoundWire manager bus reset */
42 writel(AMD_SDW_BUS_RESET_REQ
, amd_manager
->mmio
+ ACP_SW_BUS_RESET_CTRL
);
43 ret
= readl_poll_timeout(amd_manager
->mmio
+ ACP_SW_BUS_RESET_CTRL
, val
,
44 (val
& AMD_SDW_BUS_RESET_DONE
), ACP_DELAY_US
, AMD_SDW_TIMEOUT
);
48 writel(AMD_SDW_BUS_RESET_CLEAR_REQ
, amd_manager
->mmio
+ ACP_SW_BUS_RESET_CTRL
);
49 ret
= readl_poll_timeout(amd_manager
->mmio
+ ACP_SW_BUS_RESET_CTRL
, val
, !val
,
50 ACP_DELAY_US
, AMD_SDW_TIMEOUT
);
52 dev_err(amd_manager
->dev
, "Failed to reset SoundWire manager instance%d\n",
53 amd_manager
->instance
);
57 writel(AMD_SDW_DISABLE
, amd_manager
->mmio
+ ACP_SW_EN
);
58 return readl_poll_timeout(amd_manager
->mmio
+ ACP_SW_EN_STATUS
, val
, !val
, ACP_DELAY_US
,
62 static int amd_enable_sdw_manager(struct amd_sdw_manager
*amd_manager
)
66 writel(AMD_SDW_ENABLE
, amd_manager
->mmio
+ ACP_SW_EN
);
67 return readl_poll_timeout(amd_manager
->mmio
+ ACP_SW_EN_STATUS
, val
, val
, ACP_DELAY_US
,
71 static int amd_disable_sdw_manager(struct amd_sdw_manager
*amd_manager
)
75 writel(AMD_SDW_DISABLE
, amd_manager
->mmio
+ ACP_SW_EN
);
77 * After invoking manager disable sequence, check whether
78 * manager has executed clock stop sequence. In this case,
79 * manager should ignore checking enable status register.
81 val
= readl(amd_manager
->mmio
+ ACP_SW_CLK_RESUME_CTRL
);
84 return readl_poll_timeout(amd_manager
->mmio
+ ACP_SW_EN_STATUS
, val
, !val
, ACP_DELAY_US
,
88 static void amd_enable_sdw_interrupts(struct amd_sdw_manager
*amd_manager
)
92 mutex_lock(amd_manager
->acp_sdw_lock
);
93 val
= sdw_manager_reg_mask_array
[amd_manager
->instance
];
94 amd_updatel(amd_manager
->acp_mmio
, ACP_EXTERNAL_INTR_CNTL(amd_manager
->instance
), val
, val
);
95 mutex_unlock(amd_manager
->acp_sdw_lock
);
97 writel(AMD_SDW_IRQ_MASK_0TO7
, amd_manager
->mmio
+
98 ACP_SW_STATE_CHANGE_STATUS_MASK_0TO7
);
99 writel(AMD_SDW_IRQ_MASK_8TO11
, amd_manager
->mmio
+
100 ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11
);
101 writel(AMD_SDW_IRQ_ERROR_MASK
, amd_manager
->mmio
+ ACP_SW_ERROR_INTR_MASK
);
104 static void amd_disable_sdw_interrupts(struct amd_sdw_manager
*amd_manager
)
108 mutex_lock(amd_manager
->acp_sdw_lock
);
109 irq_mask
= sdw_manager_reg_mask_array
[amd_manager
->instance
];
110 amd_updatel(amd_manager
->acp_mmio
, ACP_EXTERNAL_INTR_CNTL(amd_manager
->instance
),
112 mutex_unlock(amd_manager
->acp_sdw_lock
);
114 writel(0x00, amd_manager
->mmio
+ ACP_SW_STATE_CHANGE_STATUS_MASK_0TO7
);
115 writel(0x00, amd_manager
->mmio
+ ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11
);
116 writel(0x00, amd_manager
->mmio
+ ACP_SW_ERROR_INTR_MASK
);
119 static int amd_deinit_sdw_manager(struct amd_sdw_manager
*amd_manager
)
121 amd_disable_sdw_interrupts(amd_manager
);
122 return amd_disable_sdw_manager(amd_manager
);
125 static void amd_sdw_set_frameshape(struct amd_sdw_manager
*amd_manager
)
129 frame_size
= (amd_manager
->rows_index
<< 3) | amd_manager
->cols_index
;
130 writel(frame_size
, amd_manager
->mmio
+ ACP_SW_FRAMESIZE
);
133 static void amd_sdw_wake_enable(struct amd_sdw_manager
*amd_manager
, bool enable
)
137 wake_ctrl
= readl(amd_manager
->mmio
+ ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11
);
139 wake_ctrl
|= AMD_SDW_WAKE_INTR_MASK
;
141 wake_ctrl
&= ~AMD_SDW_WAKE_INTR_MASK
;
143 writel(wake_ctrl
, amd_manager
->mmio
+ ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11
);
146 static void amd_sdw_ctl_word_prep(u32
*lower_word
, u32
*upper_word
, struct sdw_msg
*msg
,
152 u8 upper_addr
, lower_addr
;
155 addr
= msg
->addr
+ cmd_offset
;
156 upper_addr
= (addr
& 0xFF00) >> 8;
157 lower_addr
= addr
& 0xFF;
159 if (msg
->flags
== SDW_MSG_FLAG_WRITE
)
160 data
= msg
->buf
[cmd_offset
];
162 upper_data
= FIELD_PREP(AMD_SDW_MCP_CMD_DEV_ADDR
, msg
->dev_num
);
163 upper_data
|= FIELD_PREP(AMD_SDW_MCP_CMD_COMMAND
, msg
->flags
+ 2);
164 upper_data
|= FIELD_PREP(AMD_SDW_MCP_CMD_REG_ADDR_HIGH
, upper_addr
);
165 lower_data
|= FIELD_PREP(AMD_SDW_MCP_CMD_REG_ADDR_LOW
, lower_addr
);
166 lower_data
|= FIELD_PREP(AMD_SDW_MCP_CMD_REG_DATA
, data
);
168 *upper_word
= upper_data
;
169 *lower_word
= lower_data
;
172 static u64
amd_sdw_send_cmd_get_resp(struct amd_sdw_manager
*amd_manager
, u32 lower_data
,
176 u32 lower_resp
, upper_resp
;
180 ret
= readl_poll_timeout(amd_manager
->mmio
+ ACP_SW_IMM_CMD_STS
, sts
,
181 !(sts
& AMD_SDW_IMM_CMD_BUSY
), ACP_DELAY_US
, AMD_SDW_TIMEOUT
);
183 dev_err(amd_manager
->dev
, "SDW%x previous cmd status clear failed\n",
184 amd_manager
->instance
);
188 if (sts
& AMD_SDW_IMM_RES_VALID
) {
189 dev_err(amd_manager
->dev
, "SDW%x manager is in bad state\n", amd_manager
->instance
);
190 writel(0x00, amd_manager
->mmio
+ ACP_SW_IMM_CMD_STS
);
192 writel(upper_data
, amd_manager
->mmio
+ ACP_SW_IMM_CMD_UPPER_WORD
);
193 writel(lower_data
, amd_manager
->mmio
+ ACP_SW_IMM_CMD_LOWER_QWORD
);
195 ret
= readl_poll_timeout(amd_manager
->mmio
+ ACP_SW_IMM_CMD_STS
, sts
,
196 (sts
& AMD_SDW_IMM_RES_VALID
), ACP_DELAY_US
, AMD_SDW_TIMEOUT
);
198 dev_err(amd_manager
->dev
, "SDW%x cmd response timeout occurred\n",
199 amd_manager
->instance
);
202 upper_resp
= readl(amd_manager
->mmio
+ ACP_SW_IMM_RESP_UPPER_WORD
);
203 lower_resp
= readl(amd_manager
->mmio
+ ACP_SW_IMM_RESP_LOWER_QWORD
);
205 writel(AMD_SDW_IMM_RES_VALID
, amd_manager
->mmio
+ ACP_SW_IMM_CMD_STS
);
206 ret
= readl_poll_timeout(amd_manager
->mmio
+ ACP_SW_IMM_CMD_STS
, sts
,
207 !(sts
& AMD_SDW_IMM_RES_VALID
), ACP_DELAY_US
, AMD_SDW_TIMEOUT
);
209 dev_err(amd_manager
->dev
, "SDW%x cmd status retry failed\n",
210 amd_manager
->instance
);
214 resp
= (resp
<< 32) | lower_resp
;
218 static enum sdw_command_response
219 amd_program_scp_addr(struct amd_sdw_manager
*amd_manager
, struct sdw_msg
*msg
)
221 struct sdw_msg scp_msg
= {0};
222 u64 response_buf
[2] = {0};
223 u32 upper_data
= 0, lower_data
= 0;
226 scp_msg
.dev_num
= msg
->dev_num
;
227 scp_msg
.addr
= SDW_SCP_ADDRPAGE1
;
228 scp_msg
.buf
= &msg
->addr_page1
;
229 scp_msg
.flags
= SDW_MSG_FLAG_WRITE
;
230 amd_sdw_ctl_word_prep(&lower_data
, &upper_data
, &scp_msg
, 0);
231 response_buf
[0] = amd_sdw_send_cmd_get_resp(amd_manager
, lower_data
, upper_data
);
232 scp_msg
.addr
= SDW_SCP_ADDRPAGE2
;
233 scp_msg
.buf
= &msg
->addr_page2
;
234 amd_sdw_ctl_word_prep(&lower_data
, &upper_data
, &scp_msg
, 0);
235 response_buf
[1] = amd_sdw_send_cmd_get_resp(amd_manager
, lower_data
, upper_data
);
237 for (index
= 0; index
< 2; index
++) {
238 if (response_buf
[index
] == -ETIMEDOUT
) {
239 dev_err_ratelimited(amd_manager
->dev
,
240 "SCP_addrpage command timeout for Slave %d\n",
242 return SDW_CMD_TIMEOUT
;
243 } else if (!(response_buf
[index
] & AMD_SDW_MCP_RESP_ACK
)) {
244 if (response_buf
[index
] & AMD_SDW_MCP_RESP_NACK
) {
245 dev_err_ratelimited(amd_manager
->dev
,
246 "SCP_addrpage NACKed for Slave %d\n",
250 dev_dbg_ratelimited(amd_manager
->dev
, "SCP_addrpage ignored for Slave %d\n",
252 return SDW_CMD_IGNORED
;
258 static int amd_prep_msg(struct amd_sdw_manager
*amd_manager
, struct sdw_msg
*msg
)
263 ret
= amd_program_scp_addr(amd_manager
, msg
);
269 switch (msg
->flags
) {
270 case SDW_MSG_FLAG_READ
:
271 case SDW_MSG_FLAG_WRITE
:
274 dev_err(amd_manager
->dev
, "Invalid msg cmd: %d\n", msg
->flags
);
280 static enum sdw_command_response
amd_sdw_fill_msg_resp(struct amd_sdw_manager
*amd_manager
,
281 struct sdw_msg
*msg
, u64 response
,
284 if (response
& AMD_SDW_MCP_RESP_ACK
) {
285 if (msg
->flags
== SDW_MSG_FLAG_READ
)
286 msg
->buf
[offset
] = FIELD_GET(AMD_SDW_MCP_RESP_RDATA
, response
);
288 if (response
== -ETIMEDOUT
) {
289 dev_err_ratelimited(amd_manager
->dev
, "command timeout for Slave %d\n",
291 return SDW_CMD_TIMEOUT
;
292 } else if (response
& AMD_SDW_MCP_RESP_NACK
) {
293 dev_err_ratelimited(amd_manager
->dev
,
294 "command response NACK received for Slave %d\n",
298 dev_err_ratelimited(amd_manager
->dev
, "command is ignored for Slave %d\n",
300 return SDW_CMD_IGNORED
;
305 static unsigned int _amd_sdw_xfer_msg(struct amd_sdw_manager
*amd_manager
, struct sdw_msg
*msg
,
309 u32 upper_data
= 0, lower_data
= 0;
311 amd_sdw_ctl_word_prep(&lower_data
, &upper_data
, msg
, cmd_offset
);
312 response
= amd_sdw_send_cmd_get_resp(amd_manager
, lower_data
, upper_data
);
313 return amd_sdw_fill_msg_resp(amd_manager
, msg
, response
, cmd_offset
);
316 static enum sdw_command_response
amd_sdw_xfer_msg(struct sdw_bus
*bus
, struct sdw_msg
*msg
)
318 struct amd_sdw_manager
*amd_manager
= to_amd_sdw(bus
);
321 ret
= amd_prep_msg(amd_manager
, msg
);
323 return SDW_CMD_FAIL_OTHER
;
324 for (i
= 0; i
< msg
->len
; i
++) {
325 ret
= _amd_sdw_xfer_msg(amd_manager
, msg
, i
);
332 static void amd_sdw_fill_slave_status(struct amd_sdw_manager
*amd_manager
, u16 index
, u32 status
)
335 case SDW_SLAVE_ATTACHED
:
336 case SDW_SLAVE_UNATTACHED
:
337 case SDW_SLAVE_ALERT
:
338 amd_manager
->status
[index
] = status
;
341 amd_manager
->status
[index
] = SDW_SLAVE_RESERVED
;
346 static void amd_sdw_process_ping_status(u64 response
, struct amd_sdw_manager
*amd_manager
)
352 /* slave status response */
353 slave_stat
= FIELD_GET(AMD_SDW_MCP_SLAVE_STAT_0_3
, response
);
354 slave_stat
|= FIELD_GET(AMD_SDW_MCP_SLAVE_STAT_4_11
, response
) << 8;
355 dev_dbg(amd_manager
->dev
, "slave_stat:0x%llx\n", slave_stat
);
356 for (dev_index
= 0; dev_index
<= SDW_MAX_DEVICES
; ++dev_index
) {
357 val
= (slave_stat
>> (dev_index
* 2)) & AMD_SDW_MCP_SLAVE_STATUS_MASK
;
358 dev_dbg(amd_manager
->dev
, "val:0x%x\n", val
);
359 amd_sdw_fill_slave_status(amd_manager
, dev_index
, val
);
363 static void amd_sdw_read_and_process_ping_status(struct amd_sdw_manager
*amd_manager
)
367 mutex_lock(&amd_manager
->bus
.msg_lock
);
368 response
= amd_sdw_send_cmd_get_resp(amd_manager
, 0, 0);
369 mutex_unlock(&amd_manager
->bus
.msg_lock
);
370 amd_sdw_process_ping_status(response
, amd_manager
);
373 static u32
amd_sdw_read_ping_status(struct sdw_bus
*bus
)
375 struct amd_sdw_manager
*amd_manager
= to_amd_sdw(bus
);
379 response
= amd_sdw_send_cmd_get_resp(amd_manager
, 0, 0);
380 /* slave status from ping response */
381 slave_stat
= FIELD_GET(AMD_SDW_MCP_SLAVE_STAT_0_3
, response
);
382 slave_stat
|= FIELD_GET(AMD_SDW_MCP_SLAVE_STAT_4_11
, response
) << 8;
383 dev_dbg(amd_manager
->dev
, "slave_stat:0x%x\n", slave_stat
);
387 static int amd_sdw_compute_params(struct sdw_bus
*bus
)
389 struct sdw_transport_data t_data
= {0};
390 struct sdw_master_runtime
*m_rt
;
391 struct sdw_port_runtime
*p_rt
;
392 struct sdw_bus_params
*b_params
= &bus
->params
;
393 int port_bo
, hstart
, hstop
, sample_int
;
394 unsigned int rate
, bps
;
398 hstop
= bus
->params
.col
- 1;
399 t_data
.hstop
= hstop
;
400 t_data
.hstart
= hstart
;
402 list_for_each_entry(m_rt
, &bus
->m_rt_list
, bus_node
) {
403 rate
= m_rt
->stream
->params
.rate
;
404 bps
= m_rt
->stream
->params
.bps
;
405 sample_int
= (bus
->params
.curr_dr_freq
/ rate
);
406 list_for_each_entry(p_rt
, &m_rt
->port_list
, port_node
) {
407 port_bo
= (p_rt
->num
* 64) + 1;
408 dev_dbg(bus
->dev
, "p_rt->num=%d hstart=%d hstop=%d port_bo=%d\n",
409 p_rt
->num
, hstart
, hstop
, port_bo
);
410 sdw_fill_xport_params(&p_rt
->transport_params
, p_rt
->num
,
411 false, SDW_BLK_GRP_CNT_1
, sample_int
,
412 port_bo
, port_bo
>> 8, hstart
, hstop
,
413 SDW_BLK_PKG_PER_PORT
, 0x0);
415 sdw_fill_port_params(&p_rt
->port_params
,
417 SDW_PORT_FLOW_MODE_ISOCH
,
418 b_params
->m_data_mode
);
419 t_data
.hstart
= hstart
;
420 t_data
.hstop
= hstop
;
421 t_data
.block_offset
= port_bo
;
422 t_data
.sub_block_offset
= 0;
424 sdw_compute_slave_ports(m_rt
, &t_data
);
429 static int amd_sdw_port_params(struct sdw_bus
*bus
, struct sdw_port_params
*p_params
,
432 struct amd_sdw_manager
*amd_manager
= to_amd_sdw(bus
);
433 u32 frame_fmt_reg
, dpn_frame_fmt
;
435 dev_dbg(amd_manager
->dev
, "p_params->num:0x%x\n", p_params
->num
);
436 switch (amd_manager
->acp_rev
) {
437 case ACP63_PCI_REV_ID
:
438 switch (amd_manager
->instance
) {
440 frame_fmt_reg
= acp63_sdw0_dp_reg
[p_params
->num
].frame_fmt_reg
;
443 frame_fmt_reg
= acp63_sdw1_dp_reg
[p_params
->num
].frame_fmt_reg
;
453 dpn_frame_fmt
= readl(amd_manager
->mmio
+ frame_fmt_reg
);
454 u32p_replace_bits(&dpn_frame_fmt
, p_params
->flow_mode
, AMD_DPN_FRAME_FMT_PFM
);
455 u32p_replace_bits(&dpn_frame_fmt
, p_params
->data_mode
, AMD_DPN_FRAME_FMT_PDM
);
456 u32p_replace_bits(&dpn_frame_fmt
, p_params
->bps
- 1, AMD_DPN_FRAME_FMT_WORD_LEN
);
457 writel(dpn_frame_fmt
, amd_manager
->mmio
+ frame_fmt_reg
);
461 static int amd_sdw_transport_params(struct sdw_bus
*bus
,
462 struct sdw_transport_params
*params
,
463 enum sdw_reg_bank bank
)
465 struct amd_sdw_manager
*amd_manager
= to_amd_sdw(bus
);
467 u32 dpn_sampleinterval
;
471 u32 frame_fmt_reg
, sample_int_reg
, hctrl_dp0_reg
;
472 u32 offset_reg
, lane_ctrl_ch_en_reg
;
474 switch (amd_manager
->acp_rev
) {
475 case ACP63_PCI_REV_ID
:
476 switch (amd_manager
->instance
) {
478 frame_fmt_reg
= acp63_sdw0_dp_reg
[params
->port_num
].frame_fmt_reg
;
479 sample_int_reg
= acp63_sdw0_dp_reg
[params
->port_num
].sample_int_reg
;
480 hctrl_dp0_reg
= acp63_sdw0_dp_reg
[params
->port_num
].hctrl_dp0_reg
;
481 offset_reg
= acp63_sdw0_dp_reg
[params
->port_num
].offset_reg
;
482 lane_ctrl_ch_en_reg
=
483 acp63_sdw0_dp_reg
[params
->port_num
].lane_ctrl_ch_en_reg
;
486 frame_fmt_reg
= acp63_sdw1_dp_reg
[params
->port_num
].frame_fmt_reg
;
487 sample_int_reg
= acp63_sdw1_dp_reg
[params
->port_num
].sample_int_reg
;
488 hctrl_dp0_reg
= acp63_sdw1_dp_reg
[params
->port_num
].hctrl_dp0_reg
;
489 offset_reg
= acp63_sdw1_dp_reg
[params
->port_num
].offset_reg
;
490 lane_ctrl_ch_en_reg
=
491 acp63_sdw1_dp_reg
[params
->port_num
].lane_ctrl_ch_en_reg
;
500 writel(AMD_SDW_SSP_COUNTER_VAL
, amd_manager
->mmio
+ ACP_SW_SSP_COUNTER
);
502 dpn_frame_fmt
= readl(amd_manager
->mmio
+ frame_fmt_reg
);
503 u32p_replace_bits(&dpn_frame_fmt
, params
->blk_pkg_mode
, AMD_DPN_FRAME_FMT_BLK_PKG_MODE
);
504 u32p_replace_bits(&dpn_frame_fmt
, params
->blk_grp_ctrl
, AMD_DPN_FRAME_FMT_BLK_GRP_CTRL
);
505 u32p_replace_bits(&dpn_frame_fmt
, SDW_STREAM_PCM
, AMD_DPN_FRAME_FMT_PCM_OR_PDM
);
506 writel(dpn_frame_fmt
, amd_manager
->mmio
+ frame_fmt_reg
);
508 dpn_sampleinterval
= params
->sample_interval
- 1;
509 writel(dpn_sampleinterval
, amd_manager
->mmio
+ sample_int_reg
);
511 dpn_hctrl
= FIELD_PREP(AMD_DPN_HCTRL_HSTOP
, params
->hstop
);
512 dpn_hctrl
|= FIELD_PREP(AMD_DPN_HCTRL_HSTART
, params
->hstart
);
513 writel(dpn_hctrl
, amd_manager
->mmio
+ hctrl_dp0_reg
);
515 dpn_offsetctrl
= FIELD_PREP(AMD_DPN_OFFSET_CTRL_1
, params
->offset1
);
516 dpn_offsetctrl
|= FIELD_PREP(AMD_DPN_OFFSET_CTRL_2
, params
->offset2
);
517 writel(dpn_offsetctrl
, amd_manager
->mmio
+ offset_reg
);
520 * lane_ctrl_ch_en_reg will be used to program lane_ctrl and ch_mask
523 dpn_lanectrl
= readl(amd_manager
->mmio
+ lane_ctrl_ch_en_reg
);
524 u32p_replace_bits(&dpn_lanectrl
, params
->lane_ctrl
, AMD_DPN_CH_EN_LCTRL
);
525 writel(dpn_lanectrl
, amd_manager
->mmio
+ lane_ctrl_ch_en_reg
);
529 static int amd_sdw_port_enable(struct sdw_bus
*bus
,
530 struct sdw_enable_ch
*enable_ch
,
533 struct amd_sdw_manager
*amd_manager
= to_amd_sdw(bus
);
535 u32 lane_ctrl_ch_en_reg
;
537 switch (amd_manager
->acp_rev
) {
538 case ACP63_PCI_REV_ID
:
539 switch (amd_manager
->instance
) {
541 lane_ctrl_ch_en_reg
=
542 acp63_sdw0_dp_reg
[enable_ch
->port_num
].lane_ctrl_ch_en_reg
;
545 lane_ctrl_ch_en_reg
=
546 acp63_sdw1_dp_reg
[enable_ch
->port_num
].lane_ctrl_ch_en_reg
;
557 * lane_ctrl_ch_en_reg will be used to program lane_ctrl and ch_mask
560 dpn_ch_enable
= readl(amd_manager
->mmio
+ lane_ctrl_ch_en_reg
);
561 u32p_replace_bits(&dpn_ch_enable
, enable_ch
->ch_mask
, AMD_DPN_CH_EN_CHMASK
);
562 if (enable_ch
->enable
)
563 writel(dpn_ch_enable
, amd_manager
->mmio
+ lane_ctrl_ch_en_reg
);
565 writel(0, amd_manager
->mmio
+ lane_ctrl_ch_en_reg
);
569 static int sdw_master_read_amd_prop(struct sdw_bus
*bus
)
571 struct amd_sdw_manager
*amd_manager
= to_amd_sdw(bus
);
572 struct fwnode_handle
*link
;
573 struct sdw_master_prop
*prop
;
575 u32 wake_en_mask
= 0;
576 u32 power_mode_mask
= 0;
580 /* Find manager handle */
581 snprintf(name
, sizeof(name
), "mipi-sdw-link-%d-subproperties", bus
->link_id
);
582 link
= device_get_named_child_node(bus
->dev
, name
);
584 dev_err(bus
->dev
, "Manager node %s not found\n", name
);
587 fwnode_property_read_u32(link
, "amd-sdw-enable", &quirk_mask
);
588 if (!(quirk_mask
& AMD_SDW_QUIRK_MASK_BUS_ENABLE
))
589 prop
->hw_disabled
= true;
590 prop
->quirks
= SDW_MASTER_QUIRKS_CLEAR_INITIAL_CLASH
|
591 SDW_MASTER_QUIRKS_CLEAR_INITIAL_PARITY
;
593 fwnode_property_read_u32(link
, "amd-sdw-wakeup-enable", &wake_en_mask
);
594 amd_manager
->wake_en_mask
= wake_en_mask
;
595 fwnode_property_read_u32(link
, "amd-sdw-power-mode", &power_mode_mask
);
596 amd_manager
->power_mode_mask
= power_mode_mask
;
598 fwnode_handle_put(link
);
603 static int amd_prop_read(struct sdw_bus
*bus
)
605 sdw_master_read_prop(bus
);
606 sdw_master_read_amd_prop(bus
);
610 static const struct sdw_master_port_ops amd_sdw_port_ops
= {
611 .dpn_set_port_params
= amd_sdw_port_params
,
612 .dpn_set_port_transport_params
= amd_sdw_transport_params
,
613 .dpn_port_enable_ch
= amd_sdw_port_enable
,
616 static const struct sdw_master_ops amd_sdw_ops
= {
617 .read_prop
= amd_prop_read
,
618 .xfer_msg
= amd_sdw_xfer_msg
,
619 .read_ping_status
= amd_sdw_read_ping_status
,
622 static int amd_sdw_hw_params(struct snd_pcm_substream
*substream
,
623 struct snd_pcm_hw_params
*params
,
624 struct snd_soc_dai
*dai
)
626 struct amd_sdw_manager
*amd_manager
= snd_soc_dai_get_drvdata(dai
);
627 struct sdw_amd_dai_runtime
*dai_runtime
;
628 struct sdw_stream_config sconfig
;
632 dai_runtime
= amd_manager
->dai_runtime_array
[dai
->id
];
636 ch
= params_channels(params
);
637 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
638 dir
= SDW_DATA_DIR_RX
;
640 dir
= SDW_DATA_DIR_TX
;
641 dev_dbg(amd_manager
->dev
, "dir:%d dai->id:0x%x\n", dir
, dai
->id
);
643 sconfig
.direction
= dir
;
644 sconfig
.ch_count
= ch
;
645 sconfig
.frame_rate
= params_rate(params
);
646 sconfig
.type
= dai_runtime
->stream_type
;
648 sconfig
.bps
= snd_pcm_format_width(params_format(params
));
650 /* Port configuration */
651 struct sdw_port_config
*pconfig
__free(kfree
) = kzalloc(sizeof(*pconfig
),
656 pconfig
->num
= dai
->id
;
657 pconfig
->ch_mask
= (1 << ch
) - 1;
658 ret
= sdw_stream_add_master(&amd_manager
->bus
, &sconfig
,
659 pconfig
, 1, dai_runtime
->stream
);
661 dev_err(amd_manager
->dev
, "add manager to stream failed:%d\n", ret
);
666 static int amd_sdw_hw_free(struct snd_pcm_substream
*substream
, struct snd_soc_dai
*dai
)
668 struct amd_sdw_manager
*amd_manager
= snd_soc_dai_get_drvdata(dai
);
669 struct sdw_amd_dai_runtime
*dai_runtime
;
672 dai_runtime
= amd_manager
->dai_runtime_array
[dai
->id
];
676 ret
= sdw_stream_remove_master(&amd_manager
->bus
, dai_runtime
->stream
);
678 dev_err(dai
->dev
, "remove manager from stream %s failed: %d\n",
679 dai_runtime
->stream
->name
, ret
);
683 static int amd_set_sdw_stream(struct snd_soc_dai
*dai
, void *stream
, int direction
)
685 struct amd_sdw_manager
*amd_manager
= snd_soc_dai_get_drvdata(dai
);
686 struct sdw_amd_dai_runtime
*dai_runtime
;
688 dai_runtime
= amd_manager
->dai_runtime_array
[dai
->id
];
690 /* first paranoia check */
692 dev_err(dai
->dev
, "dai_runtime already allocated for dai %s\n", dai
->name
);
696 /* allocate and set dai_runtime info */
697 dai_runtime
= kzalloc(sizeof(*dai_runtime
), GFP_KERNEL
);
701 dai_runtime
->stream_type
= SDW_STREAM_PCM
;
702 dai_runtime
->bus
= &amd_manager
->bus
;
703 dai_runtime
->stream
= stream
;
704 amd_manager
->dai_runtime_array
[dai
->id
] = dai_runtime
;
706 /* second paranoia check */
708 dev_err(dai
->dev
, "dai_runtime not allocated for dai %s\n", dai
->name
);
712 /* for NULL stream we release allocated dai_runtime */
714 amd_manager
->dai_runtime_array
[dai
->id
] = NULL
;
719 static int amd_pcm_set_sdw_stream(struct snd_soc_dai
*dai
, void *stream
, int direction
)
721 return amd_set_sdw_stream(dai
, stream
, direction
);
724 static void *amd_get_sdw_stream(struct snd_soc_dai
*dai
, int direction
)
726 struct amd_sdw_manager
*amd_manager
= snd_soc_dai_get_drvdata(dai
);
727 struct sdw_amd_dai_runtime
*dai_runtime
;
729 dai_runtime
= amd_manager
->dai_runtime_array
[dai
->id
];
731 return ERR_PTR(-EINVAL
);
733 return dai_runtime
->stream
;
736 static const struct snd_soc_dai_ops amd_sdw_dai_ops
= {
737 .hw_params
= amd_sdw_hw_params
,
738 .hw_free
= amd_sdw_hw_free
,
739 .set_stream
= amd_pcm_set_sdw_stream
,
740 .get_stream
= amd_get_sdw_stream
,
743 static const struct snd_soc_component_driver amd_sdw_dai_component
= {
747 static int amd_sdw_register_dais(struct amd_sdw_manager
*amd_manager
)
749 struct sdw_amd_dai_runtime
**dai_runtime_array
;
750 struct snd_soc_dai_driver
*dais
;
751 struct snd_soc_pcm_stream
*stream
;
755 dev
= amd_manager
->dev
;
756 num_dais
= amd_manager
->num_dout_ports
+ amd_manager
->num_din_ports
;
757 dais
= devm_kcalloc(dev
, num_dais
, sizeof(*dais
), GFP_KERNEL
);
761 dai_runtime_array
= devm_kcalloc(dev
, num_dais
,
762 sizeof(struct sdw_amd_dai_runtime
*),
764 if (!dai_runtime_array
)
766 amd_manager
->dai_runtime_array
= dai_runtime_array
;
767 for (i
= 0; i
< num_dais
; i
++) {
768 dais
[i
].name
= devm_kasprintf(dev
, GFP_KERNEL
, "SDW%d Pin%d", amd_manager
->instance
,
772 if (i
< amd_manager
->num_dout_ports
)
773 stream
= &dais
[i
].playback
;
775 stream
= &dais
[i
].capture
;
777 stream
->channels_min
= 2;
778 stream
->channels_max
= 2;
779 stream
->rates
= SNDRV_PCM_RATE_48000
;
780 stream
->formats
= SNDRV_PCM_FMTBIT_S16_LE
;
782 dais
[i
].ops
= &amd_sdw_dai_ops
;
786 return devm_snd_soc_register_component(dev
, &amd_sdw_dai_component
,
790 static void amd_sdw_update_slave_status_work(struct work_struct
*work
)
792 struct amd_sdw_manager
*amd_manager
=
793 container_of(work
, struct amd_sdw_manager
, amd_sdw_work
);
796 if (amd_manager
->status
[0] == SDW_SLAVE_ATTACHED
) {
797 writel(0, amd_manager
->mmio
+ ACP_SW_STATE_CHANGE_STATUS_MASK_0TO7
);
798 writel(0, amd_manager
->mmio
+ ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11
);
802 sdw_handle_slave_status(&amd_manager
->bus
, amd_manager
->status
);
804 * During the peripheral enumeration sequence, the SoundWire manager interrupts
805 * are masked. Once the device number programming is done for all peripherals,
806 * interrupts will be unmasked. Read the peripheral device status from ping command
807 * and process the response. This sequence will ensure all peripheral devices enumerated
808 * and initialized properly.
810 if (amd_manager
->status
[0] == SDW_SLAVE_ATTACHED
) {
811 if (retry_count
++ < SDW_MAX_DEVICES
) {
812 writel(AMD_SDW_IRQ_MASK_0TO7
, amd_manager
->mmio
+
813 ACP_SW_STATE_CHANGE_STATUS_MASK_0TO7
);
814 writel(AMD_SDW_IRQ_MASK_8TO11
, amd_manager
->mmio
+
815 ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11
);
816 amd_sdw_read_and_process_ping_status(amd_manager
);
819 dev_err_ratelimited(amd_manager
->dev
,
820 "Device0 detected after %d iterations\n",
826 static void amd_sdw_update_slave_status(u32 status_change_0to7
, u32 status_change_8to11
,
827 struct amd_sdw_manager
*amd_manager
)
833 if (status_change_0to7
== AMD_SDW_SLAVE_0_ATTACHED
)
834 memset(amd_manager
->status
, 0, sizeof(amd_manager
->status
));
835 slave_stat
= status_change_0to7
;
836 slave_stat
|= FIELD_GET(AMD_SDW_MCP_SLAVE_STATUS_8TO_11
, status_change_8to11
) << 32;
837 dev_dbg(amd_manager
->dev
, "status_change_0to7:0x%x status_change_8to11:0x%x\n",
838 status_change_0to7
, status_change_8to11
);
840 for (dev_index
= 0; dev_index
<= SDW_MAX_DEVICES
; ++dev_index
) {
841 if (slave_stat
& AMD_SDW_MCP_SLAVE_STATUS_VALID_MASK(dev_index
)) {
842 val
= (slave_stat
>> AMD_SDW_MCP_SLAVE_STAT_SHIFT_MASK(dev_index
)) &
843 AMD_SDW_MCP_SLAVE_STATUS_MASK
;
844 amd_sdw_fill_slave_status(amd_manager
, dev_index
, val
);
850 static void amd_sdw_process_wake_event(struct amd_sdw_manager
*amd_manager
)
852 pm_request_resume(amd_manager
->dev
);
853 writel(0x00, amd_manager
->acp_mmio
+ ACP_SW_WAKE_EN(amd_manager
->instance
));
854 writel(0x00, amd_manager
->mmio
+ ACP_SW_STATE_CHANGE_STATUS_8TO11
);
857 static void amd_sdw_irq_thread(struct work_struct
*work
)
859 struct amd_sdw_manager
*amd_manager
=
860 container_of(work
, struct amd_sdw_manager
, amd_sdw_irq_thread
);
861 u32 status_change_8to11
;
862 u32 status_change_0to7
;
864 status_change_8to11
= readl(amd_manager
->mmio
+ ACP_SW_STATE_CHANGE_STATUS_8TO11
);
865 status_change_0to7
= readl(amd_manager
->mmio
+ ACP_SW_STATE_CHANGE_STATUS_0TO7
);
866 dev_dbg(amd_manager
->dev
, "[SDW%d] SDW INT: 0to7=0x%x, 8to11=0x%x\n",
867 amd_manager
->instance
, status_change_0to7
, status_change_8to11
);
868 if (status_change_8to11
& AMD_SDW_WAKE_STAT_MASK
)
869 return amd_sdw_process_wake_event(amd_manager
);
871 if (status_change_8to11
& AMD_SDW_PREQ_INTR_STAT
) {
872 amd_sdw_read_and_process_ping_status(amd_manager
);
874 /* Check for the updated status on peripheral device */
875 amd_sdw_update_slave_status(status_change_0to7
, status_change_8to11
, amd_manager
);
877 if (status_change_8to11
|| status_change_0to7
)
878 schedule_work(&amd_manager
->amd_sdw_work
);
879 writel(0x00, amd_manager
->mmio
+ ACP_SW_STATE_CHANGE_STATUS_8TO11
);
880 writel(0x00, amd_manager
->mmio
+ ACP_SW_STATE_CHANGE_STATUS_0TO7
);
883 int amd_sdw_manager_start(struct amd_sdw_manager
*amd_manager
)
885 struct sdw_master_prop
*prop
;
888 prop
= &amd_manager
->bus
.prop
;
889 if (!prop
->hw_disabled
) {
890 ret
= amd_init_sdw_manager(amd_manager
);
893 amd_enable_sdw_interrupts(amd_manager
);
894 ret
= amd_enable_sdw_manager(amd_manager
);
897 amd_sdw_set_frameshape(amd_manager
);
899 /* Enable runtime PM */
900 pm_runtime_set_autosuspend_delay(amd_manager
->dev
, AMD_SDW_MASTER_SUSPEND_DELAY_MS
);
901 pm_runtime_use_autosuspend(amd_manager
->dev
);
902 pm_runtime_mark_last_busy(amd_manager
->dev
);
903 pm_runtime_set_active(amd_manager
->dev
);
904 pm_runtime_enable(amd_manager
->dev
);
908 static int amd_sdw_manager_probe(struct platform_device
*pdev
)
910 const struct acp_sdw_pdata
*pdata
= pdev
->dev
.platform_data
;
911 struct resource
*res
;
912 struct device
*dev
= &pdev
->dev
;
913 struct sdw_master_prop
*prop
;
914 struct sdw_bus_params
*params
;
915 struct amd_sdw_manager
*amd_manager
;
918 amd_manager
= devm_kzalloc(dev
, sizeof(struct amd_sdw_manager
), GFP_KERNEL
);
922 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
926 amd_manager
->acp_mmio
= devm_ioremap(dev
, res
->start
, resource_size(res
));
927 if (!amd_manager
->acp_mmio
) {
928 dev_err(dev
, "mmio not found\n");
931 amd_manager
->instance
= pdata
->instance
;
932 amd_manager
->mmio
= amd_manager
->acp_mmio
+
933 (amd_manager
->instance
* SDW_MANAGER_REG_OFFSET
);
934 amd_manager
->acp_sdw_lock
= pdata
->acp_sdw_lock
;
935 amd_manager
->acp_rev
= pdata
->acp_rev
;
936 amd_manager
->cols_index
= sdw_find_col_index(AMD_SDW_DEFAULT_COLUMNS
);
937 amd_manager
->rows_index
= sdw_find_row_index(AMD_SDW_DEFAULT_ROWS
);
938 amd_manager
->dev
= dev
;
939 amd_manager
->bus
.ops
= &amd_sdw_ops
;
940 amd_manager
->bus
.port_ops
= &amd_sdw_port_ops
;
941 amd_manager
->bus
.compute_params
= &amd_sdw_compute_params
;
942 amd_manager
->bus
.clk_stop_timeout
= 200;
943 amd_manager
->bus
.link_id
= amd_manager
->instance
;
946 * Due to BIOS compatibility, the two links are exposed within
947 * the scope of a single controller. If this changes, the
948 * controller_id will have to be updated with drv_data
951 amd_manager
->bus
.controller_id
= 0;
952 dev_dbg(dev
, "acp_rev:0x%x\n", amd_manager
->acp_rev
);
953 switch (amd_manager
->acp_rev
) {
954 case ACP63_PCI_REV_ID
:
955 switch (amd_manager
->instance
) {
957 amd_manager
->num_dout_ports
= AMD_ACP63_SDW0_MAX_TX_PORTS
;
958 amd_manager
->num_din_ports
= AMD_ACP63_SDW0_MAX_RX_PORTS
;
961 amd_manager
->num_dout_ports
= AMD_ACP63_SDW1_MAX_TX_PORTS
;
962 amd_manager
->num_din_ports
= AMD_ACP63_SDW1_MAX_RX_PORTS
;
972 params
= &amd_manager
->bus
.params
;
974 params
->col
= AMD_SDW_DEFAULT_COLUMNS
;
975 params
->row
= AMD_SDW_DEFAULT_ROWS
;
976 prop
= &amd_manager
->bus
.prop
;
977 prop
->clk_freq
= &amd_sdw_freq_tbl
[0];
978 prop
->mclk_freq
= AMD_SDW_BUS_BASE_FREQ
;
979 prop
->max_clk_freq
= AMD_SDW_DEFAULT_CLK_FREQ
;
981 ret
= sdw_bus_master_add(&amd_manager
->bus
, dev
, dev
->fwnode
);
983 dev_err(dev
, "Failed to register SoundWire manager(%d)\n", ret
);
986 ret
= amd_sdw_register_dais(amd_manager
);
988 dev_err(dev
, "CPU DAI registration failed\n");
989 sdw_bus_master_delete(&amd_manager
->bus
);
992 dev_set_drvdata(dev
, amd_manager
);
993 INIT_WORK(&amd_manager
->amd_sdw_irq_thread
, amd_sdw_irq_thread
);
994 INIT_WORK(&amd_manager
->amd_sdw_work
, amd_sdw_update_slave_status_work
);
998 static void amd_sdw_manager_remove(struct platform_device
*pdev
)
1000 struct amd_sdw_manager
*amd_manager
= dev_get_drvdata(&pdev
->dev
);
1003 pm_runtime_disable(&pdev
->dev
);
1004 amd_disable_sdw_interrupts(amd_manager
);
1005 sdw_bus_master_delete(&amd_manager
->bus
);
1006 ret
= amd_disable_sdw_manager(amd_manager
);
1008 dev_err(&pdev
->dev
, "Failed to disable device (%pe)\n", ERR_PTR(ret
));
1011 static int amd_sdw_clock_stop(struct amd_sdw_manager
*amd_manager
)
1016 ret
= sdw_bus_prep_clk_stop(&amd_manager
->bus
);
1017 if (ret
< 0 && ret
!= -ENODATA
) {
1018 dev_err(amd_manager
->dev
, "prepare clock stop failed %d", ret
);
1021 ret
= sdw_bus_clk_stop(&amd_manager
->bus
);
1022 if (ret
< 0 && ret
!= -ENODATA
) {
1023 dev_err(amd_manager
->dev
, "bus clock stop failed %d", ret
);
1027 ret
= readl_poll_timeout(amd_manager
->mmio
+ ACP_SW_CLK_RESUME_CTRL
, val
,
1028 (val
& AMD_SDW_CLK_STOP_DONE
), ACP_DELAY_US
, AMD_SDW_TIMEOUT
);
1030 dev_err(amd_manager
->dev
, "SDW%x clock stop failed\n", amd_manager
->instance
);
1034 amd_manager
->clk_stopped
= true;
1035 if (amd_manager
->wake_en_mask
)
1036 writel(0x01, amd_manager
->acp_mmio
+ ACP_SW_WAKE_EN(amd_manager
->instance
));
1038 dev_dbg(amd_manager
->dev
, "SDW%x clock stop successful\n", amd_manager
->instance
);
1042 static int amd_sdw_clock_stop_exit(struct amd_sdw_manager
*amd_manager
)
1047 if (amd_manager
->clk_stopped
) {
1048 val
= readl(amd_manager
->mmio
+ ACP_SW_CLK_RESUME_CTRL
);
1049 val
|= AMD_SDW_CLK_RESUME_REQ
;
1050 writel(val
, amd_manager
->mmio
+ ACP_SW_CLK_RESUME_CTRL
);
1051 ret
= readl_poll_timeout(amd_manager
->mmio
+ ACP_SW_CLK_RESUME_CTRL
, val
,
1052 (val
& AMD_SDW_CLK_RESUME_DONE
), ACP_DELAY_US
,
1054 if (val
& AMD_SDW_CLK_RESUME_DONE
) {
1055 writel(0, amd_manager
->mmio
+ ACP_SW_CLK_RESUME_CTRL
);
1056 ret
= sdw_bus_exit_clk_stop(&amd_manager
->bus
);
1058 dev_err(amd_manager
->dev
, "bus failed to exit clock stop %d\n",
1060 amd_manager
->clk_stopped
= false;
1063 if (amd_manager
->clk_stopped
) {
1064 dev_err(amd_manager
->dev
, "SDW%x clock stop exit failed\n", amd_manager
->instance
);
1067 dev_dbg(amd_manager
->dev
, "SDW%x clock stop exit successful\n", amd_manager
->instance
);
1071 static int amd_resume_child_device(struct device
*dev
, void *data
)
1073 struct sdw_slave
*slave
= dev_to_sdw_dev(dev
);
1076 if (!slave
->probed
) {
1077 dev_dbg(dev
, "skipping device, no probed driver\n");
1080 if (!slave
->dev_num_sticky
) {
1081 dev_dbg(dev
, "skipping device, never detected on bus\n");
1084 ret
= pm_request_resume(dev
);
1086 dev_err(dev
, "pm_request_resume failed: %d\n", ret
);
1092 static int __maybe_unused
amd_pm_prepare(struct device
*dev
)
1094 struct amd_sdw_manager
*amd_manager
= dev_get_drvdata(dev
);
1095 struct sdw_bus
*bus
= &amd_manager
->bus
;
1098 if (bus
->prop
.hw_disabled
) {
1099 dev_dbg(bus
->dev
, "SoundWire manager %d is disabled, ignoring\n",
1104 * When multiple peripheral devices connected over the same link, if SoundWire manager
1105 * device is not in runtime suspend state, observed that device alerts are missing
1106 * without pm_prepare on AMD platforms in clockstop mode0.
1108 if (amd_manager
->power_mode_mask
& AMD_SDW_CLK_STOP_MODE
) {
1109 ret
= pm_request_resume(dev
);
1111 dev_err(bus
->dev
, "pm_request_resume failed: %d\n", ret
);
1115 /* To force peripheral devices to system level suspend state, resume the devices
1116 * from runtime suspend state first. Without that unable to dispatch the alert
1117 * status to peripheral driver during system level resume as they are in runtime
1120 ret
= device_for_each_child(bus
->dev
, NULL
, amd_resume_child_device
);
1122 dev_err(dev
, "amd_resume_child_device failed: %d\n", ret
);
1126 static int __maybe_unused
amd_suspend(struct device
*dev
)
1128 struct amd_sdw_manager
*amd_manager
= dev_get_drvdata(dev
);
1129 struct sdw_bus
*bus
= &amd_manager
->bus
;
1132 if (bus
->prop
.hw_disabled
) {
1133 dev_dbg(bus
->dev
, "SoundWire manager %d is disabled, ignoring\n",
1138 if (amd_manager
->power_mode_mask
& AMD_SDW_CLK_STOP_MODE
) {
1139 amd_sdw_wake_enable(amd_manager
, false);
1140 return amd_sdw_clock_stop(amd_manager
);
1141 } else if (amd_manager
->power_mode_mask
& AMD_SDW_POWER_OFF_MODE
) {
1143 * As per hardware programming sequence on AMD platforms,
1144 * clock stop should be invoked first before powering-off
1146 ret
= amd_sdw_clock_stop(amd_manager
);
1149 return amd_deinit_sdw_manager(amd_manager
);
1154 static int __maybe_unused
amd_suspend_runtime(struct device
*dev
)
1156 struct amd_sdw_manager
*amd_manager
= dev_get_drvdata(dev
);
1157 struct sdw_bus
*bus
= &amd_manager
->bus
;
1160 if (bus
->prop
.hw_disabled
) {
1161 dev_dbg(bus
->dev
, "SoundWire manager %d is disabled,\n",
1165 if (amd_manager
->power_mode_mask
& AMD_SDW_CLK_STOP_MODE
) {
1166 amd_sdw_wake_enable(amd_manager
, true);
1167 return amd_sdw_clock_stop(amd_manager
);
1168 } else if (amd_manager
->power_mode_mask
& AMD_SDW_POWER_OFF_MODE
) {
1169 ret
= amd_sdw_clock_stop(amd_manager
);
1172 return amd_deinit_sdw_manager(amd_manager
);
1177 static int __maybe_unused
amd_resume_runtime(struct device
*dev
)
1179 struct amd_sdw_manager
*amd_manager
= dev_get_drvdata(dev
);
1180 struct sdw_bus
*bus
= &amd_manager
->bus
;
1184 if (bus
->prop
.hw_disabled
) {
1185 dev_dbg(bus
->dev
, "SoundWire manager %d is disabled, ignoring\n",
1190 if (amd_manager
->power_mode_mask
& AMD_SDW_CLK_STOP_MODE
) {
1191 return amd_sdw_clock_stop_exit(amd_manager
);
1192 } else if (amd_manager
->power_mode_mask
& AMD_SDW_POWER_OFF_MODE
) {
1193 val
= readl(amd_manager
->mmio
+ ACP_SW_CLK_RESUME_CTRL
);
1195 val
|= AMD_SDW_CLK_RESUME_REQ
;
1196 writel(val
, amd_manager
->mmio
+ ACP_SW_CLK_RESUME_CTRL
);
1197 ret
= readl_poll_timeout(amd_manager
->mmio
+ ACP_SW_CLK_RESUME_CTRL
, val
,
1198 (val
& AMD_SDW_CLK_RESUME_DONE
), ACP_DELAY_US
,
1200 if (val
& AMD_SDW_CLK_RESUME_DONE
) {
1201 writel(0, amd_manager
->mmio
+ ACP_SW_CLK_RESUME_CTRL
);
1202 amd_manager
->clk_stopped
= false;
1205 sdw_clear_slave_status(bus
, SDW_UNATTACH_REQUEST_MASTER_RESET
);
1206 amd_init_sdw_manager(amd_manager
);
1207 amd_enable_sdw_interrupts(amd_manager
);
1208 ret
= amd_enable_sdw_manager(amd_manager
);
1211 amd_sdw_set_frameshape(amd_manager
);
1216 static const struct dev_pm_ops amd_pm
= {
1217 .prepare
= amd_pm_prepare
,
1218 SET_SYSTEM_SLEEP_PM_OPS(amd_suspend
, amd_resume_runtime
)
1219 SET_RUNTIME_PM_OPS(amd_suspend_runtime
, amd_resume_runtime
, NULL
)
1222 static struct platform_driver amd_sdw_driver
= {
1223 .probe
= &amd_sdw_manager_probe
,
1224 .remove
= &amd_sdw_manager_remove
,
1226 .name
= "amd_sdw_manager",
1230 module_platform_driver(amd_sdw_driver
);
1232 MODULE_AUTHOR("Vijendar.Mukunda@amd.com");
1233 MODULE_DESCRIPTION("AMD SoundWire driver");
1234 MODULE_LICENSE("Dual BSD/GPL");
1235 MODULE_ALIAS("platform:" DRV_NAME
);