Commit Graph

118 Commits

Author SHA1 Message Date
Nick Ward 2d65acca3a drivers: gpio: use gpio_is_ready_dt helper function
Update `struct gpio_dt_spec` use with gpio_is_ready_dt()

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2023-08-28 08:48:35 -05:00
Martin Kiepfer 74db02bad1 drivers: gpio: AXP192 GPIO driver
AXP192 is a small power management IC, that also
features 5 GPIOS.
Besides GPIO driver this commit also includes needed modifications
in axp192 regulator and mfd driver as LDOIO0 functioanlity
is multiplexed with GPIO0 pin.

Signed-off-by: Martin Kiepfer <mrmarteng@teleschirm.org>
2023-08-22 18:08:51 +02:00
Fabio Baltieri 5b1b874206 regulator: shell: add device name completion
Add the code for the shell to complete the device name in the regulator
commands.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-08-21 10:56:12 +02:00
Mykola Kvach 5a87252c53 drivers: regulator: add regulator-gpio driver
Add basic support of 'regulator-gpio'. For now, it is support
only controling voltage and driver presents only six functions:
  * enable and disable the regulator;
  * set and get voltage;
  * count and list of voltage(s).

Signed-off-by: Mykola Kvach <mykola_kvach@epam.com>
2023-08-21 10:55:26 +02:00
Fabio Baltieri d55ea3aa72 drivers: regulator: shell: add a shipmode command
Add a shipmode regulator shell command to test shipmode on regulators.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-08-14 18:11:36 +00:00
Mykola Kvach d9fe261f8e drivers: regulator-fixed: extend api of driver (list/count voltages)
Allow properties 'regulator-min-microvolt' and 'regulator-max-microvolt'
for fixed regulators: Note: they should be equal.

Add simple functions for getting list of allowed and count of voltages.

Signed-off-by: Mykola Kvach <mykola_kvach@epam.com>
2023-08-10 18:11:35 +00:00
Mykola Kvach ed9ca0f6d3 drivers: regulator-fixed: add possibility to work without enable pins
Possible situation is that in some driver, devices can be controlled in
different ways: in some, we can only turn the power on or off, in others,
we can only control the voltage, and in some, we can control power supply
or voltage level. There may also be devices where there is no control
over power supply at all. A clear example of this can be eMMC devices
where the voltage is usually fixed and they are always powered on.
However, we would like to have a common code for controlling all the
mentioned types of devices, at least the driver shouldn't worry about the
implementation details of voltage regulators. Therefore, there may exist
empty regulators - regulators that only contain information about the
supported voltage, and we cannot change anything in them. The device tree
node description for such a regulator is only necessary for compatibility
with other regulators. Hence, we need to add the possibility of the
existence of such a dummy fixed-regulator.

In this commit, support for a fixed dummy regulator without the ability
for any control has been added. Note that such support also exists in the
Linux kernel. In other words, the logic of the fixed regulator has been
aligned with the logic of the fixed regulator inside the Linux kernel.

Signed-off-by: Mykola Kvach <mykola_kvach@epam.com>
2023-08-10 18:11:35 +00:00
Martin Kiepfer 09da4cf89d driver: regulator: Add support for AXP192 power management IC
AXP192 is a small and simple power management IC featuring different
LDOs, DCDCs, AINs and also GPIOs. It also offers functionaltiy for
battery management.
This change includes the basic regulator driver functionaltiy for
LDO2-3 and DCDC1-3 as well as the mfd driver layer. Further drivers
for GPIO and ADC will follow.
Drivers have been developed and tested on M5StackCore2, an ESP32-based
board. Support for M5StackCore2 is still in progress.

Signed-off-by: Martin Kiepfer <mrmarteng@teleschirm.org>
2023-07-19 09:52:15 +00:00
Andy Sinclair 024196be9d drivers: regulator: npm1300: Added ship mode
npm1300 ship mode entry added

Signed-off-by: Andy Sinclair <andy.sinclair@nordicsemi.no>
2023-07-19 09:30:22 +00:00
Andy Sinclair f6aa1c4321 drivers: regulator: Added ship mode to API
Added ship mode entry function to common regulator driver

