From: Pengyu Luo <mitltlatltl@gmail.com>
To: maccraft123mc@gmail.com
Cc: andersson@kernel.org, bryan.odonoghue@linaro.org,
conor+dt@kernel.org, devicetree@vger.kernel.org,
dmitry.baryshkov@linaro.org, gregkh@linuxfoundation.org,
hdegoede@redhat.com, heikki.krogerus@linux.intel.com,
ilpo.jarvinen@linux.intel.com, konradybcio@kernel.org,
krzk+dt@kernel.org, linux-arm-msm@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
linux-usb@vger.kernel.org, mitltlatltl@gmail.com, nikita@trvn.ru,
platform-driver-x86@vger.kernel.org, robh@kernel.org,
sre@kernel.org
Subject: Re: [PATCH 2/5] platform: arm64: add Huawei Matebook E Go (sc8280xp) EC driver
Date: Sat, 28 Dec 2024 13:42:57 +0800 [thread overview]
Message-ID: <20241228054259.485044-1-mitltlatltl@gmail.com> (raw)
In-Reply-To: <CAO_MupKJyHbEb6RQ0B4gHwPQCrB=NfHJ-odY6R+DaSwOaSfnGw@mail.gmail.com>
On Sat, Dec 28, 2024 at 2:21 AM Maya Matuszczyk <maccraft123mc@gmail.com> wrote:
> Good to see someone else doing EC drivers for arm64 laptops!
>
Yeah, I have worked on it for a while. I really don't know why don't some
mechines use a pmic glink. AFAIK, there are some WOA devices without EC.
Mechines can definitely work without it in a way.
I am also glad that you are reviewing my code.
> pt., 27 gru 2024 o 18:16 Pengyu Luo <mitltlatltl@gmail.com> napisał(a):
> >
> > There are 3 variants, Huawei released first 2 at the same time.
> > Huawei Matebook E Go LTE(sc8180x), codename should be gaokun2.
> > Huawei Matebook E Go(sc8280xp@3.0GHz), codename is gaokun3.
> > Huawei Matebook E Go 2023(sc8280xp@2.69GHz).
> >
> > Adding support for the latter two variants for now, this driver should
> > also work for the sc8180x variant according to acpi table files, but I
> > don't have the device yet.
> >
> > Different from other Qualcomm Snapdragon sc8280xp based machines, the
> > Huawei Matebook E Go uses an embedded controller while others use
> > something called pmic glink. This embedded controller can be used to
> > perform a set of various functions, including, but not limited:
> >
> > - Battery and charger monitoring;
> > - Charge control and smart charge;
> > - Fn_lock settings;
> > - Tablet lid status;
> > - Temperature sensors;
> > - USB Type-C notifications (ports orientation, DP alt mode HPD);
> > - USB Type-C PD (according to observation, up to 48w).
> >
> > Add the driver for the EC, that creates devices for UCSI, wmi and power
> > supply devices.
> >
> > Signed-off-by: Pengyu Luo <mitltlatltl@gmail.com>
> > ---
> > drivers/platform/arm64/Kconfig | 19 +
> > drivers/platform/arm64/Makefile | 2 +
> > drivers/platform/arm64/huawei-gaokun-ec.c | 598 ++++++++++++++++++
> > drivers/platform/arm64/huawei-gaokun-wmi.c | 283 +++++++++
> > .../linux/platform_data/huawei-gaokun-ec.h | 90 +++
> > 5 files changed, 992 insertions(+)
> > create mode 100644 drivers/platform/arm64/huawei-gaokun-ec.c
> > create mode 100644 drivers/platform/arm64/huawei-gaokun-wmi.c
> > create mode 100644 include/linux/platform_data/huawei-gaokun-ec.h
[...]
> > +/* -------------------------------------------------------------------------- */
> > +/* API For PSY */
> > +
> > +int gaokun_ec_psy_multi_read(struct gaokun_ec *ec, u8 reg,
> > + size_t resp_len, u8 *resp)
> > +{
> > + int i, ret;
> > + u8 _resp[RESP_HDR_SIZE + 1];
> > + u8 req[REQ_HDR_SIZE + 1] = {0x02, EC_READ, 1, };
> > +
> > + for (i = 0; i < resp_len; ++i) {
> > + req[INPUT_DATA_OFFSET] = reg++;
> > + ret = gaokun_ec_read(ec, req, sizeof(_resp), _resp);
> > + if (ret)
> > + return -EIO;
> > + resp[i] = _resp[DATA_OFFSET];
> > + }
> > +
> > + return 0;
> > +}
> > +EXPORT_SYMBOL_GPL(gaokun_ec_psy_multi_read);
> > +
> > +/* -------------------------------------------------------------------------- */
> > +/* API For WMI */
> WMI is in ACPI, this laptop doesn't boot with ACPI so why are things
> handled in WMI separate from rest of the driver?
>
This driver reimplemented WMI functoins, and it perform a lot of
operations, to avoid naming it, just call it WMI, make life easier.
Once I considered keeping WMI things in this file, but it makes this file
bloated. Then I splitted every part into a module.
> > +
> > +/* Battery charging threshold */
> > +int gaokun_ec_wmi_get_threshold(struct gaokun_ec *ec, u8 *value, int ind)
> > +{
> > + /* GBTT */
> > + return gaokun_ec_read_byte(ec, (u8 []){0x02, 0x69, 1, ind}, value);
> > +}
> > +EXPORT_SYMBOL_GPL(gaokun_ec_wmi_get_threshold);
> > +
> > +int gaokun_ec_wmi_set_threshold(struct gaokun_ec *ec, u8 start, u8 end)
> > +{
> > + /* SBTT */
> > + int ret;
> > + u8 req[REQ_HDR_SIZE + 2] = {0x02, 0x68, 2, 3, 0x5a};
> > +
> > + ret = gaokun_ec_write(ec, req);
> > + if (ret)
> > + return -EIO;
> > +
> > + if (start == 0 && end == 0)
> > + return -EINVAL;
> > +
> > + if (start >= 0 && start <= end && end <= 100) {
> > + req[INPUT_DATA_OFFSET] = 1;
> > + req[INPUT_DATA_OFFSET + 1] = start;
> > + ret = gaokun_ec_write(ec, req);
> > + if (ret)
> > + return -EIO;
> > +
> > + req[INPUT_DATA_OFFSET] = 2;
> > + req[INPUT_DATA_OFFSET + 1] = end;
> > + ret = gaokun_ec_write(ec, req);
> > + } else {
> > + return -EINVAL;
> > + }
> > +
> > + return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(gaokun_ec_wmi_set_threshold);
[...]
> > +/* -------------------------------------------------------------------------- */
> > +/* EC */
> > +
> > +static irqreturn_t gaokun_ec_irq_handler(int irq, void *data)
> > +{
> > + struct gaokun_ec *ec = data;
> > + u8 req[REQ_HDR_SIZE] = {EC_EVENT, EC_QUERY, 0};
> > + u8 status, id;
> > + int ret;
> > +
> > + ret = gaokun_ec_read_byte(ec, req, &id);
> > + if (ret)
> > + return IRQ_HANDLED;
> The error should probably be logged instead of silently ignored
>
Generally, one or two I/O errors don't crash anything, but actually if we
just do as ACPI methoda did, there should not be any error. It may be
necessary for debugging at the early stage of developemnt. If you suggest,
then we can add a report to the lower function (gaokun_ec_request) to check
every transaction. BTW, lenovo c630 also ignored them.
> > +
> > + switch (id) {
> > + case 0x0: /* No event */
> > + break;
> > +
> > + case EC_EVENT_LID:
> > + gaokun_ec_psy_read_byte(ec, EC_LID_STATE, &status);
> > + status = EC_LID_OPEN & status;
> > + input_report_switch(ec->idev, SW_LID, !status);
> > + input_sync(ec->idev);
> > + break;
> > +
> > + default:
> > + blocking_notifier_call_chain(&ec->notifier_list, id, ec);
> > + }
> > +
> > + return IRQ_HANDLED;
> > +}
> > +
[...]
> > diff --git a/drivers/platform/arm64/huawei-gaokun-wmi.c b/drivers/platform/arm64/huawei-gaokun-wmi.c
> > new file mode 100644
> > index 000000000..793cb1659
> > --- /dev/null
> > +++ b/drivers/platform/arm64/huawei-gaokun-wmi.c
> > @@ -0,0 +1,283 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * huawei-gaokun-wmi - A WMI driver for HUAWEI Matebook E Go (sc8280xp)
> Just because in ACPI it's done by WMI stuff doesn't mean the non-ACPI
> driver has to reflect this
>
As I just said, and the WMI stuffs are all implemented by wrapping a EC
transaction in ACPI, at least in this machine.
> > + *
> > + * reference: drivers/platform/x86/huawei-wmi.c
> > + *
> > + * Copyright (C) 2024 Pengyu Luo <mitltlatltl@gmail.com>
> > + */
> > +
> > +#include <linux/auxiliary_bus.h>
> > +#include <linux/module.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/sysfs.h>
> > +#include <linux/version.h>
> > +
> > +#include <linux/platform_data/huawei-gaokun-ec.h>
> > +
> >
[...]
> >
>
> Best Regards,
> Maya Matuszczyk
Best Wishes,
Pengyu
next prev parent reply other threads:[~2024-12-28 5:44 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-27 17:13 [PATCH 0/5] platform: arm64: Huawei Matebook E Go embedded controller Pengyu Luo
2024-12-27 17:13 ` [PATCH 1/5] dt-bindings: platform: Add Huawei Matebook E Go EC Pengyu Luo
2024-12-27 18:18 ` Rob Herring (Arm)
2024-12-28 9:54 ` Krzysztof Kozlowski
2024-12-28 10:50 ` Pengyu Luo
2024-12-29 9:50 ` Krzysztof Kozlowski
2024-12-29 10:12 ` Pengyu Luo
2024-12-30 7:28 ` Aiqun(Maria) Yu
2024-12-30 7:35 ` Krzysztof Kozlowski
2024-12-30 9:10 ` Aiqun(Maria) Yu
2024-12-30 8:00 ` Pengyu Luo
2025-01-01 5:57 ` Pengyu Luo
2024-12-27 17:13 ` [PATCH 2/5] platform: arm64: add Huawei Matebook E Go (sc8280xp) EC driver Pengyu Luo
2024-12-27 18:21 ` Maya Matuszczyk
2024-12-28 5:42 ` Pengyu Luo [this message]
2024-12-28 9:58 ` Krzysztof Kozlowski
2024-12-28 11:34 ` [PATCH 1/5] dt-bindings: platform: Add Huawei Matebook E Go EC Pengyu Luo
2024-12-29 4:08 ` Dmitry Baryshkov
2024-12-29 9:04 ` [PATCH 2/5] platform: arm64: add Huawei Matebook E Go (sc8280xp) EC driver Pengyu Luo
2024-12-29 9:44 ` Krzysztof Kozlowski
2024-12-29 9:43 ` [PATCH 1/5] dt-bindings: platform: Add Huawei Matebook E Go EC Krzysztof Kozlowski
2024-12-29 10:28 ` Pengyu Luo
2024-12-29 21:45 ` Krzysztof Kozlowski
2024-12-28 12:33 ` [PATCH 2/5] platform: arm64: add Huawei Matebook E Go (sc8280xp) EC driver Bryan O'Donoghue
2024-12-28 13:51 ` Pengyu Luo
2024-12-29 15:32 ` Ilpo Järvinen
2024-12-29 15:55 ` Pengyu Luo
2024-12-29 14:49 ` Markus Elfring
2024-12-30 9:04 ` Aiqun(Maria) Yu
2024-12-30 10:44 ` Pengyu Luo
2024-12-31 5:00 ` Aiqun(Maria) Yu
2024-12-31 7:44 ` Pengyu Luo
2024-12-31 11:09 ` Bryan O'Donoghue
2025-01-03 5:38 ` Dmitry Baryshkov
2025-01-03 7:19 ` Pengyu Luo
2025-01-01 11:27 ` Pengyu Luo
2024-12-27 17:13 ` [PATCH 3/5] usb: typec: ucsi: add Huawei Matebook E Go (sc8280xp) ucsi driver Pengyu Luo
2024-12-28 13:06 ` Bryan O'Donoghue
2024-12-28 14:38 ` Pengyu Luo
2024-12-29 14:51 ` Bryan O'Donoghue
2024-12-29 16:25 ` Pengyu Luo
2024-12-29 4:40 ` Dmitry Baryshkov
2024-12-29 9:05 ` Pengyu Luo
2025-01-06 3:33 ` Dmitry Baryshkov
2025-01-06 9:20 ` [PATCH 1/5] dt-bindings: platform: Add Huawei Matebook E Go EC Pengyu Luo
2025-01-06 9:22 ` [PATCH 3/5] usb: typec: ucsi: add Huawei Matebook E Go (sc8280xp) ucsi driver Pengyu Luo
2024-12-29 16:15 ` Markus Elfring
2024-12-27 17:13 ` [PATCH 4/5] power: supply: add Huawei Matebook E Go (sc8280xp) psy driver Pengyu Luo
2024-12-27 17:13 ` [PATCH 5/5] arm64: dts: qcom: gaokun3: Add Embedded Controller node Pengyu Luo
2024-12-30 14:53 ` Konrad Dybcio
2024-12-30 16:22 ` Pengyu Luo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241228054259.485044-1-mitltlatltl@gmail.com \
--to=mitltlatltl@gmail.com \
--cc=andersson@kernel.org \
--cc=bryan.odonoghue@linaro.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.baryshkov@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=heikki.krogerus@linux.intel.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=maccraft123mc@gmail.com \
--cc=nikita@trvn.ru \
--cc=platform-driver-x86@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sre@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox