diff options
author | Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 2020-03-24 13:32:16 +0100 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2020-03-24 22:36:59 +0100 |
commit | 90224e6468e15d5eb22a10ae1849cf8ca2e7360a (patch) | |
tree | f5ba968fec565daa61c1bff4d04da380873f0254 /drivers/i2c/busses/i2c-designware-platdrv.c | |
parent | i2c: algo: Use generic definitions for bus frequencies (diff) | |
download | linux-90224e6468e15d5eb22a10ae1849cf8ca2e7360a.tar.xz linux-90224e6468e15d5eb22a10ae1849cf8ca2e7360a.zip |
i2c: drivers: Use generic definitions for bus frequencies
Since we have generic definitions for bus frequencies, let's use them.
Reviewed-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Acked-by: Robert Richter <rrichter@marvell.com>
Reviewed-by: Thor Thayer <thor.thayer@linux.intel.com>
Acked-by: Elie Morisse <syniurge@gmail.com>
Acked-by: Nehal Shah <nehal-bakulchandra.shah@amd.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Acked-by: Scott Branden <scott.branden@broadcom.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Acked-by: Baruch Siach <baruch@tkos.co.il>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
Acked-by: Vladimir Zapolskiy <vz@mleia.com>
Acked-by: Gregory CLEMENT <gregory.clement@bootlin.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Reviewed-by: Chris Brandt <chris.brandt@renesas.com>
Reviewed-by: Baolin Wang <baolin.wang7@gmail.com>
Reviewed-by: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>
Acked-by: Patrice Chotard <patrice.chotard@st.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
Acked-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c/busses/i2c-designware-platdrv.c')
-rw-r--r-- | drivers/i2c/busses/i2c-designware-platdrv.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index cb494273bb60..c98befe2a92e 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -99,16 +99,16 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev) dw_i2c_acpi_params(pdev, "FMCN", &dev->fs_hcnt, &dev->fs_lcnt, &fs_ht); switch (t->bus_freq_hz) { - case 100000: + case I2C_MAX_STANDARD_MODE_FREQ: dev->sda_hold_time = ss_ht; break; - case 1000000: + case I2C_MAX_FAST_MODE_PLUS_FREQ: dev->sda_hold_time = fp_ht; break; - case 3400000: + case I2C_MAX_HIGH_SPEED_MODE_FREQ: dev->sda_hold_time = hs_ht; break; - case 400000: + case I2C_MAX_FAST_MODE_FREQ: default: dev->sda_hold_time = fs_ht; break; @@ -198,10 +198,10 @@ static void i2c_dw_configure_master(struct dw_i2c_dev *dev) dev->mode = DW_IC_MASTER; switch (t->bus_freq_hz) { - case 100000: + case I2C_MAX_STANDARD_MODE_FREQ: dev->master_cfg |= DW_IC_CON_SPEED_STD; break; - case 3400000: + case I2C_MAX_HIGH_SPEED_MODE_FREQ: dev->master_cfg |= DW_IC_CON_SPEED_HIGH; break; default: @@ -227,6 +227,13 @@ static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev) pm_runtime_put_noidle(dev->dev); } +static const u32 supported_speeds[] = { + I2C_MAX_HIGH_SPEED_MODE_FREQ, + I2C_MAX_FAST_MODE_PLUS_FREQ, + I2C_MAX_FAST_MODE_FREQ, + I2C_MAX_STANDARD_MODE_FREQ, +}; + static int dw_i2c_plat_probe(struct platform_device *pdev) { struct dw_i2c_platform_data *pdata = dev_get_platdata(&pdev->dev); @@ -236,9 +243,6 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) u32 acpi_speed; struct resource *mem; int i, irq, ret; - static const int supported_speeds[] = { - 0, 100000, 400000, 1000000, 3400000 - }; irq = platform_get_irq(pdev, 0); if (irq < 0) @@ -274,11 +278,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) * 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]) + for (i = 0; i < ARRAY_SIZE(supported_speeds); i++) { + if (acpi_speed >= supported_speeds[i]) break; } - acpi_speed = supported_speeds[i - 1]; + acpi_speed = i < ARRAY_SIZE(supported_speeds) ? supported_speeds[i] : 0; /* * Find bus speed from the "clock-frequency" device property, ACPI @@ -289,7 +293,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) else if (acpi_speed || t->bus_freq_hz) t->bus_freq_hz = max(t->bus_freq_hz, acpi_speed); else - t->bus_freq_hz = 400000; + t->bus_freq_hz = I2C_MAX_FAST_MODE_FREQ; dev->flags |= (uintptr_t)device_get_match_data(&pdev->dev); @@ -303,8 +307,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) * Only standard mode at 100kHz, fast mode at 400kHz, * fast mode plus at 1MHz and high speed mode at 3.4MHz are supported. */ - if (t->bus_freq_hz != 100000 && t->bus_freq_hz != 400000 && - t->bus_freq_hz != 1000000 && t->bus_freq_hz != 3400000) { + for (i = 0; i < ARRAY_SIZE(supported_speeds); i++) { + if (t->bus_freq_hz == supported_speeds[i]) + break; + } + if (i == ARRAY_SIZE(supported_speeds)) { dev_err(&pdev->dev, "%d Hz is unsupported, only 100kHz, 400kHz, 1MHz and 3.4MHz are supported\n", t->bus_freq_hz); |