Skip to contentSkip to conversation

platform/chrome: cros_ec_uart: Add transport layer

PATCH Applied Mark Hasemeyer 2 participants 5 messages Dec 27, 2022 – Dec 28, 2022

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v13 1/3 platform/chrome: cros_ec_uart: Add transport layer

From: Bhanu Prakash Maiya <[email protected]>

This patch does following:
1. Adds a new cros-ec-uart driver. This driver can send EC requests on UART and process response packets received on UART transport.
2. Once probed, this driver will initialize the serdev device based on the underlying information in the ACPI resource. After serdev device properties are set, this driver will register itself cros-ec.
3. High level driver can use this implementation to talk to ChromeOS Embedded Controller device in case it supports UART as transport.
4. When cros-ec driver initiates a request packet, outgoing message is processed in buffer and sent via serdev. Once bytes are sent, driver enables a wait_queue.
5. Since ChromeOS EC device sends response asynchronously, AP's TTY driver accumulates response bytes and calls the registered callback. TTY driver can send multiple callback for bytes ranging from 1 to MAX bytes supported by EC device.
6. Driver waits for EC_MSG_DEADLINE_MS to collect and process received bytes. It wakes wait_queue if expected bytes are received or else wait_queue timeout. Based on the error condition, driver returns data_len or error to cros_ec.

---

Changes in v13:
- Introduce resp pointer to improve readability
- Remove whitespace
- Initialize sum variable just in time to improve readability
- Initialize ec_uart->serdev just in time to improve readability
- Update commit message to be more concise
- Remove tag: Reported-by: kernel test robot <[email protected]>

Changes in v12:
- No change

Changes in v11:
- Clarify error status in documentation
- Join more multi-line statments onto a single line if < 100 chars
- Add newline to the end of some printks
- Terminate acpi_device_id with a NULL entry
- Fix serdev doc warning for cros_ec_uart struct

Changes in v10:
- Remove superfluous comments
- Remove unneeded #include
- Use uninterruptible variant of wait_event
- Merge error and received variables into a single status var
- White space alignment
- Add warning message when byes are received out of band
- Join some multi-line statments onto a single line if < 100 chars

Changes in v9:
- Rebase onto for-next
- Update contact information in MAINTAINERS
- Remove superfluous comments
- Invert conditional logic checking response size
- Update authorship
- Convert single case switch statement to if conditional
- Reorder initializer list in increasing order of line length
- Use wait_event_timeout return value to detect timeout
- Remove unnecessary zeroizing of ec_uart struct
- Set received conditional on -EMSGSIZE error case
- Join dev_err msg onto single line where possible

Changes in v8:
- Combine for loops used for xsum calculation
- Use ec_dev->dev instead of serdev->dev
- Sort includes
- Swap struct var order to match doc order
- fix whitespace
- Update contact information in MAINTAINERS
- Update copyright date

Changes in v7:
- Use ACPI ID matching
- Change MODULE_LICENSE from GPL v2 to GPL

Changes in v6:
- Tuning EC_MSG_DEADLINE_MS from 1 sec to 500 msec. Since the EC's UART response buffer was tuned and redeuced to 256 byte, 500 msec timeout should give enough time for 256 bytes to be recieved from SoC UART buffer.

Changes in v5:
- Fixed checkpatch.pl warnings.

Changes in v4:
- Change EC_MSG_DEADLINE_MS from 3 secs to 1 sec. 3 secs timeout prevents driver from intercepting EC in RO stage. In case of request failure, 1 sec allows driver to retry and send HC when EC is in RO.
- Add more information in commit message.

Changes in v3:
- checkpatch.pl script warns about char len 80 even though we have relaxed view guideline for line below 100 chars. Currently sticking with 80 chars in v3.
- Fixed style issues

Changes in v2:
- Fixed build error on v1.
- Changed EC timeout for response packet to 3 Sec and added comments.
- Fixed cros_ec_uart_rx_bytes function to handle rx buffer < size of response header.

---
 MAINTAINERS                            |   7 +
 drivers/platform/chrome/Kconfig        |  10 +
 drivers/platform/chrome/Makefile       |   1 +
 drivers/platform/chrome/cros_ec_uart.c | 352 +++++++++++++++++++++++++
 4 files changed, 370 insertions(+)
 create mode 100644 drivers/platform/chrome/cros_ec_uart.c
MAINTAINERS +7 -0
index f61eb221415bd..49b0f0525502f 100644
@@ -4985,6 +4985,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/sound/google,cros-ec-codec.yaml
 F:	sound/soc/codecs/cros_ec_codec.*
 
+CHROMEOS EC UART DRIVER
+M:	Bhanu Prakash Maiya <[email protected]>
+R:	Benson Leung <[email protected]>
+R:	Tzung-Bi Shih <[email protected]>
+S:	Maintained
+F:	drivers/platform/chrome/cros_ec_uart.c
+
 CHROMEOS EC SUBDRIVERS
 M:	Benson Leung <[email protected]>
 R:	Guenter Roeck <[email protected]>
