Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

i2c: i2c-mxs: move to use generic DMA helper

With the generic DMA device tree helper supported by mxs-dma driver,
client devices only need to call dma_request_slave_channel() for
requesting a DMA channel from dmaengine.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Wolfram Sang <wsa@the-dreams.de>

Shawn Guo e5aba13d 26aafa77

+11 -41
+8 -4
Documentation/devicetree/bindings/i2c/i2c-mxs.txt
··· 3 3 Required properties: 4 4 - compatible: Should be "fsl,<chip>-i2c" 5 5 - reg: Should contain registers location and length 6 - - interrupts: Should contain ERROR and DMA interrupts 6 + - interrupts: Should contain ERROR interrupt number 7 7 - clock-frequency: Desired I2C bus clock frequency in Hz. 8 8 Only 100000Hz and 400000Hz modes are supported. 9 - - fsl,i2c-dma-channel: APBX DMA channel for the I2C 9 + - dmas: DMA specifier, consisting of a phandle to DMA controller node 10 + and I2C DMA channel ID. 11 + Refer to dma.txt and fsl-mxs-dma.txt for details. 12 + - dma-names: Must be "rx-tx". 10 13 11 14 Examples: 12 15 ··· 18 15 #size-cells = <0>; 19 16 compatible = "fsl,imx28-i2c"; 20 17 reg = <0x80058000 2000>; 21 - interrupts = <111 68>; 18 + interrupts = <111>; 22 19 clock-frequency = <100000>; 23 - fsl,i2c-dma-channel = <6>; 20 + dmas = <&dma_apbx 6>; 21 + dma-names = "rx-tx"; 24 22 };
+3 -37
drivers/i2c/busses/i2c-mxs.c
··· 31 31 #include <linux/of_i2c.h> 32 32 #include <linux/dma-mapping.h> 33 33 #include <linux/dmaengine.h> 34 - #include <linux/fsl/mxs-dma.h> 35 34 36 35 #define DRIVER_NAME "mxs-i2c" 37 36 ··· 112 113 uint32_t timing1; 113 114 114 115 /* DMA support components */ 115 - int dma_channel; 116 116 struct dma_chan *dmach; 117 - struct mxs_dma_data dma_data; 118 117 uint32_t pio_data[2]; 119 118 uint32_t addr_data; 120 119 struct scatterlist sg_io[2]; ··· 515 518 .functionality = mxs_i2c_func, 516 519 }; 517 520 518 - static bool mxs_i2c_dma_filter(struct dma_chan *chan, void *param) 519 - { 520 - struct mxs_i2c_dev *i2c = param; 521 - 522 - if (!mxs_dma_is_apbx(chan)) 523 - return false; 524 - 525 - if (chan->chan_id != i2c->dma_channel) 526 - return false; 527 - 528 - chan->private = &i2c->dma_data; 529 - 530 - return true; 531 - } 532 - 533 521 static void mxs_i2c_derive_timing(struct mxs_i2c_dev *i2c, int speed) 534 522 { 535 523 /* The I2C block clock run at 24MHz */ ··· 559 577 struct device_node *node = dev->of_node; 560 578 int ret; 561 579 562 - /* 563 - * TODO: This is a temporary solution and should be changed 564 - * to use generic DMA binding later when the helpers get in. 565 - */ 566 - ret = of_property_read_u32(node, "fsl,i2c-dma-channel", 567 - &i2c->dma_channel); 568 - if (ret) { 569 - dev_err(dev, "Failed to get DMA channel!\n"); 570 - return -ENODEV; 571 - } 572 - 573 580 ret = of_property_read_u32(node, "clock-frequency", &speed); 574 581 if (ret) { 575 582 dev_warn(dev, "No I2C speed selected, using 100kHz\n"); ··· 578 607 struct pinctrl *pinctrl; 579 608 struct resource *res; 580 609 resource_size_t res_size; 581 - int err, irq, dmairq; 582 - dma_cap_mask_t mask; 610 + int err, irq; 583 611 584 612 pinctrl = devm_pinctrl_get_select_default(dev); 585 613 if (IS_ERR(pinctrl)) ··· 590 620 591 621 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 592 622 irq = platform_get_irq(pdev, 0); 593 - dmairq = platform_get_irq(pdev, 1); 594 623 595 - if (!res || irq < 0 || dmairq < 0) 624 + if (!res || irq < 0) 596 625 return -ENOENT; 597 626 598 627 res_size = resource_size(res); ··· 617 648 } 618 649 619 650 /* Setup the DMA */ 620 - dma_cap_zero(mask); 621 - dma_cap_set(DMA_SLAVE, mask); 622 - i2c->dma_data.chan_irq = dmairq; 623 - i2c->dmach = dma_request_channel(mask, mxs_i2c_dma_filter, i2c); 651 + i2c->dmach = dma_request_slave_channel(dev, "rx-tx"); 624 652 if (!i2c->dmach) { 625 653 dev_err(dev, "Failed to request dma\n"); 626 654 return -ENODEV;