Skip to content

Commit 357ee88

Browse files
Roja Rani Yarubandiwsakernel
authored andcommitted
i2c: qcom-geni: Store DMA mapping data in geni_i2c_dev struct
Store DMA mapping data in geni_i2c_dev struct to enhance DMA mapping data scope. For example during shutdown callback to unmap DMA mapping, this stored DMA mapping data can be used to call geni_se_tx_dma_unprep and geni_se_rx_dma_unprep functions. Add two helper functions geni_i2c_rx_msg_cleanup and geni_i2c_tx_msg_cleanup to unwrap the things after rx/tx FIFO/DMA transfers, so that the same can be used in geni_i2c_stop_xfer() function during shutdown callback. Signed-off-by: Roja Rani Yarubandi <[email protected]> Reviewed-by: Akash Asthana <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 5581b41 commit 357ee88

File tree

1 file changed

+43
-16
lines changed

1 file changed

+43
-16
lines changed

drivers/i2c/busses/i2c-qcom-geni.c

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ struct geni_i2c_dev {
8686
u32 clk_freq_out;
8787
const struct geni_i2c_clk_fld *clk_fld;
8888
int suspended;
89+
void *dma_buf;
90+
size_t xfer_len;
91+
dma_addr_t dma_addr;
8992
};
9093

9194
struct geni_i2c_err_log {
@@ -348,14 +351,39 @@ static void geni_i2c_tx_fsm_rst(struct geni_i2c_dev *gi2c)
348351
dev_err(gi2c->se.dev, "Timeout resetting TX_FSM\n");
349352
}
350353

354+
static void geni_i2c_rx_msg_cleanup(struct geni_i2c_dev *gi2c,
355+
struct i2c_msg *cur)
356+
{
357+
gi2c->cur_rd = 0;
358+
if (gi2c->dma_buf) {
359+
if (gi2c->err)
360+
geni_i2c_rx_fsm_rst(gi2c);
361+
geni_se_rx_dma_unprep(&gi2c->se, gi2c->dma_addr, gi2c->xfer_len);
362+
i2c_put_dma_safe_msg_buf(gi2c->dma_buf, cur, !gi2c->err);
363+
}
364+
}
365+
366+
static void geni_i2c_tx_msg_cleanup(struct geni_i2c_dev *gi2c,
367+
struct i2c_msg *cur)
368+
{
369+
gi2c->cur_wr = 0;
370+
if (gi2c->dma_buf) {
371+
if (gi2c->err)
372+
geni_i2c_tx_fsm_rst(gi2c);
373+
geni_se_tx_dma_unprep(&gi2c->se, gi2c->dma_addr, gi2c->xfer_len);
374+
i2c_put_dma_safe_msg_buf(gi2c->dma_buf, cur, !gi2c->err);
375+
}
376+
}
377+
351378
static int geni_i2c_rx_one_msg(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
352379
u32 m_param)
353380
{
354-
dma_addr_t rx_dma;
381+
dma_addr_t rx_dma = 0;
355382
unsigned long time_left;
356383
void *dma_buf;
357384
struct geni_se *se = &gi2c->se;
358385
size_t len = msg->len;
386+
struct i2c_msg *cur;
359387

360388
dma_buf = i2c_get_dma_safe_msg_buf(msg, 32);
361389
if (dma_buf)
@@ -370,31 +398,31 @@ static int geni_i2c_rx_one_msg(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
370398
geni_se_select_mode(se, GENI_SE_FIFO);
371399
i2c_put_dma_safe_msg_buf(dma_buf, msg, false);
372400
dma_buf = NULL;
401+
} else {
402+
gi2c->xfer_len = len;
403+
gi2c->dma_addr = rx_dma;
404+
gi2c->dma_buf = dma_buf;
373405
}
374406

407+
cur = gi2c->cur;
375408
time_left = wait_for_completion_timeout(&gi2c->done, XFER_TIMEOUT);
376409
if (!time_left)
377410
geni_i2c_abort_xfer(gi2c);
378411

379-
gi2c->cur_rd = 0;
380-
if (dma_buf) {
381-
if (gi2c->err)
382-
geni_i2c_rx_fsm_rst(gi2c);
383-
geni_se_rx_dma_unprep(se, rx_dma, len);
384-
i2c_put_dma_safe_msg_buf(dma_buf, msg, !gi2c->err);
385-
}
412+
geni_i2c_rx_msg_cleanup(gi2c, cur);
386413

387414
return gi2c->err;
388415
}
389416

390417
static int geni_i2c_tx_one_msg(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
391418
u32 m_param)
392419
{
393-
dma_addr_t tx_dma;
420+
dma_addr_t tx_dma = 0;
394421
unsigned long time_left;
395422
void *dma_buf;
396423
struct geni_se *se = &gi2c->se;
397424
size_t len = msg->len;
425+
struct i2c_msg *cur;
398426

399427
dma_buf = i2c_get_dma_safe_msg_buf(msg, 32);
400428
if (dma_buf)
@@ -409,22 +437,21 @@ static int geni_i2c_tx_one_msg(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
409437
geni_se_select_mode(se, GENI_SE_FIFO);
410438
i2c_put_dma_safe_msg_buf(dma_buf, msg, false);
411439
dma_buf = NULL;
440+
} else {
441+
gi2c->xfer_len = len;
442+
gi2c->dma_addr = tx_dma;
443+
gi2c->dma_buf = dma_buf;
412444
}
413445

414446
if (!dma_buf) /* Get FIFO IRQ */
415447
writel_relaxed(1, se->base + SE_GENI_TX_WATERMARK_REG);
416448

449+
cur = gi2c->cur;
417450
time_left = wait_for_completion_timeout(&gi2c->done, XFER_TIMEOUT);
418451
if (!time_left)
419452
geni_i2c_abort_xfer(gi2c);
420453

421-
gi2c->cur_wr = 0;
422-
if (dma_buf) {
423-
if (gi2c->err)
424-
geni_i2c_tx_fsm_rst(gi2c);
425-
geni_se_tx_dma_unprep(se, tx_dma, len);
426-
i2c_put_dma_safe_msg_buf(dma_buf, msg, !gi2c->err);
427-
}
454+
geni_i2c_tx_msg_cleanup(gi2c, cur);
428455

429456
return gi2c->err;
430457
}

0 commit comments

Comments
 (0)