Commit Graph

47 Commits

Author SHA1 Message Date
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
3914c76abb clk: clk_set_assigned: Skip frequency of value 0
A frequency of value 0 mean that we don't want to change the frequency so
skip it.
2018-05-07 09:42:35 +00:00
Emmanuel Vadot
d195d4acee clk: Add support for assigned-clock-rates
The properties 'assigned-clocks', 'assigned-clock-parents' and
'assigned-clock-rates' all work together.
'assigned-clocks' holds the list of clock for which we need to either
assign a new parent or a new frequency.
The old code just supported assigning a new parents, add support for
assigning a new frequency too.
2018-05-07 07:30:40 +00:00
Emmanuel Vadot
ee710ecf32 clk: Put the sysctls under hw.clock instead of clock
This is more consistant with hw.regulator and other hardware related
sysctls.
2018-04-27 00:12:00 +00:00
Emmanuel Vadot
bfeb2bd7ca regulator: Check status before disabling
When disabling regulator when they are unused, check before is they are
enabled.
While here don't check the enable_cnt on the regulator entry as it is
checked by regnode_stop.
This solve the panic on any board using a fixed regulator that is driven
by a gpio when the regulator is unused.

Tested On: OrangePi One
Pointy Hat to:	    myself
Reported by:	kevans, Milan Obuch (freebsd-arm@dino.sk)
2018-04-20 20:30:33 +00:00
Oleksandr Tymoshenko
f7604b1b27 Align OF_getencprop_alloc API with OF_getencprop and OF_getprop_alloc
Change OF_getencprop_alloc semantics to be combination of malloc and
OF_getencprop and return size of the property, not number of elements
allocated.

For the use cases where number of elements is preferred introduce
OF_getencprop_alloc_multi helper function that copies semantics
of OF_getencprop_alloc prior to this change.

This is to make OF_getencprop_alloc and OF_getencprop_alloc_multi
function signatures consistent with OF_getencprop_alloc and
OF_getencprop_alloc_multi.

Functionality-wise this patch is mostly rename of OF_getencprop_alloc
to OF_getencprop_alloc_multi except two calls in ofw_bus_setup_iinfo
where 1 was used as a block size.
2018-04-09 22:06:16 +00:00
Oleksandr Tymoshenko
217d17bcd3 Clean up OF_getprop_alloc API
OF_getprop_alloc takes element size argument and returns number of
elements in the property. There are valid use cases for such behavior
but mostly API consumers pass 1 as element size to get string
properties. What API users would expect from OF_getprop_alloc is to be
a combination of malloc + OF_getprop with the same semantic of return
value. This patch modifies API signature to match these expectations.

For the valid use cases with element size != 1 and to reduce
modification scope new OF_getprop_alloc_multi function has been
introduced that behaves the same way OF_getprop_alloc behaved prior to
this patch.

Reviewed by:	ian, manu
Differential Revision:	https://reviews.freebsd.org/D14850
2018-04-08 22:59:34 +00:00
Emmanuel Vadot
3f01401236 regulator: Disable unused regulator
bootloaders such as u-boot might enable regulators, or simply regulators could
be enabled by default by the PMIC, even if we don't have a driver for
the device or subsystem.
Disable unused regulators just before going to userland.
A tunable hw.regulator.disable_unused is added to not disable them in case
this causes problems on some board but the default behavior is to disable
everything unused.
I prefer to break thinks now and fix them rather than never switch to the
case were we disable regulators.

Tested on : Pine64-LTS (an idle board goes from ~0.33A to ~0.27A)
Tested on : BananaPi M2
Differential Revision:	https://reviews.freebsd.org/D14781
2018-04-04 06:44:24 +00:00
Emmanuel Vadot
82ce05526b extres/regulators: Add sysctls for regulators
For each regulators create an hw.regulator.<regname>. :
uvolt: Current value
always_on: 1 If the reg is always on
boot_on: 1 If the reg is set at boot time
enable_cnt: Number of consumer(s)
enable_delay: Delay before enabling the regulator
ramp_delay: The Ramp delay
max_uamp: The maximum value of the regulator in uAmps
min_uamp: The minimal value of the regulator in uAmps
max_uvolt: The maximum value of the regulator in uVolts
min_uvolt: The minimal value of the regulator in uVolts

