Skip to content

Commit 8a33543

Browse files
committed
soundwire: introduce BPT section
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 lengh and check if it reach maximum BPT bytes. No function changes. Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
1 parent 59ba113 commit 8a33543

4 files changed

Lines changed: 45 additions & 19 deletions

File tree

drivers/soundwire/bus.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,8 +2052,14 @@ EXPORT_SYMBOL(sdw_clear_slave_status);
20522052

20532053
int sdw_bpt_send_async(struct sdw_bus *bus, struct sdw_slave *slave, struct sdw_bpt_msg *msg)
20542054
{
2055-
if (msg->len > SDW_BPT_MSG_MAX_BYTES) {
2056-
dev_err(bus->dev, "Invalid BPT message length %d\n", msg->len);
2055+
int len = 0;
2056+
int i;
2057+
2058+
for (i = 0; i < msg->sections; i++)
2059+
len += msg->sec[i].len;
2060+
2061+
if (len > SDW_BPT_MSG_MAX_BYTES) {
2062+
dev_err(bus->dev, "Invalid BPT message length %d\n", len);
20572063
return -EINVAL;
20582064
}
20592065

drivers/soundwire/bus.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,31 @@ struct sdw_msg {
7373
};
7474

7575
/**
76-
* struct sdw_btp_msg - Message structure
76+
* struct sdw_btp_section - Message section structure
7777
* @addr: Start Register address accessed in the Slave
7878
* @len: number of bytes to transfer. More than 64Kb can be transferred
7979
* but a practical limit of SDW_BPT_MSG_MAX_BYTES is enforced.
80-
* @dev_num: Slave device number
81-
* @flags: transfer flags, indicate if xfer is read or write
82-
* @buf: message data buffer (filled by host for write, filled
80+
* @buf: section data buffer (filled by host for write, filled
8381
* by Peripheral hardware for reads)
8482
*/
85-
struct sdw_bpt_msg {
83+
struct sdw_bpt_section {
8684
u32 addr;
8785
u32 len;
86+
u8 *buf;
87+
};
88+
89+
/**
90+
* struct sdw_btp_msg - Message structure
91+
* @sec: Pointer to array of sections
92+
* @sections: Number of sections in the array
93+
* @dev_num: Slave device number
94+
* @flags: transfer flags, indicate if xfer is read or write
95+
*/
96+
struct sdw_bpt_msg {
97+
struct sdw_bpt_section *sec;
98+
int sections;
8899
u8 dev_num;
89100
u8 flags;
90-
u8 *buf;
91101
};
92102

93103
#define SDW_DOUBLE_RATE_FACTOR 2

drivers/soundwire/debugfs.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,23 @@ DEFINE_DEBUGFS_ATTRIBUTE(set_num_bytes_fops, NULL,
222222
static int do_bpt_sequence(struct sdw_slave *slave, bool write, u8 *buffer)
223223
{
224224
struct sdw_bpt_msg msg = {0};
225+
struct sdw_bpt_section *sec;
225226

226-
msg.addr = start_addr;
227-
msg.len = num_bytes;
227+
sec = kcalloc(1, sizeof(*sec), GFP_KERNEL);
228+
if (!sec)
229+
return -ENOMEM;
230+
msg.sections = 1;
231+
232+
sec[0].addr = start_addr;
233+
sec[0].len = num_bytes;
234+
235+
msg.sec = sec;
228236
msg.dev_num = slave->dev_num;
229237
if (write)
230238
msg.flags = SDW_MSG_FLAG_WRITE;
231239
else
232240
msg.flags = SDW_MSG_FLAG_READ;
233-
msg.buf = buffer;
241+
sec[0].buf = buffer;
234242

235243
return sdw_bpt_send_sync(slave->bus, slave, &msg);
236244
}

drivers/soundwire/intel_ace2x.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static int intel_ace2x_bpt_open_stream(struct sdw_intel *sdw, struct sdw_slave *
156156
goto deprepare_stream;
157157

158158
ret = sdw_cdns_bpt_find_buffer_sizes(command, cdns->bus.params.row, cdns->bus.params.col,
159-
msg->len, SDW_BPT_MSG_MAX_BYTES, &data_per_frame,
159+
msg->sec[0].len, SDW_BPT_MSG_MAX_BYTES, &data_per_frame,
160160
&pdi0_buffer_size, &pdi1_buffer_size, &num_frames);
161161
if (ret < 0)
162162
goto deprepare_stream;
@@ -204,7 +204,7 @@ static int intel_ace2x_bpt_open_stream(struct sdw_intel *sdw, struct sdw_slave *
204204
}
205205

206206
dev_dbg(cdns->dev, "Message len %d transferred in %d frames (%d per frame)\n",
207-
msg->len, num_frames, data_per_frame);
207+
msg->sec[0].len, num_frames, data_per_frame);
208208
dev_dbg(cdns->dev, "sizes pdi0 %d pdi1 %d tx_bandwidth %d rx_bandwidth %d\n",
209209
pdi0_buffer_size, pdi1_buffer_size, tx_dma_bandwidth, rx_dma_bandwidth);
210210

@@ -219,12 +219,14 @@ static int intel_ace2x_bpt_open_stream(struct sdw_intel *sdw, struct sdw_slave *
219219
}
220220

221221
if (!command) {
222-
ret = sdw_cdns_prepare_write_dma_buffer(msg->dev_num, msg->addr, msg->buf,
223-
msg->len, data_per_frame,
222+
ret = sdw_cdns_prepare_write_dma_buffer(msg->dev_num, msg->sec[0].addr,
223+
msg->sec[0].buf,
224+
msg->sec[0].len, data_per_frame,
224225
sdw->bpt_ctx.dmab_tx_bdl.area,
225226
pdi0_buffer_size, &tx_total_bytes);
226227
} else {
227-
ret = sdw_cdns_prepare_read_dma_buffer(msg->dev_num, msg->addr, msg->len,
228+
ret = sdw_cdns_prepare_read_dma_buffer(msg->dev_num, msg->sec[0].addr,
229+
msg->sec[0].len,
228230
data_per_frame,
229231
sdw->bpt_ctx.dmab_tx_bdl.area,
230232
pdi0_buffer_size, &tx_total_bytes,
@@ -305,9 +307,9 @@ static int intel_ace2x_bpt_send_async(struct sdw_intel *sdw, struct sdw_slave *s
305307
struct sdw_cdns *cdns = &sdw->cdns;
306308
int ret;
307309

308-
if (msg->len < INTEL_BPT_MSG_BYTE_MIN) {
310+
if (msg->sec[0].len < INTEL_BPT_MSG_BYTE_MIN) {
309311
dev_err(cdns->dev, "BPT message length %d is less than the minimum bytes %d\n",
310-
msg->len, INTEL_BPT_MSG_BYTE_MIN);
312+
msg->sec[0].len, INTEL_BPT_MSG_BYTE_MIN);
311313
return -EINVAL;
312314
}
313315

@@ -367,7 +369,7 @@ static int intel_ace2x_bpt_wait(struct sdw_intel *sdw, struct sdw_slave *slave,
367369
} else {
368370
ret = sdw_cdns_check_read_response(cdns->dev, sdw->bpt_ctx.dmab_rx_bdl.area,
369371
sdw->bpt_ctx.pdi1_buffer_size,
370-
msg->buf, msg->len, sdw->bpt_ctx.num_frames,
372+
msg->sec[0].buf, msg->sec[0].len, sdw->bpt_ctx.num_frames,
371373
sdw->bpt_ctx.data_per_frame);
372374
if (ret < 0)
373375
dev_err(cdns->dev, "%s: BPT Read failed %d\n", __func__, ret);

0 commit comments

Comments
 (0)