Merge tag 'soundwire-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul...
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 19 Jan 2024 01:08:31 +0000 (17:08 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 19 Jan 2024 01:08:31 +0000 (17:08 -0800)
Pull soundwire updates from Vinod Koul:

 - Core: add concept of controller_id to deal with clear Controller /
   Manager hierarchy

 - bunch of qcom driver refactoring for qcom_swrm_stream_alloc_ports(),
   qcom_swrm_stream_alloc_ports() and setting controller id to hw master
   id

* tag 'soundwire-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/soundwire:
  soundwire: amd: drop bus freq calculation and set 'max_clk_freq'
  soundwire: generic_bandwidth_allocation use bus->params.max_dr_freq
  soundwire: qcom: set controller id to hw master id
  soundwire: fix initializing sysfs for same devices on different buses
  soundwire: bus: introduce controller_id
  soundwire: stream: constify sdw_port_config when adding devices
  soundwire: qcom: move sconfig in qcom_swrm_stream_alloc_ports() out of critical section
  soundwire: qcom: drop unneeded qcom_swrm_stream_alloc_ports() cleanup

drivers/soundwire/amd_manager.c
drivers/soundwire/bus.c
drivers/soundwire/debugfs.c
drivers/soundwire/generic_bandwidth_allocation.c
drivers/soundwire/intel_auxdevice.c
drivers/soundwire/master.c
drivers/soundwire/qcom.c
drivers/soundwire/slave.c
drivers/soundwire/stream.c
include/linux/soundwire/sdw.h
sound/soc/intel/boards/sof_sdw.c

index 3a99f6dcdfafa24b9115ea7358837a57aa95a423..f54bb4dd2d1016a5c18abd53356ee02bf101a19a 100644 (file)
@@ -927,6 +927,14 @@ static int amd_sdw_manager_probe(struct platform_device *pdev)
        amd_manager->bus.clk_stop_timeout = 200;
        amd_manager->bus.link_id = amd_manager->instance;
 
+       /*
+        * Due to BIOS compatibility, the two links are exposed within
+        * the scope of a single controller. If this changes, the
+        * controller_id will have to be updated with drv_data
+        * information.
+        */
+       amd_manager->bus.controller_id = 0;
+
        switch (amd_manager->instance) {
        case ACP_SDW0:
                amd_manager->num_dout_ports = AMD_SDW0_MAX_TX_PORTS;
@@ -942,13 +950,13 @@ static int amd_sdw_manager_probe(struct platform_device *pdev)
 
        amd_manager->reg_mask = &sdw_manager_reg_mask_array[amd_manager->instance];
        params = &amd_manager->bus.params;
-       params->max_dr_freq = AMD_SDW_DEFAULT_CLK_FREQ * 2;
-       params->curr_dr_freq = AMD_SDW_DEFAULT_CLK_FREQ * 2;
+
        params->col = AMD_SDW_DEFAULT_COLUMNS;
        params->row = AMD_SDW_DEFAULT_ROWS;
        prop = &amd_manager->bus.prop;
        prop->clk_freq = &amd_sdw_freq_tbl[0];
        prop->mclk_freq = AMD_SDW_BUS_BASE_FREQ;
+       prop->max_clk_freq = AMD_SDW_DEFAULT_CLK_FREQ;
 
        ret = sdw_bus_master_add(&amd_manager->bus, dev, dev->fwnode);
        if (ret) {
index 41b0d9adf68ef349053b0fe8317bc9817eba4f31..f3fec15c311229f7a1da48bfb3de416ed52a95d6 100644 (file)
@@ -22,6 +22,10 @@ static int sdw_get_id(struct sdw_bus *bus)
                return rc;
 
        bus->id = rc;
+
+       if (bus->controller_id == -1)
+               bus->controller_id = rc;
+
        return 0;
 }
 
index d1553cb77187471b40e4601f3cd5399e241ad076..67abd7e52f092a988a2e3f20e253dd76c53b178f 100644 (file)
@@ -20,7 +20,7 @@ void sdw_bus_debugfs_init(struct sdw_bus *bus)
                return;
 
        /* create the debugfs master-N */
-       snprintf(name, sizeof(name), "master-%d-%d", bus->id, bus->link_id);
+       snprintf(name, sizeof(name), "master-%d-%d", bus->controller_id, bus->link_id);
        bus->debugfs = debugfs_create_dir(name, sdw_debugfs_root);
 }
 
index 31162f2b563811569dcf1bec7a0fc0757efa72f4..c70a63d009ae4b0ae4184952540f3a48b2b400d3 100644 (file)
@@ -333,7 +333,7 @@ static int sdw_select_row_col(struct sdw_bus *bus, int clk_freq)
  */
 static int sdw_compute_bus_params(struct sdw_bus *bus)
 {
-       unsigned int max_dr_freq, curr_dr_freq = 0;
+       unsigned int curr_dr_freq = 0;
        struct sdw_master_prop *mstr_prop = &bus->prop;
        int i, clk_values, ret;
        bool is_gear = false;
@@ -351,14 +351,12 @@ static int sdw_compute_bus_params(struct sdw_bus *bus)
                clk_buf = NULL;
        }
 
-       max_dr_freq = mstr_prop->max_clk_freq * SDW_DOUBLE_RATE_FACTOR;
-
        for (i = 0; i < clk_values; i++) {
                if (!clk_buf)
-                       curr_dr_freq = max_dr_freq;
+                       curr_dr_freq = bus->params.max_dr_freq;
                else
                        curr_dr_freq = (is_gear) ?
-                               (max_dr_freq >>  clk_buf[i]) :
+                               (bus->params.max_dr_freq >>  clk_buf[i]) :
                                clk_buf[i] * SDW_DOUBLE_RATE_FACTOR;
 
                if (curr_dr_freq <= bus->params.bandwidth)
index 7f15e3549e539d053a82b63b8346a362c6d0145c..93698532deac4098706099dfceaf85055f563b09 100644 (file)
@@ -234,6 +234,9 @@ static int intel_link_probe(struct auxiliary_device *auxdev,
        cdns->instance = sdw->instance;
        cdns->msg_count = 0;
 
+       /* single controller for all SoundWire links */
+       bus->controller_id = 0;
+
        bus->link_id = auxdev->id;
        bus->clk_stop_timeout = 1;
 
index 9b05c9e25ebe48a7d135ff45ad4b3af0fb1cb2aa..51abedbbaa6630e53ab301b85d6dcefe2f8ce9ac 100644 (file)
@@ -145,7 +145,7 @@ int sdw_master_device_add(struct sdw_bus *bus, struct device *parent,
        md->dev.fwnode = fwnode;
        md->dev.dma_mask = parent->dma_mask;
 
-       dev_set_name(&md->dev, "sdw-master-%d", bus->id);
+       dev_set_name(&md->dev, "sdw-master-%d-%d", bus->controller_id, bus->link_id);
 
        ret = device_register(&md->dev);
        if (ret) {
index 8076d40407d4d2647dcc658b760cdeddd02c3a21..3c4d6debab1f36b2648174071b7ad153ca4aac09 100644 (file)
@@ -1157,9 +1157,20 @@ static int qcom_swrm_stream_alloc_ports(struct qcom_swrm_ctrl *ctrl,
        struct sdw_port_runtime *p_rt;
        struct sdw_slave *slave;
        unsigned long *port_mask;
-       int i, maxport, pn, nports = 0, ret = 0;
+       int maxport, pn, nports = 0, ret = 0;
        unsigned int m_port;
 
+       if (direction == SNDRV_PCM_STREAM_CAPTURE)
+               sconfig.direction = SDW_DATA_DIR_TX;
+       else
+               sconfig.direction = SDW_DATA_DIR_RX;
+
+       /* hw parameters wil be ignored as we only support PDM */
+       sconfig.ch_count = 1;
+       sconfig.frame_rate = params_rate(params);
+       sconfig.type = stream->type;
+       sconfig.bps = 1;
+
        mutex_lock(&ctrl->port_lock);
        list_for_each_entry(m_rt, &stream->master_list, stream_node) {
                if (m_rt->direction == SDW_DATA_DIR_RX) {
@@ -1183,7 +1194,7 @@ static int qcom_swrm_stream_alloc_ports(struct qcom_swrm_ctrl *ctrl,
                                if (pn > maxport) {
                                        dev_err(ctrl->dev, "All ports busy\n");
                                        ret = -EBUSY;
-                                       goto err;
+                                       goto out;
                                }
                                set_bit(pn, port_mask);
                                pconfig[nports].num = pn;
@@ -1193,24 +1204,9 @@ static int qcom_swrm_stream_alloc_ports(struct qcom_swrm_ctrl *ctrl,
                }
        }
 
-       if (direction == SNDRV_PCM_STREAM_CAPTURE)
-               sconfig.direction = SDW_DATA_DIR_TX;
-       else
-               sconfig.direction = SDW_DATA_DIR_RX;
-
-       /* hw parameters wil be ignored as we only support PDM */
-       sconfig.ch_count = 1;
-       sconfig.frame_rate = params_rate(params);
-       sconfig.type = stream->type;
-       sconfig.bps = 1;
        sdw_stream_add_master(&ctrl->bus, &sconfig, pconfig,
                              nports, stream);
-err:
-       if (ret) {
-               for (i = 0; i < nports; i++)
-                       clear_bit(pconfig[i].num, port_mask);
-       }
-
+out:
        mutex_unlock(&ctrl->port_lock);
 
        return ret;
@@ -1593,6 +1589,13 @@ static int qcom_swrm_probe(struct platform_device *pdev)
                }
        }
 
+       ctrl->bus.controller_id = -1;
+
+       if (ctrl->version > SWRM_VERSION_1_3_0) {
+               ctrl->reg_read(ctrl, SWRM_COMP_MASTER_ID, &val);
+               ctrl->bus.controller_id = val;
+       }
+
        ret = sdw_bus_master_add(&ctrl->bus, dev, dev->fwnode);
        if (ret) {
                dev_err(dev, "Failed to register Soundwire controller (%d)\n",
index c1c1a2ac293af4eed496edf98c89178eee5f9818..060c2982e26b009d561eafcbf81b888ada781fd4 100644 (file)
@@ -39,14 +39,14 @@ int sdw_slave_add(struct sdw_bus *bus,
        slave->dev.fwnode = fwnode;
 
        if (id->unique_id == SDW_IGNORED_UNIQUE_ID) {
-               /* name shall be sdw:link:mfg:part:class */
-               dev_set_name(&slave->dev, "sdw:%01x:%04x:%04x:%02x",
-                            bus->link_id, id->mfg_id, id->part_id,
+               /* name shall be sdw:ctrl:link:mfg:part:class */
+               dev_set_name(&slave->dev, "sdw:%01x:%01x:%04x:%04x:%02x",
+                            bus->controller_id, bus->link_id, id->mfg_id, id->part_id,
                             id->class_id);
        } else {
-               /* name shall be sdw:link:mfg:part:class:unique */
-               dev_set_name(&slave->dev, "sdw:%01x:%04x:%04x:%02x:%01x",
-                            bus->link_id, id->mfg_id, id->part_id,
+               /* name shall be sdw:ctrl:link:mfg:part:class:unique */
+               dev_set_name(&slave->dev, "sdw:%01x:%01x:%04x:%04x:%02x:%01x",
+                            bus->controller_id, bus->link_id, id->mfg_id, id->part_id,
                             id->class_id, id->unique_id);
        }
 
index f048b3d55b2edcb32269369aa7c2b5dda07414ea..f9c0adc0738db27a7578509edbfbcd82c60b5206 100644 (file)
@@ -898,7 +898,7 @@ static struct sdw_port_runtime *sdw_port_alloc(struct list_head *port_list)
 }
 
 static int sdw_port_config(struct sdw_port_runtime *p_rt,
-                          struct sdw_port_config *port_config,
+                          const struct sdw_port_config *port_config,
                           int port_index)
 {
        p_rt->ch_mask = port_config[port_index].ch_mask;
@@ -971,7 +971,7 @@ static int sdw_slave_port_is_valid_range(struct device *dev, int num)
 
 static int sdw_slave_port_config(struct sdw_slave *slave,
                                 struct sdw_slave_runtime *s_rt,
-                                struct sdw_port_config *port_config)
+                                const struct sdw_port_config *port_config)
 {
        struct sdw_port_runtime *p_rt;
        int ret;
@@ -1027,7 +1027,7 @@ static int sdw_master_port_alloc(struct sdw_master_runtime *m_rt,
 }
 
 static int sdw_master_port_config(struct sdw_master_runtime *m_rt,
-                                 struct sdw_port_config *port_config)
+                                 const struct sdw_port_config *port_config)
 {
        struct sdw_port_runtime *p_rt;
        int ret;
@@ -1862,7 +1862,7 @@ EXPORT_SYMBOL(sdw_release_stream);
  */
 int sdw_stream_add_master(struct sdw_bus *bus,
                          struct sdw_stream_config *stream_config,
-                         struct sdw_port_config *port_config,
+                         const struct sdw_port_config *port_config,
                          unsigned int num_ports,
                          struct sdw_stream_runtime *stream)
 {
@@ -1982,7 +1982,7 @@ EXPORT_SYMBOL(sdw_stream_remove_master);
  */
 int sdw_stream_add_slave(struct sdw_slave *slave,
                         struct sdw_stream_config *stream_config,
-                        struct sdw_port_config *port_config,
+                        const struct sdw_port_config *port_config,
                         unsigned int num_ports,
                         struct sdw_stream_runtime *stream)
 {
index 4f3d14bb15385a2860e4e1ee54738f60eb7c1b06..66f814b63a435f65bcdf8743d7adbfde39ca7ad7 100644 (file)
@@ -886,7 +886,8 @@ struct sdw_master_ops {
  * struct sdw_bus - SoundWire bus
  * @dev: Shortcut to &bus->md->dev to avoid changing the entire code.
  * @md: Master device
- * @link_id: Link id number, can be 0 to N, unique for each Master
+ * @controller_id: system-unique controller ID. If set to -1, the bus @id will be used.
+ * @link_id: Link id number, can be 0 to N, unique for each Controller
  * @id: bus system-wide unique id
  * @slaves: list of Slaves on this bus
  * @assigned: Bitmap for Slave device numbers.
@@ -918,6 +919,7 @@ struct sdw_master_ops {
 struct sdw_bus {
        struct device *dev;
        struct sdw_master_device *md;
+       int controller_id;
        unsigned int link_id;
        int id;
        struct list_head slaves;
@@ -1040,7 +1042,7 @@ int sdw_compute_params(struct sdw_bus *bus);
 
 int sdw_stream_add_master(struct sdw_bus *bus,
                struct sdw_stream_config *stream_config,
-               struct sdw_port_config *port_config,
+               const struct sdw_port_config *port_config,
                unsigned int num_ports,
                struct sdw_stream_runtime *stream);
 int sdw_stream_remove_master(struct sdw_bus *bus,
@@ -1062,7 +1064,7 @@ void sdw_extract_slave_id(struct sdw_bus *bus, u64 addr, struct sdw_slave_id *id
 
 int sdw_stream_add_slave(struct sdw_slave *slave,
                         struct sdw_stream_config *stream_config,
-                        struct sdw_port_config *port_config,
+                        const struct sdw_port_config *port_config,
                         unsigned int num_ports,
                         struct sdw_stream_runtime *stream);
 int sdw_stream_remove_slave(struct sdw_slave *slave,
@@ -1084,7 +1086,7 @@ int sdw_update_no_pm(struct sdw_slave *slave, u32 addr, u8 mask, u8 val);
 
 static inline int sdw_stream_add_slave(struct sdw_slave *slave,
                                       struct sdw_stream_config *stream_config,
-                                      struct sdw_port_config *port_config,
+                                      const struct sdw_port_config *port_config,
                                       unsigned int num_ports,
                                       struct sdw_stream_runtime *stream)
 {
index 9ecee43ad84d115ed3460855fa46c3a6efb577bc..300391fbc2fc2b29863d6ba19169d60e9a22502c 100644 (file)
@@ -1256,11 +1256,11 @@ static int fill_sdw_codec_dlc(struct device *dev,
        else if (is_unique_device(adr_link, sdw_version, mfg_id, part_id,
                                  class_id, adr_index))
                codec->name = devm_kasprintf(dev, GFP_KERNEL,
-                                            "sdw:%01x:%04x:%04x:%02x", link_id,
+                                            "sdw:0:%01x:%04x:%04x:%02x", link_id,
                                             mfg_id, part_id, class_id);
        else
                codec->name = devm_kasprintf(dev, GFP_KERNEL,
-                                            "sdw:%01x:%04x:%04x:%02x:%01x", link_id,
+                                            "sdw:0:%01x:%04x:%04x:%02x:%01x", link_id,
                                             mfg_id, part_id, class_id, unique_id);
 
        if (!codec->name)