Skip to content

Commit 90224e6

Browse files
andy-shevWolfram Sang
authored andcommitted
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 <[email protected]> Acked-by: Robert Richter <[email protected]> Reviewed-by: Thor Thayer <[email protected]> Acked-by: Elie Morisse <[email protected]> Acked-by: Nehal Shah <[email protected]> Reviewed-by: Brendan Higgins <[email protected]> Acked-by: Scott Branden <[email protected]> Reviewed-by: Mika Westerberg <[email protected]> Acked-by: Jarkko Nikula <[email protected]> Acked-by: Baruch Siach <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Acked-by: Oleksij Rempel <[email protected]> Acked-by: Vladimir Zapolskiy <[email protected]> Acked-by: Gregory CLEMENT <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Reviewed-by: Chris Brandt <[email protected]> Reviewed-by: Baolin Wang <[email protected]> Reviewed-by: Pierre-Yves MORDRET <[email protected]> Acked-by: Patrice Chotard <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Reviewed-by: Dmitry Osipenko <[email protected]> Acked-by: Masahiro Yamada <[email protected]> Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 7b8c4c0 commit 90224e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+165
-199
lines changed

drivers/i2c/busses/i2c-altera.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static void altr_i2c_init(struct altr_i2c_dev *idev)
147147
(ALTR_I2C_THRESHOLD << ALTR_I2C_CTRL_TCT_SHFT);
148148
u32 t_high, t_low;
149149

