diff options
author | Arseny Solokha <asolokha@kb.kras.ru> | 2017-12-07 05:20:00 -0500 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2018-01-15 13:13:06 -0500 |
commit | 6d106139191e58b9f4ef126cfc1e3c26c0d6702e (patch) | |
tree | e72c8ea76087ae8cb8ed739865d07e167ab05b5d | |
parent | aad550f93fbc28d562a624700f9c12c9b9055a5e (diff) |
i2c: mpc: get MPC8xxx I2C clock prescaler before using it in calculations
Obtaining the actual I2C clock prescaler value in mpc_i2c_setup_8xxx() only
happens when the clock parameter is set to something other than
MPC_I2C_CLOCK_LEGACY. When the clock parameter is exactly
MPC_I2C_CLOCK_LEGACY, the prescaler parameter is used in arithmetic
division as provided by the caller, resulting in a division by zero
for the majority of processors supported by the module.
Avoid division by zero by obtaining the actual I2C clock prescaler
in mpc_i2c_setup_8xxx() unconditionally regardless of the passed clock
value.
Signed-off-by: Arseny Solokha <asolokha@kb.kras.ru>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
-rw-r--r-- | drivers/i2c/busses/i2c-mpc.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c index 950a9d74f54d..6ad87555f71e 100644 --- a/drivers/i2c/busses/i2c-mpc.c +++ b/drivers/i2c/busses/i2c-mpc.c | |||
@@ -382,18 +382,18 @@ static int mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock, | |||
382 | u32 divider; | 382 | u32 divider; |
383 | int i; | 383 | int i; |
384 | 384 | ||
385 | if (clock == MPC_I2C_CLOCK_LEGACY) { | ||
386 | /* see below - default fdr = 0x1031 -> div = 16 * 3072 */ | ||
387 | *real_clk = fsl_get_sys_freq() / prescaler / (16 * 3072); | ||
388 | return -EINVAL; | ||
389 | } | ||
390 | |||
391 | /* Determine proper divider value */ | 385 | /* Determine proper divider value */ |
392 | if (of_device_is_compatible(node, "fsl,mpc8544-i2c")) | 386 | if (of_device_is_compatible(node, "fsl,mpc8544-i2c")) |
393 | prescaler = mpc_i2c_get_sec_cfg_8xxx() ? 3 : 2; | 387 | prescaler = mpc_i2c_get_sec_cfg_8xxx() ? 3 : 2; |
394 | if (!prescaler) | 388 | if (!prescaler) |
395 | prescaler = mpc_i2c_get_prescaler_8xxx(); | 389 | prescaler = mpc_i2c_get_prescaler_8xxx(); |
396 | 390 | ||
391 | if (clock == MPC_I2C_CLOCK_LEGACY) { | ||
392 | /* see below - default fdr = 0x1031 -> div = 16 * 3072 */ | ||
393 | *real_clk = fsl_get_sys_freq() / prescaler / (16 * 3072); | ||
394 | return -EINVAL; | ||
395 | } | ||
396 | |||
397 | divider = fsl_get_sys_freq() / clock / prescaler; | 397 | divider = fsl_get_sys_freq() / clock / prescaler; |
398 | 398 | ||
399 | pr_debug("I2C: src_clock=%d clock=%d divider=%d\n", | 399 | pr_debug("I2C: src_clock=%d clock=%d divider=%d\n", |