Skip to content

Commit e844a79

Browse files
Wolfram SangWolfram Sang
authored andcommitted
i2c: sh_mobile: refactor DMA setup
Refactor DMA setup to keep the errno so we can implement better deferred probe support in the next step. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
1 parent 00d8689 commit e844a79

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

drivers/i2c/busses/i2c-sh_mobile.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ static void sh_mobile_i2c_xfer_dma(struct sh_mobile_i2c_data *pd)
548548
dma_addr_t dma_addr;
549549
dma_cookie_t cookie;
550550

551-
if (!chan)
551+
if (IS_ERR(chan))
552552
return;
553553

554554
dma_addr = dma_map_single(chan->device->dev, pd->msg->buf, pd->msg->len, dir);
@@ -747,21 +747,18 @@ static const struct of_device_id sh_mobile_i2c_dt_ids[] = {
747747
};
748748
MODULE_DEVICE_TABLE(of, sh_mobile_i2c_dt_ids);
749749

750-
static int sh_mobile_i2c_request_dma_chan(struct device *dev, enum dma_transfer_direction dir,
751-
dma_addr_t port_addr, struct dma_chan **chan_ptr)
750+
static struct dma_chan *sh_mobile_i2c_request_dma_chan(struct device *dev,
751+
enum dma_transfer_direction dir, dma_addr_t port_addr)
752752
{
753753
struct dma_chan *chan;
754754
struct dma_slave_config cfg;
755755
char *chan_name = dir == DMA_MEM_TO_DEV ? "tx" : "rx";
756756
int ret;
757757

758-
*chan_ptr = NULL;
759-
760758
chan = dma_request_slave_channel_reason(dev, chan_name);
761759
if (IS_ERR(chan)) {
762-
ret = PTR_ERR(chan);
763760
dev_dbg(dev, "request_channel failed for %s (%d)\n", chan_name, ret);
764-
return ret;
761+
return chan;
765762
}
766763

767764
memset(&cfg, 0, sizeof(cfg));
@@ -778,25 +775,23 @@ static int sh_mobile_i2c_request_dma_chan(struct device *dev, enum dma_transfer_
778775
if (ret) {
779776
dev_dbg(dev, "slave_config failed for %s (%d)\n", chan_name, ret);
780777
dma_release_channel(chan);
781-
return ret;
778+
return ERR_PTR(ret);
782779
}
783780

784-
*chan_ptr = chan;
785-
786781
dev_dbg(dev, "got DMA channel for %s\n", chan_name);
787-
return 0;
782+
return chan;
788783
}
789784

790785
static void sh_mobile_i2c_release_dma(struct sh_mobile_i2c_data *pd)
791786
{
792-
if (pd->dma_tx) {
787+
if (!IS_ERR(pd->dma_tx)) {
793788
dma_release_channel(pd->dma_tx);
794-
pd->dma_tx = NULL;
789+
pd->dma_tx = ERR_PTR(-EPROBE_DEFER);
795790
}
796791

797-
if (pd->dma_rx) {
792+
if (!IS_ERR(pd->dma_rx)) {
798793
dma_release_channel(pd->dma_rx);
799-
pd->dma_rx = NULL;
794+
pd->dma_rx = ERR_PTR(-EPROBE_DEFER);
800795
}
801796
}
802797

@@ -889,13 +884,15 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
889884
/* Init DMA */
890885
sg_init_table(&pd->sg, 1);
891886
pd->dma_direction = DMA_NONE;
892-
ret = sh_mobile_i2c_request_dma_chan(pd->dev, DMA_DEV_TO_MEM,
893-
res->start + ICDR, &pd->dma_rx);
887+
pd->dma_rx = sh_mobile_i2c_request_dma_chan(pd->dev, DMA_DEV_TO_MEM,
888+
res->start + ICDR);
889+
ret = PTR_ERR(pd->dma_rx);
894890
if (ret == -EPROBE_DEFER)
895891
return ret;
896892

897-
ret = sh_mobile_i2c_request_dma_chan(pd->dev, DMA_MEM_TO_DEV,
898-
res->start + ICDR, &pd->dma_tx);
893+
pd->dma_tx = sh_mobile_i2c_request_dma_chan(pd->dev, DMA_MEM_TO_DEV,
894+
res->start + ICDR);
895+
ret = PTR_ERR(pd->dma_tx);
899896
if (ret == -EPROBE_DEFER) {
900897
sh_mobile_i2c_release_dma(pd);
901898
return ret;

0 commit comments

Comments
 (0)