Reviewed by:	ian
Differential Revision:	https://reviews.freebsd.org/D14578
2018-03-11 04:37:05 +00:00
Michal Meloun
4a744c0e9d Define meaning of remaining clock rounding flags combinations.
MFC after: 2 weeks
2018-02-27 16:08:08 +00:00
Michal Meloun
f1824e85ef Use more verbose panic messages.
MFC after: 2 weeks
2018-01-30 04:06:30 +00:00
Michal Meloun
962eb1c03f Revert r328511, it was committed with <patch>.diff instead of <patch>.txt as
commit log.
2018-01-30 04:05:03 +00:00
Michal Meloun
6403138990 diff --git a/sys/dev/extres/clk/clk.c b/sys/dev/extres/clk/clk.c
index c6a1f466ceb..c3708a0ce27 100644
--- a/sys/dev/extres/clk/clk.c
+++ b/sys/dev/extres/clk/clk.c
@@ -642,10 +642,11 @@ clknode_adjust_parent(struct clknode *clknode, int idx)
 	if (clknode->parent_cnt == 0)
 		return;
 	if ((idx == CLKNODE_IDX_NONE) || (idx >= clknode->parent_cnt))
-		panic("Invalid clock parent index\n");
+		panic("%s: Invalid parent index %d for clock %s",
+		    __func__, idx, clknode->name);

 	if (clknode->parents[idx] == NULL)
-		panic("%s: Attempt to set invalid parent %d for clock %s",
+		panic("%s: Invalid parent index %d for clock %s",
 		    __func__, idx, clknode->name);

 	/* Remove me from old children list. */
@@ -674,8 +675,8 @@ clknode_init_parent_idx(struct clknode *clknode, int idx)
 	if ((idx == CLKNODE_IDX_NONE) ||
 	    (idx >= clknode->parent_cnt) ||
 	    (clknode->parent_names[idx] == NULL))
-		panic("%s: Invalid clock parent index: %d\n", __func__, idx);
-
+		panic("%s: Invalid parent index %d for clock %s",
+		    __func__, idx, clknode->name);
 	clknode->parent_idx = idx;
 }
2018-01-28 15:20:45 +00:00
Michal Meloun
f8759facd2 Convert extres/phy to kobj model.
Similarly as other extres pseudo-drivers, implement phy by using kobj model.
This detaches it from provider device, so single device driver can export
multiple different phys. Additionally, this  allows phy to be subclassed to
more specialized drivers, like is USB OTG phy, or PCIe phy with hot-plug
capability.

Tested by:	manu (previous version, on Allwinner board)
MFC after:	1 month
2018-01-20 17:02:17 +00:00
Emmanuel Vadot
2b541904af clk: Get new parent freq after set_freq
During set_freq a clknode might have reparent (using a better parent that
have a higher frequency for example), before refreshing the cache, re-get
the parent frequency.

Reviewed by:	mmel
2018-01-20 14:47:27 +00:00
Kyle Evans
5996fd28fe Add SPDX tags to syscon bits, correct inconsistency in Copyright line. 2018-01-13 19:00:41 +00:00
Kyle Evans
a9f41deff6 Introduce aw_syscon(4) for earlier attachment
Attaching syscon_generic earlier than BUS_PASS_DEFAULT makes it more
difficult for specific syscon drivers to attach to the syscon node and to
get ordering right. Further discussion yielded the following set of
decisions:

- Move syscon_generic to BUS_PASS_DEFAULT
- If a platform needs a syscon with different attach order or probe
behavior, it should subclass syscon_generic and match on the SoC specific
compat string
- When we come across a need for a syscon that attaches earlier but only
specifies compatible = "syscon", we should create a syscon_exclusive driver
that provides generic access but probes earlier and only matches if "syscon"
is the only compatible. Such fdt nodes do exist in the wild right now, but
we don't really use them at the moment.

Additionally:

- Any syscon provider that has needs any more complex than a spinlock solely
for syscon access and a single memory resource should subclass syscon
directly rather than attempting to subclass syscon_generic or add complexity
to it. syscon_generic's attach/detach methods may be made public should the
need arise to subclass it with additional attach/detach behavior.

We introduce aw_syscon(4) that just subclasses syscon_generic but probes
earlier to meet our requirements for if_awg and implements #2 above for this
specific situation. It currently only matches a64/a83t/h3 since these are
the only platforms that really need it at the time being.

Discussed with:	ian
Reviewed by:	manu, andrew, bcr (manpages, content unchanged since review)
Differential Revision:	https://reviews.freebsd.org/D13793
2018-01-13 18:46:31 +00:00
Kyle Evans
ea9e0e28e0 Fix bogus pass for syscon_generic introduced in r327621
ian@ pointed out that BUS_PASS_DEFAULT + $anything is bogus, given that
BUS_PASS_DEFAULT is defined as __INT_MAX. Instead, we take a page out of
imx6_usbphy's book and use BUS_PASS_DEFAULT - 1000 to achieve the desired
effect of syscon_generic attaching before if_awg and other potential
consumers, but late enough that more specialized implementations should have
no problem attaching instead.

