Commit Graph

105 Commits

Author SHA1 Message Date
Michal Meloun
e4ef4c5d66 extres/phy: Add mode setting function.
Modern multi-protocol phys are capable of supporting multiple different
protocols. Add a method for mode (and/or its variants) setting.

Discused with:	ganbold, manu, andrew
MFC after:	3 weeks
2023-01-03 10:19:29 +01:00
Andrew Turner
969935b86b Add support for an array of hwresets
In some drivers we need to assert and deassert a group of hardware
resets in any order. To support this add a new hwreset_array that
manages all hwresets defined for a device.

Reviewed by:	bz, manu, mmel
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D37357
2022-12-21 11:25:23 +00:00
Ganbold Tsagaankhuu
5cfacab132 Revert "Enable setting the phy id."
This reverts commit 6692670f58.
2022-12-19 15:19:57 +00:00
Søren Schmidt
6692670f58 Enable setting the phy id.
It is needed for the RK356X combo phy.
2022-12-19 13:08:42 +00:00
Andrew Turner
5566f84822 Only include regdev_if.h when it's needed
We don't need to include regdev_if.h when not building for FDT.

Sponsored by:	Innovate UK
2022-10-28 18:31:55 +01:00
Andrew Turner
01aaff6d1c Fix the includes in regulator_fixed.c
Include sys/bus.h directly rather than depend on header pollution.
While here fix the order of sys/systm.h.

Sponsored by:	Innovate UK
2022-10-28 18:31:55 +01:00
Andrew Turner
78e60ba04a Only include phydev_if.h when needed
We only need to include phydev_if.h in phy.c when FDT is enabled and
don't need it at all in phy_usb.c.

Sponsored by:	Innovate UK
2022-10-28 18:31:55 +01:00
Andrew Turner
754358108c Include sys/systm.h in phy_usb.c for KASSERT
Rather than depending on header pollution include systm.h directly.

Sponsored by:	Innovate UK
2022-10-28 18:31:55 +01:00
Andrew Turner
8724dd26d4 Allow clk_fixed.c to be built without FDT
Include opt_platform.h to get the FDT definition and only include FDT
headers when FDT is defined.

Sponsored by:	Innovate UK
2022-10-28 18:31:55 +01:00
Andrew Turner
83de695791 Remove unneeded headers from clk_link.c
There is no OFW/FDT specific code in this file so the ofw headers can
be removed.

Sponsored by:	Innovate UK
2022-10-28 18:31:55 +01:00
Andrew Turner
64c3edc237 Allow the extres regulator code to build without FDT
This allows drivers that use this to build in an ACPI only kernel.

Sponsored by:	The FreeBSD Foundation
2022-10-27 17:28:56 +01:00
Andrew Turner
47218e711e Include opt_platform.h to ensure FDT is defined
We need to include opt_platform.h as it's where FDT will be defined.

Sponsored by:	The FreeBSD Foundation
2022-10-04 17:38:56 +01:00
Andrew Turner
89a9a13c1a Remove unneeded FDT checks from phydev and regdev
They are only ever built when FDT is enabled so there is no need to
check for it in the files.

Sponsored by:	The FreeBSD Foundation
2022-10-04 17:37:37 +01:00
Kyle Evans
23c318ed86 extres: regulator: fix the build without FDT
The regnode interface is currently only built for FDT, thus not
applicable to ACPI-only kernels.  Move the "regnode_if.h" include
underneath a previously existing FDT cpp segment.

Reviewed by:	andrew, imp, manu
Differential Revision:	https://reviews.freebsd.org/D36790
2022-09-29 14:33:33 -05:00
Kyle Evans
79794d5c18 extres: syscon: pull in sys/malloc.h (fix !FDT)
syscon currently includes sys/malloc.h via header pollution from
dev/ofw/ofw_bus.h -> dev/ofw/openfirm.h.  Fix the build without FDT
defined by including sys/malloc.h directly.

Reviewed by:	andrew, imp, manu
Differential Revision:	https://reviews.freebsd.org/D36787
2022-09-29 14:33:32 -05:00
John Baldwin
b440e459a7 extres drivers: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 14:26:44 -07:00
Adrian Chadd
a82907ed13 clk: rename clknode_try_freq to clknode_test_freq
This brings it in line with what the clk_*_freq routines are named.
2021-12-26 06:16:02 -08:00
Adrian Chadd
9df53d07e6 clk: add call for nodes to get the programmed/decided frequency passed back
Summary:

The existing call can only really be used for a node wishing to
configure its parent, but as we don't pass in a pointer to the freq,
we can't set it to what it would be for a DRY_RUN pass.

So for clock nodes that wish to try setting parent frequencies to see
which would be the best for its own target frequency, we really do need
a way to call in and pass in a flag /and/ a pointer to freq so it can be
updated for us as the clock tree is recursed through.

Reviewers: manu

Approved by: manu

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D33445
2021-12-26 04:18:53 -08:00
Michal Meloun
1a74d77f85 extres/clk: Add a method to detect the HW state of the clock gate.
- add method to read gate enable/disable staust from HW
- show gate status in sysctl clock dump

MFC after:	1 week
2021-12-24 19:42:44 +01:00
Michal Meloun
72a2f3b5e2 extres/clk: Improve sysctl dump of clocks.
Always recalculate the frequency, the cache is lazily initialized so it is not always up to date.
While I'm in mark sysctl as MPSAFE.

Discussed with:	manu, adrian
MFC after:	1 week
2021-12-24 19:42:01 +01:00
Gordon Bergling
899a3b38f5 Fix two typos in source code comments
- s/alocated/allocated/
- s/realocated/reallocated/

MFC after:	3 days
2021-10-16 08:09:31 +02:00
Emmanuel Vadot
f52072b06d extres: regulator: Fix regulator_status for already enable regulators
If a regulator hasn't been enable by a driver but is enabled in hardware
(most likely enabled by U-Boot), regulator_status will returns that it
is enabled and so any call to regulator_disable will panic as it wasn't
enabled by one of our drivers.

Sponsored by:	Diablotin Systems
Differential Revision:	https://reviews.freebsd.org/D30293
2021-05-21 17:39:07 +02:00
Michal Meloun
c830003198 EXTRES: Ignore index modifier flags for table based clock dividers.
The divider table already contains the correct HW divider value, it should
not be modified by other flags such as 'CLK_DIV_ZERO_BASED'.

MFC after:	4 weeks
2020-12-27 17:47:19 +01:00
Emmanuel Vadot
e35c28a24b syscon: Add syscon_get_by_ofw_node
This allow to get a syscon node defined under a specific fdt node (which isn't
always the device one).
2020-11-17 14:59:58 +00:00
Bjoern A. Zeeb
3d8a0ab61d clk: fix indentation
Just fix indentation of an if() clause.
No functional changes intended.

MFC after:	3 days
2020-10-17 23:42:33 +00:00
Michal Meloun
c19440e350 Fix the inverted condition in mtx_asserts.
Mutex should be owned in affected functions.

Reborted by:	emaste
MFC after:	4 weeks
MFC with:	r366161
2020-10-01 09:50:08 +00:00
Michal Meloun
01d0f9c0e4 Refine locking inside of syscon driver.
In some cases, the syscon driver may be used by consumer requiring better
control about locking (ie. it may be used as registe file provider for clock
driver which needs locked access to multiple registers).
Add fine locking protocol methods together with bunch of helper functions
in syscon driver and implement this functionality in syscon_generic driver.

MFC after:	4 weeks
2020-09-25 16:44:01 +00:00
Michal Meloun
8dc348a479 Correctly handle nodes compatible with "syscon", "simple-bus".
Syscon can also have child nodes that share a registration file with it.
To do this correctly, follow these steps:
- subclass syscon from simplebus and expose it if the node is also
  "simple-bus" compatible.
- block simplebus probe for this compatible string, so it's priority
 (bus pass) doesn't colide with syscon driver.

While I'm in, also block "syscon", "simple-mfd" for the same reason.

MFC after:	4 weeks
2020-09-25 13:52:31 +00:00
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
Jessica Clarke
28da7c9ed0 Add syscon power and reset control device driver
This device driver supports both syscon-power and syscon-reset devices,
as specified in [1] and [2]. These provide a very simple interface for
power and reset control, and among other things are used by QEMU's virt
machine on RISC-V. A separate commit will enable this on RISC-V, as that
requires adding a RISC-V-specific riscv_syscon akin to r327936's
aw_syscon.

[1] https://www.kernel.org/doc/Documentation/devicetree/bindings/power/reset/syscon-poweroff.txt
[2] https://www.kernel.org/doc/Documentation/devicetree/bindings/power/reset/syscon-reboot.txt

Reviewed by:	brooks (mentor), jhb (mentor)
Approved by:	brooks (mentor), jhb (mentor)
Obtained from:	CheriBSD
Differential Revision:	https://reviews.freebsd.org/D25724
2020-07-26 18:19:50 +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
Emmanuel Vadot
9d2c88ab2a extres/syscon_generic: Make device quiet if not in boot verbose
On some boards there is a lot of of syscon node that are unused as
more specific drivers is probed before, no need to flood the console
for the mostly-unused generic ones.

MFC after:	1 week
2020-07-08 17:14:44 +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
Emmanuel Vadot
42d3cf0f82 regulator_fixed: Add a get_voltage method
Some consumer cannot know the voltage of the regulator without it.
While here, refuse to attach is min_voltage != max_voltage, it
shouldn't happens anyway.

Reviewed by:	mmel
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D23003
2020-01-16 20:52:26 +00:00
Kyle Evans
89476f9c99 regulator: small enhancements to regulator_shutdown
Highlights:

- Exit early if we're not disabling unused regulators; there's no need to
  take the regulator topology lock and re-evaluate this every iteration, as
  it's not going to change.
- Don't emit a notice that we're shutting down a regulator if it's not
  enabled, to reduce noise.
- Mention the outcome of the shutdown, to aide debugging and easily let
  developer/user collect list of regulators we actually shutdown to
  determine problematic one.

Reviewed by:	manu
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D22213
2020-01-12 04:07:03 +00:00
Emmanuel Vadot
650a41c6d0 regulator: fix regnode_method_get_voltage
This method is supposed to write the voltage into uvolt
and return an errno compatible value.

Reviewed by:	mmel
Differential Revision:	https://reviews.freebsd.org/D23006
2020-01-08 11:30:42 +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
9c3a56d076 regulator: Add regulator_check_voltage function
This function will call the regnode_check_voltage method for a given regulator
and check if the desired voltage in reachable by it.
Also adds a default method that check the std_param and which should be enough
for most regulators and add it as the method for axp* rk805 and fixed regulators.

Reviewed by:	mmel
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D22260
2019-11-06 14:55:24 +00:00
Emmanuel Vadot
a601368040 regulator: Add a regnode_set_constraint function
This method check that boot_on or always_on is set to 1 and if it
is it will try to enable the regulator.
The binding docs aren't clear on what to do but Linux enable the regulator
if any of those properties is set so we want to do the same.
The function first check the status to see if the regulator is
already enabled it then get the voltage to check if it is in a acceptable
range and then enables it.
This will be either called from the regnode_init method (if it's needed by the platform)
or by a SYSINIT at SI_SUB_LAST

Reviewed by:	mmel
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D22106
2019-10-23 09:56:53 +00:00
Emmanuel Vadot
a24735546b regulator: Add a regnode_method_init
This is a default init method for regulator that don't really
need one.

MFC after:	1 week
2019-10-23 09:54:12 +00:00
Michal Meloun
7f8c4c78f5 Add method for getting of syscon handle from parent device.
If simple multifuction device also provides syscon interface, its
childern should be able to consume it. Due to this:
- declare coresponding method in syscon interface
- implement it in simple multifunction device driver

MFC after:	1 week
2019-08-18 08:08:56 +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
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
Michal Meloun
2dd13cf6a4 extres: Unify error codes for <foo>_get_by_ofw_property() methods.
Return:
 - ENOENT if requested property doesn't exist
 - ENODEV if producer device is not (yet) attached
 - ENXIO otherwise

MFC after:	2 weeks
2019-03-19 14:30:54 +00:00
Michal Meloun
1289ca623e Properly define and declare phynode_topo_lock,
it should be single global variable.

X-MFC with:	r340845
Noticed by:	phynode_topo_lock
2019-01-27 15:50:36 +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
3cb36739ce regulator_fixed: Do not disable fixed regulator at probe
If the regulator is unused it will be disabled by the regulator_shutdown sysinit.

Tested on pinebook where the backlight is controlled by a fixed-regulator.
The regulator doesn't have a regulator-boot-on param (I'm gonna upstream this) and so we disable it at probe.
We later enable it but this cause the screen to go black.
Linux doesn't disable regulator at boot (at least for fixed-regulator) so better match this to have the same UX.

MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D17978
2018-11-26 18:46:15 +00:00
Emmanuel Vadot
f9f020a409 Derive PHY class to new one specialized for USB PHY functions.
Submitted by:	mmel
2018-11-23 19:43:18 +00:00