Lines Matching full:bus
5 * stream.c - SoundWire Bus stream operations.
16 #include "bus.h"
58 static int _sdw_program_slave_port_params(struct sdw_bus *bus, in _sdw_program_slave_port_params() argument
67 if (bus->params.next_bank) { in _sdw_program_slave_port_params()
82 dev_err(bus->dev, "DPN_OffsetCtrl2 register write failed\n"); in _sdw_program_slave_port_params()
89 dev_err(bus->dev, "DPN_BlockCtrl3 register write failed\n"); in _sdw_program_slave_port_params()
108 dev_err(bus->dev, "DPN_SampleCtrl2 register write failed\n"); in _sdw_program_slave_port_params()
119 dev_err(bus->dev, "DPN_HCtrl register write failed\n"); in _sdw_program_slave_port_params()
124 static int sdw_program_slave_port_params(struct sdw_bus *bus, in sdw_program_slave_port_params() argument
145 if (bus->params.next_bank) { in sdw_program_slave_port_params()
221 ret = _sdw_program_slave_port_params(bus, s_rt->slave, in sdw_program_slave_port_params()
232 static int sdw_program_master_port_params(struct sdw_bus *bus, in sdw_program_master_port_params() argument
243 ret = bus->port_ops->dpn_set_port_transport_params(bus, in sdw_program_master_port_params()
245 bus->params.next_bank); in sdw_program_master_port_params()
249 return bus->port_ops->dpn_set_port_params(bus, in sdw_program_master_port_params()
251 bus->params.next_bank); in sdw_program_master_port_params()
263 struct sdw_bus *bus = m_rt->bus; in sdw_program_port_params() local
270 ret = sdw_program_slave_port_params(bus, s_rt, p_rt); in sdw_program_port_params()
278 ret = sdw_program_master_port_params(bus, p_rt); in sdw_program_port_params()
289 * @bus: bus instance
297 static int sdw_enable_disable_slave_ports(struct sdw_bus *bus, in sdw_enable_disable_slave_ports() argument
306 if (bus->params.next_bank) in sdw_enable_disable_slave_ports()
312 * Since bus doesn't support sharing a port across two streams, in sdw_enable_disable_slave_ports()
333 struct sdw_bus *bus = m_rt->bus; in sdw_enable_disable_master_ports() local
342 if (bus->port_ops->dpn_port_enable_ch) { in sdw_enable_disable_master_ports()
343 ret = bus->port_ops->dpn_port_enable_ch(bus, in sdw_enable_disable_master_ports()
345 bus->params.next_bank); in sdw_enable_disable_master_ports()
347 dev_err(bus->dev, in sdw_enable_disable_master_ports()
353 dev_err(bus->dev, in sdw_enable_disable_master_ports()
378 ret = sdw_enable_disable_slave_ports(m_rt->bus, s_rt, in sdw_enable_disable_ports()
415 static int sdw_prep_deprep_slave_ports(struct sdw_bus *bus, in sdw_prep_deprep_slave_ports() argument
435 dev_err(bus->dev, in sdw_prep_deprep_slave_ports()
442 prep_ch.bank = bus->params.next_bank; in sdw_prep_deprep_slave_ports()
508 struct sdw_bus *bus = m_rt->bus; in sdw_prep_deprep_master_ports() local
509 const struct sdw_master_port_ops *ops = bus->port_ops; in sdw_prep_deprep_master_ports()
516 prep_ch.bank = bus->params.next_bank; in sdw_prep_deprep_master_ports()
520 ret = ops->dpn_port_prep(bus, &prep_ch); in sdw_prep_deprep_master_ports()
522 dev_err(bus->dev, "Port prepare failed for port:%d\n", in sdw_prep_deprep_master_ports()
547 ret = sdw_prep_deprep_slave_ports(m_rt->bus, s_rt, in sdw_prep_deprep_ports()
565 * sdw_notify_config() - Notify bus configuration
570 * new bus configuration.
575 struct sdw_bus *bus = m_rt->bus; in sdw_notify_config() local
579 if (bus->ops->set_bus_conf) { in sdw_notify_config()
580 ret = bus->ops->set_bus_conf(bus, &bus->params); in sdw_notify_config()
589 ret = slave->ops->bus_config(slave, &bus->params); in sdw_notify_config()
591 dev_err(bus->dev, "Notify Slave: %d failed\n", in sdw_notify_config()
604 * @bus: SDW bus instance
606 static int sdw_program_params(struct sdw_bus *bus) in sdw_program_params() argument
611 list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) { in sdw_program_params()
614 dev_err(bus->dev, in sdw_program_params()
621 dev_err(bus->dev, in sdw_program_params()
622 "Notify bus config failed: %d\n", ret); in sdw_program_params()
632 dev_err(bus->dev, "Enable channel failed: %d\n", ret); in sdw_program_params()
640 static int sdw_bank_switch(struct sdw_bus *bus, int m_rt_count) in sdw_bank_switch() argument
653 bus->defer_msg.msg = wr_msg; in sdw_bank_switch()
662 col_index = sdw_find_col_index(bus->params.col); in sdw_bank_switch()
663 row_index = sdw_find_row_index(bus->params.row); in sdw_bank_switch()
666 if (bus->params.next_bank) in sdw_bank_switch()
679 multi_link = bus->multi_link && (m_rt_count > 1); in sdw_bank_switch()
682 ret = sdw_transfer_defer(bus, wr_msg, &bus->defer_msg); in sdw_bank_switch()
684 ret = sdw_transfer(bus, wr_msg); in sdw_bank_switch()
687 dev_err(bus->dev, "Slave frame_ctrl reg write failed\n"); in sdw_bank_switch()
694 bus->defer_msg.msg = NULL; in sdw_bank_switch()
695 bus->params.curr_bank = !bus->params.curr_bank; in sdw_bank_switch()
696 bus->params.next_bank = !bus->params.next_bank; in sdw_bank_switch()
711 * @bus: SDW bus instance
715 static int sdw_ml_sync_bank_switch(struct sdw_bus *bus) in sdw_ml_sync_bank_switch() argument
719 if (!bus->multi_link) in sdw_ml_sync_bank_switch()
723 time_left = wait_for_completion_timeout(&bus->defer_msg.complete, in sdw_ml_sync_bank_switch()
724 bus->bank_switch_timeout); in sdw_ml_sync_bank_switch()
727 dev_err(bus->dev, "Controller Timed out on bank switch\n"); in sdw_ml_sync_bank_switch()
731 bus->params.curr_bank = !bus->params.curr_bank; in sdw_ml_sync_bank_switch()
732 bus->params.next_bank = !bus->params.next_bank; in sdw_ml_sync_bank_switch()
734 if (bus->defer_msg.msg) { in sdw_ml_sync_bank_switch()
735 kfree(bus->defer_msg.msg->buf); in sdw_ml_sync_bank_switch()
736 kfree(bus->defer_msg.msg); in sdw_ml_sync_bank_switch()
746 struct sdw_bus *bus; in do_bank_switch() local
751 bus = m_rt->bus; in do_bank_switch()
752 ops = bus->ops; in do_bank_switch()
754 if (bus->multi_link) { in do_bank_switch()
756 mutex_lock(&bus->msg_lock); in do_bank_switch()
761 ret = ops->pre_bank_switch(bus); in do_bank_switch()
763 dev_err(bus->dev, in do_bank_switch()
775 ret = sdw_bank_switch(bus, stream->m_rt_count); in do_bank_switch()
777 dev_err(bus->dev, "Bank switch failed: %d\n", ret); in do_bank_switch()
789 bus = m_rt->bus; in do_bank_switch()
790 ops = bus->ops; in do_bank_switch()
794 ret = ops->post_bank_switch(bus); in do_bank_switch()
796 dev_err(bus->dev, in do_bank_switch()
801 } else if (bus->multi_link && stream->m_rt_count > 1) { in do_bank_switch()
802 dev_err(bus->dev, in do_bank_switch()
808 if (!bus->bank_switch_timeout) in do_bank_switch()
809 bus->bank_switch_timeout = DEFAULT_BANK_SWITCH_TIMEOUT; in do_bank_switch()
812 ret = sdw_ml_sync_bank_switch(bus); in do_bank_switch()
814 dev_err(bus->dev, in do_bank_switch()
819 if (bus->multi_link) in do_bank_switch()
820 mutex_unlock(&bus->msg_lock); in do_bank_switch()
827 bus = m_rt->bus; in do_bank_switch()
829 kfree(bus->defer_msg.msg->buf); in do_bank_switch()
830 kfree(bus->defer_msg.msg); in do_bank_switch()
837 bus = m_rt->bus; in do_bank_switch()
838 if (mutex_is_locked(&bus->msg_lock)) in do_bank_switch()
839 mutex_unlock(&bus->msg_lock); in do_bank_switch()
886 *sdw_find_master_rt(struct sdw_bus *bus, in sdw_find_master_rt() argument
891 /* Retrieve Bus handle if already available */ in sdw_find_master_rt()
893 if (m_rt->bus == bus) in sdw_find_master_rt()
903 * @bus: SDW bus instance
910 *sdw_alloc_master_rt(struct sdw_bus *bus, in sdw_alloc_master_rt() argument
920 m_rt = sdw_find_master_rt(bus, stream); in sdw_alloc_master_rt()
933 list_add_tail(&m_rt->bus_node, &bus->m_rt_list); in sdw_alloc_master_rt()
937 m_rt->bus = bus; in sdw_alloc_master_rt()
972 static void sdw_master_port_release(struct sdw_bus *bus, in sdw_master_port_release() argument
983 static void sdw_slave_port_release(struct sdw_bus *bus, in sdw_slave_port_release() argument
1049 sdw_slave_port_release(s_rt->slave->bus, s_rt->slave, stream); in sdw_release_master_stream()
1061 * @bus: SDW Bus instance
1066 int sdw_stream_remove_master(struct sdw_bus *bus, in sdw_stream_remove_master() argument
1071 mutex_lock(&bus->bus_lock); in sdw_stream_remove_master()
1075 if (m_rt->bus != bus) in sdw_stream_remove_master()
1078 sdw_master_port_release(bus, m_rt); in sdw_stream_remove_master()
1086 mutex_unlock(&bus->bus_lock); in sdw_stream_remove_master()
1103 mutex_lock(&slave->bus->bus_lock); in sdw_stream_remove_slave()
1105 sdw_slave_port_release(slave->bus, slave, stream); in sdw_stream_remove_slave()
1108 mutex_unlock(&slave->bus->bus_lock); in sdw_stream_remove_slave()
1189 static int sdw_master_port_config(struct sdw_bus *bus, in sdw_master_port_config() argument
1199 p_rt = sdw_port_alloc(bus->dev, port_config, i); in sdw_master_port_config()
1252 * @bus: SDW Bus instance
1258 int sdw_stream_add_master(struct sdw_bus *bus, in sdw_stream_add_master() argument
1267 mutex_lock(&bus->bus_lock); in sdw_stream_add_master()
1271 * the bus supports it. in sdw_stream_add_master()
1272 * Check if bus->multi_link is set in sdw_stream_add_master()
1274 if (!bus->multi_link && stream->m_rt_count > 0) { in sdw_stream_add_master()
1275 dev_err(bus->dev, in sdw_stream_add_master()
1276 "Multilink not supported, link %d\n", bus->link_id); in sdw_stream_add_master()
1281 m_rt = sdw_alloc_master_rt(bus, stream_config, stream); in sdw_stream_add_master()
1283 dev_err(bus->dev, in sdw_stream_add_master()
1290 ret = sdw_config_stream(bus->dev, stream, stream_config, false); in sdw_stream_add_master()
1294 ret = sdw_master_port_config(bus, m_rt, port_config, num_ports); in sdw_stream_add_master()
1305 mutex_unlock(&bus->bus_lock); in sdw_stream_add_master()
1333 mutex_lock(&slave->bus->bus_lock); in sdw_stream_add_slave()
1339 m_rt = sdw_alloc_master_rt(slave->bus, stream_config, stream); in sdw_stream_add_slave()
1369 * Bus is not aware of number of Slave(s) in a stream at this in sdw_stream_add_slave()
1383 mutex_unlock(&slave->bus->bus_lock); in sdw_stream_add_slave()
1420 * sdw_acquire_bus_lock: Acquire bus lock for all Master runtime(s)
1425 * stream to reconfigure the bus.
1432 struct sdw_bus *bus = NULL; in sdw_acquire_bus_lock() local
1436 bus = m_rt->bus; in sdw_acquire_bus_lock()
1438 mutex_lock(&bus->bus_lock); in sdw_acquire_bus_lock()
1443 * sdw_release_bus_lock: Release bus lock for all Master runtime(s)
1447 * Release the previously held bus_lock after reconfiguring the bus.
1454 struct sdw_bus *bus = NULL; in sdw_release_bus_lock() local
1458 bus = m_rt->bus; in sdw_release_bus_lock()
1459 mutex_unlock(&bus->bus_lock); in sdw_release_bus_lock()
1466 struct sdw_bus *bus = NULL; in _sdw_prepare_stream() local
1473 bus = m_rt->bus; in _sdw_prepare_stream()
1474 prop = &bus->prop; in _sdw_prepare_stream()
1475 memcpy(¶ms, &bus->params, sizeof(params)); in _sdw_prepare_stream()
1479 dev_err(bus->dev, "Async mode not supported\n"); in _sdw_prepare_stream()
1483 /* Increment cumulative bus bandwidth */ in _sdw_prepare_stream()
1485 bus->params.bandwidth += m_rt->stream->params.rate * in _sdw_prepare_stream()
1489 if (bus->compute_params) { in _sdw_prepare_stream()
1490 ret = bus->compute_params(bus); in _sdw_prepare_stream()
1492 dev_err(bus->dev, "Compute params failed: %d", in _sdw_prepare_stream()
1499 ret = sdw_program_params(bus); in _sdw_prepare_stream()
1501 dev_err(bus->dev, "Program params failed: %d\n", ret); in _sdw_prepare_stream()
1506 if (!bus) { in _sdw_prepare_stream()
1513 dev_err(bus->dev, "Bank switch failed: %d\n", ret); in _sdw_prepare_stream()
1518 bus = m_rt->bus; in _sdw_prepare_stream()
1523 dev_err(bus->dev, "Prepare port(s) failed ret = %d\n", in _sdw_prepare_stream()
1534 memcpy(&bus->params, ¶ms, sizeof(params)); in _sdw_prepare_stream()
1568 struct sdw_bus *bus = NULL; in _sdw_enable_stream() local
1573 bus = m_rt->bus; in _sdw_enable_stream()
1576 ret = sdw_program_params(bus); in _sdw_enable_stream()
1578 dev_err(bus->dev, "Program params failed: %d\n", ret); in _sdw_enable_stream()
1585 dev_err(bus->dev, in _sdw_enable_stream()
1591 if (!bus) { in _sdw_enable_stream()
1598 dev_err(bus->dev, "Bank switch failed: %d\n", ret); in _sdw_enable_stream()
1639 struct sdw_bus *bus = m_rt->bus; in _sdw_disable_stream() local
1644 dev_err(bus->dev, "Disable port(s) failed: %d\n", ret); in _sdw_disable_stream()
1651 struct sdw_bus *bus = m_rt->bus; in _sdw_disable_stream() local
1654 ret = sdw_program_params(bus); in _sdw_disable_stream()
1656 dev_err(bus->dev, "Program params failed: %d\n", ret); in _sdw_disable_stream()
1669 struct sdw_bus *bus = m_rt->bus; in _sdw_disable_stream() local
1674 dev_err(bus->dev, "Disable port(s) failed: %d\n", ret); in _sdw_disable_stream()
1712 struct sdw_bus *bus; in _sdw_deprepare_stream() local
1716 bus = m_rt->bus; in _sdw_deprepare_stream()
1720 dev_err(bus->dev, in _sdw_deprepare_stream()
1726 bus->params.bandwidth -= m_rt->stream->params.rate * in _sdw_deprepare_stream()
1730 ret = sdw_program_params(bus); in _sdw_deprepare_stream()
1732 dev_err(bus->dev, "Program params failed: %d\n", ret); in _sdw_deprepare_stream()