Commit Graph

64 Commits

Author SHA1 Message Date
Dimitry Andric
2d8a0c01e5 Fix the following -Werror warning from clang 10.0.0:
sys/arm/allwinner/clkng/aw_clk_mipi.c:144:6: error: misleading indentation; statement is not part of the previous 'if' [-Werror,-Wmisleading-indentation]
                                        m++;
                                        ^
sys/arm/allwinner/clkng/aw_clk_mipi.c:142:5: note: previous statement is here
                                if (best == *fout)
                                ^

Move the increment operations into the for loop headers instead.

Discussed with:	manu
MFC after:	3 days
2020-02-18 17:55:24 +00:00
Emmanuel Vadot
e213223c9b Remove "all rights reserved" from copyright for the file I own.
Some of the files have both me and Jared McNeill and he gave me
permission to remove it from his files too.
2019-12-03 21:00:45 +00:00
Emmanuel Vadot
5bf4529b14 arm64: allwinner: a64: Do not init the video related clocks
This should be handled by the video drivers and this break EFIFB
as this changes clock setup by the bootloader.

MFC after:	1 month
2019-11-06 18:39:32 +00:00
Emmanuel Vadot
6c4464cb74 arm64: allwinner: Add Allwinner H6 Support
This adds support for H6 SoC.
Add a CCU driver for H6 that support all PLLs and most of the clocks
that we are intersted in for now (i2c, mmc, usb, etc ...)

MFC after:	1 month
2019-10-14 21:53:53 +00:00
Emmanuel Vadot
153e7b98e9 arm64: allwinner: Add aw_clk_nmm clock
This is a clock type present on Allwinner H6 where the formula is :
f = fparent * n / m0 / m1

MFC after:	1 month
2019-10-14 21:49:07 +00:00
Emmanuel Vadot
fcc82a8310 arm64: allwinner: Add new clock aw_clk_np
This is a clock type present in Allwinner H6 where the formula is :
f = fparent * N / P

MFC after:	1 month
2019-10-14 21:47:20 +00:00
Emmanuel Vadot
59c7842efe aw_ccung: Add more debug printfs
No functional changes

MFC after:	1 month
2019-10-14 21:45:15 +00:00
Emmanuel Vadot
f99055394d arm64: allwinner: a64: Add PLL_MIPI
PLL_MIPI is the last important PLL that we missed.
Add support for it.
Since it's one of the possible parent for TCON0 also add this clock
now that we can.
While here add some info about what video related clocks should be
enabled at boot and with what frequency.
2019-09-28 22:14:33 +00:00
Emmanuel Vadot
d27bec74fe allwinner: Add support to min/max in aw_clk_frac
The Fractionals clock in Allwinner device have some min/max frequencies
that they can do.
Add support for it.
2019-08-10 19:02:50 +00:00
Emmanuel Vadot
e727f392bf Remove some duplicate code that end up in r350844 2019-08-10 18:58:25 +00:00
Emmanuel Vadot
8c8b86922a allwinner: Add a new clock aw_clk_m
We used the aw_clk_nm clock for clock with only one divider factor
and used a fake multiplier factor. This cannot work properly as we
end up writing the "fake" factor to the register (and so always set
the LSB to 1).
Create a new clock for those.
The reason for not using the clk_div clock is because those clocks are
a bit special. Since they are (almost) all related to video we also need
to set the parent clock (the main PLL) to a frequency that they can support.
As the main PLL have some minimal frequency that they can support we need to
be able to set the main PLL to a multiple of the desired frequency.
Let say you want to have a 71Mhz pixel clock (typical for a 1280x800 display)
and the main PLL cannot go under 192Mhz, you need to set it to 3 times the
desired frequency and set the divider to 3 on the hdmi clock.
So this also introduce the CLK_SET_ROUND_MULTIPLE flag that allow for this kind
of scenario.
2019-08-10 18:50:37 +00:00
Emmanuel Vadot
cfc8861b06 allwinner: Rework the BUS_PASS on drivers
- Put all clock and control unit driver in BUS_PASS_RESOURCE except
  for the DE2 CCU as it needs the main CCU to be available.
- Use BUS_PASS_CPU for a20_cpu_cfg as it makes more sense.
- For aw_syscon use SCHEDULER pass as we need it early for drivers
  that attach in BUS_PASS_SUPPORTDEV
