devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/4] power: supply: add support for Pegatron Chagall battery
@ 2025-03-23  7:14 Svyatoslav Ryhel
  2025-03-23  7:14 ` [PATCH v1 1/4] dt-bindings: vendor-prefixes: add prefix for Pegatron Corporation Svyatoslav Ryhel
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Svyatoslav Ryhel @ 2025-03-23  7:14 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Thierry Reding, Jonathan Hunter, Sebastian Reichel,
	Svyatoslav Ryhel
  Cc: devicetree, linux-kernel, linux-tegra, linux-pm

The Pegatron Chagall is an Android tablet utilizing a customized Cypress
CG7153AM microcontroller (MCU) as its battery fuel gauge. It supports a
single-cell battery and features a dual-color charging LED.

Svyatoslav Ryhel (4):
  dt-bindings: vendor-prefixes: add prefix for Pegatron Corporation
  dt-bindings: mfd: Document Infineon/Cypress CG7153AM MCU
  power/supply: Add driver for Pegatron Chagall battery
  ARM: tegra: chagall: Add embedded controller node

 .../bindings/mfd/cypress,cg7153am.yaml        |  55 ++++
 .../devicetree/bindings/vendor-prefixes.yaml  |   2 +
 .../dts/nvidia/tegra30-pegatron-chagall.dts   |  16 +
 drivers/power/supply/Kconfig                  |  12 +
 drivers/power/supply/Makefile                 |   1 +
 drivers/power/supply/chagall-battery.c        | 308 ++++++++++++++++++
 6 files changed, 394 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml
 create mode 100644 drivers/power/supply/chagall-battery.c

-- 
2.43.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v1 1/4] dt-bindings: vendor-prefixes: add prefix for Pegatron Corporation
  2025-03-23  7:14 [PATCH v1 0/4] power: supply: add support for Pegatron Chagall battery Svyatoslav Ryhel
@ 2025-03-23  7:14 ` Svyatoslav Ryhel
  2025-03-24 16:53   ` Rob Herring
  2025-03-23  7:14 ` [PATCH v1 2/4] dt-bindings: mfd: Document Infineon/Cypress CG7153AM MCU Svyatoslav Ryhel
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Svyatoslav Ryhel @ 2025-03-23  7:14 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Thierry Reding, Jonathan Hunter, Sebastian Reichel,
	Svyatoslav Ryhel
  Cc: devicetree, linux-kernel, linux-tegra, linux-pm

PEGATRON Corporation is a Taiwanese electronics manufacturing company that
mainly develops computing, communications and consumer electronics for
branded vendors. Link https://www.pegatroncorp.com/

Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
 Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml
index da01616802c7..d36389aa4d7b 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
+++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
@@ -1146,6 +1146,8 @@ patternProperties:
     description: Parallax Inc.
   "^pda,.*":
     description: Precision Design Associates, Inc.
