[RFC] serial: mxc: get the clock frequency from the used clock for the device

Sean Anderson seanga2 at gmail.com
Fri Mar 18 03:15:09 CET 2022


On 3/17/22 10:47 AM, Michael Walle wrote:
> 
>>> +        struct clk clk;
>>> +        if(!clk_get_by_name(dev, "ipg", &clk))
>>> +            rate = clk_get_rate(&clk);
>>> +    }
>>> +
>>> +    /* as fallback we try to get the clk rate that way */
>>> +    if (rate == 0)
>>
>> !rate || IS_ERR_VALUE(rate)
> 
> This looked so weird I had to actually look at clk_get_rate()
> in u-boot.
> 
> /**
>   * clk_get_rate() - Get current clock rate.
>   * @clk:    A clock struct that was previously successfully requested by
>   *        clk_request/get_by_*().
>   *
>   * Return: clock rate in Hz on success, 0 for invalid clock, or -ve error code
>   *       for other errors.
>   */
> ulong clk_get_rate(struct clk *clk);
> 
> How can an ulong return a negative error value?

It can't. Which is why we need IS_ERR_VALUE and not < 0.

> What if the clock speed happens to be the same as -errno?

Due to physical constraints, this isn't an issue on 64 bit systems. And you
could run into trouble if you have a 32-bit system with a 4GHz processor.

I don't think it's the best interface. In e.g. Linux clk_get_rate returns 0 on
failure, which I think is reasonable. If you are interested, please send a patch series :)

--Sean



More information about the U-Boot mailing list