i2c: designware: deduce speed mode from device tree setting
Subsystems (3)
PATCH 1/1 i2c: designware: deduce speed mode from device tree setting
From: Alan Tull <[email protected]>
Use the documented, but unimplemented "clock-frequency" Device Tree setting as a guide on whether to set the speed mode bits in DW_IC_CON to standard or fast i2c mode.
Previously, the driver was hardwired to fast mode. Default to fast mode if the "clock-frequency" property is not present for backwards compatiblity.
--- drivers/i2c/busses/i2c-designware-platdrv.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-platdrv.c +8 -2
@@ -122,7 +122,8 @@ static int dw_i2c_probe(struct platform_device *pdev)struct dw_i2c_dev *dev;struct i2c_adapter *adap;struct resource *mem; -int irq, r; +int irq, r, ret, speed =DW_IC_CON_SPEED_FAST ; +u32 bus_rate; irq =platform_get_irq (pdev,0 );if (irq <0 ) {
@@ -167,6 +168,11 @@ static int dw_i2c_probe(struct platform_device *pdev)of_property_read_u32 (pdev->dev.of_node,"i2c-scl-falling-time-ns" , &dev->scl_falling_time); + + ret =of_property_read_u32 (pdev->dev.of_node, +"clock-frequency" , &bus_rate); +if (!ret && (bus_rate <=100000 )) + speed =DW_IC_CON_SPEED_STD ; } dev->functionality =
@@ -177,7 +183,7 @@ static int dw_i2c_probe(struct platform_device *pdev)I2C_FUNC_SMBUS_WORD_DATA |I2C_FUNC_SMBUS_I2C_BLOCK ; dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | -DW_IC_CON_RESTART_EN |DW_IC_CON_SPEED_FAST ; +DW_IC_CON_RESTART_EN | speed;/* Try first if we can configure the device from ACPI */ r =dw_i2c_acpi_configure (pdev);
Signature · 1 line
1.7.9.5
Quoted 11 lines · On Tue, Aug 19, 2014 at 03:18:49PM -0500…
From: Alan Tull <[email protected]>
Use the documented, but unimplemented "clock-frequency" Device Tree setting as a guide on whether to set the speed mode bits in
DW_IC_CONto standard or fast i2c mode.Previously, the driver was hardwired to fast mode. Default to fast mode if the "clock-frequency" property is not present for backwards compatiblity.
Signed-off-by Alan Tull <[email protected]>
I don't know much about the Device Tree bindings but the patch looks good to me,
Quoted 30 lines · On Tue, Aug 19, 2014 at 09:18:49PM +0100…
From: Alan Tull <[email protected]>
Use the documented, but unimplemented "clock-frequency" Device Tree setting as a guide on whether to set the speed mode bits in
DW_IC_CONto standard or fast i2c mode.Previously, the driver was hardwired to fast mode. Default to fast mode if the "clock-frequency" property is not present for backwards compatiblity.
Signed-off-by Alan Tull <[email protected]>--- drivers/i2c/busses/i2c-designware-platdrv.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/i2c/busses/i2c-designware-platdrv.c +2
-1@@ -122,7 +122,8 @@ static int dw_i2c_probe(struct platform_device *pdev)struct dw_i2c_dev *dev;struct i2c_adapter *adap;struct resource *mem; -int irq, r; +int irq, r, ret, speed =DW_IC_CON_SPEED_FAST ; +u32 bus_rate; irq =platform_get_irq (pdev,0 );if (irq <0 ) {
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_probe(struct platform_device *pdev) · line 175
Quoted 8 lines
drivers/i2c/busses/i2c-designware-platdrv.c +5
-0@@ -167,6 +168,11 @@ static int dw_i2c_probe(struct platform_device *pdev)of_property_read_u32 (pdev->dev.of_node,"i2c-scl-falling-time-ns" , &dev->scl_falling_time); + + ret =of_property_read_u32 (pdev->dev.of_node, +"clock-frequency" , &bus_rate); +if (!ret && (bus_rate <=100000 )) + speed =DW_IC_CON_SPEED_STD ;
This looks a bit odd.
If the device only supports two particular speeds why do we accept any other speed in the clock-frequency property? Surely we should at least warn that something was off?
Thanks,
Mark
Quoted 20 lines
drivers/i2c/busses/i2c-designware-platdrv.c +1
-1} dev->functionality =@@ -177,7 +183,7 @@ static int dw_i2c_probe(struct platform_device *pdev)I2C_FUNC_SMBUS_WORD_DATA |I2C_FUNC_SMBUS_I2C_BLOCK ; dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | -DW_IC_CON_RESTART_EN |DW_IC_CON_SPEED_FAST ; +DW_IC_CON_RESTART_EN | speed;/* Try first if we can configure the device from ACPI */ r =dw_i2c_acpi_configure (pdev);Signature · 6 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi,
With the patch "i2c designware add support of I2C standard mode" I already proposed:
- I2C standard mode is selected with 100kHz clock frequency.
- I2C fast mode is selected with 400kHy clock frequency.
- EINVAL error is returned if clock frequency is not 100000 and not 400000.
but this patch seems not available yet.
What about the other patch "i2c designware make SCL and SDA falling time configurable" ?
In i2c-designware_platdrv.c the flag DW_IC_CON_SPEED_xxx is well set depending on the mode:
if (clk_freq == 100000)
dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_STD;
else
dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST;So for me everything should be fine if there patches are applied.
Regards,
Romain
----- Original Message -----
From: "Mark Rutland" <[email protected]>
To: [email protected]
Cc: wsa-z923LK4zBo2bacvFa/[email protected], [email protected], "mika westerberg" <mika.westerberg-VuQAYsv1563Yd54FQh9/[email protected]>, "grant likely" <[email protected]>, [email protected], [email protected], "Romain Baeriswyl" <[email protected]>, "rafael j wysocki" <[email protected]>, alan-VuQAYsv1563Yd54FQh9/[email protected], [email protected], [email protected], [email protected], "delicious quinoa" <[email protected]>, [email protected], [email protected]
Sent: Wednesday, August 20, 2014 11:22:57 AM
Subject: Re: [PATCH] i2c: designware: deduce speed mode from device tree setting
Quoted 30 lines · On Tue, Aug 19, 2014 at 09:18:49PM +0100…
From: Alan Tull <[email protected]>
Use the documented, but unimplemented "clock-frequency" Device Tree setting as a guide on whether to set the speed mode bits in
DW_IC_CONto standard or fast i2c mode.Previously, the driver was hardwired to fast mode. Default to fast mode if the "clock-frequency" property is not present for backwards compatiblity.
Signed-off-by Alan Tull <[email protected]>--- drivers/i2c/busses/i2c-designware-platdrv.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/i2c/busses/i2c-designware-platdrv.c +2
-1@@ -122,7 +122,8 @@ static int dw_i2c_probe(struct platform_device *pdev)struct dw_i2c_dev *dev;struct i2c_adapter *adap;struct resource *mem; -int irq, r; +int irq, r, ret, speed =DW_IC_CON_SPEED_FAST ; +u32 bus_rate; irq =platform_get_irq (pdev,0 );if (irq <0 ) {
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_probe(struct platform_device *pdev) · line 175
Quoted 8 lines
drivers/i2c/busses/i2c-designware-platdrv.c +5
-0@@ -167,6 +168,11 @@ static int dw_i2c_probe(struct platform_device *pdev)of_property_read_u32 (pdev->dev.of_node,"i2c-scl-falling-time-ns" , &dev->scl_falling_time); + + ret =of_property_read_u32 (pdev->dev.of_node, +"clock-frequency" , &bus_rate); +if (!ret && (bus_rate <=100000 )) + speed =DW_IC_CON_SPEED_STD ;
This looks a bit odd.
If the device only supports two particular speeds why do we accept any other speed in the clock-frequency property? Surely we should at least warn that something was off?
Thanks,
Mark
Quoted 20 lines
drivers/i2c/busses/i2c-designware-platdrv.c +1
-1} dev->functionality =@@ -177,7 +183,7 @@ static int dw_i2c_probe(struct platform_device *pdev)I2C_FUNC_SMBUS_WORD_DATA |I2C_FUNC_SMBUS_I2C_BLOCK ; dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | -DW_IC_CON_RESTART_EN |DW_IC_CON_SPEED_FAST ; +DW_IC_CON_RESTART_EN | speed;/* Try first if we can configure the device from ACPI */ r =dw_i2c_acpi_configure (pdev);Signature · 6 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Please find below link to these patches:
[PATCH 1/2] i2c designware make SCL and SDA falling time configurable
https://lkml.org/lkml/2013/10/8/443
[PATCH V3 2/2] i2c designware add support of I2C standard mode
https://lkml.org/lkml/2014/3/25/135
Are they fine to be included in the mainline ?
Romain
----- Original Message -----
From: "Romain Baeriswyl" <[email protected]>
To: "Mark Rutland" <[email protected]>, [email protected]
Cc: [email protected], [email protected], "mika westerberg" <[email protected]>, "grant likely" <[email protected]>, [email protected], [email protected], "rafael j wysocki" <[email protected]>, [email protected], [email protected], [email protected], [email protected], "delicious quinoa" <[email protected]>, [email protected], [email protected]
Sent: Wednesday, August 20, 2014 11:49:37 AM
Subject: Re: [PATCH] i2c: designware: deduce speed mode from device tree setting
Hi,
With the patch "i2c designware add support of I2C standard mode" I already proposed:
- I2C standard mode is selected with 100kHz clock frequency.
- I2C fast mode is selected with 400kHy clock frequency.
- EINVAL error is returned if clock frequency is not 100000 and not 400000.
but this patch seems not available yet.
What about the other patch "i2c designware make SCL and SDA falling time configurable" ?
In i2c-designware_platdrv.c the flag DW_IC_CON_SPEED_xxx is well set depending on the mode:
if (clk_freq == 100000)
dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_STD;
else
dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST;So for me everything should be fine if there patches are applied.
Regards,
Romain
----- Original Message -----
From: "Mark Rutland" <[email protected]>
To: [email protected]
Cc: [email protected], [email protected], "mika westerberg" <[email protected]>, "grant likely" <[email protected]>, [email protected], [email protected], "Romain Baeriswyl" <[email protected]>, "rafael j wysocki" <[email protected]>, [email protected], [email protected], [email protected], [email protected], "delicious quinoa" <[email protected]>, [email protected], [email protected]
Sent: Wednesday, August 20, 2014 11:22:57 AM
Subject: Re: [PATCH] i2c: designware: deduce speed mode from device tree setting
Quoted 30 lines · On Tue, Aug 19, 2014 at 09:18:49PM +0100, [email protected] wrote:
From: Alan Tull <[email protected]>
Use the documented, but unimplemented "clock-frequency" Device Tree setting as a guide on whether to set the speed mode bits in
DW_IC_CONto standard or fast i2c mode.Previously, the driver was hardwired to fast mode. Default to fast mode if the "clock-frequency" property is not present for backwards compatiblity.
Signed-off-by Alan Tull <[email protected]>--- drivers/i2c/busses/i2c-designware-platdrv.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/i2c/busses/i2c-designware-platdrv.c +2
-1@@ -122,7 +122,8 @@ static int dw_i2c_probe(struct platform_device *pdev)struct dw_i2c_dev *dev;struct i2c_adapter *adap;struct resource *mem; -int irq, r; +int irq, r, ret, speed =DW_IC_CON_SPEED_FAST ; +u32 bus_rate; irq =platform_get_irq (pdev,0 );if (irq <0 ) {
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_probe(struct platform_device *pdev) · line 175
Quoted 8 lines
drivers/i2c/busses/i2c-designware-platdrv.c +5
-0@@ -167,6 +168,11 @@ static int dw_i2c_probe(struct platform_device *pdev)of_property_read_u32 (pdev->dev.of_node,"i2c-scl-falling-time-ns" , &dev->scl_falling_time); + + ret =of_property_read_u32 (pdev->dev.of_node, +"clock-frequency" , &bus_rate); +if (!ret && (bus_rate <=100000 )) + speed =DW_IC_CON_SPEED_STD ;
This looks a bit odd.
If the device only supports two particular speeds why do we accept any other speed in the clock-frequency property? Surely we should at least warn that something was off?
Thanks,
Mark
Quoted 20 lines
drivers/i2c/busses/i2c-designware-platdrv.c +1
-1} dev->functionality =@@ -177,7 +183,7 @@ static int dw_i2c_probe(struct platform_device *pdev)I2C_FUNC_SMBUS_WORD_DATA |I2C_FUNC_SMBUS_I2C_BLOCK ; dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | -DW_IC_CON_RESTART_EN |DW_IC_CON_SPEED_FAST ; +DW_IC_CON_RESTART_EN | speed;/* Try first if we can configure the device from ACPI */ r =dw_i2c_acpi_configure (pdev);Signature · 6 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 5 lines
With the patch "i2c designware add support of I2C standard mode" I already proposed:
- I2C standard mode is selected with 100kHz clock frequency.
- I2C fast mode is selected with 400kHy clock frequency.
- EINVAL error is returned if clock frequency is not 100000 and not 400000.
You forgot to send this patch to the i2c list. So, it didn't get into patchwork which I rely on for tracking patches.
Please resend an updated version to the latest codebase. I like that it has the EINVAL error checking.
Quoted 1 line
What about the other patch "i2c designware make SCL and SDA falling time configurable" ?
6468276b22069d4442aafcd8c59e5d8ccae23f5f upstream.
Quoted 10 lines
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_probe(struct platform_device *pdev) · line 175
Quoted 5 lines
drivers/i2c/busses/i2c-designware-platdrv.c +5
-0+ + ret =of_property_read_u32 (pdev->dev.of_node, +"clock-frequency" , &bus_rate); +if (!ret && (bus_rate <=100000 )) + speed =DW_IC_CON_SPEED_STD ;This looks a bit odd.
If the device only supports two particular speeds why do we accept any other speed in the clock-frequency property?
"clock-frequency" is the default binding for specifying i2c bus speeds today. Some controllers can be programmed to do various speeds, some can only do a set of fixed values.
Quoted 1 line
Surely we should at least warn that something was off?
Yes, I was going to say the same until Romain's old patch showed up which does that.
Thanks,
Wolfram
Quoted 8 lines · Wolfram Sang
Quoted 8 lines
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_probe(struct platform_device *pdev) · line 175
Quoted 5 lines
drivers/i2c/busses/i2c-designware-platdrv.c +5
-0+ + ret =of_property_read_u32 (pdev->dev.of_node, +"clock-frequency" , &bus_rate); +if (!ret && (bus_rate <=100000 )) + speed =DW_IC_CON_SPEED_STD ;This looks a bit odd.
Quoted 6 lines
Quoted 2 lines
If the device only supports two particular speeds why do we accept any other speed in the clock-frequency property?
"clock-frequency" is the default binding for specifying i2c bus speeds today. Some controllers can be programmed to do various speeds, some can only do a set of fixed values.
Sure. My complaint was that the driver would accept invalid values. That wasn't meant to be suggestion to use a property other than the standard clock-freqeuncy.
Quoted 4 lines
Quoted 1 line
Surely we should at least warn that something was off?
Yes, I was going to say the same until Romain's old patch showed up which does that.
Cool. Sounds like we can use Romain's patch to handle this then.
Cheers,
Mark.
Quoted 7 lines · Romain Baeriswyl
Hi,
With the patch "i2c designware add support of I2C standard mode" I already proposed:
- I2C standard mode is selected with 100kHz clock frequency.
- I2C fast mode is selected with 400kHy clock frequency.
- EINVAL error is returned if clock frequency is not 100000 and not 400000.
Quoted 7 lines
but this patch seems not available yet.
What about the other patch "i2c designware make SCL and SDA falling time configurable" ?In
i2c-designware_platdrv.cthe flagDW_IC_CON_SPEED_xxxis well set depending on the mode:if (
clk_freq== 100000)
Romain,
I'm really happy if your patches get accepted. Can this be <= 100000? It is really common to run I2C at a lower speed if you have some board issues with the i2c bus.
Alan
Quoted 90 lines
dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_STD; else dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST;So for me everything should be fine if there patches are applied.
Regards,
Romain
----- Original Message -----
From: "Mark Rutland" <[email protected]>
To: [email protected]
Cc: wsa-z923LK4zBo2bacvFa/[email protected], [email protected], "mika westerberg" <mika.westerberg-VuQAYsv1563Yd54FQh9/[email protected]>, "grant likely" <[email protected]>, [email protected], [email protected], "Romain Baeriswyl" <[email protected]>, "rafael j wysocki" <[email protected]>, alan-VuQAYsv1563Yd54FQh9/[email protected], [email protected], [email protected], [email protected], "delicious quinoa" <[email protected]>, [email protected], [email protected]
Sent: Wednesday, August 20, 2014 11:22:57 AM
Subject: Re: [PATCH] i2c: designware: deduce speed mode from device tree settingQuoted 30 lines · On Tue, Aug 19, 2014 at 09:18:49PM +0100…
From: Alan Tull <[email protected]>
Use the documented, but unimplemented "clock-frequency" Device Tree setting as a guide on whether to set the speed mode bits in
DW_IC_CONto standard or fast i2c mode.Previously, the driver was hardwired to fast mode. Default to fast mode if the "clock-frequency" property is not present for backwards compatiblity.
Signed-off-by Alan Tull <[email protected]>--- drivers/i2c/busses/i2c-designware-platdrv.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/i2c/busses/i2c-designware-platdrv.c +2
-1@@ -122,7 +122,8 @@ static int dw_i2c_probe(struct platform_device *pdev)struct dw_i2c_dev *dev;struct i2c_adapter *adap;struct resource *mem; -int irq, r; +int irq, r, ret, speed =DW_IC_CON_SPEED_FAST ; +u32 bus_rate; irq =platform_get_irq (pdev,0 );if (irq <0 ) {drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_probe(struct platform_device *pdev) · line 175
Quoted 8 lines
drivers/i2c/busses/i2c-designware-platdrv.c +5
-0@@ -167,6 +168,11 @@ static int dw_i2c_probe(struct platform_device *pdev)of_property_read_u32 (pdev->dev.of_node,"i2c-scl-falling-time-ns" , &dev->scl_falling_time); + + ret =of_property_read_u32 (pdev->dev.of_node, +"clock-frequency" , &bus_rate); +if (!ret && (bus_rate <=100000 )) + speed =DW_IC_CON_SPEED_STD ;This looks a bit odd.
If the device only supports two particular speeds why do we accept any other speed in the clock-frequency property? Surely we should at least warn that something was off?
Thanks,
MarkQuoted 20 lines
drivers/i2c/busses/i2c-designware-platdrv.c +1
-1} dev->functionality =@@ -177,7 +183,7 @@ static int dw_i2c_probe(struct platform_device *pdev)I2C_FUNC_SMBUS_WORD_DATA |I2C_FUNC_SMBUS_I2C_BLOCK ; dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | -DW_IC_CON_RESTART_EN |DW_IC_CON_SPEED_FAST ; +DW_IC_CON_RESTART_EN | speed;/* Try first if we can configure the device from ACPI */ r =dw_i2c_acpi_configure (pdev);Signature · 6 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/1 i2c designware add support of I2C standard mode
In reply to Mark RutlandFrom: Romain Baeriswyl <[email protected]>
Some legacy devices support ony I2C standard mode at 100kHz. This patch allows to select the standard mode through the DTS with the use of the existing clock-frequency parameter.
When clock-frequency parameter is not set, the fast mode is selected. Only when the parameter is set at 100000, the standard mode is selected.
--- drivers/i2c/busses/i2c-designware-platdrv.c | 23 +++++++++++++++++++++-- 1 files changed, 21 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-platdrv.c +21 -2
@@ -122,6 +122,7 @@ static int dw_i2c_probe(struct platform_device *pdev)struct i2c_adapter *adap;struct resource *mem;int irq, r; +u32 clk_freq; irq =platform_get_irq (pdev,0 );if (irq <0 ) {
@@ -151,6 +152,9 @@ static int dw_i2c_probe(struct platform_device *pdev)return PTR_ERR (dev->clk);clk_prepare_enable (dev->clk); +/* fast mode by default because of legacy reasons */ + clk_freq =400000 ; +if (pdev->dev.of_node) {u32 ht =0 ;u32 ic_clk = dev->get_clk_rate_khz (dev);
@@ -166,6 +170,17 @@ static int dw_i2c_probe(struct platform_device *pdev)of_property_read_u32 (pdev->dev.of_node,"i2c-scl-falling-time-ns" , &dev->scl_falling_time); + +of_property_read_u32 (pdev->dev.of_node,"clock-frequency" , + &clk_freq); + +/* Only standard mode at 100kHz and fast mode at 400kHz +* are supported. +*/ +if (clk_freq !=100000 && clk_freq !=400000 ) { +dev_err (&pdev->dev,"Only 100kHz and 400kHz supported" ); +return -EINVAL ; + } } dev->functionality =
@@ -175,8 +190,12 @@ static int dw_i2c_probe(struct platform_device *pdev)I2C_FUNC_SMBUS_BYTE_DATA |I2C_FUNC_SMBUS_WORD_DATA |I2C_FUNC_SMBUS_I2C_BLOCK ; - dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | -DW_IC_CON_RESTART_EN |DW_IC_CON_SPEED_FAST ; +if (clk_freq ==100000 ) + dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | +DW_IC_CON_RESTART_EN |DW_IC_CON_SPEED_STD ; +else + dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | +DW_IC_CON_RESTART_EN |DW_IC_CON_SPEED_FAST ;/* Try first if we can configure the device from ACPI */ r =dw_i2c_acpi_configure (pdev);
Signature · 1 line
1.7.1
Re: [PATCH] i2c designware add support of I2C standard mode
Quoted 42 lines · Romain Baeriswyl
From: Romain Baeriswyl <[email protected]>
Some legacy devices support ony I2C standard mode at 100kHz. This patch allows to select the standard mode through the DTS with the use of the existing clock-frequency parameter.
When clock-frequency parameter is not set, the fast mode is selected. Only when the parameter is set at 100000, the standard mode is selected.
Signed-off-by Romain Baeriswyl <[email protected]>Reviewed-by Christian Ruppert <[email protected]>--- drivers/i2c/busses/i2c-designware-platdrv.c | 23 +++++++++++++++++++++-- 1 files changed, 21 insertions(+), 2 deletions(-)drivers/i2c/busses/i2c-designware-platdrv.c +5
-0@@ -122,6 +122,7 @@ static int dw_i2c_probe(struct platform_device *pdev)struct i2c_adapter *adap;struct resource *mem;int irq, r; +u32 clk_freq; irq =platform_get_irq (pdev,0 );if (irq <0 ) {@@ -151,6 +152,9 @@ static int dw_i2c_probe(struct platform_device *pdev)return PTR_ERR (dev->clk);clk_prepare_enable (dev->clk); +/* fast mode by default because of legacy reasons */ + clk_freq =400000 ; +if (pdev->dev.of_node) {u32 ht =0 ;u32 ic_clk = dev->get_clk_rate_khz (dev);@@ -166,6 +170,17 @@ static int dw_i2c_probe(struct platform_device *pdev)of_property_read_u32 (pdev->dev.of_node,"i2c-scl-falling-time-ns" , &dev->scl_falling_time); +
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_probe(struct platform_device *pdev) · line 183
Quoted 10 lines
drivers/i2c/busses/i2c-designware-platdrv.c +10
-0+of_property_read_u32 (pdev->dev.of_node,"clock-frequency" , + &clk_freq); + +/* Only standard mode at 100kHz and fast mode at 400kHz +* are supported. +*/ +if (clk_freq !=100000 && clk_freq !=400000 ) { +dev_err (&pdev->dev,"Only 100kHz and 400kHz supported" ); +return -EINVAL ; + }
Hi Romain,
It is common to operate i2c at <100KHz on boards that have i2c issues. I am using this driver at 50KHz because I have a LCD module that just doesn't work at a full 100KHz. Please remove the check for these two frequency points.
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_probe(struct platform_device *pdev) · line 193
Quoted 10 lines
drivers/i2c/busses/i2c-designware-platdrv.c +1
-2} dev->functionality =@@ -175,8 +190,12 @@ static int dw_i2c_probe(struct platform_device *pdev)I2C_FUNC_SMBUS_BYTE_DATA |I2C_FUNC_SMBUS_WORD_DATA |I2C_FUNC_SMBUS_I2C_BLOCK ; - dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | -DW_IC_CON_RESTART_EN |DW_IC_CON_SPEED_FAST ; +if (clk_freq ==100000 )
Please change to <=
Quoted 12 lines
drivers/i2c/busses/i2c-designware-platdrv.c +5
-0+ dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | +DW_IC_CON_RESTART_EN |DW_IC_CON_SPEED_STD ; + else + dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | +DW_IC_CON_RESTART_EN |DW_IC_CON_SPEED_FAST ;/* Try first if we can configure the device from ACPI */ r =dw_i2c_acpi_configure (pdev);Signature · 1 line
1.7.1
Hi Alan,
We got board issue using I2C and they were solved by changing the i2c timing.
It is possible to change the tLOW and tHIGH period with the following parameters:
i2c-sda-hold-time-ns
i2c-sda-falling-time-ns
i2c-scl-falling-time-ns
Romain
----- Original Message -----
From: "atull" <[email protected]>
To: "Romain Baeriswyl" <[email protected]>
Cc: "Mark Rutland" <[email protected]>, wsa-z923LK4zBo2bacvFa/[email protected], [email protected], "mika westerberg" <mika.westerberg-VuQAYsv1563Yd54FQh9/[email protected]>, "grant likely" <[email protected]>, [email protected], [email protected], "rafael j wysocki" <[email protected]>, alan-VuQAYsv1563Yd54FQh9/[email protected], [email protected], [email protected], [email protected], "delicious quinoa" <[email protected]>, [email protected], [email protected]
Sent: Wednesday, August 20, 2014 4:24:45 PM
Subject: Re: [PATCH] i2c: designware: deduce speed mode from device tree setting
Quoted 7 lines · Romain Baeriswyl
Hi,
With the patch "i2c designware add support of I2C standard mode" I already proposed:
- I2C standard mode is selected with 100kHz clock frequency.
- I2C fast mode is selected with 400kHy clock frequency.
- EINVAL error is returned if clock frequency is not 100000 and not 400000.
Quoted 7 lines
but this patch seems not available yet.
What about the other patch "i2c designware make SCL and SDA falling time configurable" ?In
i2c-designware_platdrv.cthe flagDW_IC_CON_SPEED_xxxis well set depending on the mode:if (
clk_freq== 100000)
Romain,
I'm really happy if your patches get accepted. Can this be <= 100000? It is really common to run I2C at a lower speed if you have some board issues with the i2c bus.
Alan
Quoted 84 lines
dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_STD; else dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST;So for me everything should be fine if there patches are applied.
Regards,
Romain
----- Original Message -----
From: "Mark Rutland" <[email protected]>
To: [email protected]
Cc: wsa-z923LK4zBo2bacvFa/[email protected], [email protected], "mika westerberg" <mika.westerberg-VuQAYsv1563Yd54FQh9/[email protected]>, "grant likely" <[email protected]>, [email protected], [email protected], "Romain Baeriswyl" <[email protected]>, "rafael j wysocki" <[email protected]>, alan-VuQAYsv1563Yd54FQh9/[email protected], [email protected], [email protected], [email protected], "delicious quinoa" <[email protected]>, [email protected], [email protected]
Sent: Wednesday, August 20, 2014 11:22:57 AM
Subject: Re: [PATCH] i2c: designware: deduce speed mode from device tree settingQuoted 30 lines · On Tue, Aug 19, 2014 at 09:18:49PM +0100…
From: Alan Tull <[email protected]>
Use the documented, but unimplemented "clock-frequency" Device Tree setting as a guide on whether to set the speed mode bits in
DW_IC_CONto standard or fast i2c mode.Previously, the driver was hardwired to fast mode. Default to fast mode if the "clock-frequency" property is not present for backwards compatiblity.
Signed-off-by Alan Tull <[email protected]>--- drivers/i2c/busses/i2c-designware-platdrv.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/i2c/busses/i2c-designware-platdrv.c +2
-1@@ -122,7 +122,8 @@ static int dw_i2c_probe(struct platform_device *pdev)struct dw_i2c_dev *dev;struct i2c_adapter *adap;struct resource *mem; -int irq, r; +int irq, r, ret, speed =DW_IC_CON_SPEED_FAST ; +u32 bus_rate; irq =platform_get_irq (pdev,0 );if (irq <0 ) {drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_probe(struct platform_device *pdev) · line 175
Quoted 8 lines
drivers/i2c/busses/i2c-designware-platdrv.c +5
-0@@ -167,6 +168,11 @@ static int dw_i2c_probe(struct platform_device *pdev)of_property_read_u32 (pdev->dev.of_node,"i2c-scl-falling-time-ns" , &dev->scl_falling_time); + + ret =of_property_read_u32 (pdev->dev.of_node, +"clock-frequency" , &bus_rate); +if (!ret && (bus_rate <=100000 )) + speed =DW_IC_CON_SPEED_STD ;This looks a bit odd.
If the device only supports two particular speeds why do we accept any other speed in the clock-frequency property? Surely we should at least warn that something was off?
Thanks,
MarkQuoted 15 lines
drivers/i2c/busses/i2c-designware-platdrv.c +1
-1} dev->functionality =@@ -177,7 +183,7 @@ static int dw_i2c_probe(struct platform_device *pdev)I2C_FUNC_SMBUS_WORD_DATA |I2C_FUNC_SMBUS_I2C_BLOCK ; dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | -DW_IC_CON_RESTART_EN |DW_IC_CON_SPEED_FAST ; +DW_IC_CON_RESTART_EN | speed;/* Try first if we can configure the device from ACPI */ r =dw_i2c_acpi_configure (pdev);Signature · 1 line
1.7.9.5
Quoted 6 lines
Quoted 5 lines
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 10 lines · Romain Baeriswyl
Hi Alan,
We got board issue using I2C and they were solved by changing the i2c timing.
It is possible to change the tLOW and tHIGH period with the following parameters:
i2c-sda-hold-time-ns
i2c-sda-falling-time-ns
i2c-scl-falling-time-nsRomain
Hi Romain,
This thread is getting kind of messed up. Yep, that's how I am slowing down the bus, using i2c-sda-falling-time-ns and i2c-scl-falling-time-ns. It is fine with me if you want to test for == 100KHz, just not my (probably hair-splitting) preference. :)
Alan
Quoted 126 lines
----- Original Message -----
From: "atull" <[email protected]>
To: "Romain Baeriswyl" <[email protected]>
Cc: "Mark Rutland" <[email protected]>, wsa-z923LK4zBo2bacvFa/[email protected], [email protected], "mika westerberg" <mika.westerberg-VuQAYsv1563Yd54FQh9/[email protected]>, "grant likely" <[email protected]>, [email protected], [email protected], "rafael j wysocki" <[email protected]>, alan-VuQAYsv1563Yd54FQh9/[email protected], [email protected], [email protected], [email protected], "delicious quinoa" <[email protected]>, [email protected], [email protected]
Sent: Wednesday, August 20, 2014 4:24:45 PM
Subject: Re: [PATCH] i2c: designware: deduce speed mode from device tree settingQuoted 7 lines · Romain Baeriswyl
Hi,
With the patch "i2c designware add support of I2C standard mode" I already proposed:
- I2C standard mode is selected with 100kHz clock frequency.
- I2C fast mode is selected with 400kHy clock frequency.
- EINVAL error is returned if clock frequency is not 100000 and not 400000.Quoted 7 lines
but this patch seems not available yet.
What about the other patch "i2c designware make SCL and SDA falling time configurable" ?In
i2c-designware_platdrv.cthe flagDW_IC_CON_SPEED_xxxis well set depending on the mode:if (
clk_freq== 100000)Romain,
I'm really happy if your patches get accepted. Can this be <= 100000? It is really common to run I2C at a lower speed if you have some board issues with the i2c bus.
Alan
Quoted 90 lines
dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_STD; else dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST;So for me everything should be fine if there patches are applied.
Regards,
Romain
----- Original Message -----
From: "Mark Rutland" <[email protected]>
To: [email protected]
Cc: wsa-z923LK4zBo2bacvFa/[email protected], [email protected], "mika westerberg" <mika.westerberg-VuQAYsv1563Yd54FQh9/[email protected]>, "grant likely" <[email protected]>, [email protected], [email protected], "Romain Baeriswyl" <[email protected]>, "rafael j wysocki" <[email protected]>, alan-VuQAYsv1563Yd54FQh9/[email protected], [email protected], [email protected], [email protected], "delicious quinoa" <[email protected]>, [email protected], [email protected]
Sent: Wednesday, August 20, 2014 11:22:57 AM
Subject: Re: [PATCH] i2c: designware: deduce speed mode from device tree settingQuoted 30 lines · On Tue, Aug 19, 2014 at 09:18:49PM +0100…
From: Alan Tull <[email protected]>
Use the documented, but unimplemented "clock-frequency" Device Tree setting as a guide on whether to set the speed mode bits in
DW_IC_CONto standard or fast i2c mode.Previously, the driver was hardwired to fast mode. Default to fast mode if the "clock-frequency" property is not present for backwards compatiblity.
Signed-off-by Alan Tull <[email protected]>--- drivers/i2c/busses/i2c-designware-platdrv.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/i2c/busses/i2c-designware-platdrv.c +2
-1@@ -122,7 +122,8 @@ static int dw_i2c_probe(struct platform_device *pdev)struct dw_i2c_dev *dev;struct i2c_adapter *adap;struct resource *mem; -int irq, r; +int irq, r, ret, speed =DW_IC_CON_SPEED_FAST ; +u32 bus_rate; irq =platform_get_irq (pdev,0 );if (irq <0 ) {drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_probe(struct platform_device *pdev) · line 175
Quoted 8 lines
drivers/i2c/busses/i2c-designware-platdrv.c +5
-0@@ -167,6 +168,11 @@ static int dw_i2c_probe(struct platform_device *pdev)of_property_read_u32 (pdev->dev.of_node,"i2c-scl-falling-time-ns" , &dev->scl_falling_time); + + ret =of_property_read_u32 (pdev->dev.of_node, +"clock-frequency" , &bus_rate); +if (!ret && (bus_rate <=100000 )) + speed =DW_IC_CON_SPEED_STD ;This looks a bit odd.
If the device only supports two particular speeds why do we accept any other speed in the clock-frequency property? Surely we should at least warn that something was off?
Thanks,
MarkQuoted 20 lines
drivers/i2c/busses/i2c-designware-platdrv.c +1
-1} dev->functionality =@@ -177,7 +183,7 @@ static int dw_i2c_probe(struct platform_device *pdev)I2C_FUNC_SMBUS_WORD_DATA |I2C_FUNC_SMBUS_I2C_BLOCK ; dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | -DW_IC_CON_RESTART_EN |DW_IC_CON_SPEED_FAST ; +DW_IC_CON_RESTART_EN | speed;/* Try first if we can configure the device from ACPI */ r =dw_i2c_acpi_configure (pdev);Signature · 6 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
atull
Acked-byRe: [PATCH] i2c designware add support of I2C standard mode
In reply to atullQuoted 66 lines · atull
Quoted 42 lines · Romain Baeriswyl
From: Romain Baeriswyl <[email protected]>
Some legacy devices support ony I2C standard mode at 100kHz. This patch allows to select the standard mode through the DTS with the use of the existing clock-frequency parameter.
When clock-frequency parameter is not set, the fast mode is selected. Only when the parameter is set at 100000, the standard mode is selected.
Signed-off-by Romain Baeriswyl <[email protected]>Reviewed-by Christian Ruppert <[email protected]>--- drivers/i2c/busses/i2c-designware-platdrv.c | 23 +++++++++++++++++++++-- 1 files changed, 21 insertions(+), 2 deletions(-)drivers/i2c/busses/i2c-designware-platdrv.c +5
-0@@ -122,6 +122,7 @@ static int dw_i2c_probe(struct platform_device *pdev)struct i2c_adapter *adap;struct resource *mem;int irq, r; +u32 clk_freq; irq =platform_get_irq (pdev,0 );if (irq <0 ) {@@ -151,6 +152,9 @@ static int dw_i2c_probe(struct platform_device *pdev)return PTR_ERR (dev->clk);clk_prepare_enable (dev->clk); +/* fast mode by default because of legacy reasons */ + clk_freq =400000 ; +if (pdev->dev.of_node) {u32 ht =0 ;u32 ic_clk = dev->get_clk_rate_khz (dev);@@ -166,6 +170,17 @@ static int dw_i2c_probe(struct platform_device *pdev)of_property_read_u32 (pdev->dev.of_node,"i2c-scl-falling-time-ns" , &dev->scl_falling_time); +drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_probe(struct platform_device *pdev) · line 183
Quoted 10 lines
drivers/i2c/busses/i2c-designware-platdrv.c +10
-0+of_property_read_u32 (pdev->dev.of_node,"clock-frequency" , + &clk_freq); + +/* Only standard mode at 100kHz and fast mode at 400kHz +* are supported. +*/ +if (clk_freq !=100000 && clk_freq !=400000 ) { +dev_err (&pdev->dev,"Only 100kHz and 400kHz supported" ); +return -EINVAL ; + }Hi Romain,
It is common to operate i2c at <100KHz on boards that have i2c issues. I am using this driver at 50KHz because I have a LCD module that just doesn't work at a full 100KHz. Please remove the check for these two frequency points.
Quoted 2 lines
drivers/i2c/busses/i2c-designware-platdrv.c +0
-0}
Quoted 11 lines
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_probe(struct platform_device *pdev) · line 193
Quoted 8 lines
drivers/i2c/busses/i2c-designware-platdrv.c +1
-2dev->functionality =@@ -175,8 +190,12 @@ static int dw_i2c_probe(struct platform_device *pdev)I2C_FUNC_SMBUS_BYTE_DATA |I2C_FUNC_SMBUS_WORD_DATA |I2C_FUNC_SMBUS_I2C_BLOCK ; - dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | -DW_IC_CON_RESTART_EN |DW_IC_CON_SPEED_FAST ; +if (clk_freq ==100000 )Please change to <=
Hi Romain,
This looks fine to me, my "<= issues" are not important as this isn't really setting a frequency, but just setting a bit that controls speed.
Quoted 13 lines
Quoted 12 lines
drivers/i2c/busses/i2c-designware-platdrv.c +5
-0+ dev->master_cfg =DW_IC_CON_MASTER |DW_IC_CON_SLAVE_DISABLE | +DW_IC_CON_RESTART_EN |DW_IC_CON_SPEED_STD ; + else + dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | +DW_IC_CON_RESTART_EN |DW_IC_CON_SPEED_FAST ;/* Try first if we can configure the device from ACPI */ r =dw_i2c_acpi_configure (pdev);Signature · 1 line
1.7.1
Re: [PATCH] i2c designware add support of I2C standard mode
In reply to Romain BaeriswylQuoted 6 lines · Romain Baeriswyl
From: Romain Baeriswyl <[email protected]>
Some legacy devices support ony I2C standard mode at 100kHz. This patch allows to select the standard mode through the DTS with the use of the existing clock-frequency parameter.
Quoted 9 lines
When clock-frequency parameter is not set, the fast mode is selected. Only when the parameter is set at 100000, the standard mode is selected.
Signed-off-by Romain Baeriswyl <[email protected]>Reviewed-by Christian Ruppert <[email protected]>--- drivers/i2c/busses/i2c-designware-platdrv.c | 23 +++++++++++++++++++++-- 1 files changed, 21 insertions(+), 2 deletions(-)
Hi Wolfram,
This patch is really useful for us. Is it going to be picked up?
Alan
Wolfram Sang
AppliedRe: [PATCH] i2c designware add support of I2C standard mode
In reply to Romain BaeriswylQuoted 11 lines · Romain Baeriswyl
From: Romain Baeriswyl <[email protected]>
Some legacy devices support ony I2C standard mode at 100kHz. This patch allows to select the standard mode through the DTS with the use of the existing clock-frequency parameter.
When clock-frequency parameter is not set, the fast mode is selected. Only when the parameter is set at 100000, the standard mode is selected.
Signed-off-by Romain Baeriswyl <[email protected]>Reviewed-by Christian Ruppert <[email protected]>
Applied to for-next, thanks to all involved!
Re: [PATCH] i2c designware add support of I2C standard mode
Quoted 7 lines · Wolfram Sang
Quoted 6 lines · Romain Baeriswyl
From: Romain Baeriswyl <[email protected]>
Some legacy devices support ony I2C standard mode at 100kHz. This patch allows to select the standard mode through the DTS with the use of the existing clock-frequency parameter.
Quoted 9 lines
Quoted 5 lines
When clock-frequency parameter is not set, the fast mode is selected. Only when the parameter is set at 100000, the standard mode is selected.
Signed-off-by Romain Baeriswyl <[email protected]>Reviewed-by Christian Ruppert <[email protected]>Applied to for-next, thanks to all involved!
I don't see this ingit://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git
Is this in i2c/i2c/for-next?
Alan
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html