Zephyr API Documentation  3.6.0
A Scalable Open Source RTOS
3.6.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
charger.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Cirrus Logic, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12#ifndef ZEPHYR_INCLUDE_DRIVERS_CHARGER_H_
13#define ZEPHYR_INCLUDE_DRIVERS_CHARGER_H_
14
22#include <stdbool.h>
23#include <stddef.h>
24#include <stdint.h>
25
26#include <zephyr/device.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif /* __cplusplus */
31
89};
90
98
109};
110
125};
126
144 /*
145 * Charging is being dynamically adjusted by the charger device
146 */
148 /*
149 * Charging is occurring at a reduced charge rate to preserve
150 * battery health
151 */
153 /*
154 * The charger device is being bypassed and the power conversion
155 * is being handled externally, typically by a "smart" wall adaptor
156 */
158};
159
195};
196
207};
208
219};
220
226 /* Fields have the format: */
227 /* CHARGER_PROPERTY_FIELD */
228 /* type property_field; */
229
254};
255
262typedef int (*charger_get_property_t)(const struct device *dev, const charger_prop_t prop,
263 union charger_propval *val);
264
271typedef int (*charger_set_property_t)(const struct device *dev, const charger_prop_t prop,
272 const union charger_propval *val);
273
280typedef int (*charger_charge_enable_t)(const struct device *dev, const bool enable);
281
287__subsystem struct charger_driver_api {
291};
292
303__syscall int charger_get_prop(const struct device *dev, const charger_prop_t prop,
304 union charger_propval *val);
305
306static inline int z_impl_charger_get_prop(const struct device *dev, const charger_prop_t prop,
307 union charger_propval *val)
308{
309 const struct charger_driver_api *api = (const struct charger_driver_api *)dev->api;
310
311 return api->get_property(dev, prop, val);
312}
313
324__syscall int charger_set_prop(const struct device *dev, const charger_prop_t prop,
325 const union charger_propval *val);
326
327static inline int z_impl_charger_set_prop(const struct device *dev, const charger_prop_t prop,
328 const union charger_propval *val)
329{
330 const struct charger_driver_api *api = (const struct charger_driver_api *)dev->api;
331
332 return api->set_property(dev, prop, val);
333}
334
345__syscall int charger_charge_enable(const struct device *dev, const bool enable);
346
347static inline int z_impl_charger_charge_enable(const struct device *dev, const bool enable)
348{
349 const struct charger_driver_api *api = (const struct charger_driver_api *)dev->api;
350
351 return api->charge_enable(dev, enable);
352}
353
358#ifdef __cplusplus
359}
360#endif /* __cplusplus */
361
362#include <syscalls/charger.h>
363
364#endif /* ZEPHYR_INCLUDE_DRIVERS_CHARGER_H_ */
int charger_set_prop(const struct device *dev, const charger_prop_t prop, const union charger_propval *val)
Set a battery charger property.
int charger_get_prop(const struct device *dev, const charger_prop_t prop, union charger_propval *val)
Fetch a battery charger property.
int(* charger_get_property_t)(const struct device *dev, const charger_prop_t prop, union charger_propval *val)
Callback API for getting a charger property.
Definition: charger.h:262
charger_notification_severity
Charger severity levels for system notifications.
Definition: charger.h:200
int(* charger_set_property_t)(const struct device *dev, const charger_prop_t prop, const union charger_propval *val)
Callback API for setting a charger property.
Definition: charger.h:271
charger_status
Charging states.
Definition: charger.h:114
int(* charger_charge_enable_t)(const struct device *dev, const bool enable)
Callback API enabling or disabling a charge cycle.
Definition: charger.h:280
charger_property
Runtime Dynamic Battery Parameters.
Definition: charger.h:35
charger_health
Charger health conditions.
Definition: charger.h:165
int charger_charge_enable(const struct device *dev, const bool enable)
Enable or disable a charge cycle.
uint16_t charger_prop_t
A charger property's identifier.
Definition: charger.h:97
charger_online
External supply states.
Definition: charger.h:102
charger_charge_type
Charge algorithm types.
Definition: charger.h:130
@ CHARGER_SEVERITY_WARNING
Base severity level.
Definition: charger.h:206
@ CHARGER_SEVERITY_PEAK
Most severe level, typically triggered instantaneously.
Definition: charger.h:202
@ CHARGER_SEVERITY_CRITICAL
More severe than the warning level, less severe than peak.
Definition: charger.h:204
@ CHARGER_STATUS_FULL
The battery is full and the charging device will not attempt charging.
Definition: charger.h:124
@ CHARGER_STATUS_NOT_CHARGING
Charging device is not charging a battery.
Definition: charger.h:122
@ CHARGER_STATUS_DISCHARGING
Charging device is not able to charge a battery.
Definition: charger.h:120
@ CHARGER_STATUS_UNKNOWN
Charging device state is unknown.
Definition: charger.h:116
@ CHARGER_STATUS_CHARGING
Charging device is charging a battery.
Definition: charger.h:118
@ CHARGER_PROP_PRESENT
Reports whether or not a battery is present.
Definition: charger.h:41
@ CHARGER_PROP_ONLINE
Indicates if external supply is present for the charger.
Definition: charger.h:38
@ CHARGER_PROP_INPUT_REGULATION_VOLTAGE_UV
Configuration of the input voltage regulation target in µV.
Definition: charger.h:72
@ CHARGER_PROP_CUSTOM_BEGIN
Reserved to demark downstream custom properties - use this value as the actual value may change over ...
Definition: charger.h:86
@ CHARGER_PROP_HEALTH
Represents the health of the charger.
Definition: charger.h:50
@ CHARGER_PROP_COMMON_COUNT
Reserved to demark end of common charger properties.
Definition: charger.h:81
@ CHARGER_PROP_CONSTANT_CHARGE_VOLTAGE_UV
Configuration of charge voltage regulation target in µV.
Definition: charger.h:58
@ CHARGER_PROP_INPUT_REGULATION_CURRENT_UA
Configuration of the input current regulation target in µA.
Definition: charger.h:65
@ CHARGER_PROP_INPUT_CURRENT_NOTIFICATION
Configuration to issue a notification to the system based on the input current level and timing.
Definition: charger.h:79
@ CHARGER_PROP_STATUS
Represents the charging status of the charger.
Definition: charger.h:44
@ CHARGER_PROP_CONSTANT_CHARGE_CURRENT_UA
Configuration of current sink used for charging in µA.
Definition: charger.h:52
@ CHARGER_PROP_MAX
Reserved to demark end of valid enum properties.
Definition: charger.h:88
@ CHARGER_PROP_PRECHARGE_CURRENT_UA
Configuration of current sink used for conditioning in µA.
Definition: charger.h:54
@ CHARGER_PROP_CHARGE_TERM_CURRENT_UA
Configuration of charge termination target in µA.
Definition: charger.h:56
@ CHARGER_PROP_CHARGE_TYPE
Represents the charging algo type of the charger.
Definition: charger.h:47
@ CHARGER_HEALTH_SAFETY_TIMER_EXPIRE
The charger device's safety timer has expired.
Definition: charger.h:184
@ CHARGER_HEALTH_CALIBRATION_REQUIRED
The charger device requires calibration.
Definition: charger.h:186
@ CHARGER_HEALTH_WARM
The battery temperature is in the "warm" range.
Definition: charger.h:188
@ CHARGER_HEALTH_UNKNOWN
Charger health condition is unknown.
Definition: charger.h:167
@ CHARGER_HEALTH_COLD
The battery temperature is below the "cold" threshold.
Definition: charger.h:180
@ CHARGER_HEALTH_NO_BATTERY
The charger device does not detect a battery.
Definition: charger.h:194
@ CHARGER_HEALTH_UNSPEC_FAILURE
The battery or charger device is experiencing an unspecified failure.
Definition: charger.h:178
@ CHARGER_HEALTH_GOOD
Charger health condition is good.
Definition: charger.h:169
@ CHARGER_HEALTH_HOT
The battery temperature is below the "hot" threshold.
Definition: charger.h:192
@ CHARGER_HEALTH_COOL
The battery temperature is in the "cool" range.
Definition: charger.h:190
@ CHARGER_HEALTH_WATCHDOG_TIMER_EXPIRE
The charger device's watchdog timer has expired.
Definition: charger.h:182
@ CHARGER_HEALTH_OVERVOLTAGE
The battery voltage has exceeded its overvoltage threshold.
Definition: charger.h:173
@ CHARGER_HEALTH_OVERHEAT
The charger device is overheated.
Definition: charger.h:171
@ CHARGER_ONLINE_FIXED
External supply is present and of fixed output.
Definition: charger.h:106
@ CHARGER_ONLINE_PROGRAMMABLE
External supply is present and of programmable output.
Definition: charger.h:108
@ CHARGER_ONLINE_OFFLINE
External supply not present.
Definition: charger.h:104
@ CHARGER_CHARGE_TYPE_STANDARD
Charging is occurring at a moderate charge rate.
Definition: charger.h:143
@ CHARGER_CHARGE_TYPE_NONE
Charging is not occurring.
Definition: charger.h:134
@ CHARGER_CHARGE_TYPE_ADAPTIVE
Definition: charger.h:147
@ CHARGER_CHARGE_TYPE_UNKNOWN
Charge type is unknown.
Definition: charger.h:132
@ CHARGER_CHARGE_TYPE_BYPASS
Definition: charger.h:157
@ CHARGER_CHARGE_TYPE_LONGLIFE
Definition: charger.h:152
@ CHARGER_CHARGE_TYPE_TRICKLE
Charging is occurring at the slowest desired charge rate, typically for battery detection or precondi...
Definition: charger.h:139
@ CHARGER_CHARGE_TYPE_FAST
Charging is occurring at the fastest desired charge rate.
Definition: charger.h:141
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
#define UINT16_MAX
Definition: stdint.h:28
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
The input current thresholds for the charger to notify the system.
Definition: charger.h:212
uint8_t severity
The severity of the notification where CHARGER_SEVERITY_PEAK is the most severe.
Definition: charger.h:214
uint32_t duration_us
The duration of excess current before notifying the system.
Definition: charger.h:218
uint32_t current_ua
The current threshold to be exceeded.
Definition: charger.h:216
Charging device API.
Definition: charger.h:287
charger_charge_enable_t charge_enable
Definition: charger.h:290
charger_set_property_t set_property
Definition: charger.h:289
charger_get_property_t get_property
Definition: charger.h:288
Runtime device structure (in ROM) per driver instance.
Definition: device.h:387
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:393
container for a charger_property value
Definition: charger.h:225
struct charger_current_notifier input_current_notification
CHARGER_PROP_INPUT_CURRENT_NOTIFICATION.
Definition: charger.h:253
uint32_t precharge_current_ua
CHARGER_PROP_PRECHARGE_CURRENT_UA.
Definition: charger.h:243
uint32_t const_charge_voltage_uv
CHARGER_PROP_CONSTANT_CHARGE_VOLTAGE_UV.
Definition: charger.h:247
enum charger_status status
CHARGER_PROP_STATUS.
Definition: charger.h:235
enum charger_online online
CHARGER_PROP_ONLINE.
Definition: charger.h:231
uint32_t charge_term_current_ua
CHARGER_PROP_CHARGE_TERM_CURRENT_UA.
Definition: charger.h:245
bool present
CHARGER_PROP_PRESENT.
Definition: charger.h:233
enum charger_health health
CHARGER_PROP_HEALTH.
Definition: charger.h:239
enum charger_charge_type charge_type
CHARGER_PROP_CHARGE_TYPE.
Definition: charger.h:237
uint32_t input_current_regulation_current_ua
CHARGER_PROP_INPUT_REGULATION_CURRENT_UA.
Definition: charger.h:249
uint32_t const_charge_current_ua
CHARGER_PROP_CONSTANT_CHARGE_CURRENT_UA.
Definition: charger.h:241
uint32_t input_voltage_regulation_voltage_uv
CHARGER_PROP_INPUT_REGULATION_VOLTAGE_UV.
Definition: charger.h:251