* [PATCH v12 0/2] usb: typec: Implement UCSI driver for ChromeOS
@ 2024-12-31 13:10 Łukasz Bartosik
2024-12-31 13:10 ` [PATCH v12 1/2] platform/chrome: Update ChromeOS EC header for UCSI Łukasz Bartosik
2024-12-31 13:10 ` [PATCH v12 2/2] usb: typec: ucsi: Implement ChromeOS UCSI driver Łukasz Bartosik
0 siblings, 2 replies; 10+ messages in thread
From: Łukasz Bartosik @ 2024-12-31 13:10 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman, Benson Leung,
Dmitry Baryshkov
Cc: Abhishek Pandit-Subedi, Jameson Thies, Pavan Holla, Tzung-Bi Shih,
linux-usb, chrome-platform
This series implements a UCSI ChromeOS EC transport driver.
The ChromeOS EC is expected to implement UCSI Platform Policy
Manager (PPM).
---
Changes in v12:
- Fixed passing of cmd argument (from '&cmd' to 'cmd) to cros_ucsi_async_control()
which caused compilation failure. Verified also that all compilation
failures reported by the 0-Day CI passed:
https://lore.kernel.org/linux-usb/202412240743.tzTftk4H-lkp@intel.com/
https://lore.kernel.org/linux-usb/202412240903.xAqTOQpa-lkp@intel.com/
https://lore.kernel.org/linux-usb/202412241137.ld79A9Iq-lkp@intel.com/
-Link to v11: https://lore.kernel.org/linux-usb/20241210144527.1657888-1-ukaszb@chromium.org/
Changes in v11:
- Updated cancel_delayed_work() to cancel_delayed_work_sync() in both
cros_ucsi_suspend() and cros_ucsi_destroy() in order to wait for delayed
work to finish if it is running.
- Link to v10: https://lore.kernel.org/linux-usb/20241204194900.371696-1-ukaszb@chromium.org/
Changes in v10:
- Added cancel_delayed_work() in the cros_ucsi_suspend() in order
to prevent premature wake up during suspend.
- Added cancel_delayed_work() in the cros_ucsi_destroy() as well.
- Link to v9: https://lore.kernel.org/linux-usb/20241203142314.3892422-1-ukaszb@chromium.org/
Changes in v9:
- Squash "usb: typec: cros_ec_ucsi: Recover from write timeouts" commit
into "usb: typec: ucsi: Implement ChromeOS UCSI driver".
- Replaced out label in cros_ucsi_sync_control() with switch statement.
- Link to v8: https://lore.kernel.org/linux-usb/20241128232035.1525978-1-ukaszb@chromium.org/
Changes in v8:
- Set .sync_control in cros_ucsi_ops struct to point
to ucsi_sync_control_common().
- Added explanation why complete() is used instead of resume()
in cros_ucsi_pm_ops struct.
- Updated s/miliseconds/milliseconds/.
- Link to v7: https://lore.kernel.org/linux-usb/20241115155234.1587589-1-ukaszb@chromium.org/
Changes in v7:
- Dropped the following commits for now as I want to focus
on upstreaming cros_ec_ucsi driver first. Then I will get
back to the topic of trace events and netlink:
"usb: typec: cros_ec_ucsi: Add trace events"
"usb: typec: cros_ec_ucsi: Add netlink"
- Squashed "usb: typec: cros_ec_ucsi: Use complete instead of resume"
into "usb: typec: ucsi: Implement ChromeOS UCSI driver".
- Added "usb: typec: cros_ec_ucsi: Recover from write timeouts" commmit.
- Added usage of common functins ucsi_sync_control_common()
and ucsi_notify_common().
- Commits:
"platform/chrome: Update EC feature flags"
"mfd: cros_ec: Load cros_ec_ucsi on supported ECs"
"mfd: cros_ec: Don't load charger with UCSI"
landed in the tree https://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git/log/?h=for-mfd-next
- Link to v6: https://lore.kernel.org/linux-usb/20240910101527.603452-1-ukaszb@chromium.org
Changes in v6:
- Reverted to type names uint*_t in cros_ec_commands.h in order
to be consistent with type names used in other parts of the file.
- Updated comments in cros_ec_commands.h related to UCSI.
- Added missing sign-offs.
- Fixed memory leak in cros_ucsi_async_control() by moving
ec_params_ucsi_ppm_set request buffer to stack.
- Replaced cros_ucsi_read with cros_ucsi_read_cci in cros_ucsi_work().
- Updated changes in v5, it was missing information related to
commits addition:
platform/chrome: Update EC feature flags
usb: typec: cros_ec_ucsi: Use complete instead of resume
mfd: cros_ec: Load cros_ec_ucsi on supported ECs
mfd: cros_ec: Don't load charger with UCSI
- Link to v5: https://lore.kernel.org/r/all/20240903163033.3170815-1-ukaszb@chromium.org/
Changes in v5:
- Increased WRITE_TMO_MS to 5000.
- Replaced DRV_NAME with KBUILD_MODNAME.
- Added comments for WRITE_TMO_MS and MAX_EC_DATA_SIZE defines.
- Refactored cros_ucsi_async_control() to dynamically allocate memory
for a message to EC instead of allocating the message on stack.
- Replaced type names uint*_t with u*.
- Removed ret variable in cros_ucsi_work().
- Updated ucsi_operations interface to align with changes introduced in
v6.11.
- Replaced test_bit() with test_and_clear_bit() in cros_ucsi_work().
- Updated EC feature flags in commit "platform/chrome: Update EC feature
flags".
- Added new commit "usb: typec: cros_ec_ucsi: Use complete instead
of resume".
- Added trace events in commit "usb: typec: cros_ec_ucsi: Add trace
events".
- Added netlink in commit "usb: typec: cros_ec_ucsi: Add netlink"
for debugging and testing puropses.
- Added new commit "mfd: cros_ec: Load cros_ec_ucsi on supported ECs".
- Added new commit "mfd: cros_ec: Don't load charger with UCSI".
- Link to v4: https://lore.kernel.org/all/CAB2FV=6We88NrvN8NZYt8NkMFH9N_ZBGyUWVUpGwPdja2X_+NA@mail.gmail.com/T/
Changes in v4:
- Setup notifications before calling ucsi_register.
- Cancel work before destroying driver data.
- Link to v3: https://lore.kernel.org/r/20240403-public-ucsi-h-v3-0-f848e18c8ed2@chromium.org
Changes in v3:
- Moved driver from platform/chrome to usb/typec/ucsi.
- Used id_table instead of MODULE_ALIAS.
- Split EC header changes into seperate commit.
- Fixes from additional internal reviews and kernel bot warnings.
- Link to v2: https://lore.kernel.org/r/20240325-public-ucsi-h-v2-0-a6d716968bb1@chromium.org
Changes in v2:
- No code or commit message changes.
- Added drivers/platform/chrome maintainers for review.
Pavan Holla (2):
platform/chrome: Update ChromeOS EC header for UCSI
usb: typec: ucsi: Implement ChromeOS UCSI driver
MAINTAINERS | 7 +
drivers/usb/typec/ucsi/Kconfig | 13 +
drivers/usb/typec/ucsi/Makefile | 1 +
drivers/usb/typec/ucsi/cros_ec_ucsi.c | 337 ++++++++++++++++++
.../linux/platform_data/cros_ec_commands.h | 28 +-
5 files changed, 385 insertions(+), 1 deletion(-)
create mode 100644 drivers/usb/typec/ucsi/cros_ec_ucsi.c
--
2.47.1.613.gc27f4b7a9f-goog
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v12 1/2] platform/chrome: Update ChromeOS EC header for UCSI
2024-12-31 13:10 [PATCH v12 0/2] usb: typec: Implement UCSI driver for ChromeOS Łukasz Bartosik
@ 2024-12-31 13:10 ` Łukasz Bartosik
2025-01-03 23:34 ` [PATCH] driver/platform/chrome: Update cros_ec_trace with new USCI commands Gwendal Grignou
2024-12-31 13:10 ` [PATCH v12 2/2] usb: typec: ucsi: Implement ChromeOS UCSI driver Łukasz Bartosik
1 sibling, 1 reply; 10+ messages in thread
From: Łukasz Bartosik @ 2024-12-31 13:10 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman, Benson Leung,
Dmitry Baryshkov
Cc: Abhishek Pandit-Subedi, Jameson Thies, Pavan Holla, Tzung-Bi Shih,
linux-usb, chrome-platform
From: Pavan Holla <pholla@chromium.org>
Add EC host commands for reading and writing UCSI structures
in the EC. The corresponding kernel driver is cros-ec-ucsi.
Also update PD events supported by the EC.
Acked-by: Tzung-Bi Shih <tzungbi@kernel.org>
Signed-off-by: Pavan Holla <pholla@chromium.org>
Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
---
.../linux/platform_data/cros_ec_commands.h | 28 ++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h
index b3c4993e656e..ecf290a0c98f 100644
--- a/include/linux/platform_data/cros_ec_commands.h
+++ b/include/linux/platform_data/cros_ec_commands.h
@@ -5044,8 +5044,11 @@ struct ec_response_pd_status {
#define PD_EVENT_POWER_CHANGE BIT(1)
#define PD_EVENT_IDENTITY_RECEIVED BIT(2)
#define PD_EVENT_DATA_SWAP BIT(3)
+#define PD_EVENT_TYPEC BIT(4)
+#define PD_EVENT_PPM BIT(5)
+
struct ec_response_host_event_status {
- uint32_t status; /* PD MCU host event status */
+ uint32_t status; /* PD MCU host event status */
} __ec_align4;
/* Set USB type-C port role and muxes */
@@ -6105,6 +6108,29 @@ struct ec_response_typec_vdm_response {
#undef VDO_MAX_SIZE
+/*
+ * UCSI OPM-PPM commands
+ *
+ * These commands are used for communication between OPM and PPM.
+ * Only UCSI3.0 is tested.
+ */
+
+#define EC_CMD_UCSI_PPM_SET 0x0140
+
+/* The data size is stored in the host command protocol header. */
+struct ec_params_ucsi_ppm_set {
+ uint16_t offset;
+ uint8_t data[];
+} __ec_align2;
+
+#define EC_CMD_UCSI_PPM_GET 0x0141
+
+/* For 'GET' sub-commands, data will be returned as a raw payload. */
+struct ec_params_ucsi_ppm_get {
+ uint16_t offset;
+ uint8_t size;
+} __ec_align2;
+
/*****************************************************************************/
/* The command range 0x200-0x2FF is reserved for Rotor. */
--
2.47.1.613.gc27f4b7a9f-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v12 2/2] usb: typec: ucsi: Implement ChromeOS UCSI driver
2024-12-31 13:10 [PATCH v12 0/2] usb: typec: Implement UCSI driver for ChromeOS Łukasz Bartosik
2024-12-31 13:10 ` [PATCH v12 1/2] platform/chrome: Update ChromeOS EC header for UCSI Łukasz Bartosik
@ 2024-12-31 13:10 ` Łukasz Bartosik
2025-01-07 10:28 ` Heikki Krogerus
1 sibling, 1 reply; 10+ messages in thread
From: Łukasz Bartosik @ 2024-12-31 13:10 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman, Benson Leung,
Dmitry Baryshkov
Cc: Abhishek Pandit-Subedi, Jameson Thies, Pavan Holla, Tzung-Bi Shih,
linux-usb, chrome-platform
From: Pavan Holla <pholla@chromium.org>
Implementation of a UCSI transport driver for ChromeOS.
This driver will be loaded if the ChromeOS EC implements a PPM.
Signed-off-by: Pavan Holla <pholla@chromium.org>
Co-developed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
Co-developed-by: Łukasz Bartosik <ukaszb@chromium.org>
Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
---
MAINTAINERS | 7 +
drivers/usb/typec/ucsi/Kconfig | 13 +
drivers/usb/typec/ucsi/Makefile | 1 +
drivers/usb/typec/ucsi/cros_ec_ucsi.c | 337 ++++++++++++++++++++++++++
4 files changed, 358 insertions(+)
create mode 100644 drivers/usb/typec/ucsi/cros_ec_ucsi.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 910305c11e8a..0f2ee59540a9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5454,6 +5454,13 @@ L: chrome-platform@lists.linux.dev
S: Maintained
F: drivers/watchdog/cros_ec_wdt.c
+CHROMEOS UCSI DRIVER
+M: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
+M: Łukasz Bartosik <ukaszb@chromium.org>
+L: chrome-platform@lists.linux.dev
+S: Maintained
+F: drivers/usb/typec/ucsi/cros_ec_ucsi.c
+
CHRONTEL CH7322 CEC DRIVER
M: Joe Tessler <jrt@google.com>
L: linux-media@vger.kernel.org
diff --git a/drivers/usb/typec/ucsi/Kconfig b/drivers/usb/typec/ucsi/Kconfig
index 680e1b87b152..75559601fe8f 100644
--- a/drivers/usb/typec/ucsi/Kconfig
+++ b/drivers/usb/typec/ucsi/Kconfig
@@ -69,6 +69,19 @@ config UCSI_PMIC_GLINK
To compile the driver as a module, choose M here: the module will be
called ucsi_glink.
+config CROS_EC_UCSI
+ tristate "UCSI Driver for ChromeOS EC"
+ depends on MFD_CROS_EC_DEV
+ depends on CROS_USBPD_NOTIFY
+ depends on !EXTCON_TCSS_CROS_EC
+ default MFD_CROS_EC_DEV
+ help
+ This driver enables UCSI support for a ChromeOS EC. The EC is
+ expected to implement a PPM.
+
+ To compile the driver as a module, choose M here: the module
+ will be called cros_ec_ucsi.
+
config UCSI_LENOVO_YOGA_C630
tristate "UCSI Interface Driver for Lenovo Yoga C630"
depends on EC_LENOVO_YOGA_C630
diff --git a/drivers/usb/typec/ucsi/Makefile b/drivers/usb/typec/ucsi/Makefile
index aed41d23887b..be98a879104d 100644
--- a/drivers/usb/typec/ucsi/Makefile
+++ b/drivers/usb/typec/ucsi/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_UCSI_ACPI) += ucsi_acpi.o
obj-$(CONFIG_UCSI_CCG) += ucsi_ccg.o
obj-$(CONFIG_UCSI_STM32G0) += ucsi_stm32g0.o
obj-$(CONFIG_UCSI_PMIC_GLINK) += ucsi_glink.o
+obj-$(CONFIG_CROS_EC_UCSI) += cros_ec_ucsi.o
obj-$(CONFIG_UCSI_LENOVO_YOGA_C630) += ucsi_yoga_c630.o
diff --git a/drivers/usb/typec/ucsi/cros_ec_ucsi.c b/drivers/usb/typec/ucsi/cros_ec_ucsi.c
new file mode 100644
index 000000000000..db8324b71ee9
--- /dev/null
+++ b/drivers/usb/typec/ucsi/cros_ec_ucsi.c
@@ -0,0 +1,337 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * UCSI driver for ChromeOS EC
+ *
+ * Copyright 2024 Google LLC.
+ */
+
+#include <linux/container_of.h>
+#include <linux/dev_printk.h>
+#include <linux/jiffies.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_data/cros_ec_commands.h>
+#include <linux/platform_data/cros_usbpd_notify.h>
+#include <linux/platform_data/cros_ec_proto.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/wait.h>
+
+#include "ucsi.h"
+
+/*
+ * Maximum size in bytes of a UCSI message between AP and EC
+ */
+#define MAX_EC_DATA_SIZE 256
+
+/*
+ * Maximum time in milliseconds the cros_ec_ucsi driver
+ * will wait for a response to a command or and ack.
+ */
+#define WRITE_TMO_MS 5000
+
+/* Number of times to attempt recovery from a write timeout before giving up. */
+#define WRITE_TMO_CTR_MAX 5
+
+struct cros_ucsi_data {
+ struct device *dev;
+ struct ucsi *ucsi;
+
+ struct cros_ec_device *ec;
+ struct notifier_block nb;
+ struct work_struct work;
+ struct delayed_work write_tmo;
+ int tmo_counter;
+
+ struct completion complete;
+ unsigned long flags;
+};
+
+static int cros_ucsi_read(struct ucsi *ucsi, unsigned int offset, void *val,
+ size_t val_len)
+{
+ struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi);
+ struct ec_params_ucsi_ppm_get req = {
+ .offset = offset,
+ .size = val_len,
+ };
+ int ret;
+
+ if (val_len > MAX_EC_DATA_SIZE) {
+ dev_err(udata->dev, "Can't read %zu bytes. Too big.", val_len);
+ return -EINVAL;
+ }
+
+ ret = cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_GET,
+ &req, sizeof(req), val, val_len);
+ if (ret < 0) {
+ dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_GET: error=%d", ret);
+ return ret;
+ }
+ return 0;
+}
+
+static int cros_ucsi_read_version(struct ucsi *ucsi, u16 *version)
+{
+ return cros_ucsi_read(ucsi, UCSI_VERSION, version, sizeof(*version));
+}
+
+static int cros_ucsi_read_cci(struct ucsi *ucsi, u32 *cci)
+{
+ return cros_ucsi_read(ucsi, UCSI_CCI, cci, sizeof(*cci));
+}
+
+static int cros_ucsi_read_message_in(struct ucsi *ucsi, void *val,
+ size_t val_len)
+{
+ return cros_ucsi_read(ucsi, UCSI_MESSAGE_IN, val, val_len);
+}
+
+static int cros_ucsi_async_control(struct ucsi *ucsi, u64 cmd)
+{
+ struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi);
+ u8 ec_buf[sizeof(struct ec_params_ucsi_ppm_set) + sizeof(cmd)];
+ struct ec_params_ucsi_ppm_set *req = (struct ec_params_ucsi_ppm_set *) ec_buf;
+ int ret;
+
+ req->offset = UCSI_CONTROL;
+ memcpy(req->data, &cmd, sizeof(cmd));
+ ret = cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_SET,
+ req, sizeof(ec_buf), NULL, 0);
+ if (ret < 0) {
+ dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_SET: error=%d", ret);
+ return ret;
+ }
+ return 0;
+}
+
+static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd)
+{
+ struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi);
+ int ret;
+
+ ret = ucsi_sync_control_common(ucsi, cmd);
+ switch (ret) {
+ case -EBUSY:
+ /* EC may return -EBUSY if CCI.busy is set.
+ * Convert this to a timeout.
+ */
+ case -ETIMEDOUT:
+ /* Schedule recovery attempt when we timeout
+ * or tried to send a command while still busy.
+ */
+ cancel_delayed_work_sync(&udata->write_tmo);
+ schedule_delayed_work(&udata->write_tmo,
+ msecs_to_jiffies(WRITE_TMO_MS));
+ break;
+ case 0:
+ /* Successful write. Cancel any pending recovery work. */
+ cancel_delayed_work_sync(&udata->write_tmo);
+ break;
+ }
+
+ return ret;
+}
+
+struct ucsi_operations cros_ucsi_ops = {
+ .read_version = cros_ucsi_read_version,
+ .read_cci = cros_ucsi_read_cci,
+ .read_message_in = cros_ucsi_read_message_in,
+ .async_control = cros_ucsi_async_control,
+ .sync_control = cros_ucsi_sync_control,
+};
+
+static void cros_ucsi_work(struct work_struct *work)
+{
+ struct cros_ucsi_data *udata = container_of(work, struct cros_ucsi_data, work);
+ u32 cci;
+
+ if (cros_ucsi_read_cci(udata->ucsi, &cci))
+ return;
+
+ ucsi_notify_common(udata->ucsi, cci);
+}
+
+static void cros_ucsi_write_timeout(struct work_struct *work)
+{
+ struct cros_ucsi_data *udata =
+ container_of(work, struct cros_ucsi_data, write_tmo.work);
+ u32 cci;
+ u64 cmd;
+
+ if (cros_ucsi_read(udata->ucsi, UCSI_CCI, &cci, sizeof(cci))) {
+ dev_err(udata->dev,
+ "Reading CCI failed; no write timeout recovery possible.");
+ return;
+ }
+
+ if (cci & UCSI_CCI_BUSY) {
+ udata->tmo_counter++;
+
+ if (udata->tmo_counter <= WRITE_TMO_CTR_MAX)
+ schedule_delayed_work(&udata->write_tmo,
+ msecs_to_jiffies(WRITE_TMO_MS));
+ else
+ dev_err(udata->dev,
+ "PPM unresponsive - too many write timeouts.");
+
+ return;
+ }
+
+ /* No longer busy means we can reset our timeout counter. */
+ udata->tmo_counter = 0;
+
+ /* Need to ack previous command which may have timed out. */
+ if (cci & UCSI_CCI_COMMAND_COMPLETE) {
+ cmd = UCSI_ACK_CC_CI | UCSI_ACK_COMMAND_COMPLETE;
+ cros_ucsi_async_control(udata->ucsi, cmd);
+
+ /* Check again after a few seconds that the system has
+ * recovered to make sure our async write above was successful.
+ */
+ schedule_delayed_work(&udata->write_tmo,
+ msecs_to_jiffies(WRITE_TMO_MS));
+ return;
+ }
+
+ /* We recovered from a previous timeout. Treat this as a recovery from
+ * suspend and call resume.
+ */
+ ucsi_resume(udata->ucsi);
+}
+
+static int cros_ucsi_event(struct notifier_block *nb,
+ unsigned long host_event, void *_notify)
+{
+ struct cros_ucsi_data *udata = container_of(nb, struct cros_ucsi_data, nb);
+
+ if (!(host_event & PD_EVENT_PPM))
+ return NOTIFY_OK;
+
+ dev_dbg(udata->dev, "UCSI notification received");
+ flush_work(&udata->work);
+ schedule_work(&udata->work);
+
+ return NOTIFY_OK;
+}
+
+static void cros_ucsi_destroy(struct cros_ucsi_data *udata)
+{
+ cros_usbpd_unregister_notify(&udata->nb);
+ cancel_delayed_work_sync(&udata->write_tmo);
+ cancel_work_sync(&udata->work);
+ ucsi_destroy(udata->ucsi);
+}
+
+static int cros_ucsi_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct cros_ec_dev *ec_data = dev_get_drvdata(dev->parent);
+ struct cros_ucsi_data *udata;
+ int ret;
+
+ udata = devm_kzalloc(dev, sizeof(*udata), GFP_KERNEL);
+ if (!udata)
+ return -ENOMEM;
+
+ udata->dev = dev;
+
+ udata->ec = ec_data->ec_dev;
+ if (!udata->ec) {
+ dev_err(dev, "couldn't find parent EC device");
+ return -ENODEV;
+ }
+
+ platform_set_drvdata(pdev, udata);
+
+ INIT_WORK(&udata->work, cros_ucsi_work);
+ INIT_DELAYED_WORK(&udata->write_tmo, cros_ucsi_write_timeout);
+ init_completion(&udata->complete);
+
+ udata->ucsi = ucsi_create(dev, &cros_ucsi_ops);
+ if (IS_ERR(udata->ucsi)) {
+ dev_err(dev, "failed to allocate UCSI instance");
+ return PTR_ERR(udata->ucsi);
+ }
+
+ ucsi_set_drvdata(udata->ucsi, udata);
+
+ udata->nb.notifier_call = cros_ucsi_event;
+ ret = cros_usbpd_register_notify(&udata->nb);
+ if (ret) {
+ dev_err(dev, "failed to register notifier: error=%d", ret);
+ ucsi_destroy(udata->ucsi);
+ return ret;
+ }
+
+ ret = ucsi_register(udata->ucsi);
+ if (ret) {
+ dev_err(dev, "failed to register UCSI: error=%d", ret);
+ cros_ucsi_destroy(udata);
+ return ret;
+ }
+
+ return 0;
+}
+
+static void cros_ucsi_remove(struct platform_device *dev)
+{
+ struct cros_ucsi_data *udata = platform_get_drvdata(dev);
+
+ ucsi_unregister(udata->ucsi);
+ cros_ucsi_destroy(udata);
+}
+
+static int __maybe_unused cros_ucsi_suspend(struct device *dev)
+{
+ struct cros_ucsi_data *udata = dev_get_drvdata(dev);
+
+ cancel_delayed_work_sync(&udata->write_tmo);
+ cancel_work_sync(&udata->work);
+
+ return 0;
+}
+
+static void __maybe_unused cros_ucsi_complete(struct device *dev)
+{
+ struct cros_ucsi_data *udata = dev_get_drvdata(dev);
+
+ ucsi_resume(udata->ucsi);
+}
+
+/*
+ * UCSI protocol is also used on ChromeOS platforms which reply on
+ * cros_ec_lpc.c driver for communication with embedded controller (EC).
+ * On such platforms communication with the EC is not available until
+ * the .complete() callback of the cros_ec_lpc driver is executed.
+ * For this reason we delay ucsi_resume() until the .complete() stage
+ * otherwise UCSI SET_NOTIFICATION_ENABLE command will fail and we won't
+ * receive any UCSI notifications from the EC where PPM is implemented.
+ */
+static const struct dev_pm_ops cros_ucsi_pm_ops = {
+#ifdef CONFIG_PM_SLEEP
+ .suspend = cros_ucsi_suspend,
+ .complete = cros_ucsi_complete,
+#endif
+};
+
+static const struct platform_device_id cros_ucsi_id[] = {
+ { KBUILD_MODNAME, 0 },
+ {}
+};
+MODULE_DEVICE_TABLE(platform, cros_ucsi_id);
+
+static struct platform_driver cros_ucsi_driver = {
+ .driver = {
+ .name = KBUILD_MODNAME,
+ .pm = &cros_ucsi_pm_ops,
+ },
+ .id_table = cros_ucsi_id,
+ .probe = cros_ucsi_probe,
+ .remove = cros_ucsi_remove,
+};
+
+module_platform_driver(cros_ucsi_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("UCSI driver for ChromeOS EC");
--
2.47.1.613.gc27f4b7a9f-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH] driver/platform/chrome: Update cros_ec_trace with new USCI commands
2024-12-31 13:10 ` [PATCH v12 1/2] platform/chrome: Update ChromeOS EC header for UCSI Łukasz Bartosik
@ 2025-01-03 23:34 ` Gwendal Grignou
2025-01-04 7:55 ` kernel test robot
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Gwendal Grignou @ 2025-01-03 23:34 UTC (permalink / raw)
To: ukaszb
Cc: abhishekpandit, bleung, chrome-platform, dmitry.baryshkov, gregkh,
heikki.krogerus, jthies, linux-usb, pholla, tzungbi,
Gwendal Grignou
Add this patch to "platform/chrome: Update ChromeOS EC header for UCSI"
to add the new commands form cros_ec_commands.h in the tracer so that
they are nicely decoded. Enable the tracer with:
cd /sys/kernel/debug/tracing
echo 1 > events/cros_ec/enable
echo 1 > tracing_on
cat trace_pipe
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
---
drivers/platform/chrome/cros_ec_trace.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/platform/chrome/cros_ec_trace.c b/drivers/platform/chrome/cros_ec_trace.c
index 425e9441b7ca5..ddc6adfb3897a 100644
--- a/drivers/platform/chrome/cros_ec_trace.c
+++ b/drivers/platform/chrome/cros_ec_trace.c
@@ -166,6 +166,8 @@
TRACE_SYMBOL(EC_CMD_REGULATOR_IS_ENABLED), \
TRACE_SYMBOL(EC_CMD_REGULATOR_SET_VOLTAGE), \
TRACE_SYMBOL(EC_CMD_REGULATOR_GET_VOLTAGE), \
+ TRACE_SYMBOL(EC_CMD_UCSI_PPM_SET), \
+ TRACE_SYMBOL(EC_CMD_UCSI_PPM_GET), \
TRACE_SYMBOL(EC_CMD_CR51_BASE), \
TRACE_SYMBOL(EC_CMD_CR51_LAST), \
TRACE_SYMBOL(EC_CMD_FP_PASSTHRU), \
--
2.47.1.613.gc27f4b7a9f-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] driver/platform/chrome: Update cros_ec_trace with new USCI commands
2025-01-03 23:34 ` [PATCH] driver/platform/chrome: Update cros_ec_trace with new USCI commands Gwendal Grignou
@ 2025-01-04 7:55 ` kernel test robot
2025-01-04 8:12 ` Greg KH
2025-01-04 16:27 ` kernel test robot
2 siblings, 0 replies; 10+ messages in thread
From: kernel test robot @ 2025-01-04 7:55 UTC (permalink / raw)
To: Gwendal Grignou, ukaszb
Cc: oe-kbuild-all, abhishekpandit, bleung, chrome-platform,
dmitry.baryshkov, gregkh, heikki.krogerus, jthies, linux-usb,
pholla, tzungbi, Gwendal Grignou
Hi Gwendal,
kernel test robot noticed the following build errors:
[auto build test ERROR on chrome-platform/for-next]
[also build test ERROR on linus/master v6.13-rc5 next-20241220]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Gwendal-Grignou/driver-platform-chrome-Update-cros_ec_trace-with-new-USCI-commands/20250104-073614
base: https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next
patch link: https://lore.kernel.org/r/20250103233407.4001046-1-gwendal%40chromium.org
patch subject: [PATCH] driver/platform/chrome: Update cros_ec_trace with new USCI commands
config: i386-buildonly-randconfig-002-20250104 (https://download.01.org/0day-ci/archive/20250104/202501041541.ZbA4mnNs-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250104/202501041541.ZbA4mnNs-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202501041541.ZbA4mnNs-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from include/trace/define_trace.h:113,
from drivers/platform/chrome/cros_ec_trace.h:83,
from drivers/platform/chrome/cros_ec_trace.c:217:
drivers/platform/chrome/./cros_ec_trace.h: In function 'trace_raw_output_cros_ec_request_start':
>> drivers/platform/chrome/cros_ec_trace.c:169:22: error: 'EC_CMD_UCSI_PPM_SET' undeclared (first use in this function); did you mean 'EC_CMD_GPIO_SET'?
169 | TRACE_SYMBOL(EC_CMD_UCSI_PPM_SET), \
| ^~~~~~~~~~~~~~~~~~~
include/trace/trace_events.h:219:34: note: in definition of macro 'DECLARE_EVENT_CLASS'
219 | trace_event_printf(iter, print); \
| ^~~~~
include/trace/trace_events.h:45:30: note: in expansion of macro 'PARAMS'
45 | PARAMS(print)); \
| ^~~~~~
drivers/platform/chrome/./cros_ec_trace.h:21:1: note: in expansion of macro 'TRACE_EVENT'
21 | TRACE_EVENT(cros_ec_request_start,
| ^~~~~~~~~~~
drivers/platform/chrome/./cros_ec_trace.h:38:9: note: in expansion of macro 'TP_printk'
38 | TP_printk("version: %u, offset: %d, command: %s, outsize: %u, insize: %u",
| ^~~~~~~~~
drivers/platform/chrome/./cros_ec_trace.h:40:19: note: in expansion of macro '__print_symbolic'
40 | __print_symbolic(__entry->command, EC_CMDS),
| ^~~~~~~~~~~~~~~~
drivers/platform/chrome/cros_ec_trace.c:169:9: note: in expansion of macro 'TRACE_SYMBOL'
169 | TRACE_SYMBOL(EC_CMD_UCSI_PPM_SET), \
| ^~~~~~~~~~~~
drivers/platform/chrome/./cros_ec_trace.h:40:54: note: in expansion of macro 'EC_CMDS'
40 | __print_symbolic(__entry->command, EC_CMDS),
| ^~~~~~~
drivers/platform/chrome/cros_ec_trace.c:169:22: note: each undeclared identifier is reported only once for each function it appears in
169 | TRACE_SYMBOL(EC_CMD_UCSI_PPM_SET), \
| ^~~~~~~~~~~~~~~~~~~
include/trace/trace_events.h:219:34: note: in definition of macro 'DECLARE_EVENT_CLASS'
219 | trace_event_printf(iter, print); \
| ^~~~~
include/trace/trace_events.h:45:30: note: in expansion of macro 'PARAMS'
45 | PARAMS(print)); \
| ^~~~~~
drivers/platform/chrome/./cros_ec_trace.h:21:1: note: in expansion of macro 'TRACE_EVENT'
21 | TRACE_EVENT(cros_ec_request_start,
| ^~~~~~~~~~~
drivers/platform/chrome/./cros_ec_trace.h:38:9: note: in expansion of macro 'TP_printk'
38 | TP_printk("version: %u, offset: %d, command: %s, outsize: %u, insize: %u",
| ^~~~~~~~~
drivers/platform/chrome/./cros_ec_trace.h:40:19: note: in expansion of macro '__print_symbolic'
40 | __print_symbolic(__entry->command, EC_CMDS),
| ^~~~~~~~~~~~~~~~
drivers/platform/chrome/cros_ec_trace.c:169:9: note: in expansion of macro 'TRACE_SYMBOL'
169 | TRACE_SYMBOL(EC_CMD_UCSI_PPM_SET), \
| ^~~~~~~~~~~~
drivers/platform/chrome/./cros_ec_trace.h:40:54: note: in expansion of macro 'EC_CMDS'
40 | __print_symbolic(__entry->command, EC_CMDS),
| ^~~~~~~
>> drivers/platform/chrome/cros_ec_trace.c:170:22: error: 'EC_CMD_UCSI_PPM_GET' undeclared (first use in this function); did you mean 'EC_CMD_GPIO_GET'?
170 | TRACE_SYMBOL(EC_CMD_UCSI_PPM_GET), \
| ^~~~~~~~~~~~~~~~~~~
include/trace/trace_events.h:219:34: note: in definition of macro 'DECLARE_EVENT_CLASS'
219 | trace_event_printf(iter, print); \
| ^~~~~
include/trace/trace_events.h:45:30: note: in expansion of macro 'PARAMS'
45 | PARAMS(print)); \
| ^~~~~~
drivers/platform/chrome/./cros_ec_trace.h:21:1: note: in expansion of macro 'TRACE_EVENT'
21 | TRACE_EVENT(cros_ec_request_start,
| ^~~~~~~~~~~
drivers/platform/chrome/./cros_ec_trace.h:38:9: note: in expansion of macro 'TP_printk'
38 | TP_printk("version: %u, offset: %d, command: %s, outsize: %u, insize: %u",
| ^~~~~~~~~
drivers/platform/chrome/./cros_ec_trace.h:40:19: note: in expansion of macro '__print_symbolic'
40 | __print_symbolic(__entry->command, EC_CMDS),
| ^~~~~~~~~~~~~~~~
drivers/platform/chrome/cros_ec_trace.c:170:9: note: in expansion of macro 'TRACE_SYMBOL'
170 | TRACE_SYMBOL(EC_CMD_UCSI_PPM_GET), \
| ^~~~~~~~~~~~
drivers/platform/chrome/./cros_ec_trace.h:40:54: note: in expansion of macro 'EC_CMDS'
40 | __print_symbolic(__entry->command, EC_CMDS),
| ^~~~~~~
drivers/platform/chrome/./cros_ec_trace.h: In function 'trace_raw_output_cros_ec_request_done':
>> drivers/platform/chrome/cros_ec_trace.c:169:22: error: 'EC_CMD_UCSI_PPM_SET' undeclared (first use in this function); did you mean 'EC_CMD_GPIO_SET'?
169 | TRACE_SYMBOL(EC_CMD_UCSI_PPM_SET), \
| ^~~~~~~~~~~~~~~~~~~
include/trace/trace_events.h:219:34: note: in definition of macro 'DECLARE_EVENT_CLASS'
219 | trace_event_printf(iter, print); \
| ^~~~~
include/trace/trace_events.h:45:30: note: in expansion of macro 'PARAMS'
45 | PARAMS(print)); \
| ^~~~~~
drivers/platform/chrome/./cros_ec_trace.h:44:1: note: in expansion of macro 'TRACE_EVENT'
44 | TRACE_EVENT(cros_ec_request_done,
| ^~~~~~~~~~~
drivers/platform/chrome/./cros_ec_trace.h:65:9: note: in expansion of macro 'TP_printk'
65 | TP_printk("version: %u, offset: %d, command: %s, outsize: %u, insize: %u, ec result: %s, retval: %u",
| ^~~~~~~~~
drivers/platform/chrome/./cros_ec_trace.h:67:19: note: in expansion of macro '__print_symbolic'
67 | __print_symbolic(__entry->command, EC_CMDS),
| ^~~~~~~~~~~~~~~~
drivers/platform/chrome/cros_ec_trace.c:169:9: note: in expansion of macro 'TRACE_SYMBOL'
169 | TRACE_SYMBOL(EC_CMD_UCSI_PPM_SET), \
| ^~~~~~~~~~~~
drivers/platform/chrome/./cros_ec_trace.h:67:54: note: in expansion of macro 'EC_CMDS'
67 | __print_symbolic(__entry->command, EC_CMDS),
| ^~~~~~~
>> drivers/platform/chrome/cros_ec_trace.c:170:22: error: 'EC_CMD_UCSI_PPM_GET' undeclared (first use in this function); did you mean 'EC_CMD_GPIO_GET'?
170 | TRACE_SYMBOL(EC_CMD_UCSI_PPM_GET), \
| ^~~~~~~~~~~~~~~~~~~
include/trace/trace_events.h:219:34: note: in definition of macro 'DECLARE_EVENT_CLASS'
219 | trace_event_printf(iter, print); \
| ^~~~~
include/trace/trace_events.h:45:30: note: in expansion of macro 'PARAMS'
45 | PARAMS(print)); \
| ^~~~~~
drivers/platform/chrome/./cros_ec_trace.h:44:1: note: in expansion of macro 'TRACE_EVENT'
44 | TRACE_EVENT(cros_ec_request_done,
| ^~~~~~~~~~~
drivers/platform/chrome/./cros_ec_trace.h:65:9: note: in expansion of macro 'TP_printk'
65 | TP_printk("version: %u, offset: %d, command: %s, outsize: %u, insize: %u, ec result: %s, retval: %u",
| ^~~~~~~~~
drivers/platform/chrome/./cros_ec_trace.h:67:19: note: in expansion of macro '__print_symbolic'
67 | __print_symbolic(__entry->command, EC_CMDS),
| ^~~~~~~~~~~~~~~~
drivers/platform/chrome/cros_ec_trace.c:170:9: note: in expansion of macro 'TRACE_SYMBOL'
170 | TRACE_SYMBOL(EC_CMD_UCSI_PPM_GET), \
| ^~~~~~~~~~~~
drivers/platform/chrome/./cros_ec_trace.h:67:54: note: in expansion of macro 'EC_CMDS'
67 | __print_symbolic(__entry->command, EC_CMDS),
| ^~~~~~~
vim +169 drivers/platform/chrome/cros_ec_trace.c
7
8 // Generate the list using the following script:
9 // sed -n 's/^#define \(EC_CMD_[[:alnum:]_]*\)\s.*/\tTRACE_SYMBOL(\1), \\/p' include/linux/platform_data/cros_ec_commands.h
10 #define EC_CMDS \
11 TRACE_SYMBOL(EC_CMD_ACPI_READ), \
12 TRACE_SYMBOL(EC_CMD_ACPI_WRITE), \
13 TRACE_SYMBOL(EC_CMD_ACPI_BURST_ENABLE), \
14 TRACE_SYMBOL(EC_CMD_ACPI_BURST_DISABLE), \
15 TRACE_SYMBOL(EC_CMD_ACPI_QUERY_EVENT), \
16 TRACE_SYMBOL(EC_CMD_PROTO_VERSION), \
17 TRACE_SYMBOL(EC_CMD_HELLO), \
18 TRACE_SYMBOL(EC_CMD_GET_VERSION), \
19 TRACE_SYMBOL(EC_CMD_READ_TEST), \
20 TRACE_SYMBOL(EC_CMD_GET_BUILD_INFO), \
21 TRACE_SYMBOL(EC_CMD_GET_CHIP_INFO), \
22 TRACE_SYMBOL(EC_CMD_GET_BOARD_VERSION), \
23 TRACE_SYMBOL(EC_CMD_READ_MEMMAP), \
24 TRACE_SYMBOL(EC_CMD_GET_CMD_VERSIONS), \
25 TRACE_SYMBOL(EC_CMD_GET_COMMS_STATUS), \
26 TRACE_SYMBOL(EC_CMD_TEST_PROTOCOL), \
27 TRACE_SYMBOL(EC_CMD_GET_PROTOCOL_INFO), \
28 TRACE_SYMBOL(EC_CMD_GSV_PAUSE_IN_S5), \
29 TRACE_SYMBOL(EC_CMD_GET_FEATURES), \
30 TRACE_SYMBOL(EC_CMD_GET_SKU_ID), \
31 TRACE_SYMBOL(EC_CMD_SET_SKU_ID), \
32 TRACE_SYMBOL(EC_CMD_FLASH_INFO), \
33 TRACE_SYMBOL(EC_CMD_FLASH_READ), \
34 TRACE_SYMBOL(EC_CMD_FLASH_WRITE), \
35 TRACE_SYMBOL(EC_CMD_FLASH_ERASE), \
36 TRACE_SYMBOL(EC_CMD_FLASH_PROTECT), \
37 TRACE_SYMBOL(EC_CMD_FLASH_REGION_INFO), \
38 TRACE_SYMBOL(EC_CMD_VBNV_CONTEXT), \
39 TRACE_SYMBOL(EC_CMD_FLASH_SPI_INFO), \
40 TRACE_SYMBOL(EC_CMD_FLASH_SELECT), \
41 TRACE_SYMBOL(EC_CMD_PWM_GET_FAN_TARGET_RPM), \
42 TRACE_SYMBOL(EC_CMD_PWM_SET_FAN_TARGET_RPM), \
43 TRACE_SYMBOL(EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT), \
44 TRACE_SYMBOL(EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT), \
45 TRACE_SYMBOL(EC_CMD_PWM_SET_FAN_DUTY), \
46 TRACE_SYMBOL(EC_CMD_PWM_SET_DUTY), \
47 TRACE_SYMBOL(EC_CMD_PWM_GET_DUTY), \
48 TRACE_SYMBOL(EC_CMD_LIGHTBAR_CMD), \
49 TRACE_SYMBOL(EC_CMD_LED_CONTROL), \
50 TRACE_SYMBOL(EC_CMD_VBOOT_HASH), \
51 TRACE_SYMBOL(EC_CMD_MOTION_SENSE_CMD), \
52 TRACE_SYMBOL(EC_CMD_FORCE_LID_OPEN), \
53 TRACE_SYMBOL(EC_CMD_CONFIG_POWER_BUTTON), \
54 TRACE_SYMBOL(EC_CMD_USB_CHARGE_SET_MODE), \
55 TRACE_SYMBOL(EC_CMD_PSTORE_INFO), \
56 TRACE_SYMBOL(EC_CMD_PSTORE_READ), \
57 TRACE_SYMBOL(EC_CMD_PSTORE_WRITE), \
58 TRACE_SYMBOL(EC_CMD_RTC_GET_VALUE), \
59 TRACE_SYMBOL(EC_CMD_RTC_GET_ALARM), \
60 TRACE_SYMBOL(EC_CMD_RTC_SET_VALUE), \
61 TRACE_SYMBOL(EC_CMD_RTC_SET_ALARM), \
62 TRACE_SYMBOL(EC_CMD_PORT80_LAST_BOOT), \
63 TRACE_SYMBOL(EC_CMD_PORT80_READ), \
64 TRACE_SYMBOL(EC_CMD_VSTORE_INFO), \
65 TRACE_SYMBOL(EC_CMD_VSTORE_READ), \
66 TRACE_SYMBOL(EC_CMD_VSTORE_WRITE), \
67 TRACE_SYMBOL(EC_CMD_THERMAL_SET_THRESHOLD), \
68 TRACE_SYMBOL(EC_CMD_THERMAL_GET_THRESHOLD), \
69 TRACE_SYMBOL(EC_CMD_THERMAL_AUTO_FAN_CTRL), \
70 TRACE_SYMBOL(EC_CMD_TMP006_GET_CALIBRATION), \
71 TRACE_SYMBOL(EC_CMD_TMP006_SET_CALIBRATION), \
72 TRACE_SYMBOL(EC_CMD_TMP006_GET_RAW), \
73 TRACE_SYMBOL(EC_CMD_MKBP_STATE), \
74 TRACE_SYMBOL(EC_CMD_MKBP_INFO), \
75 TRACE_SYMBOL(EC_CMD_MKBP_SIMULATE_KEY), \
76 TRACE_SYMBOL(EC_CMD_GET_KEYBOARD_ID), \
77 TRACE_SYMBOL(EC_CMD_MKBP_SET_CONFIG), \
78 TRACE_SYMBOL(EC_CMD_MKBP_GET_CONFIG), \
79 TRACE_SYMBOL(EC_CMD_KEYSCAN_SEQ_CTRL), \
80 TRACE_SYMBOL(EC_CMD_GET_NEXT_EVENT), \
81 TRACE_SYMBOL(EC_CMD_KEYBOARD_FACTORY_TEST), \
82 TRACE_SYMBOL(EC_CMD_TEMP_SENSOR_GET_INFO), \
83 TRACE_SYMBOL(EC_CMD_HOST_EVENT_GET_B), \
84 TRACE_SYMBOL(EC_CMD_HOST_EVENT_GET_SMI_MASK), \
85 TRACE_SYMBOL(EC_CMD_HOST_EVENT_GET_SCI_MASK), \
86 TRACE_SYMBOL(EC_CMD_HOST_EVENT_GET_WAKE_MASK), \
87 TRACE_SYMBOL(EC_CMD_HOST_EVENT_SET_SMI_MASK), \
88 TRACE_SYMBOL(EC_CMD_HOST_EVENT_SET_SCI_MASK), \
89 TRACE_SYMBOL(EC_CMD_HOST_EVENT_CLEAR), \
90 TRACE_SYMBOL(EC_CMD_HOST_EVENT_SET_WAKE_MASK), \
91 TRACE_SYMBOL(EC_CMD_HOST_EVENT_CLEAR_B), \
92 TRACE_SYMBOL(EC_CMD_HOST_EVENT), \
93 TRACE_SYMBOL(EC_CMD_SWITCH_ENABLE_BKLIGHT), \
94 TRACE_SYMBOL(EC_CMD_SWITCH_ENABLE_WIRELESS), \
95 TRACE_SYMBOL(EC_CMD_GPIO_SET), \
96 TRACE_SYMBOL(EC_CMD_GPIO_GET), \
97 TRACE_SYMBOL(EC_CMD_I2C_READ), \
98 TRACE_SYMBOL(EC_CMD_I2C_WRITE), \
99 TRACE_SYMBOL(EC_CMD_CHARGE_CONTROL), \
100 TRACE_SYMBOL(EC_CMD_CONSOLE_SNAPSHOT), \
101 TRACE_SYMBOL(EC_CMD_CONSOLE_READ), \
102 TRACE_SYMBOL(EC_CMD_BATTERY_CUT_OFF), \
103 TRACE_SYMBOL(EC_CMD_USB_MUX), \
104 TRACE_SYMBOL(EC_CMD_LDO_SET), \
105 TRACE_SYMBOL(EC_CMD_LDO_GET), \
106 TRACE_SYMBOL(EC_CMD_POWER_INFO), \
107 TRACE_SYMBOL(EC_CMD_I2C_PASSTHRU), \
108 TRACE_SYMBOL(EC_CMD_HANG_DETECT), \
109 TRACE_SYMBOL(EC_CMD_CHARGE_STATE), \
110 TRACE_SYMBOL(EC_CMD_CHARGE_CURRENT_LIMIT), \
111 TRACE_SYMBOL(EC_CMD_EXTERNAL_POWER_LIMIT), \
112 TRACE_SYMBOL(EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT), \
113 TRACE_SYMBOL(EC_CMD_HIBERNATION_DELAY), \
114 TRACE_SYMBOL(EC_CMD_HOST_SLEEP_EVENT), \
115 TRACE_SYMBOL(EC_CMD_DEVICE_EVENT), \
116 TRACE_SYMBOL(EC_CMD_SB_READ_WORD), \
117 TRACE_SYMBOL(EC_CMD_SB_WRITE_WORD), \
118 TRACE_SYMBOL(EC_CMD_SB_READ_BLOCK), \
119 TRACE_SYMBOL(EC_CMD_SB_WRITE_BLOCK), \
120 TRACE_SYMBOL(EC_CMD_BATTERY_VENDOR_PARAM), \
121 TRACE_SYMBOL(EC_CMD_SB_FW_UPDATE), \
122 TRACE_SYMBOL(EC_CMD_ENTERING_MODE), \
123 TRACE_SYMBOL(EC_CMD_I2C_PASSTHRU_PROTECT), \
124 TRACE_SYMBOL(EC_CMD_CEC_WRITE_MSG), \
125 TRACE_SYMBOL(EC_CMD_CEC_SET), \
126 TRACE_SYMBOL(EC_CMD_CEC_GET), \
127 TRACE_SYMBOL(EC_CMD_EC_CODEC), \
128 TRACE_SYMBOL(EC_CMD_EC_CODEC_DMIC), \
129 TRACE_SYMBOL(EC_CMD_EC_CODEC_I2S_RX), \
130 TRACE_SYMBOL(EC_CMD_EC_CODEC_WOV), \
131 TRACE_SYMBOL(EC_CMD_REBOOT_EC), \
132 TRACE_SYMBOL(EC_CMD_GET_PANIC_INFO), \
133 TRACE_SYMBOL(EC_CMD_REBOOT), \
134 TRACE_SYMBOL(EC_CMD_RESEND_RESPONSE), \
135 TRACE_SYMBOL(EC_CMD_VERSION0), \
136 TRACE_SYMBOL(EC_CMD_PD_EXCHANGE_STATUS), \
137 TRACE_SYMBOL(EC_CMD_PD_HOST_EVENT_STATUS), \
138 TRACE_SYMBOL(EC_CMD_USB_PD_CONTROL), \
139 TRACE_SYMBOL(EC_CMD_USB_PD_PORTS), \
140 TRACE_SYMBOL(EC_CMD_USB_PD_POWER_INFO), \
141 TRACE_SYMBOL(EC_CMD_CHARGE_PORT_COUNT), \
142 TRACE_SYMBOL(EC_CMD_USB_PD_FW_UPDATE), \
143 TRACE_SYMBOL(EC_CMD_USB_PD_RW_HASH_ENTRY), \
144 TRACE_SYMBOL(EC_CMD_USB_PD_DEV_INFO), \
145 TRACE_SYMBOL(EC_CMD_USB_PD_DISCOVERY), \
146 TRACE_SYMBOL(EC_CMD_PD_CHARGE_PORT_OVERRIDE), \
147 TRACE_SYMBOL(EC_CMD_PD_GET_LOG_ENTRY), \
148 TRACE_SYMBOL(EC_CMD_USB_PD_GET_AMODE), \
149 TRACE_SYMBOL(EC_CMD_USB_PD_SET_AMODE), \
150 TRACE_SYMBOL(EC_CMD_PD_WRITE_LOG_ENTRY), \
151 TRACE_SYMBOL(EC_CMD_PD_CONTROL), \
152 TRACE_SYMBOL(EC_CMD_USB_PD_MUX_INFO), \
153 TRACE_SYMBOL(EC_CMD_PD_CHIP_INFO), \
154 TRACE_SYMBOL(EC_CMD_RWSIG_CHECK_STATUS), \
155 TRACE_SYMBOL(EC_CMD_RWSIG_ACTION), \
156 TRACE_SYMBOL(EC_CMD_EFS_VERIFY), \
157 TRACE_SYMBOL(EC_CMD_GET_CROS_BOARD_INFO), \
158 TRACE_SYMBOL(EC_CMD_SET_CROS_BOARD_INFO), \
159 TRACE_SYMBOL(EC_CMD_GET_UPTIME_INFO), \
160 TRACE_SYMBOL(EC_CMD_ADD_ENTROPY), \
161 TRACE_SYMBOL(EC_CMD_ADC_READ), \
162 TRACE_SYMBOL(EC_CMD_ROLLBACK_INFO), \
163 TRACE_SYMBOL(EC_CMD_AP_RESET), \
164 TRACE_SYMBOL(EC_CMD_REGULATOR_GET_INFO), \
165 TRACE_SYMBOL(EC_CMD_REGULATOR_ENABLE), \
166 TRACE_SYMBOL(EC_CMD_REGULATOR_IS_ENABLED), \
167 TRACE_SYMBOL(EC_CMD_REGULATOR_SET_VOLTAGE), \
168 TRACE_SYMBOL(EC_CMD_REGULATOR_GET_VOLTAGE), \
> 169 TRACE_SYMBOL(EC_CMD_UCSI_PPM_SET), \
> 170 TRACE_SYMBOL(EC_CMD_UCSI_PPM_GET), \
171 TRACE_SYMBOL(EC_CMD_CR51_BASE), \
172 TRACE_SYMBOL(EC_CMD_CR51_LAST), \
173 TRACE_SYMBOL(EC_CMD_FP_PASSTHRU), \
174 TRACE_SYMBOL(EC_CMD_FP_MODE), \
175 TRACE_SYMBOL(EC_CMD_FP_INFO), \
176 TRACE_SYMBOL(EC_CMD_FP_FRAME), \
177 TRACE_SYMBOL(EC_CMD_FP_TEMPLATE), \
178 TRACE_SYMBOL(EC_CMD_FP_CONTEXT), \
179 TRACE_SYMBOL(EC_CMD_FP_STATS), \
180 TRACE_SYMBOL(EC_CMD_FP_SEED), \
181 TRACE_SYMBOL(EC_CMD_FP_ENC_STATUS), \
182 TRACE_SYMBOL(EC_CMD_TP_SELF_TEST), \
183 TRACE_SYMBOL(EC_CMD_TP_FRAME_INFO), \
184 TRACE_SYMBOL(EC_CMD_TP_FRAME_SNAPSHOT), \
185 TRACE_SYMBOL(EC_CMD_TP_FRAME_GET), \
186 TRACE_SYMBOL(EC_CMD_BATTERY_GET_STATIC), \
187 TRACE_SYMBOL(EC_CMD_BATTERY_GET_DYNAMIC), \
188 TRACE_SYMBOL(EC_CMD_CHARGER_CONTROL), \
189 TRACE_SYMBOL(EC_CMD_BOARD_SPECIFIC_BASE), \
190 TRACE_SYMBOL(EC_CMD_BOARD_SPECIFIC_LAST)
191
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] driver/platform/chrome: Update cros_ec_trace with new USCI commands
2025-01-03 23:34 ` [PATCH] driver/platform/chrome: Update cros_ec_trace with new USCI commands Gwendal Grignou
2025-01-04 7:55 ` kernel test robot
@ 2025-01-04 8:12 ` Greg KH
2025-01-06 18:43 ` Gwendal Grignou
2025-01-04 16:27 ` kernel test robot
2 siblings, 1 reply; 10+ messages in thread
From: Greg KH @ 2025-01-04 8:12 UTC (permalink / raw)
To: Gwendal Grignou
Cc: ukaszb, abhishekpandit, bleung, chrome-platform, dmitry.baryshkov,
heikki.krogerus, jthies, linux-usb, pholla, tzungbi
On Fri, Jan 03, 2025 at 03:34:07PM -0800, Gwendal Grignou wrote:
> Add this patch to "platform/chrome: Update ChromeOS EC header for UCSI"
I do not understand this changelog text, sorry. How can you "add"
something to an existing change?
> to add the new commands form cros_ec_commands.h in the tracer so that
> they are nicely decoded. Enable the tracer with:
> cd /sys/kernel/debug/tracing
> echo 1 > events/cros_ec/enable
> echo 1 > tracing_on
> cat trace_pipe
We don't need to document how to enable a tracepoint here in the
changelog, right? That's going to get lost and why is this new one
somehow special?
confused,
greg k-h
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] driver/platform/chrome: Update cros_ec_trace with new USCI commands
2025-01-03 23:34 ` [PATCH] driver/platform/chrome: Update cros_ec_trace with new USCI commands Gwendal Grignou
2025-01-04 7:55 ` kernel test robot
2025-01-04 8:12 ` Greg KH
@ 2025-01-04 16:27 ` kernel test robot
2 siblings, 0 replies; 10+ messages in thread
From: kernel test robot @ 2025-01-04 16:27 UTC (permalink / raw)
To: Gwendal Grignou, ukaszb
Cc: llvm, oe-kbuild-all, abhishekpandit, bleung, chrome-platform,
dmitry.baryshkov, gregkh, heikki.krogerus, jthies, linux-usb,
pholla, tzungbi, Gwendal Grignou
Hi Gwendal,
kernel test robot noticed the following build errors:
[auto build test ERROR on chrome-platform/for-next]
[also build test ERROR on chrome-platform/for-firmware-next linus/master v6.13-rc5 next-20241220]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Gwendal-Grignou/driver-platform-chrome-Update-cros_ec_trace-with-new-USCI-commands/20250104-073614
base: https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next
patch link: https://lore.kernel.org/r/20250103233407.4001046-1-gwendal%40chromium.org
patch subject: [PATCH] driver/platform/chrome: Update cros_ec_trace with new USCI commands
config: x86_64-buildonly-randconfig-005-20250104 (https://download.01.org/0day-ci/archive/20250105/202501050055.oR3g1RHJ-lkp@intel.com/config)
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250105/202501050055.oR3g1RHJ-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202501050055.oR3g1RHJ-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from drivers/platform/chrome/cros_ec_trace.c:217:
In file included from drivers/platform/chrome/cros_ec_trace.h:83:
In file included from include/trace/define_trace.h:113:
In file included from include/trace/trace_events.h:256:
>> drivers/platform/chrome/cros_ec_trace.h:40:40: error: use of undeclared identifier 'EC_CMD_UCSI_PPM_SET'
40 | __print_symbolic(__entry->command, EC_CMDS),
| ^
drivers/platform/chrome/cros_ec_trace.c:169:15: note: expanded from macro 'EC_CMDS'
169 | TRACE_SYMBOL(EC_CMD_UCSI_PPM_SET), \
| ^
In file included from drivers/platform/chrome/cros_ec_trace.c:217:
In file included from drivers/platform/chrome/cros_ec_trace.h:83:
In file included from include/trace/define_trace.h:113:
In file included from include/trace/trace_events.h:256:
>> drivers/platform/chrome/cros_ec_trace.h:40:40: error: use of undeclared identifier 'EC_CMD_UCSI_PPM_GET'
drivers/platform/chrome/cros_ec_trace.c:170:15: note: expanded from macro 'EC_CMDS'
170 | TRACE_SYMBOL(EC_CMD_UCSI_PPM_GET), \
| ^
In file included from drivers/platform/chrome/cros_ec_trace.c:217:
In file included from drivers/platform/chrome/cros_ec_trace.h:83:
In file included from include/trace/define_trace.h:113:
In file included from include/trace/trace_events.h:256:
drivers/platform/chrome/cros_ec_trace.h:67:40: error: use of undeclared identifier 'EC_CMD_UCSI_PPM_SET'
67 | __print_symbolic(__entry->command, EC_CMDS),
| ^
drivers/platform/chrome/cros_ec_trace.c:169:15: note: expanded from macro 'EC_CMDS'
169 | TRACE_SYMBOL(EC_CMD_UCSI_PPM_SET), \
| ^
In file included from drivers/platform/chrome/cros_ec_trace.c:217:
In file included from drivers/platform/chrome/cros_ec_trace.h:83:
In file included from include/trace/define_trace.h:113:
In file included from include/trace/trace_events.h:256:
drivers/platform/chrome/cros_ec_trace.h:67:40: error: use of undeclared identifier 'EC_CMD_UCSI_PPM_GET'
drivers/platform/chrome/cros_ec_trace.c:170:15: note: expanded from macro 'EC_CMDS'
170 | TRACE_SYMBOL(EC_CMD_UCSI_PPM_GET), \
| ^
4 errors generated.
vim +/EC_CMD_UCSI_PPM_SET +40 drivers/platform/chrome/cros_ec_trace.h
58a2109f6eb46b Raul E Rangel 2019-04-16 20
205c9326fd8665 Raul E Rangel 2019-11-25 21 TRACE_EVENT(cros_ec_request_start,
58a2109f6eb46b Raul E Rangel 2019-04-16 22 TP_PROTO(struct cros_ec_command *cmd),
58a2109f6eb46b Raul E Rangel 2019-04-16 23 TP_ARGS(cmd),
58a2109f6eb46b Raul E Rangel 2019-04-16 24 TP_STRUCT__entry(
58a2109f6eb46b Raul E Rangel 2019-04-16 25 __field(uint32_t, version)
8143182426874a Gwendal Grignou 2020-08-14 26 __field(uint32_t, offset)
58a2109f6eb46b Raul E Rangel 2019-04-16 27 __field(uint32_t, command)
8143182426874a Gwendal Grignou 2020-08-14 28 __field(uint32_t, outsize)
8143182426874a Gwendal Grignou 2020-08-14 29 __field(uint32_t, insize)
58a2109f6eb46b Raul E Rangel 2019-04-16 30 ),
58a2109f6eb46b Raul E Rangel 2019-04-16 31 TP_fast_assign(
58a2109f6eb46b Raul E Rangel 2019-04-16 32 __entry->version = cmd->version;
3db0c9e5de7bd9 Tzung-Bi Shih 2022-06-09 33 __entry->offset = cmd->command / EC_CMD_PASSTHRU_OFFSET(CROS_EC_DEV_PD_INDEX);
3db0c9e5de7bd9 Tzung-Bi Shih 2022-06-09 34 __entry->command = cmd->command % EC_CMD_PASSTHRU_OFFSET(CROS_EC_DEV_PD_INDEX);
8143182426874a Gwendal Grignou 2020-08-14 35 __entry->outsize = cmd->outsize;
8143182426874a Gwendal Grignou 2020-08-14 36 __entry->insize = cmd->insize;
58a2109f6eb46b Raul E Rangel 2019-04-16 37 ),
8143182426874a Gwendal Grignou 2020-08-14 38 TP_printk("version: %u, offset: %d, command: %s, outsize: %u, insize: %u",
8143182426874a Gwendal Grignou 2020-08-14 39 __entry->version, __entry->offset,
8143182426874a Gwendal Grignou 2020-08-14 @40 __print_symbolic(__entry->command, EC_CMDS),
8143182426874a Gwendal Grignou 2020-08-14 41 __entry->outsize, __entry->insize)
58a2109f6eb46b Raul E Rangel 2019-04-16 42 );
58a2109f6eb46b Raul E Rangel 2019-04-16 43
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] driver/platform/chrome: Update cros_ec_trace with new USCI commands
2025-01-04 8:12 ` Greg KH
@ 2025-01-06 18:43 ` Gwendal Grignou
2025-01-07 10:33 ` Greg KH
0 siblings, 1 reply; 10+ messages in thread
From: Gwendal Grignou @ 2025-01-06 18:43 UTC (permalink / raw)
To: Greg KH
Cc: ukaszb, abhishekpandit, bleung, chrome-platform, dmitry.baryshkov,
heikki.krogerus, jthies, linux-usb, pholla, tzungbi
On Sat, Jan 4, 2025 at 12:13 AM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Fri, Jan 03, 2025 at 03:34:07PM -0800, Gwendal Grignou wrote:
> > Add this patch to "platform/chrome: Update ChromeOS EC header for UCSI"
>
> I do not understand this changelog text, sorry. How can you "add"
> something to an existing change?
>
> > to add the new commands form cros_ec_commands.h in the tracer so that
> > they are nicely decoded. Enable the tracer with:
> > cd /sys/kernel/debug/tracing
> > echo 1 > events/cros_ec/enable
> > echo 1 > tracing_on
> > cat trace_pipe
>
> We don't need to document how to enable a tracepoint here in the
> changelog, right? That's going to get lost and why is this new one
> somehow special?
>
> confused,
Sorry, I did not use `git send-email` appropriately: the code snippet
inside the email was not meant to be a standalone patch, but to be
added to patch v12 1/2 "platform/chrome: Update ChromeOS EC header for
UCSI".
If this is too late, that's fine; I will send a proper kernel patch
through the chrome-platform@lists.linux.dev mailing list.
Gwendal.
>
> greg k-h
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v12 2/2] usb: typec: ucsi: Implement ChromeOS UCSI driver
2024-12-31 13:10 ` [PATCH v12 2/2] usb: typec: ucsi: Implement ChromeOS UCSI driver Łukasz Bartosik
@ 2025-01-07 10:28 ` Heikki Krogerus
0 siblings, 0 replies; 10+ messages in thread
From: Heikki Krogerus @ 2025-01-07 10:28 UTC (permalink / raw)
To: Łukasz Bartosik
Cc: Greg Kroah-Hartman, Benson Leung, Dmitry Baryshkov,
Abhishek Pandit-Subedi, Jameson Thies, Pavan Holla, Tzung-Bi Shih,
linux-usb, chrome-platform
On Tue, Dec 31, 2024 at 01:10:47PM +0000, Łukasz Bartosik wrote:
> From: Pavan Holla <pholla@chromium.org>
>
> Implementation of a UCSI transport driver for ChromeOS.
> This driver will be loaded if the ChromeOS EC implements a PPM.
>
> Signed-off-by: Pavan Holla <pholla@chromium.org>
> Co-developed-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> Co-developed-by: Łukasz Bartosik <ukaszb@chromium.org>
> Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> MAINTAINERS | 7 +
> drivers/usb/typec/ucsi/Kconfig | 13 +
> drivers/usb/typec/ucsi/Makefile | 1 +
> drivers/usb/typec/ucsi/cros_ec_ucsi.c | 337 ++++++++++++++++++++++++++
> 4 files changed, 358 insertions(+)
> create mode 100644 drivers/usb/typec/ucsi/cros_ec_ucsi.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 910305c11e8a..0f2ee59540a9 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -5454,6 +5454,13 @@ L: chrome-platform@lists.linux.dev
> S: Maintained
> F: drivers/watchdog/cros_ec_wdt.c
>
> +CHROMEOS UCSI DRIVER
> +M: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> +M: Łukasz Bartosik <ukaszb@chromium.org>
> +L: chrome-platform@lists.linux.dev
> +S: Maintained
> +F: drivers/usb/typec/ucsi/cros_ec_ucsi.c
> +
> CHRONTEL CH7322 CEC DRIVER
> M: Joe Tessler <jrt@google.com>
> L: linux-media@vger.kernel.org
> diff --git a/drivers/usb/typec/ucsi/Kconfig b/drivers/usb/typec/ucsi/Kconfig
> index 680e1b87b152..75559601fe8f 100644
> --- a/drivers/usb/typec/ucsi/Kconfig
> +++ b/drivers/usb/typec/ucsi/Kconfig
> @@ -69,6 +69,19 @@ config UCSI_PMIC_GLINK
> To compile the driver as a module, choose M here: the module will be
> called ucsi_glink.
>
> +config CROS_EC_UCSI
> + tristate "UCSI Driver for ChromeOS EC"
> + depends on MFD_CROS_EC_DEV
> + depends on CROS_USBPD_NOTIFY
> + depends on !EXTCON_TCSS_CROS_EC
> + default MFD_CROS_EC_DEV
> + help
> + This driver enables UCSI support for a ChromeOS EC. The EC is
> + expected to implement a PPM.
> +
> + To compile the driver as a module, choose M here: the module
> + will be called cros_ec_ucsi.
> +
> config UCSI_LENOVO_YOGA_C630
> tristate "UCSI Interface Driver for Lenovo Yoga C630"
> depends on EC_LENOVO_YOGA_C630
> diff --git a/drivers/usb/typec/ucsi/Makefile b/drivers/usb/typec/ucsi/Makefile
> index aed41d23887b..be98a879104d 100644
> --- a/drivers/usb/typec/ucsi/Makefile
> +++ b/drivers/usb/typec/ucsi/Makefile
> @@ -21,4 +21,5 @@ obj-$(CONFIG_UCSI_ACPI) += ucsi_acpi.o
> obj-$(CONFIG_UCSI_CCG) += ucsi_ccg.o
> obj-$(CONFIG_UCSI_STM32G0) += ucsi_stm32g0.o
> obj-$(CONFIG_UCSI_PMIC_GLINK) += ucsi_glink.o
> +obj-$(CONFIG_CROS_EC_UCSI) += cros_ec_ucsi.o
> obj-$(CONFIG_UCSI_LENOVO_YOGA_C630) += ucsi_yoga_c630.o
> diff --git a/drivers/usb/typec/ucsi/cros_ec_ucsi.c b/drivers/usb/typec/ucsi/cros_ec_ucsi.c
> new file mode 100644
> index 000000000000..db8324b71ee9
> --- /dev/null
> +++ b/drivers/usb/typec/ucsi/cros_ec_ucsi.c
> @@ -0,0 +1,337 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * UCSI driver for ChromeOS EC
> + *
> + * Copyright 2024 Google LLC.
> + */
> +
> +#include <linux/container_of.h>
> +#include <linux/dev_printk.h>
> +#include <linux/jiffies.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/module.h>
> +#include <linux/platform_data/cros_ec_commands.h>
> +#include <linux/platform_data/cros_usbpd_notify.h>
> +#include <linux/platform_data/cros_ec_proto.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
> +#include <linux/wait.h>
> +
> +#include "ucsi.h"
> +
> +/*
> + * Maximum size in bytes of a UCSI message between AP and EC
> + */
> +#define MAX_EC_DATA_SIZE 256
> +
> +/*
> + * Maximum time in milliseconds the cros_ec_ucsi driver
> + * will wait for a response to a command or and ack.
> + */
> +#define WRITE_TMO_MS 5000
> +
> +/* Number of times to attempt recovery from a write timeout before giving up. */
> +#define WRITE_TMO_CTR_MAX 5
> +
> +struct cros_ucsi_data {
> + struct device *dev;
> + struct ucsi *ucsi;
> +
> + struct cros_ec_device *ec;
> + struct notifier_block nb;
> + struct work_struct work;
> + struct delayed_work write_tmo;
> + int tmo_counter;
> +
> + struct completion complete;
> + unsigned long flags;
> +};
> +
> +static int cros_ucsi_read(struct ucsi *ucsi, unsigned int offset, void *val,
> + size_t val_len)
> +{
> + struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi);
> + struct ec_params_ucsi_ppm_get req = {
> + .offset = offset,
> + .size = val_len,
> + };
> + int ret;
> +
> + if (val_len > MAX_EC_DATA_SIZE) {
> + dev_err(udata->dev, "Can't read %zu bytes. Too big.", val_len);
> + return -EINVAL;
> + }
> +
> + ret = cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_GET,
> + &req, sizeof(req), val, val_len);
> + if (ret < 0) {
> + dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_GET: error=%d", ret);
> + return ret;
> + }
> + return 0;
> +}
> +
> +static int cros_ucsi_read_version(struct ucsi *ucsi, u16 *version)
> +{
> + return cros_ucsi_read(ucsi, UCSI_VERSION, version, sizeof(*version));
> +}
> +
> +static int cros_ucsi_read_cci(struct ucsi *ucsi, u32 *cci)
> +{
> + return cros_ucsi_read(ucsi, UCSI_CCI, cci, sizeof(*cci));
> +}
> +
> +static int cros_ucsi_read_message_in(struct ucsi *ucsi, void *val,
> + size_t val_len)
> +{
> + return cros_ucsi_read(ucsi, UCSI_MESSAGE_IN, val, val_len);
> +}
> +
> +static int cros_ucsi_async_control(struct ucsi *ucsi, u64 cmd)
> +{
> + struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi);
> + u8 ec_buf[sizeof(struct ec_params_ucsi_ppm_set) + sizeof(cmd)];
> + struct ec_params_ucsi_ppm_set *req = (struct ec_params_ucsi_ppm_set *) ec_buf;
> + int ret;
> +
> + req->offset = UCSI_CONTROL;
> + memcpy(req->data, &cmd, sizeof(cmd));
> + ret = cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_SET,
> + req, sizeof(ec_buf), NULL, 0);
> + if (ret < 0) {
> + dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_SET: error=%d", ret);
> + return ret;
> + }
> + return 0;
> +}
> +
> +static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd)
> +{
> + struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi);
> + int ret;
> +
> + ret = ucsi_sync_control_common(ucsi, cmd);
> + switch (ret) {
> + case -EBUSY:
> + /* EC may return -EBUSY if CCI.busy is set.
> + * Convert this to a timeout.
> + */
> + case -ETIMEDOUT:
> + /* Schedule recovery attempt when we timeout
> + * or tried to send a command while still busy.
> + */
> + cancel_delayed_work_sync(&udata->write_tmo);
> + schedule_delayed_work(&udata->write_tmo,
> + msecs_to_jiffies(WRITE_TMO_MS));
> + break;
> + case 0:
> + /* Successful write. Cancel any pending recovery work. */
> + cancel_delayed_work_sync(&udata->write_tmo);
> + break;
> + }
> +
> + return ret;
> +}
> +
> +struct ucsi_operations cros_ucsi_ops = {
> + .read_version = cros_ucsi_read_version,
> + .read_cci = cros_ucsi_read_cci,
> + .read_message_in = cros_ucsi_read_message_in,
> + .async_control = cros_ucsi_async_control,
> + .sync_control = cros_ucsi_sync_control,
> +};
> +
> +static void cros_ucsi_work(struct work_struct *work)
> +{
> + struct cros_ucsi_data *udata = container_of(work, struct cros_ucsi_data, work);
> + u32 cci;
> +
> + if (cros_ucsi_read_cci(udata->ucsi, &cci))
> + return;
> +
> + ucsi_notify_common(udata->ucsi, cci);
> +}
> +
> +static void cros_ucsi_write_timeout(struct work_struct *work)
> +{
> + struct cros_ucsi_data *udata =
> + container_of(work, struct cros_ucsi_data, write_tmo.work);
> + u32 cci;
> + u64 cmd;
> +
> + if (cros_ucsi_read(udata->ucsi, UCSI_CCI, &cci, sizeof(cci))) {
> + dev_err(udata->dev,
> + "Reading CCI failed; no write timeout recovery possible.");
> + return;
> + }
> +
> + if (cci & UCSI_CCI_BUSY) {
> + udata->tmo_counter++;
> +
> + if (udata->tmo_counter <= WRITE_TMO_CTR_MAX)
> + schedule_delayed_work(&udata->write_tmo,
> + msecs_to_jiffies(WRITE_TMO_MS));
> + else
> + dev_err(udata->dev,
> + "PPM unresponsive - too many write timeouts.");
> +
> + return;
> + }
> +
> + /* No longer busy means we can reset our timeout counter. */
> + udata->tmo_counter = 0;
> +
> + /* Need to ack previous command which may have timed out. */
> + if (cci & UCSI_CCI_COMMAND_COMPLETE) {
> + cmd = UCSI_ACK_CC_CI | UCSI_ACK_COMMAND_COMPLETE;
> + cros_ucsi_async_control(udata->ucsi, cmd);
> +
> + /* Check again after a few seconds that the system has
> + * recovered to make sure our async write above was successful.
> + */
> + schedule_delayed_work(&udata->write_tmo,
> + msecs_to_jiffies(WRITE_TMO_MS));
> + return;
> + }
> +
> + /* We recovered from a previous timeout. Treat this as a recovery from
> + * suspend and call resume.
> + */
> + ucsi_resume(udata->ucsi);
> +}
> +
> +static int cros_ucsi_event(struct notifier_block *nb,
> + unsigned long host_event, void *_notify)
> +{
> + struct cros_ucsi_data *udata = container_of(nb, struct cros_ucsi_data, nb);
> +
> + if (!(host_event & PD_EVENT_PPM))
> + return NOTIFY_OK;
> +
> + dev_dbg(udata->dev, "UCSI notification received");
> + flush_work(&udata->work);
> + schedule_work(&udata->work);
> +
> + return NOTIFY_OK;
> +}
> +
> +static void cros_ucsi_destroy(struct cros_ucsi_data *udata)
> +{
> + cros_usbpd_unregister_notify(&udata->nb);
> + cancel_delayed_work_sync(&udata->write_tmo);
> + cancel_work_sync(&udata->work);
> + ucsi_destroy(udata->ucsi);
> +}
> +
> +static int cros_ucsi_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct cros_ec_dev *ec_data = dev_get_drvdata(dev->parent);
> + struct cros_ucsi_data *udata;
> + int ret;
> +
> + udata = devm_kzalloc(dev, sizeof(*udata), GFP_KERNEL);
> + if (!udata)
> + return -ENOMEM;
> +
> + udata->dev = dev;
> +
> + udata->ec = ec_data->ec_dev;
> + if (!udata->ec) {
> + dev_err(dev, "couldn't find parent EC device");
> + return -ENODEV;
> + }
> +
> + platform_set_drvdata(pdev, udata);
> +
> + INIT_WORK(&udata->work, cros_ucsi_work);
> + INIT_DELAYED_WORK(&udata->write_tmo, cros_ucsi_write_timeout);
> + init_completion(&udata->complete);
> +
> + udata->ucsi = ucsi_create(dev, &cros_ucsi_ops);
> + if (IS_ERR(udata->ucsi)) {
> + dev_err(dev, "failed to allocate UCSI instance");
> + return PTR_ERR(udata->ucsi);
> + }
> +
> + ucsi_set_drvdata(udata->ucsi, udata);
> +
> + udata->nb.notifier_call = cros_ucsi_event;
> + ret = cros_usbpd_register_notify(&udata->nb);
> + if (ret) {
> + dev_err(dev, "failed to register notifier: error=%d", ret);
> + ucsi_destroy(udata->ucsi);
> + return ret;
> + }
> +
> + ret = ucsi_register(udata->ucsi);
> + if (ret) {
> + dev_err(dev, "failed to register UCSI: error=%d", ret);
> + cros_ucsi_destroy(udata);
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> +static void cros_ucsi_remove(struct platform_device *dev)
> +{
> + struct cros_ucsi_data *udata = platform_get_drvdata(dev);
> +
> + ucsi_unregister(udata->ucsi);
> + cros_ucsi_destroy(udata);
> +}
> +
> +static int __maybe_unused cros_ucsi_suspend(struct device *dev)
> +{
> + struct cros_ucsi_data *udata = dev_get_drvdata(dev);
> +
> + cancel_delayed_work_sync(&udata->write_tmo);
> + cancel_work_sync(&udata->work);
> +
> + return 0;
> +}
> +
> +static void __maybe_unused cros_ucsi_complete(struct device *dev)
> +{
> + struct cros_ucsi_data *udata = dev_get_drvdata(dev);
> +
> + ucsi_resume(udata->ucsi);
> +}
> +
> +/*
> + * UCSI protocol is also used on ChromeOS platforms which reply on
> + * cros_ec_lpc.c driver for communication with embedded controller (EC).
> + * On such platforms communication with the EC is not available until
> + * the .complete() callback of the cros_ec_lpc driver is executed.
> + * For this reason we delay ucsi_resume() until the .complete() stage
> + * otherwise UCSI SET_NOTIFICATION_ENABLE command will fail and we won't
> + * receive any UCSI notifications from the EC where PPM is implemented.
> + */
> +static const struct dev_pm_ops cros_ucsi_pm_ops = {
> +#ifdef CONFIG_PM_SLEEP
> + .suspend = cros_ucsi_suspend,
> + .complete = cros_ucsi_complete,
> +#endif
> +};
> +
> +static const struct platform_device_id cros_ucsi_id[] = {
> + { KBUILD_MODNAME, 0 },
> + {}
> +};
> +MODULE_DEVICE_TABLE(platform, cros_ucsi_id);
> +
> +static struct platform_driver cros_ucsi_driver = {
> + .driver = {
> + .name = KBUILD_MODNAME,
> + .pm = &cros_ucsi_pm_ops,
> + },
> + .id_table = cros_ucsi_id,
> + .probe = cros_ucsi_probe,
> + .remove = cros_ucsi_remove,
> +};
> +
> +module_platform_driver(cros_ucsi_driver);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_DESCRIPTION("UCSI driver for ChromeOS EC");
> --
> 2.47.1.613.gc27f4b7a9f-goog
--
heikki
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] driver/platform/chrome: Update cros_ec_trace with new USCI commands
2025-01-06 18:43 ` Gwendal Grignou
@ 2025-01-07 10:33 ` Greg KH
0 siblings, 0 replies; 10+ messages in thread
From: Greg KH @ 2025-01-07 10:33 UTC (permalink / raw)
To: Gwendal Grignou
Cc: ukaszb, abhishekpandit, bleung, chrome-platform, dmitry.baryshkov,
heikki.krogerus, jthies, linux-usb, pholla, tzungbi
On Mon, Jan 06, 2025 at 10:43:20AM -0800, Gwendal Grignou wrote:
> On Sat, Jan 4, 2025 at 12:13 AM Greg KH <gregkh@linuxfoundation.org> wrote:
> >
> > On Fri, Jan 03, 2025 at 03:34:07PM -0800, Gwendal Grignou wrote:
> > > Add this patch to "platform/chrome: Update ChromeOS EC header for UCSI"
> >
> > I do not understand this changelog text, sorry. How can you "add"
> > something to an existing change?
> >
> > > to add the new commands form cros_ec_commands.h in the tracer so that
> > > they are nicely decoded. Enable the tracer with:
> > > cd /sys/kernel/debug/tracing
> > > echo 1 > events/cros_ec/enable
> > > echo 1 > tracing_on
> > > cat trace_pipe
> >
> > We don't need to document how to enable a tracepoint here in the
> > changelog, right? That's going to get lost and why is this new one
> > somehow special?
> >
> > confused,
> Sorry, I did not use `git send-email` appropriately: the code snippet
> inside the email was not meant to be a standalone patch, but to be
> added to patch v12 1/2 "platform/chrome: Update ChromeOS EC header for
> UCSI".
> If this is too late, that's fine; I will send a proper kernel patch
> through the chrome-platform@lists.linux.dev mailing list.
Please send a proper fix as obviously we can not merge commits, you know
this :(
thanks,
greg k-h
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-01-07 10:33 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-31 13:10 [PATCH v12 0/2] usb: typec: Implement UCSI driver for ChromeOS Łukasz Bartosik
2024-12-31 13:10 ` [PATCH v12 1/2] platform/chrome: Update ChromeOS EC header for UCSI Łukasz Bartosik
2025-01-03 23:34 ` [PATCH] driver/platform/chrome: Update cros_ec_trace with new USCI commands Gwendal Grignou
2025-01-04 7:55 ` kernel test robot
2025-01-04 8:12 ` Greg KH
2025-01-06 18:43 ` Gwendal Grignou
2025-01-07 10:33 ` Greg KH
2025-01-04 16:27 ` kernel test robot
2024-12-31 13:10 ` [PATCH v12 2/2] usb: typec: ucsi: Implement ChromeOS UCSI driver Łukasz Bartosik
2025-01-07 10:28 ` Heikki Krogerus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox