Commit Graph

10 Commits

Author SHA1 Message Date
Nick O'Brien
96d3575edc riscv/sifive: add FE310 Always-on driver
This driver supports SiFive's FE310 Always-on (AON) peripheral's
Real-time clock (RTC) and Watchdog timer (WDT). AON has other
functionality that this driver could support such as the power
management unit (PMU) but that functionality hasn't been implemented.

Reviewed by:	philip (mentor), kp (mentor)
Approved by:	philip (mentor)
Sponsored by:	Axiado
Differential Revision:	https://reviews.freebsd.org/D24170
2020-04-02 00:33:15 +00:00
Philip Paeps
8375d1173f fuspi: silence build warning, plug resource leak
This silences an "unused label" warning as well as fixes the attach fail
path that wasn't releasing resources.

Submitted by:   Nicholas O'Brien <nickisobrien_gmail.com>
Sponsored by:	Axiado
Differential Revision: https://reviews.freebsd.org/D24004
2020-03-09 04:09:36 +00:00
Mitchell Horne
9e483eadd4 prci: register tlclk as a fixed clock
The PRCI exports tlclk as a constant fixed divisor clock, defined as 1/2
of the coreclk frequency. In older FU540 device trees (such as the one
provided by SiFive), tlclk is represented as its own entity, and is
automatically registered as a fixed-divisor-clock. Unfortunately the
upstream FU540 device tree (that we have in our tree) represents tlclk
as an output of the PRCI block, and we must register it manually. At
worst, users of the old device tree will end up with an unreferenced
duplicate of tlclk.

This fixes device attachment for the SiFive UART on newer device trees,
since it references tlclk via the PRCI.

Reviewed by:	kp
Differential Revision:	https://reviews.freebsd.org/D23406
2020-02-01 17:13:52 +00:00
Mitchell Horne
adec0ce785 prci: fix up compat
Add two additional compat strings that can be used to identify the PRCI.

With newer device trees the PRCI has two parents, hfclk and rtcclk, so
allow the driver to attach when more than one parent is found.

Reviewed by:	kp
Differential Revision:	https://reviews.freebsd.org/D23405
2020-02-01 17:12:15 +00:00
Mitchell Horne
f6029f2bc9 prci: register the DDR and GEMGX PLLs
The PRCI module exports three PLLs. Currently only the coreclk/corepll
is registered, so add the logic to register the DDR (memory) and GEMGX
(ethernet) clocks as well. These clocks are unused at the moment.

Reviewed by:	kp
Differential Revision:	https://reviews.freebsd.org/D23404
2020-02-01 17:09:56 +00:00
Kristof Provost
76c6e771bc sifive: Fix incorrect tx/rx ctrl defines
Happily these were never used, but they should be correct anyway.

Reported by:	Nicholas O'Brien <nickisobrien_gmail.com>
Sponsored by:	Axiado
2020-01-07 09:02:14 +00:00
Kristof Provost
01774d0d18 sifive: uart driver
Implement support for the UART as found on the SiFive FU540. It should
also work on, but has not been tested with, the FU310.

Reviewed by:	philip
Sponsored by:	Axiado
2019-12-31 10:54:13 +00:00
Philip Paeps
2d581b3a7c fuspi: Fix 'sleepable after non-sleepable' lock
With WITNESS enabled we see the following warning:

    lock order reversal: (sleepable after non-sleepable)
     1st 0xffffffd0847c7210 fu540spi0 (fu540spi0) @
     /usr/home/kp/axiado/hornet-freebsd/src/sys/riscv/sifive/fu540_spi.c:297
      2nd 0xffffffc00372bb30 Clock topology lock (Clock topology lock) @
      /usr/home/kp/axiado/hornet-freebsd/src/sys/dev/extres/clk/clk.c:1137
      stack backtrace:
      #0 0xffffffc0002a579e at witness_checkorder+0xb72
      #1 0xffffffc0002a5556 at witness_checkorder+0x92a
      #2 0xffffffc000254c7a at _sx_slock_int+0x66
      #3 0xffffffc00025537a at _sx_slock+0x8
      #4 0xffffffc000123022 at clk_get_freq+0x38
      #5 0xffffffc0005463e4 at __clzdi2+0x2bb8
      #6 0xffffffc00014af58 at randomdev_getkey+0x76e
      #7 0xffffffc0001278b0 at simplebus_add_device+0x7ee
      #8 0xffffffc00027c9a8 at device_attach+0x2e6
      #9 0xffffffc00027c634 at device_probe_and_attach+0x7a
      #10 0xffffffc00027d76a at bus_generic_attach+0x10
      #11 0xffffffc00014aab0 at randomdev_getkey+0x2c6
      #12 0xffffffc00027c9a8 at device_attach+0x2e6
      #13 0xffffffc00027c634 at device_probe_and_attach+0x7a
      #14 0xffffffc00027d76a at bus_generic_attach+0x10
      #15 0xffffffc000278bd2 at config_intrhook_oneshot+0x52
      #16 0xffffffc000278b3e at config_intrhook_establish+0x146
      #17 0xffffffc000278cf2 at config_intrhook_disestablish+0xfe

The clock topology lock can sleep, which means we cannot attempt to
acquire it while holding the non-sleepable mutex.

Fix that by retrieving the clock speed once, during attach and not every
time during SPI transaction setup.

Submitted by:   kp
Sponsored by:   Axiado
2019-12-29 04:26:10 +00:00
Philip Paeps
109ece57d0 riscv/sifive: add FU540 SPI controller driver
Initial working prototype of the Serial Peripheral Interface controller
in the SiFive FU540 SoC.

Reviewed by:    kp
Sponsored by:   Axiado
2019-12-20 03:40:04 +00:00
Philip Paeps
09728b2df6 riscv/sifive: add SiFive FU540 PRCI driver
The SiFive FU540 Power Reset Clocking Interrupt block contains a PLL
that turns the input crystal (33.3MHz) into a 1-1.5GHz clock.
This clock in turn is divided by two to produce the tlclk, which is fed
into devices such as the SPI and I2C controllers.

Register a new clock device for the PRCI so that those devices can
read the correct clock through the clk framework.

Submitted by:   kp
Sponsored by:   Axiado
2019-12-20 03:38:21 +00:00