Lines Matching +full:soundwire +full:- +full:controller

1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2 // Copyright(c) 2015-18 Intel Corporation.
5 * stream.c - SoundWire Bus stream operations.
14 #include <linux/soundwire/sdw_registers.h>
15 #include <linux/soundwire/sdw.h>
16 #include <linux/soundwire/sdw_type.h>
21 * Array of supported rows and columns as per MIPI SoundWire Specification 1.1
71 if (bus->params.next_bank) { in _sdw_program_slave_port_params()
72 addr1 = SDW_DPN_OFFSETCTRL2_B1(t_params->port_num); in _sdw_program_slave_port_params()
73 addr2 = SDW_DPN_BLOCKCTRL3_B1(t_params->port_num); in _sdw_program_slave_port_params()
74 addr3 = SDW_DPN_SAMPLECTRL2_B1(t_params->port_num); in _sdw_program_slave_port_params()
75 addr4 = SDW_DPN_HCTRL_B1(t_params->port_num); in _sdw_program_slave_port_params()
77 addr1 = SDW_DPN_OFFSETCTRL2_B0(t_params->port_num); in _sdw_program_slave_port_params()
78 addr2 = SDW_DPN_BLOCKCTRL3_B0(t_params->port_num); in _sdw_program_slave_port_params()
79 addr3 = SDW_DPN_SAMPLECTRL2_B0(t_params->port_num); in _sdw_program_slave_port_params()
80 addr4 = SDW_DPN_HCTRL_B0(t_params->port_num); in _sdw_program_slave_port_params()
84 ret = sdw_write_no_pm(slave, addr1, t_params->offset2); in _sdw_program_slave_port_params()
86 dev_err(bus->dev, "DPN_OffsetCtrl2 register write failed\n"); in _sdw_program_slave_port_params()
91 ret = sdw_write_no_pm(slave, addr2, t_params->blk_pkg_mode); in _sdw_program_slave_port_params()
93 dev_err(bus->dev, "DPN_BlockCtrl3 register write failed\n"); in _sdw_program_slave_port_params()
106 wbuf = FIELD_GET(SDW_DPN_SAMPLECTRL_HIGH, t_params->sample_interval - 1); in _sdw_program_slave_port_params()
110 dev_err(bus->dev, "DPN_SampleCtrl2 register write failed\n"); in _sdw_program_slave_port_params()
115 wbuf = FIELD_PREP(SDW_DPN_HCTRL_HSTART, t_params->hstart); in _sdw_program_slave_port_params()
116 wbuf |= FIELD_PREP(SDW_DPN_HCTRL_HSTOP, t_params->hstop); in _sdw_program_slave_port_params()
120 dev_err(bus->dev, "DPN_HCtrl register write failed\n"); in _sdw_program_slave_port_params()
129 struct sdw_transport_params *t_params = &p_rt->transport_params; in sdw_program_slave_port_params()
130 struct sdw_port_params *p_params = &p_rt->port_params; in sdw_program_slave_port_params()
131 struct sdw_slave_prop *slave_prop = &s_rt->slave->prop; in sdw_program_slave_port_params()
137 if (s_rt->slave->is_mockup_device) in sdw_program_slave_port_params()
140 dpn_prop = sdw_get_slave_dpn_prop(s_rt->slave, in sdw_program_slave_port_params()
141 s_rt->direction, in sdw_program_slave_port_params()
142 t_params->port_num); in sdw_program_slave_port_params()
144 return -EINVAL; in sdw_program_slave_port_params()
146 addr1 = SDW_DPN_PORTCTRL(t_params->port_num); in sdw_program_slave_port_params()
147 addr2 = SDW_DPN_BLOCKCTRL1(t_params->port_num); in sdw_program_slave_port_params()
149 if (bus->params.next_bank) { in sdw_program_slave_port_params()
150 addr3 = SDW_DPN_SAMPLECTRL1_B1(t_params->port_num); in sdw_program_slave_port_params()
151 addr4 = SDW_DPN_OFFSETCTRL1_B1(t_params->port_num); in sdw_program_slave_port_params()
152 addr5 = SDW_DPN_BLOCKCTRL2_B1(t_params->port_num); in sdw_program_slave_port_params()
153 addr6 = SDW_DPN_LANECTRL_B1(t_params->port_num); in sdw_program_slave_port_params()
156 addr3 = SDW_DPN_SAMPLECTRL1_B0(t_params->port_num); in sdw_program_slave_port_params()
157 addr4 = SDW_DPN_OFFSETCTRL1_B0(t_params->port_num); in sdw_program_slave_port_params()
158 addr5 = SDW_DPN_BLOCKCTRL2_B0(t_params->port_num); in sdw_program_slave_port_params()
159 addr6 = SDW_DPN_LANECTRL_B0(t_params->port_num); in sdw_program_slave_port_params()
163 wbuf = FIELD_PREP(SDW_DPN_PORTCTRL_DATAMODE, p_params->data_mode); in sdw_program_slave_port_params()
164 wbuf |= FIELD_PREP(SDW_DPN_PORTCTRL_FLOWMODE, p_params->flow_mode); in sdw_program_slave_port_params()
166 ret = sdw_update_no_pm(s_rt->slave, addr1, 0xF, wbuf); in sdw_program_slave_port_params()
168 dev_err(&s_rt->slave->dev, in sdw_program_slave_port_params()
170 t_params->port_num); in sdw_program_slave_port_params()
174 if (!dpn_prop->read_only_wordlength) { in sdw_program_slave_port_params()
176 ret = sdw_write_no_pm(s_rt->slave, addr2, (p_params->bps - 1)); in sdw_program_slave_port_params()
178 dev_err(&s_rt->slave->dev, in sdw_program_slave_port_params()
180 t_params->port_num); in sdw_program_slave_port_params()
186 wbuf = (t_params->sample_interval - 1) & SDW_DPN_SAMPLECTRL_LOW; in sdw_program_slave_port_params()
187 ret = sdw_write_no_pm(s_rt->slave, addr3, wbuf); in sdw_program_slave_port_params()
189 dev_err(&s_rt->slave->dev, in sdw_program_slave_port_params()
191 t_params->port_num); in sdw_program_slave_port_params()
196 ret = sdw_write_no_pm(s_rt->slave, addr4, t_params->offset1); in sdw_program_slave_port_params()
198 dev_err(&s_rt->slave->dev, in sdw_program_slave_port_params()
200 t_params->port_num); in sdw_program_slave_port_params()
205 if (t_params->blk_grp_ctrl_valid) { in sdw_program_slave_port_params()
206 ret = sdw_write_no_pm(s_rt->slave, addr5, t_params->blk_grp_ctrl); in sdw_program_slave_port_params()
208 dev_err(&s_rt->slave->dev, in sdw_program_slave_port_params()
210 t_params->port_num); in sdw_program_slave_port_params()
216 if (slave_prop->lane_control_support) { in sdw_program_slave_port_params()
217 ret = sdw_write_no_pm(s_rt->slave, addr6, t_params->lane_ctrl); in sdw_program_slave_port_params()
219 dev_err(&s_rt->slave->dev, in sdw_program_slave_port_params()
221 t_params->port_num); in sdw_program_slave_port_params()
226 if (dpn_prop->type != SDW_DPN_SIMPLE) { in sdw_program_slave_port_params()
227 ret = _sdw_program_slave_port_params(bus, s_rt->slave, in sdw_program_slave_port_params()
228 t_params, dpn_prop->type); in sdw_program_slave_port_params()
230 dev_err(&s_rt->slave->dev, in sdw_program_slave_port_params()
232 t_params->port_num); in sdw_program_slave_port_params()
249 ret = bus->port_ops->dpn_set_port_transport_params(bus, in sdw_program_master_port_params()
250 &p_rt->transport_params, in sdw_program_master_port_params()
251 bus->params.next_bank); in sdw_program_master_port_params()
255 return bus->port_ops->dpn_set_port_params(bus, in sdw_program_master_port_params()
256 &p_rt->port_params, in sdw_program_master_port_params()
257 bus->params.next_bank); in sdw_program_master_port_params()
261 * sdw_program_port_params() - Programs transport parameters of Master(s)
269 struct sdw_bus *bus = m_rt->bus; in sdw_program_port_params()
274 list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) { in sdw_program_port_params()
275 list_for_each_entry(p_rt, &s_rt->port_list, port_node) { in sdw_program_port_params()
283 list_for_each_entry(p_rt, &m_rt->port_list, port_node) { in sdw_program_port_params()
308 struct sdw_transport_params *t_params = &p_rt->transport_params; in sdw_enable_disable_slave_ports()
312 if (bus->params.next_bank) in sdw_enable_disable_slave_ports()
313 addr = SDW_DPN_CHANNELEN_B1(p_rt->num); in sdw_enable_disable_slave_ports()
315 addr = SDW_DPN_CHANNELEN_B0(p_rt->num); in sdw_enable_disable_slave_ports()
322 ret = sdw_write_no_pm(s_rt->slave, addr, p_rt->ch_mask); in sdw_enable_disable_slave_ports()
324 ret = sdw_write_no_pm(s_rt->slave, addr, 0x0); in sdw_enable_disable_slave_ports()
327 dev_err(&s_rt->slave->dev, in sdw_enable_disable_slave_ports()
329 ret, t_params->port_num); in sdw_enable_disable_slave_ports()
338 struct sdw_transport_params *t_params = &p_rt->transport_params; in sdw_enable_disable_master_ports()
339 struct sdw_bus *bus = m_rt->bus; in sdw_enable_disable_master_ports()
343 enable_ch.port_num = p_rt->num; in sdw_enable_disable_master_ports()
344 enable_ch.ch_mask = p_rt->ch_mask; in sdw_enable_disable_master_ports()
348 if (bus->port_ops->dpn_port_enable_ch) { in sdw_enable_disable_master_ports()
349 ret = bus->port_ops->dpn_port_enable_ch(bus, in sdw_enable_disable_master_ports()
351 bus->params.next_bank); in sdw_enable_disable_master_ports()
353 dev_err(bus->dev, in sdw_enable_disable_master_ports()
355 ret, t_params->port_num); in sdw_enable_disable_master_ports()
359 dev_err(bus->dev, in sdw_enable_disable_master_ports()
362 return -EINVAL; in sdw_enable_disable_master_ports()
369 * sdw_enable_disable_ports() - Enable/disable port(s) for Master and
382 list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) { in sdw_enable_disable_ports()
383 list_for_each_entry(s_port, &s_rt->port_list, port_node) { in sdw_enable_disable_ports()
384 ret = sdw_enable_disable_slave_ports(m_rt->bus, s_rt, in sdw_enable_disable_ports()
392 list_for_each_entry(m_port, &m_rt->port_list, port_node) { in sdw_enable_disable_ports()
406 struct sdw_slave *slave = s_rt->slave; in sdw_do_port_prep()
408 mutex_lock(&slave->sdw_dev_lock); in sdw_do_port_prep()
410 if (slave->probed) { in sdw_do_port_prep()
411 struct device *dev = &slave->dev; in sdw_do_port_prep()
412 struct sdw_driver *drv = drv_to_sdw_driver(dev->driver); in sdw_do_port_prep()
414 if (drv->ops && drv->ops->port_prep) { in sdw_do_port_prep()
415 ret = drv->ops->port_prep(slave, &prep_ch, cmd); in sdw_do_port_prep()
422 mutex_unlock(&slave->sdw_dev_lock); in sdw_do_port_prep()
439 prep_ch.num = p_rt->num; in sdw_prep_deprep_slave_ports()
440 prep_ch.ch_mask = p_rt->ch_mask; in sdw_prep_deprep_slave_ports()
442 dpn_prop = sdw_get_slave_dpn_prop(s_rt->slave, in sdw_prep_deprep_slave_ports()
443 s_rt->direction, in sdw_prep_deprep_slave_ports()
446 dev_err(bus->dev, in sdw_prep_deprep_slave_ports()
448 return -EINVAL; in sdw_prep_deprep_slave_ports()
453 prep_ch.bank = bus->params.next_bank; in sdw_prep_deprep_slave_ports()
455 if (dpn_prop->imp_def_interrupts || !dpn_prop->simple_ch_prep_sm || in sdw_prep_deprep_slave_ports()
456 bus->params.s_data_mode != SDW_PORT_DATA_MODE_NORMAL) in sdw_prep_deprep_slave_ports()
461 * For Port de-prepare, it is assumed that port in sdw_prep_deprep_slave_ports()
465 ret = sdw_configure_dpn_intr(s_rt->slave, p_rt->num, prep, in sdw_prep_deprep_slave_ports()
466 dpn_prop->imp_def_interrupts); in sdw_prep_deprep_slave_ports()
475 if (!dpn_prop->simple_ch_prep_sm) { in sdw_prep_deprep_slave_ports()
476 addr = SDW_DPN_PREPARECTRL(p_rt->num); in sdw_prep_deprep_slave_ports()
479 ret = sdw_write_no_pm(s_rt->slave, addr, p_rt->ch_mask); in sdw_prep_deprep_slave_ports()
481 ret = sdw_write_no_pm(s_rt->slave, addr, 0x0); in sdw_prep_deprep_slave_ports()
484 dev_err(&s_rt->slave->dev, in sdw_prep_deprep_slave_ports()
490 port_ready = &s_rt->slave->port_ready[prep_ch.num]; in sdw_prep_deprep_slave_ports()
492 msecs_to_jiffies(dpn_prop->ch_prep_timeout)); in sdw_prep_deprep_slave_ports()
494 val = sdw_read_no_pm(s_rt->slave, SDW_DPN_PREPARESTATUS(p_rt->num)); in sdw_prep_deprep_slave_ports()
495 if ((val < 0) || (val & p_rt->ch_mask)) { in sdw_prep_deprep_slave_ports()
496 ret = (val < 0) ? val : -ETIMEDOUT; in sdw_prep_deprep_slave_ports()
497 dev_err(&s_rt->slave->dev, in sdw_prep_deprep_slave_ports()
506 /* Disable interrupt after Port de-prepare */ in sdw_prep_deprep_slave_ports()
508 ret = sdw_configure_dpn_intr(s_rt->slave, p_rt->num, prep, in sdw_prep_deprep_slave_ports()
509 dpn_prop->imp_def_interrupts); in sdw_prep_deprep_slave_ports()
518 struct sdw_transport_params *t_params = &p_rt->transport_params; in sdw_prep_deprep_master_ports()
519 struct sdw_bus *bus = m_rt->bus; in sdw_prep_deprep_master_ports()
520 const struct sdw_master_port_ops *ops = bus->port_ops; in sdw_prep_deprep_master_ports()
524 prep_ch.num = p_rt->num; in sdw_prep_deprep_master_ports()
525 prep_ch.ch_mask = p_rt->ch_mask; in sdw_prep_deprep_master_ports()
526 prep_ch.prepare = prep; /* Prepare/De-prepare */ in sdw_prep_deprep_master_ports()
527 prep_ch.bank = bus->params.next_bank; in sdw_prep_deprep_master_ports()
529 /* Pre-prepare/Pre-deprepare port(s) */ in sdw_prep_deprep_master_ports()
530 if (ops->dpn_port_prep) { in sdw_prep_deprep_master_ports()
531 ret = ops->dpn_port_prep(bus, &prep_ch); in sdw_prep_deprep_master_ports()
533 dev_err(bus->dev, "Port prepare failed for port:%d\n", in sdw_prep_deprep_master_ports()
534 t_params->port_num); in sdw_prep_deprep_master_ports()
543 * sdw_prep_deprep_ports() - Prepare/De-prepare port(s) for Master(s) and
547 * @prep: Prepare or De-prepare
555 /* Prepare/De-prepare Slave port(s) */ in sdw_prep_deprep_ports()
556 list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) { in sdw_prep_deprep_ports()
557 list_for_each_entry(p_rt, &s_rt->port_list, port_node) { in sdw_prep_deprep_ports()
558 ret = sdw_prep_deprep_slave_ports(m_rt->bus, s_rt, in sdw_prep_deprep_ports()
565 /* Prepare/De-prepare Master port(s) */ in sdw_prep_deprep_ports()
566 list_for_each_entry(p_rt, &m_rt->port_list, port_node) { in sdw_prep_deprep_ports()
576 * sdw_notify_config() - Notify bus configuration
586 struct sdw_bus *bus = m_rt->bus; in sdw_notify_config()
590 if (bus->ops->set_bus_conf) { in sdw_notify_config()
591 ret = bus->ops->set_bus_conf(bus, &bus->params); in sdw_notify_config()
596 list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) { in sdw_notify_config()
597 slave = s_rt->slave; in sdw_notify_config()
599 mutex_lock(&slave->sdw_dev_lock); in sdw_notify_config()
601 if (slave->probed) { in sdw_notify_config()
602 struct device *dev = &slave->dev; in sdw_notify_config()
603 struct sdw_driver *drv = drv_to_sdw_driver(dev->driver); in sdw_notify_config()
605 if (drv->ops && drv->ops->bus_config) { in sdw_notify_config()
606 ret = drv->ops->bus_config(slave, &bus->params); in sdw_notify_config()
609 slave->dev_num); in sdw_notify_config()
610 mutex_unlock(&slave->sdw_dev_lock); in sdw_notify_config()
616 mutex_unlock(&slave->sdw_dev_lock); in sdw_notify_config()
623 * sdw_program_params() - Program transport and port parameters for Master(s)
634 list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) { in sdw_program_params()
640 * already-prepared stream otherwise. in sdw_program_params()
643 m_rt->stream->state == SDW_STREAM_CONFIGURED) in sdw_program_params()
648 dev_err(bus->dev, in sdw_program_params()
655 dev_err(bus->dev, in sdw_program_params()
661 if (m_rt->stream->state != SDW_STREAM_ENABLED) in sdw_program_params()
666 dev_err(bus->dev, "Enable channel failed: %d\n", ret); in sdw_program_params()
685 return -ENOMEM; in sdw_bank_switch()
689 ret = -ENOMEM; in sdw_bank_switch()
694 col_index = sdw_find_col_index(bus->params.col); in sdw_bank_switch()
695 row_index = sdw_find_row_index(bus->params.row); in sdw_bank_switch()
698 if (bus->params.next_bank) in sdw_bank_switch()
705 wr_msg->ssp_sync = true; in sdw_bank_switch()
709 * and hardware-based sync is required in sdw_bank_switch()
711 multi_link = bus->multi_link && (m_rt_count >= bus->hw_sync_min_links); in sdw_bank_switch()
718 if (ret < 0 && ret != -ENODATA) { in sdw_bank_switch()
719 dev_err(bus->dev, "Slave frame_ctrl reg write failed\n"); in sdw_bank_switch()
726 bus->defer_msg.msg = NULL; in sdw_bank_switch()
727 bus->params.curr_bank = !bus->params.curr_bank; in sdw_bank_switch()
728 bus->params.next_bank = !bus->params.next_bank; in sdw_bank_switch()
737 bus->defer_msg.msg = NULL; in sdw_bank_switch()
745 * @multi_link: whether this is a multi-link stream with hardware-based sync
757 time_left = wait_for_completion_timeout(&bus->defer_msg.complete, in sdw_ml_sync_bank_switch()
758 bus->bank_switch_timeout); in sdw_ml_sync_bank_switch()
761 dev_err(bus->dev, "Controller Timed out on bank switch\n"); in sdw_ml_sync_bank_switch()
762 return -ETIMEDOUT; in sdw_ml_sync_bank_switch()
765 bus->params.curr_bank = !bus->params.curr_bank; in sdw_ml_sync_bank_switch()
766 bus->params.next_bank = !bus->params.next_bank; in sdw_ml_sync_bank_switch()
768 if (bus->defer_msg.msg) { in sdw_ml_sync_bank_switch()
769 kfree(bus->defer_msg.msg->buf); in sdw_ml_sync_bank_switch()
770 kfree(bus->defer_msg.msg); in sdw_ml_sync_bank_switch()
771 bus->defer_msg.msg = NULL; in sdw_ml_sync_bank_switch()
786 m_rt_count = stream->m_rt_count; in do_bank_switch()
788 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in do_bank_switch()
789 bus = m_rt->bus; in do_bank_switch()
790 ops = bus->ops; in do_bank_switch()
792 if (bus->multi_link && m_rt_count >= bus->hw_sync_min_links) { in do_bank_switch()
794 mutex_lock(&bus->msg_lock); in do_bank_switch()
797 /* Pre-bank switch */ in do_bank_switch()
798 if (ops->pre_bank_switch) { in do_bank_switch()
799 ret = ops->pre_bank_switch(bus); in do_bank_switch()
801 dev_err(bus->dev, in do_bank_switch()
815 dev_err(bus->dev, "Bank switch failed: %d\n", ret); in do_bank_switch()
826 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in do_bank_switch()
827 bus = m_rt->bus; in do_bank_switch()
828 ops = bus->ops; in do_bank_switch()
830 /* Post-bank switch */ in do_bank_switch()
831 if (ops->post_bank_switch) { in do_bank_switch()
832 ret = ops->post_bank_switch(bus); in do_bank_switch()
834 dev_err(bus->dev, in do_bank_switch()
840 dev_err(bus->dev, in do_bank_switch()
842 ret = -EINVAL; in do_bank_switch()
847 if (!bus->bank_switch_timeout) in do_bank_switch()
848 bus->bank_switch_timeout = DEFAULT_BANK_SWITCH_TIMEOUT; in do_bank_switch()
853 dev_err(bus->dev, in do_bank_switch()
859 mutex_unlock(&bus->msg_lock); in do_bank_switch()
865 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in do_bank_switch()
866 bus = m_rt->bus; in do_bank_switch()
867 if (bus->defer_msg.msg) { in do_bank_switch()
868 kfree(bus->defer_msg.msg->buf); in do_bank_switch()
869 kfree(bus->defer_msg.msg); in do_bank_switch()
870 bus->defer_msg.msg = NULL; in do_bank_switch()
877 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in do_bank_switch()
878 bus = m_rt->bus; in do_bank_switch()
879 if (mutex_is_locked(&bus->msg_lock)) in do_bank_switch()
880 mutex_unlock(&bus->msg_lock); in do_bank_switch()
895 list_add_tail(&p_rt->port_node, port_list); in sdw_port_alloc()
904 p_rt->ch_mask = port_config[port_index].ch_mask; in sdw_port_config()
905 p_rt->num = port_config[port_index].num; in sdw_port_config()
916 list_del(&p_rt->port_node); in sdw_port_free()
922 return !list_empty(&s_rt->port_list); in sdw_slave_port_allocated()
932 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in sdw_slave_port_free()
933 list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) { in sdw_slave_port_free()
934 if (s_rt->slave != slave) in sdw_slave_port_free()
938 &s_rt->port_list, port_node) { in sdw_slave_port_free()
954 p_rt = sdw_port_alloc(&s_rt->port_list); in sdw_slave_port_alloc()
956 return -ENOMEM; in sdw_slave_port_alloc()
965 dev_err(dev, "SoundWire: Invalid port number :%d\n", num); in sdw_slave_port_is_valid_range()
966 return -EINVAL; in sdw_slave_port_is_valid_range()
981 list_for_each_entry(p_rt, &s_rt->port_list, port_node) { in sdw_slave_port_config()
986 ret = sdw_slave_port_is_valid_range(&slave->dev, port_config[i].num); in sdw_slave_port_config()
1001 return !list_empty(&m_rt->port_list); in sdw_master_port_allocated()
1008 list_for_each_entry_safe(p_rt, _p_rt, &m_rt->port_list, port_node) { in sdw_master_port_free()
1021 p_rt = sdw_port_alloc(&m_rt->port_list); in sdw_master_port_alloc()
1023 return -ENOMEM; in sdw_master_port_alloc()
1037 list_for_each_entry(p_rt, &m_rt->port_list, port_node) { in sdw_master_port_config()
1048 * sdw_slave_rt_alloc() - Allocate a Slave runtime handle.
1065 INIT_LIST_HEAD(&s_rt->port_list); in sdw_slave_rt_alloc()
1066 s_rt->slave = slave; in sdw_slave_rt_alloc()
1068 list_add_tail(&s_rt->m_rt_node, &m_rt->slave_rt_list); in sdw_slave_rt_alloc()
1074 * sdw_slave_rt_config() - Configure a Slave runtime handle.
1084 s_rt->ch_count = stream_config->ch_count; in sdw_slave_rt_config()
1085 s_rt->direction = stream_config->direction; in sdw_slave_rt_config()
1096 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in sdw_slave_rt_find()
1099 &m_rt->slave_rt_list, m_rt_node) { in sdw_slave_rt_find()
1100 if (s_rt->slave == slave) in sdw_slave_rt_find()
1108 * sdw_slave_rt_free() - Free Slave(s) runtime handle
1122 list_del(&s_rt->m_rt_node); in sdw_slave_rt_free()
1134 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in sdw_master_rt_find()
1135 if (m_rt->bus == bus) in sdw_master_rt_find()
1143 * sdw_master_rt_alloc() - Allocates a Master runtime handle
1162 INIT_LIST_HEAD(&m_rt->port_list); in sdw_master_rt_alloc()
1163 INIT_LIST_HEAD(&m_rt->slave_rt_list); in sdw_master_rt_alloc()
1170 insert_after = &stream->master_list; in sdw_master_rt_alloc()
1171 list_for_each_entry_reverse(walk_m_rt, &stream->master_list, stream_node) { in sdw_master_rt_alloc()
1172 if (walk_m_rt->bus->id < bus->id) { in sdw_master_rt_alloc()
1173 insert_after = &walk_m_rt->stream_node; in sdw_master_rt_alloc()
1177 list_add(&m_rt->stream_node, insert_after); in sdw_master_rt_alloc()
1179 list_add_tail(&m_rt->bus_node, &bus->m_rt_list); in sdw_master_rt_alloc()
1181 m_rt->bus = bus; in sdw_master_rt_alloc()
1182 m_rt->stream = stream; in sdw_master_rt_alloc()
1184 bus->stream_refcount++; in sdw_master_rt_alloc()
1190 * sdw_master_rt_config() - Configure Master runtime handle
1201 m_rt->ch_count = stream_config->ch_count; in sdw_master_rt_config()
1202 m_rt->direction = stream_config->direction; in sdw_master_rt_config()
1208 * sdw_master_rt_free() - Free Master runtime handle
1222 struct sdw_bus *bus = m_rt->bus; in sdw_master_rt_free()
1224 list_for_each_entry_safe(s_rt, _s_rt, &m_rt->slave_rt_list, m_rt_node) { in sdw_master_rt_free()
1225 sdw_slave_port_free(s_rt->slave, stream); in sdw_master_rt_free()
1226 sdw_slave_rt_free(s_rt->slave, stream); in sdw_master_rt_free()
1229 list_del(&m_rt->stream_node); in sdw_master_rt_free()
1230 list_del(&m_rt->bus_node); in sdw_master_rt_free()
1233 bus->stream_refcount--; in sdw_master_rt_free()
1237 * sdw_config_stream() - Configure the allocated stream
1240 * @stream: SoundWire stream
1259 if (stream->params.rate && in sdw_config_stream()
1260 stream->params.rate != stream_config->frame_rate) { in sdw_config_stream()
1261 dev_err(dev, "rate not matching, stream:%s\n", stream->name); in sdw_config_stream()
1262 return -EINVAL; in sdw_config_stream()
1265 if (stream->params.bps && in sdw_config_stream()
1266 stream->params.bps != stream_config->bps) { in sdw_config_stream()
1267 dev_err(dev, "bps not matching, stream:%s\n", stream->name); in sdw_config_stream()
1268 return -EINVAL; in sdw_config_stream()
1271 stream->type = stream_config->type; in sdw_config_stream()
1272 stream->params.rate = stream_config->frame_rate; in sdw_config_stream()
1273 stream->params.bps = stream_config->bps; in sdw_config_stream()
1275 /* TODO: Update this check during Device-device support */ in sdw_config_stream()
1277 stream->params.ch_count += stream_config->ch_count; in sdw_config_stream()
1283 * sdw_get_slave_dpn_prop() - Get Slave port capabilities
1298 num_ports = hweight32(slave->prop.source_ports); in sdw_get_slave_dpn_prop()
1299 dpn_prop = slave->prop.src_dpn_prop; in sdw_get_slave_dpn_prop()
1301 num_ports = hweight32(slave->prop.sink_ports); in sdw_get_slave_dpn_prop()
1302 dpn_prop = slave->prop.sink_dpn_prop; in sdw_get_slave_dpn_prop()
1316 * @stream: SoundWire stream
1320 * NOTE: This function is called from SoundWire stream ops and is
1329 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in sdw_acquire_bus_lock()
1330 bus = m_rt->bus; in sdw_acquire_bus_lock()
1332 mutex_lock(&bus->bus_lock); in sdw_acquire_bus_lock()
1339 * @stream: SoundWire stream
1342 * NOTE: This function is called from SoundWire stream ops and is
1351 list_for_each_entry_reverse(m_rt, &stream->master_list, stream_node) { in sdw_release_bus_lock()
1352 bus = m_rt->bus; in sdw_release_bus_lock()
1353 mutex_unlock(&bus->bus_lock); in sdw_release_bus_lock()
1367 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_prepare_stream()
1368 bus = m_rt->bus; in _sdw_prepare_stream()
1369 prop = &bus->prop; in _sdw_prepare_stream()
1370 memcpy(&params, &bus->params, sizeof(params)); in _sdw_prepare_stream()
1373 if ((prop->max_clk_freq % stream->params.rate) != 0) { in _sdw_prepare_stream()
1374 dev_err(bus->dev, "Async mode not supported\n"); in _sdw_prepare_stream()
1375 return -EINVAL; in _sdw_prepare_stream()
1380 /* TODO: Update this during Device-Device support */ in _sdw_prepare_stream()
1381 bus->params.bandwidth += m_rt->stream->params.rate * in _sdw_prepare_stream()
1382 m_rt->ch_count * m_rt->stream->params.bps; in _sdw_prepare_stream()
1385 if (bus->compute_params) { in _sdw_prepare_stream()
1386 ret = bus->compute_params(bus); in _sdw_prepare_stream()
1388 dev_err(bus->dev, "Compute params failed: %d\n", in _sdw_prepare_stream()
1398 dev_err(bus->dev, "Program params failed: %d\n", ret); in _sdw_prepare_stream()
1409 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_prepare_stream()
1410 bus = m_rt->bus; in _sdw_prepare_stream()
1415 dev_err(bus->dev, "Prepare port(s) failed ret = %d\n", in _sdw_prepare_stream()
1421 stream->state = SDW_STREAM_PREPARED; in _sdw_prepare_stream()
1426 memcpy(&bus->params, &params, sizeof(params)); in _sdw_prepare_stream()
1431 * sdw_prepare_stream() - Prepare SoundWire stream
1433 * @stream: Soundwire stream
1435 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1443 pr_err("SoundWire: Handle not found for stream\n"); in sdw_prepare_stream()
1444 return -EINVAL; in sdw_prepare_stream()
1449 if (stream->state == SDW_STREAM_PREPARED) { in sdw_prepare_stream()
1454 if (stream->state != SDW_STREAM_CONFIGURED && in sdw_prepare_stream()
1455 stream->state != SDW_STREAM_DEPREPARED && in sdw_prepare_stream()
1456 stream->state != SDW_STREAM_DISABLED) { in sdw_prepare_stream()
1458 __func__, stream->name, stream->state); in sdw_prepare_stream()
1459 ret = -EINVAL; in sdw_prepare_stream()
1467 * still need to be re-applied in sdw_prepare_stream()
1469 if (stream->state == SDW_STREAM_DISABLED) in sdw_prepare_stream()
1487 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_enable_stream()
1488 bus = m_rt->bus; in _sdw_enable_stream()
1493 dev_err(bus->dev, "%s: Program params failed: %d\n", __func__, ret); in _sdw_enable_stream()
1500 dev_err(bus->dev, in _sdw_enable_stream()
1512 stream->state = SDW_STREAM_ENABLED; in _sdw_enable_stream()
1517 * sdw_enable_stream() - Enable SoundWire stream
1519 * @stream: Soundwire stream
1521 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1528 pr_err("SoundWire: Handle not found for stream\n"); in sdw_enable_stream()
1529 return -EINVAL; in sdw_enable_stream()
1534 if (stream->state == SDW_STREAM_ENABLED) { in sdw_enable_stream()
1539 if (stream->state != SDW_STREAM_PREPARED && in sdw_enable_stream()
1540 stream->state != SDW_STREAM_DISABLED) { in sdw_enable_stream()
1542 __func__, stream->name, stream->state); in sdw_enable_stream()
1543 ret = -EINVAL; in sdw_enable_stream()
1560 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_disable_stream()
1561 struct sdw_bus *bus = m_rt->bus; in _sdw_disable_stream()
1566 dev_err(bus->dev, "Disable port(s) failed: %d\n", ret); in _sdw_disable_stream()
1570 stream->state = SDW_STREAM_DISABLED; in _sdw_disable_stream()
1572 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_disable_stream()
1573 struct sdw_bus *bus = m_rt->bus; in _sdw_disable_stream()
1578 dev_err(bus->dev, "%s: Program params failed: %d\n", __func__, ret); in _sdw_disable_stream()
1590 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_disable_stream()
1591 struct sdw_bus *bus = m_rt->bus; in _sdw_disable_stream()
1596 dev_err(bus->dev, "Disable port(s) failed: %d\n", ret); in _sdw_disable_stream()
1605 * sdw_disable_stream() - Disable SoundWire stream
1607 * @stream: Soundwire stream
1609 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1616 pr_err("SoundWire: Handle not found for stream\n"); in sdw_disable_stream()
1617 return -EINVAL; in sdw_disable_stream()
1622 if (stream->state == SDW_STREAM_DISABLED) { in sdw_disable_stream()
1627 if (stream->state != SDW_STREAM_ENABLED) { in sdw_disable_stream()
1629 __func__, stream->name, stream->state); in sdw_disable_stream()
1630 ret = -EINVAL; in sdw_disable_stream()
1648 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_deprepare_stream()
1649 bus = m_rt->bus; in _sdw_deprepare_stream()
1650 /* De-prepare port(s) */ in _sdw_deprepare_stream()
1653 dev_err(bus->dev, in _sdw_deprepare_stream()
1654 "De-prepare port(s) failed: %d\n", ret); in _sdw_deprepare_stream()
1658 /* TODO: Update this during Device-Device support */ in _sdw_deprepare_stream()
1659 bus->params.bandwidth -= m_rt->stream->params.rate * in _sdw_deprepare_stream()
1660 m_rt->ch_count * m_rt->stream->params.bps; in _sdw_deprepare_stream()
1663 if (bus->compute_params) { in _sdw_deprepare_stream()
1664 ret = bus->compute_params(bus); in _sdw_deprepare_stream()
1666 dev_err(bus->dev, "Compute params failed: %d\n", in _sdw_deprepare_stream()
1675 dev_err(bus->dev, "%s: Program params failed: %d\n", __func__, ret); in _sdw_deprepare_stream()
1680 stream->state = SDW_STREAM_DEPREPARED; in _sdw_deprepare_stream()
1685 * sdw_deprepare_stream() - Deprepare SoundWire stream
1687 * @stream: Soundwire stream
1689 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1696 pr_err("SoundWire: Handle not found for stream\n"); in sdw_deprepare_stream()
1697 return -EINVAL; in sdw_deprepare_stream()
1702 if (stream->state == SDW_STREAM_DEPREPARED) { in sdw_deprepare_stream()
1707 if (stream->state != SDW_STREAM_PREPARED && in sdw_deprepare_stream()
1708 stream->state != SDW_STREAM_DISABLED) { in sdw_deprepare_stream()
1710 __func__, stream->name, stream->state); in sdw_deprepare_stream()
1711 ret = -EINVAL; in sdw_deprepare_stream()
1733 ret = snd_soc_dai_set_stream(dai, sdw_stream, substream->stream); in set_stream()
1735 dev_err(rtd->dev, "failed to set stream pointer on dai %s\n", dai->name); in set_stream()
1744 * sdw_alloc_stream() - Allocate and return stream runtime
1746 * @stream_name: SoundWire stream name
1748 * Allocates a SoundWire stream runtime instance.
1760 stream->name = stream_name; in sdw_alloc_stream()
1761 INIT_LIST_HEAD(&stream->master_list); in sdw_alloc_stream()
1762 stream->state = SDW_STREAM_ALLOCATED; in sdw_alloc_stream()
1763 stream->m_rt_count = 0; in sdw_alloc_stream()
1770 * sdw_startup_stream() - Startup SoundWire stream
1772 * @sdw_substream: Soundwire stream
1774 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1784 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in sdw_startup_stream()
1785 name = kasprintf(GFP_KERNEL, "%s-Playback", substream->name); in sdw_startup_stream()
1787 name = kasprintf(GFP_KERNEL, "%s-Capture", substream->name); in sdw_startup_stream()
1790 return -ENOMEM; in sdw_startup_stream()
1794 dev_err(rtd->dev, "alloc stream failed for substream DAI %s\n", substream->name); in sdw_startup_stream()
1795 ret = -ENOMEM; in sdw_startup_stream()
1814 * sdw_shutdown_stream() - Shutdown SoundWire stream
1816 * @sdw_substream: Soundwire stream
1818 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1830 sdw_stream = snd_soc_dai_get_stream(dai, substream->stream); in sdw_shutdown_stream()
1833 dev_err(rtd->dev, "no stream found for DAI %s\n", dai->name); in sdw_shutdown_stream()
1838 kfree(sdw_stream->name); in sdw_shutdown_stream()
1847 * sdw_release_stream() - Free the assigned stream runtime
1849 * @stream: SoundWire stream runtime
1860 * sdw_stream_add_master() - Allocate and add master runtime to a stream
1866 * @stream: SoundWire stream
1878 mutex_lock(&bus->bus_lock); in sdw_stream_add_master()
1883 * Check if bus->multi_link is set in sdw_stream_add_master()
1885 if (!bus->multi_link && stream->m_rt_count > 0) { in sdw_stream_add_master()
1886 dev_err(bus->dev, in sdw_stream_add_master()
1887 "Multilink not supported, link %d\n", bus->link_id); in sdw_stream_add_master()
1888 ret = -EINVAL; in sdw_stream_add_master()
1900 dev_err(bus->dev, "%s: Master runtime alloc failed for stream:%s\n", in sdw_stream_add_master()
1901 __func__, stream->name); in sdw_stream_add_master()
1902 ret = -ENOMEM; in sdw_stream_add_master()
1914 stream->m_rt_count++; in sdw_stream_add_master()
1921 ret = sdw_config_stream(bus->dev, stream, stream_config, false); in sdw_stream_add_master()
1936 mutex_unlock(&bus->bus_lock); in sdw_stream_add_master()
1942 * sdw_stream_remove_master() - Remove master from sdw_stream
1945 * @stream: SoundWire stream
1954 mutex_lock(&bus->bus_lock); in sdw_stream_remove_master()
1957 &stream->master_list, stream_node) { in sdw_stream_remove_master()
1958 if (m_rt->bus != bus) in sdw_stream_remove_master()
1963 stream->m_rt_count--; in sdw_stream_remove_master()
1966 if (list_empty(&stream->master_list)) in sdw_stream_remove_master()
1967 stream->state = SDW_STREAM_RELEASED; in sdw_stream_remove_master()
1969 mutex_unlock(&bus->bus_lock); in sdw_stream_remove_master()
1976 * sdw_stream_add_slave() - Allocate and add master/slave runtime to a stream
1980 * @stream: SoundWire stream
2001 mutex_lock(&slave->bus->bus_lock); in sdw_stream_add_slave()
2007 m_rt = sdw_master_rt_find(slave->bus, stream); in sdw_stream_add_slave()
2013 m_rt = sdw_master_rt_alloc(slave->bus, stream); in sdw_stream_add_slave()
2015 dev_err(&slave->dev, "%s: Master runtime alloc failed for stream:%s\n", in sdw_stream_add_slave()
2016 __func__, stream->name); in sdw_stream_add_slave()
2017 ret = -ENOMEM; in sdw_stream_add_slave()
2028 dev_err(&slave->dev, "Slave runtime alloc failed for stream:%s\n", in sdw_stream_add_slave()
2029 stream->name); in sdw_stream_add_slave()
2030 ret = -ENOMEM; in sdw_stream_add_slave()
2051 ret = sdw_config_stream(&slave->dev, stream, stream_config, true); in sdw_stream_add_slave()
2065 stream->state = SDW_STREAM_CONFIGURED; in sdw_stream_add_slave()
2079 mutex_unlock(&slave->bus->bus_lock); in sdw_stream_add_slave()
2085 * sdw_stream_remove_slave() - Remove slave from sdw_stream
2088 * @stream: SoundWire stream
2095 mutex_lock(&slave->bus->bus_lock); in sdw_stream_remove_slave()
2100 mutex_unlock(&slave->bus->bus_lock); in sdw_stream_remove_slave()