150-
if (idev->bus_clk_rate <= 100000) {
150+
if (idev->bus_clk_rate <= I2C_MAX_STANDARD_MODE_FREQ) {
151151
tmp &= ~ALTR_I2C_CTRL_BSPEED;
152152
/* Standard mode SCL 50/50 */
153153
t_high = divisor * 1 / 2;
@@ -423,10 +423,10 @@ static int altr_i2c_probe(struct platform_device *pdev)
423423
&idev->bus_clk_rate);
424424
if (val) {
425425
dev_err(&pdev->dev, "Default to 100kHz\n");
426-
idev->bus_clk_rate = 100000; /* default clock rate */
426+
idev->bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; /* default clock rate */
427427
}
428428

429-
if (idev->bus_clk_rate > 400000) {
429+
if (idev->bus_clk_rate > I2C_MAX_FAST_MODE_FREQ) {
430430
dev_err(&pdev->dev, "invalid clock-frequency %d\n",
431431
idev->bus_clk_rate);
432432
return -EINVAL;

drivers/i2c/busses/i2c-amd-mp2-plat.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,32 +201,37 @@ static int i2c_amd_resume(struct amd_i2c_common *i2c_common)
201201
}
202202
#endif
203203

204+
static const u32 supported_speeds[] = {
205+
I2C_MAX_HIGH_SPEED_MODE_FREQ,
206+
I2C_MAX_TURBO_MODE_FREQ,
207+
I2C_MAX_FAST_MODE_PLUS_FREQ,
208+
I2C_MAX_FAST_MODE_FREQ,
209+
I2C_MAX_STANDARD_MODE_FREQ,
210+
};
211+
204212
static enum speed_enum i2c_amd_get_bus_speed(struct platform_device *pdev)
205213
{
206214
u32 acpi_speed;
207215
int i;
208-
static const u32 supported_speeds[] = {
209-
0, 100000, 400000, 1000000, 1400000, 3400000
210-
};
211216

212217
acpi_speed = i2c_acpi_find_bus_speed(&pdev->dev);
213218
/* round down to the lowest standard speed */
214-
for (i = 1; i < ARRAY_SIZE(supported_speeds); i++) {
215-
if (acpi_speed < supported_speeds[i])
219+
for (i = 0; i < ARRAY_SIZE(supported_speeds); i++) {
220+
if (acpi_speed >= supported_speeds[i])
216221
break;
217222
}
218-
acpi_speed = supported_speeds[i - 1];
223+
acpi_speed = i < ARRAY_SIZE(supported_speeds) ? supported_speeds[i] : 0;
219224

220225
switch (acpi_speed) {
221-
case 100000:
226+
case I2C_MAX_STANDARD_MODE_FREQ:
222227
return speed100k;
223-
case 400000:
228+
case I2C_MAX_FAST_MODE_FREQ:
224229
return speed400k;
225-
case 1000000:
230+
case I2C_MAX_FAST_MODE_PLUS_FREQ:
226231
return speed1000k;
227-
case 1400000:
232+
case I2C_MAX_TURBO_MODE_FREQ:
228233
return speed1400k;
229-
case 3400000:
234+
case I2C_MAX_HIGH_SPEED_MODE_FREQ:
230235
return speed3400k;
231236
default:
232237
return speed400k;

drivers/i2c/busses/i2c-aspeed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ static int aspeed_i2c_probe_bus(struct platform_device *pdev)
997997
if (ret < 0) {
998998
dev_err(&pdev->dev,
999999
"Could not read bus-frequency property\n");
1000-
bus->bus_frequency = 100000;
1000+
bus->bus_frequency = I2C_MAX_STANDARD_MODE_FREQ;
10011001
}
10021002

10031003
match = of_match_node(aspeed_i2c_bus_of_table, pdev->dev.of_node);

drivers/i2c/busses/i2c-axxia.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static int axxia_i2c_init(struct axxia_i2c_dev *idev)
199199
/* Enable Master Mode */
200200
writel(0x1, idev->base + GLOBAL_CONTROL);
201201

202-
if (idev->bus_clk_rate <= 100000) {
202+
if (idev->bus_clk_rate <= I2C_MAX_STANDARD_MODE_FREQ) {
203203
/* Standard mode SCL 50/50, tSU:DAT = 250 ns */
204204
t_high = divisor * 1 / 2;
205205
t_low = divisor * 1 / 2;
@@ -765,7 +765,7 @@ static int axxia_i2c_probe(struct platform_device *pdev)
765765

766766
of_property_read_u32(np, "clock-frequency", &idev->bus_clk_rate);
767767
if (idev->bus_clk_rate == 0)
768-
idev->bus_clk_rate = 100000; /* default clock rate */
768+
idev->bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; /* default clock rate */
769769

770770
ret = clk_prepare_enable(idev->i2c_clk);
771771
if (ret) {

drivers/i2c/busses/i2c-bcm-iproc.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -858,25 +858,25 @@ static int bcm_iproc_i2c_cfg_speed(struct bcm_iproc_i2c_dev *iproc_i2c)
858858
if (ret < 0) {
859859
dev_info(iproc_i2c->device,
860860
"unable to interpret clock-frequency DT property\n");
861-
bus_speed = 100000;
861+
bus_speed = I2C_MAX_STANDARD_MODE_FREQ;
862862
}
863863

864-
if (bus_speed < 100000) {
864+
if (bus_speed < I2C_MAX_STANDARD_MODE_FREQ) {
865865
dev_err(iproc_i2c->device, "%d Hz bus speed not supported\n",
866866
bus_speed);
867867
dev_err(iproc_i2c->device,
868868
"valid speeds are 100khz and 400khz\n");
869869
return -EINVAL;
870-
} else if (bus_speed < 400000) {
871-
bus_speed = 100000;
870+
} else if (bus_speed < I2C_MAX_FAST_MODE_FREQ) {
871+
bus_speed = I2C_MAX_STANDARD_MODE_FREQ;
872872
} else {
873-
bus_speed = 400000;
873+
bus_speed = I2C_MAX_FAST_MODE_FREQ;
874874
}
875875

876876
iproc_i2c->bus_speed = bus_speed;
877877
val = iproc_i2c_rd_reg(iproc_i2c, TIM_CFG_OFFSET);
878878
val &= ~BIT(TIM_CFG_MODE_400_SHIFT);
879-
val |= (bus_speed == 400000) << TIM_CFG_MODE_400_SHIFT;
879+
val |= (bus_speed == I2C_MAX_FAST_MODE_FREQ) << TIM_CFG_MODE_400_SHIFT;
880880
iproc_i2c_wr_reg(iproc_i2c, TIM_CFG_OFFSET, val);
881881

882882
dev_info(iproc_i2c->device, "bus set to %u Hz\n", bus_speed);
@@ -1029,7 +1029,7 @@ static int bcm_iproc_i2c_resume(struct device *dev)
10291029
/* configure to the desired bus speed */
10301030
val = iproc_i2c_rd_reg(iproc_i2c, TIM_CFG_OFFSET);
10311031
val &= ~BIT(TIM_CFG_MODE_400_SHIFT);
1032-
val |= (iproc_i2c->bus_speed == 400000) << TIM_CFG_MODE_400_SHIFT;
1032+
val |= (iproc_i2c->bus_speed == I2C_MAX_FAST_MODE_FREQ) << TIM_CFG_MODE_400_SHIFT;
10331033
iproc_i2c_wr_reg(iproc_i2c, TIM_CFG_OFFSET, val);
10341034

10351035
bcm_iproc_i2c_enable_disable(iproc_i2c, true);

drivers/i2c/busses/i2c-bcm-kona.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,16 +722,16 @@ static int bcm_kona_i2c_assign_bus_speed(struct bcm_kona_i2c_dev *dev)
722722
}
723723

724724
switch (bus_speed) {
725-
case 100000:
725+
case I2C_MAX_STANDARD_MODE_FREQ:
726726
dev->std_cfg = &std_cfg_table[BCM_SPD_100K];
727727
break;
728-
case 400000:
728+
case I2C_MAX_FAST_MODE_FREQ:
729729
dev->std_cfg = &std_cfg_table[BCM_SPD_400K];
730730
break;
731-
case 1000000:
731+
case I2C_MAX_FAST_MODE_PLUS_FREQ:
732732
dev->std_cfg = &std_cfg_table[BCM_SPD_1MHZ];
733733
break;
734-
case 3400000:
734+
case I2C_MAX_HIGH_SPEED_MODE_FREQ:
735735
/* Send mastercode at 100k */
736736
dev->std_cfg = &std_cfg_table[BCM_SPD_100K];
737737
dev->hs_cfg = &hs_cfg_table[BCM_SPD_3P4MHZ];

drivers/i2c/busses/i2c-bcm2835.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
439439
if (ret < 0) {
440440
dev_warn(&pdev->dev,
441441
"Could not read clock-frequency property\n");
442-
bus_clk_rate = 100000;
442+
bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ;
443443
}
444444

445445
ret = clk_set_rate_exclusive(i2c_dev->bus_clk, bus_clk_rate);

drivers/i2c/busses/i2c-cadence.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@
104104

105105
#define DRIVER_NAME "cdns-i2c"
106106

107-
#define CDNS_I2C_SPEED_MAX 400000
108-
#define CDNS_I2C_SPEED_DEFAULT 100000
109-
110107
#define CDNS_I2C_DIVA_MAX 4
111108
#define CDNS_I2C_DIVB_MAX 64
112109

@@ -949,8 +946,8 @@ static int cdns_i2c_probe(struct platform_device *pdev)
949946

950947
ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
951948
&id->i2c_clk);
952-
if (ret || (id->i2c_clk > CDNS_I2C_SPEED_MAX))
953-
id->i2c_clk = CDNS_I2C_SPEED_DEFAULT;
949+
if (ret || (id->i2c_clk > I2C_MAX_FAST_MODE_FREQ))
950+
id->i2c_clk = I2C_MAX_STANDARD_MODE_FREQ;
954951

955952
cdns_i2c_writereg(CDNS_I2C_CR_ACK_EN | CDNS_I2C_CR_NEA | CDNS_I2C_CR_MS,
956953
CDNS_I2C_CR_OFFSET);

drivers/i2c/busses/i2c-designware-platdrv.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,16 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev)
9999
dw_i2c_acpi_params(pdev, "FMCN", &dev->fs_hcnt, &dev->fs_lcnt, &fs_ht);
100100

101101
switch (t->bus_freq_hz) {
102-
case 100000:
102+
case I2C_MAX_STANDARD_MODE_FREQ:
103103
dev->sda_hold_time = ss_ht;
104104
break;
105-
case 1000000:
105+
case I2C_MAX_FAST_MODE_PLUS_FREQ:
106106
dev->sda_hold_time = fp_ht;
107107
break;
108-
case 3400000:
108+
case I2C_MAX_HIGH_SPEED_MODE_FREQ:
109109
dev->sda_hold_time = hs_ht;
110110
break;
111-
case 400000:
111+
case I2C_MAX_FAST_MODE_FREQ:
112112
default:
113113
dev->sda_hold_time = fs_ht;
114114
break;
@@ -198,10 +198,10 @@ static void i2c_dw_configure_master(struct dw_i2c_dev *dev)
198198
dev->mode = DW_IC_MASTER;
199199

200200
switch (t->bus_freq_hz) {
201-
case 100000:
201+
case I2C_MAX_STANDARD_MODE_FREQ:
202202
dev->master_cfg |= DW_IC_CON_SPEED_STD;
203203
break;
204-
case 3400000:
204+
case I2C_MAX_HIGH_SPEED_MODE_FREQ:
205205
dev->master_cfg |= DW_IC_CON_SPEED_HIGH;
206206
break;
207207
default:
@@ -227,6 +227,13 @@ static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev)
227227
pm_runtime_put_noidle(dev->dev);
228228
}
229229

230+
static const u32 supported_speeds[] = {
231+
I2C_MAX_HIGH_SPEED_MODE_FREQ,
232+
I2C_MAX_FAST_MODE_PLUS_FREQ,
233+
I2C_MAX_FAST_MODE_FREQ,
234+
I2C_MAX_STANDARD_MODE_FREQ,
235+
};
236+
230237
static int dw_i2c_plat_probe(struct platform_device *pdev)
231238
{
232239
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)
236243
u32 acpi_speed;
237244
struct resource *mem;
238245
int i, irq, ret;
239-
static const int supported_speeds[] = {
240-
0, 100000, 400000, 1000000, 3400000
241-
};
242246

243247
irq = platform_get_irq(pdev, 0);
244248
if (irq < 0)
@@ -274,11 +278,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
274278
* Some DSTDs use a non standard speed, round down to the lowest
275279
* standard speed.
276280
*/
277-
for (i = 1; i < ARRAY_SIZE(supported_speeds); i++) {
278-
if (acpi_speed < supported_speeds[i])
281+
for (i = 0; i < ARRAY_SIZE(supported_speeds); i++) {
282+
if (acpi_speed >= supported_speeds[i])
279283
break;
280284
}
281-
acpi_speed = supported_speeds[i - 1];
285+
acpi_speed = i < ARRAY_SIZE(supported_speeds) ? supported_speeds[i] : 0;
282286

283287
/*
284288
* Find bus speed from the "clock-frequency" device property, ACPI
@@ -289,7 +293,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
289293
else if (acpi_speed || t->bus_freq_hz)
290294
t->bus_freq_hz = max(t->bus_freq_hz, acpi_speed);
291295
else
292-
t->bus_freq_hz = 400000;
296+
t->bus_freq_hz = I2C_MAX_FAST_MODE_FREQ;
293297

294298
dev->flags |= (uintptr_t)device_get_match_data(&pdev->dev);
295299

@@ -303,8 +307,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
303307
* Only standard mode at 100kHz, fast mode at 400kHz,
304308
* fast mode plus at 1MHz and high speed mode at 3.4MHz are supported.
305309
*/
306-
if (t->bus_freq_hz != 100000 && t->bus_freq_hz != 400000 &&
307-
t->bus_freq_hz != 1000000 && t->bus_freq_hz != 3400000) {
310+
for (i = 0; i < ARRAY_SIZE(supported_speeds); i++) {
311+
if (t->bus_freq_hz == supported_speeds[i])
312+
break;
313+
}
314+
if (i == ARRAY_SIZE(supported_speeds)) {
308315
dev_err(&pdev->dev,
309316
"%d Hz is unsupported, only 100kHz, 400kHz, 1MHz and 3.4MHz are supported\n",
310317
t->bus_freq_hz);

drivers/i2c/busses/i2c-digicolor.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <linux/of.h>
1919
#include <linux/platform_device.h>
2020

21-
#define DEFAULT_FREQ 100000
2221
#define TIMEOUT_MS 100
2322

2423
#define II_CONTROL 0x0
@@ -300,7 +299,7 @@ static int dc_i2c_probe(struct platform_device *pdev)
300299

301300
if (of_property_read_u32(pdev->dev.of_node, "clock-frequency",
302301
&i2c->frequency))
303-
i2c->frequency = DEFAULT_FREQ;
302+
i2c->frequency = I2C_MAX_STANDARD_MODE_FREQ;
304303

305304
i2c->dev = &pdev->dev;
306305
platform_set_drvdata(pdev, i2c);

0 commit comments

Comments
 (0)