+  "^pegatron,.*":
+    description: Pegatron Corporation
   "^pericom,.*":
     description: Pericom Technology Inc.
   "^pervasive,.*":
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v1 2/4] dt-bindings: mfd: Document Infineon/Cypress CG7153AM MCU
  2025-03-23  7:14 [PATCH v1 0/4] power: supply: add support for Pegatron Chagall battery Svyatoslav Ryhel
  2025-03-23  7:14 ` [PATCH v1 1/4] dt-bindings: vendor-prefixes: add prefix for Pegatron Corporation Svyatoslav Ryhel
@ 2025-03-23  7:14 ` Svyatoslav Ryhel
  2025-03-24 16:52   ` Rob Herring
  2025-03-23  7:14 ` [PATCH v1 3/4] power/supply: Add driver for Pegatron Chagall battery Svyatoslav Ryhel
  2025-03-23  7:14 ` [PATCH v1 4/4] ARM: tegra: chagall: Add embedded controller node Svyatoslav Ryhel
  3 siblings, 1 reply; 10+ messages in thread
From: Svyatoslav Ryhel @ 2025-03-23  7:14 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Thierry Reding, Jonathan Hunter, Sebastian Reichel,
	Svyatoslav Ryhel
  Cc: devicetree, linux-kernel, linux-tegra, linux-pm

Add binding for Cypress CG7153AM embedded controller. Pegatron implemented
a custom configuration of this MCU in their Chagall tablets, utilizing it
for battery monitoring.

Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
 .../bindings/mfd/cypress,cg7153am.yaml        | 55 +++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml

diff --git a/Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml b/Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml
new file mode 100644
index 000000000000..f8469b5e3816
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml
@@ -0,0 +1,55 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/cypress,cg7153am.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Infineon/Cypress Semicon CG7153AM Microcontroller
+
+maintainers:
+  - Svyatoslav Ryhel <clamor95@gmail.com>
+
+description:
+  The CG7153AM, an 8-bit programmable microcontroller from Infineon/Cypress
+  Semiconductor, communicates over I2C and is implemented in devices like the
+  Pegatron Chagall tablet for fuel gauge and battery control functions.
+
+$ref: /schemas/power/supply/power-supply.yaml
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+          - enum:
+              - pegatron,chagall-ec # Pegatron Chagall tablet device
+          - const: cypress,cg7153am
+      - items:
+          const: cypress,cg7153am
+
+  reg:
+    maxItems: 1
+
+  monitored-battery: true
+  power-supplies: true
+
+required:
+  - compatible
+  - reg
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        embedded-controller@10 {
+            compatible = "pegatron,chagall-ec", "cypress,cg7153am";
+            reg = <0x10>;
+
+            monitored-battery = <&battery>;
+            power-supplies = <&mains>;
+        };
+    };
+...
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v1 3/4] power/supply: Add driver for Pegatron Chagall battery
  2025-03-23  7:14 [PATCH v1 0/4] power: supply: add support for Pegatron Chagall battery Svyatoslav Ryhel
  2025-03-23  7:14 ` [PATCH v1 1/4] dt-bindings: vendor-prefixes: add prefix for Pegatron Corporation Svyatoslav Ryhel
  2025-03-23  7:14 ` [PATCH v1 2/4] dt-bindings: mfd: Document Infineon/Cypress CG7153AM MCU Svyatoslav Ryhel
@ 2025-03-23  7:14 ` Svyatoslav Ryhel
  2025-03-23  7:14 ` [PATCH v1 4/4] ARM: tegra: chagall: Add embedded controller node Svyatoslav Ryhel
  3 siblings, 0 replies; 10+ messages in thread
From: Svyatoslav Ryhel @ 2025-03-23  7:14 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Thierry Reding, Jonathan Hunter, Sebastian Reichel,
	Svyatoslav Ryhel
  Cc: devicetree, linux-kernel, linux-tegra, linux-pm

The Pegatron Chagall is an Android tablet utilizing a customized Cypress
CG7153AM microcontroller (MCU) as its battery fuel gauge. It supports a
single-cell battery and features a dual-color charging LED.

Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
 drivers/power/supply/Kconfig           |  12 +
 drivers/power/supply/Makefile          |   1 +
 drivers/power/supply/chagall-battery.c | 308 +++++++++++++++++++++++++
 3 files changed, 321 insertions(+)
 create mode 100644 drivers/power/supply/chagall-battery.c

diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
index 9f2eef6787f7..d0fc9db524bd 100644
--- a/drivers/power/supply/Kconfig
+++ b/drivers/power/supply/Kconfig
@@ -107,6 +107,18 @@ config BATTERY_ACT8945A
 	  Say Y here to enable support for power supply provided by
 	  Active-semi ActivePath ACT8945A charger.
 
+config BATTERY_CHAGALL
+	tristate "Pegatron Chagall battery driver"
+	depends on I2C
+	depends on LEDS_CLASS
+	help
+	  Say Y to include support for Cypress CG7153AM IC based battery
+	  fuel gauge with custom firmware found in Pegatron Chagall based
+	  tablet line.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called chagall-battery.
+
 config BATTERY_CPCAP
 	tristate "Motorola CPCAP PMIC battery driver"
 	depends on MFD_CPCAP && IIO
diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile
index 59c4a9f40d28..4ecf48a33fdd 100644
--- a/drivers/power/supply/Makefile
+++ b/drivers/power/supply/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_CHARGER_ADP5061)	+= adp5061.o
 obj-$(CONFIG_BATTERY_ACT8945A)	+= act8945a_charger.o
 obj-$(CONFIG_BATTERY_AXP20X)	+= axp20x_battery.o
 obj-$(CONFIG_CHARGER_AXP20X)	+= axp20x_ac_power.o
+obj-$(CONFIG_BATTERY_CHAGALL)	+= chagall-battery.o
 obj-$(CONFIG_BATTERY_CPCAP)	+= cpcap-battery.o
 obj-$(CONFIG_BATTERY_CW2015)	+= cw2015_battery.o
 obj-$(CONFIG_BATTERY_DS2760)	+= ds2760_battery.o
diff --git a/drivers/power/supply/chagall-battery.c b/drivers/power/supply/chagall-battery.c
new file mode 100644
index 000000000000..1a278331efe7
--- /dev/null
+++ b/drivers/power/supply/chagall-battery.c
@@ -0,0 +1,308 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include <linux/array_size.h>
+#include <linux/delay.h>
+#include <linux/devm-helpers.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/leds.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/power_supply.h>
+#include <linux/regmap.h>
+
+#define CHAGALL_REG_LED_AMBER				0x60
+#define CHAGALL_REG_LED_WHITE				0x70
+#define CHAGALL_REG_BATTERY_TEMPERATURE			0xa2
+#define CHAGALL_REG_BATTERY_VOLTAGE			0xa4
+#define CHAGALL_REG_BATTERY_CURRENT			0xa6
+#define CHAGALL_REG_BATTERY_CAPACITY			0xa8
+#define CHAGALL_REG_BATTERY_CHARGING_CURRENT		0xaa
+#define CHAGALL_REG_BATTERY_CHARGING_VOLTAGE		0xac
+#define CHAGALL_REG_BATTERY_STATUS			0xae
+#define   BATTERY_DISCHARGING				BIT(6)
+#define   BATTERY_FULL_CHARGED				BIT(5)
+#define   BATTERY_FULL_DISCHARGED			BIT(4)
+#define CHAGALL_REG_BATTERY_REMAIN_CAPACITY		0xb0
+#define CHAGALL_REG_BATTERY_FULL_CAPACITY		0xb2
+#define CHAGALL_REG_MAX_COUNT				0xb4
+
+#define CHAGALL_BATTERY_DATA_REFRESH			5000
+#define TEMP_CELSIUS_OFFSET				2731
+
+static const struct regmap_config chagall_battery_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = CHAGALL_REG_MAX_COUNT,
+	.reg_format_endian = REGMAP_ENDIAN_LITTLE,
+	.val_format_endian = REGMAP_ENDIAN_LITTLE,
+};
+
+struct chagall_battery_data {
+	struct regmap *regmap;
+	struct led_classdev amber_led;
+	struct led_classdev white_led;
+	struct power_supply *battery;
+	struct delayed_work poll_work;
+	u16 last_state;
+};
+
+static void chagall_led_set_brightness_amber(struct led_classdev *led,
+					     enum led_brightness brightness)
+{
+	struct chagall_battery_data *cg =
+		container_of(led, struct chagall_battery_data, amber_led);
+
+	regmap_write(cg->regmap, CHAGALL_REG_LED_AMBER, brightness);
+}
+
+static void chagall_led_set_brightness_white(struct led_classdev *led,
+					     enum led_brightness brightness)
+{
+	struct chagall_battery_data *cg =
+		container_of(led, struct chagall_battery_data, white_led);
+
+	regmap_write(cg->regmap, CHAGALL_REG_LED_WHITE, brightness);
+}
+
+static void chagall_leds_status_update(struct chagall_battery_data *cg, int state)
+{
+	switch (state) {
+	case POWER_SUPPLY_STATUS_FULL:
+		led_set_brightness(&cg->amber_led, LED_OFF);
+		led_set_brightness(&cg->white_led,  LED_ON);
+		break;
+
+	case POWER_SUPPLY_STATUS_CHARGING:
+		led_set_brightness(&cg->white_led, LED_OFF);
+		led_set_brightness(&cg->amber_led,  LED_ON);
+		break;
+
+	default:
+		led_set_brightness(&cg->amber_led, LED_OFF);
+		led_set_brightness(&cg->white_led, LED_OFF);
+		break;
+	}
+}
+
+static const enum power_supply_property chagall_battery_properties[] = {
+	POWER_SUPPLY_PROP_STATUS,
+	POWER_SUPPLY_PROP_PRESENT,
+	POWER_SUPPLY_PROP_VOLTAGE_NOW,
+	POWER_SUPPLY_PROP_VOLTAGE_MAX,
+	POWER_SUPPLY_PROP_CURRENT_NOW,
+	POWER_SUPPLY_PROP_CURRENT_MAX,
+	POWER_SUPPLY_PROP_CAPACITY,
+	POWER_SUPPLY_PROP_TEMP,
+	POWER_SUPPLY_PROP_CHARGE_FULL,
+	POWER_SUPPLY_PROP_CHARGE_NOW,
+};
+
+static const unsigned int chagall_battery_prop_offs[] = {
+	[POWER_SUPPLY_PROP_TEMP] = CHAGALL_REG_BATTERY_TEMPERATURE,
+	[POWER_SUPPLY_PROP_VOLTAGE_NOW] = CHAGALL_REG_BATTERY_VOLTAGE,
+	[POWER_SUPPLY_PROP_CURRENT_NOW] = CHAGALL_REG_BATTERY_CURRENT,
+	[POWER_SUPPLY_PROP_CAPACITY] = CHAGALL_REG_BATTERY_CAPACITY,
+	[POWER_SUPPLY_PROP_CURRENT_MAX] = CHAGALL_REG_BATTERY_CHARGING_CURRENT,
+	[POWER_SUPPLY_PROP_VOLTAGE_MAX] = CHAGALL_REG_BATTERY_CHARGING_VOLTAGE,
+	[POWER_SUPPLY_PROP_STATUS] = CHAGALL_REG_BATTERY_STATUS,
+	[POWER_SUPPLY_PROP_CHARGE_NOW] = CHAGALL_REG_BATTERY_REMAIN_CAPACITY,
+	[POWER_SUPPLY_PROP_CHARGE_FULL] = CHAGALL_REG_BATTERY_FULL_CAPACITY,
+};
+
+static int chagall_battery_get_value(struct chagall_battery_data *cg,
+				     enum power_supply_property psp, u32 *val)
+{
+	if (psp >= ARRAY_SIZE(chagall_battery_prop_offs))
+		return -EINVAL;
+	if (!chagall_battery_prop_offs[psp])
+		return -EINVAL;
+
+	/* Battery data is stored in 2 consecutive registers with little-endian */
+	return regmap_bulk_read(cg->regmap, chagall_battery_prop_offs[psp], val, 2);
+}
+
+static int chagall_battery_get_property(struct power_supply *psy,
+					enum power_supply_property psp,
+					union power_supply_propval *val)
+{
+	struct chagall_battery_data *cg = power_supply_get_drvdata(psy);
+	int ret;
+
+	switch (psp) {
+	case POWER_SUPPLY_PROP_PRESENT:
+		val->intval = 1;
+		break;
+
+	default:
+		ret = chagall_battery_get_value(cg, psp, &val->intval);
+		if (ret)
+			return ret;
+
+		switch (psp) {
+		case POWER_SUPPLY_PROP_TEMP:
+			val->intval -= TEMP_CELSIUS_OFFSET;
+			break;
+
+		case POWER_SUPPLY_PROP_VOLTAGE_MAX:
+		case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+		case POWER_SUPPLY_PROP_CURRENT_MAX:
+		case POWER_SUPPLY_PROP_CURRENT_NOW:
+		case POWER_SUPPLY_PROP_CHARGE_FULL:
+		case POWER_SUPPLY_PROP_CHARGE_NOW:
+			val->intval *= 1000;
+			break;
+
+		case POWER_SUPPLY_PROP_STATUS:
+			if (val->intval & BATTERY_FULL_CHARGED)
+				val->intval = POWER_SUPPLY_STATUS_FULL;
+			else if (val->intval & BATTERY_FULL_DISCHARGED)
+				val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
+			else if (val->intval & BATTERY_DISCHARGING)
+				val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
+			else
+				val->intval = POWER_SUPPLY_STATUS_CHARGING;
+			break;
+
+		default:
+			break;
+		}
+
+		break;
+	}
+
+	return 0;
+}
+
+static void chagall_battery_poll_work(struct work_struct *work)
+{
+	struct chagall_battery_data *cg =
+		container_of(work, struct chagall_battery_data, poll_work.work);
+	u32 state;
+	int ret;
+
+	ret = chagall_battery_get_value(cg, POWER_SUPPLY_PROP_STATUS, &state);
+	if (ret)
+		return;
+
+	if (state & BATTERY_FULL_CHARGED)
+		state = POWER_SUPPLY_STATUS_FULL;
+	else if (state & BATTERY_DISCHARGING)
+		state = POWER_SUPPLY_STATUS_DISCHARGING;
+	else
+		state = POWER_SUPPLY_STATUS_CHARGING;
+
+	if (cg->last_state != state) {
+		cg->last_state = state;
+		power_supply_changed(cg->battery);
+	}
+
+	chagall_leds_status_update(cg, state);
+
+	/* continuously send uevent notification */
+	schedule_delayed_work(&cg->poll_work,
+			      msecs_to_jiffies(CHAGALL_BATTERY_DATA_REFRESH));
+}
+
+static const struct power_supply_desc chagall_battery_desc = {
+	.name = "chagall-battery",
+	.type = POWER_SUPPLY_TYPE_BATTERY,
+	.properties = chagall_battery_properties,
+	.num_properties = ARRAY_SIZE(chagall_battery_properties),
+	.get_property = chagall_battery_get_property,
+	.external_power_changed = power_supply_changed,
+};
+
+static int chagall_battery_probe(struct i2c_client *client)
+{
+	struct chagall_battery_data *cg;
+	struct device *dev = &client->dev;
+	struct power_supply_config cfg = { };
+	int ret;
+
+	cg = devm_kzalloc(dev, sizeof(*cg), GFP_KERNEL);
+	if (!cg)
+		return -ENOMEM;
+
+	cfg.drv_data = cg;
+	cfg.fwnode = dev_fwnode(dev);
+
+	i2c_set_clientdata(client, cg);
+
+	cg->regmap = devm_regmap_init_i2c(client, &chagall_battery_regmap_config);
+	if (IS_ERR(cg->regmap))
+		return dev_err_probe(dev, PTR_ERR(cg->regmap), "cannot allocate regmap\n");
+
+	cg->last_state = POWER_SUPPLY_STATUS_UNKNOWN;
+	cg->battery = devm_power_supply_register(dev, &chagall_battery_desc, &cfg);
+	if (IS_ERR(cg->battery))
+		return dev_err_probe(dev, PTR_ERR(cg->battery), "failed to register power supply\n");
+
+	cg->amber_led.name = "power::amber";
+	cg->amber_led.max_brightness = 1;
+	cg->amber_led.flags = LED_CORE_SUSPENDRESUME;
+	cg->amber_led.brightness_set = chagall_led_set_brightness_amber;
+
+	ret = devm_led_classdev_register(dev, &cg->amber_led);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to register amber LED\n");
+
+	cg->white_led.name = "power::white";
+	cg->white_led.max_brightness = 1;
+	cg->white_led.flags = LED_CORE_SUSPENDRESUME;
+	cg->white_led.brightness_set = chagall_led_set_brightness_white;
+
+	ret = devm_led_classdev_register(dev, &cg->white_led);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to register white LED\n");
+
+	led_set_brightness(&cg->amber_led, LED_OFF);
+	led_set_brightness(&cg->white_led, LED_OFF);
+
+	ret = devm_delayed_work_autocancel(dev, &cg->poll_work, chagall_battery_poll_work);
+	if (ret)
+		return ret;
+
+	schedule_delayed_work(&cg->poll_work, msecs_to_jiffies(CHAGALL_BATTERY_DATA_REFRESH));
+	return 0;
+}
+
+static int __maybe_unused chagall_battery_suspend(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct chagall_battery_data *cg = i2c_get_clientdata(client);
+
+	cancel_delayed_work_sync(&cg->poll_work);
+	return 0;
+}
+
+static int __maybe_unused chagall_battery_resume(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct chagall_battery_data *cg = i2c_get_clientdata(client);
+
+	schedule_delayed_work(&cg->poll_work, msecs_to_jiffies(CHAGALL_BATTERY_DATA_REFRESH));
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(chagall_battery_pm_ops,
+			 chagall_battery_suspend, chagall_battery_resume);
+
+static const struct of_device_id chagall_of_match[] = {
+	{ .compatible = "pegatron,chagall-ec" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, chagall_of_match);
+
+static struct i2c_driver chagall_battery_driver = {
+	.driver = {
+		.name = "chagall-battery",
+		.pm = &chagall_battery_pm_ops,
+		.of_match_table = chagall_of_match,
+	},
+	.probe = chagall_battery_probe,
+};
+module_i2c_driver(chagall_battery_driver);
+
+MODULE_AUTHOR("Svyatoslav Ryhel <clamor95@gmail.com>");
+MODULE_DESCRIPTION("Pegatron Chagall fuel gauge driver");
+MODULE_LICENSE("GPL");
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v1 4/4] ARM: tegra: chagall: Add embedded controller node
  2025-03-23  7:14 [PATCH v1 0/4] power: supply: add support for Pegatron Chagall battery Svyatoslav Ryhel
                   ` (2 preceding siblings ...)
  2025-03-23  7:14 ` [PATCH v1 3/4] power/supply: Add driver for Pegatron Chagall battery Svyatoslav Ryhel
@ 2025-03-23  7:14 ` Svyatoslav Ryhel
  3 siblings, 0 replies; 10+ messages in thread