drivers/platform/chrome/Kconfig +10 -0
index c1ca247987d2d..0d272c87f32b2 100644
@@ -119,6 +119,16 @@ config CROS_EC_SPI
 	  response time cannot be guaranteed, we support ignoring
 	  'pre-amble' bytes before the response actually starts.
 
+config CROS_EC_UART
+	tristate "ChromeOS Embedded Controller (UART)"
+	depends on CROS_EC && ACPI && SERIAL_DEV_BUS
+	help
+	  If you say Y here, you get support for talking to the ChromeOS EC
+	  through a UART, using a byte-level protocol.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called cros_ec_uart.
+
 config CROS_EC_LPC
 	tristate "ChromeOS Embedded Controller (LPC)"
 	depends on CROS_EC && ACPI && (X86 || COMPILE_TEST)
drivers/platform/chrome/Makefile +1 -0
index f6068d077a40a..0f39edef660dd 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_CROS_EC_ISHTP)		+= cros_ec_ishtp.o
 obj-$(CONFIG_CROS_TYPEC_SWITCH)		+= cros_typec_switch.o
 obj-$(CONFIG_CROS_EC_RPMSG)		+= cros_ec_rpmsg.o
 obj-$(CONFIG_CROS_EC_SPI)		+= cros_ec_spi.o
+obj-$(CONFIG_CROS_EC_UART)		+= cros_ec_uart.o
 cros_ec_lpcs-objs			:= cros_ec_lpc.o cros_ec_lpc_mec.o
 obj-$(CONFIG_CROS_EC_TYPEC)		+= cros_ec_typec.o
 obj-$(CONFIG_CROS_EC_LPC)		+= cros_ec_lpcs.o
drivers/platform/chrome/cros_ec_uart.c new file +352 -0

352 lines not on this page · raw message

Signature · 1 line
2.39.0.314.g84b9a713c41-goog
#1 lore raw

PATCH v13 2/3 dt-bindings: mfd: cros-ec: Add UART compatible string

From: Bhanu Prakash Maiya <[email protected]>

Add a compatible string to support the UART implementation of the cros ec interface. The driver does not support the reg and interrupt properties, so exempt them from being required for UART compatible nodes.

---

Changes in v13:
- No change

Changes in v12:
- No change

Changes in v11:
- Update commit message to include device

Changes in v10:
- No change

Changes in v9:
- Rebase onto for-next
- Update node-name from uart0 to serial
- Remove reg and interrupt property requirement for UART compatible nodes.
- Update authorship

Changes in v8:
- Update commit message

Changes in v7:
- No change

Changes in v6:
- No change

Changes in v5:
- No change

Changes in v4:
- Changes in commit message.

Changes in v3:
- Rebased changes on google,cros-ec.yaml

Changes in v2:
- No change

---
 .../bindings/mfd/google,cros-ec.yaml          | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
Documentation/devicetree/bindings/mfd/google,cros-ec.yaml +20 -0
index 3d5efa5578d1b..cdf1d719efe9d 100644
@@ -33,6 +33,9 @@ properties:
       - description:
           For implementations of the EC connected through RPMSG.
         const: google,cros-ec-rpmsg
+      - description:
+          For implementations of the EC connected through UART.
+        const: google,cros-ec-uart
 
   controller-data: true
 
@@ -187,6 +190,15 @@ allOf:
       properties:
         mediatek,rpmsg-name: false
 
+  - if:
+      properties:
+        compatible:
+          not:
+            contains:
+              enum:
+                - google,cros-ec-rpmsg
+                - google,cros-ec-uart
+    then:
       required:
         - reg
         - interrupts
@@ -299,4 +311,12 @@ examples:
         vdd-supply = <&pp3300_fp_mcu>;
       };
     };
+
+  # Example for UART
+  - |
+    serial {
+        cros-ec {
+            compatible = "google,cros-ec-uart";
+        };
+    };
 ...
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
#2 lore raw

PATCH v13 3/3 platform/chrome: cros_ec_uart: Add DT enumeration support

In reply to Mark Hasemeyer

From: Bhanu Prakash Maiya <[email protected]>

Existing firmware uses the "PRP0001" _HID and an associated compatible string to enumerate the cros_ec_uart.

Add DT enumeration support for already shipped firmware.

---

Changes in v13:
- No change

Changes in v12:
- Add Reviewed-by: Prashant Malani <[email protected]>

Changes in v11:
- No change

Changes in v10:
- No change

Changes in v9:
- Rebase onto for-next
- Update authorship

Changes in v8:
- No change

Changes in v7:
- Move PRP0001 enumeration support to its own commit

 drivers/platform/chrome/cros_ec_uart.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/platform/chrome/cros_ec_uart.c +8 -0
index 971ea4bc2df80..0cef2888dffd0 100644
@@ -11,6 +11,7 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_data/cros_ec_proto.h>
 #include <linux/serdev.h>
 #include <linux/slab.h>
