Skip to content

Commit 83672db

Browse files
andy-shevWolfram Sang
authored andcommitted
i2c: stm32f7: switch to I²C generic property parsing
Switch to the new generic functions: i2c_parse_fw_timings(). While here, replace hard coded values with standard bus frequency definitions. Signed-off-by: Andy Shevchenko <[email protected]> Reviewed-by: Alain Volmat <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 38a592e commit 83672db

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed

drivers/i2c/busses/i2c-stm32f7.c

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,9 @@ struct stm32f7_i2c_dev {
344344
*/
345345
static struct stm32f7_i2c_spec i2c_specs[] = {
346346
[STM32_I2C_SPEED_STANDARD] = {
347-
.rate = 100000,
348-
.rate_min = 80000,
349-
.rate_max = 100000,
347+
.rate = I2C_MAX_STANDARD_MODE_FREQ,
348+
.rate_min = I2C_MAX_STANDARD_MODE_FREQ * 8 / 10, /* 80% */
349+
.rate_max = I2C_MAX_STANDARD_MODE_FREQ,
350350
.fall_max = 300,
351351
.rise_max = 1000,
352352
.hddat_min = 0,
@@ -356,9 +356,9 @@ static struct stm32f7_i2c_spec i2c_specs[] = {
356356
.h_min = 4000,
357357
},
358358
[STM32_I2C_SPEED_FAST] = {
359-
.rate = 400000,
360-
.rate_min = 320000,
361-
.rate_max = 400000,
359+
.rate = I2C_MAX_FAST_MODE_FREQ,
360+
.rate_min = I2C_MAX_FAST_MODE_FREQ * 8 / 10, /* 80% */
361+
.rate_max = I2C_MAX_FAST_MODE_FREQ,
362362
.fall_max = 300,
363363
.rise_max = 300,
364364
.hddat_min = 0,
@@ -368,9 +368,9 @@ static struct stm32f7_i2c_spec i2c_specs[] = {
368368
.h_min = 600,
369369
},
370370
[STM32_I2C_SPEED_FAST_PLUS] = {
371-
.rate = 1000000,
372-
.rate_min = 800000,
373-
.rate_max = 1000000,
371+
.rate = I2C_MAX_FAST_MODE_PLUS_FREQ,
372+
.rate_min = I2C_MAX_FAST_MODE_PLUS_FREQ * 8 / 10, /* 80% */
373+
.rate_max = I2C_MAX_FAST_MODE_PLUS_FREQ,
374374
.fall_max = 100,
375375
.rise_max = 120,
376376
.hddat_min = 0,
@@ -610,8 +610,25 @@ static int stm32f7_i2c_compute_timing(struct stm32f7_i2c_dev *i2c_dev,
610610
static int stm32f7_i2c_setup_timing(struct stm32f7_i2c_dev *i2c_dev,
611611
struct stm32f7_i2c_setup *setup)
612612
{
613+
struct i2c_timings timings, *t = &timings;
613614
int ret = 0;
614615

616+
t->bus_freq_hz = I2C_MAX_STANDARD_MODE_FREQ;
617+
t->scl_rise_ns = i2c_dev->setup.rise_time;
618+
t->scl_fall_ns = i2c_dev->setup.fall_time;
619+
620+
i2c_parse_fw_timings(i2c_dev->dev, t, false);
621+
622+
if (t->bus_freq_hz >= I2C_MAX_FAST_MODE_PLUS_FREQ)
623+
i2c_dev->speed = STM32_I2C_SPEED_FAST_PLUS;
624+
else if (t->bus_freq_hz >= I2C_MAX_FAST_MODE_FREQ)
625+
i2c_dev->speed = STM32_I2C_SPEED_FAST;
626+
else
627+
i2c_dev->speed = STM32_I2C_SPEED_STANDARD;
628+
629+
i2c_dev->setup.rise_time = t->scl_rise_ns;
630+
i2c_dev->setup.fall_time = t->scl_fall_ns;
631+
615632
setup->speed = i2c_dev->speed;
616633
setup->speed_freq = i2c_specs[setup->speed].rate;
617634
setup->clock_src = clk_get_rate(i2c_dev->clk);
@@ -1914,7 +1931,6 @@ static int stm32f7_i2c_probe(struct platform_device *pdev)
19141931
struct stm32f7_i2c_dev *i2c_dev;
19151932
const struct stm32f7_i2c_setup *setup;
19161933
struct resource *res;
1917-
u32 clk_rate, rise_time, fall_time;
19181934
struct i2c_adapter *adap;
19191935
struct reset_control *rst;
19201936
dma_addr_t phy_addr;
@@ -1961,17 +1977,6 @@ static int stm32f7_i2c_probe(struct platform_device *pdev)
19611977
return ret;
19621978
}
19631979

1964-
i2c_dev->speed = STM32_I2C_SPEED_STANDARD;
1965-
ret = device_property_read_u32(&pdev->dev, "clock-frequency",
1966-
&clk_rate);
1967-
if (!ret && clk_rate >= 1000000) {
1968-
i2c_dev->speed = STM32_I2C_SPEED_FAST_PLUS;
1969-
} else if (!ret && clk_rate >= 400000) {
1970-
i2c_dev->speed = STM32_I2C_SPEED_FAST;
1971-
} else if (!ret && clk_rate >= 100000) {
1972-
i2c_dev->speed = STM32_I2C_SPEED_STANDARD;
1973-
}
1974-
19751980
rst = devm_reset_control_get(&pdev->dev, NULL);
19761981
if (IS_ERR(rst)) {
19771982
dev_err(&pdev->dev, "Error: Missing controller reset\n");
@@ -2011,16 +2016,6 @@ static int stm32f7_i2c_probe(struct platform_device *pdev)
20112016
}
20122017
i2c_dev->setup = *setup;
20132018

2014-
ret = device_property_read_u32(i2c_dev->dev, "i2c-scl-rising-time-ns",
2015-
&rise_time);
2016-
if (!ret)
2017-
i2c_dev->setup.rise_time = rise_time;
2018-
2019-
ret = device_property_read_u32(i2c_dev->dev, "i2c-scl-falling-time-ns",
2020-
&fall_time);
2021-
if (!ret)
2022-
i2c_dev->setup.fall_time = fall_time;
2023-
20242019
ret = stm32f7_i2c_setup_timing(i2c_dev, &i2c_dev->setup);
20252020
if (ret)
20262021
goto clk_free;

0 commit comments

Comments
 (0)