From: Svyatoslav Ryhel @ 2025-03-23  7:14 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Thierry Reding, Jonathan Hunter, Sebastian Reichel,
	Svyatoslav Ryhel
  Cc: devicetree, linux-kernel, linux-tegra, linux-pm

Add embedded controller node to Pegatron Chagall device-tree.

Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
 .../boot/dts/nvidia/tegra30-pegatron-chagall.dts | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/arch/arm/boot/dts/nvidia/tegra30-pegatron-chagall.dts b/arch/arm/boot/dts/nvidia/tegra30-pegatron-chagall.dts
index 4012f9c799a8..fc9eeec54692 100644
--- a/arch/arm/boot/dts/nvidia/tegra30-pegatron-chagall.dts
+++ b/arch/arm/boot/dts/nvidia/tegra30-pegatron-chagall.dts
@@ -1155,6 +1155,14 @@ lcd_ddc: i2c@7000c000 {
 		status = "okay";
 		clock-frequency = <400000>;
 
+		embedded-controller@10 {
+			compatible = "pegatron,chagall-ec", "cypress,cg7153am";
+			reg = <0x10>;
+
+			monitored-battery = <&battery>;
+			power-supplies = <&mains>;
+		};
+
 		/* Wolfson Microelectronics WM8903 audio codec */
 		wm8903: audio-codec@1a {
 			compatible = "wlf,wm8903";
@@ -2596,6 +2604,14 @@ backlight: backlight {
 		default-brightness-level = <15>;
 	};
 
+	battery: battery-cell {
+		compatible = "simple-battery";
+		device-chemistry = "lithium-ion-polymer";
+		charge-full-design-microamp-hours = <3050000>;
+		energy-full-design-microwatt-hours = <23000000>;
+		operating-range-celsius = <0 45>;
+	};
+
 	/* PMIC has a built-in 32KHz oscillator which is used by PMC */
 	clk32k_in: clock-32k {
 		compatible = "fixed-clock";
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v1 2/4] dt-bindings: mfd: Document Infineon/Cypress CG7153AM MCU
  2025-03-23  7:14 ` [PATCH v1 2/4] dt-bindings: mfd: Document Infineon/Cypress CG7153AM MCU Svyatoslav Ryhel
@ 2025-03-24 16:52   ` Rob Herring
  2025-03-24 17:05     ` Svyatoslav Ryhel
  0 siblings, 1 reply; 10+ messages in thread
From: Rob Herring @ 2025-03-24 16:52 UTC (permalink / raw)
  To: Svyatoslav Ryhel
  Cc: Lee Jones, Krzysztof Kozlowski, Conor Dooley, Thierry Reding,
	Jonathan Hunter, Sebastian Reichel, devicetree, linux-kernel,
	linux-tegra, linux-pm

On Sun, Mar 23, 2025 at 09:14:22AM +0200, Svyatoslav Ryhel wrote:
> Add binding for Cypress CG7153AM embedded controller. Pegatron implemented
> a custom configuration of this MCU in their Chagall tablets, utilizing it
> for battery monitoring.
> 
> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
> ---
>  .../bindings/mfd/cypress,cg7153am.yaml        | 55 +++++++++++++++++++
>  1 file changed, 55 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml
> 
> diff --git a/Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml b/Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml
> new file mode 100644
> index 000000000000..f8469b5e3816
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml
> @@ -0,0 +1,55 @@
> +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/mfd/cypress,cg7153am.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Infineon/Cypress Semicon CG7153AM Microcontroller
> +
> +maintainers:
> +  - Svyatoslav Ryhel <clamor95@gmail.com>
> +
> +description:
> +  The CG7153AM, an 8-bit programmable microcontroller from Infineon/Cypress
> +  Semiconductor, communicates over I2C and is implemented in devices like the
> +  Pegatron Chagall tablet for fuel gauge and battery control functions.
> +
> +$ref: /schemas/power/supply/power-supply.yaml
> +
> +properties:
> +  compatible:
> +    oneOf:
> +      - items:
> +          - enum:
> +              - pegatron,chagall-ec # Pegatron Chagall tablet device
> +          - const: cypress,cg7153am
> +      - items:
> +          const: cypress,cg7153am

Is this just some general purpose uC which could be used for anything 
and the interface exposed is Pegatron's invention. If so, then I'd drop 
the cypress,cg7153am compatible. What use would it be to software?

> +
> +  reg:
> +    maxItems: 1
> +
> +  monitored-battery: true
> +  power-supplies: true
> +
> +required:
> +  - compatible
> +  - reg
> +
> +unevaluatedProperties: false
> +
> +examples:
> +  - |
> +    i2c {
> +        #address-cells = <1>;
> +        #size-cells = <0>;
> +
> +        embedded-controller@10 {
> +            compatible = "pegatron,chagall-ec", "cypress,cg7153am";
> +            reg = <0x10>;
> +
> +            monitored-battery = <&battery>;
> +            power-supplies = <&mains>;
> +        };
> +    };
> +...
> -- 
> 2.43.0
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1 1/4] dt-bindings: vendor-prefixes: add prefix for Pegatron Corporation
  2025-03-23  7:14 ` [PATCH v1 1/4] dt-bindings: vendor-prefixes: add prefix for Pegatron Corporation Svyatoslav Ryhel
@ 2025-03-24 16:53   ` Rob Herring
  0 siblings, 0 replies; 10+ messages in thread
From: Rob Herring @ 2025-03-24 16:53 UTC (permalink / raw)
  To: Svyatoslav Ryhel
  Cc: Lee Jones, Krzysztof Kozlowski, Conor Dooley, Thierry Reding,
	Jonathan Hunter, Sebastian Reichel, devicetree, linux-kernel,
	linux-tegra, linux-pm

On Sun, Mar 23, 2025 at 09:14:21AM +0200, Svyatoslav Ryhel wrote:
> PEGATRON Corporation is a Taiwanese electronics manufacturing company that
> mainly develops computing, communications and consumer electronics for
> branded vendors. Link https://www.pegatroncorp.com/
> 
> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
> ---
>  Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
>  1 file changed, 2 insertions(+)

Acked-by: Rob Herring (Arm) <robh@kernel.org>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1 2/4] dt-bindings: mfd: Document Infineon/Cypress CG7153AM MCU
  2025-03-24 16:52   ` Rob Herring
@ 2025-03-24 17:05     ` Svyatoslav Ryhel
  2025-03-25  2:59       ` Rob Herring
  0 siblings, 1 reply; 10+ messages in thread
From: Svyatoslav Ryhel @ 2025-03-24 17:05 UTC (permalink / raw)
  To: Rob Herring
  Cc: Lee Jones, Krzysztof Kozlowski, Conor Dooley, Thierry Reding,
	Jonathan Hunter, Sebastian Reichel, devicetree, linux-kernel,
	linux-tegra, linux-pm

пн, 24 бер. 2025 р. о 18:52 Rob Herring <robh@kernel.org> пише:
>
> On Sun, Mar 23, 2025 at 09:14:22AM +0200, Svyatoslav Ryhel wrote:
> > Add binding for Cypress CG7153AM embedded controller. Pegatron implemented
> > a custom configuration of this MCU in their Chagall tablets, utilizing it
> > for battery monitoring.
> >
> > Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
> > ---
> >  .../bindings/mfd/cypress,cg7153am.yaml        | 55 +++++++++++++++++++
> >  1 file changed, 55 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml
> >
> > diff --git a/Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml b/Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml
> > new file mode 100644
> > index 000000000000..f8469b5e3816
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml
> > @@ -0,0 +1,55 @@
> > +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
> > +%YAML 1.2
> > +---
> > +$id: http://devicetree.org/schemas/mfd/cypress,cg7153am.yaml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: Infineon/Cypress Semicon CG7153AM Microcontroller
> > +
> > +maintainers:
> > +  - Svyatoslav Ryhel <clamor95@gmail.com>
> > +
> > +description:
> > +  The CG7153AM, an 8-bit programmable microcontroller from Infineon/Cypress
> > +  Semiconductor, communicates over I2C and is implemented in devices like the
> > +  Pegatron Chagall tablet for fuel gauge and battery control functions.
> > +
> > +$ref: /schemas/power/supply/power-supply.yaml
> > +
> > +properties:
> > +  compatible:
> > +    oneOf:
> > +      - items:
> > +          - enum:
> > +              - pegatron,chagall-ec # Pegatron Chagall tablet device
> > +          - const: cypress,cg7153am
> > +      - items:
> > +          const: cypress,cg7153am
>
> Is this just some general purpose uC which could be used for anything
> and the interface exposed is Pegatron's invention. If so, then I'd drop
> the cypress,cg7153am compatible. What use would it be to software?
>

Yeah, Cypress made an MPU, Pegatron used it as a base to make a fuel gauge.

You propose smth like this?

      - items:
          - enum:
              - pegatron,chagall-ec # Pegatron Chagall tablet device
          - const: cypress,cg7153am

Without oneOf and second item or remove cypress,cg7153am entirely and
submit as pegatron,chagall-ec.yaml? Just to be clear.

I am fine with removing oneOf and items: const: cypress,cg7153am, but
I would like to preserve cypress,cg7153am as second compatible since
this is an actual MCU model.

Thanks.

> > +
> > +  reg:
> > +    maxItems: 1
> > +
> > +  monitored-battery: true
> > +  power-supplies: true
> > +
> > +required:
> > +  - compatible
> > +  - reg
> > +
> > +unevaluatedProperties: false
> > +
> > +examples:
> > +  - |
> > +    i2c {
> > +        #address-cells = <1>;
> > +        #size-cells = <0>;
> > +
> > +        embedded-controller@10 {
> > +            compatible = "pegatron,chagall-ec", "cypress,cg7153am";
> > +            reg = <0x10>;
> > +
> > +            monitored-battery = <&battery>;
> > +            power-supplies = <&mains>;
> > +        };
> > +    };
> > +...
> > --
> > 2.43.0
> >

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1 2/4] dt-bindings: mfd: Document Infineon/Cypress CG7153AM MCU
  2025-03-24 17:05     ` Svyatoslav Ryhel
@ 2025-03-25  2:59       ` Rob Herring
  2025-03-25  6:57         ` Svyatoslav Ryhel
  0 siblings, 1 reply; 10+ messages in thread
From: Rob Herring @ 2025-03-25  2:59 UTC (permalink / raw)
  To: Svyatoslav Ryhel
  Cc: Lee Jones, Krzysztof Kozlowski, Conor Dooley, Thierry Reding,
	Jonathan Hunter, Sebastian Reichel, devicetree, linux-kernel,
	linux-tegra, linux-pm

On Mon, Mar 24, 2025 at 12:06 PM Svyatoslav Ryhel <clamor95@gmail.com> wrote:
>
> пн, 24 бер. 2025 р. о 18:52 Rob Herring <robh@kernel.org> пише:
> >
> > On Sun, Mar 23, 2025 at 09:14:22AM +0200, Svyatoslav Ryhel wrote:
> > > Add binding for Cypress CG7153AM embedded controller. Pegatron implemented
> > > a custom configuration of this MCU in their Chagall tablets, utilizing it
> > > for battery monitoring.
> > >
> > > Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
> > > ---
> > >  .../bindings/mfd/cypress,cg7153am.yaml        | 55 +++++++++++++++++++
> > >  1 file changed, 55 insertions(+)
> > >  create mode 100644 Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml
> > >
> > > diff --git a/Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml b/Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml
> > > new file mode 100644
> > > index 000000000000..f8469b5e3816
> > > --- /dev/null
> > > +++ b/Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml
> > > @@ -0,0 +1,55 @@
> > > +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
> > > +%YAML 1.2
> > > +---
> > > +$id: http://devicetree.org/schemas/mfd/cypress,cg7153am.yaml#
> > > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > > +
> > > +title: Infineon/Cypress Semicon CG7153AM Microcontroller
> > > +
> > > +maintainers:
> > > +  - Svyatoslav Ryhel <clamor95@gmail.com>
> > > +
> > > +description:
> > > +  The CG7153AM, an 8-bit programmable microcontroller from Infineon/Cypress
> > > +  Semiconductor, communicates over I2C and is implemented in devices like the
> > > +  Pegatron Chagall tablet for fuel gauge and battery control functions.
> > > +
> > > +$ref: /schemas/power/supply/power-supply.yaml
> > > +
> > > +properties:
> > > +  compatible:
> > > +    oneOf:
> > > +      - items:
> > > +          - enum:
> > > +              - pegatron,chagall-ec # Pegatron Chagall tablet device
> > > +          - const: cypress,cg7153am
> > > +      - items:
> > > +          const: cypress,cg7153am
> >
> > Is this just some general purpose uC which could be used for anything
> > and the interface exposed is Pegatron's invention. If so, then I'd drop
> > the cypress,cg7153am compatible. What use would it be to software?
> >
>
> Yeah, Cypress made an MPU, Pegatron used it as a base to make a fuel gauge.
>
> You propose smth like this?
>
>       - items:
>           - enum:
>               - pegatron,chagall-ec # Pegatron Chagall tablet device
>           - const: cypress,cg7153am
>
> Without oneOf and second item or remove cypress,cg7153am entirely and
> submit as pegatron,chagall-ec.yaml? Just to be clear.
>
> I am fine with removing oneOf and items: const: cypress,cg7153am, but
> I would like to preserve cypress,cg7153am as second compatible since
> this is an actual MCU model.

I would just drop the cypress compatible entirely. It needs to be
useful to a client (OS) in some way. If you said something like the
firmware downloading is defined by Cypress or some other feature, then
it would make sense. Otherwise, how this interface is implemented is
irrelevant. I can't think of any other embedded controller where we
have a compatible for the underlying MCU.

Rob

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1 2/4] dt-bindings: mfd: Document Infineon/Cypress CG7153AM MCU
  2025-03-25  2:59       ` Rob Herring
@ 2025-03-25  6:57         ` Svyatoslav Ryhel
  0 siblings, 0 replies; 10+ messages in thread
From: Svyatoslav Ryhel @ 2025-03-25  6:57 UTC (permalink / raw)
  To: Rob Herring
  Cc: Lee Jones, Krzysztof Kozlowski, Conor Dooley, Thierry Reding,
	Jonathan Hunter, Sebastian Reichel, devicetree, linux-kernel,
	linux-tegra, linux-pm

вт, 25 бер. 2025 р. о 05:00 Rob Herring <robh@kernel.org> пише:
>
> On Mon, Mar 24, 2025 at 12:06 PM Svyatoslav Ryhel <clamor95@gmail.com> wrote:
> >
> > пн, 24 бер. 2025 р. о 18:52 Rob Herring <robh@kernel.org> пише:
> > >
> > > On Sun, Mar 23, 2025 at 09:14:22AM +0200, Svyatoslav Ryhel wrote:
> > > > Add binding for Cypress CG7153AM embedded controller. Pegatron implemented
> > > > a custom configuration of this MCU in their Chagall tablets, utilizing it
> > > > for battery monitoring.
> > > >
> > > > Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
> > > > ---
> > > >  .../bindings/mfd/cypress,cg7153am.yaml        | 55 +++++++++++++++++++
> > > >  1 file changed, 55 insertions(+)
> > > >  create mode 100644 Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml
> > > >
> > > > diff --git a/Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml b/Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml
> > > > new file mode 100644
> > > > index 000000000000..f8469b5e3816
> > > > --- /dev/null
> > > > +++ b/Documentation/devicetree/bindings/mfd/cypress,cg7153am.yaml
> > > > @@ -0,0 +1,55 @@
> > > > +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
> > > > +%YAML 1.2
> > > > +---
> > > > +$id: http://devicetree.org/schemas/mfd/cypress,cg7153am.yaml#
> > > > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > > > +
> > > > +title: Infineon/Cypress Semicon CG7153AM Microcontroller
> > > > +
> > > > +maintainers:
> > > > +  - Svyatoslav Ryhel <clamor95@gmail.com>
> > > > +
> > > > +description:
> > > > +  The CG7153AM, an 8-bit programmable microcontroller from Infineon/Cypress
> > > > +  Semiconductor, communicates over I2C and is implemented in devices like the
> > > > +  Pegatron Chagall tablet for fuel gauge and battery control functions.
> > > > +
> > > > +$ref: /schemas/power/supply/power-supply.yaml
> > > > +
> > > > +properties:
> > > > +  compatible:
> > > > +    oneOf:
> > > > +      - items:
> > > > +          - enum:
> > > > +              - pegatron,chagall-ec # Pegatron Chagall tablet device
> > > > +          - const: cypress,cg7153am
> > > > +      - items:
> > > > +          const: cypress,cg7153am
> > >
> > > Is this just some general purpose uC which could be used for anything
> > > and the interface exposed is Pegatron's invention. If so, then I'd drop
> > > the cypress,cg7153am compatible. What use would it be to software?
> > >
> >
> > Yeah, Cypress made an MPU, Pegatron used it as a base to make a fuel gauge.
> >
> > You propose smth like this?
> >
> >       - items:
> >           - enum:
> >               - pegatron,chagall-ec # Pegatron Chagall tablet device
> >           - const: cypress,cg7153am
> >
> > Without oneOf and second item or remove cypress,cg7153am entirely and
> > submit as pegatron,chagall-ec.yaml? Just to be clear.
> >
> > I am fine with removing oneOf and items: const: cypress,cg7153am, but
> > I would like to preserve cypress,cg7153am as second compatible since
> > this is an actual MCU model.
>
> I would just drop the cypress compatible entirely. It needs to be
> useful to a client (OS) in some way. If you said something like the
> firmware downloading is defined by Cypress or some other feature, then
> it would make sense. Otherwise, how this interface is implemented is
> irrelevant. I can't think of any other embedded controller where we
> have a compatible for the underlying MCU.
>

So I will move this schema to power supplies and name it
pegratron,chagall-ec.yaml along with suggested changes in the
compatible and descriptions.

> Rob

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-03-25  6:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-23  7:14 [PATCH v1 0/4] power: supply: add support for Pegatron Chagall battery Svyatoslav Ryhel
2025-03-23  7:14 ` [PATCH v1 1/4] dt-bindings: vendor-prefixes: add prefix for Pegatron Corporation Svyatoslav Ryhel
2025-03-24 16:53   ` Rob Herring
2025-03-23  7:14 ` [PATCH v1 2/4] dt-bindings: mfd: Document Infineon/Cypress CG7153AM MCU Svyatoslav Ryhel
2025-03-24 16:52   ` Rob Herring
2025-03-24 17:05     ` Svyatoslav Ryhel
2025-03-25  2:59       ` Rob Herring
2025-03-25  6:57         ` Svyatoslav Ryhel
2025-03-23  7:14 ` [PATCH v1 3/4] power/supply: Add driver for Pegatron Chagall battery Svyatoslav Ryhel
2025-03-23  7:14 ` [PATCH v1 4/4] ARM: tegra: chagall: Add embedded controller node Svyatoslav Ryhel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).