@@ -326,6 +327,12 @@ static int __maybe_unused cros_ec_uart_resume(struct device *dev)
 static SIMPLE_DEV_PM_OPS(cros_ec_uart_pm_ops, cros_ec_uart_suspend,
 			 cros_ec_uart_resume);
 
+static const struct of_device_id cros_ec_uart_of_match[] = {
+	{ .compatible = "google,cros-ec-uart" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, cros_ec_uart_of_match);
+
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id cros_ec_uart_acpi_id[] = {
 	{ "GOOG0019", 0 },
@@ -339,6 +346,7 @@ static struct serdev_device_driver cros_ec_uart_driver = {
 	.driver	= {
 		.name	= "cros-ec-uart",
 		.acpi_match_table = ACPI_PTR(cros_ec_uart_acpi_id),
+		.of_match_table = cros_ec_uart_of_match,
 		.pm	= &cros_ec_uart_pm_ops,
 	},
 	.probe		= cros_ec_uart_probe,
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
#3 lore raw
In reply to Mark Hasemeyer
This series was applied to chrome-platform/linux.git (for-kernelci) by Tzung-Bi Shih <[email protected]>:

Hello:

This series was applied to chrome-platform/linux.git (for-kernelci) by Tzung-Bi Shih <[email protected]>:

Quoted 22 lines · On Tue, 27 Dec 2022 12:32:22 -0700 you wrote:

From: Bhanu Prakash Maiya <[email protected]>

This patch does following:
1. Adds a new cros-ec-uart driver. This driver can send EC requests on UART and process response packets received on UART transport.
2. Once probed, this driver will initialize the serdev device based on the underlying information in the ACPI resource. After serdev device properties are set, this driver will register itself cros-ec.
3. High level driver can use this implementation to talk to ChromeOS Embedded Controller device in case it supports UART as transport.
4. When cros-ec driver initiates a request packet, outgoing message is processed in buffer and sent via serdev. Once bytes are sent, driver enables a wait_queue.
5. Since ChromeOS EC device sends response asynchronously, AP's TTY driver accumulates response bytes and calls the registered callback. TTY driver can send multiple callback for bytes ranging from 1 to MAX bytes supported by EC device.
6. Driver waits for EC_MSG_DEADLINE_MS to collect and process received bytes. It wakes wait_queue if expected bytes are received or else wait_queue timeout. Based on the error condition, driver returns data_len or error to cros_ec.

Quoted 1 line

[...]

Here is the summary with links:
- [v13,1/3] platform/chrome: cros_ec_uart: Add transport layer

    https://git.kernel.org/chrome-platform/c/04a8bdd135cc
  - [v13,2/3] dt-bindings: mfd: cros-ec: Add UART compatible string
    https://git.kernel.org/chrome-platform/c/5be8cd61dcdd
  - [v13,3/3] platform/chrome: cros_ec_uart: Add DT enumeration support
    https://git.kernel.org/chrome-platform/c/c34fea225806

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#4 lore raw
In reply to Mark Hasemeyer
This series was applied to chrome-platform/linux.git (for-next) by Tzung-Bi Shih <[email protected]>:

Hello:

This series was applied to chrome-platform/linux.git (for-next) by Tzung-Bi Shih <[email protected]>:

Quoted 22 lines · On Tue, 27 Dec 2022 12:32:22 -0700 you wrote:

From: Bhanu Prakash Maiya <[email protected]>

This patch does following:
1. Adds a new cros-ec-uart driver. This driver can send EC requests on UART and process response packets received on UART transport.
2. Once probed, this driver will initialize the serdev device based on the underlying information in the ACPI resource. After serdev device properties are set, this driver will register itself cros-ec.
3. High level driver can use this implementation to talk to ChromeOS Embedded Controller device in case it supports UART as transport.
4. When cros-ec driver initiates a request packet, outgoing message is processed in buffer and sent via serdev. Once bytes are sent, driver enables a wait_queue.
5. Since ChromeOS EC device sends response asynchronously, AP's TTY driver accumulates response bytes and calls the registered callback. TTY driver can send multiple callback for bytes ranging from 1 to MAX bytes supported by EC device.
6. Driver waits for EC_MSG_DEADLINE_MS to collect and process received bytes. It wakes wait_queue if expected bytes are received or else wait_queue timeout. Based on the error condition, driver returns data_len or error to cros_ec.

Quoted 1 line

[...]

Here is the summary with links:
- [v13,1/3] platform/chrome: cros_ec_uart: Add transport layer

    https://git.kernel.org/chrome-platform/c/04a8bdd135cc
  - [v13,2/3] dt-bindings: mfd: cros-ec: Add UART compatible string
    https://git.kernel.org/chrome-platform/c/5be8cd61dcdd
  - [v13,3/3] platform/chrome: cros_ec_uart: Add DT enumeration support
    https://git.kernel.org/chrome-platform/c/c34fea225806

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html