Skip to content

Commit bb5cb09

Browse files
plbossartvinodkoul
authored andcommitted
soundwire: debugfs: add interface for BPT/BRA transfers
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 <[email protected]> Signed-off-by: Bard Liao <[email protected]> Reviewed-by: Péter Ujfalusi <[email protected]> Reviewed-by: Liam Girdwood <[email protected]> Reviewed-by: Ranjani Sridharan <[email protected]> Tested-by: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 3394e2b commit bb5cb09

File tree

1 file changed

+68
-16
lines changed

1 file changed

+68
-16
lines changed

drivers/soundwire/debugfs.c

+68-16
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ static int sdw_slave_reg_show(struct seq_file *s_file, void *data)
136136
}
137137
DEFINE_SHOW_ATTRIBUTE(sdw_slave_reg);
138138

139-
#define MAX_CMD_BYTES 256
139+
#define MAX_CMD_BYTES (1024 * 1024)
140140

141141
static int cmd;
142+
static int cmd_type;
142143
static u32 start_addr;
143144
static size_t num_bytes;
144145
static u8 read_buffer[MAX_CMD_BYTES];
@@ -162,6 +163,25 @@ static int set_command(void *data, u64 value)
162163
DEFINE_DEBUGFS_ATTRIBUTE(set_command_fops, NULL,
163164
set_command, "%llu\n");
164165

166+
static int set_command_type(void *data, u64 value)
167+
{
168+
struct sdw_slave *slave = data;
169+
170+
if (value > 1)
171+
return -EINVAL;
172+
173+
/* Userspace changed the hardware state behind the kernel's back */
174+
add_taint(TAINT_USER, LOCKDEP_STILL_OK);
175+
176+
dev_dbg(&slave->dev, "command type: %s\n", value ? "BRA" : "Column0");
177+
178+
cmd_type = (int)value;
179+
180+
return 0;
181+
}
182+
DEFINE_DEBUGFS_ATTRIBUTE(set_command_type_fops, NULL,
183+
set_command_type, "%llu\n");
184+
165185
static int set_start_address(void *data, u64 value)
166186
{
167187
struct sdw_slave *slave = data;
@@ -197,9 +217,28 @@ static int set_num_bytes(void *data, u64 value)
197217
DEFINE_DEBUGFS_ATTRIBUTE(set_num_bytes_fops, NULL,
198218
set_num_bytes, "%llu\n");
199219

220+
static int do_bpt_sequence(struct sdw_slave *slave, bool write, u8 *buffer)
221+
{
222+
struct sdw_bpt_msg msg = {0};
223+
224+
msg.addr = start_addr;
225+
msg.len = num_bytes;
226+
msg.dev_num = slave->dev_num;
227+
if (write)
228+
msg.flags = SDW_MSG_FLAG_WRITE;
229+
else
230+
msg.flags = SDW_MSG_FLAG_READ;
231+
msg.buf = buffer;
232+
233+
return sdw_bpt_send_sync(slave->bus, slave, &msg);
234+
}
235+
200236
static int cmd_go(void *data, u64 value)
201237
{
238+
const struct firmware *fw = NULL;
202239
struct sdw_slave *slave = data;
240+
ktime_t start_t;
241+
ktime_t finish_t;
203242
int ret;
204243

205244
if (value != 1)
@@ -216,40 +255,52 @@ static int cmd_go(void *data, u64 value)
216255
return ret;
217256
}
218257

219-
/* Userspace changed the hardware state behind the kernel's back */
220-
add_taint(TAINT_USER, LOCKDEP_STILL_OK);
221-
222-
dev_dbg(&slave->dev, "starting command\n");
223-
224258
if (cmd == 0) {
225-
const struct firmware *fw;
226-
227259
ret = request_firmware(&fw, firmware_file, &slave->dev);
228260
if (ret < 0) {
229261
dev_err(&slave->dev, "firmware %s not found\n", firmware_file);
230262
goto out;
231263
}
232-
233-
if (fw->size != num_bytes) {
264+
if (fw->size < num_bytes) {
234265
dev_err(&slave->dev,
235-
"firmware %s: unexpected size %zd, desired %zd\n",
266+
"firmware %s: firmware size %zd, desired %zd\n",
236267
firmware_file, fw->size, num_bytes);
237-
release_firmware(fw);
238268
goto out;
239269
}
270+
}
240271

241-
ret = sdw_nwrite_no_pm(slave, start_addr, num_bytes, fw->data);
242-
release_firmware(fw);
272+
/* Userspace changed the hardware state behind the kernel's back */
273+
add_taint(TAINT_USER, LOCKDEP_STILL_OK);
274+
275+
dev_dbg(&slave->dev, "starting command\n");
276+
start_t = ktime_get();
277+
278+
if (cmd == 0) {
279+
if (cmd_type)
280+
ret = do_bpt_sequence(slave, true, (u8 *)fw->data);
281+
else
282+
ret = sdw_nwrite_no_pm(slave, start_addr, num_bytes, fw->data);
243283
} else {
244-
ret = sdw_nread_no_pm(slave, start_addr, num_bytes, read_buffer);
284+
memset(read_buffer, 0, sizeof(read_buffer));
285+
286+
if (cmd_type)
287+
ret = do_bpt_sequence(slave, false, read_buffer);
288+
else
289+
ret = sdw_nread_no_pm(slave, start_addr, num_bytes, read_buffer);
245290
}
246291

247-
dev_dbg(&slave->dev, "command completed %d\n", ret);
292+
finish_t = ktime_get();
248293

249294
out:
295+
if (fw)
296+
release_firmware(fw);
297+
250298
pm_runtime_mark_last_busy(&slave->dev);
251299
pm_runtime_put(&slave->dev);
252300

301+
dev_dbg(&slave->dev, "command completed, num_byte %zu status %d, time %lld ms\n",
302+
num_bytes, ret, div_u64(finish_t - start_t, NSEC_PER_MSEC));
303+
253304
return ret;
254305
}
255306
DEFINE_DEBUGFS_ATTRIBUTE(cmd_go_fops, NULL,
@@ -291,6 +342,7 @@ void sdw_slave_debugfs_init(struct sdw_slave *slave)
291342

292343
/* interface to send arbitrary commands */
293344
debugfs_create_file("command", 0200, d, slave, &set_command_fops);
345+
debugfs_create_file("command_type", 0200, d, slave, &set_command_type_fops);
294346
debugfs_create_file("start_address", 0200, d, slave, &set_start_address_fops);
295347
debugfs_create_file("num_bytes", 0200, d, slave, &set_num_bytes_fops);
296348
debugfs_create_file("go", 0200, d, slave, &cmd_go_fops);

0 commit comments

Comments
 (0)