Commit graph

46 commits

Author SHA1 Message Date
Roman Studenikin 260fc89643 drivers: use DT_INST_PROP over DT_INST_PROP_OR if possible
It might happens that DT(_INST)_PROP_OR is used with boolean properties.
For instance:

	.single_wire = DT_INST_PROP_OR(index, single_wire, false),	\
	.tx_rx_swap = DT_INST_PROP_OR(index, tx_rx_swap, false),	\

This is not required as boolean properties are generated with false
value when not present, so the _OR macro extension is superflous
and the above code can be replaced by:

	.single_wire = DT_INST_PROP(index, single_wire),		\
	.tx_rx_swap = DT_INST_PROP(index, tx_rx_swap),			\

Signed-off-by: Roman Studenikin <srv@meta.com>
2024-01-30 00:26:58 +00: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 9c4d881183 syscall: rename Z_SYSCALL_ to K_SYSCALL_
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
Martin Calsyn 12c0204b60 drivers: fuel_gauge: max17048: Fix overflow when calculating voltage
Annotate the calculation with type casts to force
promotion to uint32_t and then cast back down
to uint16_t for the return. This solves the issue
with invalid voltage (mV) values being returned
due to overflow during the conversion from the
register value on the max17048 chip.

Signed-off-by: Martin Calsyn <martin.calsyn@outcomex.com.au>
2023-10-13 19:07:38 +01:00
Aaron Massey 32b27384a6 fuel_gauge: Fix desired current/voltage units
The desired current/voltage properties make use of milliamps/volts while
the present current/voltage properties make use of microamps/volts.

Fix the desired current/voltage properties to be consistent with the
present current/voltage properties where they're most likely to be used
with.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-10-09 19:01:49 +03:00
Aaron Massey 12cbfcf397 fuel_gauge: Repl property struct w/ union
Based on review of the similar charger driver API, it's been demonstrated
from the community that embedding a per value property type when fetching
properties. Separating off the property types from the property values
themselves also allow an array of property types to declared as static
const.

Break up fuel_gauge_property struct into a fuel_gauge_prop_val union and a
fuel_gauge_prop_t property type as inputs into fuel gauge API functions.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-09-27 12:07:59 +02:00
Aaron Massey 329ecd1e12 fuel_gauge: Remove status from fuel gauge properties
Based on review of the similar charger driver API, it's been demonstrated
from the community that embedding a per value status code when fetching
multiple properties isn't particularly wanted or needed. It was largely
considered not worth the additional maintenance to have the extra per
property error information.

Remove the status field from the fuel_gauge property value structs.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-09-27 12:07:59 +02:00
Aaron Massey bddd88955d fuel_gauge: Add fuel_guage_set_props()
The fuel_gauge_set_prop() function prototype declares a function that sets
multiple fuel gauge properties at once. The naming suggests it ought to
fetch a singular property at a time. Moreso, some clients may just want to
set properties one at a time and may feel uncomfortable using a prototype
for fetching multiple properties when wanting to fetch them one at a time.

Modify fuel_gauge_set_prop() to fetch a single property and add
fuel_gauge_set_props() to support fetching multiple properties. Modify
existing tests/drivers/samples.

This is part of #61818 work.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-09-27 12:07:59 +02:00
Aaron Massey e294b16a2f fuel_gauge: Add fuel_guage_get_props()
The fuel_gauge_get_prop() function prototype declares a function that
retrieves multiple fuel gauge properties at once. The naming suggests it
ought to fetch a singular property at a time. Moreso, some clients may just
want to fetch properties one at a time and may feel uncomfortable using a
prototype for fetching multiple properties when wanting to fetch them one
at a time.

Modify fuel_gauge_get_prop() to fetch a single property and add
fuel_gauge_get_props() to support fetching multiple properties. Modify
existing tests/drivers/samples.

This is part of #61818 work.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-09-27 12:07:59 +02:00
Aaron Massey a7b25d599b fuel_gauge: Join get/set prop structs
The fuel gauge API uses separate get/set property structs to indicate what
properties are readable or writable. This lead to duplication in property
names and potential confusion for new users of the API. See issue #61818.
In addition to above, drivers already determine at runtime if a property is
supported for read or write actions.

Join the get/set fuel gauge property structs as a single struct.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-09-18 10:38:59 +01:00
Fabio Baltieri c99f7ec019 drivers: fuel_gauge: fix i2c_dump_msgs_rw argument
Fix another i2c_dump_msgs_rw:

/drivers/fuel_gauge/bq27z746/emul_bq27z746.c:282:26: warning: passing
argument 1 of ‘i2c_dump_msgs_rw’ from incompatible pointer type

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-09-13 12:37:32 +01:00
Marcel Krüger 387f3c2092 drivers: fuelgauge: Add TI BQ27z746 driver
Add driver for the Texas Instruments BQ27z746 fuel gauge

