* [PATCH 00/22] platform/chrome: Add DT USB/DP muxing/topology to Trogdor
@ 2024-02-10 7:09 Stephen Boyd
2024-02-10 7:09 ` [PATCH 01/22] dt-bindings: gpio: Add binding for ChromeOS EC GPIO controller Stephen Boyd
2024-02-10 7:09 ` [PATCH 02/22] gpio: Add ChromeOS EC GPIO driver Stephen Boyd
0 siblings, 2 replies; 8+ messages in thread
From: Stephen Boyd @ 2024-02-10 7:09 UTC (permalink / raw)
To: chrome-platform
Cc: linux-kernel, patches, linux-arm-kernel, devicetree,
linux-arm-msm, Douglas Anderson, Pin-yen Lin, Alexandre Belloni,
Andrzej Hajda, Andy Gross, Andy Shevchenko, Bartosz Golaszewski,
Benson Leung, Bjorn Andersson, Conor Dooley,
cros-qcom-dts-watchers, Daniel Scally, Daniel Vetter,
David Airlie, dri-devel, Greg Kroah-Hartman, Guenter Roeck,
Heikki Krogerus, Ivan Orlov, Jernej Skrabec, Jonas Karlman,
Konrad Dybcio, Krzysztof Kozlowski, Laurent Pinchart, Lee Jones,
Linus Walleij, linux-acpi, linux-gpio, linux-usb,
Maarten Lankhorst, maciek swiech, Matthias Kaehlcke,
Maxime Ripard, Mika Westerberg, Neil Armstrong, Prashant Malani,
Rafael J. Wysocki, Robert Foss, Rob Herring, Sakari Ailus,
Thomas Zimmermann, Tzung-Bi Shih, Vinod Koul
This series adds support for fully describing the USB/DP topology on
ChromeOS Trogdor devices in DT. Trogdor devices have a single DP phy in
the AP that is muxed to one of two usb type-c connectors depending on
which port asserts HPD first to the EC. We'd like to know which port is
connected to an external monitor to provide a better experience to the
user about things like which type-c port is displaying DP or which
type-c hub is acting up, etc. Describing the connection all the way from
the source to the connector will allow us to do this. There will be some
more work to do after this to wire up sysfs connections, but that work
has already started or finished so it should be mostly minor changes to
support DT there.
This patch series is large, unfortunately, and is ordered in logical
groups: gpio, USB, DRM, typec, and finally dts to put it all together.
There's more that could be put in here, e.g. supporting ChromeOS Corsola
devices, but I wanted to get something out there early instead of
waiting to make this work with everything that exists today and posting
it then.
Onto the patches:
First is the EC GPIO driver, which is dependency free and can be merged
at any time. It's only needed to provide information about which port
the EC is steering DP to, because the EC had a bug where it never told
the AP about which port has HPD asserted or not.
Second is the USB binding and hub patches. These are used to describe
how the USB hub is wired up on all the Trogdor devices, and make the
connect_type be something besides "unknown" on DT devices. ACPI has
supported setting a proper connect_type for some time now. These can
also be merged pretty much dependency free, except that the dt binding
will be needed to avoid DT binding check failures. I don't think those
checks are fatal though, so probably also fine to take this part
independently.
Third is the DRM bridge patches. These are used to implement lane
assignment for DP altmode configurations through the drm_bridge code.
The typec code will use this to tell the DP phy how many lanes of DP to
drive and which lanes to drive out to the USB type-c connector. Adding
support for lane assignment allows us to implement DP muxing as well,
physically splitting the DP lanes on the DP phy so that hardware doesn't
have to use an analog mux to steer two DP lanes to one or the other
type-c port. These are a hard dependency for the typec code.
Fourth is the typec patches, that ties together everything that comes
before it in this series. The EC typec switch driver implements a
drm_bridge that can signal HPD from the type-c connector through the
bridge chain, mux the DP phy in software so that we don't have to use an
analog mux, and implement orientation control for boards like Kukui that
directly connect the DP phy to the type-c port, necessitating lane
assignment to flip the lanes to match the cable orientation.
Finally, the dts patches wire everything up to fully describe the USB/DT
topology on Trogdor. This includes the USB hub, the EC gpios, the DP
controller, and the external connectors like the usb-c and usb-a
connectors.
After this initial version I will probably split this series and send
parts in pieces to more rapidly send new versions. Those parts will
refer back to this version in the cover letter so we can all get the
full context. I don't expect to merge this through one maintainer tree
immediately, so I set the 'To' line to chrome-platform to reflect the
overall target audience.
Prashant Malani (1):
platform/chrome: cros_ec_typec: Purge blocking switch devlinks
Stephen Boyd (21):
dt-bindings: gpio: Add binding for ChromeOS EC GPIO controller
gpio: Add ChromeOS EC GPIO driver
dt-bindings: usb: Add downstream facing ports to realtek binding
usb: core: Set connect_type of ports based on DT node
drm/atomic-helper: Introduce lane remapping support to bridges
drm/bridge: Verify lane assignment is going to work during
atomic_check
device property: Add remote endpoint to devcon matcher
platform/chrome: cros_typec_switch: Use read_poll_timeout helper
platform/chrome: cros_typec_switch: Move port creation code to
sub-function
platform/chrome: cros_typec_switch: Use fwnode instead of ACPI APIs
platform/chrome: cros_typec_switch: Use dev_err_probe()
dt-bindings: chrome: Add google,cros-ec-typec-switch binding
platform/chrome: cros_typec_switch: Add support for signaling HPD to
drm_bridge
platform/chrome: cros_typec_switch: Support DP muxing via DRM lane
assignment
platform/chrome: cros_typec_switch: Support orientation-switch
platform/chrome: cros_typec_switch: Handle lack of HPD information
dt-bindings: chrome: Add binding for ChromeOS Pogo pin connector
arm64: dts: qcom: sc7180: quackingstick: Disable instead of delete
usb_c1
arm64: dts: qcom: sc7180: pazquel: Add missing comment header
arm64: dts: qcom: sc7180-trogdor: Make clamshell/detachable fragments
arm64: dts: qcom: sc7180-trogdor: Wire up USB and DP to
usb-c-connectors
.../chrome/google,cros-ec-typec-switch.yaml | 365 ++++++++++++
.../chrome/google,pogo-pin-connector.yaml | 61 ++
.../bindings/gpio/google,cros-ec-gpio.yaml | 49 ++
.../bindings/mfd/google,cros-ec.yaml | 8 +
.../bindings/usb/realtek,rts5411.yaml | 50 ++
.../dts/qcom/sc7180-trogdor-clamshell.dtsi | 30 +
.../boot/dts/qcom/sc7180-trogdor-coachz.dtsi | 52 +-
.../dts/qcom/sc7180-trogdor-detachable.dtsi | 25 +
.../dts/qcom/sc7180-trogdor-homestar.dtsi | 54 +-
.../dts/qcom/sc7180-trogdor-kingoftown.dts | 57 +-
.../boot/dts/qcom/sc7180-trogdor-lazor.dtsi | 58 +-
.../boot/dts/qcom/sc7180-trogdor-pazquel.dtsi | 59 +-
.../boot/dts/qcom/sc7180-trogdor-pompom.dtsi | 46 +-
.../qcom/sc7180-trogdor-quackingstick.dtsi | 46 +-
.../arm64/boot/dts/qcom/sc7180-trogdor-r1.dts | 2 +-
.../dts/qcom/sc7180-trogdor-wormdingler.dtsi | 52 +-
arch/arm64/boot/dts/qcom/sc7180-trogdor.dtsi | 175 ++++++
drivers/base/property.c | 7 +-
drivers/gpio/Kconfig | 10 +
drivers/gpio/Makefile | 1 +
drivers/gpio/gpio-cros-ec.c | 218 +++++++
drivers/gpu/drm/drm_atomic_state_helper.c | 2 +
drivers/gpu/drm/drm_bridge.c | 50 ++
drivers/platform/chrome/Kconfig | 3 +-
drivers/platform/chrome/cros_ec_typec.c | 10 +
drivers/platform/chrome/cros_typec_switch.c | 555 +++++++++++++++---
drivers/usb/core/port.c | 37 ++
drivers/usb/roles/class.c | 4 +-
drivers/usb/typec/mux.c | 8 +
drivers/usb/typec/retimer.c | 7 +-
include/drm/drm_atomic.h | 31 +
include/drm/drm_bridge.h | 4 +
include/linux/property.h | 5 +-
33 files changed, 2026 insertions(+), 115 deletions(-)
create mode 100644 Documentation/devicetree/bindings/chrome/google,cros-ec-typec-switch.yaml
create mode 100644 Documentation/devicetree/bindings/chrome/google,pogo-pin-connector.yaml
create mode 100644 Documentation/devicetree/bindings/gpio/google,cros-ec-gpio.yaml
create mode 100644 arch/arm64/boot/dts/qcom/sc7180-trogdor-clamshell.dtsi
create mode 100644 arch/arm64/boot/dts/qcom/sc7180-trogdor-detachable.dtsi
create mode 100644 drivers/gpio/gpio-cros-ec.c
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Andrzej Hajda <andrzej.hajda@intel.com>
Cc: Andy Gross <agross@kernel.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Benson Leung <bleung@chromium.org>
Cc: Bjorn Andersson <andersson@kernel.org>
Cc: <chrome-platform@lists.linux.dev>
Cc: Conor Dooley <conor+dt@kernel.org>
Cc: <cros-qcom-dts-watchers@chromium.org>
Cc: Daniel Scally <djrscally@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: David Airlie <airlied@gmail.com>
Cc: <devicetree@vger.kernel.org>
Cc: <dri-devel@lists.freedesktop.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Guenter Roeck <groeck@chromium.org>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Ivan Orlov <ivan.orlov0322@gmail.com>
Cc: Jernej Skrabec <jernej.skrabec@gmail.com>
Cc: Jonas Karlman <jonas@kwiboo.se>
Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
Cc: Laurent Pinchart <Laurent.pinchart@ideasonboard.com>
Cc: Lee Jones <lee@kernel.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: <linux-acpi@vger.kernel.org>
Cc: <linux-arm-msm@vger.kernel.org>
Cc: <linux-gpio@vger.kernel.org>
Cc: <linux-usb@vger.kernel.org>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: maciek swiech <drmasquatch@google.com>
Cc: Matthias Kaehlcke <mka@chromium.org>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Neil Armstrong <neil.armstrong@linaro.org>
Cc: Pin-yen Lin <treapking@chromium.org>
Cc: Prashant Malani <pmalani@chromium.org>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: Robert Foss <rfoss@kernel.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Tzung-Bi Shih <tzungbi@kernel.org>
Cc: Vinod Koul <vkoul@kernel.org>
base-commit: 0dd3ee31125508cd67f7e7172247f05b7fd1753a
--
https://chromeos.dev
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 01/22] dt-bindings: gpio: Add binding for ChromeOS EC GPIO controller
2024-02-10 7:09 [PATCH 00/22] platform/chrome: Add DT USB/DP muxing/topology to Trogdor Stephen Boyd
@ 2024-02-10 7:09 ` Stephen Boyd
2024-02-11 13:26 ` Krzysztof Kozlowski
2024-02-15 14:06 ` Rob Herring
2024-02-10 7:09 ` [PATCH 02/22] gpio: Add ChromeOS EC GPIO driver Stephen Boyd
1 sibling, 2 replies; 8+ messages in thread
From: Stephen Boyd @ 2024-02-10 7:09 UTC (permalink / raw)
To: chrome-platform
Cc: linux-kernel, patches, linux-arm-kernel, devicetree,
linux-arm-msm, Douglas Anderson, Pin-yen Lin, Linus Walleij,
Bartosz Golaszewski, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Lee Jones, Benson Leung, Guenter Roeck, linux-gpio
The ChromeOS embedded controller (EC) supports setting the state of
GPIOs when the system is unlocked, and getting the state of GPIOs in all
cases. The GPIOs are on the EC itself, so the EC acts similar to a GPIO
expander. Add a binding to describe these GPIOs in DT so that other
devices described in DT can read the GPIOs on the EC.
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
Cc: Conor Dooley <conor+dt@kernel.org>
Cc: Lee Jones <lee@kernel.org>
Cc: Benson Leung <bleung@chromium.org>
Cc: Guenter Roeck <groeck@chromium.org>
Cc: <linux-gpio@vger.kernel.org>
Cc: <devicetree@vger.kernel.org>
Cc: <chrome-platform@lists.linux.dev>
Cc: Pin-yen Lin <treapking@chromium.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
.../bindings/gpio/google,cros-ec-gpio.yaml | 49 +++++++++++++++++++
.../bindings/mfd/google,cros-ec.yaml | 3 ++
2 files changed, 52 insertions(+)
create mode 100644 Documentation/devicetree/bindings/gpio/google,cros-ec-gpio.yaml
diff --git a/Documentation/devicetree/bindings/gpio/google,cros-ec-gpio.yaml b/Documentation/devicetree/bindings/gpio/google,cros-ec-gpio.yaml
new file mode 100644
index 000000000000..a9f1d7784070
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/google,cros-ec-gpio.yaml
@@ -0,0 +1,49 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/gpio/google,cros-ec-gpio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: GPIOs controlled by ChromeOS EC
+
+maintainers:
+ - Stephen Boyd <swboyd@chromium.org>
+
+description:
+ Google's ChromeOS EC has a gpio controller inside the Embedded Controller
+ (EC) and controlled via a host-command interface. The node for this
+ device should be under a cros-ec node like google,cros-ec-spi.
+
+properties:
+ compatible:
+ const: google,cros-ec-gpio
+
+ '#gpio-cells':
+ const: 2
+
+ gpio-controller: true
+
+required:
+ - compatible
+ - '#gpio-cells'
+ - gpio-controller
+
+additionalProperties: false
+
+examples:
+ - |
+ spi {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ cros-ec@0 {
+ compatible = "google,cros-ec-spi";
+ reg = <0>;
+ interrupts = <101 0>;
+ gpio {
+ compatible = "google,cros-ec-gpio";
+ gpio-controller;
+ #gpio-cells = <2>;
+ };
+ };
+ };
diff --git a/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml b/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml
index e1ca4f297c6d..ded396b28fba 100644
--- a/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml
+++ b/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml
@@ -93,6 +93,9 @@ properties:
'#size-cells':
const: 0
+ gpio:
+ $ref: /schemas/gpio/google,cros-ec-gpio.yaml#
+
typec:
$ref: /schemas/chrome/google,cros-ec-typec.yaml#
--
https://chromeos.dev
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 02/22] gpio: Add ChromeOS EC GPIO driver
2024-02-10 7:09 [PATCH 00/22] platform/chrome: Add DT USB/DP muxing/topology to Trogdor Stephen Boyd
2024-02-10 7:09 ` [PATCH 01/22] dt-bindings: gpio: Add binding for ChromeOS EC GPIO controller Stephen Boyd
@ 2024-02-10 7:09 ` Stephen Boyd
2024-02-13 17:57 ` Linus Walleij
1 sibling, 1 reply; 8+ messages in thread
From: Stephen Boyd @ 2024-02-10 7:09 UTC (permalink / raw)
To: chrome-platform
Cc: linux-kernel, patches, linux-arm-kernel, devicetree,
linux-arm-msm, Douglas Anderson, Pin-yen Lin, Linus Walleij,
Bartosz Golaszewski, Benson Leung, Guenter Roeck, linux-gpio
The ChromeOS embedded controller (EC) supports setting the state of
GPIOs when the system is unlocked, and getting the state of GPIOs in all
cases. The GPIOs are on the EC itself, so the EC acts similar to a GPIO
expander. Add a driver to get and set the GPIOs on the EC through the
host command interface.
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Benson Leung <bleung@chromium.org>
Cc: Guenter Roeck <groeck@chromium.org>
Cc: <linux-gpio@vger.kernel.org>
Cc: <chrome-platform@lists.linux.dev>
Cc: Pin-yen Lin <treapking@chromium.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
drivers/gpio/Kconfig | 10 ++
drivers/gpio/Makefile | 1 +
drivers/gpio/gpio-cros-ec.c | 218 ++++++++++++++++++++++++++++++++++++
3 files changed, 229 insertions(+)
create mode 100644 drivers/gpio/gpio-cros-ec.c
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index b3a133ed31ee..62b0ae25a727 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -1220,6 +1220,16 @@ config GPIO_BD9571MWV
This driver can also be built as a module. If so, the module
will be called gpio-bd9571mwv.
+config GPIO_CROS_EC
+ tristate "ChromeOS EC GPIO support"
+ depends on CROS_EC
+ help
+ GPIO driver for exposing GPIOs on the ChromeOS Embedded
+ Controller.
+
+ This driver can also be built as a module. If so, the module
+ will be called gpio-cros-ec.
+
config GPIO_CRYSTAL_COVE
tristate "GPIO support for Crystal Cove PMIC"
depends on (X86 || COMPILE_TEST) && INTEL_SOC_PMIC
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index eb73b5d633eb..2e66410c1da6 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -46,6 +46,7 @@ obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o
obj-$(CONFIG_GPIO_CADENCE) += gpio-cadence.o
obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o
obj-$(CONFIG_GPIO_SNPS_CREG) += gpio-creg-snps.o
+obj-$(CONFIG_GPIO_CROS_EC) += gpio-cros-ec.o
obj-$(CONFIG_GPIO_CRYSTAL_COVE) += gpio-crystalcove.o
obj-$(CONFIG_GPIO_CS5535) += gpio-cs5535.o
obj-$(CONFIG_GPIO_DA9052) += gpio-da9052.o
diff --git a/drivers/gpio/gpio-cros-ec.c b/drivers/gpio/gpio-cros-ec.c
new file mode 100644
index 000000000000..0d35558304bf
--- /dev/null
+++ b/drivers/gpio/gpio-cros-ec.c
@@ -0,0 +1,218 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright 2024 Google LLC
+ *
+ * This driver provides the ability to control GPIOs on the Chrome OS EC.
+ * There isn't any direction control, and setting values on GPIOs is only
+ * possible when the system is unlocked.
+ */
+
+#include <linux/bitops.h>
+#include <linux/errno.h>
+#include <linux/gpio/driver.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_data/cros_ec_commands.h>
+#include <linux/platform_data/cros_ec_proto.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+/* Setting gpios is only supported when the system is unlocked */
+static void cros_ec_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
+{
+ const char *name = gc->names[gpio];
+ struct cros_ec_device *cros_ec = gpiochip_get_data(gc);
+ struct ec_params_gpio_set params = {
+ .val = val,
+ };
+ int ret;
+ ssize_t copied;
+
+ copied = strscpy(params.name, name, sizeof(params.name));
+ if (copied < 0)
+ return;
+
+ ret = cros_ec_cmd(cros_ec, 0, EC_CMD_GPIO_SET, ¶ms,
+ sizeof(params), NULL, 0);
+ if (ret < 0)
+ dev_err(gc->parent, "error setting gpio%d (%s) on EC: %d\n", gpio, name, ret);
+}
+
+static int cros_ec_gpio_get(struct gpio_chip *gc, unsigned int gpio)
+{
+ const char *name = gc->names[gpio];
+ struct cros_ec_device *cros_ec = gpiochip_get_data(gc);
+ struct ec_params_gpio_get params;
+ struct ec_response_gpio_get response;
+ int ret;
+ ssize_t copied;
+
+ copied = strscpy(params.name, name, sizeof(params.name));
+ if (copied < 0)
+ return -EINVAL;
+
+ ret = cros_ec_cmd(cros_ec, 0, EC_CMD_GPIO_GET, ¶ms,
+ sizeof(params), &response, sizeof(response));
+ if (ret < 0) {
+ dev_err(gc->parent, "error getting gpio%d (%s) on EC: %d\n", gpio, name, ret);
+ return ret;
+ }
+
+ return response.val;
+}
+
+#define CROS_EC_GPIO_INPUT BIT(8)
+#define CROS_EC_GPIO_OUTPUT BIT(9)
+
+static int cros_ec_gpio_get_direction(struct gpio_chip *gc, unsigned int gpio)
+{
+ const char *name = gc->names[gpio];
+ struct cros_ec_device *cros_ec = gpiochip_get_data(gc);
+ struct ec_params_gpio_get_v1 params = {
+ .subcmd = EC_GPIO_GET_INFO,
+ .get_info.index = gpio,
+ };
+ struct ec_response_gpio_get_v1 response;
+ int ret;
+
+ ret = cros_ec_cmd(cros_ec, 1, EC_CMD_GPIO_GET, ¶ms,
+ sizeof(params), &response, sizeof(response));
+ if (ret < 0) {
+ dev_err(gc->parent, "error getting direction of gpio%d (%s) on EC: %d\n", gpio, name, ret);
+ return ret;
+ }
+
+ if (response.get_info.flags & CROS_EC_GPIO_INPUT)
+ return GPIO_LINE_DIRECTION_IN;
+
+ if (response.get_info.flags & CROS_EC_GPIO_OUTPUT)
+ return GPIO_LINE_DIRECTION_OUT;
+
+ return -EINVAL;
+}
+
+static int cros_ec_gpio_request(struct gpio_chip *chip, unsigned gpio_pin)
+{
+ if (gpio_pin < chip->ngpio)
+ return 0;
+
+ return -EINVAL;
+}
+
+/* Query EC for all gpio line names */
+static int cros_ec_gpio_init_names(struct cros_ec_device *cros_ec, struct gpio_chip *gc)
+{
+ struct ec_params_gpio_get_v1 params = {
+ .subcmd = EC_GPIO_GET_INFO,
+ };
+ struct ec_response_gpio_get_v1 response;
+ int ret, i;
+ /* EC may not NUL terminate */
+ size_t name_len = sizeof(response.get_info.name) + 1;
+ ssize_t copied;
+ const char **names;
+ char *str;
+
+ names = devm_kcalloc(gc->parent, gc->ngpio, sizeof(*names), GFP_KERNEL);
+ if (!names)
+ return -ENOMEM;
+ gc->names = names;
+
+ str = devm_kcalloc(gc->parent, gc->ngpio, name_len, GFP_KERNEL);
+ if (!str)
+ return -ENOMEM;
+
+ /* Get gpio line names one at a time */
+ for (i = 0; i < gc->ngpio; i++) {
+ params.get_info.index = i;
+ ret = cros_ec_cmd(cros_ec, 1, EC_CMD_GPIO_GET, ¶ms,
+ sizeof(params), &response, sizeof(response));
+ if (ret < 0) {
+ dev_err_probe(gc->parent, ret, "error getting gpio%d info\n", i);
+ return ret;
+ }
+
+ names[i] = str;
+ copied = strscpy(str, response.get_info.name, name_len);
+ if (copied < 0)
+ return copied;
+
+ str += copied + 1;
+ }
+
+ return 0;
+}
+
+/* Query EC for number of gpios */
+static int cros_ec_gpio_ngpios(struct cros_ec_device *cros_ec)
+{
+ struct ec_params_gpio_get_v1 params = {
+ .subcmd = EC_GPIO_GET_COUNT,
+ };
+ struct ec_response_gpio_get_v1 response;
+ int ret;
+
+ ret = cros_ec_cmd(cros_ec, 1, EC_CMD_GPIO_GET, ¶ms,
+ sizeof(params), &response, sizeof(response));
+ if (ret < 0)
+ return ret;
+
+ return response.get_count.val;
+}
+
+static int cros_ec_gpio_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct cros_ec_device *cros_ec = dev_get_drvdata(dev->parent);
+ struct gpio_chip *gc;
+ int ngpios;
+ int ret;
+
+ ngpios = cros_ec_gpio_ngpios(cros_ec);
+ if (ngpios < 0) {
+ dev_err_probe(dev, ngpios, "error getting gpio count\n");
+ return ngpios;
+ }
+
+ gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
+ if (!gc)
+ return -ENOMEM;
+
+ gc->ngpio = ngpios;
+ gc->parent = dev;
+ ret = cros_ec_gpio_init_names(cros_ec, gc);
+ if (ret)
+ return ret;
+
+ gc->can_sleep = true;
+ gc->label = dev_name(dev);
+ gc->base = -1;
+ gc->set = cros_ec_gpio_set;
+ gc->get = cros_ec_gpio_get;
+ gc->get_direction = cros_ec_gpio_get_direction;
+ gc->request = cros_ec_gpio_request;
+
+ return devm_gpiochip_add_data(&pdev->dev, gc, cros_ec);
+}
+
+#ifdef CONFIG_OF
+static const struct of_device_id cros_ec_gpio_of_match[] = {
+ { .compatible = "google,cros-ec-gpio" },
+ {}
+};
+MODULE_DEVICE_TABLE(of, cros_ec_gpio_of_match);
+#endif
+
+static struct platform_driver cros_ec_gpio_driver = {
+ .probe = cros_ec_gpio_probe,
+ .driver = {
+ .name = "cros-ec-gpio",
+ .of_match_table = of_match_ptr(cros_ec_gpio_of_match),
+ },
+};
+module_platform_driver(cros_ec_gpio_driver);
+
+MODULE_DESCRIPTION("ChromeOS EC GPIO Driver");
+MODULE_LICENSE("GPL");
--
https://chromeos.dev
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 01/22] dt-bindings: gpio: Add binding for ChromeOS EC GPIO controller
2024-02-10 7:09 ` [PATCH 01/22] dt-bindings: gpio: Add binding for ChromeOS EC GPIO controller Stephen Boyd
@ 2024-02-11 13:26 ` Krzysztof Kozlowski
2024-02-15 0:44 ` Stephen Boyd
2024-02-15 14:06 ` Rob Herring
1 sibling, 1 reply; 8+ messages in thread
From: Krzysztof Kozlowski @ 2024-02-11 13:26 UTC (permalink / raw)
To: Stephen Boyd, chrome-platform
Cc: linux-kernel, patches, linux-arm-kernel, devicetree,
linux-arm-msm, Douglas Anderson, Pin-yen Lin, Linus Walleij,
Bartosz Golaszewski, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Lee Jones, Benson Leung, Guenter Roeck, linux-gpio
On 10/02/2024 08:09, Stephen Boyd wrote:
> The ChromeOS embedded controller (EC) supports setting the state of
> GPIOs when the system is unlocked, and getting the state of GPIOs in all
> cases. The GPIOs are on the EC itself, so the EC acts similar to a GPIO
> expander. Add a binding to describe these GPIOs in DT so that other
> devices described in DT can read the GPIOs on the EC.
...
> +
> +additionalProperties: false
> +
> +examples:
> + - |
> + spi {
> + #address-cells = <1>;
> + #size-cells = <0>;
> +
> + cros-ec@0 {
> + compatible = "google,cros-ec-spi";
> + reg = <0>;
> + interrupts = <101 0>;
This is should be proper define but then are you sure interrupt is type
NONE? Does not look right.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 02/22] gpio: Add ChromeOS EC GPIO driver
2024-02-10 7:09 ` [PATCH 02/22] gpio: Add ChromeOS EC GPIO driver Stephen Boyd
@ 2024-02-13 17:57 ` Linus Walleij
0 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2024-02-13 17:57 UTC (permalink / raw)
To: Stephen Boyd
Cc: chrome-platform, linux-kernel, patches, linux-arm-kernel,
devicetree, linux-arm-msm, Douglas Anderson, Pin-yen Lin,
Bartosz Golaszewski, Benson Leung, Guenter Roeck, linux-gpio
Hi Stephen,
thanks for your patch!
Overall it looks good I have a few nitpicks
On Sat, Feb 10, 2024 at 8:09 AM Stephen Boyd <swboyd@chromium.org> wrote:
> The ChromeOS embedded controller (EC) supports setting the state of
> GPIOs when the system is unlocked, and getting the state of GPIOs in all
> cases. The GPIOs are on the EC itself, so the EC acts similar to a GPIO
> expander. Add a driver to get and set the GPIOs on the EC through the
> host command interface.
>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Bartosz Golaszewski <brgl@bgdev.pl>
> Cc: Benson Leung <bleung@chromium.org>
> Cc: Guenter Roeck <groeck@chromium.org>
> Cc: <linux-gpio@vger.kernel.org>
> Cc: <chrome-platform@lists.linux.dev>
> Cc: Pin-yen Lin <treapking@chromium.org>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
(...)
> +config GPIO_CROS_EC
> + tristate "ChromeOS EC GPIO support"
> + depends on CROS_EC
> + help
> + GPIO driver for exposing GPIOs on the ChromeOS Embedded
> + Controller.
> +
> + This driver can also be built as a module. If so, the module
> + will be called gpio-cros-ec.
Classified as "MFD Expander" but I honestly don't know anything better.
> +#include <linux/bitops.h>
> +#include <linux/errno.h>
> +#include <linux/gpio/driver.h>
> +#include <linux/init.h>
Do you need init.h?
I guess maybe... I thought module would be enough for this.
> +static int cros_ec_gpio_request(struct gpio_chip *chip, unsigned gpio_pin)
> +{
> + if (gpio_pin < chip->ngpio)
> + return 0;
> +
> + return -EINVAL;
> +}
If this check is needed, it should be in gpiolib I think?
> +#ifdef CONFIG_OF
This ifdef should not be needed these days.
> +static const struct of_device_id cros_ec_gpio_of_match[] = {
> + { .compatible = "google,cros-ec-gpio" },
> + {}
> +};
> +MODULE_DEVICE_TABLE(of, cros_ec_gpio_of_match);
> +#endif
> +
> +static struct platform_driver cros_ec_gpio_driver = {
> + .probe = cros_ec_gpio_probe,
> + .driver = {
> + .name = "cros-ec-gpio",
> + .of_match_table = of_match_ptr(cros_ec_gpio_of_match),
Nor the of_match_ptr() business.
With these fixed/addressed:
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 01/22] dt-bindings: gpio: Add binding for ChromeOS EC GPIO controller
2024-02-11 13:26 ` Krzysztof Kozlowski
@ 2024-02-15 0:44 ` Stephen Boyd
0 siblings, 0 replies; 8+ messages in thread
From: Stephen Boyd @ 2024-02-15 0:44 UTC (permalink / raw)
To: Krzysztof Kozlowski, chrome-platform
Cc: linux-kernel, patches, linux-arm-kernel, devicetree,
linux-arm-msm, Douglas Anderson, Pin-yen Lin, Linus Walleij,
Bartosz Golaszewski, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Lee Jones, Benson Leung, Guenter Roeck, linux-gpio
Quoting Krzysztof Kozlowski (2024-02-11 05:26:33)
> On 10/02/2024 08:09, Stephen Boyd wrote:
> > The ChromeOS embedded controller (EC) supports setting the state of
> > GPIOs when the system is unlocked, and getting the state of GPIOs in all
> > cases. The GPIOs are on the EC itself, so the EC acts similar to a GPIO
> > expander. Add a binding to describe these GPIOs in DT so that other
> > devices described in DT can read the GPIOs on the EC.
>
> ...
>
> > +
> > +additionalProperties: false
> > +
> > +examples:
> > + - |
> > + spi {
> > + #address-cells = <1>;
> > + #size-cells = <0>;
> > +
> > + cros-ec@0 {
> > + compatible = "google,cros-ec-spi";
> > + reg = <0>;
> > + interrupts = <101 0>;
>
> This is should be proper define but then are you sure interrupt is type
> NONE? Does not look right.
>
I copied this from cros-ec-typec.yaml so I'll have to fix them all!
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 01/22] dt-bindings: gpio: Add binding for ChromeOS EC GPIO controller
2024-02-10 7:09 ` [PATCH 01/22] dt-bindings: gpio: Add binding for ChromeOS EC GPIO controller Stephen Boyd
2024-02-11 13:26 ` Krzysztof Kozlowski
@ 2024-02-15 14:06 ` Rob Herring
2024-02-15 22:00 ` Stephen Boyd
1 sibling, 1 reply; 8+ messages in thread
From: Rob Herring @ 2024-02-15 14:06 UTC (permalink / raw)
To: Stephen Boyd
Cc: chrome-platform, linux-kernel, patches, linux-arm-kernel,
devicetree, linux-arm-msm, Douglas Anderson, Pin-yen Lin,
Linus Walleij, Bartosz Golaszewski, Krzysztof Kozlowski,
Conor Dooley, Lee Jones, Benson Leung, Guenter Roeck, linux-gpio
On Fri, Feb 09, 2024 at 11:09:12PM -0800, Stephen Boyd wrote:
> The ChromeOS embedded controller (EC) supports setting the state of
> GPIOs when the system is unlocked, and getting the state of GPIOs in all
> cases. The GPIOs are on the EC itself, so the EC acts similar to a GPIO
> expander. Add a binding to describe these GPIOs in DT so that other
> devices described in DT can read the GPIOs on the EC.
>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Bartosz Golaszewski <brgl@bgdev.pl>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
> Cc: Conor Dooley <conor+dt@kernel.org>
> Cc: Lee Jones <lee@kernel.org>
> Cc: Benson Leung <bleung@chromium.org>
> Cc: Guenter Roeck <groeck@chromium.org>
> Cc: <linux-gpio@vger.kernel.org>
> Cc: <devicetree@vger.kernel.org>
> Cc: <chrome-platform@lists.linux.dev>
> Cc: Pin-yen Lin <treapking@chromium.org>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> ---
> .../bindings/gpio/google,cros-ec-gpio.yaml | 49 +++++++++++++++++++
> .../bindings/mfd/google,cros-ec.yaml | 3 ++
> 2 files changed, 52 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/gpio/google,cros-ec-gpio.yaml
>
> diff --git a/Documentation/devicetree/bindings/gpio/google,cros-ec-gpio.yaml b/Documentation/devicetree/bindings/gpio/google,cros-ec-gpio.yaml
> new file mode 100644
> index 000000000000..a9f1d7784070
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/gpio/google,cros-ec-gpio.yaml
> @@ -0,0 +1,49 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/gpio/google,cros-ec-gpio.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: GPIOs controlled by ChromeOS EC
> +
> +maintainers:
> + - Stephen Boyd <swboyd@chromium.org>
> +
> +description:
> + Google's ChromeOS EC has a gpio controller inside the Embedded Controller
> + (EC) and controlled via a host-command interface. The node for this
> + device should be under a cros-ec node like google,cros-ec-spi.
Why do we need a child node here?
Rob
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 01/22] dt-bindings: gpio: Add binding for ChromeOS EC GPIO controller
2024-02-15 14:06 ` Rob Herring
@ 2024-02-15 22:00 ` Stephen Boyd
0 siblings, 0 replies; 8+ messages in thread
From: Stephen Boyd @ 2024-02-15 22:00 UTC (permalink / raw)
To: Rob Herring
Cc: chrome-platform, linux-kernel, patches, linux-arm-kernel,
devicetree, linux-arm-msm, Douglas Anderson, Pin-yen Lin,
Linus Walleij, Bartosz Golaszewski, Krzysztof Kozlowski,
Conor Dooley, Lee Jones, Benson Leung, Guenter Roeck, linux-gpio
Quoting Rob Herring (2024-02-15 06:06:38)
> On Fri, Feb 09, 2024 at 11:09:12PM -0800, Stephen Boyd wrote:
> > +
> > +description:
> > + Google's ChromeOS EC has a gpio controller inside the Embedded Controller
> > + (EC) and controlled via a host-command interface. The node for this
> > + device should be under a cros-ec node like google,cros-ec-spi.
>
> Why do we need a child node here?
>
When in Rome... but I get your point. I will work on moving #gpio-cells
and gpio-controller into the cros-ec binding and populating some child
device from the mfd driver.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-02-15 22:00 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-10 7:09 [PATCH 00/22] platform/chrome: Add DT USB/DP muxing/topology to Trogdor Stephen Boyd
2024-02-10 7:09 ` [PATCH 01/22] dt-bindings: gpio: Add binding for ChromeOS EC GPIO controller Stephen Boyd
2024-02-11 13:26 ` Krzysztof Kozlowski
2024-02-15 0:44 ` Stephen Boyd
2024-02-15 14:06 ` Rob Herring
2024-02-15 22:00 ` Stephen Boyd
2024-02-10 7:09 ` [PATCH 02/22] gpio: Add ChromeOS EC GPIO driver Stephen Boyd
2024-02-13 17:57 ` Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).