Signed-off-by: Andy Sinclair <andy.sinclair@nordicsemi.no>
2023-07-19 09:30:22 +00:00
Martin Kiepfer 4da1518108 regulator: shell: fix unitialized variable warning from SCA
Static code analysis it has highlighted that a variable is beeing
accessed before initializing. This is a very minor fix
to resolve this potential issue.

Signed-off-by: Martin Kiepfer <mrmarteng@teleschirm.org>
2023-07-07 10:51:53 +02:00
Andy Sinclair 5e6f82c872 drivers: regulator: npm1300: Now uses MFD register access functions
Local register read/write functions have been removed and replaced
with calls to the new MFD functions.

Signed-off-by: Andy Sinclair <andy.sinclair@nordicsemi.no>
2023-06-19 11:02:58 +02:00
Daniel DeGrasse bd1cf25821 drivers: regulator: regulator_shell: add command to set DVS mode
Add command to set DVS mode, to aid in testing regulators that expose
this functionality. Since DVS modes are device specific, take an integer
as the mode identifier and pass it to the driver directly.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2023-06-17 07:59:26 -04:00
Daniel DeGrasse 402d4eb0da drivers: regulator: pca9420: fix support for DVS modes
Fix support for DVS modes, as the dvs_state_set implementation
previously had the mask and value parameters in the
i2c_reg_update_byte_dt function swapped.

Also, record the active DVS state and update the voltage get/set and
regulator enable/disable function to target the active DVS mode. This
will enable a user to configure multiple run modes, and modify target
voltages for those modes when in the new mode. When a user is utilizing
the MODESEL pins, update the active state but return an error so that
the application can still edit settings for the new DVS mode once it has
reconfigured the appropriate pins.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2023-06-07 05:48:11 -04:00
Gerard Marull-Paretas 9494981181 drivers: regulator: npm6001: remove common device
Common device part is now handled by the nPM6001 MFD device driver.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-24 19:39:55 -04:00
Gerard Marull-Paretas 5521db3576 drivers: regulator: npm6001: format code
Format code using clang-format. This will ease incoming refactor.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-24 19:39:55 -04:00
Gerard Marull-Paretas d99afcd0da drivers: regulator: adp5360: remove unused init priority
The common init priority is a leftover from a previous implementation.
Remove it as it's not used.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-24 13:14:52 -04:00
Gerard Marull-Paretas e05df8faf1 drivers: regulator: adp5360: initial version
Add a new regulator driver for Analog Devices ADP5360. While it is a MFD
device, only support for BUCK/BUCKBOOST regulators is added in this
patch.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-24 11:54:30 +00:00
Andy Sinclair d82781acb9 drivers: regulator: npm1300: Fixed ldo2 device source
Fixed error which meant that ldo2 referenced the wrong source

Signed-off-by: Andy Sinclair <andy.sinclair@nordicsemi.no>
2023-05-23 22:08:46 +02:00
Gerard Marull-Paretas 7fa4776948 drivers: regulator: fixed: refactor initialization code.
In some cases, the enable pin may be already enabled by a previous
stage, e.g. bootloader. Therefore, it is not desirable to disable
the pin, as it could cause malfunctioning of the device. Refactor init
procedure so that we pick the right GPIO flags during the first
configuration stage.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-28 20:38:17 +02:00
Gerard Marull-Paretas 9faa60aeda drivers: regulator: allow non-thread-safe reference counting
In some cases, it may be desirable to not have thread-safe reference
counting. For example, when CONFIG_MULTITHREADING=n.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-25 12:23:07 +02:00
Gerard Marull-Paretas 1eb683a514 device: remove redundant init functions
Remove all init functions that do nothing, and provide a `NULL` to
*DEVICE*DEFINE* macros.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-19 10:00:25 +02:00
Andy Sinclair d1e201ccf6 drivers: regulator: npm1300: Initial driver for nPM1300 PMIC
Initial regulator driver for Nordic NPM1300 PMIC.

Signed-off-by: Andy Sinclair <andy.sinclair@nordicsemi.no>
2023-04-17 10:14:40 +02:00
Andy Sinclair a00713bc45 drivers: regulator: Added initial voltage configuration
The regulator driver has a configured min/max range that is used
to limit set values, and to initialise the regulator.

