Re: mcp251x: read oscillator frequency?

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

 



On 11/11/19 12:09 AM, Drew Fustini wrote:
> Hello, I'm looking at mcp251x driver and it does not seem to read the
> device tree property 
> mcp251x,oscillator-frequency.  
> 
> I have a problem where I have MCP2515 with a 16MHz oscillator.  However,
> it is getting configured with a 8MHz clock despite
> having mcp251x,oscillator-frequency defined as 16MHz:
> https://github.com/pdp7/bb.org-overlays/blob/patch-1/src/arm/PB-MCP2515-SPI1.dts

I assume you get the 8MHz clock rate from the "ip" output, right?

> ip -details -statistics link show can0
> 8: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
>     link/can  promiscuity 0 minmtu 0 maxmtu 0 
>     can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0 
> 	  bitrate 500000 sample-point 0.875 
> 	  tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
> 	  usb_8dev: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..1024 brp-inc 1
> 	  clock 32000000 
                ^^^^^^^^

Like here? (example output from a different CAN controller)

> 	  re-started bus-errors arbit-lost error-warn error-pass bus-off
> 	  0          0          0          0          0          0         numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
>     RX: bytes  packets  errors  dropped overrun mcast   
>     0          0        0       0       0       0       
>     TX: bytes  packets  errors  dropped carrier collsns 
>     0          0        0       0       0       0       

It's due to this line in the code:

https://elixir.bootlin.com/linux/latest/source/drivers/net/can/spi/mcp251x.c#L1065

where only the half of the external osc frequency is stored. That value
is displayed in the user space by the "ip" command.

> I would appreciate any advice on whether a patch for mcp251x.c to
> read mcp251x,oscillator-frequency would be a good way to solve this issue.

Looking at the datasheet[1] of the mcp2515 page 40, equation 5-2, I
think this is correct. As the timequanta is calculated by:

    Tq = (2 * Brp) / fosc

On other words:

    Tq = Brp / (fosc / 2)

We have no means of expressing the additional "/2" during the bit timing
calculation, but to store the fosc/2 as the "effective" oscillator
frequency.

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.

[1]
http://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf

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