Reported by:	ian
2018-01-07 02:19:54 +00:00
Kyle Evans
e7cfe78afe Move syscon_generic to attach much later
It still needs to be before if_awg at least in order to be available for
other operations, but it should not be attaching before interrupt
controllers at the very least.

This should make errors involving syscon register space colliding with other
devices a little more innocent, but these conflicts should really be tracked
down and resolved. One such conflict is with the Raspberry Pi 3 local
interrupt controller, noticed by tuexen@

Reported by:	tuexen
2018-01-06 14:21:32 +00:00
Kyle Evans
198ca831a1 extres/syscon: Commit missing bits from r327106
r327106 introduced kobj to syscon so it can be subclassed and fit in with
the rest of the syscon framework. The diff for syscon.c was misapplied in a
clean tree prior to commit, so bring it back to what was included in the
review and tested. The entire file has basically been rewritten from what
was present prior to the kobj work.

Pointy hat to:	me
2017-12-26 16:38:04 +00:00
Alexander Kabaev
151ba7933a Do pass removing some write-only variables from the kernel.
This reduces noise when kernel is compiled by newer GCC versions,
such as one used by external toolchain ports.

Reviewed by: kib, andrew(sys/arm and sys/arm64), emaste(partial), erj(partial)
Reviewed by: jhb (sys/dev/pci/* sys/kern/vfs_aio.c and sys/kern/kern_synch.c)
Differential Revision: https://reviews.freebsd.org/D10385
2017-12-25 04:48:39 +00:00
Kyle Evans
cd04523f0e Move syscon into extres framework
This should help reduce confusion between syscon/syscons a little bit.
syscon is a resource generally modeled by FDT platforms, and not to be
confused with syscons.
2017-12-23 14:30:44 +00:00
Andrew Turner
43f0edd4e7 Remove redundant declarations. Newer gcc has a warning for these so will
fail when building with -Werror.

Sponsored by:	DARPA, AFRL
2017-08-19 17:18:27 +00:00
Emmanuel Vadot
c1b014c51c Export a sysctl dev.<clkdom>.<unit>.clocks for each clock domain containing
all the clocks that they provide.
Each clocks are exported under the node 'clock.<clkname>' and have the following
children nodes :
- frequency
- parent (The selected parent, if any)
- parents (The list of parents, if any)
- childrens (The list of childrens, if any)
- enable_cnt (The enabled counter)

This give us the possibility to examine clocks at runtime and make graph of
the clock flow.

Reviewed by:	mmel
MFC after:	2 month
Differential Revision:	https://reviews.freebsd.org/D9833
2017-03-05 07:13:29 +00:00
Emmanuel Vadot
dd165efb5a Do not check divider length if we have a div table.
Reviewed by:	mmel
2017-02-23 05:33:20 +00:00
Emmanuel Vadot
bbd72acb3b clk_div: Add a div lookup table
Some clocks on SoC have a diff between the value written in the register
and the real divider.
Add a table that where we can lookup the real value of the divider.

Reviewed by:	mmel (earlier revision)
Differential Revision:	https://reviews.freebsd.org/D8728
2016-12-12 16:43:31 +00:00
Michal Meloun
3b29466b94 Clock framework fixes:
- The clk_test_freq() (aka CLK_SET_DRYRUN) doesn't change frequency,
   don't cache it result.
 - Fix busy condition for clk_set_freq().

MFC after: 3 weeks
2016-12-04 16:02:59 +00:00
Emmanuel Vadot
ad6d341799 Do not warn if the 'assigned-clock-parents' property does not exists.
MFC after:	2 weeks
2016-11-08 10:05:11 +00:00
Emmanuel Vadot
90aabaafa5 Add clk_set_assigned
assigned-clock-parents are DT properties used to configure
some default parent clocks on one node.

Reviewed by:	mmel
MFC after:	2 weeks
2016-11-04 17:04:45 +00:00
Michal Meloun
fd02931841 REGULATOR: Move functions for handling with regulator ranges to
common file. They can be useful for other PMICs.

MFC after: 2 weeks
2016-10-18 12:27:46 +00:00
Michal Meloun
dac935533b EXTRES: Add OF node as argument to all <foo>_get_by_ofw_<bar>() functions.
In some cases, the driver must handle given properties located in
specific OF subnode. Instead of creating duplicate set of function, add
'node' as argument to existing functions, defaulting it to device OF node.

MFC after: 3 weeks
2016-07-10 18:28:15 +00:00
Jared McNeill
0e1cdf8ba6 Add clk_get_by_ofw_node_index, which is like clk_get_by_ofw_index but
operates on a specific OF node instead of the pass in device's OF node.

Reviewed by:		andrew, mmel
Differential Revision:	https://reviews.freebsd.org/D6957
2016-07-10 10:53:50 +00:00
Ian Lepore
c45b842250 Rename gpiobus_map_pin() to gpiobus_acquire_pin(), to better reflect the
fact that the caller is requesting exclusive use of the pin, and also to
better match the inverse operation which is named gpiobus_release_pin().
2016-05-26 15:45:36 +00:00
Oleksandr Tymoshenko
f4eefe43b2 Use OF_prop_free instead of direct call to free(9)
Reviewed by:	mmel@
2016-05-14 04:59:36 +00:00
Andrew Turner
670e854e4a Fix a format string when uint64_t is not unsigned long long by casting
through uintmax_t.
2016-04-04 10:03:06 +00:00
Jared McNeill
7a8917b25d Pass clkdev_if methods through to parent device by default.
Reviewed by:		mmel, adrian (mentor)
Approved by:		adrian (mentor)
Differential Revision:	https://reviews.freebsd.org/D5750
2016-03-28 11:51:35 +00:00
Alexander Kabaev
19a8851f7b Do nothing if requested clk frequency is already correct.
Reviewed by: mmel
2016-03-27 23:19:20 +00:00
Jared McNeill
64f86dc4cb Fix support for fixed factor clocks.
- Use a different device description for fixed and fixed factor clocks.
 - Fix a bug where the "clock-div" property was stored in the "mult" field
   of the clock definition.
 - Get the fixed factor parent clock by index instead of by name, as a
   clock-names property is not required to be present here.

Reviewed by:		mmel, adrian (mentor)
Approved by:		adrian (mentor)
Differential Revision:	https://reviews.freebsd.org/D5703
2016-03-23 19:26:53 +00:00
Jared McNeill
694f5cae46 clk_parse_ofw_out_names is supposed to return a list of indices when the
clock-indices property is present, so change the "uint32_t *indices" parameter
to "uint32_t **indices" to allow this.

Reviewed by:		mmel, adrian (mentor)
Approved by:		adrian (mentor)
Differential Revision:	https://reviews.freebsd.org/D5702
2016-03-23 19:24:09 +00:00
Jared McNeill
e1f3a8ce54 Return BUS_PROBE_GENERIC instead of 0 from ofw_clkbus_probe, giving
platform specific drivers a chance to override the generic driver.

Reviewed by:		mmel, adrian (mentor)
Approved by:		adrian (mentor)
Differential Revision:	https://reviews.freebsd.org/D5701
2016-03-23 19:21:21 +00:00
Michal Meloun
4e3d35d76e Add phy framework, a next part of new 'extended resources' family of
support frameworks (i.e. clk/regulators/tsensors/fuses...).

It provides simple unified consumers interface for manipulations with
phy (USB/SATA/PCIe) resources.
2016-03-15 15:31:17 +00:00
Michal Meloun
878ca242eb Add regulator framework, a next part of new 'extended resources' family of
support frameworks(i.e. clk/reset/phy/tsensors/fuses...).

The framework is still far from perfect and probably doesn't have stable
interface yet, but we want to start testing it on more real boards and
different architectures.
2016-03-15 15:30:17 +00:00
Michal Meloun
cc42bd4f3d CLK: Add and use explicit locking for access to clock device registers.
Implicit locking (for read/write/modify) is not sufficient for complex
cases.
2016-03-15 15:28:24 +00:00
Michal Meloun
58de845996 CLK: Add enumerator for 'clocks' OFW node. Add bus device bindings
for clk_fixed class.
2016-03-15 15:27:15 +00:00
Michal Meloun
3ad8c0e5a1 CLK: Remove forgotten mutex from clk_fixed class. 2016-03-15 15:25:26 +00:00
Michal Meloun
0a17d8c230 Add reset framework, a second part of new 'extended resources' family of
support frameworks (i.e. regulators/phy/tsensors/fuses...).

It provides simple unified consumers interface for manipulations with
on-chip resets.

Reviewed by: ian, imp (paritaly)
2016-01-24 11:03:35 +00:00
Michal Meloun
12a05f9a86 Add clock framework, a first part of new 'extended resources' family of
support frameworks(i.e. reset/regulators/phy/tsensors/fuses...).

The clock framework significantly simplifies handling of complex clock
structures found in modern SoCs. It provides the unified consumers
interface, holds and manages actual clock topology, frequency and gating.

It's tested on three different ARM boards (Nvidia Tegra TK1, Inforce 6410 and
Odroid XU2) and on one MIPS board (Creator Ci20) by kan@.

The framework is still far from perfect and probably doesn't have stable
interface yet, but we want to start testing it on more real boards and
different architectures.

Reviewed by: ian, kan (earlier version)
2016-01-24 11:00:38 +00:00