Re: [PATCH v6] i2c: rk3x: handle dynamic clock rate changes correctly

Doug Anderson
2014-11-20T06:16:23Z

Max,

On Tue, Nov 18, 2014 at 3:18 PM, Max Schwarz <max.schwarz-BGeptl67XyCzQB+pC5nmwQ@public.gmane.org> wrote:
> -static int rk3x_i2c_calc_divs(unsigned long i2c_rate, unsigned long scl_rate,
> - unsigned long *div_low, unsigned long *div_high)
> +/**
> + * Calculate divider values for desired SCL frequency
> + *
> + * @clk_rate: I2C input clock rate
> + * @scl_rate: Desired SCL rate
> + * @div_low: Divider output for low
> + * @div_high: Divider output for high
> + *
> + * Returns: 0 on success, -EINVAL on unreachable SCL rate. In that case
> + * a best-effort divider value is returned in divs.

I don't think it's returning a best-effort divider with your current
pach. It will return an error and leave the "div_high" or "div_low"
as some value > 0xffff.

I'll also note that your patch doesn't fix the bug in the old code
that a divider of 0xffff exactly is considered an error.

I kinda doubt that anyone ever trips this condition, but I figured I'd
mention it.

-Doug