Re: mcp251x: read oscillator frequency?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/11/19 9:31 PM, Drew Fustini wrote:
>> On Mon, Nov 11, 2019 at 11:28:14AM +0100, Marc Kleine-Budde wrote:
>>> I successfully got a mcp25625 (which is basically a mcp2515 with
>>> internal phy) running on a rapsi using the frequency printed on the
>>> oscillator in the DT-overlay.
>>
>> I came across this patch by Andy on the linux-can archives:
>>
>> [PATCH v2] can: mcp251x: Get rid of legacy platform data
>> https://www.spinics.net/lists/linux-can/msg02407.html
>>
>> The description:
>> Instead of using legacy platform data, switch to use device properties.
>> For clock frequency we are using well established clock-frequency property.
>>
>> I reads the clock-frequency property from device tree:
>>
>>         freq = clk_get_rate(clk);
>> -       if (freq == 0 && pdata)
>> -               freq = pdata->oscillator_frequency;
>> +       if (freq == 0)
>> +               device_property_read_u32(&spi->dev, "clock-frequency", &freq);
>>
>>
>> I feel like this is currently missing from mcp251x.c.  I don't see how it is
>> reading the clock frequency from Device Tree as I don't see any code in the
>> current mcp251x.c to read device tree properties.
>>
>> I would appreciate any insights to improve my understanding.
> 
> Also, I meant to ask as to why the clock for MCP2515 Oscillator comes
> from the spi device:
> clk = devm_clk_get(&spi->dev, NULL);

The mcp2515 is a SPI chip and it's clocked by an external oscillator.
This is described via the DT. Looking at a random board in the kernel:
arch/arm/boot/dts/at91-sama5d4_ma5d4.dtsi

>                 clk20m: clk20m {
>                         compatible = "fixed-clock";
>                         #clock-cells = <0>;
>                         clock-frequency = <20000000>;
>                         clock-output-names = "clk20m";
>                 };
[...]
>                         spi1: spi@fc018000 {
>                                 cs-gpios = <&pioB 22 0>, <&pioB 23 0>, <0>, <0>;
>                                 status = "okay";
> 
>                                 can0: can@0 {
>                                         compatible = "microchip,mcp2515";
>                                         reg = <0>;
>                                         clocks = <&clk20m>;

This is a "link" (called phandle in the DT-world) to the "clk20m" node
above. That node has a "clock-frequency" property of 20MHz.

>                                         interrupt-parent = <&pioE>;
>                                         interrupts = <6 IRQ_TYPE_EDGE_RISING>;
>                                         spi-max-frequency = <10000000>;
>                                 };

By "devm_clk_get()" the driver first gets a reference to the clock and
by "clk_get_rate()" the frequency. This is generic non-spi specific DT
handling.

> line 1034 from:
> https://elixir.bootlin.com/linux/latest/source/drivers/net/can/spi/mcp251x.c#L1034
> 
> It seem like there should be separate clocks for the SPI frequency and
> the MCP2515 oscillator frequency.
The SPI frequency, to be more precise the maximal SPI frequency the
mcp2515 supports on that particular board, is specified by the property
"spi-max-frequency" it's handled by the SPI core code.

hth,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

Attachment: signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux