Commit Graph

38 Commits

Author SHA1 Message Date
Andriy Gapon
c3a7328be8 aw_clk_nm: fix incorrect use of abs()
abs() takes a (signed) int as input.
Instead, it was used with unsigned 64-bit integers.

So, add and use a new helper function to calculate a difference between
two uint64_t-s.

Reviewed by:	manu
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D26307
2020-09-07 06:27:18 +00:00
Michal Meloun
d873a521ca Revert r363123.
As Emanuel poited me the Linux processes these clock assignments in forward
order, not in reversed. I misread the original code.
Tha problem with wrong order for assigned clocks found in tegra (and some imx)
DT should be reanalyzed and solved by different way.

MFC with:	r363123
Reported by;	manu
2020-07-25 06:32:23 +00:00
Michal Meloun
c0c5cf7b31 Reverse the processing order of assigned clocks property.
Linux processes these clocks in reverse order and some DT relies
on this fact. For example, the frequency setting for a given PLL
is the last in the list, preceded by the frequency setting of its
following divider or so...

MFC after:	1 week
2020-07-12 07:59:15 +00:00
Michal Meloun
a9be5d7515 Assigned clocks: fix off-by-one bug, don't leak allocated memory.
MFC after:	1 week
2020-07-12 07:42:21 +00:00
Pawel Biernacki
7029da5c36 Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)
r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked).
Use it in preparation for a general review of all nodes.

This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Mark all obvious cases as MPSAFE.  All entries that haven't been marked
as MPSAFE before are by default marked as NEEDGIANT

Approved by:	kib (mentor, blanket)
Commented by:	kib, gallatin, melifaro
Differential Revision:	https://reviews.freebsd.org/D23718
2020-02-26 14:26:36 +00:00
Michal Meloun
124a91ac18 Implement support for (soft)linked clocks.
This kind of clock nodes represent temporary placeholder for clocks
defined later in boot process. Also, these are necessary to break
circular dependencies occasionally occurring in complex clock graphs.

MFC after: 3 weeks
2019-11-08 18:57:41 +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
baec4d5985 extres: clk: Fix clk_set_assigned
ofw_bus_parse_xref_list_get_length doesn't returns the number of elements, fix this.
While here when setting the clock to the assigned freqeuncy, allow the clock
driver to round down or up the frequency as sometimes the exact frequency cannot
be obtain.
2018-11-29 19:06:05 +00:00
Emmanuel Vadot
aed85e3011 extres: clkdiv: Fix div_with_table
We didn't allowed a divider register value of 0 which can exists and
also didn't wrote the value but the divider, which result of a wrong
frequency to be selected
2018-08-05 06:15:35 +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
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
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
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
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
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
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
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
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
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