Signed-off-by: Marcel Krüger <marcel.krueger@ithinx.io>
2023-09-13 12:05:04 +02:00
Aaron Massey c6fd21c5de emul: Remove unused ZTEST_DMEM in sbs emulator
The redefinition of ZTEST_DMEM in the SBS emulator is unused. We ought to
remove it as it's dead code.

Remove the unused #define ZTEST_DMEM.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-09-12 17:23:00 +01:00
Aaron Massey 8035ec69fa emul: Add syscall support for fuel gauge emulators
In order to ease user thread testing with fuel gauges, enable syscalls for
the fuel gauge emulator backend API.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-09-12 17:23:00 +01:00
Michał Barnaś 4aac1756a9 i2c: use device instead of name for i2c dump messages
This commit changes the parameter of i2c_dump_msgs function from
string name to pointer to the device structure.
It allows for comparison of device pointers and allow to use
the printed device name in i2c shell commands.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2023-09-06 17:54:53 +02:00
Daniel Leung 302f06534e fuel_gauge: sbs_gauge: fix uninitialized variable warning
The return variable rc in sbs_gauge_do_battery_cutoff() needs to
be initialized, or else it would return random value if the for
loop is never entered.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-23 19:36:41 -04:00
Aaron Massey 82bfb26446 fuel_gauge: Add battery cutoff support
Many fuel gauge ICs offer a battery cutoff/shipping mode functionality that
cutoff charge from the battery. This is often useful for preserving battery
charge on devices while in storage.

Add battery cutoff support to the fuel gauge API with a generic default SBS
driver showing an example of support in tests.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-08-22 18:05:50 +02:00
Marcel Krüger f2ba0b7ae2 drivers: fuel_gauge: max17048: Remov unused var
Remove the unused variable 'data' from function
max17048_emul_transfer_i2c()

Signed-off-by: Marcel Krüger <marcel.krueger@ithinx.io>
2023-07-13 09:21:52 +02:00
Aaron Massey 3e33d6af89 emul: SBS Gauge emulator reset rule
Since we have state that gets mutated between tests in the SBS fuel gauge
emulator we ought to reset its state before each test.

Add a reset rule to the SBS fuel gauge emulator that resets the state
before each test. Note: This includes allowing the emulator state to be
modified by user-threads.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-07-07 09:22:20 +02:00
Aaron Massey e1401fcf5e emul: Add SBS Gauge emulator backend_api
In order to support easier setup of test scenarios with fuel gauge
emulators, we should expose an API that can change internal emulator state.

Add a minimal fuel gauge emulator backend API for setting the charging
current and voltage with a sample implementation in the emul_sbs_gauge with
an associated driver test.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-07-07 09:22:20 +02:00
Daniel Leung 26ecaba4af drivers: syscalls: use zephyr_syscall_header
This adds a few line use zephyr_syscall_header() to include
headers containing syscall function prototypes.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-06-17 07:57:45 -04:00
Alvaro Garcia 4d854a562c drivers: fixed div by zero when reading max17048
Avoid divsion by zero when current rate is zero

Signed-off-by: Alvaro Garcia <maxpowel@gmail.com>
2023-06-02 18:51:25 -04:00
Andrei Emeltchenko f6211e2641 drivers: sbs_gauge: Fix buffer overflow
Fixes buffer overflow when trying to copy 5 bytes to 4 bytes array.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-05-23 08:55:43 +02:00
Peter Rowley d01780fc94 drivers: fuel_gauge: sbs_gauge: Fix copy/paste error in RTTF
Looks like a copy/paste error when copying runtime to empty to runtime
to full.  Fixing so that we're assigning to the right union member.

Signed-off-by: Peter Rowley <perowle@microsoft.com>
2023-05-20 05:59:16 -04:00
Peter Rowley 66c568e300 drivers: fuel_gauge: sbs_gauge: Add support for buffer registers
The buffer registers (chemistry, manufacturer name, device name) were
not implemented. Implemented by adding a new api interface for
retrieving buffer properties. fuel_gauge_get_block_property has been
added, and uses a memory buffer allocated in the app in order to
store the fuel gauge information.

Signed-off-by: Peter Rowley <perowle@microsoft.com>
2023-05-19 16:39:25 -04:00
Peter Rowley ff36548616 drivers: fuel_gauge: Add support for RSOC and ASOC
Current driver only allows state-of-charge.  Adding relative-state-
of-charge and absolute-state-of-charge to differentiate between the
different types.  Updated sbs and max drivers to support new enum.
Discussed in issue #57523

Signed-off-by: Peter Rowley <perowle@microsoft.com>
2023-05-19 13:40:19 -04:00
Madhurima Paruchuri f8d9cd67c8 drivers: sbs_gauge: Reformat the changes
Reformat the files touched by code changes using clang

