power: supply: Lenovo Yoga C630 EC
v2 cover power: supply: Lenovo Yoga C630 EC
This adds binding, driver and the DT support for the Lenovo Yoga C630 Embedded Controller, to provide battery information.
Support for this EC was implemented by Bjorn, who can no longer work on this topic. Thus it was agreed that I'll pick this patchset up and update it following the pending review comments.
Changes since v1:
- Dropped DP support for now, as the bindings are in process of being discussed separately,
- Merged dt patch into the same patchseries,
- Removed the fixed serial number battery property,
- Fixed indentation of dt bindings example,
- Added property: reg and unevaluatedProperties to the connector bindings.
Bjorn Andersson (3):
dt-bindings: power: supply: Add Lenovo Yoga C630 EC
power: supply: Add Lenovo Yoga C630 EC driver
arm64: dts: qcom: c630: Add Embedded Controller node
.../power/supply/lenovo,yoga-c630-ec.yaml | 83 +++ .../boot/dts/qcom/sdm850-lenovo-yoga-c630.dts | 35 ++ drivers/power/supply/Kconfig | 14 + drivers/power/supply/Makefile | 1 + drivers/power/supply/yoga-c630-ec.c | 471 ++++++++++++++++++ 5 files changed, 604 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml create mode 100644 drivers/power/supply/yoga-c630-ec.c
Signature · 1 line
2.39.1
PATCH v2 1/3 dt-bindings: power: supply: Add Lenovo Yoga C630 EC
From: Bjorn Andersson <[email protected]>
Add binding for the Embedded Controller found in the Qualcomm Snapdragon-based Lenovo Yoga C630.
--- .../power/supply/lenovo,yoga-c630-ec.yaml | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml new file +83 -0
@@ -0,0 +1,83 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/supply/lenovo,yoga-c630-ec.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Lenovo Yoga C630 Embedded Controller. + +maintainers: + - Bjorn Andersson <[email protected]> + +description: + The Qualcomm Snapdragon-based Lenovo Yoga C630 has an Embedded Controller + (EC) which handles things such as battery and USB Type-C. This binding + describes the interface, on an I2C bus, to this EC. + +properties: + compatible: + const: lenovo,yoga-c630-ec + + reg: + const: 0x70 + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + interrupts: + maxItems: 1 + +patternProperties: + '^connector@[01]$': + $ref: /schemas/connector/usb-connector.yaml# + + properties: + reg: + maxItems: 1 + + unevaluatedProperties: false + +required: + - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - |+ + #include <dt-bindings/interrupt-controller/irq.h> + i2c1 { + clock-frequency = <400000>; + + #address-cells = <1>; + #size-cells = <0>; + + embedded-controller@70 { + compatible = "lenovo,yoga-c630-ec"; + reg = <0x70>; + + interrupts-extended = <&tlmm 20 IRQ_TYPE_LEVEL_HIGH>; + + #address-cells = <1>; + #size-cells = <0>; + + connector@0 { + compatible = "usb-c-connector"; + reg = <0>; + power-role = "source"; + data-role = "host"; + }; + + connector@1 { + compatible = "usb-c-connector"; + reg = <1>; + power-role = "source"; + data-role = "host"; + }; + }; + }; +...
Signature · 1 line
2.39.1
Re: [PATCH v2 1/3] dt-bindings: power: supply: Add Lenovo Yoga C630 EC
Quoted 7 lines · Dmitry Baryshkov
From: Bjorn Andersson <[email protected]>
Add binding for the Embedded Controller found in the Qualcomm Snapdragon-based Lenovo Yoga C630.
Signed-off-by Bjorn Andersson <[email protected]>Signed-off-by Dmitry Baryshkov <[email protected]>
Loooks ok for me.
If there is going to be resend, three nits below:
Quoted 11 lines
--- .../power/supply/lenovo,yoga-c630-ec.yaml | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yamlDocumentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml new file +0
-0
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml line 7
Quoted 7 lines
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml new file +7
-0@@ -0,0 +1,83 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/supply/lenovo,yoga-c630-ec.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Lenovo Yoga C630 Embedded Controller.
Drop trailing full stop
(...)
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml line 51
Quoted 3 lines
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml new file +3
-0+ +examples: + - |+
Just:
- |
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml line 53
Quoted 2 lines
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml new file +2
-0+ #include <dt-bindings/interrupt-controller/irq.h> + i2c1 {
Just: "i2c"
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml line 57
Quoted 4 lines
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml new file +4
-0+ clock-frequency = <400000>; + + #address-cells = <1>; + #size-cells = <0>;
Best regards,
Krzysztof
Rob Herring
maintainerRe: [PATCH v2 1/3] dt-bindings: power: supply: Add Lenovo Yoga C630 EC
In reply to Dmitry BaryshkovQuoted 61 lines · Dmitry Baryshkov
From: Bjorn Andersson <[email protected]>
Add binding for the Embedded Controller found in the Qualcomm Snapdragon-based Lenovo Yoga C630.
Signed-off-by Bjorn Andersson <[email protected]>Signed-off-by Dmitry Baryshkov <[email protected]>--- .../power/supply/lenovo,yoga-c630-ec.yaml | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yamlDocumentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml new file +43
-0@@ -0,0 +1,83 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/supply/lenovo,yoga-c630-ec.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Lenovo Yoga C630 Embedded Controller. + +maintainers: + - Bjorn Andersson <[email protected]> + +description: + The Qualcomm Snapdragon-based Lenovo Yoga C630 has an Embedded Controller + (EC) which handles things such as battery and USB Type-C. This binding + describes the interface, on an I2C bus, to this EC. + +properties: + compatible: + const: lenovo,yoga-c630-ec + + reg: + const: 0x70 + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + interrupts: + maxItems: 1 + +patternProperties: + '^connector@[01]$': + $ref: /schemas/connector/usb-connector.yaml# + + properties: + reg: + maxItems: 1 + + unevaluatedProperties: false + +required:
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml line 53
Quoted 10 lines
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml new file +10
-0+ - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - |+ + #include <dt-bindings/interrupt-controller/irq.h> + i2c1 {
i2c {
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml line 54
Quoted 1 line
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml new file +1
-0+ clock-frequency = <400000>;
Not relevant to the example.
Quoted 32 lines
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml new file +29
-0+ + #address-cells = <1>; + #size-cells = <0>; + + embedded-controller@70 { + compatible = "lenovo,yoga-c630-ec"; + reg = <0x70>; + + interrupts-extended = <&tlmm 20 IRQ_TYPE_LEVEL_HIGH>; + + #address-cells = <1>; + #size-cells = <0>; + + connector@0 { + compatible = "usb-c-connector"; + reg = <0>; + power-role = "source"; + data-role = "host"; + }; + + connector@1 { + compatible = "usb-c-connector"; + reg = <1>; + power-role = "source"; + data-role = "host"; + }; + }; + }; +...Signature · 1 line
2.39.1
Re: [PATCH v2 1/3] dt-bindings: power: supply: Add Lenovo Yoga C630 EC
In reply to Dmitry BaryshkovQuoted 18 lines · Dmitry Baryshkov
From: Bjorn Andersson <[email protected]>
Add binding for the Embedded Controller found in the Qualcomm Snapdragon-based Lenovo Yoga C630.
Signed-off-by Bjorn Andersson <[email protected]>Signed-off-by Dmitry Baryshkov <[email protected]>--- .../power/supply/lenovo,yoga-c630-ec.yaml | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yamlDocumentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml new file +0
-0
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml line 10
Quoted 10 lines
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml new file +10
-0@@ -0,0 +1,83 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/supply/lenovo,yoga-c630-ec.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Lenovo Yoga C630 Embedded Controller. + +maintainers: + - Bjorn Andersson <[email protected]>
Since this is new: Should this be updated with Bjorn's kernel.org address? Last I checked, this address doesn't exist anymore.
Brian
Re: [PATCH v2 1/3] dt-bindings: power: supply: Add Lenovo Yoga C630 EC
Quoted 24 lines · Brian Masney
Quoted 23 lines · Dmitry Baryshkov
From: Bjorn Andersson <[email protected]>
Add binding for the Embedded Controller found in the Qualcomm Snapdragon-based Lenovo Yoga C630.
Signed-off-by Bjorn Andersson <[email protected]>Signed-off-by Dmitry Baryshkov <[email protected]>--- .../power/supply/lenovo,yoga-c630-ec.yaml | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+)create mode 100644
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yamlDocumentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml new file +5
-0@@ -0,0 +1,83 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/supply/lenovo,yoga-c630-ec.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml#
Quoted 8 lines
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml line 10
Quoted 5 lines
Documentation/devicetree/bindings/power/supply/lenovo,yoga-c630-ec.yaml new file +5
-0+ +title: Lenovo Yoga C630 Embedded Controller. + +maintainers: + - Bjorn Andersson <[email protected]>Since this is new: Should this be updated with Bjorn's kernel.org address? Last I checked, this address doesn't exist anymore.
Ack, nice catch.
Quoted 3 lines
Brian
Signature · 2 lines
With best wishes Dmitry
PATCH v2 2/3 power: supply: Add Lenovo Yoga C630 EC driver
In reply to Dmitry BaryshkovFrom: Bjorn Andersson <[email protected]>
The Qualcomm Snapdragon-based Lenovo Yoga C630 has some sort of EC providing AC-adapter and battery status, as well as USB Type-C altmode notifications for Displayport operation.
The Yoga C630 ships with Windows, where these operations primarily are implemented in ACPI, but due to various issues with the hardware representation therein it's not possible to run Linux on this information. As such this is a best-effort re-implementation of these operations, based on the register map expressed in ACPI and a fair amount of trial and error.
--- drivers/power/supply/Kconfig | 14 + drivers/power/supply/Makefile | 1 + drivers/power/supply/yoga-c630-ec.c | 471 ++++++++++++++++++++++++++++ 3 files changed, 486 insertions(+) create mode 100644 drivers/power/supply/yoga-c630-ec.c
drivers/power/supply/Kconfig +14 -0
@@ -918,4 +918,18 @@ config BATTERY_UG3105 device is off or suspended, the functionality of this driver is limited to reporting capacity only. +config LENOVO_YOGA_C630_EC + tristate "Lenovo Yoga C630 EC battery driver" + depends on I2C + help + Driver for the Embedded Controller in the Qualcomm Snapdragon-based + Lenovo Yoga C630, which provides battery and power adapter + information. + + This driver provides battery and AC status support for the mentioned + laptop where this information is not properly exposed via the + standard ACPI devices. + + Say M or Y here to include this support. + endif # POWER_SUPPLY
drivers/power/supply/Makefile +1 -0
@@ -110,3 +110,4 @@ obj-$(CONFIG_BATTERY_ACER_A500) += acer_a500_battery.o obj-$(CONFIG_BATTERY_SURFACE) += surface_battery.o obj-$(CONFIG_CHARGER_SURFACE) += surface_charger.o obj-$(CONFIG_BATTERY_UG3105) += ug3105_battery.o +obj-$(CONFIG_LENOVO_YOGA_C630_EC) += yoga-c630-ec.o
drivers/power/supply/yoga-c630-ec.c new file +471 -0
471 lines not on this page · raw message
Signature · 1 line
2.39.1
Re: [PATCH v2 2/3] power: supply: Add Lenovo Yoga C630 EC driver
Quoted 9 lines · Dmitry Baryshkov
drivers/power/supply/yoga-c630-ec.c new file +9
-0+static int yoga_c630_ec_adpt_get_property (struct power_supply *psy, +enum power_supply_property psp, +union power_supply_propval *val) +{ +struct yoga_c630_ec *ec =power_supply_get_drvdata (psy); +int rc =0 ; + +yoga_c630_ec_update_adapter_status (ec); +
drivers/power/supply/yoga-c630-ec.c line 340
Quoted 10 lines
drivers/power/supply/yoga-c630-ec.c new file +10
-0+switch (psp) { +case POWER_SUPPLY_PROP_ONLINE : + val->intval = ec->adapter_online; +break ; +default : + rc = -EINVAL ; +break ; + } + +return rc;
You can simplify this function by getting rid of the switch statement and rc variable:
if (psp == POWER_SUPPLY_PROP_ONLINE) {
val->intval = ec->adapter_online;
return 0;
}
return -EINVAL;Brian
Re: [PATCH v2 2/3] power: supply: Add Lenovo Yoga C630 EC driver
In reply to Dmitry BaryshkovHi,
Quoted 17 lines · Dmitry Baryshkov
From: Bjorn Andersson <[email protected]>
The Qualcomm Snapdragon-based Lenovo Yoga C630 has some sort of EC providing AC-adapter and battery status, as well as USB Type-C altmode notifications for Displayport operation.
The Yoga C630 ships with Windows, where these operations primarily are implemented in ACPI, but due to various issues with the hardware representation therein it's not possible to run Linux on this information. As such this is a best-effort re-implementation of these operations, based on the register map expressed in ACPI and a fair amount of trial and error.
Tested-by Steev Klimaszewski <[email protected]>Signed-off-by Bjorn Andersson <[email protected]>Signed-off-by Dmitry Baryshkov <[email protected]>---
[...]
drivers/power/supply/yoga-c630-ec.c line 234
Quoted 10 lines
drivers/power/supply/yoga-c630-ec.c new file +10
-0+static bool yoga_c630_ec_is_charged (struct yoga_c630_ec *ec) +{ +if (ec->bat_status !=0 ) +return false; + +if (ec->full_charge_capacity == ec->capacity_now) +return true; + +if (ec->design_capacity == ec->capacity_now) +return true;
For other platforms I've seen the current capacity sometimes reaching higher values than the full charge capacity, so it's better to use <= here.
Quoted 2 lines
(quoted diff) +2
-0+ return false; +}
[...]
Quoted 4 lines
drivers/power/supply/yoga-c630-ec.c new file +4
-0+static int yoga_c630_ec_query_usb_event (struct yoga_c630_ec *ec) +{ +struct device *dev = &ec->client->dev; +int event;
drivers/power/supply/yoga-c630-ec.c line 368
Quoted 10 lines
drivers/power/supply/yoga-c630-ec.c new file +10
-0+ +mutex_lock (&ec->lock); + event =yoga_c630_ec_read8 (ec,LENOVO_EC_QUERY_USB_EVENT ); +mutex_unlock (&ec->lock); +if (event <0 ) { +dev_err (dev,"unable to query USB event\n" ); +return event; + } + +/* FIXME: handle the returned event to set the Type-C properties */
I guess this is more of a TODO than a FIXME? :)
drivers/power/supply/yoga-c630-ec.c line 371
Quoted 3 lines
drivers/power/supply/yoga-c630-ec.c new file +3
-0+ +return 0 ; +}
-- Sebastian
PATCH v2 3/3 arm64: dts: qcom: c630: Add Embedded Controller node
In reply to Dmitry BaryshkovFrom: Bjorn Andersson <[email protected]>
The Embedded Controller in the Lenovo Yoga C630 is accessible on &i2c1 and provides battery and adapter status, as well as altmode notifications for the second USB Type-C port.
Add a definition for the EC.
--- .../boot/dts/qcom/sdm850-lenovo-yoga-c630.dts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+)
arch/arm64/boot/dts/qcom/sdm850-lenovo-yoga-c630.dts +35 -0
@@ -352,6 +352,33 @@ zap-shader { &i2c1 { status = "okay"; clock-frequency = <400000>; + + embedded-controller@70 { + compatible = "lenovo,yoga-c630-ec"; + reg = <0x70>; + + interrupts-extended = <&tlmm 20 IRQ_TYPE_LEVEL_HIGH>; + + pinctrl-names = "default"; + pinctrl-0 = <&ec_int_state>; + + #address-cells = <1>; + #size-cells = <0>; + + connector@0 { + compatible = "usb-c-connector"; + reg = <0>; + power-role = "source"; + data-role = "host"; + }; + + connector@1 { + compatible = "usb-c-connector"; + reg = <1>; + power-role = "source"; + data-role = "host"; + }; + }; }; &i2c3 {
@@ -652,6 +679,14 @@ mode_pin_active: mode-pin-state { input-enable; bias-disable; }; + + ec_int_state: ec-int-state { + pins = "gpio20"; + function = "gpio"; + + input-enable; + bias-disable; + }; }; &uart6 {
Signature · 1 line
2.39.1
Re: [PATCH v2 3/3] arm64: dts: qcom: c630: Add Embedded Controller node
Quoted 54 lines · Dmitry Baryshkov
From: Bjorn Andersson <[email protected]>
The Embedded Controller in the Lenovo Yoga C630 is accessible on &i2c1 and provides battery and adapter status, as well as altmode notifications for the second USB Type-C port.
Add a definition for the EC.
Signed-off-by Bjorn Andersson <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>Signed-off-by Dmitry Baryshkov <[email protected]>--- .../boot/dts/qcom/sdm850-lenovo-yoga-c630.dts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+)arch/arm64/boot/dts/qcom/sdm850-lenovo-yoga-c630.dts +27
-0@@ -352,6 +352,33 @@ zap-shader { &i2c1 { status = "okay"; clock-frequency = <400000>; + + embedded-controller@70 { + compatible = "lenovo,yoga-c630-ec"; + reg = <0x70>; + + interrupts-extended = <&tlmm 20 IRQ_TYPE_LEVEL_HIGH>; + + pinctrl-names = "default"; + pinctrl-0 = <&ec_int_state>; + + #address-cells = <1>; + #size-cells = <0>; + + connector@0 { + compatible = "usb-c-connector"; + reg = <0>; + power-role = "source"; + data-role = "host"; + }; + + connector@1 { + compatible = "usb-c-connector"; + reg = <1>; + power-role = "source"; + data-role = "host"; + }; + }; }; &i2c3 {
arch/arm64/boot/dts/qcom/sdm850-lenovo-yoga-c630.dts mode_pin_active: mode-pin-state { · line 688
Quoted 10 lines
arch/arm64/boot/dts/qcom/sdm850-lenovo-yoga-c630.dts +7
-0@@ -652,6 +679,14 @@ mode_pin_active: mode-pin-state { input-enable; bias-disable; }; + + ec_int_state: ec-int-state { + pins = "gpio20"; + function = "gpio"; + + input-enable; + bias-disable;
Unnecessary newline + most other trees do bias- before input/output-
Other than that
Konrad
Quoted 4 lines
arch/arm64/boot/dts/qcom/sdm850-lenovo-yoga-c630.dts +1
-0+ }; }; &uart6 {