]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
soundwire: introduce BPT section
authorBard Liao <yung-chuan.liao@linux.intel.com>
Tue, 21 Oct 2025 09:43:52 +0000 (17:43 +0800)
committerVinod Koul <vkoul@kernel.org>
Mon, 8 Dec 2025 07:07:27 +0000 (12:37 +0530)
Currently we send a BRA message with a start address with continuous
registers in a BPT stream. However, a codec may need to write different
register sections shortly. Introduce a register section in struct
sdw_btp_msg which contain register start address, length, and buffer.
This commit uses only 1 section for each BPT message. And we need to add
up all BPT section length and check if it reach maximum BPT bytes.
No function changes.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Tested-by: Shuming Fan <shumingf@realtek.com>
Link: https://patch.msgid.link/20251021094355.132943-2-yung-chuan.liao@linux.intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/soundwire/bus.c
drivers/soundwire/bus.h
drivers/soundwire/debugfs.c
drivers/soundwire/intel_ace2x.c

index 55c1db81653400e36a9ad9a5f4394f23a49e1bbe..fb68738dfb9b8447b0c03f3bd4cfbec4cea7504d 100644 (file)
@@ -2052,8 +2052,14 @@ EXPORT_SYMBOL(sdw_clear_slave_status);
 
 int sdw_bpt_send_async(struct sdw_bus *bus, struct sdw_slave *slave, struct sdw_bpt_msg *msg)
 {
-       if (msg->len > SDW_BPT_MSG_MAX_BYTES) {
-               dev_err(bus->dev, "Invalid BPT message length %d\n", msg->len);
+       int len = 0;
+       int i;
+
+       for (i = 0; i < msg->sections; i++)
+               len += msg->sec[i].len;
+
+       if (len > SDW_BPT_MSG_MAX_BYTES) {
+               dev_err(bus->dev, "Invalid BPT message length %d\n", len);
                return -EINVAL;
        }
 
index 02651fbb683aca9651b5844359ef444f8f7cb936..8115c64dd48e2fd767121724e92813deb81f5da9 100644 (file)
@@ -73,21 +73,31 @@ struct sdw_msg {
 };
 
 /**
- * struct sdw_btp_msg - Message structure
+ * struct sdw_btp_section - Message section structure
  * @addr: Start Register address accessed in the Slave
  * @len: number of bytes to transfer. More than 64Kb can be transferred
  * but a practical limit of SDW_BPT_MSG_MAX_BYTES is enforced.
- * @dev_num: Slave device number
- * @flags: transfer flags, indicate if xfer is read or write
- * @buf: message data buffer (filled by host for write, filled
+ * @buf: section data buffer (filled by host for write, filled
  * by Peripheral hardware for reads)
  */
-struct sdw_bpt_msg {
+struct sdw_bpt_section {
        u32 addr;
        u32 len;
+       u8 *buf;
+};
+
+/**
+ * struct sdw_btp_msg - Message structure
+ * @sec: Pointer to array of sections
+ * @sections: Number of sections in the array
+ * @dev_num: Slave device number
+ * @flags: transfer flags, indicate if xfer is read or write
+ */
+struct sdw_bpt_msg {
+       struct sdw_bpt_section *sec;
+       int sections;
        u8 dev_num;
        u8 flags;
-       u8 *buf;
 };
 
 #define SDW_DOUBLE_RATE_FACTOR         2
index 1e0f9318b61656434d42797e5facfc289189c2b9..6068011dd0d989b027b8f38a2ab401be56d6237a 100644 (file)
@@ -222,15 +222,23 @@ DEFINE_DEBUGFS_ATTRIBUTE(set_num_bytes_fops, NULL,
 static int do_bpt_sequence(struct sdw_slave *slave, bool write, u8 *buffer)
 {
        struct sdw_bpt_msg msg = {0};
+       struct sdw_bpt_section *sec;
 
-       msg.addr = start_addr;
-       msg.len = num_bytes;
+       sec = kcalloc(1, sizeof(*sec), GFP_KERNEL);
+       if (!sec)
+               return -ENOMEM;
+       msg.sections = 1;
+
+       sec[0].addr = start_addr;
+       sec[0].len = num_bytes;
+
+       msg.sec = sec;
        msg.dev_num = slave->dev_num;
        if (write)
                msg.flags = SDW_MSG_FLAG_WRITE;
        else
                msg.flags = SDW_MSG_FLAG_READ;
-       msg.buf = buffer;
+       sec[0].buf = buffer;
 
        return sdw_bpt_send_sync(slave->bus, slave, &msg);
 }
index e11a0cf771936a7aaca97fbd85e3c1c7a4b1affa..a0f708a7cdff00a9597482bfdbf889460073855b 100644 (file)
@@ -156,8 +156,9 @@ static int intel_ace2x_bpt_open_stream(struct sdw_intel *sdw, struct sdw_slave *
                goto deprepare_stream;
 
        ret = sdw_cdns_bpt_find_buffer_sizes(command, cdns->bus.params.row, cdns->bus.params.col,
-                                            msg->len, SDW_BPT_MSG_MAX_BYTES, &data_per_frame,
-                                            &pdi0_buffer_size, &pdi1_buffer_size, &num_frames);
+                                            msg->sec[0].len, SDW_BPT_MSG_MAX_BYTES,
+                                            &data_per_frame, &pdi0_buffer_size, &pdi1_buffer_size,
+                                            &num_frames);
        if (ret < 0)
                goto deprepare_stream;
 
@@ -204,7 +205,7 @@ static int intel_ace2x_bpt_open_stream(struct sdw_intel *sdw, struct sdw_slave *
        }
 
        dev_dbg(cdns->dev, "Message len %d transferred in %d frames (%d per frame)\n",
-               msg->len, num_frames, data_per_frame);
+               msg->sec[0].len, num_frames, data_per_frame);
        dev_dbg(cdns->dev, "sizes pdi0 %d pdi1 %d tx_bandwidth %d rx_bandwidth %d\n",
                pdi0_buffer_size, pdi1_buffer_size, tx_dma_bandwidth, rx_dma_bandwidth);
 
@@ -219,12 +220,14 @@ static int intel_ace2x_bpt_open_stream(struct sdw_intel *sdw, struct sdw_slave *
        }
 
        if (!command) {
-               ret = sdw_cdns_prepare_write_dma_buffer(msg->dev_num, msg->addr, msg->buf,
-                                                       msg->len, data_per_frame,
+               ret = sdw_cdns_prepare_write_dma_buffer(msg->dev_num, msg->sec[0].addr,
+                                                       msg->sec[0].buf,
+                                                       msg->sec[0].len, data_per_frame,
                                                        sdw->bpt_ctx.dmab_tx_bdl.area,
                                                        pdi0_buffer_size, &tx_total_bytes);
        } else {
-               ret = sdw_cdns_prepare_read_dma_buffer(msg->dev_num, msg->addr, msg->len,
+               ret = sdw_cdns_prepare_read_dma_buffer(msg->dev_num, msg->sec[0].addr,
+                                                      msg->sec[0].len,
                                                       data_per_frame,
                                                       sdw->bpt_ctx.dmab_tx_bdl.area,
                                                       pdi0_buffer_size, &tx_total_bytes,
@@ -305,9 +308,9 @@ static int intel_ace2x_bpt_send_async(struct sdw_intel *sdw, struct sdw_slave *s
        struct sdw_cdns *cdns = &sdw->cdns;
        int ret;
 
-       if (msg->len < INTEL_BPT_MSG_BYTE_MIN) {
+       if (msg->sec[0].len < INTEL_BPT_MSG_BYTE_MIN) {
                dev_err(cdns->dev, "BPT message length %d is less than the minimum bytes %d\n",
-                       msg->len, INTEL_BPT_MSG_BYTE_MIN);
+                       msg->sec[0].len, INTEL_BPT_MSG_BYTE_MIN);
                return -EINVAL;
        }
 
@@ -367,7 +370,8 @@ static int intel_ace2x_bpt_wait(struct sdw_intel *sdw, struct sdw_slave *slave,
        } else {
                ret = sdw_cdns_check_read_response(cdns->dev, sdw->bpt_ctx.dmab_rx_bdl.area,
                                                   sdw->bpt_ctx.pdi1_buffer_size,
-                                                  msg->buf, msg->len, sdw->bpt_ctx.num_frames,
+                                                  msg->sec[0].buf, msg->sec[0].len,
+                                                  sdw->bpt_ctx.num_frames,
                                                   sdw->bpt_ctx.data_per_frame);
                if (ret < 0)
                        dev_err(cdns->dev, "%s: BPT Read failed %d\n", __func__, ret);