diff options
author | Shawn Guo <shawn.guo@linaro.org> | 2013-02-25 22:20:22 -0500 |
---|---|---|
committer | Shawn Guo <shawn.guo@linaro.org> | 2013-04-04 09:22:45 -0400 |
commit | e5aba13da0cc598a5573ea059717949fbd7536ad (patch) | |
tree | 6c47089e7225edb4024a8889b8ee6207f6eb6556 | |
parent | 26aafa77df61c4190eae80646211ee6f07c88eaf (diff) |
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>
-rw-r--r-- | Documentation/devicetree/bindings/i2c/i2c-mxs.txt | 12 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-mxs.c | 40 |
2 files changed, 11 insertions, 41 deletions
diff --git a/Documentation/devicetree/bindings/i2c/i2c-mxs.txt b/Documentation/devicetree/bindings/i2c/i2c-mxs.txt index 7a3fe9e5f4cb..4e1c8ac01eba 100644 --- a/Documentation/devicetree/bindings/i2c/i2c-mxs.txt +++ b/Documentation/devicetree/bindings/i2c/i2c-mxs.txt | |||
@@ -3,10 +3,13 @@ | |||
3 | Required properties: | 3 | Required properties: |
4 | - compatible: Should be "fsl,<chip>-i2c" | 4 | - compatible: Should be "fsl,<chip>-i2c" |
5 | - reg: Should contain registers location and length | 5 | - reg: Should contain registers location and length |
6 | - interrupts: Should contain ERROR and DMA interrupts | 6 | - interrupts: Should contain ERROR interrupt number |
7 | - clock-frequency: Desired I2C bus clock frequency in Hz. | 7 | - clock-frequency: Desired I2C bus clock frequency in Hz. |
8 | Only 100000Hz and 400000Hz modes are supported. | 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 | Examples: | 14 | Examples: |
12 | 15 | ||
@@ -15,7 +18,8 @@ i2c0: i2c@80058000 { | |||
15 | #size-cells = <0>; | 18 | #size-cells = <0>; |
16 | compatible = "fsl,imx28-i2c"; | 19 | compatible = "fsl,imx28-i2c"; |
17 | reg = <0x80058000 2000>; | 20 | reg = <0x80058000 2000>; |
18 | interrupts = <111 68>; | 21 | interrupts = <111>; |
19 | clock-frequency = <100000>; | 22 | clock-frequency = <100000>; |
20 | fsl,i2c-dma-channel = <6>; | 23 | dmas = <&dma_apbx 6>; |
24 | dma-names = "rx-tx"; | ||
21 | }; | 25 | }; |
diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c index 120f24646696..d1ba6b403b84 100644 --- a/drivers/i2c/busses/i2c-mxs.c +++ b/drivers/i2c/busses/i2c-mxs.c | |||
@@ -31,7 +31,6 @@ | |||
31 | #include <linux/of_i2c.h> | 31 | #include <linux/of_i2c.h> |
32 | #include <linux/dma-mapping.h> | 32 | #include <linux/dma-mapping.h> |
33 | #include <linux/dmaengine.h> | 33 | #include <linux/dmaengine.h> |
34 | #include <linux/fsl/mxs-dma.h> | ||
35 | 34 | ||
36 | #define DRIVER_NAME "mxs-i2c" | 35 | #define DRIVER_NAME "mxs-i2c" |
37 | 36 | ||
@@ -113,9 +112,7 @@ struct mxs_i2c_dev { | |||
113 | uint32_t timing1; | 112 | uint32_t timing1; |
114 | 113 | ||
115 | /* DMA support components */ | 114 | /* DMA support components */ |
116 | int dma_channel; | ||
117 | struct dma_chan *dmach; | 115 | struct dma_chan *dmach; |
118 | struct mxs_dma_data dma_data; | ||
119 | uint32_t pio_data[2]; | 116 | uint32_t pio_data[2]; |
120 | uint32_t addr_data; | 117 | uint32_t addr_data; |
121 | struct scatterlist sg_io[2]; | 118 | struct scatterlist sg_io[2]; |
@@ -518,21 +515,6 @@ static const struct i2c_algorithm mxs_i2c_algo = { | |||
518 | .functionality = mxs_i2c_func, | 515 | .functionality = mxs_i2c_func, |
519 | }; | 516 | }; |
520 | 517 | ||
521 | static bool mxs_i2c_dma_filter(struct dma_chan *chan, void *param) | ||
522 | { | ||
523 | struct mxs_i2c_dev *i2c = param; | ||
524 | |||
525 | if (!mxs_dma_is_apbx(chan)) | ||
526 | return false; | ||
527 | |||
528 | if (chan->chan_id != i2c->dma_channel) | ||
529 | return false; | ||
530 | |||
531 | chan->private = &i2c->dma_data; | ||
532 | |||
533 | return true; | ||
534 | } | ||
535 | |||
536 | static void mxs_i2c_derive_timing(struct mxs_i2c_dev *i2c, int speed) | 518 | static void mxs_i2c_derive_timing(struct mxs_i2c_dev *i2c, int speed) |
537 | { | 519 | { |
538 | /* The I2C block clock run at 24MHz */ | 520 | /* The I2C block clock run at 24MHz */ |
@@ -577,17 +559,6 @@ static int mxs_i2c_get_ofdata(struct mxs_i2c_dev *i2c) | |||
577 | struct device_node *node = dev->of_node; | 559 | struct device_node *node = dev->of_node; |
578 | int ret; | 560 | int ret; |
579 | 561 | ||
580 | /* | ||
581 | * TODO: This is a temporary solution and should be changed | ||
582 | * to use generic DMA binding later when the helpers get in. | ||
583 | */ | ||
584 | ret = of_property_read_u32(node, "fsl,i2c-dma-channel", | ||
585 | &i2c->dma_channel); | ||
586 | if (ret) { | ||
587 | dev_err(dev, "Failed to get DMA channel!\n"); | ||
588 | return -ENODEV; | ||
589 | } | ||
590 | |||
591 | ret = of_property_read_u32(node, "clock-frequency", &speed); | 562 | ret = of_property_read_u32(node, "clock-frequency", &speed); |
592 | if (ret) { | 563 | if (ret) { |
593 | dev_warn(dev, "No I2C speed selected, using 100kHz\n"); | 564 | dev_warn(dev, "No I2C speed selected, using 100kHz\n"); |
@@ -607,8 +578,7 @@ static int mxs_i2c_probe(struct platform_device *pdev) | |||
607 | struct pinctrl *pinctrl; | 578 | struct pinctrl *pinctrl; |
608 | struct resource *res; | 579 | struct resource *res; |
609 | resource_size_t res_size; | 580 | resource_size_t res_size; |
610 | int err, irq, dmairq; | 581 | int err, irq; |
611 | dma_cap_mask_t mask; | ||
612 | 582 | ||
613 | pinctrl = devm_pinctrl_get_select_default(dev); | 583 | pinctrl = devm_pinctrl_get_select_default(dev); |
614 | if (IS_ERR(pinctrl)) | 584 | if (IS_ERR(pinctrl)) |
@@ -620,9 +590,8 @@ static int mxs_i2c_probe(struct platform_device *pdev) | |||
620 | 590 | ||
621 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 591 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
622 | irq = platform_get_irq(pdev, 0); | 592 | irq = platform_get_irq(pdev, 0); |
623 | dmairq = platform_get_irq(pdev, 1); | ||
624 | 593 | ||
625 | if (!res || irq < 0 || dmairq < 0) | 594 | if (!res || irq < 0) |
626 | return -ENOENT; | 595 | return -ENOENT; |
627 | 596 | ||
628 | res_size = resource_size(res); | 597 | res_size = resource_size(res); |
@@ -648,10 +617,7 @@ static int mxs_i2c_probe(struct platform_device *pdev) | |||
648 | } | 617 | } |
649 | 618 | ||
650 | /* Setup the DMA */ | 619 | /* Setup the DMA */ |
651 | dma_cap_zero(mask); | 620 | i2c->dmach = dma_request_slave_channel(dev, "rx-tx"); |
652 | dma_cap_set(DMA_SLAVE, mask); | ||
653 | i2c->dma_data.chan_irq = dmairq; | ||
654 | i2c->dmach = dma_request_channel(mask, mxs_i2c_dma_filter, i2c); | ||
655 | if (!i2c->dmach) { | 621 | if (!i2c->dmach) { |
656 | dev_err(dev, "Failed to request dma\n"); | 622 | dev_err(dev, "Failed to request dma\n"); |
657 | return -ENODEV; | 623 | return -ENODEV; |