Skip to contentSkip to conversation

LEGO MINDSTORMS EV3 Battery

PATCH Superseded David Lechner 3 participants 6 messages Apr 3, 2017 – Apr 11, 2017

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

David Lechner

author reviewer
#0 lore raw

cover LEGO MINDSTORMS EV3 Battery

This series adds support for the LEGO MINDSTORMS EV3 battery.

David Lechner (3):
dt-bindings: power: supply: New bindings for LEGO MINDSTORMS EV3
battery
power: supply: New driver for LEGO MINDSTORMS EV3 battery
ARM: dts: da850: Add node for LEGO MINDSTORMS EV3 Battery

 .../bindings/power/supply/lego_ev3_battery.txt     |  21 ++
 arch/arm/boot/dts/da850-lego-ev3.dts               |  28 +++
 drivers/power/supply/Kconfig                       |   6 +
 drivers/power/supply/Makefile                      |   1 +
 drivers/power/supply/lego_ev3_battery.c            | 237 +++++++++++++++++++++
 5 files changed, 293 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/lego_ev3_battery.txt
 create mode 100644 drivers/power/supply/lego_ev3_battery.c
Signature · 1 line
2.7.4
author reviewer
#1 lore raw

PATCH 1/3 dt-bindings: power: supply: New bindings for LEGO MINDSTORMS EV3 battery

This add a new device tree binding for LEGO MINDSTORMS EV3 battery. The EV3 has some built-in capability for monitoring the attached battery.

---
 .../bindings/power/supply/lego_ev3_battery.txt      | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/lego_ev3_battery.txt
Documentation/devicetree/bindings/power/supply/lego_ev3_battery.txt new file +21 -0
new file mode 100644
index 0000000..5485633
@@ -0,0 +1,21 @@
+LEGO MINDSTORMS EV3 Battery
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+LEGO MINDSTORMS EV3 has some built-in capability for monitoring the battery.
+It uses 6 AA batteries or a special Li-ion rechargeable battery pack that is
+detected by a key switch in the battery compartment.
+
+Required properties:
+ - compatible: Must be "lego,ev3-battery"
+ - io-channels: phandles to analog inputs for reading voltage and current
+ - io-channel-names: Must be "voltage", "current"
+ - rechargeable-gpios: phandle to the rechargeable battery indication gpio
+
+Example:
+
+	battery {
+		compatible = "lego,ev3-battery";
+		io-channels = <&adc 4>, <&adc 3>;
+		io-channel-names = "voltage", "current";
+		rechargeable-gpios = <&gpio 136 GPIO_ACTIVE_LOW>;
+	};
Signature · 1 line
2.7.4
author reviewer
#3 lore raw

PATCH 2/3 power: supply: New driver for LEGO MINDSTORMS EV3 battery

In reply to David Lechner

This adds a new driver for the LEGO MINDSTORMS EV3 battery. The EV3 is an embedded ARM device that can use 6 AA batteries or a special rechargeable Li-ion battery pack. The rechargeable battery pack presses a special key switch in the battery compartment to indicate that it is present.

The EV3 is only capable of monitoring battery voltage and current. The charging circuit is built into the rechargeable battery pack and there is no way to communicate with is, so we can't provide any information about charging status.

When not using the rechargeable battery pack, it is most common to use alkaline batteries to power the device, but it is also common for people to use rechargeable NiMH batteries. Since there is not a way to automatically differentiate between these, the technology property is made writable.

---
 drivers/power/supply/Kconfig            |   6 +
 drivers/power/supply/Makefile           |   1 +
 drivers/power/supply/lego_ev3_battery.c | 237 ++++++++++++++++++++++++++++++++
 3 files changed, 244 insertions(+)
 create mode 100644 drivers/power/supply/lego_ev3_battery.c
drivers/power/supply/Kconfig +6 -0
index cc50e15..e00bf25 100644
@@ -117,6 +117,12 @@ config BATTERY_DS2782
 	  Say Y here to enable support for the DS2782/DS2786 standalone battery
 	  gas-gauge.
 
+config BATTERY_LEGO_EV3
+	tristate "LEGO MINDSTORMS EV3 battery"
+	depends on OF && IIO && GPIOLIB
+	help
+	  Say Y here to enable support for the LEGO MINDSTORMS EV3 battery.
+
 config BATTERY_PMU
 	tristate "Apple PMU battery"
 	depends on PPC32 && ADB_PMU
drivers/power/supply/Makefile +1 -0
index 3789a2c..dfeadbc 100644
@@ -25,6 +25,7 @@ obj-$(CONFIG_BATTERY_DS2781)	+= ds2781_battery.o
 obj-$(CONFIG_BATTERY_DS2782)	+= ds2782_battery.o
 obj-$(CONFIG_BATTERY_GAUGE_LTC2941)	+= ltc2941-battery-gauge.o
 obj-$(CONFIG_BATTERY_GOLDFISH)	+= goldfish_battery.o
+obj-$(CONFIG_BATTERY_LEGO_EV3)	+= lego_ev3_battery.o
 obj-$(CONFIG_BATTERY_PMU)	+= pmu_battery.o
 obj-$(CONFIG_BATTERY_OLPC)	+= olpc_battery.o
 obj-$(CONFIG_BATTERY_TOSA)	+= tosa_battery.o
drivers/power/supply/lego_ev3_battery.c new file +237 -0

237 lines not on this page · raw message

Signature · 1 line
2.7.4
author reviewer
#5 lore raw

PATCH 3/3 ARM: dts: da850: Add node for LEGO MINDSTORMS EV3 Battery

In reply to David Lechner

This adds a new node to the LEGO MINDSTORMS EV3 device tree for the battery.

---
 arch/arm/boot/dts/da850-lego-ev3.dts | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
arch/arm/boot/dts/da850-lego-ev3.dts +28 -0
index c20580a..99cd561 100644
@@ -172,6 +172,18 @@
 		gpio = <&gpio 111 GPIO_ACTIVE_HIGH>;
 		enable-active-high;
 	};
+
+	/*
+	 * The EV3 can use 6-AA batteries or a rechargable Li-ion battery pack.
+	 */
+	battery {
+		pinctrl-names = "default";
+		pintctrl-0 = <&battery_pins>;
+		compatible = "lego,ev3-battery";
+		io-channels = <&adc 4>, <&adc 3>;
+		io-channel-names = "voltage", "current";
+		rechargeable-gpios = <&gpio 136 GPIO_ACTIVE_LOW>;
+	};
 };
 
 &pmx_core {
@@ -235,6 +247,15 @@
 			0x34 0x00000008 0x0000000f
 		>;
 	};
+
+	battery_pins: pinmux_battery_pins {
+		pinctrl-single,bits = <
+			/* GP0[6] */
+			0x04 0x00000080 0x000000f0
+			/* GP8[8] */
+			0x4c 0x00000080 0x000000f0
+		>;
+	};
 };
 
 &pinconf {
@@ -349,6 +370,13 @@
 
 &gpio {
 	status = "okay";
+
+	/* Don't pull down battery voltage adc io channel */
+	batt_volt_en {
+		gpio-hog;
+		gpios = <6 GPIO_ACTIVE_HIGH>;
+		output-low;
+	};
 };
 
 &usb_phy {
Signature · 1 line
2.7.4
maintainer Acked-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] dt-bindings: power: supply: New bindings for LEGO MINDSTORMS EV3 battery

In reply to David Lechner
Quoted 8 lines · David Lechner

This add a new device tree binding for LEGO MINDSTORMS EV3 battery. The EV3 has some built-in capability for monitoring the attached battery.

---
 .../bindings/power/supply/lego_ev3_battery.txt      | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/lego_ev3_battery.txt
#4 lore raw

Re: [PATCH 2/3] power: supply: New driver for LEGO MINDSTORMS EV3 battery

In reply to David Lechner

Hi,

Driver looks fine. One minor thing, though:

drivers/power/supply/lego_ev3_battery.c line 205

Quoted 8 lines · David Lechner

[...]

drivers/power/supply/lego_ev3_battery.c new file +6 -0
+	batt->psy = power_supply_register(dev, &lego_ev3_battery_desc, &psy_cfg);
+	err = PTR_ERR_OR_ZERO(batt->psy);
+	if (err) {
+		dev_err(dev, "failed to register power supply\n");
+		return err;
+	}

There is devm_power_supply_register() and it makes sense to use it, since that means you can drop the remove function completly :)

drivers/power/supply/lego_ev3_battery.c line 217

Quoted 11 lines
drivers/power/supply/lego_ev3_battery.c new file +11 -0
+	return 0;
+}
+
+static int lego_ev3_battery_remove(struct platform_device *pdev)
+{
+	struct lego_ev3_battery *batt = platform_get_drvdata(pdev);
+
+	power_supply_unregister(batt->psy);
+
+	return 0;
+}

-- Sebastian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170411/5eecb7ba/attachment.sig>