A new init value has been added, so that the startup voltage can
be higher than the lowest permitted value.

Signed-off-by: Andy Sinclair <andy.sinclair@nordicsemi.no>
2023-03-22 21:19:51 +01:00
Ionut Catalin Pavel 867c254801 drivers: regulator: common: skip voltage change at init if already valid
The current implementation always sets the voltage before enabling,
even if the current voltage is in the allowed range.

This has some side effects, i.e. for PMIC regulators that are
pre-programmed for a specific value but allow voltage changes during
runtime. The side effect being that the regulator will always be reset
to the lower value of the voltage range at init.

Another usecase would be when a bootloader sets a specific voltage then
loads an application that uses the same driver.

The proposed fix is to evaluate the current voltage and try to bring
the actual voltage in range if the current voltage is not valid
according to the min/max constraints.

Tested on custom SAMD20 board with a custom RK816 PMIC driver.

Signed-off-by: Ionut Catalin Pavel <iocapa@iocapa.com>
2023-03-13 18:33:26 +00:00
TOKITA Hiroshi 47f52bba42 drivers: regulator: add support for RaspberryPi Pico regulator.
Add support for rpi_pico regulator.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@fujitsu.com>
2023-03-02 21:14:34 +01:00
Gerard Marull-Paretas e59e38532a drivers: regulator: shell: fix fp number parsing
Parser did not handle decimals correctly (multiplier was not decreased).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-01-16 16:52:35 +01:00
Gerard Marull-Paretas 0c28da26ba drivers: regulator: npm6001: handle LDO0 set voltage correctly
Even if the regulator is fixed, allow valid voltage input (1.8V).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-01-16 16:52:35 +01:00
Gerard Marull-Paretas 240be492fa drivers: regulator: common: set regulator voltage before enabling
Regulator voltage needs to be within allowed range before enabling. It
could happen that regulator default voltage is out of the allowed range,
so the regulator could be enabled at boot time producing a not-allowed
voltage.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-01-16 16:52:35 +01:00
Gerard Marull-Paretas 4eb74c8ed2 drivers: regulator: remove ONOFF dependency
The regulator drivers no longer depend on ONOFF.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-01-16 16:52:35 +01:00
Gerard Marull-Paretas e086738b88 sys: linear_range: allow out-of-range values/windows
The existing linear_range API did not allow values or windows outside of
the linear range (returned -EINVAL). With this change values are allowed
outside of the range, being adjusted to the edge values (min/max)
instead. In the case of windows, it is allowed to have partial
intersection. In both cases, the API assigns a valid index (nearest) and
returns -ERANGE. This change is useful because the main client of the
linear range API, regulators, needs such behavior. For example, If an
application specifies a voltage range from 1.0V to 1.5V and the
regulator supports from 1.2V to 2.7V, the regulator can configure a
voltage that satisfies the condition: 1.2V.  With the current API, the
input would be refused because 1.0V lies outside of the 1.2V-2.7V range.

Also, for constant ranges, the minimum index is returned.

Tests have been updated/extended accordingly.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-01-16 16:52:35 +01:00
Gerard Marull-Paretas 3bd9352b24 drivers: regulator: npm1100: regulator device may be unused
Since nPM1100 may be configured statically in some circuits, BUCK node
may note be defined, so neither API ops or init call are used in the
code. Add __unused attribute to account for such case.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-01-13 16:14:35 +01:00
Gerard Marull-Paretas 8c73db666c drivers: regulator: npm1100: add initial support
While nPM1100 is to be operated in fixed configuration for some
applications, it has some degree of configuration via GPIOs. For
example, mode (auto/PWM) can be configured via MODE pin. VBUS current
can also be adjusted using ISET pin, even though there is no API yet to
limit the PMIC input current.

