i2c: designware: Round down ACPI provided clk to nearest supported clk
Subsystems (3)
PATCH 1/1 i2c: designware: Round down ACPI provided clk to nearest supported clk
The Lenovo Miix2 8 DSDT contains an i2c clk / bus speed of 1700000 Hz for one if its devices, which is not supported.
This is the second DSDT to show up with an unsupported clk in a short time, remove the hardcoded fix for DSDTs with a 1 MiHz clock and simply always round down the clk to the nearest supported value.
--- drivers/i2c/busses/i2c-designware-platdrv.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-designware-platdrv.c +12 -4
@@ -256,7 +256,8 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)struct dw_i2c_dev *dev;u32 acpi_speed, ht =0 ;struct resource *mem; -int irq, ret; +int i, irq, ret; +const int supported_speeds[] = {0 ,100000 ,400000 ,1000000 ,3400000 }; irq =platform_get_irq (pdev,0 );if (irq <0 )
@@ -297,9 +298,16 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) } acpi_speed =i2c_acpi_find_bus_speed (&pdev->dev); -/* Some broken DSTDs use 1MiHz instead of 1MHz */ -if (acpi_speed ==1048576 ) - acpi_speed =1000000 ; +/* +* Some DSTDs use a non standard speed, round down to the lowest +* standard speed. +*/ +for (i =1 ; i <ARRAY_SIZE (supported_speeds); i++) { +if (acpi_speed < supported_speeds[i]) +break ; + } + acpi_speed = supported_speeds[i -1 ]; +/* * Find bus speed from the "clock-frequency" device property, ACPI * or by using fast mode if neither is set.
Signature · 1 line
2.13.4
Andy Shevchenko
reviewerQuoted 43 lines · Hans de Goede
The Lenovo Miix2 8 DSDT contains an i2c clk / bus speed of 1700000 Hz for one if its devices, which is not supported.
This is the second DSDT to show up with an unsupported clk in a short time, remove the hardcoded fix for DSDTs with a 1 MiHz clock and simply
always round down the clk to the nearest supported value.Reported-by [email protected]Fixes 682c6c2188 ("i2c: designware: Some broken DSTDs use 1MiHz ...")Signed-off-by Hans de Goede <[email protected]>---
drivers/i2c/busses/i2c-designware-platdrv.c | 16 ++++++++++++----1 file changed, 12 insertions(+), 4 deletions(-)drivers/i2c/busses/i2c-designware-platdrv.c +2
-1@@ -256,7 +256,8 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) struct dw_i2c_dev *dev; u32 acpi_speed, ht = 0; struct resource *mem; -int irq, ret; +int i, irq, ret; +const int supported_speeds[] = {0 ,100000 ,400000 ,1000000 ,3400000 };
irq =platform_get_irq(pdev, 0);
if (irq < 0)drivers/i2c/busses/i2c-designware-platdrv.c +0
-0@@ -297,9 +298,16 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) }
acpi_speed=i2c_acpi_find_bus_speed(&pdev->dev);drivers/i2c/busses/i2c-designware-platdrv.c +2
-3-/* Some broken DSTDs use 1MiHz instead of 1MHz */ -if (acpi_speed ==1048576 ) - acpi_speed =1000000 ; +/* +* Some DSTDs use a non standard speed, round down to the lowest
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_probe(struct platform_device *pdev) · line 309
Quoted 7 lines
drivers/i2c/busses/i2c-designware-platdrv.c +7
-0+* standard speed. +*/ +for (i =1 ; i <ARRAY_SIZE (supported_speeds); i++) { +if (acpi_speed < supported_speeds[i]) +break ; + } + acpi_speed = supported_speeds[i -1 ];
I dunno what standard says if we may or may not use 100 kHz as a last resort even for speeds defined less than 100 kHz.
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Hi,
Quoted 46 lines · Andy Shevchenko
Quoted 45 lines · Hans de Goede
The Lenovo Miix2 8 DSDT contains an i2c clk / bus speed of 1700000 Hz for one if its devices, which is not supported.
This is the second DSDT to show up with an unsupported clk in a short time, remove the hardcoded fix for DSDTs with a 1 MiHz clock and simply
always round down the clk to the nearest supported value.Reported-by [email protected]Fixes 682c6c2188 ("i2c: designware: Some broken DSTDs use 1MiHz ...")Signed-off-by Hans de Goede <[email protected]>--- drivers/i2c/busses/i2c-designware-platdrv.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)drivers/i2c/busses/i2c-designware-platdrv.c +2
-1@@ -256,7 +256,8 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)struct dw_i2c_dev *dev;u32 acpi_speed, ht =0 ;struct resource *mem; -int irq, ret; +int i, irq, ret; +const int supported_speeds[] = {0 ,100000 ,400000 ,1000000 ,3400000 };irq = platform_get_irq(pdev, 0); if (irq < 0)drivers/i2c/busses/i2c-designware-platdrv.c +2
-3@@ -297,9 +298,16 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) } acpi_speed =i2c_acpi_find_bus_speed (&pdev->dev); -/* Some broken DSTDs use 1MiHz instead of 1MHz */ -if (acpi_speed ==1048576 ) - acpi_speed =1000000 ; +/* +* Some DSTDs use a non standard speed, round down to the lowest
drivers/i2c/busses/i2c-designware-platdrv.c +2
-0+* standard speed. +*/
Quoted 8 lines
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_probe(struct platform_device *pdev) · line 309
Quoted 5 lines
drivers/i2c/busses/i2c-designware-platdrv.c +5
-0+for (i =1 ; i <ARRAY_SIZE (supported_speeds); i++) { +if (acpi_speed < supported_speeds[i]) +break ; + } + acpi_speed = supported_speeds[i -1 ];I dunno what standard says if we may or may not use 100 kHz as a last resort even for speeds defined less than 100 kHz.
The < 100000 case is for when i2c_acpi_find_bus_speed() returns 0, so that we then keep it 0, in which case the code a bit lower will pick a default. Since speeds < 100000 are clearly not valid treating them as ACPI not providing any bus-speed info seems sensible to me.
Regards,
Hans
Jarkko Nikula
Acked-byQuoted 56 lines · Hans de Goede
Hi,
Quoted 44 lines · Andy Shevchenko
Quoted 43 lines · Hans de Goede
The Lenovo Miix2 8 DSDT contains an i2c clk / bus speed of 1700000 Hz for one if its devices, which is not supported.
This is the second DSDT to show up with an unsupported clk in a short time, remove the hardcoded fix for DSDTs with a 1 MiHz clock and simply
always round down the clk to the nearest supported value.Reported-by [email protected]Fixes 682c6c2188 ("i2c: designware: Some broken DSTDs use 1MiHz ...")Signed-off-by Hans de Goede <[email protected]>--- drivers/i2c/busses/i2c-designware-platdrv.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)drivers/i2c/busses/i2c-designware-platdrv.c +2
-1@@ -256,7 +256,8 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)struct dw_i2c_dev *dev;u32 acpi_speed, ht =0 ;struct resource *mem; -int irq, ret; +int i, irq, ret; +const int supported_speeds[] = {0 ,100000 ,400000 ,1000000 ,3400000 }; irq =platform_get_irq (pdev,0 );if (irq < 0)drivers/i2c/busses/i2c-designware-platdrv.c +2
-3@@ -297,9 +298,16 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) } acpi_speed =i2c_acpi_find_bus_speed (&pdev->dev); -/* Some broken DSTDs use 1MiHz instead of 1MHz */ -if (acpi_speed ==1048576 ) - acpi_speed =1000000 ; +/* +* Some DSTDs use a non standard speed, round down to the lowest
drivers/i2c/busses/i2c-designware-platdrv.c +2
-0+* standard speed. +*/ Quoted 8 lines
drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_probe(struct platform_device *pdev) · line 309
Quoted 5 lines
drivers/i2c/busses/i2c-designware-platdrv.c +5
-0+for (i =1 ; i <ARRAY_SIZE (supported_speeds); i++) { +if (acpi_speed < supported_speeds[i]) +break ; + } + acpi_speed = supported_speeds[i -1 ];I dunno what standard says if we may or may not use 100 kHz as a last resort even for speeds defined less than 100 kHz.
Quoted 5 lines
The < 100000 case is for when
i2c_acpi_find_bus_speed()returns 0, so that we then keep it 0, in which case the code a bit lower will pick a default. Since speeds < 100000 are clearly not valid treating them as ACPI not providing any bus-speed info seems sensible to me.
I don't know how sensible values timing parameter calculation routines would produce for "bogus" < 100 kHz ACPI speeds so picking the default 400 kHz sounds more sensible to me as well as it used to be the default speed earlier.
Hi,
Quoted 6 lines
Quoted 2 lines
I dunno what standard says if we may or may not use 100 kHz as a last resort even for speeds defined less than 100 kHz.
The < 100000 case is for when
i2c_acpi_find_bus_speed()returns 0, so that we then keep it 0, in which case the code a bit lower will pick a default.
This is fine by me.
Quoted 1 line
Since speeds < 100000 are clearly not valid treating them
Here I wonder: Not valid because of ACPI specs? Because I2C specs surely allow speeds < 100kHz.
Quoted 1 line
as ACPI not providing any bus-speed info seems sensible to me.
Regards,
Wolfram
Hi,
Quoted 9 lines · Wolfram Sang
Hi,
Quoted 6 lines
Quoted 2 lines
I dunno what standard says if we may or may not use 100 kHz as a last resort even for speeds defined less than 100 kHz.
The < 100000 case is for when
i2c_acpi_find_bus_speed()returns 0, so that we then keep it 0, in which case the code a bit lower will pick a default.
Quoted 6 lines
This is fine by me.
Quoted 1 line
Since speeds < 100000 are clearly not valid treating them
Here I wonder: Not valid because of ACPI specs? Because I2C specs surely allow speeds < 100kHz.
The speed comes from an ACPI entry describing an i2c client, any compliant i2c client must at least support 100KHz, right ?
Alternatively I could wrap the entire round-down for loop in an if (acpi_speed) {} block.
Regards,
Hans
Quoted 3 lines
The speed comes from an ACPI entry describing an i2c client, any compliant i2c client must at least support 100KHz, right ?
Well, due to flaky board design, you may not be able to utilize the max speed because of interferences etc even if the devices would support it. Such knowledge of flaky boards could be encoded in the ACPI tables, or? But probably not in the client device, hmmm...
Quoted 2 lines
Alternatively I could wrap the entire round-down for loop in an if (
acpi_speed) {} block.
I don't know enough about real-world ACPI tables to suggest a best practice here. I just wanted to add that busses < 100 kHz are legal from how I read the specs.
Oh well, Jarkko liked the patch, so let's all sleep over this patch and if nothing else comes up, I'll apply it tomorrow or so...
Quoted 12 lines · Wolfram Sang
Quoted 3 lines
The speed comes from an ACPI entry describing an i2c client, any compliant i2c client must at least support 100KHz, right ?
Well, due to flaky board design, you may not be able to utilize the max speed because of interferences etc even if the devices would support it. Such knowledge of flaky boards could be encoded in the ACPI tables, or? But probably not in the client device, hmmm...
Quoted 2 lines
Alternatively I could wrap the entire round-down for loop in an if (
acpi_speed) {} block.
Quoted 7 lines
I don't know enough about real-world ACPI tables to suggest a best practice here. I just wanted to add that busses < 100 kHz are legal from how I read the specs.
Oh well, Jarkko liked the patch, so let's all sleep over this patch and if nothing else comes up, I'll apply it tomorrow or so...
My understanding is 100k is what the client must support. But sometimes buses need to be run slower. Particularly when using range extenders.
eg: I have an i2c bus running over a 10m cable that needs to run at about 40k to be reliable.
Signature · 2 lines
Regards Phil Reid
Quoted 9 lines · Phil Reid
Quoted 7 lines · Wolfram Sang
I don't know enough about real-world ACPI tables to suggest a best practice here. I just wanted to add that busses < 100 kHz are legal from how I read the specs.
Oh well, Jarkko liked the patch, so let's all sleep over this patch and if nothing else comes up, I'll apply it tomorrow or so...
Quoted 7 lines
My understanding is 100k is what the client must support. But sometimes buses need to be run slower. Particularly when using range extenders.
eg: I have an i2c bus running over a 10m cable that needs to run at about 40k to be reliable.
I acked the patch because I see it as a possibility for a regression if we blindly accept slower than 100 kHz speed from ACPI without validating does that result working setup and timing parameters.
It is better to have an another patch explicitly adding support for < 100 kHz speeds when needed.
Signature · 1 line
Jarkko
Wolfram Sang
AppliedQuoted 10 lines · Hans de Goede
The Lenovo Miix2 8 DSDT contains an i2c clk / bus speed of 1700000 Hz for one if its devices, which is not supported.
This is the second DSDT to show up with an unsupported clk in a short time, remove the hardcoded fix for DSDTs with a 1 MiHz clock and simply always round down the clk to the nearest supported value.
Reported-by [email protected]Fixes 682c6c2188 ("i2c: designware: Some broken DSTDs use 1MiHz ...")Signed-off-by Hans de Goede <[email protected]>
Applied to for-current, thanks!