Commit 20ee1d90 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Wolfram Sang

i2c: designware: Move i2c_dw_validate_speed() helper to a common code

In order to export array supported speed for wider use, move it
to a header along with i2c_dw_validate_speed() helper moved to
a common code.

No functional changes intended.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: default avatarJarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
parent a19f133f
...@@ -116,6 +116,30 @@ int i2c_dw_set_reg_access(struct dw_i2c_dev *dev) ...@@ -116,6 +116,30 @@ int i2c_dw_set_reg_access(struct dw_i2c_dev *dev)
return 0; return 0;
} }
int i2c_dw_validate_speed(struct dw_i2c_dev *dev)
{
struct i2c_timings *t = &dev->timings;
unsigned int i;
/*
* Only standard mode at 100kHz, fast mode at 400kHz,
* fast mode plus at 1MHz and high speed mode at 3.4MHz are supported.
*/
for (i = 0; i < ARRAY_SIZE(i2c_dw_supported_speeds); i++) {
if (t->bus_freq_hz == i2c_dw_supported_speeds[i])
break;
}
if (i == ARRAY_SIZE(i2c_dw_supported_speeds)) {
dev_err(dev->dev,
"%d Hz is unsupported, only 100kHz, 400kHz, 1MHz and 3.4MHz are supported\n",
t->bus_freq_hz);
return -EINVAL;
}
return 0;
}
EXPORT_SYMBOL_GPL(i2c_dw_validate_speed);
u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset) u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
{ {
/* /*
......
...@@ -359,3 +359,12 @@ extern int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev); ...@@ -359,3 +359,12 @@ extern int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev);
#else #else
static inline int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev) { return 0; } static inline int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev) { return 0; }
#endif #endif
static __maybe_unused const u32 i2c_dw_supported_speeds[] = {
I2C_MAX_HIGH_SPEED_MODE_FREQ,
I2C_MAX_FAST_MODE_PLUS_FREQ,
I2C_MAX_FAST_MODE_FREQ,
I2C_MAX_STANDARD_MODE_FREQ,
};
int i2c_dw_validate_speed(struct dw_i2c_dev *dev);
...@@ -192,13 +192,6 @@ static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev) ...@@ -192,13 +192,6 @@ static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev)
pm_runtime_put_noidle(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) static int dw_i2c_plat_probe(struct platform_device *pdev)
{ {
struct dw_i2c_platform_data *pdata = dev_get_platdata(&pdev->dev); struct dw_i2c_platform_data *pdata = dev_get_platdata(&pdev->dev);
...@@ -241,11 +234,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) ...@@ -241,11 +234,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
* Some DSTDs use a non standard speed, round down to the lowest * Some DSTDs use a non standard speed, round down to the lowest
* standard speed. * standard speed.
*/ */
for (i = 0; i < ARRAY_SIZE(supported_speeds); i++) { for (i = 0; i < ARRAY_SIZE(i2c_dw_supported_speeds); i++) {
if (acpi_speed >= supported_speeds[i]) if (acpi_speed >= i2c_dw_supported_speeds[i])
break; break;
} }
acpi_speed = i < ARRAY_SIZE(supported_speeds) ? supported_speeds[i] : 0; acpi_speed = i < ARRAY_SIZE(i2c_dw_supported_speeds) ? i2c_dw_supported_speeds[i] : 0;
/* /*
* Find bus speed from the "clock-frequency" device property, ACPI * Find bus speed from the "clock-frequency" device property, ACPI
...@@ -266,21 +259,9 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) ...@@ -266,21 +259,9 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
if (has_acpi_companion(&pdev->dev)) if (has_acpi_companion(&pdev->dev))
dw_i2c_acpi_configure(pdev); dw_i2c_acpi_configure(pdev);
/* ret = i2c_dw_validate_speed(dev);
* Only standard mode at 100kHz, fast mode at 400kHz, if (ret)
* fast mode plus at 1MHz and high speed mode at 3.4MHz are supported.
*/
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);
ret = -EINVAL;
goto exit_reset; goto exit_reset;
}
ret = i2c_dw_probe_lock_support(dev); ret = i2c_dw_probe_lock_support(dev);
if (ret) if (ret)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment