Lines Matching +full:slave +full:- +full:mode

1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2 // Copyright(c) 2015-17 Intel Corporation.
24 bus->id = rc; in sdw_get_id()
29 * sdw_bus_master_add() - add a bus Master instance
45 return -ENODEV; in sdw_bus_master_add()
57 bus->link_id); in sdw_bus_master_add()
61 if (!bus->ops) { in sdw_bus_master_add()
62 dev_err(bus->dev, "SoundWire Bus ops are not set\n"); in sdw_bus_master_add()
63 return -EINVAL; in sdw_bus_master_add()
66 if (!bus->compute_params) { in sdw_bus_master_add()
67 dev_err(bus->dev, in sdw_bus_master_add()
69 return -EINVAL; in sdw_bus_master_add()
72 mutex_init(&bus->msg_lock); in sdw_bus_master_add()
73 mutex_init(&bus->bus_lock); in sdw_bus_master_add()
74 INIT_LIST_HEAD(&bus->slaves); in sdw_bus_master_add()
75 INIT_LIST_HEAD(&bus->m_rt_list); in sdw_bus_master_add()
80 bus->multi_link = false; in sdw_bus_master_add()
81 if (bus->ops->read_prop) { in sdw_bus_master_add()
82 ret = bus->ops->read_prop(bus); in sdw_bus_master_add()
84 dev_err(bus->dev, in sdw_bus_master_add()
100 *bus->assigned = ~GENMASK(SDW_BROADCAST_DEV_NUM, SDW_ENUM_DEV_NUM); in sdw_bus_master_add()
103 set_bit(SDW_ENUM_DEV_NUM, bus->assigned); in sdw_bus_master_add()
104 set_bit(SDW_BROADCAST_DEV_NUM, bus->assigned); in sdw_bus_master_add()
107 set_bit(SDW_GROUP12_DEV_NUM, bus->assigned); in sdw_bus_master_add()
108 set_bit(SDW_GROUP13_DEV_NUM, bus->assigned); in sdw_bus_master_add()
109 set_bit(SDW_MASTER_DEV_NUM, bus->assigned); in sdw_bus_master_add()
115 * Create Slave devices based on Slaves described in in sdw_bus_master_add()
118 if (IS_ENABLED(CONFIG_ACPI) && ACPI_HANDLE(bus->dev)) in sdw_bus_master_add()
120 else if (IS_ENABLED(CONFIG_OF) && bus->dev->of_node) in sdw_bus_master_add()
123 ret = -ENOTSUPP; /* No ACPI/DT so error out */ in sdw_bus_master_add()
126 dev_err(bus->dev, "Finding slaves failed:%d\n", ret); in sdw_bus_master_add()
139 prop = &bus->prop; in sdw_bus_master_add()
140 bus->params.max_dr_freq = prop->max_clk_freq * SDW_DOUBLE_RATE_FACTOR; in sdw_bus_master_add()
141 bus->params.curr_dr_freq = bus->params.max_dr_freq; in sdw_bus_master_add()
142 bus->params.curr_bank = SDW_BANK0; in sdw_bus_master_add()
143 bus->params.next_bank = SDW_BANK1; in sdw_bus_master_add()
151 struct sdw_slave *slave = dev_to_sdw_dev(dev); in sdw_delete_slave() local
152 struct sdw_bus *bus = slave->bus; in sdw_delete_slave()
156 sdw_slave_debugfs_exit(slave); in sdw_delete_slave()
158 mutex_lock(&bus->bus_lock); in sdw_delete_slave()
160 if (slave->dev_num) { /* clear dev_num if assigned */ in sdw_delete_slave()
161 clear_bit(slave->dev_num, bus->assigned); in sdw_delete_slave()
162 if (bus->dev_num_ida_min) in sdw_delete_slave()
163 ida_free(&sdw_peripheral_ida, slave->dev_num); in sdw_delete_slave()
165 list_del_init(&slave->node); in sdw_delete_slave()
166 mutex_unlock(&bus->bus_lock); in sdw_delete_slave()
173 * sdw_bus_master_delete() - delete the bus master instance
180 device_for_each_child(bus->dev, NULL, sdw_delete_slave); in sdw_bus_master_delete()
184 ida_free(&sdw_bus_ida, bus->id); in sdw_bus_master_delete()
199 return -ENODATA; in find_response_code()
202 return -ETIMEDOUT; in find_response_code()
205 return -EIO; in find_response_code()
211 int retry = bus->prop.err_threshold; in do_transfer()
216 resp = bus->ops->xfer_msg(bus, msg); in do_transfer()
220 if (ret == 0 || ret == -ENODATA) in do_transfer()
231 int retry = bus->prop.err_threshold; in do_transfer_defer()
235 defer->msg = msg; in do_transfer_defer()
236 defer->length = msg->len; in do_transfer_defer()
237 init_completion(&defer->complete); in do_transfer_defer()
240 resp = bus->ops->xfer_msg_defer(bus, msg, defer); in do_transfer_defer()
243 if (ret == 0 || ret == -ENODATA) in do_transfer_defer()
252 int retry = bus->prop.err_threshold; in sdw_reset_page()
257 resp = bus->ops->reset_page_addr(bus, dev_num); in sdw_reset_page()
260 if (ret == 0 || ret == -ENODATA) in sdw_reset_page()
272 if (ret != 0 && ret != -ENODATA) in sdw_transfer_unlocked()
273 dev_err(bus->dev, "trf on Slave %d failed:%d %s addr %x count %d\n", in sdw_transfer_unlocked()
274 msg->dev_num, ret, in sdw_transfer_unlocked()
275 (msg->flags & SDW_MSG_FLAG_WRITE) ? "write" : "read", in sdw_transfer_unlocked()
276 msg->addr, msg->len); in sdw_transfer_unlocked()
278 if (msg->page) in sdw_transfer_unlocked()
279 sdw_reset_page(bus, msg->dev_num); in sdw_transfer_unlocked()
285 * sdw_transfer() - Synchronous transfer message to a SDW Slave device
293 mutex_lock(&bus->msg_lock); in sdw_transfer()
297 mutex_unlock(&bus->msg_lock); in sdw_transfer()
303 * sdw_show_ping_status() - Direct report of PING status, to be used by Peripheral drivers
311 if (!bus->ops->read_ping_status) in sdw_show_ping_status()
315 * wait for peripheral to sync if desired. 10-15ms should be more than in sdw_show_ping_status()
321 mutex_lock(&bus->msg_lock); in sdw_show_ping_status()
323 status = bus->ops->read_ping_status(bus); in sdw_show_ping_status()
325 mutex_unlock(&bus->msg_lock); in sdw_show_ping_status()
328 dev_warn(bus->dev, "%s: no peripherals attached\n", __func__); in sdw_show_ping_status()
330 dev_dbg(bus->dev, "PING status: %#x\n", status); in sdw_show_ping_status()
335 * sdw_transfer_defer() - Asynchronously transfer message to a SDW Slave device
347 if (!bus->ops->xfer_msg_defer) in sdw_transfer_defer()
348 return -ENOTSUPP; in sdw_transfer_defer()
351 if (ret != 0 && ret != -ENODATA) in sdw_transfer_defer()
352 dev_err(bus->dev, "Defer trf on Slave %d failed:%d\n", in sdw_transfer_defer()
353 msg->dev_num, ret); in sdw_transfer_defer()
355 if (msg->page) in sdw_transfer_defer()
356 sdw_reset_page(bus, msg->dev_num); in sdw_transfer_defer()
361 int sdw_fill_msg(struct sdw_msg *msg, struct sdw_slave *slave, in sdw_fill_msg() argument
365 msg->addr = addr; /* addr is 16 bit and truncated here */ in sdw_fill_msg()
366 msg->len = count; in sdw_fill_msg()
367 msg->dev_num = dev_num; in sdw_fill_msg()
368 msg->flags = flags; in sdw_fill_msg()
369 msg->buf = buf; in sdw_fill_msg()
376 return -EINVAL; in sdw_fill_msg()
380 if (slave && !slave->prop.paging_support) in sdw_fill_msg()
382 /* no need for else as that will fall-through to paging */ in sdw_fill_msg()
388 return -EINVAL; in sdw_fill_msg()
391 if (!slave) { in sdw_fill_msg()
392 pr_err("SDW: No slave for paging addr\n"); in sdw_fill_msg()
393 return -EINVAL; in sdw_fill_msg()
396 if (!slave->prop.paging_support) { in sdw_fill_msg()
397 dev_err(&slave->dev, in sdw_fill_msg()
399 return -EINVAL; in sdw_fill_msg()
402 msg->addr_page1 = FIELD_GET(SDW_SCP_ADDRPAGE1_MASK, addr); in sdw_fill_msg()
403 msg->addr_page2 = FIELD_GET(SDW_SCP_ADDRPAGE2_MASK, addr); in sdw_fill_msg()
404 msg->addr |= BIT(15); in sdw_fill_msg()
405 msg->page = true; in sdw_fill_msg()
413 * handling suspend-resume sequences.
418 sdw_nread_no_pm(struct sdw_slave *slave, u32 addr, size_t count, u8 *val) in sdw_nread_no_pm() argument
423 ret = sdw_fill_msg(&msg, slave, addr, count, in sdw_nread_no_pm()
424 slave->dev_num, SDW_MSG_FLAG_READ, val); in sdw_nread_no_pm()
428 ret = sdw_transfer(slave->bus, &msg); in sdw_nread_no_pm()
429 if (slave->is_mockup_device) in sdw_nread_no_pm()
435 sdw_nwrite_no_pm(struct sdw_slave *slave, u32 addr, size_t count, const u8 *val) in sdw_nwrite_no_pm() argument
440 ret = sdw_fill_msg(&msg, slave, addr, count, in sdw_nwrite_no_pm()
441 slave->dev_num, SDW_MSG_FLAG_WRITE, (u8 *)val); in sdw_nwrite_no_pm()
445 ret = sdw_transfer(slave->bus, &msg); in sdw_nwrite_no_pm()
446 if (slave->is_mockup_device) in sdw_nwrite_no_pm()
451 int sdw_write_no_pm(struct sdw_slave *slave, u32 addr, u8 value) in sdw_write_no_pm() argument
453 return sdw_nwrite_no_pm(slave, addr, 1, &value); in sdw_write_no_pm()
523 int sdw_read_no_pm(struct sdw_slave *slave, u32 addr) in sdw_read_no_pm() argument
528 ret = sdw_nread_no_pm(slave, addr, 1, &buf); in sdw_read_no_pm()
536 int sdw_update_no_pm(struct sdw_slave *slave, u32 addr, u8 mask, u8 val) in sdw_update_no_pm() argument
540 tmp = sdw_read_no_pm(slave, addr); in sdw_update_no_pm()
545 return sdw_write_no_pm(slave, addr, tmp); in sdw_update_no_pm()
549 /* Read-Modify-Write Slave register */
550 int sdw_update(struct sdw_slave *slave, u32 addr, u8 mask, u8 val) in sdw_update() argument
554 tmp = sdw_read(slave, addr); in sdw_update()
559 return sdw_write(slave, addr, tmp); in sdw_update()
564 * sdw_nread() - Read "n" contiguous SDW Slave registers
565 * @slave: SDW Slave
570 int sdw_nread(struct sdw_slave *slave, u32 addr, size_t count, u8 *val) in sdw_nread() argument
574 ret = pm_runtime_resume_and_get(&slave->dev); in sdw_nread()
575 if (ret < 0 && ret != -EACCES) in sdw_nread()
578 ret = sdw_nread_no_pm(slave, addr, count, val); in sdw_nread()
580 pm_runtime_mark_last_busy(&slave->dev); in sdw_nread()
581 pm_runtime_put(&slave->dev); in sdw_nread()
588 * sdw_nwrite() - Write "n" contiguous SDW Slave registers
589 * @slave: SDW Slave
594 int sdw_nwrite(struct sdw_slave *slave, u32 addr, size_t count, const u8 *val) in sdw_nwrite() argument
598 ret = pm_runtime_resume_and_get(&slave->dev); in sdw_nwrite()
599 if (ret < 0 && ret != -EACCES) in sdw_nwrite()
602 ret = sdw_nwrite_no_pm(slave, addr, count, val); in sdw_nwrite()
604 pm_runtime_mark_last_busy(&slave->dev); in sdw_nwrite()
605 pm_runtime_put(&slave->dev); in sdw_nwrite()
612 * sdw_read() - Read a SDW Slave register
613 * @slave: SDW Slave
616 int sdw_read(struct sdw_slave *slave, u32 addr) in sdw_read() argument
621 ret = sdw_nread(slave, addr, 1, &buf); in sdw_read()
630 * sdw_write() - Write a SDW Slave register
631 * @slave: SDW Slave
635 int sdw_write(struct sdw_slave *slave, u32 addr, u8 value) in sdw_write() argument
637 return sdw_nwrite(slave, addr, 1, &value); in sdw_write()
648 struct sdw_slave *slave; in sdw_get_slave() local
650 list_for_each_entry(slave, &bus->slaves, node) { in sdw_get_slave()
651 if (slave->dev_num == i) in sdw_get_slave()
652 return slave; in sdw_get_slave()
658 int sdw_compare_devid(struct sdw_slave *slave, struct sdw_slave_id id) in sdw_compare_devid() argument
660 if (slave->id.mfg_id != id.mfg_id || in sdw_compare_devid()
661 slave->id.part_id != id.part_id || in sdw_compare_devid()
662 slave->id.class_id != id.class_id || in sdw_compare_devid()
663 (slave->id.unique_id != SDW_IGNORED_UNIQUE_ID && in sdw_compare_devid()
664 slave->id.unique_id != id.unique_id)) in sdw_compare_devid()
665 return -ENODEV; in sdw_compare_devid()
672 static int sdw_get_device_num(struct sdw_slave *slave) in sdw_get_device_num() argument
676 if (slave->bus->dev_num_ida_min) { in sdw_get_device_num()
678 slave->bus->dev_num_ida_min, SDW_MAX_DEVICES, in sdw_get_device_num()
683 bit = find_first_zero_bit(slave->bus->assigned, SDW_MAX_DEVICES); in sdw_get_device_num()
685 bit = -ENODEV; in sdw_get_device_num()
691 * Do not update dev_num in Slave data structure here, in sdw_get_device_num()
694 set_bit(bit, slave->bus->assigned); in sdw_get_device_num()
700 static int sdw_assign_device_num(struct sdw_slave *slave) in sdw_assign_device_num() argument
702 struct sdw_bus *bus = slave->bus; in sdw_assign_device_num()
707 if (!slave->dev_num) { in sdw_assign_device_num()
708 if (!slave->dev_num_sticky) { in sdw_assign_device_num()
709 mutex_lock(&slave->bus->bus_lock); in sdw_assign_device_num()
710 dev_num = sdw_get_device_num(slave); in sdw_assign_device_num()
711 mutex_unlock(&slave->bus->bus_lock); in sdw_assign_device_num()
713 dev_err(bus->dev, "Get dev_num failed: %d\n", in sdw_assign_device_num()
717 slave->dev_num = dev_num; in sdw_assign_device_num()
718 slave->dev_num_sticky = dev_num; in sdw_assign_device_num()
721 slave->dev_num = slave->dev_num_sticky; in sdw_assign_device_num()
726 dev_dbg(bus->dev, in sdw_assign_device_num()
727 "Slave already registered, reusing dev_num:%d\n", in sdw_assign_device_num()
728 slave->dev_num); in sdw_assign_device_num()
730 /* Clear the slave->dev_num to transfer message on device 0 */ in sdw_assign_device_num()
731 dev_num = slave->dev_num; in sdw_assign_device_num()
732 slave->dev_num = 0; in sdw_assign_device_num()
734 ret = sdw_write_no_pm(slave, SDW_SCP_DEVNUMBER, dev_num); in sdw_assign_device_num()
736 dev_err(bus->dev, "Program device_num %d failed: %d\n", in sdw_assign_device_num()
742 slave->dev_num = slave->dev_num_sticky; in sdw_assign_device_num()
750 dev_dbg(bus->dev, "SDW Slave Addr: %llx\n", addr); in sdw_extract_slave_id()
752 id->sdw_version = SDW_VERSION(addr); in sdw_extract_slave_id()
753 id->unique_id = SDW_UNIQUE_ID(addr); in sdw_extract_slave_id()
754 id->mfg_id = SDW_MFG_ID(addr); in sdw_extract_slave_id()
755 id->part_id = SDW_PART_ID(addr); in sdw_extract_slave_id()
756 id->class_id = SDW_CLASS_ID(addr); in sdw_extract_slave_id()
758 dev_dbg(bus->dev, in sdw_extract_slave_id()
759 "SDW Slave class_id 0x%02x, mfg_id 0x%04x, part_id 0x%04x, unique_id 0x%x, version 0x%x\n", in sdw_extract_slave_id()
760 id->class_id, id->mfg_id, id->part_id, id->unique_id, id->sdw_version); in sdw_extract_slave_id()
767 struct sdw_slave *slave, *_s; in sdw_program_device_num() local
776 /* No Slave, so use raw xfer api */ in sdw_program_device_num()
784 if (ret == -ENODATA) { /* end of device id reads */ in sdw_program_device_num()
785 dev_dbg(bus->dev, "No more devices to enumerate\n"); in sdw_program_device_num()
790 dev_err(bus->dev, "DEVID read fail:%d\n", ret); in sdw_program_device_num()
806 list_for_each_entry_safe(slave, _s, &bus->slaves, node) { in sdw_program_device_num()
807 if (sdw_compare_devid(slave, id) == 0) { in sdw_program_device_num()
811 * To prevent skipping state-machine stages don't in sdw_program_device_num()
817 if (slave->status != SDW_SLAVE_UNATTACHED) in sdw_program_device_num()
821 * Assign a new dev_num to this Slave and in sdw_program_device_num()
826 ret = sdw_assign_device_num(slave); in sdw_program_device_num()
828 dev_err(bus->dev, in sdw_program_device_num()
844 * add Slave device even if there is no platform in sdw_program_device_num()
851 dev_err(bus->dev, "Slave Entry not found\n"); in sdw_program_device_num()
867 static void sdw_modify_slave_status(struct sdw_slave *slave, in sdw_modify_slave_status() argument
870 struct sdw_bus *bus = slave->bus; in sdw_modify_slave_status()
872 mutex_lock(&bus->bus_lock); in sdw_modify_slave_status()
874 dev_vdbg(bus->dev, in sdw_modify_slave_status()
875 "changing status slave %d status %d new status %d\n", in sdw_modify_slave_status()
876 slave->dev_num, slave->status, status); in sdw_modify_slave_status()
879 dev_dbg(&slave->dev, in sdw_modify_slave_status()
880 "initializing enumeration and init completion for Slave %d\n", in sdw_modify_slave_status()
881 slave->dev_num); in sdw_modify_slave_status()
883 init_completion(&slave->enumeration_complete); in sdw_modify_slave_status()
884 init_completion(&slave->initialization_complete); in sdw_modify_slave_status()
887 (slave->status == SDW_SLAVE_UNATTACHED)) { in sdw_modify_slave_status()
888 dev_dbg(&slave->dev, in sdw_modify_slave_status()
889 "signaling enumeration completion for Slave %d\n", in sdw_modify_slave_status()
890 slave->dev_num); in sdw_modify_slave_status()
892 complete(&slave->enumeration_complete); in sdw_modify_slave_status()
894 slave->status = status; in sdw_modify_slave_status()
895 mutex_unlock(&bus->bus_lock); in sdw_modify_slave_status()
898 static int sdw_slave_clk_stop_callback(struct sdw_slave *slave, in sdw_slave_clk_stop_callback() argument
899 enum sdw_clk_stop_mode mode, in sdw_slave_clk_stop_callback() argument
904 mutex_lock(&slave->sdw_dev_lock); in sdw_slave_clk_stop_callback()
906 if (slave->probed) { in sdw_slave_clk_stop_callback()
907 struct device *dev = &slave->dev; in sdw_slave_clk_stop_callback()
908 struct sdw_driver *drv = drv_to_sdw_driver(dev->driver); in sdw_slave_clk_stop_callback()
910 if (drv->ops && drv->ops->clk_stop) in sdw_slave_clk_stop_callback()
911 ret = drv->ops->clk_stop(slave, mode, type); in sdw_slave_clk_stop_callback()
914 mutex_unlock(&slave->sdw_dev_lock); in sdw_slave_clk_stop_callback()
919 static int sdw_slave_clk_stop_prepare(struct sdw_slave *slave, in sdw_slave_clk_stop_prepare() argument
920 enum sdw_clk_stop_mode mode, in sdw_slave_clk_stop_prepare() argument
927 wake_en = slave->prop.wake_capable; in sdw_slave_clk_stop_prepare()
932 if (mode == SDW_CLK_STOP_MODE1) in sdw_slave_clk_stop_prepare()
938 ret = sdw_read_no_pm(slave, SDW_SCP_SYSTEMCTRL); in sdw_slave_clk_stop_prepare()
940 if (ret != -ENODATA) in sdw_slave_clk_stop_prepare()
941 dev_err(&slave->dev, "SDW_SCP_SYSTEMCTRL read failed:%d\n", ret); in sdw_slave_clk_stop_prepare()
948 ret = sdw_write_no_pm(slave, SDW_SCP_SYSTEMCTRL, val); in sdw_slave_clk_stop_prepare()
950 if (ret < 0 && ret != -ENODATA) in sdw_slave_clk_stop_prepare()
951 dev_err(&slave->dev, "SDW_SCP_SYSTEMCTRL write failed:%d\n", ret); in sdw_slave_clk_stop_prepare()
958 int retry = bus->clk_stop_timeout; in sdw_bus_wait_for_clk_prep_deprep()
964 if (val != -ENODATA) in sdw_bus_wait_for_clk_prep_deprep()
965 dev_err(bus->dev, "SDW_SCP_STAT bread failed:%d\n", val); in sdw_bus_wait_for_clk_prep_deprep()
970 dev_dbg(bus->dev, "clock stop prep/de-prep done slave:%d\n", in sdw_bus_wait_for_clk_prep_deprep()
976 retry--; in sdw_bus_wait_for_clk_prep_deprep()
979 dev_err(bus->dev, "clock stop prep/de-prep failed slave:%d\n", in sdw_bus_wait_for_clk_prep_deprep()
982 return -ETIMEDOUT; in sdw_bus_wait_for_clk_prep_deprep()
986 * sdw_bus_prep_clk_stop: prepare Slave(s) for clock stop
990 * Query Slave for clock stop mode and prepare for that mode.
995 struct sdw_slave *slave; in sdw_bus_prep_clk_stop() local
1001 * each Slave and then wait for all Slave(s) to be in sdw_bus_prep_clk_stop()
1003 * If one of the Slave devices has lost sync and in sdw_bus_prep_clk_stop()
1004 * replies with Command Ignored/-ENODATA, we continue in sdw_bus_prep_clk_stop()
1007 list_for_each_entry(slave, &bus->slaves, node) { in sdw_bus_prep_clk_stop()
1008 if (!slave->dev_num) in sdw_bus_prep_clk_stop()
1011 if (slave->status != SDW_SLAVE_ATTACHED && in sdw_bus_prep_clk_stop()
1012 slave->status != SDW_SLAVE_ALERT) in sdw_bus_prep_clk_stop()
1015 /* Identify if Slave(s) are available on Bus */ in sdw_bus_prep_clk_stop()
1018 ret = sdw_slave_clk_stop_callback(slave, in sdw_bus_prep_clk_stop()
1021 if (ret < 0 && ret != -ENODATA) { in sdw_bus_prep_clk_stop()
1022 dev_err(&slave->dev, "clock stop pre-prepare cb failed:%d\n", ret); in sdw_bus_prep_clk_stop()
1026 /* Only prepare a Slave device if needed */ in sdw_bus_prep_clk_stop()
1027 if (!slave->prop.simple_clk_stop_capable) { in sdw_bus_prep_clk_stop()
1030 ret = sdw_slave_clk_stop_prepare(slave, in sdw_bus_prep_clk_stop()
1033 if (ret < 0 && ret != -ENODATA) { in sdw_bus_prep_clk_stop()
1034 dev_err(&slave->dev, "clock stop prepare failed:%d\n", ret); in sdw_bus_prep_clk_stop()
1040 /* Skip remaining clock stop preparation if no Slave is attached */ in sdw_bus_prep_clk_stop()
1052 * if there are no Slave devices present and the reply is in sdw_bus_prep_clk_stop()
1053 * Command_Ignored/-ENODATA, we don't need to continue with the in sdw_bus_prep_clk_stop()
1062 list_for_each_entry(slave, &bus->slaves, node) { in sdw_bus_prep_clk_stop()
1063 if (!slave->dev_num) in sdw_bus_prep_clk_stop()
1066 if (slave->status != SDW_SLAVE_ATTACHED && in sdw_bus_prep_clk_stop()
1067 slave->status != SDW_SLAVE_ALERT) in sdw_bus_prep_clk_stop()
1070 ret = sdw_slave_clk_stop_callback(slave, in sdw_bus_prep_clk_stop()
1074 if (ret < 0 && ret != -ENODATA) { in sdw_bus_prep_clk_stop()
1075 dev_err(&slave->dev, "clock stop post-prepare cb failed:%d\n", ret); in sdw_bus_prep_clk_stop()
1103 if (ret != -ENODATA) in sdw_bus_clk_stop()
1104 dev_err(bus->dev, "ClockStopNow Broadcast msg failed %d\n", ret); in sdw_bus_clk_stop()
1113 * sdw_bus_exit_clk_stop: Exit clock stop mode
1117 * This De-prepares the Slaves by exiting Clock Stop Mode 0. For the Slaves
1118 * exiting Clock Stop Mode 1, they will be de-prepared after they enumerate
1124 struct sdw_slave *slave; in sdw_bus_exit_clk_stop() local
1129 * In order to save on transition time, de-prepare in sdw_bus_exit_clk_stop()
1130 * each Slave and then wait for all Slave(s) to be in sdw_bus_exit_clk_stop()
1131 * de-prepared after clock resume. in sdw_bus_exit_clk_stop()
1133 list_for_each_entry(slave, &bus->slaves, node) { in sdw_bus_exit_clk_stop()
1134 if (!slave->dev_num) in sdw_bus_exit_clk_stop()
1137 if (slave->status != SDW_SLAVE_ATTACHED && in sdw_bus_exit_clk_stop()
1138 slave->status != SDW_SLAVE_ALERT) in sdw_bus_exit_clk_stop()
1141 /* Identify if Slave(s) are available on Bus */ in sdw_bus_exit_clk_stop()
1144 ret = sdw_slave_clk_stop_callback(slave, SDW_CLK_STOP_MODE0, in sdw_bus_exit_clk_stop()
1147 dev_warn(&slave->dev, "clock stop pre-deprepare cb failed:%d\n", ret); in sdw_bus_exit_clk_stop()
1149 /* Only de-prepare a Slave device if needed */ in sdw_bus_exit_clk_stop()
1150 if (!slave->prop.simple_clk_stop_capable) { in sdw_bus_exit_clk_stop()
1153 ret = sdw_slave_clk_stop_prepare(slave, SDW_CLK_STOP_MODE0, in sdw_bus_exit_clk_stop()
1157 dev_warn(&slave->dev, "clock stop deprepare failed:%d\n", ret); in sdw_bus_exit_clk_stop()
1161 /* Skip remaining clock stop de-preparation if no Slave is attached */ in sdw_bus_exit_clk_stop()
1172 dev_warn(bus->dev, "clock stop deprepare wait failed:%d\n", ret); in sdw_bus_exit_clk_stop()
1175 list_for_each_entry(slave, &bus->slaves, node) { in sdw_bus_exit_clk_stop()
1176 if (!slave->dev_num) in sdw_bus_exit_clk_stop()
1179 if (slave->status != SDW_SLAVE_ATTACHED && in sdw_bus_exit_clk_stop()
1180 slave->status != SDW_SLAVE_ALERT) in sdw_bus_exit_clk_stop()
1183 ret = sdw_slave_clk_stop_callback(slave, SDW_CLK_STOP_MODE0, in sdw_bus_exit_clk_stop()
1186 dev_warn(&slave->dev, "clock stop post-deprepare cb failed:%d\n", ret); in sdw_bus_exit_clk_stop()
1193 int sdw_configure_dpn_intr(struct sdw_slave *slave, in sdw_configure_dpn_intr() argument
1200 if (slave->bus->params.s_data_mode != SDW_PORT_DATA_MODE_NORMAL) { in sdw_configure_dpn_intr()
1201 dev_dbg(&slave->dev, "TEST FAIL interrupt %s\n", in sdw_configure_dpn_intr()
1217 ret = sdw_update(slave, addr, (mask | SDW_DPN_INT_PORT_READY), val); in sdw_configure_dpn_intr()
1219 dev_err(&slave->dev, in sdw_configure_dpn_intr()
1225 static int sdw_slave_set_frequency(struct sdw_slave *slave) in sdw_slave_set_frequency() argument
1227 u32 mclk_freq = slave->bus->prop.mclk_freq; in sdw_slave_set_frequency()
1228 u32 curr_freq = slave->bus->params.curr_dr_freq >> 1; in sdw_slave_set_frequency()
1236 * devices. They may also be used for 1.2+/non-SDCA devices, in sdw_slave_set_frequency()
1239 if (!slave->id.class_id) in sdw_slave_set_frequency()
1243 dev_err(&slave->dev, in sdw_slave_set_frequency()
1245 return -EINVAL; in sdw_slave_set_frequency()
1273 dev_err(&slave->dev, in sdw_slave_set_frequency()
1276 return -EINVAL; in sdw_slave_set_frequency()
1280 dev_err(&slave->dev, in sdw_slave_set_frequency()
1283 return -EINVAL; in sdw_slave_set_frequency()
1289 * map scale to Table 90 of SoundWire 1.2 spec - and check in sdw_slave_set_frequency()
1295 dev_err(&slave->dev, in sdw_slave_set_frequency()
1298 return -EINVAL; in sdw_slave_set_frequency()
1302 ret = sdw_write_no_pm(slave, SDW_SCP_BUS_CLOCK_BASE, base); in sdw_slave_set_frequency()
1304 dev_err(&slave->dev, in sdw_slave_set_frequency()
1310 ret = sdw_write_no_pm(slave, SDW_SCP_BUSCLOCK_SCALE_B0, scale_index); in sdw_slave_set_frequency()
1312 dev_err(&slave->dev, in sdw_slave_set_frequency()
1316 ret = sdw_write_no_pm(slave, SDW_SCP_BUSCLOCK_SCALE_B1, scale_index); in sdw_slave_set_frequency()
1318 dev_err(&slave->dev, in sdw_slave_set_frequency()
1321 dev_dbg(&slave->dev, in sdw_slave_set_frequency()
1328 static int sdw_initialize_slave(struct sdw_slave *slave) in sdw_initialize_slave() argument
1330 struct sdw_slave_prop *prop = &slave->prop; in sdw_initialize_slave()
1335 ret = sdw_slave_set_frequency(slave); in sdw_initialize_slave()
1339 if (slave->bus->prop.quirks & SDW_MASTER_QUIRKS_CLEAR_INITIAL_CLASH) { in sdw_initialize_slave()
1341 status = sdw_read_no_pm(slave, SDW_SCP_INT1); in sdw_initialize_slave()
1343 dev_err(&slave->dev, in sdw_initialize_slave()
1348 dev_warn(&slave->dev, "Bus clash detected before INT mask is enabled\n"); in sdw_initialize_slave()
1349 ret = sdw_write_no_pm(slave, SDW_SCP_INT1, SDW_SCP_INT1_BUS_CLASH); in sdw_initialize_slave()
1351 dev_err(&slave->dev, in sdw_initialize_slave()
1357 if ((slave->bus->prop.quirks & SDW_MASTER_QUIRKS_CLEAR_INITIAL_PARITY) && in sdw_initialize_slave()
1358 !(slave->prop.quirks & SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY)) { in sdw_initialize_slave()
1360 status = sdw_read_no_pm(slave, SDW_SCP_INT1); in sdw_initialize_slave()
1362 dev_err(&slave->dev, in sdw_initialize_slave()
1367 dev_warn(&slave->dev, "PARITY error detected before INT mask is enabled\n"); in sdw_initialize_slave()
1368 ret = sdw_write_no_pm(slave, SDW_SCP_INT1, SDW_SCP_INT1_PARITY); in sdw_initialize_slave()
1370 dev_err(&slave->dev, in sdw_initialize_slave()
1379 * implementation-defined interrupt mask. The Parity detection in sdw_initialize_slave()
1381 * device-dependent, it might e.g. only be enabled in in sdw_initialize_slave()
1382 * steady-state after a couple of frames. in sdw_initialize_slave()
1384 val = slave->prop.scp_int1_mask; in sdw_initialize_slave()
1387 ret = sdw_update_no_pm(slave, SDW_SCP_INTMASK1, val, val); in sdw_initialize_slave()
1389 dev_err(&slave->dev, in sdw_initialize_slave()
1395 if (!slave->prop.dp0_prop) in sdw_initialize_slave()
1399 val = prop->dp0_prop->imp_def_interrupts; in sdw_initialize_slave()
1402 ret = sdw_update_no_pm(slave, SDW_DP0_INTMASK, val, val); in sdw_initialize_slave()
1404 dev_err(&slave->dev, in sdw_initialize_slave()
1409 static int sdw_handle_dp0_interrupt(struct sdw_slave *slave, u8 *slave_status) in sdw_handle_dp0_interrupt() argument
1414 status = sdw_read_no_pm(slave, SDW_DP0_INT); in sdw_handle_dp0_interrupt()
1416 dev_err(&slave->dev, in sdw_handle_dp0_interrupt()
1425 dev_err(&slave->dev, "Test fail for port 0\n"); in sdw_handle_dp0_interrupt()
1435 complete(&slave->port_ready[0]); in sdw_handle_dp0_interrupt()
1440 dev_err(&slave->dev, "BRA failed\n"); in sdw_handle_dp0_interrupt()
1453 ret = sdw_write_no_pm(slave, SDW_DP0_INT, clear); in sdw_handle_dp0_interrupt()
1455 dev_err(&slave->dev, in sdw_handle_dp0_interrupt()
1461 status2 = sdw_read_no_pm(slave, SDW_DP0_INT); in sdw_handle_dp0_interrupt()
1463 dev_err(&slave->dev, in sdw_handle_dp0_interrupt()
1476 dev_warn(&slave->dev, "Reached MAX_RETRY on DP0 read\n"); in sdw_handle_dp0_interrupt()
1481 static int sdw_handle_port_interrupt(struct sdw_slave *slave, in sdw_handle_port_interrupt() argument
1489 return sdw_handle_dp0_interrupt(slave, slave_status); in sdw_handle_port_interrupt()
1492 status = sdw_read_no_pm(slave, addr); in sdw_handle_port_interrupt()
1494 dev_err(&slave->dev, in sdw_handle_port_interrupt()
1504 dev_err(&slave->dev, "Test fail for port:%d\n", port); in sdw_handle_port_interrupt()
1513 complete(&slave->port_ready[port]); in sdw_handle_port_interrupt()
1526 ret = sdw_write_no_pm(slave, addr, clear); in sdw_handle_port_interrupt()
1528 dev_err(&slave->dev, in sdw_handle_port_interrupt()
1534 status2 = sdw_read_no_pm(slave, addr); in sdw_handle_port_interrupt()
1536 dev_err(&slave->dev, in sdw_handle_port_interrupt()
1549 dev_warn(&slave->dev, "Reached MAX_RETRY on port read"); in sdw_handle_port_interrupt()
1554 static int sdw_handle_slave_alerts(struct sdw_slave *slave) in sdw_handle_slave_alerts() argument
1566 sdw_modify_slave_status(slave, SDW_SLAVE_ALERT); in sdw_handle_slave_alerts()
1568 ret = pm_runtime_resume_and_get(&slave->dev); in sdw_handle_slave_alerts()
1569 if (ret < 0 && ret != -EACCES) { in sdw_handle_slave_alerts()
1570 dev_err(&slave->dev, "Failed to resume device: %d\n", ret); in sdw_handle_slave_alerts()
1575 ret = sdw_read_no_pm(slave, SDW_SCP_INT1); in sdw_handle_slave_alerts()
1577 dev_err(&slave->dev, in sdw_handle_slave_alerts()
1583 ret = sdw_nread_no_pm(slave, SDW_SCP_INTSTAT2, 2, buf2); in sdw_handle_slave_alerts()
1585 dev_err(&slave->dev, in sdw_handle_slave_alerts()
1590 if (slave->prop.is_sdca) { in sdw_handle_slave_alerts()
1591 ret = sdw_read_no_pm(slave, SDW_DP0_INT); in sdw_handle_slave_alerts()
1593 dev_err(&slave->dev, in sdw_handle_slave_alerts()
1604 * Check parity, bus clash and Slave (impl defined) in sdw_handle_slave_alerts()
1608 parity_check = slave->prop.scp_int1_mask & SDW_SCP_INT1_PARITY; in sdw_handle_slave_alerts()
1609 parity_quirk = !slave->first_interrupt_done && in sdw_handle_slave_alerts()
1610 (slave->prop.quirks & SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY); in sdw_handle_slave_alerts()
1613 dev_err(&slave->dev, "Parity error detected\n"); in sdw_handle_slave_alerts()
1618 if (slave->prop.scp_int1_mask & SDW_SCP_INT1_BUS_CLASH) in sdw_handle_slave_alerts()
1619 dev_err(&slave->dev, "Bus clash detected\n"); in sdw_handle_slave_alerts()
1631 if (slave->prop.scp_int1_mask & SDW_SCP_INT1_IMPL_DEF) { in sdw_handle_slave_alerts()
1632 dev_dbg(&slave->dev, "Slave impl defined interrupt\n"); in sdw_handle_slave_alerts()
1642 /* Check port 0 - 3 interrupts */ in sdw_handle_slave_alerts()
1648 sdw_handle_port_interrupt(slave, bit, in sdw_handle_slave_alerts()
1658 sdw_handle_port_interrupt(slave, in sdw_handle_slave_alerts()
1670 sdw_handle_port_interrupt(slave, in sdw_handle_slave_alerts()
1676 /* Update the Slave driver */ in sdw_handle_slave_alerts()
1678 mutex_lock(&slave->sdw_dev_lock); in sdw_handle_slave_alerts()
1680 if (slave->probed) { in sdw_handle_slave_alerts()
1681 struct device *dev = &slave->dev; in sdw_handle_slave_alerts()
1682 struct sdw_driver *drv = drv_to_sdw_driver(dev->driver); in sdw_handle_slave_alerts()
1684 if (drv->ops && drv->ops->interrupt_callback) { in sdw_handle_slave_alerts()
1690 drv->ops->interrupt_callback(slave, &slave_intr); in sdw_handle_slave_alerts()
1694 mutex_unlock(&slave->sdw_dev_lock); in sdw_handle_slave_alerts()
1698 ret = sdw_write_no_pm(slave, SDW_SCP_INT1, clear); in sdw_handle_slave_alerts()
1700 dev_err(&slave->dev, in sdw_handle_slave_alerts()
1706 slave->first_interrupt_done = true; in sdw_handle_slave_alerts()
1712 ret = sdw_read_no_pm(slave, SDW_SCP_INT1); in sdw_handle_slave_alerts()
1714 dev_err(&slave->dev, in sdw_handle_slave_alerts()
1720 ret = sdw_nread_no_pm(slave, SDW_SCP_INTSTAT2, 2, _buf2); in sdw_handle_slave_alerts()
1722 dev_err(&slave->dev, in sdw_handle_slave_alerts()
1727 if (slave->prop.is_sdca) { in sdw_handle_slave_alerts()
1728 ret = sdw_read_no_pm(slave, SDW_DP0_INT); in sdw_handle_slave_alerts()
1730 dev_err(&slave->dev, in sdw_handle_slave_alerts()
1747 * Exit loop if Slave is continuously in ALERT state even in sdw_handle_slave_alerts()
1756 dev_warn(&slave->dev, "Reached MAX_RETRY on alert read\n"); in sdw_handle_slave_alerts()
1759 pm_runtime_mark_last_busy(&slave->dev); in sdw_handle_slave_alerts()
1760 pm_runtime_put_autosuspend(&slave->dev); in sdw_handle_slave_alerts()
1765 static int sdw_update_slave_status(struct sdw_slave *slave, in sdw_update_slave_status() argument
1770 mutex_lock(&slave->sdw_dev_lock); in sdw_update_slave_status()
1772 if (slave->probed) { in sdw_update_slave_status()
1773 struct device *dev = &slave->dev; in sdw_update_slave_status()
1774 struct sdw_driver *drv = drv_to_sdw_driver(dev->driver); in sdw_update_slave_status()
1776 if (drv->ops && drv->ops->update_status) in sdw_update_slave_status()
1777 ret = drv->ops->update_status(slave, status); in sdw_update_slave_status()
1780 mutex_unlock(&slave->sdw_dev_lock); in sdw_update_slave_status()
1786 * sdw_handle_slave_status() - Handle Slave status
1788 * @status: Status for all Slave(s)
1794 struct sdw_slave *slave; in sdw_handle_slave_status() local
1800 mutex_lock(&bus->bus_lock); in sdw_handle_slave_status()
1801 if (test_bit(i, bus->assigned) == false) { in sdw_handle_slave_status()
1802 mutex_unlock(&bus->bus_lock); in sdw_handle_slave_status()
1805 mutex_unlock(&bus->bus_lock); in sdw_handle_slave_status()
1807 slave = sdw_get_slave(bus, i); in sdw_handle_slave_status()
1808 if (!slave) in sdw_handle_slave_status()
1812 slave->status != SDW_SLAVE_UNATTACHED) { in sdw_handle_slave_status()
1813 dev_warn(&slave->dev, "Slave %d state check1: UNATTACHED, status was %d\n", in sdw_handle_slave_status()
1814 i, slave->status); in sdw_handle_slave_status()
1815 sdw_modify_slave_status(slave, SDW_SLAVE_UNATTACHED); in sdw_handle_slave_status()
1818 ret = sdw_update_slave_status(slave, status[i]); in sdw_handle_slave_status()
1820 dev_warn(&slave->dev, "Update Slave status failed:%d\n", ret); in sdw_handle_slave_status()
1825 dev_dbg(bus->dev, "Slave attached, programming device number\n"); in sdw_handle_slave_status()
1845 /* Continue to check other slave statuses */ in sdw_handle_slave_status()
1847 mutex_lock(&bus->bus_lock); in sdw_handle_slave_status()
1848 if (test_bit(i, bus->assigned) == false) { in sdw_handle_slave_status()
1849 mutex_unlock(&bus->bus_lock); in sdw_handle_slave_status()
1852 mutex_unlock(&bus->bus_lock); in sdw_handle_slave_status()
1854 slave = sdw_get_slave(bus, i); in sdw_handle_slave_status()
1855 if (!slave) in sdw_handle_slave_status()
1862 if (slave->status == SDW_SLAVE_UNATTACHED) in sdw_handle_slave_status()
1865 dev_warn(&slave->dev, "Slave %d state check2: UNATTACHED, status was %d\n", in sdw_handle_slave_status()
1866 i, slave->status); in sdw_handle_slave_status()
1868 sdw_modify_slave_status(slave, SDW_SLAVE_UNATTACHED); in sdw_handle_slave_status()
1872 ret = sdw_handle_slave_alerts(slave); in sdw_handle_slave_status()
1874 dev_err(&slave->dev, in sdw_handle_slave_status()
1875 "Slave %d alert handling failed: %d\n", in sdw_handle_slave_status()
1880 if (slave->status == SDW_SLAVE_ATTACHED) in sdw_handle_slave_status()
1883 prev_status = slave->status; in sdw_handle_slave_status()
1884 sdw_modify_slave_status(slave, SDW_SLAVE_ATTACHED); in sdw_handle_slave_status()
1891 ret = sdw_initialize_slave(slave); in sdw_handle_slave_status()
1893 dev_err(&slave->dev, in sdw_handle_slave_status()
1894 "Slave %d initialization failed: %d\n", in sdw_handle_slave_status()
1900 dev_err(&slave->dev, "Invalid slave %d status:%d\n", in sdw_handle_slave_status()
1905 ret = sdw_update_slave_status(slave, status[i]); in sdw_handle_slave_status()
1907 dev_err(&slave->dev, in sdw_handle_slave_status()
1908 "Update Slave status failed:%d\n", ret); in sdw_handle_slave_status()
1910 dev_dbg(&slave->dev, in sdw_handle_slave_status()
1911 "signaling initialization completion for Slave %d\n", in sdw_handle_slave_status()
1912 slave->dev_num); in sdw_handle_slave_status()
1914 complete(&slave->initialization_complete); in sdw_handle_slave_status()
1923 * This would be a no-op in case the peripheral was being resumed in sdw_handle_slave_status()
1926 pm_request_resume(&slave->dev); in sdw_handle_slave_status()
1936 struct sdw_slave *slave; in sdw_clear_slave_status() local
1939 /* Check all non-zero devices */ in sdw_clear_slave_status()
1941 mutex_lock(&bus->bus_lock); in sdw_clear_slave_status()
1942 if (test_bit(i, bus->assigned) == false) { in sdw_clear_slave_status()
1943 mutex_unlock(&bus->bus_lock); in sdw_clear_slave_status()
1946 mutex_unlock(&bus->bus_lock); in sdw_clear_slave_status()
1948 slave = sdw_get_slave(bus, i); in sdw_clear_slave_status()
1949 if (!slave) in sdw_clear_slave_status()
1952 if (slave->status != SDW_SLAVE_UNATTACHED) { in sdw_clear_slave_status()
1953 sdw_modify_slave_status(slave, SDW_SLAVE_UNATTACHED); in sdw_clear_slave_status()
1954 slave->first_interrupt_done = false; in sdw_clear_slave_status()
1955 sdw_update_slave_status(slave, SDW_SLAVE_UNATTACHED); in sdw_clear_slave_status()
1959 slave->unattach_request = request; in sdw_clear_slave_status()