Skip to content

Commit 263a564

Browse files
andy-shevWolfram Sang
authored andcommitted
i2c: core: Allow override timing properties with 0
Some drivers may allow to override properties with 0 value when defaults are not in use, thus, replace memset() with corresponding per property update. Signed-off-by: Andy Shevchenko <[email protected]> Tested-by: Wolfram Sang <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent e6282fc commit 263a564

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

drivers/i2c/busses/i2c-rcar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ static int rcar_i2c_probe(struct platform_device *pdev)
920920
struct rcar_i2c_priv *priv;
921921
struct i2c_adapter *adap;
922922
struct device *dev = &pdev->dev;
923-
struct i2c_timings i2c_t;
923+
struct i2c_timings i2c_t = { 0 };
924924
int ret;
925925

926926
/* Otherwise logic will break because some bytes must always use PIO */

drivers/i2c/i2c-core-base.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,23 +1593,21 @@ EXPORT_SYMBOL(i2c_del_adapter);
15931593
* @dev: The device to scan for I2C timing properties
15941594
* @t: the i2c_timings struct to be filled with values
15951595
* @use_defaults: bool to use sane defaults derived from the I2C specification
1596-
* when properties are not found, otherwise use 0
1596+
* when properties are not found, otherwise don't update
15971597
*
15981598
* Scan the device for the generic I2C properties describing timing parameters
15991599
* for the signal and fill the given struct with the results. If a property was
16001600
* not found and use_defaults was true, then maximum timings are assumed which
16011601
* are derived from the I2C specification. If use_defaults is not used, the
1602-
* results will be 0, so drivers can apply their own defaults later. The latter
1603-
* is mainly intended for avoiding regressions of existing drivers which want
1604-
* to switch to this function. New drivers almost always should use the defaults.
1602+
* results will be as before, so drivers can apply their own defaults before
1603+
* calling this helper. The latter is mainly intended for avoiding regressions
1604+
* of existing drivers which want to switch to this function. New drivers
1605+
* almost always should use the defaults.
16051606
*/
1606-
16071607
void i2c_parse_fw_timings(struct device *dev, struct i2c_timings *t, bool use_defaults)
16081608
{
16091609
int ret;
16101610

1611-
memset(t, 0, sizeof(*t));
1612-
16131611
ret = device_property_read_u32(dev, "clock-frequency", &t->bus_freq_hz);
16141612
if (ret && use_defaults)
16151613
t->bus_freq_hz = I2C_MAX_STANDARD_MODE_FREQ;
@@ -1632,19 +1630,25 @@ void i2c_parse_fw_timings(struct device *dev, struct i2c_timings *t, bool use_de
16321630
t->scl_fall_ns = 120;
16331631
}
16341632

1635-
device_property_read_u32(dev, "i2c-scl-internal-delay-ns", &t->scl_int_delay_ns);
1633+
ret = device_property_read_u32(dev, "i2c-scl-internal-delay-ns", &t->scl_int_delay_ns);
1634+
if (ret && use_defaults)
1635+
t->scl_int_delay_ns = 0;
16361636

16371637
ret = device_property_read_u32(dev, "i2c-sda-falling-time-ns", &t->sda_fall_ns);
16381638
if (ret && use_defaults)
16391639
t->sda_fall_ns = t->scl_fall_ns;
16401640

1641-
device_property_read_u32(dev, "i2c-sda-hold-time-ns", &t->sda_hold_ns);
1641+
ret = device_property_read_u32(dev, "i2c-sda-hold-time-ns", &t->sda_hold_ns);
1642+
if (ret && use_defaults)
1643+
t->sda_hold_ns = 0;
16421644

1643-
device_property_read_u32(dev, "i2c-digital-filter-width-ns",
1644-
&t->digital_filter_width_ns);
1645+
ret = device_property_read_u32(dev, "i2c-digital-filter-width-ns", &t->digital_filter_width_ns);
1646+
if (ret && use_defaults)
1647+
t->digital_filter_width_ns = 0;
16451648

1646-
device_property_read_u32(dev, "i2c-analog-filter-cutoff-frequency",
1647-
&t->analog_filter_cutoff_freq_hz);
1649+
ret = device_property_read_u32(dev, "i2c-analog-filter-cutoff-frequency", &t->analog_filter_cutoff_freq_hz);
1650+
if (ret && use_defaults)
1651+
t->analog_filter_cutoff_freq_hz = 0;
16481652
}
16491653
EXPORT_SYMBOL_GPL(i2c_parse_fw_timings);
16501654

0 commit comments

Comments
 (0)