summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Barnaś <mb@semihalf.com>2021-08-19 14:41:52 +0200
committerCommit Bot <commit-bot@chromium.org>2021-09-03 21:30:57 +0000
commit970bd536ade4a2f4922a0dc95dfc7a7458ada89a (patch)
treec32e683887843d82de9d2f5c4aa697c2c1bebbf5
parent0c0ba0a2b1297fa9bb1c47da95c220ae1df3b9e2 (diff)
downloadchrome-ec-970bd536ade4a2f4922a0dc95dfc7a7458ada89a.tar.gz
zephyr: add batteries to device tree
This commit adds possibility to define board's batteries in device tree. Default battery is defined by adding "default_battery" as node's label. It also adds common batteries definitions that can be used using compatible string. If no 'batteries' node is defined in device tree, custom board's logic must be used and old "named-batteries" should be defined. BRANCH=main BUG=b:183544739 TEST=This commit shouldn't change behaviour of any build. Compiling and flashing CrOS EC and Zephyr should work without problems. Change-Id: I94f0121f45eb061f1358fadbcd7d8006c08b0bea Signed-off-by: Michał Barnaś <mb@semihalf.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3107385 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
-rw-r--r--zephyr/dts/bindings/battery/as3gwrc3ka,c235-41.yaml47
-rw-r--r--zephyr/dts/bindings/battery/battery-fuel-gauge.yaml84
-rw-r--r--zephyr/dts/bindings/battery/battery-info.yaml71
-rw-r--r--zephyr/dts/bindings/battery/battery-smart.yaml19
-rw-r--r--zephyr/dts/bindings/battery/lgc,ap16l8j.yaml47
-rw-r--r--zephyr/dts/bindings/battery/lgc,ap18c8k.yaml49
-rw-r--r--zephyr/dts/bindings/battery/murata,ap18c4k.yaml49
-rw-r--r--zephyr/dts/bindings/battery/panasonic,ap16l5j-009.yaml49
-rw-r--r--zephyr/dts/bindings/battery/panasonic,ap16l5j.yaml49
-rw-r--r--zephyr/shim/include/battery_enum.h15
-rw-r--r--zephyr/shim/src/CMakeLists.txt2
-rw-r--r--zephyr/shim/src/battery.c69
12 files changed, 548 insertions, 2 deletions
diff --git a/zephyr/dts/bindings/battery/as3gwrc3ka,c235-41.yaml b/zephyr/dts/bindings/battery/as3gwrc3ka,c235-41.yaml
new file mode 100644
index 0000000000..94463eca89
--- /dev/null
+++ b/zephyr/dts/bindings/battery/as3gwrc3ka,c235-41.yaml
@@ -0,0 +1,47 @@
+description: "AS3GWRc3KA C235-41"
+compatible: "as3gwrc3ka,c235-41"
+
+include: battery-smart.yaml
+
+properties:
+ enum-name:
+ type: string
+ default: "as3gwrc3ka,c235-41"
+
+ # Fuel gauge
+ manuf_name:
+ default: "AS3GWRc3KA"
+ device_name:
+ default: "C235-41"
+ ship_mode_reg_addr:
+ default: 0x00
+ ship_mode_reg_data:
+ default: [ 0x10, 0x10 ]
+ fet_reg_addr:
+ default: 0x99
+ fet_reg_mask:
+ default: 0x0c
+ fet_disconnect_val:
+ default: 0x0c
+
+ # Battery info
+ voltage_max:
+ default: 8800
+ voltage_normal:
+ default: 7700
+ voltage_min:
+ default: 6000
+ precharge_current:
+ default: 256
+ start_charging_min_c:
+ default: 0
+ start_charging_max_c:
+ default: 45
+ charging_min_c:
+ default: 0
+ charging_max_c:
+ default: 60
+ discharging_min_c:
+ default: 0
+ discharging_max_c:
+ default: 60
diff --git a/zephyr/dts/bindings/battery/battery-fuel-gauge.yaml b/zephyr/dts/bindings/battery/battery-fuel-gauge.yaml
new file mode 100644
index 0000000000..9365910aa6
--- /dev/null
+++ b/zephyr/dts/bindings/battery/battery-fuel-gauge.yaml
@@ -0,0 +1,84 @@
+# Copyright 2021 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+description: |
+ Battery fuel gauge parameters
+
+compatible: "battery-fuel-gauge"
+
+properties:
+ manuf_name:
+ description: Manufacturer name
+ type: string
+ device_name:
+ description: Model/Device name
+ type: string
+ ship_mode_wb_support:
+ description: |
+ Write Block support. If this is true, then i2c write block command
+ will be used instead of a 16-bit write
+ Value must be either 0 or 1.
+ type: int
+ ship_mode_reg_addr:
+ description: |
+ Address of register responsible for enabling ship mode.
+ type: int
+ ship_mode_reg_data:
+ description: |
+ Values written to register to enable ship mode.
+ type: array
+ sleep_mode_support:
+ description: |
+ Defines if battery support fuel gauge sleep command.
+ Value must be either 0 or 1.
+ type: int
+ sleep_mode_reg_addr:
+ description: |
+ Defines address where command will be sent to go into sleep mode.
+ type: int
+ sleep_mode_reg_data:
+ description: |
+ Defines value which will be sent to register to go into sleep mode.
+ type: int
+ fet_mfgacc_support:
+ description: |
+ Defines if battery supports manufacturer access command.
+ If enabled, FET status is read using the ManufacturerBlockAccess (0x44)
+ to read the OperationStatus (0x54) register.
+ The fet_reg_mask and fet_disconnect_val properties must still be
+ defined.
+ Value must be either 0 or 1.
+ type: int
+ fet_reg_addr:
+ description: |
+ Address of register which reports charging and discharging FETs status.
+ This property is ignored if fet_mfgacc_support is true.
+ type: int
+ fet_reg_mask:
+ description: |
+ Mask which determines which bit in status value contains the
+ discharge FET status.
+ type: int
+ fet_disconnect_val:
+ description: |
+ Value that describes which bits must be set to determine that
+ discharge FET has disconnected the battery.
+ type: int
+ fet_cfet_mask:
+ description: |
+ Mask which determines which bit in status value contains the
+ charge FET status. If this value is 0, this means there's
+ no charge FET.
+ type: int
+ fet_cfet_off_val:
+ description: |
+ Value that describes which bits must be set to determine that
+ charge FET has disconnected the battery.
+ type: int
+ imbalance_mv:
+ description: |
+ This property is used if CONFIG_BATTERY_MEASURE_IMBALANCE is defined.
+ It should be an enum and its value should be a name of function
+ which will be assigned to imbalance_mv pointer.
+ type: string
diff --git a/zephyr/dts/bindings/battery/battery-info.yaml b/zephyr/dts/bindings/battery/battery-info.yaml
new file mode 100644
index 0000000000..b84056c266
--- /dev/null
+++ b/zephyr/dts/bindings/battery/battery-info.yaml
@@ -0,0 +1,71 @@
+# Copyright 2021 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+description:
+ Information about battery
+ Voltage is in millivolts
+ Current is in milliamperes
+ Temperature is in Celsius degrees
+
+compatible: "battery-info"
+
+properties:
+ voltage_max:
+ description: |
+ Maximum voltage that can be applied to the battery.
+ type: int
+ voltage_normal:
+ description: |
+ Nominal voltage of the battery.
+ type: int
+ voltage_min:
+ description: |
+ Minimum voltage of the battery.
+ If current voltage is below this value, system will shutdown.
+ type: int
+ precharge_voltage:
+ description: |
+ Voltage used during the precharge phase. Not all chargers
+ may take these into account.
+ type: int
+ precharge_current:
+ description: |
+ Maximum current used during the precharge phase.
+ type: int
+ start_charging_min_c:
+ description: |
+ Minimum temperature of battery to start charging it.
+ This value is used only if CONFIG_BATTERY_CHECK_CHARGE_TEMP_LIMITS
+ is defined.
+ type: int
+ start_charging_max_c:
+ description: |
+ Maximum temperature of battery to start charging it.
+ This value is used only if CONFIG_BATTERY_CHECK_CHARGE_TEMP_LIMITS
+ is defined.
+ type: int
+ charging_min_c:
+ description: |
+ Minimum temperature of battery during charging it. If the battery
+ temperature falls below this value, charging will be stopped.
+ This value is used only if CONFIG_BATTERY_CHECK_CHARGE_TEMP_LIMITS
+ is defined.
+ type: int
+ charging_max_c:
+ description: |
+ Maximum temperature of battery during charging it. If the battery
+ temperature raises above this value, charging will be stopped.
+ This value is used only if CONFIG_BATTERY_CHECK_CHARGE_TEMP_LIMITS
+ is defined.
+ type: int
+ discharging_min_c:
+ description: |
+ Minimum working temperature of battery.
+ If temperature is below this value, the system will shutdown.
+ type: int
+ discharging_max_c:
+ description: |
+ Maximum working temperature of battery.
+ If temperature is above this value, the system will shutdown.
+ type: int
diff --git a/zephyr/dts/bindings/battery/battery-smart.yaml b/zephyr/dts/bindings/battery/battery-smart.yaml
new file mode 100644
index 0000000000..ce0a330077
--- /dev/null
+++ b/zephyr/dts/bindings/battery/battery-smart.yaml
@@ -0,0 +1,19 @@
+# Copyright 2021 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+compatible: "battery-smart"
+
+include: [ "base.yaml", "battery-info.yaml", "battery-fuel-gauge.yaml" ]
+
+properties:
+ enum-name:
+ description: Unique value used for creating enum of batteries types
+ type: string
+ enum:
+ - "as3gwrc3ka,c235-41"
+ - "lgc,ap16l8j"
+ - "lgc,ap18c8k"
+ - "murata,ap18c4k"
+ - "panasonic,ap16l5j"
+ - "panasonic,ap16l5j-009"
diff --git a/zephyr/dts/bindings/battery/lgc,ap16l8j.yaml b/zephyr/dts/bindings/battery/lgc,ap16l8j.yaml
new file mode 100644
index 0000000000..546b33522a
--- /dev/null
+++ b/zephyr/dts/bindings/battery/lgc,ap16l8j.yaml
@@ -0,0 +1,47 @@
+description: "LGC KT0020G010 AP16L8J"
+compatible: "lgc,ap16l8j"
+
+include: battery-smart.yaml
+
+properties:
+ enum-name:
+ type: string
+ default: "lgc,ap16l8j"
+
+ # Fuel gauge
+ manuf_name:
+ default: "LGC KT0020G010"
+ device_name:
+ default: "AP16L8J"
+ ship_mode_reg_addr:
+ default: 0x3A
+ ship_mode_reg_data:
+ default: [ 0xC574, 0xC574 ]
+ fet_mfgacc_support:
+ default: 1
+ fet_reg_mask:
+ default: 0x0002
+ fet_disconnect_val:
+ default: 0x0
+
+ # Battery info
+ voltage_max:
+ default: 8700
+ voltage_normal:
+ default: 7500
+ voltage_min:
+ default: 6000
+ precharge_current:
+ default: 256
+ start_charging_min_c:
+ default: 0
+ start_charging_max_c:
+ default: 50
+ charging_min_c:
+ default: 0
+ charging_max_c:
+ default: 60
+ discharging_min_c:
+ default: -20
+ discharging_max_c:
+ default: 75
diff --git a/zephyr/dts/bindings/battery/lgc,ap18c8k.yaml b/zephyr/dts/bindings/battery/lgc,ap18c8k.yaml
new file mode 100644
index 0000000000..727c510e04
--- /dev/null
+++ b/zephyr/dts/bindings/battery/lgc,ap18c8k.yaml
@@ -0,0 +1,49 @@
+description: "LGC KT0030G020 AP18C8K"
+compatible: "lgc,ap18c8k"
+
+include: battery-smart.yaml
+
+properties:
+ enum-name:
+ type: string
+ default: "lgc,ap18c8k"
+
+ # Fuel gauge
+ manuf_name:
+ default: "LGC KT0030G020"
+ device_name:
+ default: "AP18C8K"
+ ship_mode_reg_addr:
+ default: 0x3A
+ ship_mode_reg_data:
+ default: [ 0xC574, 0xC574 ]
+ fet_mfgacc_support:
+ default: 0
+ fet_reg_addr:
+ default: 0x43
+ fet_reg_mask:
+ default: 0x0001
+ fet_disconnect_val:
+ default: 0x0
+
+ # Battery info
+ voltage_max:
+ default: 13050
+ voltage_normal:
+ default: 11250
+ voltage_min:
+ default: 9000
+ precharge_current:
+ default: 256
+ start_charging_min_c:
+ default: 0
+ start_charging_max_c:
+ default: 50
+ charging_min_c:
+ default: 0
+ charging_max_c:
+ default: 60
+ discharging_min_c:
+ default: -20
+ discharging_max_c:
+ default: 75
diff --git a/zephyr/dts/bindings/battery/murata,ap18c4k.yaml b/zephyr/dts/bindings/battery/murata,ap18c4k.yaml
new file mode 100644
index 0000000000..c8301beaa3
--- /dev/null
+++ b/zephyr/dts/bindings/battery/murata,ap18c4k.yaml
@@ -0,0 +1,49 @@
+description: "Murata KT00304012 AP18C4K"
+compatible: "murata,ap18c4k"
+
+include: battery-smart.yaml
+
+properties:
+ enum-name:
+ type: string
+ default: "murata,ap18c4k"
+
+ # Fuel gauge
+ manuf_name:
+ default: "Murata KT00304012"
+ device_name:
+ default: "AP18C4K"
+ ship_mode_reg_addr:
+ default: 0x3A
+ ship_mode_reg_data:
+ default: [ 0xC574, 0xC574 ]
+ fet_mfgacc_support:
+ default: 0
+ fet_reg_addr:
+ default: 0x0
+ fet_reg_mask:
+ default: 0x2000
+ fet_disconnect_val:
+ default: 0x2000
+
+ # Battery info
+ voltage_max:
+ default: 13200
+ voltage_normal:
+ default: 11400
+ voltage_min:
+ default: 9000
+ precharge_current:
+ default: 256
+ start_charging_min_c:
+ default: 0
+ start_charging_max_c:
+ default: 50
+ charging_min_c:
+ default: 0
+ charging_max_c:
+ default: 60
+ discharging_min_c:
+ default: -20
+ discharging_max_c:
+ default: 75
diff --git a/zephyr/dts/bindings/battery/panasonic,ap16l5j-009.yaml b/zephyr/dts/bindings/battery/panasonic,ap16l5j-009.yaml
new file mode 100644
index 0000000000..a198049881
--- /dev/null
+++ b/zephyr/dts/bindings/battery/panasonic,ap16l5j-009.yaml
@@ -0,0 +1,49 @@
+description: "Panasonic KT00205009 AP16L5J"
+compatible: "panasonic,ap16l5j-009"
+
+include: battery-smart.yaml
+
+properties:
+ enum-name:
+ type: string
+ default: "panasonic,ap16l5j-009"
+
+ # Fuel gauge
+ manuf_name:
+ default: "PANASONIC KT00205009"
+ device_name:
+ default: "AP16L5J"
+ ship_mode_reg_addr:
+ default: 0x3A
+ ship_mode_reg_data:
+ default: [ 0xC574, 0xC574 ]
+ fet_mfgacc_support:
+ default: 0
+ fet_reg_addr:
+ default: 0x0
+ fet_reg_mask:
+ default: 0x4000
+ fet_disconnect_val:
+ default: 0x0
+
+ # Battery info
+ voltage_max:
+ default: 8800
+ voltage_normal:
+ default: 7700
+ voltage_min:
+ default: 6000
+ precharge_current:
+ default: 256
+ start_charging_min_c:
+ default: 0
+ start_charging_max_c:
+ default: 50
+ charging_min_c:
+ default: 0
+ charging_max_c:
+ default: 60
+ discharging_min_c:
+ default: -20
+ discharging_max_c:
+ default: 75
diff --git a/zephyr/dts/bindings/battery/panasonic,ap16l5j.yaml b/zephyr/dts/bindings/battery/panasonic,ap16l5j.yaml
new file mode 100644
index 0000000000..fcfff98de1
--- /dev/null
+++ b/zephyr/dts/bindings/battery/panasonic,ap16l5j.yaml
@@ -0,0 +1,49 @@
+description: "Panasonic AP16L5J"
+compatible: "panasonic,ap16l5j"
+
+include: battery-smart.yaml
+
+properties:
+ enum-name:
+ type: string
+ default: "panasonic,ap16l5j"
+
+ # Fuel gauge
+ manuf_name:
+ default: "PANASONIC"
+ device_name:
+ default: "AP16L5J"
+ ship_mode_reg_addr:
+ default: 0x3A
+ ship_mode_reg_data:
+ default: [ 0xC574, 0xC574 ]
+ fet_mfgacc_support:
+ default: 0
+ fet_reg_addr:
+ default: 0x0
+ fet_reg_mask:
+ default: 0x4000
+ fet_disconnect_val:
+ default: 0x0
+
+ # Battery info
+ voltage_max:
+ default: 8800
+ voltage_normal:
+ default: 7700
+ voltage_min:
+ default: 6000
+ precharge_current:
+ default: 256
+ start_charging_min_c:
+ default: 0
+ start_charging_max_c:
+ default: 50
+ charging_min_c:
+ default: 0
+ charging_max_c:
+ default: 60
+ discharging_min_c:
+ default: -20
+ discharging_max_c:
+ default: 75
diff --git a/zephyr/shim/include/battery_enum.h b/zephyr/shim/include/battery_enum.h
index 36692e68e5..6541d61c42 100644
--- a/zephyr/shim/include/battery_enum.h
+++ b/zephyr/shim/include/battery_enum.h
@@ -8,13 +8,21 @@
"included in all zephyr builds automatically"
#endif
-/* TODO(b/183544739): Move this to use compatible strings */
-
#define BATTERY_ENUM(val) DT_CAT(BATTERY_, val)
#define BATTERY_TYPE(id) BATTERY_ENUM(DT_ENUM_UPPER_TOKEN(id, enum_name))
#define BATTERY_TYPE_WITH_COMMA(id) BATTERY_TYPE(id),
/* This produces a list of BATTERY_<ENUM_NAME> identifiers */
+#if DT_NODE_EXISTS(DT_PATH(batteries))
+
+enum battery_type {
+ DT_FOREACH_CHILD(DT_PATH(batteries), BATTERY_TYPE_WITH_COMMA)
+
+ BATTERY_TYPE_COUNT,
+};
+
+#else /* DT_NODE_EXISTS(DT_PATH(batteries)) */
+
enum battery_type {
#if DT_NODE_EXISTS(DT_PATH(named_batteries))
DT_FOREACH_CHILD(DT_PATH(named_batteries), BATTERY_TYPE_WITH_COMMA)
@@ -22,4 +30,7 @@ enum battery_type {
BATTERY_TYPE_COUNT,
};
+
+#endif /* DT_NODE_EXISTS(DT_PATH(batteries)) */
+
#undef BATTERY_TYPE_WITH_COMMA
diff --git a/zephyr/shim/src/CMakeLists.txt b/zephyr/shim/src/CMakeLists.txt
index 6c2001602a..4b21fa3cfb 100644
--- a/zephyr/shim/src/CMakeLists.txt
+++ b/zephyr/shim/src/CMakeLists.txt
@@ -16,6 +16,8 @@ endif()
zephyr_library_sources_ifdef(no_libgcc libgcc_${ARCH}.S)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_ADC adc.c)
+zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_BATTERY_FUEL_GAUGE
+ battery.c)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CBI_EEPROM cbi.c)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CBI_GPIO cbi.c)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_ESPI espi.c)
diff --git a/zephyr/shim/src/battery.c b/zephyr/shim/src/battery.c
new file mode 100644
index 0000000000..bd4af10f03
--- /dev/null
+++ b/zephyr/shim/src/battery.c
@@ -0,0 +1,69 @@
+/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include<devicetree.h>
+#include"battery_fuel_gauge.h"
+
+#if DT_NODE_EXISTS(DT_PATH(batteries))
+
+#define NODE_FUEL_GAUGE(node) \
+{ \
+ .manuf_name = DT_PROP(node, manuf_name), \
+ .device_name = DT_PROP(node, device_name), \
+ .ship_mode = { \
+ .wb_support = DT_PROP_OR(node, ship_mode_wb_support, 0), \
+ .reg_addr = DT_PROP(node, ship_mode_reg_addr), \
+ .reg_data = DT_PROP(node, ship_mode_reg_data), \
+ }, \
+ .sleep_mode = { \
+ .sleep_supported = DT_PROP_OR(node, sleep_mode_supported, 0), \
+ .reg_addr = DT_PROP_OR(node, sleep_mode_reg_addr, 0), \
+ .reg_data = DT_PROP_OR(node, sleep_mode_reg_data, 0), \
+ }, \
+ .fet = { \
+ .mfgacc_support = DT_PROP_OR(node, fet_mgfacc_support, 0), \
+ .reg_addr = DT_PROP_OR(node, fet_reg_addr, 0), \
+ .reg_mask = DT_PROP(node, fet_reg_mask), \
+ .disconnect_val = DT_PROP(node, fet_disconnect_val), \
+ .cfet_mask = DT_PROP_OR(node, fet_cfet_mask, 0), \
+ .cfet_off_val = DT_PROP_OR(node, fet_cfet_off_val, 0), \
+ }, \
+ COND_CODE_1(UTIL_AND(IS_ENABLED(CONFIG_BATTERY_MEASURE_IMBALANCE), \
+ DT_NODE_HAS_PROP(node, imbalance_mv)), \
+ (.imbalance_mv = DT_ENUM_TOKEN(node, imbalance_mv),), ()) \
+},
+
+#define NODE_BATT_INFO(node) \
+{ \
+ .voltage_max = DT_PROP(node, voltage_max), \
+ .voltage_normal = DT_PROP(node, voltage_normal), \
+ .voltage_min = DT_PROP(node, voltage_min), \
+ .precharge_voltage = DT_PROP_OR(node, precharge_voltage, 0), \
+ .precharge_current = DT_PROP_OR(node, precharge_current, 0), \
+ .start_charging_min_c = DT_PROP(node, start_charging_min_c), \
+ .start_charging_max_c = DT_PROP(node, start_charging_max_c), \
+ .charging_min_c = DT_PROP(node, charging_min_c), \
+ .charging_max_c = DT_PROP(node, charging_max_c), \
+ .discharging_min_c = DT_PROP(node, discharging_min_c), \
+ .discharging_max_c = DT_PROP(node, discharging_max_c), \
+},
+
+#define NODE_BATT_PARAMS(node) \
+{ \
+ .fuel_gauge = NODE_FUEL_GAUGE(node) \
+ .batt_info = NODE_BATT_INFO(node) \
+},
+
+const struct board_batt_params board_battery_info[] = {
+ DT_FOREACH_CHILD(DT_PATH(batteries), NODE_BATT_PARAMS)
+};
+
+#if DT_NODE_EXISTS(DT_NODELABEL(default_battery))
+#define BAT_ENUM(node) DT_CAT(BATTERY_, node)
+const enum battery_type DEFAULT_BATTERY_TYPE =
+ BATTERY_TYPE(DT_NODELABEL(default_battery));
+#endif
+
+#endif /* DT_NODE_EXISTS(DT_PATH(batteries)) */