- For the rest we can use BUS_PASS_SUPPORTDEV
2019-08-10 17:58:30 +00:00
Emmanuel Vadot
beba2ebaef arm: allwinner: Remove frac mode from NM clk
We have a correct clock type aw_clk_frac now for this.
2019-05-23 17:36:55 +00:00
Emmanuel Vadot
747ef14e61 arm: allwinner: clk: Use the new frac clock
Some clocks used the NM type but this clock is for the ones with the
formula "clk = clkin / n / m" and not "clk = clkin * n / m"
Use the new frac clock for them.
2019-05-23 17:36:19 +00:00
Emmanuel Vadot
3b85cf6b3f arm: allwinner: clk: Add new clock aw_clk_frac
Add a clock driver for clock that can either be used in integer mode
with one N factor and one M divider or in fractional mode where the
output frequency is chosen between two predifined output.
2019-05-23 17:35:40 +00:00
Emmanuel Vadot
f7e598f60b allwinner: aw_ccu: Add some debug printfs (disabled by default)
Also print information about setting frequency at boot under bootverbose
2019-05-23 17:34:33 +00:00
Conrad Meyer
e2e050c8ef Extract eventfilter declarations to sys/_eventfilter.h
This allows replacing "sys/eventfilter.h" includes with "sys/_eventfilter.h"
in other header files (e.g., sys/{bus,conf,cpu}.h) and reduces header
pollution substantially.

EVENTHANDLER_DECLARE and EVENTHANDLER_LIST_DECLAREs were moved out of .c
files into appropriate headers (e.g., sys/proc.h, powernv/opal.h).

As a side effect of reduced header pollution, many .c files and headers no
longer contain needed definitions.  The remainder of the patch addresses
adding appropriate includes to fix those files.

LOCK_DEBUG and LOCK_FILE_LINE_ARG are moved to sys/_lock.h, as required by
sys/mutex.h since r326106 (but silently protected by header pollution prior
to this change).

No functional change (intended).  Of course, any out of tree modules that
relied on header pollution for sys/eventhandler.h, sys/lock.h, or
sys/mutex.h inclusion need to be fixed.  __FreeBSD_version has been bumped.
2019-05-20 00:38:23 +00:00
Emmanuel Vadot
da153f8e60 arm: allwinner: aw_clk_nm: Don't reparent the clock if we didn't ask
When looking for the best frequency don't change the clock parent if the
clock wasn't configured to do that.
2019-05-12 15:27:01 +00:00
Emmanuel Vadot
e69181cfc6 allwinner: clk: sun8i_r: Correct resets
The i2c reset wasn't defined and some bits where wrong, correct them.
2019-05-11 15:02:55 +00:00
Emmanuel Vadot
45f64a5956 allwinner: clk: prediv_mux: Init the current parent
Do not init the first parent but read the clock register to find
it's current parent and init this one.
2019-05-11 15:02:20 +00:00
Emmanuel Vadot
80e8fa0810 arm64: allwinner: ccu_de2: Remove H5 compatible
We don't have the display engine driver commited in FreeBSD yet so it is
useless to expose the clocks yet (and also it have not been tested on H5).

Reported by:	Manuel Stühn (freebsdnewbie@freenet.de)
PR:	 237571
MFC after:	1 week
2019-04-27 14:56:24 +00:00
Emmanuel Vadot
5f50cbd3de aw_rtc: Register the clocks
Since latest DTS update the rtc is supposed to register two clocks :

- osc32k (the 32k oscillator on the board that the RTC uses directly and
that other peripheral can use)
- iosc (the internal oscillator of the RTC when available which frequency
depend on the SoC revision)

Since we need the RTC before the proper clock control unit (because it uses
those clocks) attach it a BUS_PASS_BUS + MIDDLE and attach the clock control
unit at BUS_PASS_BUS + LAST for the SoC that requires it.

Tested On:	     A20, H3, A64

MFC after:	1 month
2019-04-16 12:39:31 +00:00
Emmanuel Vadot
34f71e304e arm: allwinner: clk: Fix nm_recalc
When comparing best frequencies use the absolute value.
If we do not do that we end up choosing an always lower value than
the best one if the exact freq cannot be met.

