]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
soundwire: debugfs: add interface for BPT/BRA transfers
authorPierre-Louis Bossart <pierre-louis.bossart@linux.dev>
Thu, 27 Feb 2025 14:06:14 +0000 (22:06 +0800)
committerVinod Koul <vkoul@kernel.org>
Mon, 10 Mar 2025 07:01:19 +0000 (12:31 +0530)
Add code to show what codec drivers will need to do to enable BPT/BRA
transfers. The only difference is to set the 'command_type' file to
'1'. A zero-value will rely on regular read/write commands in Column0.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Liam Girdwood <liam.r.girdwood@intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Tested-by: shumingf@realtek.com
Link: https://lore.kernel.org/r/20250227140615.8147-16-yung-chuan.liao@linux.intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/soundwire/debugfs.c

index 5bf0d9552433f738515be9c9f8be4a48c9a25ff0..3099ea074f10e2ef13e9c88dda5c3f526855a748 100644 (file)
@@ -136,9 +136,10 @@ static int sdw_slave_reg_show(struct seq_file *s_file, void *data)
 }
 DEFINE_SHOW_ATTRIBUTE(sdw_slave_reg);
 
-#define MAX_CMD_BYTES 256
+#define MAX_CMD_BYTES (1024 * 1024)
 
 static int cmd;
+static int cmd_type;
 static u32 start_addr;
 static size_t num_bytes;
 static u8 read_buffer[MAX_CMD_BYTES];
@@ -162,6 +163,25 @@ static int set_command(void *data, u64 value)
 DEFINE_DEBUGFS_ATTRIBUTE(set_command_fops, NULL,
                         set_command, "%llu\n");
 
+static int set_command_type(void *data, u64 value)
+{
+       struct sdw_slave *slave = data;
+
+       if (value > 1)
+               return -EINVAL;
+
+       /* Userspace changed the hardware state behind the kernel's back */
+       add_taint(TAINT_USER, LOCKDEP_STILL_OK);
+
+       dev_dbg(&slave->dev, "command type: %s\n", value ? "BRA" : "Column0");
+
+       cmd_type = (int)value;
+
+       return 0;
+}
+DEFINE_DEBUGFS_ATTRIBUTE(set_command_type_fops, NULL,
+                        set_command_type, "%llu\n");
+
 static int set_start_address(void *data, u64 value)
 {
        struct sdw_slave *slave = data;
@@ -197,9 +217,28 @@ static int set_num_bytes(void *data, u64 value)
 DEFINE_DEBUGFS_ATTRIBUTE(set_num_bytes_fops, NULL,
                         set_num_bytes, "%llu\n");
 
+static int do_bpt_sequence(struct sdw_slave *slave, bool write, u8 *buffer)
+{
+       struct sdw_bpt_msg msg = {0};
+
+       msg.addr = start_addr;
+       msg.len = num_bytes;
+       msg.dev_num = slave->dev_num;
+       if (write)
+               msg.flags = SDW_MSG_FLAG_WRITE;
+       else
+               msg.flags = SDW_MSG_FLAG_READ;
+       msg.buf = buffer;
+
+       return sdw_bpt_send_sync(slave->bus, slave, &msg);
+}
+
 static int cmd_go(void *data, u64 value)
 {
+       const struct firmware *fw = NULL;
        struct sdw_slave *slave = data;
+       ktime_t start_t;
+       ktime_t finish_t;
        int ret;
 
        if (value != 1)
@@ -216,40 +255,52 @@ static int cmd_go(void *data, u64 value)
                return ret;
        }
 
-       /* Userspace changed the hardware state behind the kernel's back */
-       add_taint(TAINT_USER, LOCKDEP_STILL_OK);
-
-       dev_dbg(&slave->dev, "starting command\n");
-
        if (cmd == 0) {
-               const struct firmware *fw;
-
                ret = request_firmware(&fw, firmware_file, &slave->dev);
                if (ret < 0) {
                        dev_err(&slave->dev, "firmware %s not found\n", firmware_file);
                        goto out;
                }
-
-               if (fw->size != num_bytes) {
+               if (fw->size < num_bytes) {
                        dev_err(&slave->dev,
-                               "firmware %s: unexpected size %zd, desired %zd\n",
+                               "firmware %s: firmware size %zd, desired %zd\n",
                                firmware_file, fw->size, num_bytes);
-                       release_firmware(fw);
                        goto out;
                }
+       }
 
-               ret = sdw_nwrite_no_pm(slave, start_addr, num_bytes, fw->data);
-               release_firmware(fw);
+       /* Userspace changed the hardware state behind the kernel's back */
+       add_taint(TAINT_USER, LOCKDEP_STILL_OK);
+
+       dev_dbg(&slave->dev, "starting command\n");
+       start_t = ktime_get();
+
+       if (cmd == 0) {
+               if (cmd_type)
+                       ret = do_bpt_sequence(slave, true, (u8 *)fw->data);
+               else
+                       ret = sdw_nwrite_no_pm(slave, start_addr, num_bytes, fw->data);
        } else {
-               ret = sdw_nread_no_pm(slave, start_addr, num_bytes, read_buffer);
+               memset(read_buffer, 0, sizeof(read_buffer));
+
+               if (cmd_type)
+                       ret = do_bpt_sequence(slave, false, read_buffer);
+               else
+                       ret = sdw_nread_no_pm(slave, start_addr, num_bytes, read_buffer);
        }
 
-       dev_dbg(&slave->dev, "command completed %d\n", ret);
+       finish_t = ktime_get();
 
 out:
+       if (fw)
+               release_firmware(fw);
+
        pm_runtime_mark_last_busy(&slave->dev);
        pm_runtime_put(&slave->dev);
 
+       dev_dbg(&slave->dev, "command completed, num_byte %zu status %d, time %lld ms\n",
+               num_bytes, ret, div_u64(finish_t - start_t, NSEC_PER_MSEC));
+
        return ret;
 }
 DEFINE_DEBUGFS_ATTRIBUTE(cmd_go_fops, NULL,
@@ -291,6 +342,7 @@ void sdw_slave_debugfs_init(struct sdw_slave *slave)
 
        /* interface to send arbitrary commands */
        debugfs_create_file("command", 0200, d, slave, &set_command_fops);
+       debugfs_create_file("command_type", 0200, d, slave, &set_command_type_fops);
        debugfs_create_file("start_address", 0200, d, slave, &set_start_address_fops);
        debugfs_create_file("num_bytes", 0200, d, slave, &set_num_bytes_fops);
        debugfs_create_file("go", 0200, d, slave, &cmd_go_fops);