Commit graph

30 commits

Author SHA1 Message Date
Lukasz Madej c7c168b378 drivers: charger: charger_max20335: rename macro to reduce ambiguity
The ILimCntl name can be understood as both register name and its field
name. Therefore it is better to change macro name so it contains both
register and field name. Second field of this register will be also
utilized by this driver in the future and new code will be aligned to
this naming convention.

Signed-off-by: Lukasz Madej <l.madej@grinn-global.com>
2024-03-26 16:18:31 -04:00
Lukasz Madej b2c460f274 drivers: charger: charger_max20335: fix linear range usage
Fix validation of `linear_range_get_index()` results.
The function can resturn both 0 or -ERANGE but -EINVAL is never
returned. Use comparison against 0 to make the validation robust.

Use valid maximum index for the linear range. The 0x0C is reserved
value and should not be used. Therefore replace it with 0x0B.

Signed-off-by: Lukasz Madej <l.madej@grinn-global.com>
2024-03-26 16:18:31 -04:00
Lukasz Madej 82169bba15 drivers: charger: charger_max20335: drop redundant validation
`max20335_get_constant_charge_current()` and
`max20335_set_chgin_to_sys_current_limit()` functions has redundant input
values validation. Drop not important ones to make the code clean.
While on it remove `max20335_get_constant_charge_voltage()` function
since it become useless.

Signed-off-by: Lukasz Madej <l.madej@grinn-global.com>
2024-03-26 16:18:31 -04:00
Lukasz Madej d791526dd8 drivers: charger: charger_max20355: fix configuration
Maximum charging current is selected with an external resistor in
the MAX20335 charger. Therefore it is not possible to configure it
with software directly. There is only a capability to limit current
set with hardware but configuration of the limiter is not
straight-forward.

To reflect real functionality, drop usage of
`constant-charge-current-max-microamp` property as an required one and
use custom `chgin-to-sys-current-limit-microamp` instead.
Use enum in binding file to signalize improper values at compile time.

Drop support for `CHARGER_PROP_CONSTANT_CHARGE_CURRENT_UA` API property
since this cannot be handled.

The `max20335_get_constant_charge_current()` function become useless so
remove it.

Signed-off-by: Lukasz Madej <l.madej@grinn-global.com>
2024-03-26 16:18:31 -04:00
Lukasz Madej f14228744f drivers: charger: charger_max20335: handle charger notifications
Add support for status and online notification properties.
Fire these notifications from int_routine_handler work directly.
Such approach makes the code cleaner and does not affect overall
max20335 interrupt processing performance. However application code
processing these notifications cannot be blocking.

Signed-off-by: Lukasz Madej <l.madej@grinn-global.com>
2024-03-08 09:38:03 +01:00
Lukasz Madej d97cebd3ca drivers: charger: charger_max20335: fix properties set
Charger hardware configuration registers are set to zero every time
external voltage is applied. Assure proper charger configuration by
buffering properties set by application and applying them at external
voltage connection event notified via interrupt.

Signed-off-by: Lukasz Madej <l.madej@grinn-global.com>
2024-03-05 18:23:12 +00:00
Lukasz Madej e38729de63 drivers: charger: charger_max20335: support charger online
Add support for charger online property.

Signed-off-by: Lukasz Madej <l.madej@grinn-global.com>
2024-03-05 18:23:12 +00:00
Lukasz Madej d43e627938 drivers: charger: charger_max20335: relocate charger state definition
An anonymous enum describing charger status is used only by one
function therefore reduce scope of this enum.

Signed-off-by: Lukasz Madej <l.madej@grinn-global.com>
2024-03-05 18:23:12 +00:00
Lukasz Madej 90c32e99d6 drivers: charger: charger_max20335: introduce int utilization
Utilization of chip interrupt line is mandatory to assure proper
charger state control. Handle interrupt to prepare the driver for
implementation of such functionality.
Modify charger status update so the current state is fetched in the
interrupt handler.

Use level based interrupts combined with interrupt disabling for a
period of time after interrupt handling to reduce number of interrupts
triggered by the charger. There may be a case where the charger
produces burst of interrupts for a several seconds and if the code
attempts to handle every single interrupt separatery then the system
might be significantly overloaded.

Co-authored-by: Bartosz Bilas <b.bilas@grinn-global.com>
Signed-off-by: Lukasz Madej <l.madej@grinn-global.com>
2024-03-05 18:23:12 +00:00
Lukasz Madej e9eb1d841e drivers: charger: charger_max20335: fix argument name
Rename `current_uv` argument name to `voltage_uv` in function
max20335_get_constant_charge_voltage() to make the name aligned with
its usage.

Signed-off-by: Lukasz Madej <l.madej@grinn-global.com>
2024-03-05 18:23:12 +00:00
Lukasz Madej d8ebe7b6c9 drivers: charger: charger_max20335: rename status get function
Current driver handles charger status only but the charger chip
provides plenty of different statuses. Change name of
max20335_get_status() function to max20335_get_charger_status()
to make further implementations easier.