MFC after:	2 weeks
2019-03-29 19:40:04 +00:00
Emmanuel Vadot
d83a581cad arm64: allwinner: a64: Add TCON clock
The tcon clock need a mux table for it's parent, for now just
list the parents twice.
2019-03-07 19:32:01 +00:00
Emmanuel Vadot
1788e14d92 arm64: allwinner: Add CCU DE2
The Display Engine 2 have it's own Clock and Control Unit, add support
for it.
2019-03-07 19:30:37 +00:00
Emmanuel Vadot
2b0adb4404 arm: allwinner: Fix NM clock recalc
If the NM clock is using a fractional divider the formula isn't the same.
2019-03-07 19:28:47 +00:00
Emmanuel Vadot
69acf61478 allwinner: a64: Add THS clock support
The clock for the thermal sensor controller was missing when this driver
was made.
2018-08-05 06:16:36 +00:00
Emmanuel Vadot
75e7ec65d6 allwinner: a83t: Fix PLL_CPU clocks
The PLL_CPU clocks formula is 24Mhz * N and not 24Mhz / N
Fix it by using a NKMP clock with fixed factor values for the one
unused.
2018-07-16 13:38:16 +00:00
Emmanuel Vadot
8b3bb1afb1 allwinner: clkng: Correct mux width and flags
The test for checking if the clock have a mux was inverted and the mask
to calculate the parent index was wrong was wrong too.
It means that upon creation the incorrect parent was resolved as the current
one and upon reparent the switch was never made.

Pointy hat (lots of them): manu
2018-06-23 15:03:54 +00:00
Emmanuel Vadot
cfba8dec89 allwinner: ccung: Fully subclass the clock drivers
Each clock drivers if now fully subclassed, this have the advantage that
we can control the probe order.
Some clocks can have parents from other drivers, for example clocks in the
sun8i_r driver uses clocks from the main clock driver.
This worked before because the sun8i_r node is after the main ccu node in the
dtb and driver are probed in DTB order. This cannot work with the Display
Engine clocks as it is the first node in the DTB.

Tested on:    A83T, H5 A64
Tested on:    A20 (kevans)
2018-06-15 08:36:21 +00:00
Kyle Evans
dcc1299f0b aw_ccung: Add a10/a20 support
Note: At this time, this has only been tested on a single board from one of
the supported SoCs. This is enough to boot the board from MMC and have
functional USB- which is still an improvement over where we were at just
before with no functional clocks.

Differential Revision:	https://reviews.freebsd.org/D15810
2018-06-14 17:50:29 +00:00
Kyle Evans
85f58288a7 aw_ccung: Support clock factors where factor=0, factor is effectively 1
This happens in two cases for a20 clocks:

pll_core for 'n' factor:
factor=0, val=1
factor=n, val=n

ahb divisor:
factor=0,val=/2
factor=n,val=/2^n

Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D15806
2018-06-14 17:36:02 +00:00
Kyle Evans
f0fb94abca Standardize SPDX tag on files I've added 2018-05-09 16:52:28 +00:00
Kyle Evans
4b3c64f722 Remove "All Rights Reserved" on files that I hold sole copyright on
See r333391 for more detail; in summary: it holds no weight and may be
removed.
2018-05-09 16:44:19 +00:00
Emmanuel Vadot
23774c3973 allwinner: clk: Add gate_shift to the clock definition
WHile gate_shift was present in the NM_CLK macro it wasn't set into the
clock definition structure resulting in NM clocks not being correctly
gated when they should.
If the module wasn't enabled by the bootloader it will have stayed ungated.
2018-04-27 09:25:27 +00:00
Emmanuel Vadot
fd1337bffc allwinner: clk: Correct aw_clk_get_factor
Switch test between zero based factor and power of two one.
This resulted in a miscalculation of the factor if it was a power
of two one.
Some clocks frequencies were not calculated correctly because of that.
2018-04-27 09:23:07 +00:00
Emmanuel Vadot
b26e3474cf allwinner: a83t_r_ccu: Add proper IR clock support
Now that NM clocks support prediv, add proper support for the IR clock found
on the A83T SoC.

Tested On:  BananaPi M3
Reported by:	kevans
2018-04-07 15:40:00 +00:00
Emmanuel Vadot
ffa4898125 allwinner: aw_clk_nm: Add prediv value
Some NM clocks needs a fixed prediv value applied to the parent frequency
on some conditions. Add support for it.
2018-04-07 15:38:42 +00:00
Emmanuel Vadot
7904418f8e allwinner: Add IR clock to sun8i
Add ir clock definition to sun8i-r-ccu.
No idea if it's working but aw_cir seems happy now and the frequency
is set to 3Mhz as it should.
2018-03-11 04:01:23 +00:00
Emmanuel Vadot
34b8ef3d77 Allwinner H5: Enhance support
Add proper gpio and clock support
2017-12-05 21:21:23 +00:00
Emmanuel Vadot
eb1eebb9aa Allwinner: Add H5 compatible to aw_ccu
Recent DTS (from Linux 4.14) specify a compatible "allwinner,sun50i-h5-ccu"
for H5 SoC. Since we get the DTB from u-boot this wasn't noticed.
Add the compatible so later version of u-boot will not fail for us.
2017-12-04 20:45:15 +00:00
Kyle Evans
3579d98f0b Add r-ccu support for the Allwinner a83t
The r-ccu on the a83t differs from the others only by what it names the
ar100 parents. Export the _CCU macros (now converted to an enu) so that
ccu_sun8i_r can differentiate between a83t r-ccu and the others, then add
the compat string for the a83t r-ccu.

Reviewed by:	manu
Approved by:	emaste (mentor, implicit)
Differential Revision:	https://reviews.freebsd.org/D13206
2017-11-25 15:14:40 +00:00
Kyle Evans
e60d3b7ff4 Add ccu compat string for Allwinner a83t
A ccu driver was added for the a83t in r326114. Add compat string to
aw_ccung and register the clocks for the a83t upon attach.

Reviewed by:	manu
Approved by:	emaste (mentor, implicit)
Differential Revision:	https://reviews.freebsd.org/D13205
2017-11-24 02:39:38 +00:00
Kyle Evans
c80eef0dc6 Allwinner a83t: add ccung bits
Upstream DTS has switched to using CCU rather than /clocks nodes. Add a CCU
driver for the a83t to bring us closer to upstream, but don't yet attach it
to ccu node.

Reviewed by:	manu
Approved by:	emaste (mentor)
Differential Revision:	https://reviews.freebsd.org/D12843
2017-11-23 05:54:04 +00:00
Kyle Evans
0b7a88e60d aw_ccung: changes to accommodate upcoming a83t support
Add a means to specify mask/value for the prediv condition instead of
shift/width/value for clocks that have a more complex mux scenario.

Specifically, ahb1 on the a83t has the prediv applied if mux is either b10
or b11.

Reviewed by:	manu
Approved by:	emaste (mentor)
Differential Revision:	https://reviews.freebsd.org/D12851
2017-11-23 05:43:44 +00:00
Emmanuel Vadot
70bc7e51ca Allwinner A13: Add clkng support
DTS files switch from clocks under /clocks to a ccu (Clock Controller Unit)
a while ago.
Restore A13 functionality by adding a clock driver for it.
Almost every clocks are handled, the missing ones are mostly video related
clocks.

Tested On: A13 Olinuxino
2017-11-08 21:24:06 +00:00
Emmanuel Vadot
58f6e2154e Allwinner: clk: Unlock the clknode after locking it.
Pointy Hat: manu
2017-11-08 21:12:59 +00:00
Emmanuel Vadot
ac9297c128 Allwinner: Add clock driver for ccu_sun8i_r
SUN8I and SUN50I (H3, H5, A83T and A64) have a second clock controller
unit. It controls the clocks for the second gpio controller, the IR
controller etc ...
Support for A83T is not supported.

Tested On: OrangePi One, Pine64
2017-10-07 16:48:42 +00:00
Emmanuel Vadot
d3609450aa Allwinner H3 CCU: Fix build on ARM64
ccu_h3.c is also used on ARM64 as it provides clocks for the H5 SoC.
Since ARM64 doesn't have sys/gun/dts/include in it's include path, use
the full name for the sun8i-h3-ccu.h include.

Reported by:	andreast
2017-10-02 19:17:09 +00:00
Emmanuel Vadot
d8ffc6fb25 Allwinner A31 ccu: Use clock/reset IDs from dt-bindings
Do not redefines resets and clocks ID which are already in the
dt-bindings include directory. Those files are under dual licenced
under GPL2/MIT so use them directly.
2017-10-02 16:21:20 +00:00