Lines Matching +full:soundwire +full:- +full:controller
1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
3 * SoundWire AMD Manager driver
5 * Copyright 2023-24 Advanced Micro Devices, Inc.
16 #include <linux/soundwire/sdw.h>
17 #include <linux/soundwire/sdw_registers.h>
35 writel(AMD_SDW_ENABLE, amd_manager->mmio + ACP_SW_EN); in amd_init_sdw_manager()
36 ret = readl_poll_timeout(amd_manager->mmio + ACP_SW_EN_STATUS, val, val, ACP_DELAY_US, in amd_init_sdw_manager()
41 /* SoundWire manager bus reset */ in amd_init_sdw_manager()
42 writel(AMD_SDW_BUS_RESET_REQ, amd_manager->mmio + ACP_SW_BUS_RESET_CTRL); in amd_init_sdw_manager()
43 ret = readl_poll_timeout(amd_manager->mmio + ACP_SW_BUS_RESET_CTRL, val, in amd_init_sdw_manager()
48 writel(AMD_SDW_BUS_RESET_CLEAR_REQ, amd_manager->mmio + ACP_SW_BUS_RESET_CTRL); in amd_init_sdw_manager()
49 ret = readl_poll_timeout(amd_manager->mmio + ACP_SW_BUS_RESET_CTRL, val, !val, in amd_init_sdw_manager()
52 dev_err(amd_manager->dev, "Failed to reset SoundWire manager instance%d\n", in amd_init_sdw_manager()
53 amd_manager->instance); in amd_init_sdw_manager()
57 writel(AMD_SDW_DISABLE, amd_manager->mmio + ACP_SW_EN); in amd_init_sdw_manager()
58 return readl_poll_timeout(amd_manager->mmio + ACP_SW_EN_STATUS, val, !val, ACP_DELAY_US, in amd_init_sdw_manager()
66 writel(AMD_SDW_ENABLE, amd_manager->mmio + ACP_SW_EN); in amd_enable_sdw_manager()
67 return readl_poll_timeout(amd_manager->mmio + ACP_SW_EN_STATUS, val, val, ACP_DELAY_US, in amd_enable_sdw_manager()
75 writel(AMD_SDW_DISABLE, amd_manager->mmio + ACP_SW_EN); in amd_disable_sdw_manager()
81 val = readl(amd_manager->mmio + ACP_SW_CLK_RESUME_CTRL); in amd_disable_sdw_manager()
84 return readl_poll_timeout(amd_manager->mmio + ACP_SW_EN_STATUS, val, !val, ACP_DELAY_US, in amd_disable_sdw_manager()
92 mutex_lock(amd_manager->acp_sdw_lock); in amd_enable_sdw_interrupts()
93 val = sdw_manager_reg_mask_array[amd_manager->instance]; in amd_enable_sdw_interrupts()
94 amd_updatel(amd_manager->acp_mmio, ACP_EXTERNAL_INTR_CNTL(amd_manager->instance), val, val); in amd_enable_sdw_interrupts()
95 mutex_unlock(amd_manager->acp_sdw_lock); in amd_enable_sdw_interrupts()
97 writel(AMD_SDW_IRQ_MASK_0TO7, amd_manager->mmio + in amd_enable_sdw_interrupts()
99 writel(AMD_SDW_IRQ_MASK_8TO11, amd_manager->mmio + in amd_enable_sdw_interrupts()
101 writel(AMD_SDW_IRQ_ERROR_MASK, amd_manager->mmio + ACP_SW_ERROR_INTR_MASK); in amd_enable_sdw_interrupts()
108 mutex_lock(amd_manager->acp_sdw_lock); in amd_disable_sdw_interrupts()
109 irq_mask = sdw_manager_reg_mask_array[amd_manager->instance]; in amd_disable_sdw_interrupts()
110 amd_updatel(amd_manager->acp_mmio, ACP_EXTERNAL_INTR_CNTL(amd_manager->instance), in amd_disable_sdw_interrupts()
112 mutex_unlock(amd_manager->acp_sdw_lock); in amd_disable_sdw_interrupts()
114 writel(0x00, amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_MASK_0TO7); in amd_disable_sdw_interrupts()
115 writel(0x00, amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11); in amd_disable_sdw_interrupts()
116 writel(0x00, amd_manager->mmio + ACP_SW_ERROR_INTR_MASK); in amd_disable_sdw_interrupts()
129 frame_size = (amd_manager->rows_index << 3) | amd_manager->cols_index; in amd_sdw_set_frameshape()
130 writel(frame_size, amd_manager->mmio + ACP_SW_FRAMESIZE); in amd_sdw_set_frameshape()
137 wake_ctrl = readl(amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11); in amd_sdw_wake_enable()
143 writel(wake_ctrl, amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11); in amd_sdw_wake_enable()
155 addr = msg->addr + cmd_offset; in amd_sdw_ctl_word_prep()
159 if (msg->flags == SDW_MSG_FLAG_WRITE) in amd_sdw_ctl_word_prep()
160 data = msg->buf[cmd_offset]; in amd_sdw_ctl_word_prep()
162 upper_data = FIELD_PREP(AMD_SDW_MCP_CMD_DEV_ADDR, msg->dev_num); in amd_sdw_ctl_word_prep()
163 upper_data |= FIELD_PREP(AMD_SDW_MCP_CMD_COMMAND, msg->flags + 2); in amd_sdw_ctl_word_prep()
180 ret = readl_poll_timeout(amd_manager->mmio + ACP_SW_IMM_CMD_STS, sts, in amd_sdw_send_cmd_get_resp()
183 dev_err(amd_manager->dev, "SDW%x previous cmd status clear failed\n", in amd_sdw_send_cmd_get_resp()
184 amd_manager->instance); in amd_sdw_send_cmd_get_resp()
189 dev_err(amd_manager->dev, "SDW%x manager is in bad state\n", amd_manager->instance); in amd_sdw_send_cmd_get_resp()
190 writel(0x00, amd_manager->mmio + ACP_SW_IMM_CMD_STS); in amd_sdw_send_cmd_get_resp()
192 writel(upper_data, amd_manager->mmio + ACP_SW_IMM_CMD_UPPER_WORD); in amd_sdw_send_cmd_get_resp()
193 writel(lower_data, amd_manager->mmio + ACP_SW_IMM_CMD_LOWER_QWORD); in amd_sdw_send_cmd_get_resp()
195 ret = readl_poll_timeout(amd_manager->mmio + ACP_SW_IMM_CMD_STS, sts, in amd_sdw_send_cmd_get_resp()
198 dev_err(amd_manager->dev, "SDW%x cmd response timeout occurred\n", in amd_sdw_send_cmd_get_resp()
199 amd_manager->instance); in amd_sdw_send_cmd_get_resp()
202 upper_resp = readl(amd_manager->mmio + ACP_SW_IMM_RESP_UPPER_WORD); in amd_sdw_send_cmd_get_resp()
203 lower_resp = readl(amd_manager->mmio + ACP_SW_IMM_RESP_LOWER_QWORD); in amd_sdw_send_cmd_get_resp()
205 writel(AMD_SDW_IMM_RES_VALID, amd_manager->mmio + ACP_SW_IMM_CMD_STS); in amd_sdw_send_cmd_get_resp()
206 ret = readl_poll_timeout(amd_manager->mmio + ACP_SW_IMM_CMD_STS, sts, in amd_sdw_send_cmd_get_resp()
209 dev_err(amd_manager->dev, "SDW%x cmd status retry failed\n", in amd_sdw_send_cmd_get_resp()
210 amd_manager->instance); in amd_sdw_send_cmd_get_resp()
226 scp_msg.dev_num = msg->dev_num; in amd_program_scp_addr()
228 scp_msg.buf = &msg->addr_page1; in amd_program_scp_addr()
233 scp_msg.buf = &msg->addr_page2; in amd_program_scp_addr()
238 if (response_buf[index] == -ETIMEDOUT) { in amd_program_scp_addr()
239 dev_err_ratelimited(amd_manager->dev, in amd_program_scp_addr()
241 msg->dev_num); in amd_program_scp_addr()
245 dev_err_ratelimited(amd_manager->dev, in amd_program_scp_addr()
247 msg->dev_num); in amd_program_scp_addr()
250 dev_dbg_ratelimited(amd_manager->dev, "SCP_addrpage ignored for Slave %d\n", in amd_program_scp_addr()
251 msg->dev_num); in amd_program_scp_addr()
262 if (msg->page) { in amd_prep_msg()
265 msg->len = 0; in amd_prep_msg()
269 switch (msg->flags) { in amd_prep_msg()
274 dev_err(amd_manager->dev, "Invalid msg cmd: %d\n", msg->flags); in amd_prep_msg()
275 return -EINVAL; in amd_prep_msg()
285 if (msg->flags == SDW_MSG_FLAG_READ) in amd_sdw_fill_msg_resp()
286 msg->buf[offset] = FIELD_GET(AMD_SDW_MCP_RESP_RDATA, response); in amd_sdw_fill_msg_resp()
288 if (response == -ETIMEDOUT) { in amd_sdw_fill_msg_resp()
289 dev_err_ratelimited(amd_manager->dev, "command timeout for Slave %d\n", in amd_sdw_fill_msg_resp()
290 msg->dev_num); in amd_sdw_fill_msg_resp()
293 dev_err_ratelimited(amd_manager->dev, in amd_sdw_fill_msg_resp()
295 msg->dev_num); in amd_sdw_fill_msg_resp()
298 dev_err_ratelimited(amd_manager->dev, "command is ignored for Slave %d\n", in amd_sdw_fill_msg_resp()
299 msg->dev_num); in amd_sdw_fill_msg_resp()
324 for (i = 0; i < msg->len; i++) { in amd_sdw_xfer_msg()
338 amd_manager->status[index] = status; in amd_sdw_fill_slave_status()
341 amd_manager->status[index] = SDW_SLAVE_RESERVED; in amd_sdw_fill_slave_status()
355 dev_dbg(amd_manager->dev, "slave_stat:0x%llx\n", slave_stat); in amd_sdw_process_ping_status()
358 dev_dbg(amd_manager->dev, "val:0x%x\n", val); in amd_sdw_process_ping_status()
367 mutex_lock(&amd_manager->bus.msg_lock); in amd_sdw_read_and_process_ping_status()
369 mutex_unlock(&amd_manager->bus.msg_lock); in amd_sdw_read_and_process_ping_status()
383 dev_dbg(amd_manager->dev, "slave_stat:0x%x\n", slave_stat); in amd_sdw_read_ping_status()
392 struct sdw_bus_params *b_params = &bus->params; in amd_sdw_compute_params()
398 hstop = bus->params.col - 1; in amd_sdw_compute_params()
402 list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) { in amd_sdw_compute_params()
403 rate = m_rt->stream->params.rate; in amd_sdw_compute_params()
404 bps = m_rt->stream->params.bps; in amd_sdw_compute_params()
405 sample_int = (bus->params.curr_dr_freq / rate); in amd_sdw_compute_params()
406 list_for_each_entry(p_rt, &m_rt->port_list, port_node) { in amd_sdw_compute_params()
407 port_bo = (p_rt->num * 64) + 1; in amd_sdw_compute_params()
408 dev_dbg(bus->dev, "p_rt->num=%d hstart=%d hstop=%d port_bo=%d\n", in amd_sdw_compute_params()
409 p_rt->num, hstart, hstop, port_bo); in amd_sdw_compute_params()
410 sdw_fill_xport_params(&p_rt->transport_params, p_rt->num, in amd_sdw_compute_params()
415 sdw_fill_port_params(&p_rt->port_params, in amd_sdw_compute_params()
416 p_rt->num, bps, in amd_sdw_compute_params()
418 b_params->m_data_mode); in amd_sdw_compute_params()
435 dev_dbg(amd_manager->dev, "p_params->num:0x%x\n", p_params->num); in amd_sdw_port_params()
436 switch (amd_manager->instance) { in amd_sdw_port_params()
438 frame_fmt_reg = sdw0_manager_dp_reg[p_params->num].frame_fmt_reg; in amd_sdw_port_params()
441 frame_fmt_reg = sdw1_manager_dp_reg[p_params->num].frame_fmt_reg; in amd_sdw_port_params()
444 return -EINVAL; in amd_sdw_port_params()
447 dpn_frame_fmt = readl(amd_manager->mmio + frame_fmt_reg); in amd_sdw_port_params()
448 u32p_replace_bits(&dpn_frame_fmt, p_params->flow_mode, AMD_DPN_FRAME_FMT_PFM); in amd_sdw_port_params()
449 u32p_replace_bits(&dpn_frame_fmt, p_params->data_mode, AMD_DPN_FRAME_FMT_PDM); in amd_sdw_port_params()
450 u32p_replace_bits(&dpn_frame_fmt, p_params->bps - 1, AMD_DPN_FRAME_FMT_WORD_LEN); in amd_sdw_port_params()
451 writel(dpn_frame_fmt, amd_manager->mmio + frame_fmt_reg); in amd_sdw_port_params()
468 switch (amd_manager->instance) { in amd_sdw_transport_params()
470 frame_fmt_reg = sdw0_manager_dp_reg[params->port_num].frame_fmt_reg; in amd_sdw_transport_params()
471 sample_int_reg = sdw0_manager_dp_reg[params->port_num].sample_int_reg; in amd_sdw_transport_params()
472 hctrl_dp0_reg = sdw0_manager_dp_reg[params->port_num].hctrl_dp0_reg; in amd_sdw_transport_params()
473 offset_reg = sdw0_manager_dp_reg[params->port_num].offset_reg; in amd_sdw_transport_params()
474 lane_ctrl_ch_en_reg = sdw0_manager_dp_reg[params->port_num].lane_ctrl_ch_en_reg; in amd_sdw_transport_params()
477 frame_fmt_reg = sdw1_manager_dp_reg[params->port_num].frame_fmt_reg; in amd_sdw_transport_params()
478 sample_int_reg = sdw1_manager_dp_reg[params->port_num].sample_int_reg; in amd_sdw_transport_params()
479 hctrl_dp0_reg = sdw1_manager_dp_reg[params->port_num].hctrl_dp0_reg; in amd_sdw_transport_params()
480 offset_reg = sdw1_manager_dp_reg[params->port_num].offset_reg; in amd_sdw_transport_params()
481 lane_ctrl_ch_en_reg = sdw1_manager_dp_reg[params->port_num].lane_ctrl_ch_en_reg; in amd_sdw_transport_params()
484 return -EINVAL; in amd_sdw_transport_params()
486 writel(AMD_SDW_SSP_COUNTER_VAL, amd_manager->mmio + ACP_SW_SSP_COUNTER); in amd_sdw_transport_params()
488 dpn_frame_fmt = readl(amd_manager->mmio + frame_fmt_reg); in amd_sdw_transport_params()
489 u32p_replace_bits(&dpn_frame_fmt, params->blk_pkg_mode, AMD_DPN_FRAME_FMT_BLK_PKG_MODE); in amd_sdw_transport_params()
490 u32p_replace_bits(&dpn_frame_fmt, params->blk_grp_ctrl, AMD_DPN_FRAME_FMT_BLK_GRP_CTRL); in amd_sdw_transport_params()
492 writel(dpn_frame_fmt, amd_manager->mmio + frame_fmt_reg); in amd_sdw_transport_params()
494 dpn_sampleinterval = params->sample_interval - 1; in amd_sdw_transport_params()
495 writel(dpn_sampleinterval, amd_manager->mmio + sample_int_reg); in amd_sdw_transport_params()
497 dpn_hctrl = FIELD_PREP(AMD_DPN_HCTRL_HSTOP, params->hstop); in amd_sdw_transport_params()
498 dpn_hctrl |= FIELD_PREP(AMD_DPN_HCTRL_HSTART, params->hstart); in amd_sdw_transport_params()
499 writel(dpn_hctrl, amd_manager->mmio + hctrl_dp0_reg); in amd_sdw_transport_params()
501 dpn_offsetctrl = FIELD_PREP(AMD_DPN_OFFSET_CTRL_1, params->offset1); in amd_sdw_transport_params()
502 dpn_offsetctrl |= FIELD_PREP(AMD_DPN_OFFSET_CTRL_2, params->offset2); in amd_sdw_transport_params()
503 writel(dpn_offsetctrl, amd_manager->mmio + offset_reg); in amd_sdw_transport_params()
509 dpn_lanectrl = readl(amd_manager->mmio + lane_ctrl_ch_en_reg); in amd_sdw_transport_params()
510 u32p_replace_bits(&dpn_lanectrl, params->lane_ctrl, AMD_DPN_CH_EN_LCTRL); in amd_sdw_transport_params()
511 writel(dpn_lanectrl, amd_manager->mmio + lane_ctrl_ch_en_reg); in amd_sdw_transport_params()
523 switch (amd_manager->instance) { in amd_sdw_port_enable()
525 lane_ctrl_ch_en_reg = sdw0_manager_dp_reg[enable_ch->port_num].lane_ctrl_ch_en_reg; in amd_sdw_port_enable()
528 lane_ctrl_ch_en_reg = sdw1_manager_dp_reg[enable_ch->port_num].lane_ctrl_ch_en_reg; in amd_sdw_port_enable()
531 return -EINVAL; in amd_sdw_port_enable()
538 dpn_ch_enable = readl(amd_manager->mmio + lane_ctrl_ch_en_reg); in amd_sdw_port_enable()
539 u32p_replace_bits(&dpn_ch_enable, enable_ch->ch_mask, AMD_DPN_CH_EN_CHMASK); in amd_sdw_port_enable()
540 if (enable_ch->enable) in amd_sdw_port_enable()
541 writel(dpn_ch_enable, amd_manager->mmio + lane_ctrl_ch_en_reg); in amd_sdw_port_enable()
543 writel(0, amd_manager->mmio + lane_ctrl_ch_en_reg); in amd_sdw_port_enable()
557 prop = &bus->prop; in sdw_master_read_amd_prop()
559 snprintf(name, sizeof(name), "mipi-sdw-link-%d-subproperties", bus->link_id); in sdw_master_read_amd_prop()
560 link = device_get_named_child_node(bus->dev, name); in sdw_master_read_amd_prop()
562 dev_err(bus->dev, "Manager node %s not found\n", name); in sdw_master_read_amd_prop()
563 return -EIO; in sdw_master_read_amd_prop()
565 fwnode_property_read_u32(link, "amd-sdw-enable", &quirk_mask); in sdw_master_read_amd_prop()
567 prop->hw_disabled = true; in sdw_master_read_amd_prop()
568 prop->quirks = SDW_MASTER_QUIRKS_CLEAR_INITIAL_CLASH | in sdw_master_read_amd_prop()
571 fwnode_property_read_u32(link, "amd-sdw-wakeup-enable", &wake_en_mask); in sdw_master_read_amd_prop()
572 amd_manager->wake_en_mask = wake_en_mask; in sdw_master_read_amd_prop()
573 fwnode_property_read_u32(link, "amd-sdw-power-mode", &power_mode_mask); in sdw_master_read_amd_prop()
574 amd_manager->power_mode_mask = power_mode_mask; in sdw_master_read_amd_prop()
610 dai_runtime = amd_manager->dai_runtime_array[dai->id]; in amd_sdw_hw_params()
612 return -EIO; in amd_sdw_hw_params()
615 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) in amd_sdw_hw_params()
619 dev_dbg(amd_manager->dev, "dir:%d dai->id:0x%x\n", dir, dai->id); in amd_sdw_hw_params()
624 sconfig.type = dai_runtime->stream_type; in amd_sdw_hw_params()
632 return -ENOMEM; in amd_sdw_hw_params()
634 pconfig->num = dai->id; in amd_sdw_hw_params()
635 pconfig->ch_mask = (1 << ch) - 1; in amd_sdw_hw_params()
636 ret = sdw_stream_add_master(&amd_manager->bus, &sconfig, in amd_sdw_hw_params()
637 pconfig, 1, dai_runtime->stream); in amd_sdw_hw_params()
639 dev_err(amd_manager->dev, "add manager to stream failed:%d\n", ret); in amd_sdw_hw_params()
650 dai_runtime = amd_manager->dai_runtime_array[dai->id]; in amd_sdw_hw_free()
652 return -EIO; in amd_sdw_hw_free()
654 ret = sdw_stream_remove_master(&amd_manager->bus, dai_runtime->stream); in amd_sdw_hw_free()
656 dev_err(dai->dev, "remove manager from stream %s failed: %d\n", in amd_sdw_hw_free()
657 dai_runtime->stream->name, ret); in amd_sdw_hw_free()
666 dai_runtime = amd_manager->dai_runtime_array[dai->id]; in amd_set_sdw_stream()
670 dev_err(dai->dev, "dai_runtime already allocated for dai %s\n", dai->name); in amd_set_sdw_stream()
671 return -EINVAL; in amd_set_sdw_stream()
677 return -ENOMEM; in amd_set_sdw_stream()
679 dai_runtime->stream_type = SDW_STREAM_PCM; in amd_set_sdw_stream()
680 dai_runtime->bus = &amd_manager->bus; in amd_set_sdw_stream()
681 dai_runtime->stream = stream; in amd_set_sdw_stream()
682 amd_manager->dai_runtime_array[dai->id] = dai_runtime; in amd_set_sdw_stream()
686 dev_err(dai->dev, "dai_runtime not allocated for dai %s\n", dai->name); in amd_set_sdw_stream()
687 return -EINVAL; in amd_set_sdw_stream()
692 amd_manager->dai_runtime_array[dai->id] = NULL; in amd_set_sdw_stream()
707 dai_runtime = amd_manager->dai_runtime_array[dai->id]; in amd_get_sdw_stream()
709 return ERR_PTR(-EINVAL); in amd_get_sdw_stream()
711 return dai_runtime->stream; in amd_get_sdw_stream()
722 .name = "soundwire",
733 dev = amd_manager->dev; in amd_sdw_register_dais()
734 num_dais = amd_manager->num_dout_ports + amd_manager->num_din_ports; in amd_sdw_register_dais()
737 return -ENOMEM; in amd_sdw_register_dais()
743 return -ENOMEM; in amd_sdw_register_dais()
744 amd_manager->dai_runtime_array = dai_runtime_array; in amd_sdw_register_dais()
746 dais[i].name = devm_kasprintf(dev, GFP_KERNEL, "SDW%d Pin%d", amd_manager->instance, in amd_sdw_register_dais()
749 return -ENOMEM; in amd_sdw_register_dais()
750 if (i < amd_manager->num_dout_ports) in amd_sdw_register_dais()
755 stream->channels_min = 2; in amd_sdw_register_dais()
756 stream->channels_max = 2; in amd_sdw_register_dais()
757 stream->rates = SNDRV_PCM_RATE_48000; in amd_sdw_register_dais()
758 stream->formats = SNDRV_PCM_FMTBIT_S16_LE; in amd_sdw_register_dais()
774 if (amd_manager->status[0] == SDW_SLAVE_ATTACHED) { in amd_sdw_update_slave_status_work()
775 writel(0, amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_MASK_0TO7); in amd_sdw_update_slave_status_work()
776 writel(0, amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11); in amd_sdw_update_slave_status_work()
780 sdw_handle_slave_status(&amd_manager->bus, amd_manager->status); in amd_sdw_update_slave_status_work()
782 * During the peripheral enumeration sequence, the SoundWire manager interrupts in amd_sdw_update_slave_status_work()
788 if (amd_manager->status[0] == SDW_SLAVE_ATTACHED) { in amd_sdw_update_slave_status_work()
790 writel(AMD_SDW_IRQ_MASK_0TO7, amd_manager->mmio + in amd_sdw_update_slave_status_work()
792 writel(AMD_SDW_IRQ_MASK_8TO11, amd_manager->mmio + in amd_sdw_update_slave_status_work()
797 dev_err_ratelimited(amd_manager->dev, in amd_sdw_update_slave_status_work()
812 memset(amd_manager->status, 0, sizeof(amd_manager->status)); in amd_sdw_update_slave_status()
815 dev_dbg(amd_manager->dev, "status_change_0to7:0x%x status_change_8to11:0x%x\n", in amd_sdw_update_slave_status()
830 pm_request_resume(amd_manager->dev); in amd_sdw_process_wake_event()
831 writel(0x00, amd_manager->acp_mmio + ACP_SW_WAKE_EN(amd_manager->instance)); in amd_sdw_process_wake_event()
832 writel(0x00, amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_8TO11); in amd_sdw_process_wake_event()
842 status_change_8to11 = readl(amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_8TO11); in amd_sdw_irq_thread()
843 status_change_0to7 = readl(amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_0TO7); in amd_sdw_irq_thread()
844 dev_dbg(amd_manager->dev, "[SDW%d] SDW INT: 0to7=0x%x, 8to11=0x%x\n", in amd_sdw_irq_thread()
845 amd_manager->instance, status_change_0to7, status_change_8to11); in amd_sdw_irq_thread()
856 schedule_work(&amd_manager->amd_sdw_work); in amd_sdw_irq_thread()
857 writel(0x00, amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_8TO11); in amd_sdw_irq_thread()
858 writel(0x00, amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_0TO7); in amd_sdw_irq_thread()
866 prop = &amd_manager->bus.prop; in amd_sdw_manager_start()
867 if (!prop->hw_disabled) { in amd_sdw_manager_start()
878 pm_runtime_set_autosuspend_delay(amd_manager->dev, AMD_SDW_MASTER_SUSPEND_DELAY_MS); in amd_sdw_manager_start()
879 pm_runtime_use_autosuspend(amd_manager->dev); in amd_sdw_manager_start()
880 pm_runtime_mark_last_busy(amd_manager->dev); in amd_sdw_manager_start()
881 pm_runtime_set_active(amd_manager->dev); in amd_sdw_manager_start()
882 pm_runtime_enable(amd_manager->dev); in amd_sdw_manager_start()
888 const struct acp_sdw_pdata *pdata = pdev->dev.platform_data; in amd_sdw_manager_probe()
890 struct device *dev = &pdev->dev; in amd_sdw_manager_probe()
898 return -ENOMEM; in amd_sdw_manager_probe()
902 return -ENOMEM; in amd_sdw_manager_probe()
904 amd_manager->acp_mmio = devm_ioremap(dev, res->start, resource_size(res)); in amd_sdw_manager_probe()
905 if (!amd_manager->acp_mmio) { in amd_sdw_manager_probe()
907 return -ENOMEM; in amd_sdw_manager_probe()
909 amd_manager->instance = pdata->instance; in amd_sdw_manager_probe()
910 amd_manager->mmio = amd_manager->acp_mmio + in amd_sdw_manager_probe()
911 (amd_manager->instance * SDW_MANAGER_REG_OFFSET); in amd_sdw_manager_probe()
912 amd_manager->acp_sdw_lock = pdata->acp_sdw_lock; in amd_sdw_manager_probe()
913 amd_manager->cols_index = sdw_find_col_index(AMD_SDW_DEFAULT_COLUMNS); in amd_sdw_manager_probe()
914 amd_manager->rows_index = sdw_find_row_index(AMD_SDW_DEFAULT_ROWS); in amd_sdw_manager_probe()
915 amd_manager->dev = dev; in amd_sdw_manager_probe()
916 amd_manager->bus.ops = &amd_sdw_ops; in amd_sdw_manager_probe()
917 amd_manager->bus.port_ops = &amd_sdw_port_ops; in amd_sdw_manager_probe()
918 amd_manager->bus.compute_params = &amd_sdw_compute_params; in amd_sdw_manager_probe()
919 amd_manager->bus.clk_stop_timeout = 200; in amd_sdw_manager_probe()
920 amd_manager->bus.link_id = amd_manager->instance; in amd_sdw_manager_probe()
924 * the scope of a single controller. If this changes, the in amd_sdw_manager_probe()
928 amd_manager->bus.controller_id = 0; in amd_sdw_manager_probe()
930 switch (amd_manager->instance) { in amd_sdw_manager_probe()
932 amd_manager->num_dout_ports = AMD_SDW0_MAX_TX_PORTS; in amd_sdw_manager_probe()
933 amd_manager->num_din_ports = AMD_SDW0_MAX_RX_PORTS; in amd_sdw_manager_probe()
936 amd_manager->num_dout_ports = AMD_SDW1_MAX_TX_PORTS; in amd_sdw_manager_probe()
937 amd_manager->num_din_ports = AMD_SDW1_MAX_RX_PORTS; in amd_sdw_manager_probe()
940 return -EINVAL; in amd_sdw_manager_probe()
943 params = &amd_manager->bus.params; in amd_sdw_manager_probe()
945 params->col = AMD_SDW_DEFAULT_COLUMNS; in amd_sdw_manager_probe()
946 params->row = AMD_SDW_DEFAULT_ROWS; in amd_sdw_manager_probe()
947 prop = &amd_manager->bus.prop; in amd_sdw_manager_probe()
948 prop->clk_freq = &amd_sdw_freq_tbl[0]; in amd_sdw_manager_probe()
949 prop->mclk_freq = AMD_SDW_BUS_BASE_FREQ; in amd_sdw_manager_probe()
950 prop->max_clk_freq = AMD_SDW_DEFAULT_CLK_FREQ; in amd_sdw_manager_probe()
952 ret = sdw_bus_master_add(&amd_manager->bus, dev, dev->fwnode); in amd_sdw_manager_probe()
954 dev_err(dev, "Failed to register SoundWire manager(%d)\n", ret); in amd_sdw_manager_probe()
960 sdw_bus_master_delete(&amd_manager->bus); in amd_sdw_manager_probe()
964 INIT_WORK(&amd_manager->amd_sdw_irq_thread, amd_sdw_irq_thread); in amd_sdw_manager_probe()
965 INIT_WORK(&amd_manager->amd_sdw_work, amd_sdw_update_slave_status_work); in amd_sdw_manager_probe()
971 struct amd_sdw_manager *amd_manager = dev_get_drvdata(&pdev->dev); in amd_sdw_manager_remove()
974 pm_runtime_disable(&pdev->dev); in amd_sdw_manager_remove()
976 sdw_bus_master_delete(&amd_manager->bus); in amd_sdw_manager_remove()
979 dev_err(&pdev->dev, "Failed to disable device (%pe)\n", ERR_PTR(ret)); in amd_sdw_manager_remove()
987 ret = sdw_bus_prep_clk_stop(&amd_manager->bus); in amd_sdw_clock_stop()
988 if (ret < 0 && ret != -ENODATA) { in amd_sdw_clock_stop()
989 dev_err(amd_manager->dev, "prepare clock stop failed %d", ret); in amd_sdw_clock_stop()
992 ret = sdw_bus_clk_stop(&amd_manager->bus); in amd_sdw_clock_stop()
993 if (ret < 0 && ret != -ENODATA) { in amd_sdw_clock_stop()
994 dev_err(amd_manager->dev, "bus clock stop failed %d", ret); in amd_sdw_clock_stop()
998 ret = readl_poll_timeout(amd_manager->mmio + ACP_SW_CLK_RESUME_CTRL, val, in amd_sdw_clock_stop()
1001 dev_err(amd_manager->dev, "SDW%x clock stop failed\n", amd_manager->instance); in amd_sdw_clock_stop()
1005 amd_manager->clk_stopped = true; in amd_sdw_clock_stop()
1006 if (amd_manager->wake_en_mask) in amd_sdw_clock_stop()
1007 writel(0x01, amd_manager->acp_mmio + ACP_SW_WAKE_EN(amd_manager->instance)); in amd_sdw_clock_stop()
1009 dev_dbg(amd_manager->dev, "SDW%x clock stop successful\n", amd_manager->instance); in amd_sdw_clock_stop()
1018 if (amd_manager->clk_stopped) { in amd_sdw_clock_stop_exit()
1019 val = readl(amd_manager->mmio + ACP_SW_CLK_RESUME_CTRL); in amd_sdw_clock_stop_exit()
1021 writel(val, amd_manager->mmio + ACP_SW_CLK_RESUME_CTRL); in amd_sdw_clock_stop_exit()
1022 ret = readl_poll_timeout(amd_manager->mmio + ACP_SW_CLK_RESUME_CTRL, val, in amd_sdw_clock_stop_exit()
1026 writel(0, amd_manager->mmio + ACP_SW_CLK_RESUME_CTRL); in amd_sdw_clock_stop_exit()
1027 ret = sdw_bus_exit_clk_stop(&amd_manager->bus); in amd_sdw_clock_stop_exit()
1029 dev_err(amd_manager->dev, "bus failed to exit clock stop %d\n", in amd_sdw_clock_stop_exit()
1031 amd_manager->clk_stopped = false; in amd_sdw_clock_stop_exit()
1034 if (amd_manager->clk_stopped) { in amd_sdw_clock_stop_exit()
1035 dev_err(amd_manager->dev, "SDW%x clock stop exit failed\n", amd_manager->instance); in amd_sdw_clock_stop_exit()
1038 dev_dbg(amd_manager->dev, "SDW%x clock stop exit successful\n", amd_manager->instance); in amd_sdw_clock_stop_exit()
1047 if (!slave->probed) { in amd_resume_child_device()
1051 if (!slave->dev_num_sticky) { in amd_resume_child_device()
1066 struct sdw_bus *bus = &amd_manager->bus; in amd_pm_prepare()
1069 if (bus->prop.hw_disabled) { in amd_pm_prepare()
1070 dev_dbg(bus->dev, "SoundWire manager %d is disabled, ignoring\n", in amd_pm_prepare()
1071 bus->link_id); in amd_pm_prepare()
1075 * When multiple peripheral devices connected over the same link, if SoundWire manager in amd_pm_prepare()
1079 if (amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) { in amd_pm_prepare()
1082 dev_err(bus->dev, "pm_request_resume failed: %d\n", ret); in amd_pm_prepare()
1091 ret = device_for_each_child(bus->dev, NULL, amd_resume_child_device); in amd_pm_prepare()
1100 struct sdw_bus *bus = &amd_manager->bus; in amd_suspend()
1103 if (bus->prop.hw_disabled) { in amd_suspend()
1104 dev_dbg(bus->dev, "SoundWire manager %d is disabled, ignoring\n", in amd_suspend()
1105 bus->link_id); in amd_suspend()
1109 if (amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) { in amd_suspend()
1112 } else if (amd_manager->power_mode_mask & AMD_SDW_POWER_OFF_MODE) { in amd_suspend()
1115 * clock stop should be invoked first before powering-off in amd_suspend()
1128 struct sdw_bus *bus = &amd_manager->bus; in amd_suspend_runtime()
1131 if (bus->prop.hw_disabled) { in amd_suspend_runtime()
1132 dev_dbg(bus->dev, "SoundWire manager %d is disabled,\n", in amd_suspend_runtime()
1133 bus->link_id); in amd_suspend_runtime()
1136 if (amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) { in amd_suspend_runtime()
1139 } else if (amd_manager->power_mode_mask & AMD_SDW_POWER_OFF_MODE) { in amd_suspend_runtime()
1151 struct sdw_bus *bus = &amd_manager->bus; in amd_resume_runtime()
1155 if (bus->prop.hw_disabled) { in amd_resume_runtime()
1156 dev_dbg(bus->dev, "SoundWire manager %d is disabled, ignoring\n", in amd_resume_runtime()
1157 bus->link_id); in amd_resume_runtime()
1161 if (amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) { in amd_resume_runtime()
1163 } else if (amd_manager->power_mode_mask & AMD_SDW_POWER_OFF_MODE) { in amd_resume_runtime()
1164 val = readl(amd_manager->mmio + ACP_SW_CLK_RESUME_CTRL); in amd_resume_runtime()
1167 writel(val, amd_manager->mmio + ACP_SW_CLK_RESUME_CTRL); in amd_resume_runtime()
1168 ret = readl_poll_timeout(amd_manager->mmio + ACP_SW_CLK_RESUME_CTRL, val, in amd_resume_runtime()
1172 writel(0, amd_manager->mmio + ACP_SW_CLK_RESUME_CTRL); in amd_resume_runtime()
1173 amd_manager->clk_stopped = false; in amd_resume_runtime()
1204 MODULE_DESCRIPTION("AMD SoundWire driver");