Lines Matching +full:bus +full:- +full:addr
1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2 // Copyright(c) 2015-17 Intel Corporation.
10 #include "bus.h"
15 static int sdw_get_id(struct sdw_bus *bus) in sdw_get_id() argument
22 bus->id = rc; in sdw_get_id()
27 * sdw_bus_master_add() - add a bus Master instance
28 * @bus: bus instance
32 * Initializes the bus instance, read properties and create child
35 int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent, in sdw_bus_master_add() argument
43 return -ENODEV; in sdw_bus_master_add()
46 ret = sdw_get_id(bus); in sdw_bus_master_add()
48 dev_err(parent, "Failed to get bus id\n"); in sdw_bus_master_add()
52 ret = sdw_master_device_add(bus, parent, fwnode); in sdw_bus_master_add()
55 bus->link_id); in sdw_bus_master_add()
59 if (!bus->ops) { in sdw_bus_master_add()
60 dev_err(bus->dev, "SoundWire Bus ops are not set\n"); in sdw_bus_master_add()
61 return -EINVAL; in sdw_bus_master_add()
64 if (!bus->compute_params) { in sdw_bus_master_add()
65 dev_err(bus->dev, in sdw_bus_master_add()
67 return -EINVAL; in sdw_bus_master_add()
70 mutex_init(&bus->msg_lock); in sdw_bus_master_add()
71 mutex_init(&bus->bus_lock); in sdw_bus_master_add()
72 INIT_LIST_HEAD(&bus->slaves); in sdw_bus_master_add()
73 INIT_LIST_HEAD(&bus->m_rt_list); in sdw_bus_master_add()
79 bus->multi_link = false; in sdw_bus_master_add()
80 if (bus->ops->read_prop) { in sdw_bus_master_add()
81 ret = bus->ops->read_prop(bus); in sdw_bus_master_add()
83 dev_err(bus->dev, in sdw_bus_master_add()
84 "Bus read properties failed:%d\n", ret); in sdw_bus_master_add()
89 sdw_bus_debugfs_init(bus); in sdw_bus_master_add()
99 *bus->assigned = ~GENMASK(SDW_BROADCAST_DEV_NUM, SDW_ENUM_DEV_NUM); in sdw_bus_master_add()
102 set_bit(SDW_ENUM_DEV_NUM, bus->assigned); in sdw_bus_master_add()
103 set_bit(SDW_BROADCAST_DEV_NUM, bus->assigned); in sdw_bus_master_add()
106 set_bit(SDW_GROUP12_DEV_NUM, bus->assigned); in sdw_bus_master_add()
107 set_bit(SDW_GROUP13_DEV_NUM, bus->assigned); in sdw_bus_master_add()
108 set_bit(SDW_MASTER_DEV_NUM, bus->assigned); in sdw_bus_master_add()
111 * SDW is an enumerable bus, but devices can be powered off. So, in sdw_bus_master_add()
117 if (IS_ENABLED(CONFIG_ACPI) && ACPI_HANDLE(bus->dev)) in sdw_bus_master_add()
118 ret = sdw_acpi_find_slaves(bus); in sdw_bus_master_add()
119 else if (IS_ENABLED(CONFIG_OF) && bus->dev->of_node) in sdw_bus_master_add()
120 ret = sdw_of_find_slaves(bus); in sdw_bus_master_add()
122 ret = -ENOTSUPP; /* No ACPI/DT so error out */ in sdw_bus_master_add()
125 dev_err(bus->dev, "Finding slaves failed:%d\n", ret); in sdw_bus_master_add()
132 * is that the bus will start at highest clock frequency when in sdw_bus_master_add()
138 prop = &bus->prop; in sdw_bus_master_add()
139 bus->params.max_dr_freq = prop->max_clk_freq * SDW_DOUBLE_RATE_FACTOR; in sdw_bus_master_add()
140 bus->params.curr_dr_freq = bus->params.max_dr_freq; in sdw_bus_master_add()
141 bus->params.curr_bank = SDW_BANK0; in sdw_bus_master_add()
142 bus->params.next_bank = SDW_BANK1; in sdw_bus_master_add()
151 struct sdw_bus *bus = slave->bus; in sdw_delete_slave() local
157 mutex_lock(&bus->bus_lock); in sdw_delete_slave()
159 if (slave->dev_num) /* clear dev_num if assigned */ in sdw_delete_slave()
160 clear_bit(slave->dev_num, bus->assigned); in sdw_delete_slave()
162 list_del_init(&slave->node); in sdw_delete_slave()
163 mutex_unlock(&bus->bus_lock); in sdw_delete_slave()
170 * sdw_bus_master_delete() - delete the bus master instance
171 * @bus: bus to be deleted
175 void sdw_bus_master_delete(struct sdw_bus *bus) in sdw_bus_master_delete() argument
177 device_for_each_child(bus->dev, NULL, sdw_delete_slave); in sdw_bus_master_delete()
178 sdw_master_device_del(bus); in sdw_bus_master_delete()
180 sdw_bus_debugfs_exit(bus); in sdw_bus_master_delete()
181 ida_free(&sdw_ida, bus->id); in sdw_bus_master_delete()
196 return -ENODATA; in find_response_code()
199 return -ETIMEDOUT; in find_response_code()
202 return -EIO; in find_response_code()
206 static inline int do_transfer(struct sdw_bus *bus, struct sdw_msg *msg) in do_transfer() argument
208 int retry = bus->prop.err_threshold; in do_transfer()
213 resp = bus->ops->xfer_msg(bus, msg); in do_transfer()
217 if (ret == 0 || ret == -ENODATA) in do_transfer()
224 static inline int do_transfer_defer(struct sdw_bus *bus, in do_transfer_defer() argument
228 int retry = bus->prop.err_threshold; in do_transfer_defer()
232 defer->msg = msg; in do_transfer_defer()
233 defer->length = msg->len; in do_transfer_defer()
234 init_completion(&defer->complete); in do_transfer_defer()
237 resp = bus->ops->xfer_msg_defer(bus, msg, defer); in do_transfer_defer()
240 if (ret == 0 || ret == -ENODATA) in do_transfer_defer()
247 static int sdw_reset_page(struct sdw_bus *bus, u16 dev_num) in sdw_reset_page() argument
249 int retry = bus->prop.err_threshold; in sdw_reset_page()
254 resp = bus->ops->reset_page_addr(bus, dev_num); in sdw_reset_page()
257 if (ret == 0 || ret == -ENODATA) in sdw_reset_page()
264 static int sdw_transfer_unlocked(struct sdw_bus *bus, struct sdw_msg *msg) in sdw_transfer_unlocked() argument
268 ret = do_transfer(bus, msg); in sdw_transfer_unlocked()
269 if (ret != 0 && ret != -ENODATA) in sdw_transfer_unlocked()
270 dev_err(bus->dev, "trf on Slave %d failed:%d\n", in sdw_transfer_unlocked()
271 msg->dev_num, ret); in sdw_transfer_unlocked()
273 if (msg->page) in sdw_transfer_unlocked()
274 sdw_reset_page(bus, msg->dev_num); in sdw_transfer_unlocked()
280 * sdw_transfer() - Synchronous transfer message to a SDW Slave device
281 * @bus: SDW bus
284 int sdw_transfer(struct sdw_bus *bus, struct sdw_msg *msg) in sdw_transfer() argument
288 mutex_lock(&bus->msg_lock); in sdw_transfer()
290 ret = sdw_transfer_unlocked(bus, msg); in sdw_transfer()
292 mutex_unlock(&bus->msg_lock); in sdw_transfer()
298 * sdw_transfer_defer() - Asynchronously transfer message to a SDW Slave device
299 * @bus: SDW bus
305 int sdw_transfer_defer(struct sdw_bus *bus, struct sdw_msg *msg, in sdw_transfer_defer() argument
310 if (!bus->ops->xfer_msg_defer) in sdw_transfer_defer()
311 return -ENOTSUPP; in sdw_transfer_defer()
313 ret = do_transfer_defer(bus, msg, defer); in sdw_transfer_defer()
314 if (ret != 0 && ret != -ENODATA) in sdw_transfer_defer()
315 dev_err(bus->dev, "Defer trf on Slave %d failed:%d\n", in sdw_transfer_defer()
316 msg->dev_num, ret); in sdw_transfer_defer()
318 if (msg->page) in sdw_transfer_defer()
319 sdw_reset_page(bus, msg->dev_num); in sdw_transfer_defer()
325 u32 addr, size_t count, u16 dev_num, u8 flags, u8 *buf) in sdw_fill_msg() argument
328 msg->addr = addr; /* addr is 16 bit and truncated here */ in sdw_fill_msg()
329 msg->len = count; in sdw_fill_msg()
330 msg->dev_num = dev_num; in sdw_fill_msg()
331 msg->flags = flags; in sdw_fill_msg()
332 msg->buf = buf; in sdw_fill_msg()
334 if (addr < SDW_REG_NO_PAGE) /* no paging area */ in sdw_fill_msg()
337 if (addr >= SDW_REG_MAX) { /* illegal addr */ in sdw_fill_msg()
338 pr_err("SDW: Invalid address %x passed\n", addr); in sdw_fill_msg()
339 return -EINVAL; in sdw_fill_msg()
342 if (addr < SDW_REG_OPTIONAL_PAGE) { /* 32k but no page */ in sdw_fill_msg()
343 if (slave && !slave->prop.paging_support) in sdw_fill_msg()
345 /* no need for else as that will fall-through to paging */ in sdw_fill_msg()
351 return -EINVAL; in sdw_fill_msg()
355 pr_err("SDW: No slave for paging addr\n"); in sdw_fill_msg()
356 return -EINVAL; in sdw_fill_msg()
359 if (!slave->prop.paging_support) { in sdw_fill_msg()
360 dev_err(&slave->dev, in sdw_fill_msg()
361 "address %x needs paging but no support\n", addr); in sdw_fill_msg()
362 return -EINVAL; in sdw_fill_msg()
365 msg->addr_page1 = FIELD_GET(SDW_SCP_ADDRPAGE1_MASK, addr); in sdw_fill_msg()
366 msg->addr_page2 = FIELD_GET(SDW_SCP_ADDRPAGE2_MASK, addr); in sdw_fill_msg()
367 msg->addr |= BIT(15); in sdw_fill_msg()
368 msg->page = true; in sdw_fill_msg()
375 * no_pm versions can only be called by the bus, e.g. while enumerating or
376 * handling suspend-resume sequences.
381 sdw_nread_no_pm(struct sdw_slave *slave, u32 addr, size_t count, u8 *val) in sdw_nread_no_pm() argument
386 ret = sdw_fill_msg(&msg, slave, addr, count, in sdw_nread_no_pm()
387 slave->dev_num, SDW_MSG_FLAG_READ, val); in sdw_nread_no_pm()
391 return sdw_transfer(slave->bus, &msg); in sdw_nread_no_pm()
395 sdw_nwrite_no_pm(struct sdw_slave *slave, u32 addr, size_t count, u8 *val) in sdw_nwrite_no_pm() argument
400 ret = sdw_fill_msg(&msg, slave, addr, count, in sdw_nwrite_no_pm()
401 slave->dev_num, SDW_MSG_FLAG_WRITE, val); in sdw_nwrite_no_pm()
405 return sdw_transfer(slave->bus, &msg); in sdw_nwrite_no_pm()
408 static int sdw_write_no_pm(struct sdw_slave *slave, u32 addr, u8 value) in sdw_write_no_pm() argument
410 return sdw_nwrite_no_pm(slave, addr, 1, &value); in sdw_write_no_pm()
414 sdw_bread_no_pm(struct sdw_bus *bus, u16 dev_num, u32 addr) in sdw_bread_no_pm() argument
420 ret = sdw_fill_msg(&msg, NULL, addr, 1, dev_num, in sdw_bread_no_pm()
425 ret = sdw_transfer(bus, &msg); in sdw_bread_no_pm()
433 sdw_bwrite_no_pm(struct sdw_bus *bus, u16 dev_num, u32 addr, u8 value) in sdw_bwrite_no_pm() argument
438 ret = sdw_fill_msg(&msg, NULL, addr, 1, dev_num, in sdw_bwrite_no_pm()
443 return sdw_transfer(bus, &msg); in sdw_bwrite_no_pm()
446 int sdw_bread_no_pm_unlocked(struct sdw_bus *bus, u16 dev_num, u32 addr) in sdw_bread_no_pm_unlocked() argument
452 ret = sdw_fill_msg(&msg, NULL, addr, 1, dev_num, in sdw_bread_no_pm_unlocked()
457 ret = sdw_transfer_unlocked(bus, &msg); in sdw_bread_no_pm_unlocked()
465 int sdw_bwrite_no_pm_unlocked(struct sdw_bus *bus, u16 dev_num, u32 addr, u8 value) in sdw_bwrite_no_pm_unlocked() argument
470 ret = sdw_fill_msg(&msg, NULL, addr, 1, dev_num, in sdw_bwrite_no_pm_unlocked()
475 return sdw_transfer_unlocked(bus, &msg); in sdw_bwrite_no_pm_unlocked()
480 sdw_read_no_pm(struct sdw_slave *slave, u32 addr) in sdw_read_no_pm() argument
485 ret = sdw_nread_no_pm(slave, addr, 1, &buf); in sdw_read_no_pm()
493 * sdw_nread() - Read "n" contiguous SDW Slave registers
495 * @addr: Register address
499 int sdw_nread(struct sdw_slave *slave, u32 addr, size_t count, u8 *val) in sdw_nread() argument
503 ret = pm_runtime_get_sync(slave->bus->dev); in sdw_nread()
504 if (ret < 0 && ret != -EACCES) { in sdw_nread()
505 pm_runtime_put_noidle(slave->bus->dev); in sdw_nread()
509 ret = sdw_nread_no_pm(slave, addr, count, val); in sdw_nread()
511 pm_runtime_mark_last_busy(slave->bus->dev); in sdw_nread()
512 pm_runtime_put(slave->bus->dev); in sdw_nread()
519 * sdw_nwrite() - Write "n" contiguous SDW Slave registers
521 * @addr: Register address
525 int sdw_nwrite(struct sdw_slave *slave, u32 addr, size_t count, u8 *val) in sdw_nwrite() argument
529 ret = pm_runtime_get_sync(slave->bus->dev); in sdw_nwrite()
530 if (ret < 0 && ret != -EACCES) { in sdw_nwrite()
531 pm_runtime_put_noidle(slave->bus->dev); in sdw_nwrite()
535 ret = sdw_nwrite_no_pm(slave, addr, count, val); in sdw_nwrite()
537 pm_runtime_mark_last_busy(slave->bus->dev); in sdw_nwrite()
538 pm_runtime_put(slave->bus->dev); in sdw_nwrite()
545 * sdw_read() - Read a SDW Slave register
547 * @addr: Register address
549 int sdw_read(struct sdw_slave *slave, u32 addr) in sdw_read() argument
554 ret = sdw_nread(slave, addr, 1, &buf); in sdw_read()
563 * sdw_write() - Write a SDW Slave register
565 * @addr: Register address
568 int sdw_write(struct sdw_slave *slave, u32 addr, u8 value) in sdw_write() argument
570 return sdw_nwrite(slave, addr, 1, &value); in sdw_write()
579 static struct sdw_slave *sdw_get_slave(struct sdw_bus *bus, int i) in sdw_get_slave() argument
583 list_for_each_entry(slave, &bus->slaves, node) { in sdw_get_slave()
584 if (slave->dev_num == i) in sdw_get_slave()
593 if (slave->id.mfg_id != id.mfg_id || in sdw_compare_devid()
594 slave->id.part_id != id.part_id || in sdw_compare_devid()
595 slave->id.class_id != id.class_id || in sdw_compare_devid()
596 (slave->id.unique_id != SDW_IGNORED_UNIQUE_ID && in sdw_compare_devid()
597 slave->id.unique_id != id.unique_id)) in sdw_compare_devid()
598 return -ENODEV; in sdw_compare_devid()
608 bit = find_first_zero_bit(slave->bus->assigned, SDW_MAX_DEVICES); in sdw_get_device_num()
610 bit = -ENODEV; in sdw_get_device_num()
618 set_bit(bit, slave->bus->assigned); in sdw_get_device_num()
630 if (!slave->dev_num) { in sdw_assign_device_num()
631 if (!slave->dev_num_sticky) { in sdw_assign_device_num()
632 mutex_lock(&slave->bus->bus_lock); in sdw_assign_device_num()
634 mutex_unlock(&slave->bus->bus_lock); in sdw_assign_device_num()
636 dev_err(slave->bus->dev, "Get dev_num failed: %d\n", in sdw_assign_device_num()
640 slave->dev_num = dev_num; in sdw_assign_device_num()
641 slave->dev_num_sticky = dev_num; in sdw_assign_device_num()
644 slave->dev_num = slave->dev_num_sticky; in sdw_assign_device_num()
649 dev_dbg(slave->bus->dev, in sdw_assign_device_num()
651 slave->dev_num); in sdw_assign_device_num()
653 /* Clear the slave->dev_num to transfer message on device 0 */ in sdw_assign_device_num()
654 dev_num = slave->dev_num; in sdw_assign_device_num()
655 slave->dev_num = 0; in sdw_assign_device_num()
659 dev_err(&slave->dev, "Program device_num %d failed: %d\n", in sdw_assign_device_num()
665 slave->dev_num = slave->dev_num_sticky; in sdw_assign_device_num()
670 void sdw_extract_slave_id(struct sdw_bus *bus, in sdw_extract_slave_id() argument
671 u64 addr, struct sdw_slave_id *id) in sdw_extract_slave_id() argument
673 dev_dbg(bus->dev, "SDW Slave Addr: %llx\n", addr); in sdw_extract_slave_id()
675 id->sdw_version = SDW_VERSION(addr); in sdw_extract_slave_id()
676 id->unique_id = SDW_UNIQUE_ID(addr); in sdw_extract_slave_id()
677 id->mfg_id = SDW_MFG_ID(addr); in sdw_extract_slave_id()
678 id->part_id = SDW_PART_ID(addr); in sdw_extract_slave_id()
679 id->class_id = SDW_CLASS_ID(addr); in sdw_extract_slave_id()
681 dev_dbg(bus->dev, in sdw_extract_slave_id()
683 id->class_id, id->part_id, id->mfg_id, in sdw_extract_slave_id()
684 id->unique_id, id->sdw_version); in sdw_extract_slave_id()
687 static int sdw_program_device_num(struct sdw_bus *bus) in sdw_program_device_num() argument
695 u64 addr; in sdw_program_device_num() local
704 ret = sdw_transfer(bus, &msg); in sdw_program_device_num()
705 if (ret == -ENODATA) { /* end of device id reads */ in sdw_program_device_num()
706 dev_dbg(bus->dev, "No more devices to enumerate\n"); in sdw_program_device_num()
711 dev_err(bus->dev, "DEVID read fail:%d\n", ret); in sdw_program_device_num()
716 * Construct the addr and extract. Cast the higher shift in sdw_program_device_num()
719 addr = buf[5] | (buf[4] << 8) | (buf[3] << 16) | in sdw_program_device_num()
723 sdw_extract_slave_id(bus, addr, &id); in sdw_program_device_num()
726 list_for_each_entry_safe(slave, _s, &bus->slaves, node) { in sdw_program_device_num()
738 dev_err(slave->bus->dev, in sdw_program_device_num()
757 sdw_slave_add(bus, &id, NULL); in sdw_program_device_num()
759 dev_err(bus->dev, "Slave Entry not found\n"); in sdw_program_device_num()
778 mutex_lock(&slave->bus->bus_lock); in sdw_modify_slave_status()
780 dev_vdbg(&slave->dev, in sdw_modify_slave_status()
782 __func__, slave->dev_num, slave->status, status); in sdw_modify_slave_status()
785 dev_dbg(&slave->dev, in sdw_modify_slave_status()
787 __func__, slave->dev_num); in sdw_modify_slave_status()
789 init_completion(&slave->enumeration_complete); in sdw_modify_slave_status()
790 init_completion(&slave->initialization_complete); in sdw_modify_slave_status()
793 (slave->status == SDW_SLAVE_UNATTACHED)) { in sdw_modify_slave_status()
794 dev_dbg(&slave->dev, in sdw_modify_slave_status()
796 __func__, slave->dev_num); in sdw_modify_slave_status()
798 complete(&slave->enumeration_complete); in sdw_modify_slave_status()
800 slave->status = status; in sdw_modify_slave_status()
801 mutex_unlock(&slave->bus->bus_lock); in sdw_modify_slave_status()
810 * ops->get_clk_stop_mode, else read from property. in sdw_get_clk_stop_mode()
812 if (slave->ops && slave->ops->get_clk_stop_mode) { in sdw_get_clk_stop_mode()
813 mode = slave->ops->get_clk_stop_mode(slave); in sdw_get_clk_stop_mode()
815 if (slave->prop.clk_stop_mode1) in sdw_get_clk_stop_mode()
830 if (slave->ops && slave->ops->clk_stop) { in sdw_slave_clk_stop_callback()
831 ret = slave->ops->clk_stop(slave, mode, type); in sdw_slave_clk_stop_callback()
833 dev_err(&slave->dev, in sdw_slave_clk_stop_callback()
850 wake_en = slave->prop.wake_capable; in sdw_slave_clk_stop_prepare()
869 dev_err(&slave->dev, in sdw_slave_clk_stop_prepare()
875 static int sdw_bus_wait_for_clk_prep_deprep(struct sdw_bus *bus, u16 dev_num) in sdw_bus_wait_for_clk_prep_deprep() argument
877 int retry = bus->clk_stop_timeout; in sdw_bus_wait_for_clk_prep_deprep()
881 val = sdw_bread_no_pm(bus, dev_num, SDW_SCP_STAT) & in sdw_bus_wait_for_clk_prep_deprep()
884 dev_info(bus->dev, "clock stop prep/de-prep done slave:%d", in sdw_bus_wait_for_clk_prep_deprep()
890 retry--; in sdw_bus_wait_for_clk_prep_deprep()
893 dev_err(bus->dev, "clock stop prep/de-prep failed slave:%d", in sdw_bus_wait_for_clk_prep_deprep()
896 return -ETIMEDOUT; in sdw_bus_wait_for_clk_prep_deprep()
902 * @bus: SDW bus instance
906 int sdw_bus_prep_clk_stop(struct sdw_bus *bus) in sdw_bus_prep_clk_stop() argument
919 list_for_each_entry(slave, &bus->slaves, node) { in sdw_bus_prep_clk_stop()
920 if (!slave->dev_num) in sdw_bus_prep_clk_stop()
923 if (slave->status != SDW_SLAVE_ATTACHED && in sdw_bus_prep_clk_stop()
924 slave->status != SDW_SLAVE_ALERT) in sdw_bus_prep_clk_stop()
927 /* Identify if Slave(s) are available on Bus */ in sdw_bus_prep_clk_stop()
931 slave->curr_clk_stop_mode = slave_mode; in sdw_bus_prep_clk_stop()
936 dev_err(&slave->dev, in sdw_bus_prep_clk_stop()
937 "pre-prepare failed:%d", ret); in sdw_bus_prep_clk_stop()
944 dev_err(&slave->dev, in sdw_bus_prep_clk_stop()
945 "pre-prepare failed:%d", ret); in sdw_bus_prep_clk_stop()
954 ret = sdw_bus_wait_for_clk_prep_deprep(bus, in sdw_bus_prep_clk_stop()
965 list_for_each_entry(slave, &bus->slaves, node) { in sdw_bus_prep_clk_stop()
966 if (!slave->dev_num) in sdw_bus_prep_clk_stop()
969 if (slave->status != SDW_SLAVE_ATTACHED && in sdw_bus_prep_clk_stop()
970 slave->status != SDW_SLAVE_ALERT) in sdw_bus_prep_clk_stop()
973 slave_mode = slave->curr_clk_stop_mode; in sdw_bus_prep_clk_stop()
981 dev_err(&slave->dev, in sdw_bus_prep_clk_stop()
982 "post-prepare failed:%d", ret); in sdw_bus_prep_clk_stop()
992 * sdw_bus_clk_stop: stop bus clock
994 * @bus: SDW bus instance
999 int sdw_bus_clk_stop(struct sdw_bus *bus) in sdw_bus_clk_stop() argument
1007 ret = sdw_bwrite_no_pm(bus, SDW_BROADCAST_DEV_NUM, in sdw_bus_clk_stop()
1010 if (ret == -ENODATA) in sdw_bus_clk_stop()
1011 dev_dbg(bus->dev, in sdw_bus_clk_stop()
1014 dev_err(bus->dev, in sdw_bus_clk_stop()
1026 * @bus: SDW bus instance
1028 * This De-prepares the Slaves by exiting Clock Stop Mode 0. For the Slaves
1029 * exiting Clock Stop Mode 1, they will be de-prepared after they enumerate
1032 int sdw_bus_exit_clk_stop(struct sdw_bus *bus) in sdw_bus_exit_clk_stop() argument
1041 * In order to save on transition time, de-prepare in sdw_bus_exit_clk_stop()
1043 * de-prepared after clock resume. in sdw_bus_exit_clk_stop()
1045 list_for_each_entry(slave, &bus->slaves, node) { in sdw_bus_exit_clk_stop()
1046 if (!slave->dev_num) in sdw_bus_exit_clk_stop()
1049 if (slave->status != SDW_SLAVE_ATTACHED && in sdw_bus_exit_clk_stop()
1050 slave->status != SDW_SLAVE_ALERT) in sdw_bus_exit_clk_stop()
1053 /* Identify if Slave(s) are available on Bus */ in sdw_bus_exit_clk_stop()
1056 mode = slave->curr_clk_stop_mode; in sdw_bus_exit_clk_stop()
1066 dev_warn(&slave->dev, in sdw_bus_exit_clk_stop()
1073 dev_warn(&slave->dev, in sdw_bus_exit_clk_stop()
1078 sdw_bus_wait_for_clk_prep_deprep(bus, SDW_BROADCAST_DEV_NUM); in sdw_bus_exit_clk_stop()
1087 list_for_each_entry(slave, &bus->slaves, node) { in sdw_bus_exit_clk_stop()
1088 if (!slave->dev_num) in sdw_bus_exit_clk_stop()
1091 if (slave->status != SDW_SLAVE_ATTACHED && in sdw_bus_exit_clk_stop()
1092 slave->status != SDW_SLAVE_ALERT) in sdw_bus_exit_clk_stop()
1095 mode = slave->curr_clk_stop_mode; in sdw_bus_exit_clk_stop()
1107 u32 addr; in sdw_configure_dpn_intr() local
1111 if (slave->bus->params.s_data_mode != SDW_PORT_DATA_MODE_NORMAL) { in sdw_configure_dpn_intr()
1112 dev_dbg(&slave->dev, "TEST FAIL interrupt %s\n", in sdw_configure_dpn_intr()
1117 addr = SDW_DPN_INTMASK(port); in sdw_configure_dpn_intr()
1128 ret = sdw_update(slave, addr, (mask | SDW_DPN_INT_PORT_READY), val); in sdw_configure_dpn_intr()
1130 dev_err(slave->bus->dev, in sdw_configure_dpn_intr()
1138 u32 mclk_freq = slave->bus->prop.mclk_freq; in sdw_slave_set_frequency()
1139 u32 curr_freq = slave->bus->params.curr_dr_freq >> 1; in sdw_slave_set_frequency()
1147 * devices. They may also be used for 1.2+/non-SDCA devices, in sdw_slave_set_frequency()
1150 if (!slave->id.class_id) in sdw_slave_set_frequency()
1154 dev_err(&slave->dev, in sdw_slave_set_frequency()
1155 "no bus MCLK, cannot set SDW_SCP_BUS_CLOCK_BASE\n"); in sdw_slave_set_frequency()
1156 return -EINVAL; in sdw_slave_set_frequency()
1184 dev_err(&slave->dev, in sdw_slave_set_frequency()
1187 return -EINVAL; in sdw_slave_set_frequency()
1191 dev_err(&slave->dev, in sdw_slave_set_frequency()
1192 "mclk %d is not multiple of bus curr_freq %d\n", in sdw_slave_set_frequency()
1194 return -EINVAL; in sdw_slave_set_frequency()
1200 * map scale to Table 90 of SoundWire 1.2 spec - and check in sdw_slave_set_frequency()
1206 dev_err(&slave->dev, in sdw_slave_set_frequency()
1207 "No match found for scale %d, bus mclk %d curr_freq %d\n", in sdw_slave_set_frequency()
1209 return -EINVAL; in sdw_slave_set_frequency()
1215 dev_err(&slave->dev, in sdw_slave_set_frequency()
1223 dev_err(&slave->dev, in sdw_slave_set_frequency()
1229 dev_err(&slave->dev, in sdw_slave_set_frequency()
1232 dev_dbg(&slave->dev, in sdw_slave_set_frequency()
1233 "Configured bus base %d, scale %d, mclk %d, curr_freq %d\n", in sdw_slave_set_frequency()
1241 struct sdw_slave_prop *prop = &slave->prop; in sdw_initialize_slave()
1250 * Set SCP_INT1_MASK register, typically bus clash and in sdw_initialize_slave()
1251 * implementation-defined interrupt mask. The Parity detection in sdw_initialize_slave()
1253 * device-dependent, it might e.g. only be enabled in in sdw_initialize_slave()
1254 * steady-state after a couple of frames. in sdw_initialize_slave()
1256 val = slave->prop.scp_int1_mask; in sdw_initialize_slave()
1261 dev_err(slave->bus->dev, in sdw_initialize_slave()
1267 if (!slave->prop.dp0_prop) in sdw_initialize_slave()
1271 val = prop->dp0_prop->imp_def_interrupts; in sdw_initialize_slave()
1276 dev_err(slave->bus->dev, in sdw_initialize_slave()
1288 dev_err(slave->bus->dev, in sdw_handle_dp0_interrupt()
1295 dev_err(&slave->dev, "Test fail for port 0\n"); in sdw_handle_dp0_interrupt()
1305 complete(&slave->port_ready[0]); in sdw_handle_dp0_interrupt()
1310 dev_err(&slave->dev, "BRA failed\n"); in sdw_handle_dp0_interrupt()
1325 dev_err(slave->bus->dev, in sdw_handle_dp0_interrupt()
1333 dev_err(slave->bus->dev, in sdw_handle_dp0_interrupt()
1345 dev_warn(slave->bus->dev, "Reached MAX_RETRY on DP0 read\n"); in sdw_handle_dp0_interrupt()
1355 u32 addr; in sdw_handle_port_interrupt() local
1360 addr = SDW_DPN_INT(port); in sdw_handle_port_interrupt()
1361 status = sdw_read(slave, addr); in sdw_handle_port_interrupt()
1363 dev_err(slave->bus->dev, in sdw_handle_port_interrupt()
1371 dev_err(&slave->dev, "Test fail for port:%d\n", port); in sdw_handle_port_interrupt()
1380 complete(&slave->port_ready[port]); in sdw_handle_port_interrupt()
1393 ret = sdw_write(slave, addr, clear); in sdw_handle_port_interrupt()
1395 dev_err(slave->bus->dev, in sdw_handle_port_interrupt()
1401 status2 = sdw_read(slave, addr); in sdw_handle_port_interrupt()
1403 dev_err(slave->bus->dev, in sdw_handle_port_interrupt()
1415 dev_warn(slave->bus->dev, "Reached MAX_RETRY on port read"); in sdw_handle_port_interrupt()
1433 ret = pm_runtime_get_sync(&slave->dev); in sdw_handle_slave_alerts()
1434 if (ret < 0 && ret != -EACCES) { in sdw_handle_slave_alerts()
1435 dev_err(&slave->dev, "Failed to resume device: %d\n", ret); in sdw_handle_slave_alerts()
1436 pm_runtime_put_noidle(slave->bus->dev); in sdw_handle_slave_alerts()
1443 dev_err(slave->bus->dev, in sdw_handle_slave_alerts()
1451 dev_err(slave->bus->dev, in sdw_handle_slave_alerts()
1458 * Check parity, bus clash and Slave (impl defined) in sdw_handle_slave_alerts()
1462 parity_check = slave->prop.scp_int1_mask & SDW_SCP_INT1_PARITY; in sdw_handle_slave_alerts()
1463 parity_quirk = !slave->first_interrupt_done && in sdw_handle_slave_alerts()
1464 (slave->prop.quirks & SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY); in sdw_handle_slave_alerts()
1467 dev_err(&slave->dev, "Parity error detected\n"); in sdw_handle_slave_alerts()
1472 if (slave->prop.scp_int1_mask & SDW_SCP_INT1_BUS_CLASH) in sdw_handle_slave_alerts()
1473 dev_err(&slave->dev, "Bus clash detected\n"); in sdw_handle_slave_alerts()
1478 * When bus clash or parity errors are detected, such errors in sdw_handle_slave_alerts()
1480 * TODO: In such scenario, reset bus. Make this configurable in sdw_handle_slave_alerts()
1481 * via sysfs property with bus reset being the default. in sdw_handle_slave_alerts()
1485 if (slave->prop.scp_int1_mask & SDW_SCP_INT1_IMPL_DEF) { in sdw_handle_slave_alerts()
1486 dev_dbg(&slave->dev, "Slave impl defined interrupt\n"); in sdw_handle_slave_alerts()
1492 /* Check port 0 - 3 interrupts */ in sdw_handle_slave_alerts()
1527 if (slave_notify && slave->ops && in sdw_handle_slave_alerts()
1528 slave->ops->interrupt_callback) { in sdw_handle_slave_alerts()
1533 slave->ops->interrupt_callback(slave, &slave_intr); in sdw_handle_slave_alerts()
1539 dev_err(slave->bus->dev, in sdw_handle_slave_alerts()
1545 slave->first_interrupt_done = true; in sdw_handle_slave_alerts()
1553 dev_err(slave->bus->dev, in sdw_handle_slave_alerts()
1561 dev_err(slave->bus->dev, in sdw_handle_slave_alerts()
1582 dev_warn(slave->bus->dev, "Reached MAX_RETRY on alert read\n"); in sdw_handle_slave_alerts()
1585 pm_runtime_mark_last_busy(&slave->dev); in sdw_handle_slave_alerts()
1586 pm_runtime_put_autosuspend(&slave->dev); in sdw_handle_slave_alerts()
1596 if (!slave->probed) { in sdw_update_slave_status()
1605 time = wait_for_completion_timeout(&slave->probe_complete, in sdw_update_slave_status()
1608 dev_err(&slave->dev, "Probe not complete, timed out\n"); in sdw_update_slave_status()
1609 return -ETIMEDOUT; in sdw_update_slave_status()
1613 if (!slave->ops || !slave->ops->update_status) in sdw_update_slave_status()
1616 return slave->ops->update_status(slave, status); in sdw_update_slave_status()
1620 * sdw_handle_slave_status() - Handle Slave status
1621 * @bus: SDW bus instance
1624 int sdw_handle_slave_status(struct sdw_bus *bus, in sdw_handle_slave_status() argument
1632 /* first check if any Slaves fell off the bus */ in sdw_handle_slave_status()
1634 mutex_lock(&bus->bus_lock); in sdw_handle_slave_status()
1635 if (test_bit(i, bus->assigned) == false) { in sdw_handle_slave_status()
1636 mutex_unlock(&bus->bus_lock); in sdw_handle_slave_status()
1639 mutex_unlock(&bus->bus_lock); in sdw_handle_slave_status()
1641 slave = sdw_get_slave(bus, i); in sdw_handle_slave_status()
1646 slave->status != SDW_SLAVE_UNATTACHED) in sdw_handle_slave_status()
1651 dev_dbg(bus->dev, "Slave attached, programming device number\n"); in sdw_handle_slave_status()
1652 ret = sdw_program_device_num(bus); in sdw_handle_slave_status()
1654 dev_err(bus->dev, "Slave attach failed: %d\n", ret); in sdw_handle_slave_status()
1664 mutex_lock(&bus->bus_lock); in sdw_handle_slave_status()
1665 if (test_bit(i, bus->assigned) == false) { in sdw_handle_slave_status()
1666 mutex_unlock(&bus->bus_lock); in sdw_handle_slave_status()
1669 mutex_unlock(&bus->bus_lock); in sdw_handle_slave_status()
1671 slave = sdw_get_slave(bus, i); in sdw_handle_slave_status()
1679 if (slave->status == SDW_SLAVE_UNATTACHED) in sdw_handle_slave_status()
1688 dev_err(bus->dev, in sdw_handle_slave_status()
1694 if (slave->status == SDW_SLAVE_ATTACHED) in sdw_handle_slave_status()
1697 prev_status = slave->status; in sdw_handle_slave_status()
1707 dev_err(bus->dev, in sdw_handle_slave_status()
1714 dev_err(bus->dev, "Invalid slave %d status:%d\n", in sdw_handle_slave_status()
1721 dev_err(slave->bus->dev, in sdw_handle_slave_status()
1724 complete(&slave->initialization_complete); in sdw_handle_slave_status()
1731 void sdw_clear_slave_status(struct sdw_bus *bus, u32 request) in sdw_clear_slave_status() argument
1736 /* Check all non-zero devices */ in sdw_clear_slave_status()
1738 mutex_lock(&bus->bus_lock); in sdw_clear_slave_status()
1739 if (test_bit(i, bus->assigned) == false) { in sdw_clear_slave_status()
1740 mutex_unlock(&bus->bus_lock); in sdw_clear_slave_status()
1743 mutex_unlock(&bus->bus_lock); in sdw_clear_slave_status()
1745 slave = sdw_get_slave(bus, i); in sdw_clear_slave_status()
1749 if (slave->status != SDW_SLAVE_UNATTACHED) { in sdw_clear_slave_status()
1751 slave->first_interrupt_done = false; in sdw_clear_slave_status()
1755 slave->unattach_request = request; in sdw_clear_slave_status()