11/*
22 * Copyright 2022 Google LLC
3+ * Copyright 2023 Microsoft Corporation
34 *
45 * SPDX-License-Identifier: Apache-2.0
56 */
@@ -90,9 +91,15 @@ extern "C" {
9091#define FUEL_GAUGE_SBS_REMAINING_CAPACITY_ALARM FUEL_GAUGE_SBS_ATRATE_OK + 1
9192/** Remaining Time Alarm (minutes) */
9293#define FUEL_GAUGE_SBS_REMAINING_TIME_ALARM FUEL_GAUGE_SBS_REMAINING_CAPACITY_ALARM + 1
94+ /** Manufacturer of pack (1 byte length + 20 bytes data) */
95+ #define FUEL_GAUGE_MANUFACTURER_NAME FUEL_GAUGE_SBS_REMAINING_TIME_ALARM + 1
96+ /** Name of pack (1 byte length + 20 bytes data) */
97+ #define FUEL_GAUGE_DEVICE_NAME FUEL_GAUGE_MANUFACTURER_NAME + 1
98+ /** Chemistry (1 byte length + 4 bytes data) */
99+ #define FUEL_GAUGE_DEVICE_CHEMISTRY FUEL_GAUGE_DEVICE_NAME + 1
93100
94101/** Reserved to demark end of common fuel gauge properties */
95- #define FUEL_GAUGE_COMMON_COUNT FUEL_GAUGE_DESIGN_VOLTAGE + 1
102+ #define FUEL_GAUGE_COMMON_COUNT FUEL_GAUGE_DEVICE_CHEMISTRY + 1
96103/**
97104 * Reserved to demark downstream custom properties - use this value as the actual value may change
98105 * over future versions of this API
@@ -198,6 +205,37 @@ struct fuel_gauge_set_property {
198205 } value ;
199206};
200207
208+ /** Buffer properties are separated due to size */
209+ struct fuel_gauge_get_buffer_property {
210+ /** Battery fuel gauge property to get */
211+ uint16_t property_type ;
212+
213+ /** Negative error status set by callee e.g. -ENOTSUP for an unsupported property */
214+ int status ;
215+ };
216+
217+ /**
218+ * Data structures for reading SBS buffer properties
219+ */
220+ #define SBS_GAUGE_MANUFACTURER_NAME_MAX_SIZE 20
221+ #define SBS_GAUGE_DEVICE_NAME_MAX_SIZE 20
222+ #define SBS_GAUGE_DEVICE_CHEMISTRY_MAX_SIZE 4
223+
224+ struct sbs_gauge_manufacturer_name {
225+ uint8_t manufacturer_name_length ;
226+ char manufacturer_name [SBS_GAUGE_MANUFACTURER_NAME_MAX_SIZE ];
227+ } __packed ;
228+
229+ struct sbs_gauge_device_name {
230+ uint8_t device_name_length ;
231+ char device_name [SBS_GAUGE_DEVICE_NAME_MAX_SIZE ];
232+ } __packed ;
233+
234+ struct sbs_gauge_device_chemistry {
235+ uint8_t device_chemistry_length ;
236+ char device_chemistry [SBS_GAUGE_DEVICE_CHEMISTRY_MAX_SIZE ];
237+ } __packed ;
238+
201239/**
202240 * @typedef fuel_gauge_get_property_t
203241 * @brief Callback API for getting a fuel_gauge property.
@@ -216,11 +254,23 @@ typedef int (*fuel_gauge_get_property_t)(const struct device *dev,
216254typedef int (* fuel_gauge_set_property_t )(const struct device * dev ,
217255 struct fuel_gauge_set_property * props , size_t props_len );
218256
257+ /**
258+ * @typedef fuel_gauge_get_buffer_property_t
259+ * @brief Callback API for getting a fuel_gauge buffer property.
260+ *
261+ * See fuel_gauge_get_buffer_property() for argument description
262+ */
263+ typedef int (* fuel_gauge_get_buffer_property_t )(const struct device * dev ,
264+ struct fuel_gauge_get_buffer_property * prop ,
265+ void * dst , size_t dst_len );
266+
267+
219268/* Caching is entirely on the onus of the client */
220269
221270__subsystem struct fuel_gauge_driver_api {
222271 fuel_gauge_get_property_t get_property ;
223272 fuel_gauge_set_property_t set_property ;
273+ fuel_gauge_get_buffer_property_t get_buffer_property ;
224274};
225275
226276/**
@@ -280,6 +330,35 @@ static inline int z_impl_fuel_gauge_set_prop(const struct device *dev,
280330 return api -> set_property (dev , props , props_len );
281331}
282332
333+ /**
334+ * @brief Fetch a battery fuel-gauge buffer property
335+ *
336+ * @param dev Pointer to the battery fuel-gauge device
337+ * @param prop pointer to single fuel_gauge_get_buffer_property struct where the property struct
338+ * field is set by the caller to determine what property is read from the
339+ * fuel gauge device into the dst field.
340+ * @param dst byte array or struct that will hold the buffer data that is read from the fuel gauge
341+ * @param dst_len the length of the destination array in bytes
342+ *
343+ * @return return=0 if successful, return < 0 if getting property failed, return 0 on success
344+ */
345+ __syscall int fuel_gauge_get_buffer_prop (const struct device * dev ,
346+ struct fuel_gauge_get_buffer_property * prop , void * dst ,
347+ size_t dst_len );
348+
349+ static inline int z_impl_fuel_gauge_get_buffer_prop (const struct device * dev ,
350+ struct fuel_gauge_get_buffer_property * prop ,
351+ void * dst , size_t dst_len )
352+ {
353+ const struct fuel_gauge_driver_api * api = (const struct fuel_gauge_driver_api * )dev -> api ;
354+
355+ if (api -> get_buffer_property == NULL ) {
356+ return - ENOSYS ;
357+ }
358+
359+ return api -> get_buffer_property (dev , prop , dst , dst_len );
360+ }
361+
283362/**
284363 * @}
285364 */
0 commit comments