Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'soundwire-5.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/soundwire into char-misc-next

Vinod writes:
"soundwire updates for 5.20-rc1

- Core: solve the driver bind/unbind problem and remove ops pointer
- intel: runtime pm updates
- qcom: audio clock gating updates and device status checks"

* tag 'soundwire-5.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/soundwire:
soundwire: qcom: Enable software clock gating requirement flag
soundwire: qcom: Check device status before reading devid
soundwire: qcom: Add flag for software clock gating check
soundwire: qcom: Add support for controlling audio CGCR from HLOS
soundwire: intel: use pm_runtime_resume() on component probe
soundwire: peripheral: remove useless ops pointer
soundwire: revisit driver bind/unbind and callbacks
soundwire: bus_type: fix remove and shutdown support

+156 -69
+41 -32
drivers/soundwire/bus.c
··· 7 7 #include <linux/pm_runtime.h> 8 8 #include <linux/soundwire/sdw_registers.h> 9 9 #include <linux/soundwire/sdw.h> 10 + #include <linux/soundwire/sdw_type.h> 10 11 #include "bus.h" 11 12 #include "sysfs_local.h" 12 13 ··· 843 842 enum sdw_clk_stop_mode mode, 844 843 enum sdw_clk_stop_type type) 845 844 { 846 - int ret; 845 + int ret = 0; 847 846 848 - if (slave->ops && slave->ops->clk_stop) { 849 - ret = slave->ops->clk_stop(slave, mode, type); 850 - if (ret < 0) 851 - return ret; 847 + mutex_lock(&slave->sdw_dev_lock); 848 + 849 + if (slave->probed) { 850 + struct device *dev = &slave->dev; 851 + struct sdw_driver *drv = drv_to_sdw_driver(dev->driver); 852 + 853 + if (drv->ops && drv->ops->clk_stop) 854 + ret = drv->ops->clk_stop(slave, mode, type); 852 855 } 853 856 854 - return 0; 857 + mutex_unlock(&slave->sdw_dev_lock); 858 + 859 + return ret; 855 860 } 856 861 857 862 static int sdw_slave_clk_stop_prepare(struct sdw_slave *slave, ··· 1618 1611 } 1619 1612 1620 1613 /* Update the Slave driver */ 1621 - if (slave_notify && slave->ops && 1622 - slave->ops->interrupt_callback) { 1623 - slave_intr.sdca_cascade = sdca_cascade; 1624 - slave_intr.control_port = clear; 1625 - memcpy(slave_intr.port, &port_status, 1626 - sizeof(slave_intr.port)); 1614 + if (slave_notify) { 1615 + mutex_lock(&slave->sdw_dev_lock); 1627 1616 1628 - slave->ops->interrupt_callback(slave, &slave_intr); 1617 + if (slave->probed) { 1618 + struct device *dev = &slave->dev; 1619 + struct sdw_driver *drv = drv_to_sdw_driver(dev->driver); 1620 + 1621 + if (drv->ops && drv->ops->interrupt_callback) { 1622 + slave_intr.sdca_cascade = sdca_cascade; 1623 + slave_intr.control_port = clear; 1624 + memcpy(slave_intr.port, &port_status, 1625 + sizeof(slave_intr.port)); 1626 + 1627 + drv->ops->interrupt_callback(slave, &slave_intr); 1628 + } 1629 + } 1630 + 1631 + mutex_unlock(&slave->sdw_dev_lock); 1629 1632 } 1630 1633 1631 1634 /* Ack interrupt */ ··· 1709 1692 static int sdw_update_slave_status(struct sdw_slave *slave, 1710 1693 enum sdw_slave_status status) 1711 1694 { 1712 - unsigned long time; 1695 + int ret = 0; 1713 1696 1714 - if (!slave->probed) { 1715 - /* 1716 - * the slave status update is typically handled in an 1717 - * interrupt thread, which can race with the driver 1718 - * probe, e.g. when a module needs to be loaded. 1719 - * 1720 - * make sure the probe is complete before updating 1721 - * status. 1722 - */ 1723 - time = wait_for_completion_timeout(&slave->probe_complete, 1724 - msecs_to_jiffies(DEFAULT_PROBE_TIMEOUT)); 1725 - if (!time) { 1726 - dev_err(&slave->dev, "Probe not complete, timed out\n"); 1727 - return -ETIMEDOUT; 1728 - } 1697 + mutex_lock(&slave->sdw_dev_lock); 1698 + 1699 + if (slave->probed) { 1700 + struct device *dev = &slave->dev; 1701 + struct sdw_driver *drv = drv_to_sdw_driver(dev->driver); 1702 + 1703 + if (drv->ops && drv->ops->update_status) 1704 + ret = drv->ops->update_status(slave, status); 1729 1705 } 1730 1706 1731 - if (!slave->ops || !slave->ops->update_status) 1732 - return 0; 1707 + mutex_unlock(&slave->sdw_dev_lock); 1733 1708 1734 - return slave->ops->update_status(slave, status); 1709 + return ret; 1735 1710 } 1736 1711 1737 1712 /**
+27 -11
drivers/soundwire/bus_type.c
··· 98 98 if (!id) 99 99 return -ENODEV; 100 100 101 - slave->ops = drv->ops; 102 - 103 101 /* 104 102 * attach to power domain but don't turn on (last arg) 105 103 */ ··· 105 107 if (ret) 106 108 return ret; 107 109 110 + mutex_lock(&slave->sdw_dev_lock); 111 + 108 112 ret = drv->probe(slave, id); 109 113 if (ret) { 110 114 name = drv->name; 111 115 if (!name) 112 116 name = drv->driver.name; 117 + mutex_unlock(&slave->sdw_dev_lock); 118 + 113 119 dev_err(dev, "Probe of %s failed: %d\n", name, ret); 114 120 dev_pm_domain_detach(dev, false); 115 121 return ret; 116 122 } 117 123 118 124 /* device is probed so let's read the properties now */ 119 - if (slave->ops && slave->ops->read_prop) 120 - slave->ops->read_prop(slave); 125 + if (drv->ops && drv->ops->read_prop) 126 + drv->ops->read_prop(slave); 121 127 122 128 /* init the sysfs as we have properties now */ 123 129 ret = sdw_slave_sysfs_init(slave); ··· 141 139 slave->prop.clk_stop_timeout); 142 140 143 141 slave->probed = true; 144 - complete(&slave->probe_complete); 142 + 143 + /* 144 + * if the probe happened after the bus was started, notify the codec driver 145 + * of the current hardware status to e.g. start the initialization. 146 + * Errors are only logged as warnings to avoid failing the probe. 147 + */ 148 + if (drv->ops && drv->ops->update_status) { 149 + ret = drv->ops->update_status(slave, slave->status); 150 + if (ret < 0) 151 + dev_warn(dev, "%s: update_status failed with status %d\n", __func__, ret); 152 + } 153 + 154 + mutex_unlock(&slave->sdw_dev_lock); 145 155 146 156 dev_dbg(dev, "probe complete\n"); 147 157 ··· 166 152 struct sdw_driver *drv = drv_to_sdw_driver(dev->driver); 167 153 int ret = 0; 168 154 155 + mutex_lock(&slave->sdw_dev_lock); 156 + 157 + slave->probed = false; 158 + 169 159 if (drv->remove) 170 160 ret = drv->remove(slave); 161 + 162 + mutex_unlock(&slave->sdw_dev_lock); 171 163 172 164 dev_pm_domain_detach(dev, false); 173 165 ··· 213 193 214 194 drv->driver.owner = owner; 215 195 drv->driver.probe = sdw_drv_probe; 216 - 217 - if (drv->remove) 218 - drv->driver.remove = sdw_drv_remove; 219 - 220 - if (drv->shutdown) 221 - drv->driver.shutdown = sdw_drv_shutdown; 196 + drv->driver.remove = sdw_drv_remove; 197 + drv->driver.shutdown = sdw_drv_shutdown; 222 198 223 199 return driver_register(&drv->driver); 224 200 }
+18
drivers/soundwire/intel.c
··· 1043 1043 return ret; 1044 1044 } 1045 1045 1046 + static int intel_component_probe(struct snd_soc_component *component) 1047 + { 1048 + int ret; 1049 + 1050 + /* 1051 + * make sure the device is pm_runtime_active before initiating 1052 + * bus transactions during the card registration. 1053 + * We use pm_runtime_resume() here, without taking a reference 1054 + * and releasing it immediately. 1055 + */ 1056 + ret = pm_runtime_resume(component->dev); 1057 + if (ret < 0 && ret != -EACCES) 1058 + return ret; 1059 + 1060 + return 0; 1061 + } 1062 + 1046 1063 static int intel_component_dais_suspend(struct snd_soc_component *component) 1047 1064 { 1048 1065 struct snd_soc_dai *dai; ··· 1115 1098 1116 1099 static const struct snd_soc_component_driver dai_component = { 1117 1100 .name = "soundwire", 1101 + .probe = intel_component_probe, 1118 1102 .suspend = intel_component_dais_suspend 1119 1103 }; 1120 1104
+31 -1
drivers/soundwire/qcom.c
··· 13 13 #include <linux/of_device.h> 14 14 #include <linux/pm_runtime.h> 15 15 #include <linux/regmap.h> 16 + #include <linux/reset.h> 16 17 #include <linux/slab.h> 17 18 #include <linux/pm_wakeirq.h> 18 19 #include <linux/slimbus.h> ··· 143 142 struct device *dev; 144 143 struct regmap *regmap; 145 144 void __iomem *mmio; 145 + struct reset_control *audio_cgcr; 146 146 #ifdef CONFIG_DEBUG_FS 147 147 struct dentry *debugfs; 148 148 #endif ··· 181 179 struct qcom_swrm_data { 182 180 u32 default_cols; 183 181 u32 default_rows; 182 + bool sw_clk_gate_required; 184 183 }; 185 184 186 185 static const struct qcom_swrm_data swrm_v1_3_data = { ··· 192 189 static const struct qcom_swrm_data swrm_v1_5_data = { 193 190 .default_rows = 50, 194 191 .default_cols = 16, 192 + }; 193 + 194 + static const struct qcom_swrm_data swrm_v1_6_data = { 195 + .default_rows = 50, 196 + .default_cols = 16, 197 + .sw_clk_gate_required = true, 195 198 }; 196 199 197 200 #define to_qcom_sdw(b) container_of(b, struct qcom_swrm_ctrl, bus) ··· 480 471 char *buf1 = (char *)&val1, *buf2 = (char *)&val2; 481 472 482 473 for (i = 1; i <= SDW_MAX_DEVICES; i++) { 474 + /* do not continue if the status is Not Present */ 475 + if (!ctrl->status[i]) 476 + continue; 477 + 483 478 /*SCP_Devid5 - Devid 4*/ 484 479 ctrl->reg_read(ctrl, SWRM_ENUMERATOR_SLAVE_DEV_ID_1(i), &val1); 485 480 ··· 668 655 /* Clear Rows and Cols */ 669 656 val = FIELD_PREP(SWRM_MCP_FRAME_CTRL_BANK_ROW_CTRL_BMSK, ctrl->rows_index); 670 657 val |= FIELD_PREP(SWRM_MCP_FRAME_CTRL_BANK_COL_CTRL_BMSK, ctrl->cols_index); 658 + 659 + reset_control_reset(ctrl->audio_cgcr); 671 660 672 661 ctrl->reg_write(ctrl, SWRM_MCP_FRAME_CTRL_BANK_ADDR(0), val); 673 662 ··· 1322 1307 return PTR_ERR(ctrl->mmio); 1323 1308 } 1324 1309 1310 + if (data->sw_clk_gate_required) { 1311 + ctrl->audio_cgcr = devm_reset_control_get_exclusive(dev, "swr_audio_cgcr"); 1312 + if (IS_ERR_OR_NULL(ctrl->audio_cgcr)) { 1313 + dev_err(dev, "Failed to get cgcr reset ctrl required for SW gating\n"); 1314 + ret = PTR_ERR(ctrl->audio_cgcr); 1315 + goto err_init; 1316 + } 1317 + } 1318 + 1325 1319 ctrl->irq = of_irq_get(dev->of_node, 0); 1326 1320 if (ctrl->irq < 0) { 1327 1321 ret = ctrl->irq; ··· 1355 1331 ctrl->bus.port_ops = &qcom_swrm_port_ops; 1356 1332 ctrl->bus.compute_params = &qcom_swrm_compute_params; 1357 1333 ctrl->bus.clk_stop_timeout = 300; 1334 + 1335 + ctrl->audio_cgcr = devm_reset_control_get_exclusive(dev, "swr_audio_cgcr"); 1336 + if (IS_ERR(ctrl->audio_cgcr)) 1337 + dev_err(dev, "Failed to get audio_cgcr reset required for soundwire-v1.6.0\n"); 1358 1338 1359 1339 ret = qcom_swrm_get_port_config(ctrl); 1360 1340 if (ret) ··· 1513 1485 qcom_swrm_get_device_status(ctrl); 1514 1486 sdw_handle_slave_status(&ctrl->bus, ctrl->status); 1515 1487 } else { 1488 + reset_control_reset(ctrl->audio_cgcr); 1489 + 1516 1490 ctrl->reg_write(ctrl, SWRM_MCP_BUS_CTRL, SWRM_MCP_BUS_CLK_START); 1517 1491 ctrl->reg_write(ctrl, SWRM_INTERRUPT_CLEAR, 1518 1492 SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET); ··· 1578 1548 static const struct of_device_id qcom_swrm_of_match[] = { 1579 1549 { .compatible = "qcom,soundwire-v1.3.0", .data = &swrm_v1_3_data }, 1580 1550 { .compatible = "qcom,soundwire-v1.5.1", .data = &swrm_v1_5_data }, 1581 - { .compatible = "qcom,soundwire-v1.6.0", .data = &swrm_v1_5_data }, 1551 + { .compatible = "qcom,soundwire-v1.6.0", .data = &swrm_v1_6_data }, 1582 1552 {/* sentinel */}, 1583 1553 }; 1584 1554
+2 -1
drivers/soundwire/slave.c
··· 12 12 { 13 13 struct sdw_slave *slave = dev_to_sdw_dev(dev); 14 14 15 + mutex_destroy(&slave->sdw_dev_lock); 15 16 kfree(slave); 16 17 } 17 18 ··· 59 58 init_completion(&slave->enumeration_complete); 60 59 init_completion(&slave->initialization_complete); 61 60 slave->dev_num = 0; 62 - init_completion(&slave->probe_complete); 63 61 slave->probed = false; 64 62 slave->first_interrupt_done = false; 63 + mutex_init(&slave->sdw_dev_lock); 65 64 66 65 for (i = 0; i < SDW_MAX_PORTS; i++) 67 66 init_completion(&slave->port_ready[i]);
+35 -18
drivers/soundwire/stream.c
··· 13 13 #include <linux/slab.h> 14 14 #include <linux/soundwire/sdw_registers.h> 15 15 #include <linux/soundwire/sdw.h> 16 + #include <linux/soundwire/sdw_type.h> 16 17 #include <sound/soc.h> 17 18 #include "bus.h" 18 19 ··· 402 401 struct sdw_prepare_ch prep_ch, 403 402 enum sdw_port_prep_ops cmd) 404 403 { 405 - const struct sdw_slave_ops *ops = s_rt->slave->ops; 406 - int ret; 404 + int ret = 0; 405 + struct sdw_slave *slave = s_rt->slave; 407 406 408 - if (ops->port_prep) { 409 - ret = ops->port_prep(s_rt->slave, &prep_ch, cmd); 410 - if (ret < 0) { 411 - dev_err(&s_rt->slave->dev, 412 - "Slave Port Prep cmd %d failed: %d\n", 413 - cmd, ret); 414 - return ret; 407 + mutex_lock(&slave->sdw_dev_lock); 408 + 409 + if (slave->probed) { 410 + struct device *dev = &slave->dev; 411 + struct sdw_driver *drv = drv_to_sdw_driver(dev->driver); 412 + 413 + if (drv->ops && drv->ops->port_prep) { 414 + ret = drv->ops->port_prep(slave, &prep_ch, cmd); 415 + if (ret < 0) 416 + dev_err(dev, "Slave Port Prep cmd %d failed: %d\n", 417 + cmd, ret); 415 418 } 416 419 } 417 420 418 - return 0; 421 + mutex_unlock(&slave->sdw_dev_lock); 422 + 423 + return ret; 419 424 } 420 425 421 426 static int sdw_prep_deprep_slave_ports(struct sdw_bus *bus, ··· 585 578 struct sdw_slave_runtime *s_rt; 586 579 struct sdw_bus *bus = m_rt->bus; 587 580 struct sdw_slave *slave; 588 - int ret = 0; 581 + int ret; 589 582 590 583 if (bus->ops->set_bus_conf) { 591 584 ret = bus->ops->set_bus_conf(bus, &bus->params); ··· 596 589 list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) { 597 590 slave = s_rt->slave; 598 591 599 - if (slave->ops->bus_config) { 600 - ret = slave->ops->bus_config(slave, &bus->params); 601 - if (ret < 0) { 602 - dev_err(bus->dev, "Notify Slave: %d failed\n", 603 - slave->dev_num); 604 - return ret; 592 + mutex_lock(&slave->sdw_dev_lock); 593 + 594 + if (slave->probed) { 595 + struct device *dev = &slave->dev; 596 + struct sdw_driver *drv = drv_to_sdw_driver(dev->driver); 597 + 598 + if (drv->ops && drv->ops->bus_config) { 599 + ret = drv->ops->bus_config(slave, &bus->params); 600 + if (ret < 0) { 601 + dev_err(dev, "Notify Slave: %d failed\n", 602 + slave->dev_num); 603 + mutex_unlock(&slave->sdw_dev_lock); 604 + return ret; 605 + } 605 606 } 606 607 } 608 + 609 + mutex_unlock(&slave->sdw_dev_lock); 607 610 } 608 611 609 - return ret; 612 + return 0; 610 613 } 611 614 612 615 /**
+2 -6
include/linux/soundwire/sdw.h
··· 637 637 * @dev: Linux device 638 638 * @status: Status reported by the Slave 639 639 * @bus: Bus handle 640 - * @ops: Slave callback ops 641 640 * @prop: Slave properties 642 641 * @debugfs: Slave debugfs 643 642 * @node: node for bus list ··· 645 646 * @dev_num: Current Device Number, values can be 0 or dev_num_sticky 646 647 * @dev_num_sticky: one-time static Device Number assigned by Bus 647 648 * @probed: boolean tracking driver state 648 - * @probe_complete: completion utility to control potential races 649 - * on startup between driver probe/initialization and SoundWire 650 - * Slave state changes/implementation-defined interrupts 651 649 * @enumeration_complete: completion utility to control potential races 652 650 * on startup between device enumeration and read/write access to the 653 651 * Slave device ··· 659 663 * for a Slave happens for the first time after enumeration 660 664 * @is_mockup_device: status flag used to squelch errors in the command/control 661 665 * protocol for SoundWire mockup devices 666 + * @sdw_dev_lock: mutex used to protect callbacks/remove races 662 667 */ 663 668 struct sdw_slave { 664 669 struct sdw_slave_id id; 665 670 struct device dev; 666 671 enum sdw_slave_status status; 667 672 struct sdw_bus *bus; 668 - const struct sdw_slave_ops *ops; 669 673 struct sdw_slave_prop prop; 670 674 #ifdef CONFIG_DEBUG_FS 671 675 struct dentry *debugfs; ··· 676 680 u16 dev_num; 677 681 u16 dev_num_sticky; 678 682 bool probed; 679 - struct completion probe_complete; 680 683 struct completion enumeration_complete; 681 684 struct completion initialization_complete; 682 685 u32 unattach_request; 683 686 bool first_interrupt_done; 684 687 bool is_mockup_device; 688 + struct mutex sdw_dev_lock; /* protect callbacks/remove races */ 685 689 }; 686 690 687 691 #define dev_to_sdw_dev(_dev) container_of(_dev, struct sdw_slave, dev)