Signed-off-by: Lukasz Madej <l.madej@grinn-global.com>
2024-03-05 18:23:12 +00:00
Ricardo Rivera-Matos 5868c701ef samples: charger: Demos new output limit properties
Adds use of CHARGER_PROP_DISCHARGE_CURRENT_NOTIFICATION and
CHARGER_PROP_SYSTEM_VOLTAGE_NOTIFICATION_UV to the charger
sample application.

Signed-off-by: Ricardo Rivera-Matos <rriveram@opensource.cirrus.com>
2024-02-26 11:33:24 +00:00
Gustavo Silva b2b4016963 drivers: charger: bq25180: fix return value check
Fix missing check of the return value of `bq25180_set_charge_current`
function, resulting in logically dead code, as indicated by Coverity
CID 347197.

Signed-off-by: Gustavo Silva <gustavograzs@gmail.com>
2024-02-19 09:38:50 -06:00
Fabio Baltieri 044529d0cd charger: bq25180: implement online and status properties
Implement CHARGER_PROP_ONLINE and CHARGER_PROP_STATUS for the bq25180
driver.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-01-31 17:59:50 -06:00
Fabio Baltieri 63cdde10d3 charger: bq25180: reuse bq25180_set_charge_current for the initial set
Reuse bq25180_set_charge_current for the initial setting of the charging
current.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-01-31 17:59:50 -06:00
Bartosz Bilas e8f223dbe8 drivers: charger: bq24190: fix api and init functions references
There is no need to use & as a function reference, so remove it.

Signed-off-by: Bartosz Bilas <b.bilas@grinn-global.com>
2024-01-10 20:54:04 -05:00
Fabio Baltieri e517af4cff charger: add a driver for bq25180
Add a driver for the TI BQ25180. Implement enable/disable and current
set/get.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-01-05 09:00:21 +01:00
Ricardo Rivera-Matos 16519a5b3c drivers: charger: Updates drivers to use charge_enable handler
Updates existing drivers to make use of the charge_enable handler.

Signed-off-by: Ricardo Rivera-Matos <ricardo.rivera-matos@cirrus.com>
2023-12-12 10:49:39 -06:00
Ricardo Rivera-Matos d4ed6bacf0 drivers: charger: Adds charge_enable handler
Adds a charge_enable handler to facilitate enabling and disabling
a charge cycle. This deprecates enabling and disable the charge
cycle via the CHARGER_PROP_STATUS property.

Signed-off-by: Ricardo Rivera-Matos <ricardo.rivera-matos@cirrus.com>
2023-12-12 10:49:39 -06:00
Bartosz Bilas 39eb124c81 drivers: add MAX20335 charger driver
Add a MAX20335 MFD subdriver for the built-in
battery charger.

Signed-off-by: Bartosz Bilas <b.bilas@grinn-global.com>
2023-11-13 09:48:33 +01:00
Bartosz Bilas 8129307887 drivers: charger: add charger prefix for bq24190
Many (or almost all) drivers contain the specified prefixes
related to the driver subsys so add the missing one for the
BQ24190.

Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
2023-11-09 09:57:30 -06:00
Anas Nashif a08bfeb49c syscall: rename Z_OOPS -> K_OOPS
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 1a9de05767 syscall: rename Z_SYSCALL_DRIVER_ -> K_SYSCALL_DRIVER_
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 9c1aeb5fd3 syscall: rename z_user_ to k_usermode_
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 56fddd805a syscall: rename z_user_from_copy -> k_usermode_from_copy
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 4e396174ce kernel: move syscall_handler.h to internal include directory
Move the syscall_handler.h header, used internally only to a dedicated
internal folder that should not be used outside of Zephyr.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Ricardo Rivera-Matos fd06cd7c97 drivers: charger: Introduces BQ24190 support
Adds support for the BQ24190 family of charging ICs.

Signed-off-by: Ricardo Rivera-Matos <rriveram@opensource.cirrus.com>
2023-10-20 14:55:22 +02:00
Fabio Baltieri c03d0f83c8 drivers: charger: fix i2c_dump_msgs_rw argument
Fixes:

zephyr/drivers/charger/emul_sbs_charger.c:70:26: warning: passing
argument 1 of ‘i2c_dump_msgs_rw’ from incompatible pointer type
[-Wincompatible-pointer-types]

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-09-07 21:41:31 +02:00
Ricardo Rivera-Matos aee815f19d charger: Sample sbs charger driver with tests
Adds a sample sbs charger driver and basics tests.

Signed-off-by: Ricardo Rivera-Matos <rriveram@opensource.cirrus.com>
2023-09-07 13:03:13 -04:00
Ricardo Rivera-Matos a7adb06ff4 charger: Initial charger dedicated API
Add initial charger driver API with the most basic of native_posix
driver tests.

Signed-off-by: Ricardo Rivera-Matos <rriveram@opensource.cirrus.com>
2023-09-07 13:03:13 -04:00