bcm27xx: update 6.1 patches from RPi foundation
[openwrt/staging/stintel.git] / target / linux / bcm27xx / patches-6.1 / 950-1258-i2c-designware-Support-non-standard-bus-speeds.patch
1 From 6868dba87e2765042ac376a4a8427b9b981cd410 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.com>
3 Date: Tue, 16 Jan 2024 16:03:14 +0000
4 Subject: [PATCH 1258/1295] i2c: designware: Support non-standard bus speeds
5
6 Add support for non-standard bus speeds by treating them as detuned
7 versions of the slowest standard speed not less than the requested
8 speed.
9
10 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
11 ---
12 drivers/i2c/busses/i2c-designware-common.c | 27 ++++++++++++++++++++++
13 drivers/i2c/busses/i2c-designware-core.h | 1 +
14 drivers/i2c/busses/i2c-designware-master.c | 2 +-
15 3 files changed, 29 insertions(+), 1 deletion(-)
16
17 --- a/drivers/i2c/busses/i2c-designware-common.c
18 +++ b/drivers/i2c/busses/i2c-designware-common.c
19 @@ -318,6 +318,9 @@ void i2c_dw_adjust_bus_speed(struct dw_i
20 {
21 u32 acpi_speed = i2c_dw_acpi_round_bus_speed(dev->dev);
22 struct i2c_timings *t = &dev->timings;
23 + u32 wanted_speed;
24 + u32 legal_speed = 0;
25 + int i;
26
27 /*
28 * Find bus speed from the "clock-frequency" device property, ACPI
29 @@ -329,6 +332,30 @@ void i2c_dw_adjust_bus_speed(struct dw_i
30 t->bus_freq_hz = max(t->bus_freq_hz, acpi_speed);
31 else
32 t->bus_freq_hz = I2C_MAX_FAST_MODE_FREQ;
33 +
34 + wanted_speed = t->bus_freq_hz;
35 +
36 + /* For unsupported speeds, scale down the lowest speed which is faster. */
37 + for (i = 0; i < ARRAY_SIZE(supported_speeds); i++) {
38 + /* supported speeds is in decreasing order */
39 + if (wanted_speed == supported_speeds[i]) {
40 + legal_speed = 0;
41 + break;
42 + }
43 + if (wanted_speed > supported_speeds[i])
44 + break;
45 +
46 + legal_speed = supported_speeds[i];
47 + }
48 +
49 + if (legal_speed) {
50 + /*
51 + * Pretend this was the requested speed, but preserve the preferred
52 + * speed so the clock counts can be scaled.
53 + */
54 + t->bus_freq_hz = legal_speed;
55 + dev->wanted_bus_speed = wanted_speed;
56 + }
57 }
58 EXPORT_SYMBOL_GPL(i2c_dw_adjust_bus_speed);
59
60 --- a/drivers/i2c/busses/i2c-designware-core.h
61 +++ b/drivers/i2c/busses/i2c-designware-core.h
62 @@ -287,6 +287,7 @@ struct dw_i2c_dev {
63 u16 fp_lcnt;
64 u16 hs_hcnt;
65 u16 hs_lcnt;
66 + u32 wanted_bus_speed;
67 int (*acquire_lock)(void);
68 void (*release_lock)(void);
69 int semaphore_idx;
70 --- a/drivers/i2c/busses/i2c-designware-master.c
71 +++ b/drivers/i2c/busses/i2c-designware-master.c
72 @@ -41,7 +41,7 @@ static void i2c_dw_configure_fifo_master
73 static u16 clock_calc(struct dw_i2c_dev *dev, bool want_high)
74 {
75 struct i2c_timings *t = &dev->timings;
76 - u32 wanted_speed = t->bus_freq_hz;
77 + u32 wanted_speed = dev->wanted_bus_speed ?: t->bus_freq_hz;
78 u32 clk_khz = i2c_dw_clk_rate(dev);
79 u32 extra_ns = want_high ? t->scl_fall_ns : t->scl_rise_ns;
80 u32 extra_cycles = (u32)div_u64((u64)clk_khz * extra_ns, 1000000);