battery-profile-loader.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2013-2014, 2016-2020 The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __BATTERY_PROFILE_LOADER_H
  7. #define __BATTERY_PROFILE_LOADER_H
  8. #include <linux/of.h>
  9. #define MAX_BATT_ID_NUM 4
  10. #define DEGC_SCALE 10
  11. struct batt_ids {
  12. int kohm[MAX_BATT_ID_NUM];
  13. int num;
  14. };
  15. /**
  16. * struct soh_range -
  17. * @batt_age_level: Battery age level (e.g. 0, 1 etc.,)
  18. * @soh_min: Minimum SOH (state of health) level that this battery
  19. * profile can support.
  20. * @soh_max: Maximum SOH (state of health) level that this battery
  21. * profile can support.
  22. */
  23. struct soh_range {
  24. int batt_age_level;
  25. int soh_min;
  26. int soh_max;
  27. };
  28. /**
  29. * of_batterydata_get_best_profile() - Find matching battery data device node
  30. * @batterydata_container_node: pointer to the battery-data container device
  31. * node containing the profile nodes.
  32. * @batt_id_kohm: Battery ID in KOhms for which we want to find the profile.
  33. * @batt_type: Battery type which we want to force load the profile.
  34. *
  35. * This routine returns a device_node pointer to the closest match battery data
  36. * from device tree based on the battery id reading.
  37. */
  38. struct device_node *of_batterydata_get_best_profile(
  39. const struct device_node *batterydata_container_node,
  40. int batt_id_kohm, const char *batt_type);
  41. /**
  42. * of_batterydata_get_best_aged_profile() - Find best aged battery profile
  43. * @batterydata_container_node: pointer to the battery-data container device
  44. * node containing the profile nodes.
  45. * @batt_id_kohm: Battery ID in KOhms for which we want to find the profile.
  46. * @batt_age_level: Battery age level.
  47. * @avail_age_level: Available battery age level.
  48. *
  49. * This routine returns a device_node pointer to the closest match battery data
  50. * from device tree based on the battery id reading and age level.
  51. */
  52. struct device_node *of_batterydata_get_best_aged_profile(
  53. const struct device_node *batterydata_container_node,
  54. int batt_id_kohm, int batt_age_level, int *avail_age_level);
  55. /**
  56. * of_batterydata_get_aged_profile_count() - Gets the number of aged profiles
  57. * @batterydata_node: pointer to the battery-data container device
  58. * node containing the profile nodes.
  59. * @batt_id_kohm: Battery ID in KOhms for which we want to find the profile.
  60. * @count: Number of aged profiles available to support SOH based profile
  61. * loading.
  62. *
  63. * This routine returns zero if valid number of aged profiles are available.
  64. */
  65. int of_batterydata_get_aged_profile_count(
  66. const struct device_node *batterydata_node,
  67. int batt_id_kohm, int *count);
  68. /**
  69. * of_batterydata_read_soh_aged_profiles() - Reads the data from aged profiles
  70. * @batterydata_node: pointer to the battery-data container device
  71. * node containing the profile nodes.
  72. * @batt_id_kohm: Battery ID in KOhms for which we want to find the profile.
  73. * @soh_data: SOH data from the profile if it is found to be valid.
  74. *
  75. * This routine returns zero if SOH data of aged profiles is valid.
  76. */
  77. int of_batterydata_read_soh_aged_profiles(
  78. const struct device_node *batterydata_node,
  79. int batt_id_kohm, struct soh_range *soh_data);
  80. #endif /* __BATTERY_PROFILE_LOADER_H */