Signed-off-by: Madhurima Paruchuri <mparuchuri@google.com>
2023-05-16 12:07:14 +02:00
Madhurima Paruchuri 2432c94186 drivers: sbs_gauge: Add support for Alarm properties
RemainingCapacityAlarm(r/w) and RemainingTimeAlarm(r/w)

Signed-off-by: Madhurima Paruchuri <mparuchuri@google.com>
2023-05-16 12:07:14 +02:00
Aaron Massey 07ee466591 emul: Migrate all emulation use to use DT_HAS_
Remove all enabling of CONFIG_EMUL_.* in favor of automatically enabling
peripheral emulators based on the compatible string presence in the device
tree and the one true CONFIG_EMUL.

Zephyr has long since moved to a model of enabling drivers based on the
presence of their associated IC's compatible string in the final devicetree
overlay. There is no reason that emulators can't align in just the same
way, and probably ought to to remove superfluous enabling of configs.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-04-28 08:37:33 -05:00
Aaron Massey 75b2f5abed emul: Fuel gauge tests direct access to emul_sbs
The fuel gauge tests should *not* have to enable CONFIG_SENSOR in order to
get access to the sbs gauge emulator.

Allow fuel_gauge sbs_gauge direct access to emul_sbs_gauge.c

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-04-21 09:39:00 +02:00
Madhurima Paruchuri 2535b1542b drivers: sbs_gauge: Rename atRate properties to include 'SBS'
Add the term 'SBS' in atRate properties and Battery mode property name,
as they are specific to SBS

Signed-off-by: Madhurima Paruchuri <mparuchuri@google.com>
2023-04-03 17:53:42 +02:00
Madhurima Paruchuri 9727cafb41 drivers: sbs_gauge: Add support for AtRate properties
BatteryMode(w), AtRate(r/w), AtRateTimeToFull(r), AtRateTimeToEmpty(r)
and AtRateOK(r)

Signed-off-by: Madhurima Paruchuri <mparuchuri@google.com>
2023-04-03 17:53:42 +02:00
Alvaro Garcia 2380710020 drivers: Added fuel gauge max17048
Added support for fuel gauge max17048

Signed-off-by: Alvaro Garcia <maxpowel@gmail.com>
2023-03-22 14:51:33 -04:00
Aaron Massey a2e0a860a6 fuel_gauge: Add init priority
Add an device driver initialization priority for fuel gauge drivers.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-03-17 09:29:39 +01:00
Yuval Peress 8ac822e69c emul: Cleanup emul directory
Avoid implementations in the subsys emul directory to keep the directory
focused on emulator subsystem instead of consumers. Consumers should be
implemented side-by-side to their drivers

Signed-off-by: Yuval Peress <peress@google.com>
2023-02-24 11:50:10 +01:00
Aaron Massey 6cdef0894f drivers: fuel_gauge: kernel drivers use syscalls
The fuel gauge API doesn't make use of syscalls with device drivers, which
is not congruent with Zephyr's security model.

Correct the fuel gauge API to only allow access to fuel gauge device
drivers functionality via syscalls to keep with Zephyr's security model.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-02-22 08:51:55 +01:00
Aaron Massey 7d83bf7d54 drivers: fuel_gauge: Rename API struct
Fuel gauge API struct type is currently named battery_driver_api, this is
inaccurate as the API struct represents functions for interacting with fuel
gauge drivers in particular.

Rename the API struct type to fuel_gauge_driver_api to clearly signal its
functionality.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-02-22 08:51:55 +01:00
Rajavardhan Gundi 09d8123d0a drivers: sbs_gauge: Add support for additional properties
Fuel Gauge mode, status, charge current, charge voltage, design
capacity and design voltage are added.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2023-02-19 20:42:10 -05:00
Aaron Massey c4be38dec1 fuel_gauge: sbs_gauge: Enable MFR ACC write
Update the SBS Gauge driver that implements the fuel_gauge API to implement
a set_property function allowing the writing of an SBS word to the
manufacturer access register per the SBS spec.

Includes an update to the SBS Gauge emulator and SBS fuel gauge tests to
weakly verify the code runs.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-01-08 19:48:12 +01:00
Aaron Massey c0762d003a fuel_gauge: Implement sbs gauge read for mfr acc
Implement and weakly test fetching the manufacturer access word from an SBS
compatible fuel gauge.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-01-08 19:48:12 +01:00
Aaron Massey 5e33f833ed fuel_gauge: Fix sbs_gauge err to conform to API
The SBS fuel gauge driver did not return a count of the number of
properties that failed.

Fix this and add a test that verifies the sbs_gauge returns the number of
failing properties as well as a test that verifies a negative return code
if all properties failed.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2022-12-13 11:10:44 +01:00
Aaron Massey 28b8123887 fuel_gauge: Sample sbs gauge driver with tests
Add a sample sbs gauge driver with feature parity and basic tests
comparison to its sensor counter-part. Includes a simple stub test that is
extended upon.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2022-11-19 17:56:05 -05:00