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>
This commit is contained in:
committed by
Wolfram Sang
parent
aad550f93f
commit
6d10613919
@@ -382,18 +382,18 @@ static int mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock,
|
|||||||
u32 divider;
|
u32 divider;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (clock == MPC_I2C_CLOCK_LEGACY) {
|
|
||||||
/* see below - default fdr = 0x1031 -> div = 16 * 3072 */
|
|
||||||
*real_clk = fsl_get_sys_freq() / prescaler / (16 * 3072);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Determine proper divider value */
|
/* Determine proper divider value */
|
||||||
if (of_device_is_compatible(node, "fsl,mpc8544-i2c"))
|
if (of_device_is_compatible(node, "fsl,mpc8544-i2c"))
|
||||||
prescaler = mpc_i2c_get_sec_cfg_8xxx() ? 3 : 2;
|
prescaler = mpc_i2c_get_sec_cfg_8xxx() ? 3 : 2;
|
||||||
if (!prescaler)
|
if (!prescaler)
|
||||||
prescaler = mpc_i2c_get_prescaler_8xxx();
|
prescaler = mpc_i2c_get_prescaler_8xxx();
|
||||||
|
|
||||||
|
if (clock == MPC_I2C_CLOCK_LEGACY) {
|
||||||
|
/* see below - default fdr = 0x1031 -> div = 16 * 3072 */
|
||||||
|
*real_clk = fsl_get_sys_freq() / prescaler / (16 * 3072);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
divider = fsl_get_sys_freq() / clock / prescaler;
|
divider = fsl_get_sys_freq() / clock / prescaler;
|
||||||
|
|
||||||
pr_debug("I2C: src_clock=%d clock=%d divider=%d\n",
|
pr_debug("I2C: src_clock=%d clock=%d divider=%d\n",
|
||||||
|
|||||||
Reference in New Issue
Block a user