This patch adds a new regulator class driver for nPM1100 PMIC, so that
it can be used with the standard regulator API when needed.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-01-12 19:07:05 +01:00
Gerard Marull-Paretas a6575e5834 drivers: regulator: npm6001: add support for BUCK1/2 disable
BUCK1/2 are defined as "always on" regulators, however, there is a
special override register that allows to turn them on/off.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-01-09 16:19:09 +00:00
Gerard Marull-Paretas 7feb008c85 drivers: regulator: common: allow to specify on by default
Some regulators are enabled by default, however, such condition cannot
be captured now by the regulator driver API. Refactor
regulator_common_init_enable to regulator_common_init (enable removed,
as it also sets mode) and add a new argument to specify such condition.
With this change, regulator_disable() and regulator_is_enabled() work as
expected without a first call to regulator_enable().

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-01-09 16:19:09 +00:00
Gerard Marull-Paretas 24f2c30678 drivers: regulator: shell: fix isdigit() usage
ISO/IEC 9899:1999 (C Standard), §7.4 Character handling <ctype.h>:

In all cases the argument is an int, the value of which shall be
representable as an unsigned char or shall equal the value of the macro
EOF. If the argument has any other value, the behavior is undefined.

So add a cast to unsigned char to make sure we do not trigger UB.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-01-04 11:19:25 +01:00
Gerard Marull-Paretas ea7293e464 drivers: regulator: shell: fix printing of first voltage
The first supported voltages was not printed.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-12-27 16:50:36 +00:00
Gerard Marull-Paretas 2c9a9c3671 drivers: regulator: shell: refactor shell
- Refactor the regulator shell so that it exposes all regulator APIs
- vset/iset commands allow to specify a single value (equal min/max) or
  a range
- Voltage/current input is now more user friendly, e.g. user can specify
  units and decimals: 3.3v, 200mv, -4mv, etc.
- Reported values are also printed in a more user friendly way, e.g.
  1800000 uV will be printed as 1.800 V.
- Added new command to list supported voltages

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-12-27 13:12:55 +01:00
Gerard Marull-Paretas 5ec95ef35e drivers: regulator: npm6001: add support for get_mode
Allow to query operating mode on each BUCK converter (PWM or
Hysteretic).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-12-27 13:12:55 +01:00
Gerard Marull-Paretas 1ca1f25918 drivers: regulator: add get_mode API
Add a new API to query the configured regulator mode. Updated fake
driver and API tests.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-12-27 13:12:55 +01:00
Gerard Marull-Paretas fbba106a23 drivers: regulator: apply initial mode
Apply initial mode (regulator-initial-mode) as part of the
regulator_common_init_enable call. Update tests to cover this change.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-12-27 13:12:55 +01:00
Gerard Marull-Paretas 6f4c019312 drivers: regulator: common: remove redundant cast
Unlike in C++ code, explicit casts from void* are not needed, so remove
them.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-12-27 13:12:55 +01:00
Gerard Marull-Paretas 1080afa680 drivers: regulator: add fake driver
Add FFF-based fake regulator driver. This driver can be used as a stub
or mock in testing.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-12-20 10:15:29 +00:00
Gerard Marull-Paretas 63c005d3b4 drivers: regulator: fix set_current_limit limits check
Only current ranges out of the allowed range have to be skipped.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-12-20 10:15:29 +00:00
Gerard Marull-Paretas 8c6819120e drivers: regulator: fix set_voltage limits check
Only voltage ranges out of the allowed range have to be skipped.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-12-20 10:15:29 +00:00
Gerard Marull-Paretas 2b6a211946 drivers: regulator: fix is_supported_voltage return code
If a voltage is not supported we need to return false, not a negative
errno.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-12-20 10:15:29 +00:00
Gerard Marull-Paretas 491a132369 drivers: regulator: common: fix is_supported_voltage comparison
The edge voltages within a range need to be included as part of the
supported comparison.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-12-20 10:15:29 +00:00
Gerard Marull-Paretas 7568749c8c drivers: regulator: initial driver for nPM6001
Add initial driver for the nPM6001 PMIC.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-12-16 11:26:47 +01:00
Gerard Marull-Paretas 539d4aa6e6 drivers: regulator: add common init enable API
Add a new API for drivers that can be called to initialize the regulator
at init time if `regulator-boot-on` or `regulator-always-on` are set.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-12-14 17:01:44 +01:00
Gerard Marull-Paretas 9b5152153b drivers: regulator: add regulator_is_enabled
Add a new API to check if a regulator is enabled or not.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-12-14 17:01:44 +01:00