* [PATCH v7 0/3] usb: typec: Implement UCSI driver for ChromeOS
@ 2024-11-15 15:52 Łukasz Bartosik
2024-11-15 15:52 ` [PATCH v7 1/3] platform/chrome: Update ChromeOS EC header for UCSI Łukasz Bartosik
` (2 more replies)
0 siblings, 3 replies; 14+ messages in thread
From: Łukasz Bartosik @ 2024-11-15 15:52 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman, Benson Leung
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 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.
Abhishek Pandit-Subedi (1):
usb: typec: cros_ec_ucsi: Recover from write timeouts
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 | 329 ++++++++++++++++++
.../linux/platform_data/cros_ec_commands.h | 28 +-
5 files changed, 377 insertions(+), 1 deletion(-)
create mode 100644 drivers/usb/typec/ucsi/cros_ec_ucsi.c
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v7 1/3] platform/chrome: Update ChromeOS EC header for UCSI
2024-11-15 15:52 [PATCH v7 0/3] usb: typec: Implement UCSI driver for ChromeOS Łukasz Bartosik
@ 2024-11-15 15:52 ` Łukasz Bartosik
2024-11-15 15:52 ` [PATCH v7 2/3] usb: typec: ucsi: Implement ChromeOS UCSI driver Łukasz Bartosik
2024-11-15 15:52 ` [PATCH v7 3/3] usb: typec: cros_ec_ucsi: Recover from write timeouts Łukasz Bartosik
2 siblings, 0 replies; 14+ messages in thread
From: Łukasz Bartosik @ 2024-11-15 15:52 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman, Benson Leung
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 e574b790be6f..8dbb6a769e4f 100644
--- a/include/linux/platform_data/cros_ec_commands.h
+++ b/include/linux/platform_data/cros_ec_commands.h
@@ -5012,8 +5012,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 */
@@ -6073,6 +6076,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.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v7 2/3] usb: typec: ucsi: Implement ChromeOS UCSI driver
2024-11-15 15:52 [PATCH v7 0/3] usb: typec: Implement UCSI driver for ChromeOS Łukasz Bartosik
2024-11-15 15:52 ` [PATCH v7 1/3] platform/chrome: Update ChromeOS EC header for UCSI Łukasz Bartosik
@ 2024-11-15 15:52 ` Łukasz Bartosik
2024-11-15 17:00 ` Dmitry Baryshkov
2024-11-28 14:46 ` Heikki Krogerus
2024-11-15 15:52 ` [PATCH v7 3/3] usb: typec: cros_ec_ucsi: Recover from write timeouts Łukasz Bartosik
2 siblings, 2 replies; 14+ messages in thread
From: Łukasz Bartosik @ 2024-11-15 15:52 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman, Benson Leung
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 | 248 ++++++++++++++++++++++++++
4 files changed, 269 insertions(+)
create mode 100644 drivers/usb/typec/ucsi/cros_ec_ucsi.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 21fdaa19229a..b5c57bb68c44 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5389,6 +5389,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..aae0bf106494
--- /dev/null
+++ b/drivers/usb/typec/ucsi/cros_ec_ucsi.c
@@ -0,0 +1,248 @@
+// 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/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 miliseconds the cros_ec_ucsi driver
+ * will wait for a response to a command or and ack.
+ */
+#define WRITE_TMO_MS 5000
+
+struct cros_ucsi_data {
+ struct device *dev;
+ struct ucsi *ucsi;
+
+ struct cros_ec_device *ec;
+ struct notifier_block nb;
+ struct work_struct work;
+
+ 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)
+{
+ return ucsi_sync_control_common(ucsi, cmd);
+}
+
+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 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_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_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_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);
+}
+
+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.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v7 3/3] usb: typec: cros_ec_ucsi: Recover from write timeouts
2024-11-15 15:52 [PATCH v7 0/3] usb: typec: Implement UCSI driver for ChromeOS Łukasz Bartosik
2024-11-15 15:52 ` [PATCH v7 1/3] platform/chrome: Update ChromeOS EC header for UCSI Łukasz Bartosik
2024-11-15 15:52 ` [PATCH v7 2/3] usb: typec: ucsi: Implement ChromeOS UCSI driver Łukasz Bartosik
@ 2024-11-15 15:52 ` Łukasz Bartosik
2 siblings, 0 replies; 14+ messages in thread
From: Łukasz Bartosik @ 2024-11-15 15:52 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman, Benson Leung
Cc: Abhishek Pandit-Subedi, Jameson Thies, Pavan Holla, Tzung-Bi Shih,
linux-usb, chrome-platform
From: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
In a suspend-resume edge case, the OPM is timing out in ucsi_resume and
the PPM is getting stuck waiting for a command complete ack. Add a write
timeout recovery task that will get us out of this state.
Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
---
drivers/usb/typec/ucsi/cros_ec_ucsi.c | 83 ++++++++++++++++++++++++++-
1 file changed, 82 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/typec/ucsi/cros_ec_ucsi.c b/drivers/usb/typec/ucsi/cros_ec_ucsi.c
index aae0bf106494..3e6b59aba275 100644
--- a/drivers/usb/typec/ucsi/cros_ec_ucsi.c
+++ b/drivers/usb/typec/ucsi/cros_ec_ucsi.c
@@ -7,6 +7,7 @@
#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>
@@ -29,6 +30,9 @@
*/
#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;
@@ -36,6 +40,8 @@ struct cros_ucsi_data {
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;
@@ -101,7 +107,33 @@ static int cros_ucsi_async_control(struct ucsi *ucsi, u64 cmd)
static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd)
{
- return ucsi_sync_control_common(ucsi, cmd);
+ struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi);
+ int ret;
+
+ ret = ucsi_sync_control_common(ucsi, cmd);
+ if (ret)
+ goto out;
+
+ /* Successful write. Cancel any pending recovery work. */
+ cancel_delayed_work_sync(&udata->write_tmo);
+
+ return 0;
+out:
+ /* EC may return -EBUSY if CCI.busy is set. Convert this to a timeout.
+ */
+ if (ret == -EBUSY)
+ ret = -ETIMEDOUT;
+
+ /* Schedule recovery attempt when we timeout or tried to send a command
+ * while still busy.
+ */
+ if (ret == -ETIMEDOUT) {
+ cancel_delayed_work_sync(&udata->write_tmo);
+ schedule_delayed_work(&udata->write_tmo,
+ msecs_to_jiffies(WRITE_TMO_MS));
+ }
+
+ return ret;
}
struct ucsi_operations cros_ucsi_ops = {
@@ -123,6 +155,54 @@ static void cros_ucsi_work(struct work_struct *work)
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)
{
@@ -167,6 +247,7 @@ static int cros_ucsi_probe(struct platform_device *pdev)
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);
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v7 2/3] usb: typec: ucsi: Implement ChromeOS UCSI driver
2024-11-15 15:52 ` [PATCH v7 2/3] usb: typec: ucsi: Implement ChromeOS UCSI driver Łukasz Bartosik
@ 2024-11-15 17:00 ` Dmitry Baryshkov
2024-11-18 10:09 ` Łukasz Bartosik
2024-11-28 14:46 ` Heikki Krogerus
1 sibling, 1 reply; 14+ messages in thread
From: Dmitry Baryshkov @ 2024-11-15 17:00 UTC (permalink / raw)
To: Łukasz Bartosik
Cc: Heikki Krogerus, Greg Kroah-Hartman, Benson Leung,
Abhishek Pandit-Subedi, Jameson Thies, Pavan Holla, Tzung-Bi Shih,
linux-usb, chrome-platform
On Fri, Nov 15, 2024 at 03:52:33PM +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>
> ---
> MAINTAINERS | 7 +
> drivers/usb/typec/ucsi/Kconfig | 13 ++
> drivers/usb/typec/ucsi/Makefile | 1 +
> drivers/usb/typec/ucsi/cros_ec_ucsi.c | 248 ++++++++++++++++++++++++++
> 4 files changed, 269 insertions(+)
> create mode 100644 drivers/usb/typec/ucsi/cros_ec_ucsi.c
> +static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd)
> +{
> + return ucsi_sync_control_common(ucsi, cmd);
> +}
> +
> +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,
.sync_control = ucsi_sync_control_common,
> +};
> +
[...]
> +
> +static int __maybe_unused cros_ucsi_suspend(struct device *dev)
> +{
> + struct cros_ucsi_data *udata = dev_get_drvdata(dev);
> +
> + 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);
> +}
> +
> +static const struct dev_pm_ops cros_ucsi_pm_ops = {
> +#ifdef CONFIG_PM_SLEEP
> + .suspend = cros_ucsi_suspend,
> + .complete = cros_ucsi_complete,
> +#endif
SET_SYSTEM_SLEEP_PM_OPS ? Or even better, DEFINE_SIMPLE_DEV_PM_OPS() ?
What is the reason for using complete() instead of resume()?
> +};
> +
> +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.0.338.g60cca15819-goog
>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v7 2/3] usb: typec: ucsi: Implement ChromeOS UCSI driver
2024-11-15 17:00 ` Dmitry Baryshkov
@ 2024-11-18 10:09 ` Łukasz Bartosik
2024-11-18 10:21 ` Dmitry Baryshkov
0 siblings, 1 reply; 14+ messages in thread
From: Łukasz Bartosik @ 2024-11-18 10:09 UTC (permalink / raw)
To: Dmitry Baryshkov
Cc: Heikki Krogerus, Greg Kroah-Hartman, Benson Leung,
Abhishek Pandit-Subedi, Jameson Thies, Pavan Holla, Tzung-Bi Shih,
linux-usb, chrome-platform
On Fri, Nov 15, 2024 at 6:00 PM Dmitry Baryshkov
<dmitry.baryshkov@linaro.org> wrote:
>
> On Fri, Nov 15, 2024 at 03:52:33PM +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>
> > ---
> > MAINTAINERS | 7 +
> > drivers/usb/typec/ucsi/Kconfig | 13 ++
> > drivers/usb/typec/ucsi/Makefile | 1 +
> > drivers/usb/typec/ucsi/cros_ec_ucsi.c | 248 ++++++++++++++++++++++++++
> > 4 files changed, 269 insertions(+)
> > create mode 100644 drivers/usb/typec/ucsi/cros_ec_ucsi.c
>
> > +static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd)
> > +{
> > + return ucsi_sync_control_common(ucsi, cmd);
> > +}
> > +
> > +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,
>
> .sync_control = ucsi_sync_control_common,
>
I will change.
> > +};
> > +
>
> [...]
>
> > +
> > +static int __maybe_unused cros_ucsi_suspend(struct device *dev)
> > +{
> > + struct cros_ucsi_data *udata = dev_get_drvdata(dev);
> > +
> > + 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);
> > +}
> > +
> > +static const struct dev_pm_ops cros_ucsi_pm_ops = {
> > +#ifdef CONFIG_PM_SLEEP
> > + .suspend = cros_ucsi_suspend,
> > + .complete = cros_ucsi_complete,
> > +#endif
>
> SET_SYSTEM_SLEEP_PM_OPS ? Or even better, DEFINE_SIMPLE_DEV_PM_OPS() ?
>
> What is the reason for using complete() instead of resume()?
>
Due to change in
https://lore.kernel.org/linux-usb/20240910101527.603452-1-ukaszb@chromium.org/T/#m25bc17cc0a8d30439830415018c7f44f342900d1
we moved from using macro SIMPLE_DEV_PM_OPS and resume() to complete().
Per Heikki's suggestion I also squashed this change into "usb: typec:
ucsi: Implement ChromeOS UCSI driver".
Thank you,
Lukasz
> > +};
> > +
> > +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.0.338.g60cca15819-goog
> >
>
> --
> With best wishes
> Dmitry
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v7 2/3] usb: typec: ucsi: Implement ChromeOS UCSI driver
2024-11-18 10:09 ` Łukasz Bartosik
@ 2024-11-18 10:21 ` Dmitry Baryshkov
2024-11-18 10:38 ` Łukasz Bartosik
0 siblings, 1 reply; 14+ messages in thread
From: Dmitry Baryshkov @ 2024-11-18 10:21 UTC (permalink / raw)
To: Łukasz Bartosik
Cc: Heikki Krogerus, Greg Kroah-Hartman, Benson Leung,
Abhishek Pandit-Subedi, Jameson Thies, Pavan Holla, Tzung-Bi Shih,
linux-usb, chrome-platform
On Mon, 18 Nov 2024 at 12:10, Łukasz Bartosik <ukaszb@chromium.org> wrote:
>
> On Fri, Nov 15, 2024 at 6:00 PM Dmitry Baryshkov
> <dmitry.baryshkov@linaro.org> wrote:
> >
> > On Fri, Nov 15, 2024 at 03:52:33PM +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>
> > > ---
> > > MAINTAINERS | 7 +
> > > drivers/usb/typec/ucsi/Kconfig | 13 ++
> > > drivers/usb/typec/ucsi/Makefile | 1 +
> > > drivers/usb/typec/ucsi/cros_ec_ucsi.c | 248 ++++++++++++++++++++++++++
> > > 4 files changed, 269 insertions(+)
> > > create mode 100644 drivers/usb/typec/ucsi/cros_ec_ucsi.c
> >
> > > +static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd)
> > > +{
> > > + return ucsi_sync_control_common(ucsi, cmd);
> > > +}
> > > +
> > > +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,
> >
> > .sync_control = ucsi_sync_control_common,
> >
>
> I will change.
>
> > > +};
> > > +
> >
> > [...]
> >
> > > +
> > > +static int __maybe_unused cros_ucsi_suspend(struct device *dev)
> > > +{
> > > + struct cros_ucsi_data *udata = dev_get_drvdata(dev);
> > > +
> > > + 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);
> > > +}
> > > +
> > > +static const struct dev_pm_ops cros_ucsi_pm_ops = {
> > > +#ifdef CONFIG_PM_SLEEP
> > > + .suspend = cros_ucsi_suspend,
> > > + .complete = cros_ucsi_complete,
> > > +#endif
> >
> > SET_SYSTEM_SLEEP_PM_OPS ? Or even better, DEFINE_SIMPLE_DEV_PM_OPS() ?
> >
> > What is the reason for using complete() instead of resume()?
> >
>
> Due to change in
> https://lore.kernel.org/linux-usb/20240910101527.603452-1-ukaszb@chromium.org/T/#m25bc17cc0a8d30439830415018c7f44f342900d1
> we moved from using macro SIMPLE_DEV_PM_OPS and resume() to complete().
> Per Heikki's suggestion I also squashed this change into "usb: typec:
> ucsi: Implement ChromeOS UCSI driver".
Neither original patch, nor this one document, why this is necessary
>
> Thank you,
> Lukasz
>
> > > +};
> > > +
> > > +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.0.338.g60cca15819-goog
> > >
> >
> > --
> > With best wishes
> > Dmitry
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v7 2/3] usb: typec: ucsi: Implement ChromeOS UCSI driver
2024-11-18 10:21 ` Dmitry Baryshkov
@ 2024-11-18 10:38 ` Łukasz Bartosik
2024-11-18 11:08 ` Dmitry Baryshkov
0 siblings, 1 reply; 14+ messages in thread
From: Łukasz Bartosik @ 2024-11-18 10:38 UTC (permalink / raw)
To: Dmitry Baryshkov
Cc: Heikki Krogerus, Greg Kroah-Hartman, Benson Leung,
Abhishek Pandit-Subedi, Jameson Thies, Pavan Holla, Tzung-Bi Shih,
linux-usb, chrome-platform
On Mon, Nov 18, 2024 at 11:21 AM Dmitry Baryshkov
<dmitry.baryshkov@linaro.org> wrote:
>
> On Mon, 18 Nov 2024 at 12:10, Łukasz Bartosik <ukaszb@chromium.org> wrote:
> >
> > On Fri, Nov 15, 2024 at 6:00 PM Dmitry Baryshkov
> > <dmitry.baryshkov@linaro.org> wrote:
> > >
> > > On Fri, Nov 15, 2024 at 03:52:33PM +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>
> > > > ---
> > > > MAINTAINERS | 7 +
> > > > drivers/usb/typec/ucsi/Kconfig | 13 ++
> > > > drivers/usb/typec/ucsi/Makefile | 1 +
> > > > drivers/usb/typec/ucsi/cros_ec_ucsi.c | 248 ++++++++++++++++++++++++++
> > > > 4 files changed, 269 insertions(+)
> > > > create mode 100644 drivers/usb/typec/ucsi/cros_ec_ucsi.c
> > >
> > > > +static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd)
> > > > +{
> > > > + return ucsi_sync_control_common(ucsi, cmd);
> > > > +}
> > > > +
> > > > +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,
> > >
> > > .sync_control = ucsi_sync_control_common,
> > >
> >
> > I will change.
> >
> > > > +};
> > > > +
> > >
> > > [...]
> > >
> > > > +
> > > > +static int __maybe_unused cros_ucsi_suspend(struct device *dev)
> > > > +{
> > > > + struct cros_ucsi_data *udata = dev_get_drvdata(dev);
> > > > +
> > > > + 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);
> > > > +}
> > > > +
> > > > +static const struct dev_pm_ops cros_ucsi_pm_ops = {
> > > > +#ifdef CONFIG_PM_SLEEP
> > > > + .suspend = cros_ucsi_suspend,
> > > > + .complete = cros_ucsi_complete,
> > > > +#endif
> > >
> > > SET_SYSTEM_SLEEP_PM_OPS ? Or even better, DEFINE_SIMPLE_DEV_PM_OPS() ?
> > >
> > > What is the reason for using complete() instead of resume()?
> > >
> >
> > Due to change in
> > https://lore.kernel.org/linux-usb/20240910101527.603452-1-ukaszb@chromium.org/T/#m25bc17cc0a8d30439830415018c7f44f342900d1
> > we moved from using macro SIMPLE_DEV_PM_OPS and resume() to complete().
> > Per Heikki's suggestion I also squashed this change into "usb: typec:
> > ucsi: Implement ChromeOS UCSI driver".
>
> Neither original patch, nor this one document, why this is necessary
>
The https://lore.kernel.org/linux-usb/20240910101527.603452-1-ukaszb@chromium.org/T/#m25bc17cc0a8d30439830415018c7f44f342900d1
commit messages says:
"On platforms using cros_ec_lpc, resume is split into .resume_early
and .complete.
To avoid missing EC events, use .complete to schedule work when resuming."
I will add this as a comment on top of cros_ucsi_pm_ops struct.
Do you find it sufficient ?
Thanks,
Lukasz
> >
> > Thank you,
> > Lukasz
> >
> > > > +};
> > > > +
> > > > +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.0.338.g60cca15819-goog
> > > >
> > >
> > > --
> > > With best wishes
> > > Dmitry
>
>
>
> --
> With best wishes
> Dmitry
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v7 2/3] usb: typec: ucsi: Implement ChromeOS UCSI driver
2024-11-18 10:38 ` Łukasz Bartosik
@ 2024-11-18 11:08 ` Dmitry Baryshkov
2024-11-18 11:18 ` Łukasz Bartosik
0 siblings, 1 reply; 14+ messages in thread
From: Dmitry Baryshkov @ 2024-11-18 11:08 UTC (permalink / raw)
To: Łukasz Bartosik
Cc: Heikki Krogerus, Greg Kroah-Hartman, Benson Leung,
Abhishek Pandit-Subedi, Jameson Thies, Pavan Holla, Tzung-Bi Shih,
linux-usb, chrome-platform
On Mon, 18 Nov 2024 at 12:38, Łukasz Bartosik <ukaszb@chromium.org> wrote:
>
> On Mon, Nov 18, 2024 at 11:21 AM Dmitry Baryshkov
> <dmitry.baryshkov@linaro.org> wrote:
> >
> > On Mon, 18 Nov 2024 at 12:10, Łukasz Bartosik <ukaszb@chromium.org> wrote:
> > >
> > > On Fri, Nov 15, 2024 at 6:00 PM Dmitry Baryshkov
> > > <dmitry.baryshkov@linaro.org> wrote:
> > > >
> > > > On Fri, Nov 15, 2024 at 03:52:33PM +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>
> > > > > ---
> > > > > MAINTAINERS | 7 +
> > > > > drivers/usb/typec/ucsi/Kconfig | 13 ++
> > > > > drivers/usb/typec/ucsi/Makefile | 1 +
> > > > > drivers/usb/typec/ucsi/cros_ec_ucsi.c | 248 ++++++++++++++++++++++++++
> > > > > 4 files changed, 269 insertions(+)
> > > > > create mode 100644 drivers/usb/typec/ucsi/cros_ec_ucsi.c
> > > >
> > > > > +static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd)
> > > > > +{
> > > > > + return ucsi_sync_control_common(ucsi, cmd);
> > > > > +}
> > > > > +
> > > > > +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,
> > > >
> > > > .sync_control = ucsi_sync_control_common,
> > > >
> > >
> > > I will change.
> > >
> > > > > +};
> > > > > +
> > > >
> > > > [...]
> > > >
> > > > > +
> > > > > +static int __maybe_unused cros_ucsi_suspend(struct device *dev)
> > > > > +{
> > > > > + struct cros_ucsi_data *udata = dev_get_drvdata(dev);
> > > > > +
> > > > > + 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);
> > > > > +}
> > > > > +
> > > > > +static const struct dev_pm_ops cros_ucsi_pm_ops = {
> > > > > +#ifdef CONFIG_PM_SLEEP
> > > > > + .suspend = cros_ucsi_suspend,
> > > > > + .complete = cros_ucsi_complete,
> > > > > +#endif
> > > >
> > > > SET_SYSTEM_SLEEP_PM_OPS ? Or even better, DEFINE_SIMPLE_DEV_PM_OPS() ?
> > > >
> > > > What is the reason for using complete() instead of resume()?
> > > >
> > >
> > > Due to change in
> > > https://lore.kernel.org/linux-usb/20240910101527.603452-1-ukaszb@chromium.org/T/#m25bc17cc0a8d30439830415018c7f44f342900d1
> > > we moved from using macro SIMPLE_DEV_PM_OPS and resume() to complete().
> > > Per Heikki's suggestion I also squashed this change into "usb: typec:
> > > ucsi: Implement ChromeOS UCSI driver".
> >
> > Neither original patch, nor this one document, why this is necessary
> >
>
> The https://lore.kernel.org/linux-usb/20240910101527.603452-1-ukaszb@chromium.org/T/#m25bc17cc0a8d30439830415018c7f44f342900d1
> commit messages says:
> "On platforms using cros_ec_lpc, resume is split into .resume_early
> and .complete.
> To avoid missing EC events, use .complete to schedule work when resuming."
>
> I will add this as a comment on top of cros_ucsi_pm_ops struct.
> Do you find it sufficient ?
IMHO, no
>
> Thanks,
> Lukasz
>
> > >
> > > Thank you,
> > > Lukasz
> > >
> > > > > +};
> > > > > +
> > > > > +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.0.338.g60cca15819-goog
> > > > >
> > > >
> > > > --
> > > > With best wishes
> > > > Dmitry
> >
> >
> >
> > --
> > With best wishes
> > Dmitry
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v7 2/3] usb: typec: ucsi: Implement ChromeOS UCSI driver
2024-11-18 11:08 ` Dmitry Baryshkov
@ 2024-11-18 11:18 ` Łukasz Bartosik
2024-11-21 23:05 ` Dmitry Baryshkov
0 siblings, 1 reply; 14+ messages in thread
From: Łukasz Bartosik @ 2024-11-18 11:18 UTC (permalink / raw)
To: Dmitry Baryshkov
Cc: Heikki Krogerus, Greg Kroah-Hartman, Benson Leung,
Abhishek Pandit-Subedi, Jameson Thies, Pavan Holla, Tzung-Bi Shih,
linux-usb, chrome-platform
On Mon, Nov 18, 2024 at 12:08 PM Dmitry Baryshkov
<dmitry.baryshkov@linaro.org> wrote:
>
> On Mon, 18 Nov 2024 at 12:38, Łukasz Bartosik <ukaszb@chromium.org> wrote:
> >
> > On Mon, Nov 18, 2024 at 11:21 AM Dmitry Baryshkov
> > <dmitry.baryshkov@linaro.org> wrote:
> > >
> > > On Mon, 18 Nov 2024 at 12:10, Łukasz Bartosik <ukaszb@chromium.org> wrote:
> > > >
> > > > On Fri, Nov 15, 2024 at 6:00 PM Dmitry Baryshkov
> > > > <dmitry.baryshkov@linaro.org> wrote:
> > > > >
> > > > > On Fri, Nov 15, 2024 at 03:52:33PM +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>
> > > > > > ---
> > > > > > MAINTAINERS | 7 +
> > > > > > drivers/usb/typec/ucsi/Kconfig | 13 ++
> > > > > > drivers/usb/typec/ucsi/Makefile | 1 +
> > > > > > drivers/usb/typec/ucsi/cros_ec_ucsi.c | 248 ++++++++++++++++++++++++++
> > > > > > 4 files changed, 269 insertions(+)
> > > > > > create mode 100644 drivers/usb/typec/ucsi/cros_ec_ucsi.c
> > > > >
> > > > > > +static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd)
> > > > > > +{
> > > > > > + return ucsi_sync_control_common(ucsi, cmd);
> > > > > > +}
> > > > > > +
> > > > > > +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,
> > > > >
> > > > > .sync_control = ucsi_sync_control_common,
> > > > >
> > > >
> > > > I will change.
> > > >
> > > > > > +};
> > > > > > +
> > > > >
> > > > > [...]
> > > > >
> > > > > > +
> > > > > > +static int __maybe_unused cros_ucsi_suspend(struct device *dev)
> > > > > > +{
> > > > > > + struct cros_ucsi_data *udata = dev_get_drvdata(dev);
> > > > > > +
> > > > > > + 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);
> > > > > > +}
> > > > > > +
> > > > > > +static const struct dev_pm_ops cros_ucsi_pm_ops = {
> > > > > > +#ifdef CONFIG_PM_SLEEP
> > > > > > + .suspend = cros_ucsi_suspend,
> > > > > > + .complete = cros_ucsi_complete,
> > > > > > +#endif
> > > > >
> > > > > SET_SYSTEM_SLEEP_PM_OPS ? Or even better, DEFINE_SIMPLE_DEV_PM_OPS() ?
> > > > >
> > > > > What is the reason for using complete() instead of resume()?
> > > > >
> > > >
> > > > Due to change in
> > > > https://lore.kernel.org/linux-usb/20240910101527.603452-1-ukaszb@chromium.org/T/#m25bc17cc0a8d30439830415018c7f44f342900d1
> > > > we moved from using macro SIMPLE_DEV_PM_OPS and resume() to complete().
> > > > Per Heikki's suggestion I also squashed this change into "usb: typec:
> > > > ucsi: Implement ChromeOS UCSI driver".
> > >
> > > Neither original patch, nor this one document, why this is necessary
> > >
> >
> > The https://lore.kernel.org/linux-usb/20240910101527.603452-1-ukaszb@chromium.org/T/#m25bc17cc0a8d30439830415018c7f44f342900d1
> > commit messages says:
> > "On platforms using cros_ec_lpc, resume is split into .resume_early
> > and .complete.
> > To avoid missing EC events, use .complete to schedule work when resuming."
> >
> > I will add this as a comment on top of cros_ucsi_pm_ops struct.
> > Do you find it sufficient ?
>
> IMHO, no
>
Ok. If you please tell me what is not clear or missing in this
explanation in your opinion
then I will update it.
Thanks,
Lukasz
> >
> > Thanks,
> > Lukasz
> >
> > > >
> > > > Thank you,
> > > > Lukasz
> > > >
> > > > > > +};
> > > > > > +
> > > > > > +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.0.338.g60cca15819-goog
> > > > > >
> > > > >
> > > > > --
> > > > > With best wishes
> > > > > Dmitry
> > >
> > >
> > >
> > > --
> > > With best wishes
> > > Dmitry
>
>
>
> --
> With best wishes
> Dmitry
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v7 2/3] usb: typec: ucsi: Implement ChromeOS UCSI driver
2024-11-18 11:18 ` Łukasz Bartosik
@ 2024-11-21 23:05 ` Dmitry Baryshkov
2024-11-28 10:09 ` Łukasz Bartosik
0 siblings, 1 reply; 14+ messages in thread
From: Dmitry Baryshkov @ 2024-11-21 23:05 UTC (permalink / raw)
To: Łukasz Bartosik
Cc: Heikki Krogerus, Greg Kroah-Hartman, Benson Leung,
Abhishek Pandit-Subedi, Jameson Thies, Pavan Holla, Tzung-Bi Shih,
linux-usb, chrome-platform
On Mon, Nov 18, 2024 at 12:18:17PM +0100, Łukasz Bartosik wrote:
> On Mon, Nov 18, 2024 at 12:08 PM Dmitry Baryshkov
> <dmitry.baryshkov@linaro.org> wrote:
> >
> > On Mon, 18 Nov 2024 at 12:38, Łukasz Bartosik <ukaszb@chromium.org> wrote:
> > >
> > > On Mon, Nov 18, 2024 at 11:21 AM Dmitry Baryshkov
> > > <dmitry.baryshkov@linaro.org> wrote:
> > > >
> > > > On Mon, 18 Nov 2024 at 12:10, Łukasz Bartosik <ukaszb@chromium.org> wrote:
> > > > >
> > > > > On Fri, Nov 15, 2024 at 6:00 PM Dmitry Baryshkov
> > > > > <dmitry.baryshkov@linaro.org> wrote:
> > > > > >
> > > > > > On Fri, Nov 15, 2024 at 03:52:33PM +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>
> > > > > > > ---
> > > > > > > MAINTAINERS | 7 +
> > > > > > > drivers/usb/typec/ucsi/Kconfig | 13 ++
> > > > > > > drivers/usb/typec/ucsi/Makefile | 1 +
> > > > > > > drivers/usb/typec/ucsi/cros_ec_ucsi.c | 248 ++++++++++++++++++++++++++
> > > > > > > 4 files changed, 269 insertions(+)
> > > > > > > create mode 100644 drivers/usb/typec/ucsi/cros_ec_ucsi.c
> > > > > >
> > > > > > > +static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd)
> > > > > > > +{
> > > > > > > + return ucsi_sync_control_common(ucsi, cmd);
> > > > > > > +}
> > > > > > > +
> > > > > > > +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,
> > > > > >
> > > > > > .sync_control = ucsi_sync_control_common,
> > > > > >
> > > > >
> > > > > I will change.
> > > > >
> > > > > > > +};
> > > > > > > +
> > > > > >
> > > > > > [...]
> > > > > >
> > > > > > > +
> > > > > > > +static int __maybe_unused cros_ucsi_suspend(struct device *dev)
> > > > > > > +{
> > > > > > > + struct cros_ucsi_data *udata = dev_get_drvdata(dev);
> > > > > > > +
> > > > > > > + 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);
> > > > > > > +}
> > > > > > > +
> > > > > > > +static const struct dev_pm_ops cros_ucsi_pm_ops = {
> > > > > > > +#ifdef CONFIG_PM_SLEEP
> > > > > > > + .suspend = cros_ucsi_suspend,
> > > > > > > + .complete = cros_ucsi_complete,
> > > > > > > +#endif
> > > > > >
> > > > > > SET_SYSTEM_SLEEP_PM_OPS ? Or even better, DEFINE_SIMPLE_DEV_PM_OPS() ?
> > > > > >
> > > > > > What is the reason for using complete() instead of resume()?
> > > > > >
> > > > >
> > > > > Due to change in
> > > > > https://lore.kernel.org/linux-usb/20240910101527.603452-1-ukaszb@chromium.org/T/#m25bc17cc0a8d30439830415018c7f44f342900d1
> > > > > we moved from using macro SIMPLE_DEV_PM_OPS and resume() to complete().
> > > > > Per Heikki's suggestion I also squashed this change into "usb: typec:
> > > > > ucsi: Implement ChromeOS UCSI driver".
> > > >
> > > > Neither original patch, nor this one document, why this is necessary
> > > >
> > >
> > > The https://lore.kernel.org/linux-usb/20240910101527.603452-1-ukaszb@chromium.org/T/#m25bc17cc0a8d30439830415018c7f44f342900d1
> > > commit messages says:
> > > "On platforms using cros_ec_lpc, resume is split into .resume_early
> > > and .complete.
> > > To avoid missing EC events, use .complete to schedule work when resuming."
> > >
> > > I will add this as a comment on top of cros_ucsi_pm_ops struct.
> > > Do you find it sufficient ?
> >
> > IMHO, no
> >
>
> Ok. If you please tell me what is not clear or missing in this
> explanation in your opinion
> then I will update it.
For me it is a question of imbalance. The .complete() should be paired
with .prepare(), .suspend() with .resume(), etc. Also by using just
.suspend and .complete you are missing all other suspend/resume cases
which are covered by SET_SYSTEM_SLEEP_PM_OPS() or
SET_LATE_SYSTEM_SLEEP_PM_OPS().
So, back to your question. I'm reviewing the UCSI part. I don't know
anything about the cros_ec_lpc.c or any other CrOS EC drivers. You are
doing some non-standard thing in your driver. As such you should provide
a sensible explanation for it. If I understand correctly, it might be
something in line with "UCSI is used with the systems using
cros_ec_lpc.c. On such systems ... is not available until the
.complete() callback of the cros_ec_lpc is executed. For this reason,
delay ucsi_resume() until the .complete() stage."
>
> Thanks,
> Lukasz
>
> > >
> > > Thanks,
> > > Lukasz
> > >
> > > > >
> > > > > Thank you,
> > > > > Lukasz
> > > > >
> > > > > > > +};
> > > > > > > +
> > > > > > > +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.0.338.g60cca15819-goog
> > > > > > >
> > > > > >
> > > > > > --
> > > > > > With best wishes
> > > > > > Dmitry
> > > >
> > > >
> > > >
> > > > --
> > > > With best wishes
> > > > Dmitry
> >
> >
> >
> > --
> > With best wishes
> > Dmitry
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v7 2/3] usb: typec: ucsi: Implement ChromeOS UCSI driver
2024-11-21 23:05 ` Dmitry Baryshkov
@ 2024-11-28 10:09 ` Łukasz Bartosik
0 siblings, 0 replies; 14+ messages in thread
From: Łukasz Bartosik @ 2024-11-28 10:09 UTC (permalink / raw)
To: Dmitry Baryshkov
Cc: Heikki Krogerus, Greg Kroah-Hartman, Benson Leung,
Abhishek Pandit-Subedi, Jameson Thies, Pavan Holla, Tzung-Bi Shih,
linux-usb, chrome-platform
On Fri, Nov 22, 2024 at 12:05 AM Dmitry Baryshkov
<dmitry.baryshkov@linaro.org> wrote:
>
> On Mon, Nov 18, 2024 at 12:18:17PM +0100, Łukasz Bartosik wrote:
> > On Mon, Nov 18, 2024 at 12:08 PM Dmitry Baryshkov
> > <dmitry.baryshkov@linaro.org> wrote:
> > >
> > > On Mon, 18 Nov 2024 at 12:38, Łukasz Bartosik <ukaszb@chromium.org> wrote:
> > > >
> > > > On Mon, Nov 18, 2024 at 11:21 AM Dmitry Baryshkov
> > > > <dmitry.baryshkov@linaro.org> wrote:
> > > > >
> > > > > On Mon, 18 Nov 2024 at 12:10, Łukasz Bartosik <ukaszb@chromium.org> wrote:
> > > > > >
> > > > > > On Fri, Nov 15, 2024 at 6:00 PM Dmitry Baryshkov
> > > > > > <dmitry.baryshkov@linaro.org> wrote:
> > > > > > >
> > > > > > > On Fri, Nov 15, 2024 at 03:52:33PM +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>
> > > > > > > > ---
> > > > > > > > MAINTAINERS | 7 +
> > > > > > > > drivers/usb/typec/ucsi/Kconfig | 13 ++
> > > > > > > > drivers/usb/typec/ucsi/Makefile | 1 +
> > > > > > > > drivers/usb/typec/ucsi/cros_ec_ucsi.c | 248 ++++++++++++++++++++++++++
> > > > > > > > 4 files changed, 269 insertions(+)
> > > > > > > > create mode 100644 drivers/usb/typec/ucsi/cros_ec_ucsi.c
> > > > > > >
> > > > > > > > +static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd)
> > > > > > > > +{
> > > > > > > > + return ucsi_sync_control_common(ucsi, cmd);
> > > > > > > > +}
> > > > > > > > +
> > > > > > > > +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,
> > > > > > >
> > > > > > > .sync_control = ucsi_sync_control_common,
> > > > > > >
> > > > > >
> > > > > > I will change.
> > > > > >
> > > > > > > > +};
> > > > > > > > +
> > > > > > >
> > > > > > > [...]
> > > > > > >
> > > > > > > > +
> > > > > > > > +static int __maybe_unused cros_ucsi_suspend(struct device *dev)
> > > > > > > > +{
> > > > > > > > + struct cros_ucsi_data *udata = dev_get_drvdata(dev);
> > > > > > > > +
> > > > > > > > + 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);
> > > > > > > > +}
> > > > > > > > +
> > > > > > > > +static const struct dev_pm_ops cros_ucsi_pm_ops = {
> > > > > > > > +#ifdef CONFIG_PM_SLEEP
> > > > > > > > + .suspend = cros_ucsi_suspend,
> > > > > > > > + .complete = cros_ucsi_complete,
> > > > > > > > +#endif
> > > > > > >
> > > > > > > SET_SYSTEM_SLEEP_PM_OPS ? Or even better, DEFINE_SIMPLE_DEV_PM_OPS() ?
> > > > > > >
> > > > > > > What is the reason for using complete() instead of resume()?
> > > > > > >
> > > > > >
> > > > > > Due to change in
> > > > > > https://lore.kernel.org/linux-usb/20240910101527.603452-1-ukaszb@chromium.org/T/#m25bc17cc0a8d30439830415018c7f44f342900d1
> > > > > > we moved from using macro SIMPLE_DEV_PM_OPS and resume() to complete().
> > > > > > Per Heikki's suggestion I also squashed this change into "usb: typec:
> > > > > > ucsi: Implement ChromeOS UCSI driver".
> > > > >
> > > > > Neither original patch, nor this one document, why this is necessary
> > > > >
> > > >
> > > > The https://lore.kernel.org/linux-usb/20240910101527.603452-1-ukaszb@chromium.org/T/#m25bc17cc0a8d30439830415018c7f44f342900d1
> > > > commit messages says:
> > > > "On platforms using cros_ec_lpc, resume is split into .resume_early
> > > > and .complete.
> > > > To avoid missing EC events, use .complete to schedule work when resuming."
> > > >
> > > > I will add this as a comment on top of cros_ucsi_pm_ops struct.
> > > > Do you find it sufficient ?
> > >
> > > IMHO, no
> > >
> >
> > Ok. If you please tell me what is not clear or missing in this
> > explanation in your opinion
> > then I will update it.
>
> For me it is a question of imbalance. The .complete() should be paired
> with .prepare(), .suspend() with .resume(), etc. Also by using just
> .suspend and .complete you are missing all other suspend/resume cases
> which are covered by SET_SYSTEM_SLEEP_PM_OPS() or
> SET_LATE_SYSTEM_SLEEP_PM_OPS().
>
> So, back to your question. I'm reviewing the UCSI part. I don't know
> anything about the cros_ec_lpc.c or any other CrOS EC drivers. You are
> doing some non-standard thing in your driver. As such you should provide
> a sensible explanation for it. If I understand correctly, it might be
> something in line with "UCSI is used with the systems using
> cros_ec_lpc.c. On such systems ... is not available until the
> .complete() callback of the cros_ec_lpc is executed. For this reason,
> delay ucsi_resume() until the .complete() stage."
>
I will incorporate your comment.
Thanks,
Lukasz
> >
> > Thanks,
> > Lukasz
> >
> > > >
> > > > Thanks,
> > > > Lukasz
> > > >
> > > > > >
> > > > > > Thank you,
> > > > > > Lukasz
> > > > > >
> > > > > > > > +};
> > > > > > > > +
> > > > > > > > +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.0.338.g60cca15819-goog
> > > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > With best wishes
> > > > > > > Dmitry
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > With best wishes
> > > > > Dmitry
> > >
> > >
> > >
> > > --
> > > With best wishes
> > > Dmitry
>
> --
> With best wishes
> Dmitry
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v7 2/3] usb: typec: ucsi: Implement ChromeOS UCSI driver
2024-11-15 15:52 ` [PATCH v7 2/3] usb: typec: ucsi: Implement ChromeOS UCSI driver Łukasz Bartosik
2024-11-15 17:00 ` Dmitry Baryshkov
@ 2024-11-28 14:46 ` Heikki Krogerus
2024-11-28 15:37 ` Łukasz Bartosik
1 sibling, 1 reply; 14+ messages in thread
From: Heikki Krogerus @ 2024-11-28 14:46 UTC (permalink / raw)
To: Łukasz Bartosik
Cc: Greg Kroah-Hartman, Benson Leung, Abhishek Pandit-Subedi,
Jameson Thies, Pavan Holla, Tzung-Bi Shih, linux-usb,
chrome-platform
Hi Łukasz,
This LGTM, but since you'll send one more version in any case..
> +/*
> + * Maximum time in miliseconds the cros_ec_ucsi driver
> + * will wait for a response to a command or and ack.
> + */
> +#define WRITE_TMO_MS 5000
s/miliseconds/milliseconds/
thanks,
--
heikki
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v7 2/3] usb: typec: ucsi: Implement ChromeOS UCSI driver
2024-11-28 14:46 ` Heikki Krogerus
@ 2024-11-28 15:37 ` Łukasz Bartosik
0 siblings, 0 replies; 14+ messages in thread
From: Łukasz Bartosik @ 2024-11-28 15:37 UTC (permalink / raw)
To: Heikki Krogerus
Cc: Greg Kroah-Hartman, Benson Leung, Abhishek Pandit-Subedi,
Jameson Thies, Pavan Holla, Tzung-Bi Shih, linux-usb,
chrome-platform
On Thu, Nov 28, 2024 at 3:46 PM Heikki Krogerus
<heikki.krogerus@linux.intel.com> wrote:
>
> Hi Łukasz,
>
> This LGTM, but since you'll send one more version in any case..
>
> > +/*
> > + * Maximum time in miliseconds the cros_ec_ucsi driver
> > + * will wait for a response to a command or and ack.
> > + */
> > +#define WRITE_TMO_MS 5000
>
> s/miliseconds/milliseconds/
>
Thank you Heikki.
I will fix it.
Regards,
Lukasz
> thanks,
>
> --
> heikki
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2024-11-28 15:37 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-15 15:52 [PATCH v7 0/3] usb: typec: Implement UCSI driver for ChromeOS Łukasz Bartosik
2024-11-15 15:52 ` [PATCH v7 1/3] platform/chrome: Update ChromeOS EC header for UCSI Łukasz Bartosik
2024-11-15 15:52 ` [PATCH v7 2/3] usb: typec: ucsi: Implement ChromeOS UCSI driver Łukasz Bartosik
2024-11-15 17:00 ` Dmitry Baryshkov
2024-11-18 10:09 ` Łukasz Bartosik
2024-11-18 10:21 ` Dmitry Baryshkov
2024-11-18 10:38 ` Łukasz Bartosik
2024-11-18 11:08 ` Dmitry Baryshkov
2024-11-18 11:18 ` Łukasz Bartosik
2024-11-21 23:05 ` Dmitry Baryshkov
2024-11-28 10:09 ` Łukasz Bartosik
2024-11-28 14:46 ` Heikki Krogerus
2024-11-28 15:37 ` Łukasz Bartosik
2024-11-15 15:52 ` [PATCH v7 3/3] usb: typec: cros_ec_ucsi: Recover from write timeouts Łukasz Bartosik
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.