From: Pengyu Luo <mitltlatltl@gmail.com>
To: bryan.odonoghue@linaro.org
Cc: andersson@kernel.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 3/5] usb: typec: ucsi: add Huawei Matebook E Go (sc8280xp) ucsi driver
Date: Mon, 30 Dec 2024 00:25:40 +0800 [thread overview]
Message-ID: <20241229162540.95754-1-mitltlatltl@gmail.com> (raw)
In-Reply-To: <5310962f-c0d8-4ada-bb95-b727a3c88b00@linaro.org>
On Sun, Dec 29, 2024 at 10:52 PM Bryan O'Donoghue <bryan.odonoghue@linaro.org> wrote:
> On 28/12/2024 14:38, Pengyu Luo wrote:
> > On Sat, Dec 28, 2024 at 9:06 PM Bryan O'Donoghue <bryan.odonoghue@linaro.org> wrote:
> >> On 27/12/2024 17:13, Pengyu Luo wrote:
> >>> The Huawei Matebook E Go (sc8280xp) tablet provides implements UCSI
> >>> interface in the onboard EC. Add the glue driver to interface the
> >>> platform's UCSI implementation.
> >>>
> >>> Signed-off-by: Pengyu Luo <mitltlatltl@gmail.com>
> >>> ---
> >>> drivers/usb/typec/ucsi/Kconfig | 9 +
> >>> drivers/usb/typec/ucsi/Makefile | 1 +
> >>> drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 481 ++++++++++++++++++++
> >>> 3 files changed, 491 insertions(+)
> >>> create mode 100644 drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c
> >>>
> >>> diff --git a/drivers/usb/typec/ucsi/Kconfig b/drivers/usb/typec/ucsi/Kconfig
> >>> index 680e1b87b..0d0f07488 100644
> >>> --- a/drivers/usb/typec/ucsi/Kconfig
> >>> +++ b/drivers/usb/typec/ucsi/Kconfig
> >>> @@ -78,4 +78,13 @@ config UCSI_LENOVO_YOGA_C630
> >>> To compile the driver as a module, choose M here: the module will be
> >>> called ucsi_yoga_c630.
> >>>
> >>> +config UCSI_HUAWEI_GAOKUN
> >>> + tristate "UCSI Interface Driver for Huawei Matebook E Go (sc8280xp)"
> >>> + depends on EC_HUAWEI_GAOKUN
> >>> + help
> >>> + This driver enables UCSI support on the Huawei Matebook E Go tablet.
> >>> +
> >>> + To compile the driver as a module, choose M here: the module will be
> >>> + called ucsi_huawei_gaokun.
> >>> +
> >>> endif
> >>> diff --git a/drivers/usb/typec/ucsi/Makefile b/drivers/usb/typec/ucsi/Makefile
> >>> index aed41d238..0b400122b 100644
> >>> --- a/drivers/usb/typec/ucsi/Makefile
> >>> +++ b/drivers/usb/typec/ucsi/Makefile
> >>> @@ -22,3 +22,4 @@ obj-$(CONFIG_UCSI_CCG) += ucsi_ccg.o
> >>> obj-$(CONFIG_UCSI_STM32G0) += ucsi_stm32g0.o
> >>> obj-$(CONFIG_UCSI_PMIC_GLINK) += ucsi_glink.o
> >>> obj-$(CONFIG_UCSI_LENOVO_YOGA_C630) += ucsi_yoga_c630.o
> >>> +obj-$(CONFIG_UCSI_HUAWEI_GAOKUN) += ucsi_huawei_gaokun.o
> >>> diff --git a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c
> >>> new file mode 100644
> >>> index 000000000..84ed0407d
> >>> --- /dev/null
> >>> +++ b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c
> >>> @@ -0,0 +1,481 @@
> >>> +// SPDX-License-Identifier: GPL-2.0-only
> >>> +/*
> >>> + * ucsi-huawei-gaokun - A UCSI driver for HUAWEI Matebook E Go (sc8280xp)
> >>> + *
> >>> + * reference: drivers/usb/typec/ucsi/ucsi_yoga_c630.c
> >>> + * drivers/usb/typec/ucsi/ucsi_glink.c
> >>> + * drivers/soc/qcom/pmic_glink_altmode.c
> >>> + *
> >>> + * Copyright (C) 2024 Pengyu Luo <mitltlatltl@gmail.com>
> >>> + */
> >>> +
> >>> +#include <linux/auxiliary_bus.h>
> >>> +#include <linux/bitops.h>
> >>> +#include <linux/completion.h>
> >>> +#include <linux/container_of.h>
> >>> +#include <linux/delay.h>
> >>> +#include <linux/module.h>
> >>> +#include <linux/notifier.h>
> >>> +#include <linux/of.h>
> >>> +#include <linux/string.h>
> >>> +#include <linux/workqueue_types.h>
> >>> +
> >>> +#include <linux/usb/pd_vdo.h>
> >>> +#include <drm/bridge/aux-bridge.h
> >>
> >> Is there a reason you don't have strict include alphanumeric ordering here ?
> >>
> >
> > These two is dp/alt mode related, so listing them out. Above of them are
> > general things.
>
> OK. Unless there's an include dependency reason you need to, please just
> sort the headers alphanumerically in order
>
> #include <globals_first>
> #include <globals_first_alpha>
>
> #include "locals_next"
> #include "locals_next_alpha_also"
>
I will follow this in v2.
> >>>
> >>> +
> >>> +#include "ucsi.h"
> >>> +#include <linux/platform_data/huawei-gaokun-ec.h>
> >>> +
> >>> +
> >>> +#define EC_EVENT_UCSI 0x21
> >>> +#define EC_EVENT_USB 0x22
> >>> +
> >>> +#define GAOKUN_CCX_MASK GENMASK(1, 0)
> >>> +#define GAOKUN_MUX_MASK GENMASK(3, 2)
> >>> +
> >>> +#define GAOKUN_DPAM_MASK GENMASK(3, 0)
> >>> +#define GAOKUN_HPD_STATE_MASK BIT(4)
> >>> +#define GAOKUN_HPD_IRQ_MASK BIT(5)
> >>> +
> >>> +#define CCX_TO_ORI(ccx) (++ccx % 3)
> >>
> >> Why do you increment the value of the enum ?
> >> Seems strange.
> >>
> >
> > EC's logic, it is just a trick. Qualcomm maps
> > 0 1 2 to normal, reverse, none(no device insert)
> > typec lib maps 1 2 0 to that.
>
> I'd suggest making the trick much more obvious.
>
> Either with a comment or just mapping 1:1 between EC and Linux' view of
> this data.
>
> The main reason for that is to make it easier to
> read/understand/maintain/debug.
>
I got it
>
>
> >>> + port->svid = USB_SID_DISPLAYPORT;
> >>> + if (port->ccx == USBC_CCX_REVERSE)
> >>> + port->mode -= 6;
> >>
> >> why minus six ?
> >> needs a comment.
> >>
> >
> > EC's logic. I don't know why, it is a quirk from Qualcomm or Huawei.
> > I will mention this.
>
> Instead of hard-coding a mapping between the EC's mode and Linux' UCSI
> enum - just make a define or an inline, ideally something with
>
> switch(port->mode)
> case GOAKUN_MODE_0:
> val = LINUX_UCSI_MODE_X;
> case GOAKUN_MODE_1:
> val = LINUX_UCSI_MODE_Y;
> }
>
> That will make the mapping obvious and also ensure both to yourself and
> to your reviewers that you have accounted for _all_ of the potential
> mappings and if those mappings don't exist then the default: of your
> switch statement should make some noise about it
>
> dev_err(dev, "GOKUN UCSI mode %d unmapped\n"); or something like that.
>
Makes sense
>
> >
> >>> + break;
> >>> + default:
> >>> + break;
> >>> + }
> >>> +
> >>> + spin_unlock_irqrestore(&port->lock, flags);
> >>> +}
> >>> +
> >>> +static int gaokun_ucsi_refresh(struct gaokun_ucsi *uec)
> >>> +{
> >>> + struct gaokun_ucsi_reg ureg;
> >>> + int ret, idx;
> >>> +
> >>> + ret = gaokun_ec_ucsi_get_reg(uec->ec, (u8 *)&ureg);
> >>> + if (ret)
> >>> + return -EIO;
> >>> +
> >>> + uec->port_num = ureg.port_num;
> >>> + idx = GET_IDX(ureg.port_updt);
> >>> +
> >>> + if (idx >= 0 && idx < ureg.port_num)
> >>> + gaokun_ucsi_port_update(&uec->ports[idx], ureg.port_data);
> >>
> >> Since you are checking the validity of the index, you should -EINVAL if
> >> the index is out of range.
> >>
> >
> > EC / pmic glink encode every port in a bit
> > 0/1/2/4/... => ???/left/right/some port
> >
> > I remap it to -1/0/1/2, to access specific port exceptions(-1) are not
> > harmful, later in gaokun_ucsi_altmode_notify_ind
> >
> > if (idx < 0)
> > gaokun_ec_ucsi_pan_ack(uec->ec, idx);
> > else
> > gaokun_ucsi_handle_altmode(&uec->ports[idx]);
> >
> > gaokun_ec_ucsi_pan_ack can handle exceptions.
> >
>
> gaokun_ucsi_refresh() can return
>
> -EIO
> -1
> >=0
>
> Where -EIO and -1 both trigger gaokun_ec_ucsi_pan_ack() in
> gaokun_ucsi_altmode_notify_ind()
>
> So if the index doesn't matter and < 0 => pan_ack() is OK or -EIO is not
> returning meaningful error.
>
> Either way strongly advise against mixing a negative index as having a
> valid meaning with actual -E error codes...
>
> As a reviewer doing a fist-pass this looks suspicous and implies more
> thought/refinement should be done to the flow.
>
Agree, I will drop -EIO to use -1 instead, and define -1 as NO_UPDATE.
It is also resonable when there is a EC transaction error.
Best wishes,
Pengyu
next prev parent reply other threads:[~2024-12-29 16:26 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
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 [this message]
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=20241229162540.95754-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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.