• Home
  • Raw
  • Download

Lines Matching +full:stream +full:- +full:mode +full:- +full:support

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.
70 if (bus->params.next_bank) { in _sdw_program_slave_port_params()
71 addr1 = SDW_DPN_OFFSETCTRL2_B1(t_params->port_num); in _sdw_program_slave_port_params()
72 addr2 = SDW_DPN_BLOCKCTRL3_B1(t_params->port_num); in _sdw_program_slave_port_params()
73 addr3 = SDW_DPN_SAMPLECTRL2_B1(t_params->port_num); in _sdw_program_slave_port_params()
74 addr4 = SDW_DPN_HCTRL_B1(t_params->port_num); in _sdw_program_slave_port_params()
76 addr1 = SDW_DPN_OFFSETCTRL2_B0(t_params->port_num); in _sdw_program_slave_port_params()
77 addr2 = SDW_DPN_BLOCKCTRL3_B0(t_params->port_num); in _sdw_program_slave_port_params()
78 addr3 = SDW_DPN_SAMPLECTRL2_B0(t_params->port_num); in _sdw_program_slave_port_params()
79 addr4 = SDW_DPN_HCTRL_B0(t_params->port_num); in _sdw_program_slave_port_params()
83 ret = sdw_write(slave, addr1, t_params->offset2); in _sdw_program_slave_port_params()
85 dev_err(bus->dev, "DPN_OffsetCtrl2 register write failed\n"); in _sdw_program_slave_port_params()
90 ret = sdw_write(slave, addr2, t_params->blk_pkg_mode); in _sdw_program_slave_port_params()
92 dev_err(bus->dev, "DPN_BlockCtrl3 register write failed\n"); in _sdw_program_slave_port_params()
105 wbuf = FIELD_GET(SDW_DPN_SAMPLECTRL_HIGH, t_params->sample_interval - 1); in _sdw_program_slave_port_params()
109 dev_err(bus->dev, "DPN_SampleCtrl2 register write failed\n"); in _sdw_program_slave_port_params()
114 wbuf = FIELD_PREP(SDW_DPN_HCTRL_HSTART, t_params->hstart); in _sdw_program_slave_port_params()
115 wbuf |= FIELD_PREP(SDW_DPN_HCTRL_HSTOP, t_params->hstop); in _sdw_program_slave_port_params()
119 dev_err(bus->dev, "DPN_HCtrl register write failed\n"); in _sdw_program_slave_port_params()
128 struct sdw_transport_params *t_params = &p_rt->transport_params; in sdw_program_slave_port_params()
129 struct sdw_port_params *p_params = &p_rt->port_params; in sdw_program_slave_port_params()
130 struct sdw_slave_prop *slave_prop = &s_rt->slave->prop; in sdw_program_slave_port_params()
136 dpn_prop = sdw_get_slave_dpn_prop(s_rt->slave, in sdw_program_slave_port_params()
137 s_rt->direction, in sdw_program_slave_port_params()
138 t_params->port_num); in sdw_program_slave_port_params()
140 return -EINVAL; in sdw_program_slave_port_params()
142 addr1 = SDW_DPN_PORTCTRL(t_params->port_num); in sdw_program_slave_port_params()
143 addr2 = SDW_DPN_BLOCKCTRL1(t_params->port_num); in sdw_program_slave_port_params()
145 if (bus->params.next_bank) { in sdw_program_slave_port_params()
146 addr3 = SDW_DPN_SAMPLECTRL1_B1(t_params->port_num); in sdw_program_slave_port_params()
147 addr4 = SDW_DPN_OFFSETCTRL1_B1(t_params->port_num); in sdw_program_slave_port_params()
148 addr5 = SDW_DPN_BLOCKCTRL2_B1(t_params->port_num); in sdw_program_slave_port_params()
149 addr6 = SDW_DPN_LANECTRL_B1(t_params->port_num); in sdw_program_slave_port_params()
152 addr3 = SDW_DPN_SAMPLECTRL1_B0(t_params->port_num); in sdw_program_slave_port_params()
153 addr4 = SDW_DPN_OFFSETCTRL1_B0(t_params->port_num); in sdw_program_slave_port_params()
154 addr5 = SDW_DPN_BLOCKCTRL2_B0(t_params->port_num); in sdw_program_slave_port_params()
155 addr6 = SDW_DPN_LANECTRL_B0(t_params->port_num); in sdw_program_slave_port_params()
159 wbuf = FIELD_PREP(SDW_DPN_PORTCTRL_DATAMODE, p_params->data_mode); in sdw_program_slave_port_params()
160 wbuf |= FIELD_PREP(SDW_DPN_PORTCTRL_FLOWMODE, p_params->flow_mode); in sdw_program_slave_port_params()
162 ret = sdw_update(s_rt->slave, addr1, 0xF, wbuf); in sdw_program_slave_port_params()
164 dev_err(&s_rt->slave->dev, in sdw_program_slave_port_params()
166 t_params->port_num); in sdw_program_slave_port_params()
170 if (!dpn_prop->read_only_wordlength) { in sdw_program_slave_port_params()
172 ret = sdw_write(s_rt->slave, addr2, (p_params->bps - 1)); in sdw_program_slave_port_params()
174 dev_err(&s_rt->slave->dev, in sdw_program_slave_port_params()
176 t_params->port_num); in sdw_program_slave_port_params()
182 wbuf = (t_params->sample_interval - 1) & SDW_DPN_SAMPLECTRL_LOW; in sdw_program_slave_port_params()
183 ret = sdw_write(s_rt->slave, addr3, wbuf); in sdw_program_slave_port_params()
185 dev_err(&s_rt->slave->dev, in sdw_program_slave_port_params()
187 t_params->port_num); in sdw_program_slave_port_params()
192 ret = sdw_write(s_rt->slave, addr4, t_params->offset1); in sdw_program_slave_port_params()
194 dev_err(&s_rt->slave->dev, in sdw_program_slave_port_params()
196 t_params->port_num); in sdw_program_slave_port_params()
201 if (t_params->blk_grp_ctrl_valid) { in sdw_program_slave_port_params()
202 ret = sdw_write(s_rt->slave, addr5, t_params->blk_grp_ctrl); in sdw_program_slave_port_params()
204 dev_err(&s_rt->slave->dev, in sdw_program_slave_port_params()
206 t_params->port_num); in sdw_program_slave_port_params()
212 if (slave_prop->lane_control_support) { in sdw_program_slave_port_params()
213 ret = sdw_write(s_rt->slave, addr6, t_params->lane_ctrl); in sdw_program_slave_port_params()
215 dev_err(&s_rt->slave->dev, in sdw_program_slave_port_params()
217 t_params->port_num); in sdw_program_slave_port_params()
222 if (dpn_prop->type != SDW_DPN_SIMPLE) { in sdw_program_slave_port_params()
223 ret = _sdw_program_slave_port_params(bus, s_rt->slave, in sdw_program_slave_port_params()
224 t_params, dpn_prop->type); in sdw_program_slave_port_params()
226 dev_err(&s_rt->slave->dev, in sdw_program_slave_port_params()
228 t_params->port_num); in sdw_program_slave_port_params()
243 * length, flow mode etc of the port in sdw_program_master_port_params()
245 ret = bus->port_ops->dpn_set_port_transport_params(bus, in sdw_program_master_port_params()
246 &p_rt->transport_params, in sdw_program_master_port_params()
247 bus->params.next_bank); in sdw_program_master_port_params()
251 return bus->port_ops->dpn_set_port_params(bus, in sdw_program_master_port_params()
252 &p_rt->port_params, in sdw_program_master_port_params()
253 bus->params.next_bank); in sdw_program_master_port_params()
257 * sdw_program_port_params() - Programs transport parameters of Master(s)
260 * @m_rt: Master stream runtime
265 struct sdw_bus *bus = m_rt->bus; in sdw_program_port_params()
270 list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) { in sdw_program_port_params()
271 list_for_each_entry(p_rt, &s_rt->port_list, port_node) { in sdw_program_port_params()
279 list_for_each_entry(p_rt, &m_rt->port_list, port_node) { in sdw_program_port_params()
304 struct sdw_transport_params *t_params = &p_rt->transport_params; in sdw_enable_disable_slave_ports()
308 if (bus->params.next_bank) in sdw_enable_disable_slave_ports()
309 addr = SDW_DPN_CHANNELEN_B1(p_rt->num); in sdw_enable_disable_slave_ports()
311 addr = SDW_DPN_CHANNELEN_B0(p_rt->num); in sdw_enable_disable_slave_ports()
314 * Since bus doesn't support sharing a port across two streams, in sdw_enable_disable_slave_ports()
318 ret = sdw_write(s_rt->slave, addr, p_rt->ch_mask); in sdw_enable_disable_slave_ports()
320 ret = sdw_write(s_rt->slave, addr, 0x0); in sdw_enable_disable_slave_ports()
323 dev_err(&s_rt->slave->dev, in sdw_enable_disable_slave_ports()
325 ret, t_params->port_num); in sdw_enable_disable_slave_ports()
334 struct sdw_transport_params *t_params = &p_rt->transport_params; in sdw_enable_disable_master_ports()
335 struct sdw_bus *bus = m_rt->bus; in sdw_enable_disable_master_ports()
339 enable_ch.port_num = p_rt->num; in sdw_enable_disable_master_ports()
340 enable_ch.ch_mask = p_rt->ch_mask; in sdw_enable_disable_master_ports()
344 if (bus->port_ops->dpn_port_enable_ch) { in sdw_enable_disable_master_ports()
345 ret = bus->port_ops->dpn_port_enable_ch(bus, in sdw_enable_disable_master_ports()
347 bus->params.next_bank); in sdw_enable_disable_master_ports()
349 dev_err(bus->dev, in sdw_enable_disable_master_ports()
351 ret, t_params->port_num); in sdw_enable_disable_master_ports()
355 dev_err(bus->dev, in sdw_enable_disable_master_ports()
358 return -EINVAL; in sdw_enable_disable_master_ports()
365 * sdw_enable_disable_ports() - Enable/disable port(s) for Master and
368 * @m_rt: Master stream runtime
369 * @en: mode (enable/disable)
378 list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) { in sdw_enable_disable_ports()
379 list_for_each_entry(s_port, &s_rt->port_list, port_node) { in sdw_enable_disable_ports()
380 ret = sdw_enable_disable_slave_ports(m_rt->bus, s_rt, in sdw_enable_disable_ports()
388 list_for_each_entry(m_port, &m_rt->port_list, port_node) { in sdw_enable_disable_ports()
401 const struct sdw_slave_ops *ops = s_rt->slave->ops; in sdw_do_port_prep()
404 if (ops->port_prep) { in sdw_do_port_prep()
405 ret = ops->port_prep(s_rt->slave, &prep_ch, cmd); in sdw_do_port_prep()
407 dev_err(&s_rt->slave->dev, in sdw_do_port_prep()
429 prep_ch.num = p_rt->num; in sdw_prep_deprep_slave_ports()
430 prep_ch.ch_mask = p_rt->ch_mask; in sdw_prep_deprep_slave_ports()
432 dpn_prop = sdw_get_slave_dpn_prop(s_rt->slave, in sdw_prep_deprep_slave_ports()
433 s_rt->direction, in sdw_prep_deprep_slave_ports()
436 dev_err(bus->dev, in sdw_prep_deprep_slave_ports()
438 return -EINVAL; in sdw_prep_deprep_slave_ports()
443 prep_ch.bank = bus->params.next_bank; in sdw_prep_deprep_slave_ports()
445 if (dpn_prop->imp_def_interrupts || !dpn_prop->simple_ch_prep_sm || in sdw_prep_deprep_slave_ports()
446 bus->params.s_data_mode != SDW_PORT_DATA_MODE_NORMAL) in sdw_prep_deprep_slave_ports()
451 * For Port de-prepare, it is assumed that port in sdw_prep_deprep_slave_ports()
455 ret = sdw_configure_dpn_intr(s_rt->slave, p_rt->num, prep, in sdw_prep_deprep_slave_ports()
456 dpn_prop->imp_def_interrupts); in sdw_prep_deprep_slave_ports()
465 if (!dpn_prop->simple_ch_prep_sm) { in sdw_prep_deprep_slave_ports()
466 addr = SDW_DPN_PREPARECTRL(p_rt->num); in sdw_prep_deprep_slave_ports()
469 ret = sdw_write(s_rt->slave, addr, p_rt->ch_mask); in sdw_prep_deprep_slave_ports()
471 ret = sdw_write(s_rt->slave, addr, 0x0); in sdw_prep_deprep_slave_ports()
474 dev_err(&s_rt->slave->dev, in sdw_prep_deprep_slave_ports()
480 port_ready = &s_rt->slave->port_ready[prep_ch.num]; in sdw_prep_deprep_slave_ports()
482 msecs_to_jiffies(dpn_prop->ch_prep_timeout)); in sdw_prep_deprep_slave_ports()
484 val = sdw_read(s_rt->slave, SDW_DPN_PREPARESTATUS(p_rt->num)); in sdw_prep_deprep_slave_ports()
485 if ((val < 0) || (val & p_rt->ch_mask)) { in sdw_prep_deprep_slave_ports()
486 ret = (val < 0) ? val : -ETIMEDOUT; in sdw_prep_deprep_slave_ports()
487 dev_err(&s_rt->slave->dev, in sdw_prep_deprep_slave_ports()
496 /* Disable interrupt after Port de-prepare */ in sdw_prep_deprep_slave_ports()
498 ret = sdw_configure_dpn_intr(s_rt->slave, p_rt->num, prep, in sdw_prep_deprep_slave_ports()
499 dpn_prop->imp_def_interrupts); in sdw_prep_deprep_slave_ports()
508 struct sdw_transport_params *t_params = &p_rt->transport_params; in sdw_prep_deprep_master_ports()
509 struct sdw_bus *bus = m_rt->bus; in sdw_prep_deprep_master_ports()
510 const struct sdw_master_port_ops *ops = bus->port_ops; in sdw_prep_deprep_master_ports()
514 prep_ch.num = p_rt->num; in sdw_prep_deprep_master_ports()
515 prep_ch.ch_mask = p_rt->ch_mask; in sdw_prep_deprep_master_ports()
516 prep_ch.prepare = prep; /* Prepare/De-prepare */ in sdw_prep_deprep_master_ports()
517 prep_ch.bank = bus->params.next_bank; in sdw_prep_deprep_master_ports()
519 /* Pre-prepare/Pre-deprepare port(s) */ in sdw_prep_deprep_master_ports()
520 if (ops->dpn_port_prep) { in sdw_prep_deprep_master_ports()
521 ret = ops->dpn_port_prep(bus, &prep_ch); in sdw_prep_deprep_master_ports()
523 dev_err(bus->dev, "Port prepare failed for port:%d\n", in sdw_prep_deprep_master_ports()
524 t_params->port_num); in sdw_prep_deprep_master_ports()
533 * sdw_prep_deprep_ports() - Prepare/De-prepare port(s) for Master(s) and
537 * @prep: Prepare or De-prepare
545 /* Prepare/De-prepare Slave port(s) */ in sdw_prep_deprep_ports()
546 list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) { in sdw_prep_deprep_ports()
547 list_for_each_entry(p_rt, &s_rt->port_list, port_node) { in sdw_prep_deprep_ports()
548 ret = sdw_prep_deprep_slave_ports(m_rt->bus, s_rt, in sdw_prep_deprep_ports()
555 /* Prepare/De-prepare Master port(s) */ in sdw_prep_deprep_ports()
556 list_for_each_entry(p_rt, &m_rt->port_list, port_node) { in sdw_prep_deprep_ports()
566 * sdw_notify_config() - Notify bus configuration
576 struct sdw_bus *bus = m_rt->bus; in sdw_notify_config()
580 if (bus->ops->set_bus_conf) { in sdw_notify_config()
581 ret = bus->ops->set_bus_conf(bus, &bus->params); in sdw_notify_config()
586 list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) { in sdw_notify_config()
587 slave = s_rt->slave; in sdw_notify_config()
589 if (slave->ops->bus_config) { in sdw_notify_config()
590 ret = slave->ops->bus_config(slave, &bus->params); in sdw_notify_config()
592 dev_err(bus->dev, "Notify Slave: %d failed\n", in sdw_notify_config()
593 slave->dev_num); in sdw_notify_config()
603 * sdw_program_params() - Program transport and port parameters for Master(s)
614 list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) { in sdw_program_params()
619 * explicitly preparing a stream or handling an in sdw_program_params()
620 * already-prepared stream otherwise. in sdw_program_params()
623 m_rt->stream->state == SDW_STREAM_CONFIGURED) in sdw_program_params()
628 dev_err(bus->dev, in sdw_program_params()
635 dev_err(bus->dev, in sdw_program_params()
641 if (m_rt->stream->state != SDW_STREAM_ENABLED) in sdw_program_params()
646 dev_err(bus->dev, "Enable channel failed: %d\n", ret); in sdw_program_params()
665 return -ENOMEM; in sdw_bank_switch()
667 bus->defer_msg.msg = wr_msg; in sdw_bank_switch()
671 ret = -ENOMEM; in sdw_bank_switch()
676 col_index = sdw_find_col_index(bus->params.col); in sdw_bank_switch()
677 row_index = sdw_find_row_index(bus->params.row); in sdw_bank_switch()
680 if (bus->params.next_bank) in sdw_bank_switch()
687 wr_msg->ssp_sync = true; in sdw_bank_switch()
691 * and hardware-based sync is required in sdw_bank_switch()
693 multi_link = bus->multi_link && (m_rt_count >= bus->hw_sync_min_links); in sdw_bank_switch()
696 ret = sdw_transfer_defer(bus, wr_msg, &bus->defer_msg); in sdw_bank_switch()
701 dev_err(bus->dev, "Slave frame_ctrl reg write failed\n"); in sdw_bank_switch()
708 bus->defer_msg.msg = NULL; in sdw_bank_switch()
709 bus->params.curr_bank = !bus->params.curr_bank; in sdw_bank_switch()
710 bus->params.next_bank = !bus->params.next_bank; in sdw_bank_switch()
719 bus->defer_msg.msg = NULL; in sdw_bank_switch()
727 * @multi_link: whether this is a multi-link stream with hardware-based sync
739 time_left = wait_for_completion_timeout(&bus->defer_msg.complete, in sdw_ml_sync_bank_switch()
740 bus->bank_switch_timeout); in sdw_ml_sync_bank_switch()
743 dev_err(bus->dev, "Controller Timed out on bank switch\n"); in sdw_ml_sync_bank_switch()
744 return -ETIMEDOUT; in sdw_ml_sync_bank_switch()
747 bus->params.curr_bank = !bus->params.curr_bank; in sdw_ml_sync_bank_switch()
748 bus->params.next_bank = !bus->params.next_bank; in sdw_ml_sync_bank_switch()
750 if (bus->defer_msg.msg) { in sdw_ml_sync_bank_switch()
751 kfree(bus->defer_msg.msg->buf); in sdw_ml_sync_bank_switch()
752 kfree(bus->defer_msg.msg); in sdw_ml_sync_bank_switch()
758 static int do_bank_switch(struct sdw_stream_runtime *stream) in do_bank_switch() argument
767 m_rt_count = stream->m_rt_count; in do_bank_switch()
769 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in do_bank_switch()
770 bus = m_rt->bus; in do_bank_switch()
771 ops = bus->ops; in do_bank_switch()
773 if (bus->multi_link && m_rt_count >= bus->hw_sync_min_links) { in do_bank_switch()
775 mutex_lock(&bus->msg_lock); in do_bank_switch()
778 /* Pre-bank switch */ in do_bank_switch()
779 if (ops->pre_bank_switch) { in do_bank_switch()
780 ret = ops->pre_bank_switch(bus); in do_bank_switch()
782 dev_err(bus->dev, in do_bank_switch()
796 dev_err(bus->dev, "Bank switch failed: %d\n", ret); in do_bank_switch()
807 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in do_bank_switch()
808 bus = m_rt->bus; in do_bank_switch()
809 ops = bus->ops; in do_bank_switch()
811 /* Post-bank switch */ in do_bank_switch()
812 if (ops->post_bank_switch) { in do_bank_switch()
813 ret = ops->post_bank_switch(bus); in do_bank_switch()
815 dev_err(bus->dev, in do_bank_switch()
821 dev_err(bus->dev, in do_bank_switch()
827 if (!bus->bank_switch_timeout) in do_bank_switch()
828 bus->bank_switch_timeout = DEFAULT_BANK_SWITCH_TIMEOUT; in do_bank_switch()
833 dev_err(bus->dev, in do_bank_switch()
839 mutex_unlock(&bus->msg_lock); in do_bank_switch()
845 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in do_bank_switch()
846 bus = m_rt->bus; in do_bank_switch()
847 if (bus->defer_msg.msg) { in do_bank_switch()
848 kfree(bus->defer_msg.msg->buf); in do_bank_switch()
849 kfree(bus->defer_msg.msg); in do_bank_switch()
856 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in do_bank_switch()
857 bus = m_rt->bus; in do_bank_switch()
858 if (mutex_is_locked(&bus->msg_lock)) in do_bank_switch()
859 mutex_unlock(&bus->msg_lock); in do_bank_switch()
867 * sdw_release_stream() - Free the assigned stream runtime
869 * @stream: SoundWire stream runtime
871 * sdw_release_stream should be called only once per stream
873 void sdw_release_stream(struct sdw_stream_runtime *stream) in sdw_release_stream() argument
875 kfree(stream); in sdw_release_stream()
880 * sdw_alloc_stream() - Allocate and return stream runtime
882 * @stream_name: SoundWire stream name
884 * Allocates a SoundWire stream runtime instance.
885 * sdw_alloc_stream should be called only once per stream. Typically
890 struct sdw_stream_runtime *stream; in sdw_alloc_stream() local
892 stream = kzalloc(sizeof(*stream), GFP_KERNEL); in sdw_alloc_stream()
893 if (!stream) in sdw_alloc_stream()
896 stream->name = stream_name; in sdw_alloc_stream()
897 INIT_LIST_HEAD(&stream->master_list); in sdw_alloc_stream()
898 stream->state = SDW_STREAM_ALLOCATED; in sdw_alloc_stream()
899 stream->m_rt_count = 0; in sdw_alloc_stream()
901 return stream; in sdw_alloc_stream()
907 struct sdw_stream_runtime *stream) in sdw_find_master_rt() argument
912 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in sdw_find_master_rt()
913 if (m_rt->bus == bus) in sdw_find_master_rt()
921 * sdw_alloc_master_rt() - Allocates and initialize Master runtime handle
924 * @stream_config: Stream configuration
925 * @stream: Stream runtime handle.
932 struct sdw_stream_runtime *stream) in sdw_alloc_master_rt() argument
940 m_rt = sdw_find_master_rt(bus, stream); in sdw_alloc_master_rt()
949 INIT_LIST_HEAD(&m_rt->port_list); in sdw_alloc_master_rt()
950 INIT_LIST_HEAD(&m_rt->slave_rt_list); in sdw_alloc_master_rt()
951 list_add_tail(&m_rt->stream_node, &stream->master_list); in sdw_alloc_master_rt()
953 list_add_tail(&m_rt->bus_node, &bus->m_rt_list); in sdw_alloc_master_rt()
956 m_rt->ch_count = stream_config->ch_count; in sdw_alloc_master_rt()
957 m_rt->bus = bus; in sdw_alloc_master_rt()
958 m_rt->stream = stream; in sdw_alloc_master_rt()
959 m_rt->direction = stream_config->direction; in sdw_alloc_master_rt()
965 * sdw_alloc_slave_rt() - Allocate and initialize Slave runtime handle.
968 * @stream_config: Stream configuration
969 * @stream: Stream runtime handle
976 struct sdw_stream_runtime *stream) in sdw_alloc_slave_rt() argument
984 INIT_LIST_HEAD(&s_rt->port_list); in sdw_alloc_slave_rt()
985 s_rt->ch_count = stream_config->ch_count; in sdw_alloc_slave_rt()
986 s_rt->direction = stream_config->direction; in sdw_alloc_slave_rt()
987 s_rt->slave = slave; in sdw_alloc_slave_rt()
997 list_for_each_entry_safe(p_rt, _p_rt, &m_rt->port_list, port_node) { in sdw_master_port_release()
998 list_del(&p_rt->port_node); in sdw_master_port_release()
1005 struct sdw_stream_runtime *stream) in sdw_slave_port_release() argument
1011 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in sdw_slave_port_release()
1012 list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) { in sdw_slave_port_release()
1013 if (s_rt->slave != slave) in sdw_slave_port_release()
1017 &s_rt->port_list, port_node) { in sdw_slave_port_release()
1018 list_del(&p_rt->port_node); in sdw_slave_port_release()
1026 * sdw_release_slave_stream() - Free Slave(s) runtime handle
1029 * @stream: Stream runtime handle.
1034 struct sdw_stream_runtime *stream) in sdw_release_slave_stream() argument
1039 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in sdw_release_slave_stream()
1042 &m_rt->slave_rt_list, m_rt_node) { in sdw_release_slave_stream()
1043 if (s_rt->slave == slave) { in sdw_release_slave_stream()
1044 list_del(&s_rt->m_rt_node); in sdw_release_slave_stream()
1053 * sdw_release_master_stream() - Free Master runtime handle
1056 * @stream: Stream runtime handle.
1064 struct sdw_stream_runtime *stream) in sdw_release_master_stream() argument
1068 list_for_each_entry_safe(s_rt, _s_rt, &m_rt->slave_rt_list, m_rt_node) { in sdw_release_master_stream()
1069 sdw_slave_port_release(s_rt->slave->bus, s_rt->slave, stream); in sdw_release_master_stream()
1070 sdw_release_slave_stream(s_rt->slave, stream); in sdw_release_master_stream()
1073 list_del(&m_rt->stream_node); in sdw_release_master_stream()
1074 list_del(&m_rt->bus_node); in sdw_release_master_stream()
1079 * sdw_stream_remove_master() - Remove master from sdw_stream
1082 * @stream: SoundWire stream
1084 * This removes and frees port_rt and master_rt from a stream
1087 struct sdw_stream_runtime *stream) in sdw_stream_remove_master() argument
1091 mutex_lock(&bus->bus_lock); in sdw_stream_remove_master()
1094 &stream->master_list, stream_node) { in sdw_stream_remove_master()
1095 if (m_rt->bus != bus) in sdw_stream_remove_master()
1099 sdw_release_master_stream(m_rt, stream); in sdw_stream_remove_master()
1100 stream->m_rt_count--; in sdw_stream_remove_master()
1103 if (list_empty(&stream->master_list)) in sdw_stream_remove_master()
1104 stream->state = SDW_STREAM_RELEASED; in sdw_stream_remove_master()
1106 mutex_unlock(&bus->bus_lock); in sdw_stream_remove_master()
1113 * sdw_stream_remove_slave() - Remove slave from sdw_stream
1116 * @stream: SoundWire stream
1118 * This removes and frees port_rt and slave_rt from a stream
1121 struct sdw_stream_runtime *stream) in sdw_stream_remove_slave() argument
1123 mutex_lock(&slave->bus->bus_lock); in sdw_stream_remove_slave()
1125 sdw_slave_port_release(slave->bus, slave, stream); in sdw_stream_remove_slave()
1126 sdw_release_slave_stream(slave, stream); in sdw_stream_remove_slave()
1128 mutex_unlock(&slave->bus->bus_lock); in sdw_stream_remove_slave()
1135 * sdw_config_stream() - Configure the allocated stream
1138 * @stream: SoundWire stream
1139 * @stream_config: Stream configuration for audio stream
1145 struct sdw_stream_runtime *stream, in sdw_config_stream() argument
1150 * Update the stream rate, channel and bps based on data in sdw_config_stream()
1152 * match the rate, bps, stream type and increment number of channels. in sdw_config_stream()
1155 * comparison and allow the value to be set and stored in stream in sdw_config_stream()
1157 if (stream->params.rate && in sdw_config_stream()
1158 stream->params.rate != stream_config->frame_rate) { in sdw_config_stream()
1159 dev_err(dev, "rate not matching, stream:%s\n", stream->name); in sdw_config_stream()
1160 return -EINVAL; in sdw_config_stream()
1163 if (stream->params.bps && in sdw_config_stream()
1164 stream->params.bps != stream_config->bps) { in sdw_config_stream()
1165 dev_err(dev, "bps not matching, stream:%s\n", stream->name); in sdw_config_stream()
1166 return -EINVAL; in sdw_config_stream()
1169 stream->type = stream_config->type; in sdw_config_stream()
1170 stream->params.rate = stream_config->frame_rate; in sdw_config_stream()
1171 stream->params.bps = stream_config->bps; in sdw_config_stream()
1173 /* TODO: Update this check during Device-device support */ in sdw_config_stream()
1175 stream->params.ch_count += stream_config->ch_count; in sdw_config_stream()
1183 if (!SDW_VALID_PORT_RANGE(p_rt->num)) { in sdw_is_valid_port_range()
1185 "SoundWire: Invalid port number :%d\n", p_rt->num); in sdw_is_valid_port_range()
1186 return -EINVAL; in sdw_is_valid_port_range()
1203 p_rt->ch_mask = port_config[port_index].ch_mask; in sdw_port_alloc()
1204 p_rt->num = port_config[port_index].num; in sdw_port_alloc()
1219 p_rt = sdw_port_alloc(bus->dev, port_config, i); in sdw_master_port_config()
1221 return -ENOMEM; in sdw_master_port_config()
1225 * configuration (audio mode support) in sdw_master_port_config()
1228 list_add_tail(&p_rt->port_node, &m_rt->port_list); in sdw_master_port_config()
1244 p_rt = sdw_port_alloc(&slave->dev, port_config, i); in sdw_slave_port_config()
1246 return -ENOMEM; in sdw_slave_port_config()
1252 ret = sdw_is_valid_port_range(&slave->dev, p_rt); in sdw_slave_port_config()
1260 * configuration (audio mode support) in sdw_slave_port_config()
1263 list_add_tail(&p_rt->port_node, &s_rt->port_list); in sdw_slave_port_config()
1270 * sdw_stream_add_master() - Allocate and add master runtime to a stream
1273 * @stream_config: Stream configuration for audio stream
1274 * @port_config: Port configuration for audio stream
1276 * @stream: SoundWire stream
1282 struct sdw_stream_runtime *stream) in sdw_stream_add_master() argument
1287 mutex_lock(&bus->bus_lock); in sdw_stream_add_master()
1292 * Check if bus->multi_link is set in sdw_stream_add_master()
1294 if (!bus->multi_link && stream->m_rt_count > 0) { in sdw_stream_add_master()
1295 dev_err(bus->dev, in sdw_stream_add_master()
1296 "Multilink not supported, link %d\n", bus->link_id); in sdw_stream_add_master()
1297 ret = -EINVAL; in sdw_stream_add_master()
1301 m_rt = sdw_alloc_master_rt(bus, stream_config, stream); in sdw_stream_add_master()
1303 dev_err(bus->dev, in sdw_stream_add_master()
1304 "Master runtime config failed for stream:%s\n", in sdw_stream_add_master()
1305 stream->name); in sdw_stream_add_master()
1306 ret = -ENOMEM; in sdw_stream_add_master()
1310 ret = sdw_config_stream(bus->dev, stream, stream_config, false); in sdw_stream_add_master()
1318 stream->m_rt_count++; in sdw_stream_add_master()
1323 sdw_release_master_stream(m_rt, stream); in sdw_stream_add_master()
1325 mutex_unlock(&bus->bus_lock); in sdw_stream_add_master()
1331 * sdw_stream_add_slave() - Allocate and add master/slave runtime to a stream
1334 * @stream_config: Stream configuration for audio stream
1335 * @stream: SoundWire stream
1336 * @port_config: Port configuration for audio stream
1340 * to the Stream.
1347 struct sdw_stream_runtime *stream) in sdw_stream_add_slave() argument
1353 mutex_lock(&slave->bus->bus_lock); in sdw_stream_add_slave()
1359 m_rt = sdw_alloc_master_rt(slave->bus, stream_config, stream); in sdw_stream_add_slave()
1361 dev_err(&slave->dev, in sdw_stream_add_slave()
1362 "alloc master runtime failed for stream:%s\n", in sdw_stream_add_slave()
1363 stream->name); in sdw_stream_add_slave()
1364 ret = -ENOMEM; in sdw_stream_add_slave()
1368 s_rt = sdw_alloc_slave_rt(slave, stream_config, stream); in sdw_stream_add_slave()
1370 dev_err(&slave->dev, in sdw_stream_add_slave()
1371 "Slave runtime config failed for stream:%s\n", in sdw_stream_add_slave()
1372 stream->name); in sdw_stream_add_slave()
1373 ret = -ENOMEM; in sdw_stream_add_slave()
1377 ret = sdw_config_stream(&slave->dev, stream, stream_config, true); in sdw_stream_add_slave()
1389 list_add_tail(&s_rt->m_rt_node, &m_rt->slave_rt_list); in sdw_stream_add_slave()
1396 * Change stream state to CONFIGURED on first Slave add. in sdw_stream_add_slave()
1397 * Bus is not aware of number of Slave(s) in a stream at this in sdw_stream_add_slave()
1399 * change stream state to CONFIGURED. in sdw_stream_add_slave()
1401 stream->state = SDW_STREAM_CONFIGURED; in sdw_stream_add_slave()
1406 * we hit error so cleanup the stream, release all Slave(s) and in sdw_stream_add_slave()
1409 sdw_release_master_stream(m_rt, stream); in sdw_stream_add_slave()
1411 mutex_unlock(&slave->bus->bus_lock); in sdw_stream_add_slave()
1417 * sdw_get_slave_dpn_prop() - Get Slave port capabilities
1432 num_ports = hweight32(slave->prop.source_ports); in sdw_get_slave_dpn_prop()
1433 dpn_prop = slave->prop.src_dpn_prop; in sdw_get_slave_dpn_prop()
1435 num_ports = hweight32(slave->prop.sink_ports); in sdw_get_slave_dpn_prop()
1436 dpn_prop = slave->prop.sink_dpn_prop; in sdw_get_slave_dpn_prop()
1450 * @stream: SoundWire stream
1453 * stream to reconfigure the bus.
1454 * NOTE: This function is called from SoundWire stream ops and is
1457 static void sdw_acquire_bus_lock(struct sdw_stream_runtime *stream) in sdw_acquire_bus_lock() argument
1463 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in sdw_acquire_bus_lock()
1464 bus = m_rt->bus; in sdw_acquire_bus_lock()
1466 mutex_lock(&bus->bus_lock); in sdw_acquire_bus_lock()
1473 * @stream: SoundWire stream
1476 * NOTE: This function is called from SoundWire stream ops and is
1479 static void sdw_release_bus_lock(struct sdw_stream_runtime *stream) in sdw_release_bus_lock() argument
1485 list_for_each_entry_reverse(m_rt, &stream->master_list, stream_node) { in sdw_release_bus_lock()
1486 bus = m_rt->bus; in sdw_release_bus_lock()
1487 mutex_unlock(&bus->bus_lock); in sdw_release_bus_lock()
1491 static int _sdw_prepare_stream(struct sdw_stream_runtime *stream, in _sdw_prepare_stream() argument
1500 /* Prepare Master(s) and Slave(s) port(s) associated with stream */ in _sdw_prepare_stream()
1501 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_prepare_stream()
1502 bus = m_rt->bus; in _sdw_prepare_stream()
1503 prop = &bus->prop; in _sdw_prepare_stream()
1504 memcpy(&params, &bus->params, sizeof(params)); in _sdw_prepare_stream()
1506 /* TODO: Support Asynchronous mode */ in _sdw_prepare_stream()
1507 if ((prop->max_clk_freq % stream->params.rate) != 0) { in _sdw_prepare_stream()
1508 dev_err(bus->dev, "Async mode not supported\n"); in _sdw_prepare_stream()
1509 return -EINVAL; in _sdw_prepare_stream()
1516 /* TODO: Update this during Device-Device support */ in _sdw_prepare_stream()
1517 bus->params.bandwidth += m_rt->stream->params.rate * in _sdw_prepare_stream()
1518 m_rt->ch_count * m_rt->stream->params.bps; in _sdw_prepare_stream()
1521 if (bus->compute_params) { in _sdw_prepare_stream()
1522 ret = bus->compute_params(bus); in _sdw_prepare_stream()
1524 dev_err(bus->dev, "Compute params failed: %d", in _sdw_prepare_stream()
1534 dev_err(bus->dev, "Program params failed: %d\n", ret); in _sdw_prepare_stream()
1541 return -EINVAL; in _sdw_prepare_stream()
1544 ret = do_bank_switch(stream); in _sdw_prepare_stream()
1546 dev_err(bus->dev, "Bank switch failed: %d\n", ret); in _sdw_prepare_stream()
1550 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_prepare_stream()
1551 bus = m_rt->bus; in _sdw_prepare_stream()
1556 dev_err(bus->dev, "Prepare port(s) failed ret = %d\n", in _sdw_prepare_stream()
1562 stream->state = SDW_STREAM_PREPARED; in _sdw_prepare_stream()
1567 memcpy(&bus->params, &params, sizeof(params)); in _sdw_prepare_stream()
1572 * sdw_prepare_stream() - Prepare SoundWire stream
1574 * @stream: Soundwire stream
1576 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1578 int sdw_prepare_stream(struct sdw_stream_runtime *stream) in sdw_prepare_stream() argument
1583 if (!stream) { in sdw_prepare_stream()
1584 pr_err("SoundWire: Handle not found for stream\n"); in sdw_prepare_stream()
1585 return -EINVAL; in sdw_prepare_stream()
1588 sdw_acquire_bus_lock(stream); in sdw_prepare_stream()
1590 if (stream->state == SDW_STREAM_PREPARED) { in sdw_prepare_stream()
1595 if (stream->state != SDW_STREAM_CONFIGURED && in sdw_prepare_stream()
1596 stream->state != SDW_STREAM_DEPREPARED && in sdw_prepare_stream()
1597 stream->state != SDW_STREAM_DISABLED) { in sdw_prepare_stream()
1599 __func__, stream->name, stream->state); in sdw_prepare_stream()
1600 ret = -EINVAL; in sdw_prepare_stream()
1605 * when the stream is DISABLED, this means sdw_prepare_stream() in sdw_prepare_stream()
1608 * still need to be re-applied in sdw_prepare_stream()
1610 if (stream->state == SDW_STREAM_DISABLED) in sdw_prepare_stream()
1613 ret = _sdw_prepare_stream(stream, update_params); in sdw_prepare_stream()
1616 sdw_release_bus_lock(stream); in sdw_prepare_stream()
1621 static int _sdw_enable_stream(struct sdw_stream_runtime *stream) in _sdw_enable_stream() argument
1627 /* Enable Master(s) and Slave(s) port(s) associated with stream */ in _sdw_enable_stream()
1628 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_enable_stream()
1629 bus = m_rt->bus; in _sdw_enable_stream()
1634 dev_err(bus->dev, "Program params failed: %d\n", ret); in _sdw_enable_stream()
1641 dev_err(bus->dev, in _sdw_enable_stream()
1649 return -EINVAL; in _sdw_enable_stream()
1652 ret = do_bank_switch(stream); in _sdw_enable_stream()
1654 dev_err(bus->dev, "Bank switch failed: %d\n", ret); in _sdw_enable_stream()
1658 stream->state = SDW_STREAM_ENABLED; in _sdw_enable_stream()
1663 * sdw_enable_stream() - Enable SoundWire stream
1665 * @stream: Soundwire stream
1667 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1669 int sdw_enable_stream(struct sdw_stream_runtime *stream) in sdw_enable_stream() argument
1673 if (!stream) { in sdw_enable_stream()
1674 pr_err("SoundWire: Handle not found for stream\n"); in sdw_enable_stream()
1675 return -EINVAL; in sdw_enable_stream()
1678 sdw_acquire_bus_lock(stream); in sdw_enable_stream()
1680 if (stream->state != SDW_STREAM_PREPARED && in sdw_enable_stream()
1681 stream->state != SDW_STREAM_DISABLED) { in sdw_enable_stream()
1683 __func__, stream->name, stream->state); in sdw_enable_stream()
1684 ret = -EINVAL; in sdw_enable_stream()
1688 ret = _sdw_enable_stream(stream); in sdw_enable_stream()
1691 sdw_release_bus_lock(stream); in sdw_enable_stream()
1696 static int _sdw_disable_stream(struct sdw_stream_runtime *stream) in _sdw_disable_stream() argument
1701 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_disable_stream()
1702 struct sdw_bus *bus = m_rt->bus; in _sdw_disable_stream()
1707 dev_err(bus->dev, "Disable port(s) failed: %d\n", ret); in _sdw_disable_stream()
1711 stream->state = SDW_STREAM_DISABLED; in _sdw_disable_stream()
1713 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_disable_stream()
1714 struct sdw_bus *bus = m_rt->bus; in _sdw_disable_stream()
1719 dev_err(bus->dev, "Program params failed: %d\n", ret); in _sdw_disable_stream()
1724 ret = do_bank_switch(stream); in _sdw_disable_stream()
1731 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_disable_stream()
1732 struct sdw_bus *bus = m_rt->bus; in _sdw_disable_stream()
1737 dev_err(bus->dev, "Disable port(s) failed: %d\n", ret); in _sdw_disable_stream()
1746 * sdw_disable_stream() - Disable SoundWire stream
1748 * @stream: Soundwire stream
1750 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1752 int sdw_disable_stream(struct sdw_stream_runtime *stream) in sdw_disable_stream() argument
1756 if (!stream) { in sdw_disable_stream()
1757 pr_err("SoundWire: Handle not found for stream\n"); in sdw_disable_stream()
1758 return -EINVAL; in sdw_disable_stream()
1761 sdw_acquire_bus_lock(stream); in sdw_disable_stream()
1763 if (stream->state != SDW_STREAM_ENABLED) { in sdw_disable_stream()
1765 __func__, stream->name, stream->state); in sdw_disable_stream()
1766 ret = -EINVAL; in sdw_disable_stream()
1770 ret = _sdw_disable_stream(stream); in sdw_disable_stream()
1773 sdw_release_bus_lock(stream); in sdw_disable_stream()
1778 static int _sdw_deprepare_stream(struct sdw_stream_runtime *stream) in _sdw_deprepare_stream() argument
1784 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_deprepare_stream()
1785 bus = m_rt->bus; in _sdw_deprepare_stream()
1786 /* De-prepare port(s) */ in _sdw_deprepare_stream()
1789 dev_err(bus->dev, in _sdw_deprepare_stream()
1790 "De-prepare port(s) failed: %d\n", ret); in _sdw_deprepare_stream()
1794 /* TODO: Update this during Device-Device support */ in _sdw_deprepare_stream()
1795 bus->params.bandwidth -= m_rt->stream->params.rate * in _sdw_deprepare_stream()
1796 m_rt->ch_count * m_rt->stream->params.bps; in _sdw_deprepare_stream()
1799 if (bus->compute_params) { in _sdw_deprepare_stream()
1800 ret = bus->compute_params(bus); in _sdw_deprepare_stream()
1802 dev_err(bus->dev, "Compute params failed: %d", in _sdw_deprepare_stream()
1811 dev_err(bus->dev, "Program params failed: %d\n", ret); in _sdw_deprepare_stream()
1816 stream->state = SDW_STREAM_DEPREPARED; in _sdw_deprepare_stream()
1817 return do_bank_switch(stream); in _sdw_deprepare_stream()
1821 * sdw_deprepare_stream() - Deprepare SoundWire stream
1823 * @stream: Soundwire stream
1825 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1827 int sdw_deprepare_stream(struct sdw_stream_runtime *stream) in sdw_deprepare_stream() argument
1831 if (!stream) { in sdw_deprepare_stream()
1832 pr_err("SoundWire: Handle not found for stream\n"); in sdw_deprepare_stream()
1833 return -EINVAL; in sdw_deprepare_stream()
1836 sdw_acquire_bus_lock(stream); in sdw_deprepare_stream()
1838 if (stream->state != SDW_STREAM_PREPARED && in sdw_deprepare_stream()
1839 stream->state != SDW_STREAM_DISABLED) { in sdw_deprepare_stream()
1841 __func__, stream->name, stream->state); in sdw_deprepare_stream()
1842 ret = -EINVAL; in sdw_deprepare_stream()
1846 ret = _sdw_deprepare_stream(stream); in sdw_deprepare_stream()
1849 sdw_release_bus_lock(stream); in sdw_deprepare_stream()
1857 struct snd_soc_pcm_runtime *rtd = substream->private_data; in set_stream()
1862 /* Set stream pointer on all DAIs */ in set_stream()
1864 ret = snd_soc_dai_set_stream(dai, sdw_stream, substream->stream); in set_stream()
1866 dev_err(rtd->dev, "failed to set stream pointer on dai %s", dai->name); in set_stream()
1875 * sdw_startup_stream() - Startup SoundWire stream
1877 * @sdw_substream: Soundwire stream
1879 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1884 struct snd_soc_pcm_runtime *rtd = substream->private_data; in sdw_startup_stream()
1889 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in sdw_startup_stream()
1890 name = kasprintf(GFP_KERNEL, "%s-Playback", substream->name); in sdw_startup_stream()
1892 name = kasprintf(GFP_KERNEL, "%s-Capture", substream->name); in sdw_startup_stream()
1895 return -ENOMEM; in sdw_startup_stream()
1899 dev_err(rtd->dev, "alloc stream failed for substream DAI %s", substream->name); in sdw_startup_stream()
1900 ret = -ENOMEM; in sdw_startup_stream()
1919 * sdw_shutdown_stream() - Shutdown SoundWire stream
1921 * @sdw_substream: Soundwire stream
1923 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1928 struct snd_soc_pcm_runtime *rtd = substream->private_data; in sdw_shutdown_stream()
1932 /* Find stream from first CPU DAI */ in sdw_shutdown_stream()
1935 sdw_stream = snd_soc_dai_get_stream(dai, substream->stream); in sdw_shutdown_stream()
1938 dev_err(rtd->dev, "no stream found for DAI %s", dai->name); in sdw_shutdown_stream()
1943 kfree(sdw_stream->name); in sdw_shutdown_stream()