MXS: Set I2C timing registers for mxs-i2c
PATCH 1/2 MXS: Set I2C timing registers for mxs-i2c
This patch configures the I2C bus timing registers according to information passed via DT. Currently, 100kHz and 400kHz modes are supported.
The TIMING2 register value is wrong in the documentation for i.MX28! This was found and fixed by:
Shawn Guo <[email protected]>
--- Documentation/devicetree/bindings/i2c/i2c-mxs.txt | 1 + arch/arm/boot/dts/imx28.dtsi | 2 + drivers/i2c/busses/i2c-mxs.c | 56 +++++++++++++++++++++ 3 files changed, 59 insertions(+)
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +1 -0
@@ -4,6 +4,7 @@ Required properties: - compatible: Should be "fsl,<chip>-i2c" - reg: Should contain registers location and length - interrupts: Should contain ERROR and DMA interrupts +- clock-frequency: desired I2C bus clock frequency in Hz. Examples:
arch/arm/boot/dts/imx28.dtsi +2 -0
@@ -419,6 +419,7 @@ compatible = "fsl,imx28-i2c"; reg = <0x80058000 2000>; interrupts = <111 68>; + clock-frequency = <400000>; status = "disabled"; };
@@ -428,6 +429,7 @@ compatible = "fsl,imx28-i2c"; reg = <0x8005a000 2000>; interrupts = <110 69>; + clock-frequency = <400000>; status = "disabled"; };
drivers/i2c/busses/i2c-mxs.c +56 -0
91 lines not on this page · raw message
Signature · 1 line
1.7.10
PATCH 2/2 MXS: Implement DMA support into mxs-i2c
This patch implements DMA support into mxs-i2c. DMA transfers are now enabled via DT. The DMA operation is enabled by default.
--- Documentation/devicetree/bindings/i2c/i2c-mxs.txt | 4 + arch/arm/boot/dts/imx28.dtsi | 2 + drivers/i2c/busses/i2c-mxs.c | 267 +++++++++++++++++++-- 3 files changed, 251 insertions(+), 22 deletions(-)
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +4 -0
@@ -5,6 +5,10 @@ Required properties: - reg: Should contain registers location and length - interrupts: Should contain ERROR and DMA interrupts - clock-frequency: desired I2C bus clock frequency in Hz. +- fsl,i2c-dma-channel: APBX DMA channel for the I2C + +Optional properties: +- fsl,use-pio: Use PIO transfers instead of DMA, useful for debug Examples:
arch/arm/boot/dts/imx28.dtsi +2 -0
@@ -420,6 +420,7 @@ reg = <0x80058000 2000>; interrupts = <111 68>; clock-frequency = <400000>; + fsl,i2c-dma-channel = <6>; status = "disabled"; };
@@ -430,6 +431,7 @@ reg = <0x8005a000 2000>; interrupts = <110 69>; clock-frequency = <400000>; + fsl,i2c-dma-channel = <7>; status = "disabled"; };
drivers/i2c/busses/i2c-mxs.c +245 -22
372 lines not on this page · raw message
Signature · 1 line
1.7.10
PATCH 2/2 MXS: Implement DMA support into mxs-i2c
Quoted 26 lines · Marek Vasut
This patch implements DMA support into mxs-i2c. DMA transfers are now enabled via DT. The DMA operation is enabled by default.
Signed-off-by Marek Vasut <[email protected]>Cc Detlev Zundel <[email protected]>CC Dong Aisheng <[email protected]>CC Fabio Estevam <[email protected]>Cc Linux ARM kernel <[email protected]>Cc linux-i2c at vger.kernel.orgCC Sascha Hauer <[email protected]>CC Shawn Guo <[email protected]>Cc Stefano Babic <[email protected]>CC Uwe Kleine-K?nig <[email protected]>Cc Wolfgang Denk <[email protected]>Cc Wolfram Sang <[email protected]>--- Documentation/devicetree/bindings/i2c/i2c-mxs.txt | 4 + arch/arm/boot/dts/imx28.dtsi | 2 + drivers/i2c/busses/i2c-mxs.c | 267 +++++++++++++++++++-- 3 files changed, 251 insertions(+), 22 deletions(-)Documentation/devicetree/bindings/i2c/i2c-mxs.txt +0
-0
Documentation/devicetree/bindings/i2c/i2c-mxs.txt Required properties: · line 8
Quoted 4 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +1
-0@@ -5,6 +5,10 @@ Required properties: - reg: Should contain registers location and length - interrupts: Should contain ERROR and DMA interrupts - clock-frequency: desired I2C bus clock frequency in Hz. +- fsl,i2c-dma-channel: APBX DMA channel for the I2C
Shoundn't this be optional?
Quoted 9 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +9
-0+ /* + * The last descriptor must have this callback, + * to finish the DMA transaction. + */ + desc->callback = mxs_i2c_dma_irq_callback; + desc->callback_param = i2c; + + /* Start the transfer. */ + dmaengine_submit(desc);
Documentation/devicetree/bindings/i2c/i2c-mxs.txt Required properties:
Quoted 10 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +10
-0+ dma_async_issue_pending(i2c->dmach); + return 0; + +/* Read failpath. */ +read_init_dma_fail: + dma_unmap_sg(i2c->dev, &i2c->sg_io[1], 1, DMA_FROM_DEVICE); +select_init_dma_fail: + dma_unmap_sg(i2c->dev, &i2c->sg_io[0], 1, DMA_TO_DEVICE); +select_init_pio_fail: + return 1;
look strange why return 1;
Documentation/devicetree/bindings/i2c/i2c-mxs.txt
Quoted 2 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +2
-0+ +
One more unnecessary line?
Quoted 7 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +7
-0+/* Write failpath. */ +write_init_dma_fail: + dma_unmap_sg(i2c->dev, i2c->sg_io, 2, DMA_TO_DEVICE); +write_init_pio_fail: + return 1; +} +
..
Documentation/devicetree/bindings/i2c/i2c-mxs.txt static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, · line 462
Quoted 5 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +1
-0@@ -291,6 +459,7 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, timeout: dev_dbg(i2c->dev, "Timeout!\n"); + mxs_i2c_dma_finish(i2c);
Shared with pio?
Documentation/devicetree/bindings/i2c/i2c-mxs.txt static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, · line 465
Quoted 3 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +0
-0mxs_i2c_reset(i2c); return -ETIMEDOUT; }
Regards
Dong Aisheng
PATCH 2/2 MXS: Implement DMA support into mxs-i2c
Dear Dong Aisheng,
Quoted 30 lines · Marek Vasut
Quoted 29 lines
This patch implements DMA support into mxs-i2c. DMA transfers are now enabled via DT. The DMA operation is enabled by default.
Signed-off-by Marek Vasut <[email protected]>Cc Detlev Zundel <[email protected]>CC Dong Aisheng <[email protected]>CC Fabio Estevam <[email protected]>Cc Linux ARM kernel <[email protected]>Cc linux-i2c at vger.kernel.orgCC Sascha Hauer <[email protected]>CC Shawn Guo <[email protected]>Cc Stefano Babic <[email protected]>CC Uwe Kleine-K?nig <[email protected]>Cc Wolfgang Denk <[email protected]>Cc Wolfram Sang <[email protected]>---
Documentation/devicetree/bindings/i2c/i2c-mxs.txt | 4 + arch/arm/boot/dts/imx28.dtsi | 2 + drivers/i2c/busses/i2c-mxs.c | 267+++++++++++++++++++-- 3 files changed, 251 insertions(+), 22 deletions(-)
(quoted diff) +0
-0
b/Documentation/devicetree/bindings/i2c/i2c-mxs.txtindex d2bf750..9497ee0 100644Documentation/devicetree/bindings/i2c/i2c-mxs.txt +0
-0
Quoted 8 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt Required properties: · line 9
Quoted 6 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +1
-0@@ -5,6 +5,10 @@ Required properties: - reg: Should contain registers location and length - interrupts: Should contain ERROR and DMA interrupts - clock-frequency: desired I2C bus clock frequency in Hz. +- fsl,i2c-dma-channel: APBX DMA channel for the I2CShoundn't this be optional?
DMA channel? No, why?
Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +13
-0+ /* + * The last descriptor must have this callback, + * to finish the DMA transaction. + */ + desc->callback = mxs_i2c_dma_irq_callback; + desc->callback_param = i2c; + + /* Start the transfer. */ + dmaengine_submit(desc); + dma_async_issue_pending(i2c->dmach); + return 0; + +/* Read failpath. */
Quoted 8 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt
Quoted 6 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +6
-0+read_init_dma_fail: + dma_unmap_sg(i2c->dev, &i2c->sg_io[1], 1, DMA_FROM_DEVICE); +select_init_dma_fail: + dma_unmap_sg(i2c->dev, &i2c->sg_io[0], 1, DMA_TO_DEVICE); +select_init_pio_fail: + return 1;look strange why return 1;
Because it failed. -Esomething might be better ?
Quoted 18 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt
Quoted 2 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +2
-0+ +One more unnecessary line?
Quoted 7 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +7
-0+/* Write failpath. */ +write_init_dma_fail: + dma_unmap_sg(i2c->dev, i2c->sg_io, 2, DMA_TO_DEVICE); +write_init_pio_fail: + return 1; +} +..
Quoted 3 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +0
-0@@ -291,6 +459,7 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg,
Quoted 6 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, · line 464
Quoted 4 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +1
-0timeout: dev_dbg(i2c->dev, "Timeout!\n"); + mxs_i2c_dma_finish(i2c);Shared with pio?
Doesn't dma_unmap_sg() call check if the buffer is there or not? Therefore it shouldn't have any effect on PIO ops. But it can be indeed if-ed.
Quoted 7 lines
Quoted 4 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +0
-0mxs_i2c_reset(i2c);return
-ETIMEDOUT;}
Regards
Dong Aisheng
Best regards,
Marek Vasut
PATCH 2/2 MXS: Implement DMA support into mxs-i2c
Quoted 37 lines · Marek Vasut
Dear Dong Aisheng,
Quoted 35 lines · Marek Vasut
Quoted 34 lines
This patch implements DMA support into mxs-i2c. DMA transfers are now enabled via DT. The DMA operation is enabled by default.
Signed-off-by Marek Vasut <[email protected]>Cc Detlev Zundel <[email protected]>CC Dong Aisheng <[email protected]>CC Fabio Estevam <[email protected]>Cc Linux ARM kernel <[email protected]>Cc linux-i2c at vger.kernel.orgCC Sascha Hauer <[email protected]>CC Shawn Guo <[email protected]>Cc Stefano Babic <[email protected]>CC Uwe Kleine-K?nig <[email protected]>Cc Wolfgang Denk <[email protected]>Cc Wolfram Sang <[email protected]>---
Documentation/devicetree/bindings/i2c/i2c-mxs.txt | 4 + arch/arm/boot/dts/imx28.dtsi | 2 + drivers/i2c/busses/i2c-mxs.c | 267+++++++++++++++++++-- 3 files changed, 251 insertions(+), 22 deletions(-)
(quoted diff) +0
-0
b/Documentation/devicetree/bindings/i2c/i2c-mxs.txtindex d2bf750..9497ee0 100644Documentation/devicetree/bindings/i2c/i2c-mxs.txt +0
-0@@ -5,6 +5,10 @@ Required properties: - reg: Should contain registers location and length - interrupts: Should contain ERROR and DMA interrupts - clock-frequency: desired I2C bus clock frequency in Hz.
Quoted 6 lines
Quoted 3 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt Required properties: · line 8
Quoted 1 line
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +1
-0+- fsl,i2c-dma-channel: APBX DMA channel for the I2CShoundn't this be optional?
DMA channel? No, why?
User can use pio mode, so actually it's optional.
Is it reasonable?
Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +13
-0+ /* + * The last descriptor must have this callback, + * to finish the DMA transaction. + */ + desc->callback = mxs_i2c_dma_irq_callback; + desc->callback_param = i2c; + + /* Start the transfer. */ + dmaengine_submit(desc); + dma_async_issue_pending(i2c->dmach); + return 0; + +/* Read failpath. */Quoted 8 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt
Quoted 6 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +6
-0+read_init_dma_fail: + dma_unmap_sg(i2c->dev, &i2c->sg_io[1], 1, DMA_FROM_DEVICE); +select_init_dma_fail: + dma_unmap_sg(i2c->dev, &i2c->sg_io[0], 1, DMA_TO_DEVICE); +select_init_pio_fail: + return 1;look strange why return 1;
Quoted 2 lines
Because it failed. -Esomething might be better ?
i think yes.
Regards
Dong Aisheng
PATCH 2/2 MXS: Implement DMA support into mxs-i2c
Dear Dong Aisheng,
Quoted 38 lines · Marek Vasut
Quoted 37 lines
Dear Dong Aisheng,
Quoted 35 lines · Marek Vasut
Quoted 34 lines
This patch implements DMA support into mxs-i2c. DMA transfers are now enabled via DT. The DMA operation is enabled by default.
Signed-off-by Marek Vasut <[email protected]>Cc Detlev Zundel <[email protected]>CC Dong Aisheng <[email protected]>CC Fabio Estevam <[email protected]>Cc Linux ARM kernel <[email protected]>Cc linux-i2c at vger.kernel.orgCC Sascha Hauer <[email protected]>CC Shawn Guo <[email protected]>Cc Stefano Babic <[email protected]>CC Uwe Kleine-K?nig <[email protected]>Cc Wolfgang Denk <[email protected]>Cc Wolfram Sang <[email protected]>---
Documentation/devicetree/bindings/i2c/i2c-mxs.txt | 4 + arch/arm/boot/dts/imx28.dtsi | 2 + drivers/i2c/busses/i2c-mxs.c | 267+++++++++++++++++++-- 3 files changed, 251 insertions(+), 22 deletions(-)
(quoted diff) +0
-0
b/Documentation/devicetree/bindings/i2c/i2c-mxs.txtindex d2bf750..9497ee0 100644Documentation/devicetree/bindings/i2c/i2c-mxs.txt +0
-0@@ -5,6 +5,10 @@ Required properties: - reg: Should contain registers location and length - interrupts: Should contain ERROR and DMA interrupts - clock-frequency: desired I2C bus clock frequency in Hz.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt Required properties: · line 8
Quoted 1 line
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +1
-0+- fsl,i2c-dma-channel: APBX DMA channel for the I2CShoundn't this be optional?
DMA channel? No, why?
User can use pio mode, so actually it's optional.
Is it reasonable?
PIO mode is something that should not be used unless it's to be used for debugging purposes. The ultimate goal then is to use PIO for small transfers and DMA for large transfers. But that's not implemented yet and DMA is default.
Quoted 22 lines
Quoted 22 lines
Quoted 21 lines
Quoted 9 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +9
-0+ /* + * The last descriptor must have this callback, + * to finish the DMA transaction. + */ + desc->callback = mxs_i2c_dma_irq_callback; + desc->callback_param = i2c; + + /* Start the transfer. */ + dmaengine_submit(desc);Documentation/devicetree/bindings/i2c/i2c-mxs.txt Required properties:
Quoted 10 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +10
-0+ dma_async_issue_pending(i2c->dmach); + return 0; + +/* Read failpath. */ +read_init_dma_fail: + dma_unmap_sg(i2c->dev, &i2c->sg_io[1], 1, DMA_FROM_DEVICE); +select_init_dma_fail: + dma_unmap_sg(i2c->dev, &i2c->sg_io[0], 1, DMA_TO_DEVICE); +select_init_pio_fail: + return 1;look strange why return 1;
Quoted 3 lines
Quoted 1 line
Because it failed. -Esomething might be better ?
i think yes.
And -Ewhat do you suggest ? :)
Quoted 2 lines
Regards
Dong Aisheng
Best regards,
Marek Vasut
PATCH 2/2 MXS: Implement DMA support into mxs-i2c
Quoted 44 lines · Marek Vasut
Dear Dong Aisheng,
Quoted 42 lines · Marek Vasut
Quoted 41 lines
Dear Dong Aisheng,
Quoted 38 lines · Marek Vasut
Quoted 30 lines
This patch implements DMA support into mxs-i2c. DMA transfers are now enabled via DT. The DMA operation is enabled by default.
Signed-off-by Marek Vasut <[email protected]>Cc Detlev Zundel <[email protected]>CC Dong Aisheng <[email protected]>CC Fabio Estevam <[email protected]>Cc Linux ARM kernel <[email protected]>Cc linux-i2c at vger.kernel.orgCC Sascha Hauer <[email protected]>CC Shawn Guo <[email protected]>Cc Stefano Babic <[email protected]>CC Uwe Kleine-K?nig <[email protected]>Cc Wolfgang Denk <[email protected]>Cc Wolfram Sang <[email protected]>---
Documentation/devicetree/bindings/i2c/i2c-mxs.txt | 4 + arch/arm/boot/dts/imx28.dtsi | 2 + drivers/i2c/busses/i2c-mxs.c | 267+++++++++++++++++++-- 3 files changed, 251 insertions(+), 22 deletions(-)
(quoted diff) +0
-0
b/Documentation/devicetree/bindings/i2c/i2c-mxs.txtindex d2bf750..9497ee0 100644Documentation/devicetree/bindings/i2c/i2c-mxs.txt Required properties: · line 9
Quoted 5 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +1
-0@@ -5,6 +5,10 @@ Required properties: - reg: Should contain registers location and length - interrupts: Should contain ERROR and DMA interrupts - clock-frequency: desired I2C bus clock frequency in Hz. +- fsl,i2c-dma-channel: APBX DMA channel for the I2CShoundn't this be optional?
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
DMA channel? No, why?
User can use pio mode, so actually it's optional.
Is it reasonable?PIO mode is something that should not be used unless it's to be used for debugging purposes. The ultimate goal then is to use PIO for small transfers and DMA for large transfers. But that's not implemented yet and DMA is default.
Because DMA channel is not the minimum required properties to make HW work, so i had that question.
Anyway, i think it's not a big issue.
If you really like it to be mandatory required for default dma mode, i'm ok with it.
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 21 lines
Quoted 9 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +9
-0+ /* + * The last descriptor must have this callback, + * to finish the DMA transaction. + */ + desc->callback = mxs_i2c_dma_irq_callback; + desc->callback_param = i2c; + + /* Start the transfer. */ + dmaengine_submit(desc);Documentation/devicetree/bindings/i2c/i2c-mxs.txt Required properties:
Quoted 10 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +10
-0+ dma_async_issue_pending(i2c->dmach); + return 0; + +/* Read failpath. */ +read_init_dma_fail: + dma_unmap_sg(i2c->dev, &i2c->sg_io[1], 1, DMA_FROM_DEVICE); +select_init_dma_fail: + dma_unmap_sg(i2c->dev, &i2c->sg_io[0], 1, DMA_TO_DEVICE); +select_init_pio_fail: + return 1;look strange why return 1;
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Because it failed. -Esomething might be better ?
i think yes.
And -Ewhat do you suggest ? :)
I checked mxs-dma driver, it seems both EBUSY or EINVAL are ok. You can choose one. :)
Regards
Dong Aisheng
PATCH 1/2 MXS: Set I2C timing registers for mxs-i2c
In reply to Marek VasutHi Marek,
Quoted 31 lines · Marek Vasut
This patch configures the I2C bus timing registers according to information passed via DT. Currently, 100kHz and 400kHz modes are supported.
The TIMING2 register value is wrong in the documentation for i.MX28! This was found and fixed by:
Shawn Guo <[email protected]>Signed-off-by Marek Vasut <[email protected]>Cc Detlev Zundel <[email protected]>CC Dong Aisheng <[email protected]>CC Fabio Estevam <[email protected]>Cc Linux ARM kernel <[email protected]>Cc linux-i2c at vger.kernel.orgCC Sascha Hauer <[email protected]>CC Shawn Guo <[email protected]>Cc Stefano Babic <[email protected]>CC Uwe Kleine-K?nig <[email protected]>Cc Wolfgang Denk <[email protected]>Cc Wolfram Sang <[email protected]>--- Documentation/devicetree/bindings/i2c/i2c-mxs.txt | 1 + arch/arm/boot/dts/imx28.dtsi | 2 + drivers/i2c/busses/i2c-mxs.c | 56 +++++++++++++++++++++ 3 files changed, 59 insertions(+)Documentation/devicetree/bindings/i2c/i2c-mxs.txt +0
-0
Documentation/devicetree/bindings/i2c/i2c-mxs.txt Required properties: · line 7
Quoted 4 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +1
-0@@ -4,6 +4,7 @@ Required properties: - compatible: Should be "fsl,<chip>-i2c" - reg: Should contain registers location and length - interrupts: Should contain ERROR and DMA interrupts +- clock-frequency: desired I2C bus clock frequency in Hz.
Is this required properties?
If yes, it may be good to also update examples.
Quoted 39 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +0
-0Examples:arch/arm/boot/dts/imx28.dtsi +2
-0@@ -419,6 +419,7 @@ compatible = "fsl,imx28-i2c"; reg = <0x80058000 2000>; interrupts = <111 68>; + clock-frequency = <400000>; status = "disabled"; };@@ -428,6 +429,7 @@ compatible = "fsl,imx28-i2c"; reg = <0x8005a000 2000>; interrupts = <110 69>; + clock-frequency = <400000>; status = "disabled"; };drivers/i2c/busses/i2c-mxs.c +4
-0@@ -46,6 +46,10 @@#define MXS_I2C_CTRL0_DIRECTION 0x00010000#define MXS_I2C_CTRL0_XFER_COUNT (v) ((v) & 0x0000FFFF) +#define MXS_I2C_TIMING0 (0x10) +#define MXS_I2C_TIMING1 (0x20) +#define MXS_I2C_TIMING2 (0x30) +#define MXS_I2C_CTRL1 (0x40)#define MXS_I2C_CTRL1_SET (0x44)#define MXS_I2C_CTRL1_CLR (0x48)
drivers/i2c/busses/i2c-mxs.c line 110
Quoted 10 lines
drivers/i2c/busses/i2c-mxs.c +7
-0@@ -97,6 +101,25 @@#define MXS_CMD_I2C_READ (MXS_I2C_CTRL0_SEND_NAK_ON_LAST | \ MXS_I2C_CTRL0_MASTER_MODE) +struct mxs_i2c_speed_config { +uint32_t timing0; +uint32_t timing1; +uint32_t timing2; +}; + +/* Timing values for the default 24MHz clock supplied into the i2c block. */
I did not check spec,
is it possible the supplied clock changed?
drivers/i2c/busses/i2c-mxs.c line 111
Quoted 1 line
drivers/i2c/busses/i2c-mxs.c +1
-0+const struct mxs_i2c_speed_config mxs_i2c_95kHz_config = {
Do we need static for it?
drivers/i2c/busses/i2c-mxs.c line 117
Quoted 6 lines
drivers/i2c/busses/i2c-mxs.c +6
-0+ .timing0 = 0x00780030, + .timing1 = 0x00800030, + .timing2 = 0x00300030, +}; + +const struct mxs_i2c_speed_config mxs_i2c_400kHz_config = {
ditto
Quoted 31 lines
drivers/i2c/busses/i2c-mxs.c +12
-0+ .timing0 = 0x000f0007, + .timing1 = 0x001f000f, + .timing2 = 0x00300030, +}; +/** * struct mxs_i2c_dev - per device, private MXS-I2C data * @@ -112,11 +135,17 @@ struct mxs_i2c_dev {struct completion cmd_complete;u32 cmd_err;struct i2c_adapter adapter; +const struct mxs_i2c_speed_config *speed; };static void mxs_i2c_reset (struct mxs_i2c_dev *i2c) {stmp_reset_block (i2c->regs); + +writel (i2c->speed->timing0, i2c->regs +MXS_I2C_TIMING0 ); +writel (i2c->speed->timing1, i2c->regs +MXS_I2C_TIMING1 ); +writel (i2c->speed->timing2, i2c->regs +MXS_I2C_TIMING2 ); +writel (MXS_I2C_IRQ_MASK <<8 , i2c->regs +MXS_I2C_CTRL1_SET );writel (MXS_I2C_QUEUECTRL_PIO_QUEUE_MODE , i2c->regs +MXS_I2C_QUEUECTRL_SET );@@ -319,6 +348,28 @@ static const struct i2c_algorithm mxs_i2c_algo = { .functionality = mxs_i2c_func, }; +static int mxs_i2c_get_ofdata (struct mxs_i2c_dev *i2c)
drivers/i2c/busses/i2c-mxs.c static const struct i2c_algorithm mxs_i2c_algo = { · line 361
Quoted 10 lines
drivers/i2c/busses/i2c-mxs.c +10
-0+{ +uint32_t speed; +struct device *dev = i2c->dev; +struct device_node *node = dev->of_node; +int ret; + +if (!node) +return -EINVAL ; + + i2c->speed = &mxs_i2c_95kHz_config;
Can you explain why here is 95khz rather than 100kh? It seems this is for 100khz below.
Quoted 16 lines
drivers/i2c/busses/i2c-mxs.c +11
-0+ ret =of_property_read_u32 (node,"clock-frequency" , &speed); +if (ret) +dev_warn (dev,"No I2C speed selected, using 100kHz\n" ); +else if (speed ==400000 ) + i2c->speed = &mxs_i2c_400kHz_config; +else if (speed !=100000 ) +dev_warn (dev,"Invalid I2C speed selected, using 100kHz\n" ); + +return 0 ; +} +static int __devinit mxs_i2c_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;@@ -358,6 +409,11 @@ static int __devinit mxs_i2c_probe(struct platform_device *pdev)return err;
drivers/i2c/busses/i2c-mxs.c static int __devinit mxs_i2c_probe(struct platform_device *pdev) · line 419
Quoted 10 lines
drivers/i2c/busses/i2c-mxs.c +5
-0i2c->dev = dev; + + err =mxs_i2c_get_ofdata (i2c); +if (err) +return err; +platform_set_drvdata (pdev, i2c);/* Do reset to enforce correct startup after pinmuxing */
Regards
Dong Aisheng
PATCH 1/2 MXS: Set I2C timing registers for mxs-i2c
Dear Dong Aisheng,
Quoted 42 lines
Hi Marek,
Quoted 39 lines · Marek Vasut
This patch configures the I2C bus timing registers according to information passed via DT. Currently, 100kHz and 400kHz modes are supported.
The TIMING2 register value is wrong in the documentation for
i.MX28! This was found and fixed by:
Shawn Guo <[email protected]>Signed-off-by Marek Vasut <[email protected]>Cc Detlev Zundel <[email protected]>CC Dong Aisheng <[email protected]>CC Fabio Estevam <[email protected]>Cc Linux ARM kernel <[email protected]>Cc linux-i2c at vger.kernel.orgCC Sascha Hauer <[email protected]>CC Shawn Guo <[email protected]>Cc Stefano Babic <[email protected]>CC Uwe Kleine-K?nig <[email protected]>Cc Wolfgang Denk <[email protected]>Cc Wolfram Sang <[email protected]>---
Documentation/devicetree/bindings/i2c/i2c-mxs.txt | 1 + arch/arm/boot/dts/imx28.dtsi | 2 + drivers/i2c/busses/i2c-mxs.c | 56+++++++++++++++++++++ 3 files changed, 59 insertions(+)
(quoted diff) +0
-0
b/Documentation/devicetree/bindings/i2c/i2c-mxs.txtindex 1bfc02d..d2bf750 100644Documentation/devicetree/bindings/i2c/i2c-mxs.txt +0
-0@@ -4,6 +4,7 @@ Required properties: - compatible: Should be "fsl,<chip>-i2c" - reg: Should contain registers location and length - interrupts: Should contain ERROR and DMA interrupts
Quoted 4 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt Required properties: · line 7
Quoted 1 line
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +1
-0+- clock-frequency: desired I2C bus clock frequency in Hz.Is this required properties?
If yes, it may be good to also update examples.
Good point
Quoted 54 lines
Quoted 54 lines
Documentation/devicetree/bindings/i2c/i2c-mxs.txt +0
-0Examples:arch/arm/boot/dts/imx28.dtsi +1
-0@@ -419,6 +419,7 @@ compatible = "fsl,imx28-i2c"; reg = <0x80058000 2000>; interrupts = <111 68>; + clock-frequency = <400000>;arch/arm/boot/dts/imx28.dtsi +1
-0status = "disabled"; };@@ -428,6 +429,7 @@ compatible = "fsl,imx28-i2c"; reg = <0x8005a000 2000>; interrupts = <110 69>; + clock-frequency = <400000>;arch/arm/boot/dts/imx28.dtsi +0
-0status = "disabled"; };drivers/i2c/busses/i2c-mxs.c +4
-0@@ -46,6 +46,10 @@#define MXS_I2C_CTRL0_DIRECTION 0x00010000#define MXS_I2C_CTRL0_XFER_COUNT (v) ((v) & 0x0000FFFF) +#define MXS_I2C_TIMING0 (0x10) +#define MXS_I2C_TIMING1 (0x20) +#define MXS_I2C_TIMING2 (0x30) +#define MXS_I2C_CTRL1 (0x40)#define
MXS_I2C_CTRL1_SET(0x44)
#defineMXS_I2C_CTRL1_CLR(0x48)drivers/i2c/busses/i2c-mxs.c +0
-0@@ -97,6 +101,25 @@#define MXS_CMD_I2C_READ (MXS_I2C_CTRL0_SEND_NAK_ON_LAST | \ MXS_I2C_CTRL0_MASTER_MODE)
Quoted 11 lines
Quoted 8 lines
drivers/i2c/busses/i2c-mxs.c +7
-0+struct mxs_i2c_speed_config { +uint32_t timing0; +uint32_t timing1; +uint32_t timing2; +}; + +/* Timing values for the default 24MHz clock supplied into the i2c block. */
I did not check spec,
is it possible the supplied clock changed?
It's possible indeed ... Shawn?
Quoted 3 lines
Quoted 1 line
+const struct
mxs_i2c_speed_configmxs_i2c_95kHz_config= {Do we need static for it?
MX28 datasheet 27.5.2 - 27.5.4 ... there was a discussion about these in the thread under older patches. Those shall explain your questions below.
Quoted 103 lines
drivers/i2c/busses/i2c-mxs.c line 117
Quoted 6 lines
drivers/i2c/busses/i2c-mxs.c +6
-0+ .timing0 = 0x00780030, + .timing1 = 0x00800030, + .timing2 = 0x00300030, +}; + +const struct mxs_i2c_speed_config mxs_i2c_400kHz_config = {ditto
Quoted 44 lines
drivers/i2c/busses/i2c-mxs.c +12
-0+ .timing0 = 0x000f0007, + .timing1 = 0x001f000f, + .timing2 = 0x00300030, +}; +/** * struct mxs_i2c_dev - per device, private MXS-I2C data * @@ -112,11 +135,17 @@ struct mxs_i2c_dev {struct completion cmd_complete;u32 cmd_err;struct i2c_adapter adapter; +const struct mxs_i2c_speed_config *speed; };static void mxs_i2c_reset (struct mxs_i2c_dev *i2c) {stmp_reset_block (i2c->regs); + +writel (i2c->speed->timing0, i2c->regs +MXS_I2C_TIMING0 ); +writel (i2c->speed->timing1, i2c->regs +MXS_I2C_TIMING1 ); +writel (i2c->speed->timing2, i2c->regs +MXS_I2C_TIMING2 ); +writel (MXS_I2C_IRQ_MASK <<8 , i2c->regs +MXS_I2C_CTRL1_SET );writel (MXS_I2C_QUEUECTRL_PIO_QUEUE_MODE , i2c->regs +MXS_I2C_QUEUECTRL_SET );@@ -319,6 +348,28 @@ static const struct i2c_algorithm mxs_i2c_algo = { .functionality = mxs_i2c_func, }; +static int mxs_i2c_get_ofdata (struct mxs_i2c_dev *i2c)drivers/i2c/busses/i2c-mxs.c static const struct i2c_algorithm mxs_i2c_algo = { · line 363
Quoted 10 lines
drivers/i2c/busses/i2c-mxs.c +10
-0+{ +uint32_t speed; +struct device *dev = i2c->dev; +struct device_node *node = dev->of_node; +int ret; + +if (!node) +return -EINVAL ; + + i2c->speed = &mxs_i2c_95kHz_config;Can you explain why here is 95khz rather than 100kh? It seems this is for 100khz below.
Quoted 30 lines
drivers/i2c/busses/i2c-mxs.c +11
-0+ ret =of_property_read_u32 (node,"clock-frequency" , &speed); +if (ret) +dev_warn (dev,"No I2C speed selected, using 100kHz\n" ); +else if (speed ==400000 ) + i2c->speed = &mxs_i2c_400kHz_config; +else if (speed !=100000 ) +dev_warn (dev,"Invalid I2C speed selected, using 100kHz\n" ); + +return 0 ; +} +static int
__devinitmxs_i2c_probe(struct platform_device *pdev){drivers/i2c/busses/i2c-mxs.c +5
-0struct device *dev = &pdev->dev;@@ -358,6 +409,11 @@ static int __devinit mxs_i2c_probe(struct platform_device *pdev)return err; i2c->dev = dev; + + err =mxs_i2c_get_ofdata (i2c); +if (err) +return err; +drivers/i2c/busses/i2c-mxs.c static int __devinit mxs_i2c_probe(struct platform_device *pdev) · line 419
Quoted 3 lines
drivers/i2c/busses/i2c-mxs.c +0
-0platform_set_drvdata (pdev, i2c);/* Do reset to enforce correct startup after pinmuxing */ Regards
Dong Aisheng
PATCH 1/2 MXS: Set I2C timing registers for mxs-i2c
Quoted 3 lines · Marek Vasut
MX28 datasheet 27.5.2 - 27.5.4 ... there was a discussion about these in the thread under older patches. Those shall explain your questions below.
Thanks for the info.
Regards
Dong Aisheng
PATCH 1/2 MXS: Set I2C timing registers for mxs-i2c
Dear Dong Aisheng,
Quoted 6 lines · Marek Vasut
Quoted 3 lines
MX28 datasheet 27.5.2 - 27.5.4 ... there was a discussion about these in the thread under older patches. Those shall explain your questions below.
Thanks for the info.
You're welcome. Hope it helps ;-)
Quoted 2 lines
Regards
Dong Aisheng
Best regards,
Marek Vasut
PATCH 1/2 MXS: Set I2C timing registers for mxs-i2c
In reply to Marek VasutQuoted 5 lines · Marek Vasut
Quoted 2 lines
I did not check spec,
is it possible the supplied clock changed?It's possible indeed ... Shawn?
It's technically possible, but probably not practically. The imx28 RM does not mention i2c clock at all, and I was told by designer that i2c always runs at the same frequency as apbx, which sources from ref_xtal (always 24 MHz). Though there is a divider for apbx clock, it seems every single running system sets the divider as 1 all the time. That said, what I have seen is the i2c clock is always 24 MHz.
Signature · 2 lines
Regards, Shawn