Skip to contentSkip to conversation

iio: Add a ChromeOS EC MKBP proximity driver

PATCH Superseded Stephen Boyd 4 participants 10 messages Feb 2, 2021 – Feb 10, 2021

Subsystems (4)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover iio: Add a ChromeOS EC MKBP proximity driver

This is a different approach to [1] where I tried to add this proximity sensor logic to the input subsystem. Instead, we'll take the approach of making a small IIO proximity driver that parses the EC switch bitmap to find out if the front proximity sensor is detecting something or not. This allows us to treat proximity sensors as IIO devices all the time in userspace instead of handling this switch on the EC via the input subsystem and then other proximity sensors via IIO.

I propose this is all merged through IIO subsystem. Please ack the first patch so it can be merged that way.

Changes from v3:
* Added SPI and cros-ec wrapper nodes to yaml example
* Ignore notifier registration return code that is always zero

Changes from v2:
* Check iio clock and use IIO time if not boottime

Changes from v1:
* Driver moved location
* Put mkbp everywhere
* Fixed up DT binding to not fail and make sure is a child of cros-ec
* Simplified logic for sending a message
* Dropped CONFIG_OF usage
* Sorted includes

[1] https://lore.kernel.org/r/[email protected]

Cc Dmitry Torokhov <[email protected]>
Cc Benson Leung <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Douglas Anderson <[email protected]>
Cc Gwendal Grignou <[email protected]>
Cc Rob Herring <[email protected]>
Cc Enric Balletbo i Serra <[email protected]>

Stephen Boyd (3):
platform/chrome: cros_ec: Add SW_FRONT_PROXIMITY MKBP define
dt-bindings: iio: Add cros ec proximity yaml doc
iio: proximity: Add a ChromeOS EC MKBP proximity driver

 .../google,cros-ec-mkbp-proximity.yaml        |  46 ++++
 .../bindings/mfd/google,cros-ec.yaml          |   3 +
 drivers/iio/proximity/Kconfig                 |  11 +
 drivers/iio/proximity/Makefile                |   1 +
 .../iio/proximity/cros_ec_mkbp_proximity.c    | 242 ++++++++++++++++++
 .../linux/platform_data/cros_ec_commands.h    |   1 +
 6 files changed, 304 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml
 create mode 100644 drivers/iio/proximity/cros_ec_mkbp_proximity.c

base-commit: 19c329f6808995b142b3966301f217c831e7cf31

Signature · 1 line
https://chromeos.dev
#1 lore raw

PATCH v4 1/3 platform/chrome: cros_ec: Add SW_FRONT_PROXIMITY MKBP define

Some cros ECs support a front proximity MKBP event via 'EC_MKBP_FRONT_PROXIMITY'. Add this define so it can be used in a future patch.

Cc Dmitry Torokhov <[email protected]>
Cc Benson Leung <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Douglas Anderson <[email protected]>
Cc Gwendal Grignou <[email protected]>
---
 include/linux/platform_data/cros_ec_commands.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/platform_data/cros_ec_commands.h +1 -0
index 86376779ab31..776e0b2be0e9 100644
@@ -3457,6 +3457,7 @@ struct ec_response_get_next_event_v1 {
 #define EC_MKBP_LID_OPEN	0
 #define EC_MKBP_TABLET_MODE	1
 #define EC_MKBP_BASE_ATTACHED	2
+#define EC_MKBP_FRONT_PROXIMITY	3
 
 /* Run keyboard factory test scanning */
 #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
Signature · 1 line
https://chromeos.dev
#2 lore raw

PATCH v4 2/3 dt-bindings: iio: Add cros ec proximity yaml doc

In reply to Stephen Boyd

Some cros ECs support a front proximity MKBP event via 'EC_MKBP_FRONT_PROXIMITY'. Add a DT binding to document this feature via a node that is a child of the main cros_ec device node. Devices that have this ability will describe this in firmware.

Cc Dmitry Torokhov <[email protected]>
Cc Benson Leung <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Douglas Anderson <[email protected]>
Cc Gwendal Grignou <[email protected]>
Cc Rob Herring <[email protected]>
Cc Enric Balletbo i Serra <[email protected]>
---
 .../google,cros-ec-mkbp-proximity.yaml        | 46 +++++++++++++++++++
 .../bindings/mfd/google,cros-ec.yaml          |  3 ++
 2 files changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml
Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml new file +46 -0
new file mode 100644
index 000000000000..d82b929af445
@@ -0,0 +1,46 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+
+$id: http://devicetree.org/schemas/iio/proximity/google,cros-ec-mkbp-proximity.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ChromeOS EC MKBP Proximity Sensor
+
+maintainers:
+  - Stephen Boyd <[email protected]>
+  - Benson Leung <[email protected]>
+  - Enric Balletbo i Serra <[email protected]>
+
+description: |
+  Google's ChromeOS EC sometimes has the ability to detect user proximity.
+  This is implemented on the EC as near/far logic and exposed to the OS
+  via an MKBP switch bit.
+
+properties:
+  compatible:
+    const: google,cros-ec-mkbp-proximity
+
+  label:
+    description: Name for proximity sensor
+
+required:
+  - compatible
+
+unevaluatedProperties: false
+additionalProperties: false
+
+examples:
+  - |
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+      ec@0 {
+        compatible = "google,cros-ec-spi";
+        reg = <0>;
+        proximity {
+          compatible = "google,cros-ec-mkbp-proximity";
+          label = "proximity-wifi-lte";
+        };
+      };
+    };
Documentation/devicetree/bindings/mfd/google,cros-ec.yaml +3 -0
index 76bf16ee27ec..479a9f15de32 100644
@@ -94,6 +94,9 @@ properties:
   keyboard-controller:
     $ref: "/schemas/input/google,cros-ec-keyb.yaml#"
 
+  proximity:
+    $ref: "/schemas/iio/proximity/google,cros-ec-mkbp-proximity.yaml#"
+
   codecs:
     type: object
     additionalProperties: false
Signature · 1 line
https://chromeos.dev
Reviewed-by Enric Balletbo i Serra on v4 2/3
#3 lore raw

Re: [PATCH v4 2/3] dt-bindings: iio: Add cros ec proximity yaml doc

Hi Stephen,

Missatge de Stephen Boyd <[email protected]> del dia dt., 2 de febr. 2021 a les 19:53:

Quoted 6 lines

Some cros ECs support a front proximity MKBP event via 'EC_MKBP_FRONT_PROXIMITY'. Add a DT binding to document this feature via a node that is a child of the main cros_ec device node. Devices that have this ability will describe this in firmware.

Quoted 9 lines
Cc Dmitry Torokhov <[email protected]>
Cc Benson Leung <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Douglas Anderson <[email protected]>
Cc Gwendal Grignou <[email protected]>
Cc Rob Herring <[email protected]>
Cc Enric Balletbo i Serra <[email protected]>

Thanks for adding a full example, IIRC this is preferred by Rob and we are also trying to apply this rule on all the cros-ec related bindings, so the dt_bindings_check really checks a full example. From my side looks good to me.

Quoted 75 lines
---
 .../google,cros-ec-mkbp-proximity.yaml        | 46 +++++++++++++++++++
 .../bindings/mfd/google,cros-ec.yaml          |  3 ++
 2 files changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml
Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml new file +46 -0
new file mode 100644
index 000000000000..d82b929af445
@@ -0,0 +1,46 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+
+$id: http://devicetree.org/schemas/iio/proximity/google,cros-ec-mkbp-proximity.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ChromeOS EC MKBP Proximity Sensor
+
+maintainers:
+  - Stephen Boyd <[email protected]>
+  - Benson Leung <[email protected]>
+  - Enric Balletbo i Serra <[email protected]>
+
+description: |
+  Google's ChromeOS EC sometimes has the ability to detect user proximity.
+  This is implemented on the EC as near/far logic and exposed to the OS
+  via an MKBP switch bit.
+
+properties:
+  compatible:
+    const: google,cros-ec-mkbp-proximity
+
+  label:
+    description: Name for proximity sensor
+
+required:
+  - compatible
+
+unevaluatedProperties: false
+additionalProperties: false
+
+examples:
+  - |
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+      ec@0 {
+        compatible = "google,cros-ec-spi";
+        reg = <0>;
+        proximity {
+          compatible = "google,cros-ec-mkbp-proximity";
+          label = "proximity-wifi-lte";
+        };
+      };
+    };
Documentation/devicetree/bindings/mfd/google,cros-ec.yaml +3 -1
index 76bf16ee27ec..479a9f15de32 100644
@@ -94,6 +94,9 @@ properties:
   keyboard-controller:
     $ref: "/schemas/input/google,cros-ec-keyb.yaml#"
 
+  proximity:
+    $ref: "/schemas/iio/proximity/google,cros-ec-mkbp-proximity.yaml#"
+
   codecs:
     type: object
     additionalProperties: false
--

https://chromeos.dev

maintainer
#4 lore raw

Re: [PATCH v4 2/3] dt-bindings: iio: Add cros ec proximity yaml doc

In reply to Stephen Boyd
Quoted 47 lines · Stephen Boyd

Some cros ECs support a front proximity MKBP event via 'EC_MKBP_FRONT_PROXIMITY'. Add a DT binding to document this feature via a node that is a child of the main cros_ec device node. Devices that have this ability will describe this in firmware.

Cc Dmitry Torokhov <[email protected]>
Cc Benson Leung <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Douglas Anderson <[email protected]>
Cc Gwendal Grignou <[email protected]>
Cc Rob Herring <[email protected]>
Cc Enric Balletbo i Serra <[email protected]>
---
 .../google,cros-ec-mkbp-proximity.yaml        | 46 +++++++++++++++++++
 .../bindings/mfd/google,cros-ec.yaml          |  3 ++
 2 files changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml
Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml new file +21 -0
new file mode 100644
index 000000000000..d82b929af445
@@ -0,0 +1,46 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+
+$id: http://devicetree.org/schemas/iio/proximity/google,cros-ec-mkbp-proximity.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ChromeOS EC MKBP Proximity Sensor
+
+maintainers:
+  - Stephen Boyd <[email protected]>
+  - Benson Leung <[email protected]>
+  - Enric Balletbo i Serra <[email protected]>
+
+description: |
+  Google's ChromeOS EC sometimes has the ability to detect user proximity.
+  This is implemented on the EC as near/far logic and exposed to the OS
+  via an MKBP switch bit.
+
+properties:
+  compatible:

Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml line 31

Quoted 10 lines
Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml new file +10 -0
+    const: google,cros-ec-mkbp-proximity
+
+  label:
+    description: Name for proximity sensor
+
+required:
+  - compatible
+
+unevaluatedProperties: false
+additionalProperties: false

Only need one. In this case 'additionalProperties'.

Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml line 44

Quoted 13 lines
Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml new file +13 -0
+
+examples:
+  - |
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+      ec@0 {
+        compatible = "google,cros-ec-spi";
+        reg = <0>;
+        proximity {
+          compatible = "google,cros-ec-mkbp-proximity";
+          label = "proximity-wifi-lte";
+        };

The complete examples I prefer is 1 example for the whole MFD in the MFD schema and no example here.

Quoted 19 lines
Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml new file +2 -0
+      };
+    };
Documentation/devicetree/bindings/mfd/google,cros-ec.yaml +3 -0
index 76bf16ee27ec..479a9f15de32 100644
@@ -94,6 +94,9 @@ properties:
   keyboard-controller:
     $ref: "/schemas/input/google,cros-ec-keyb.yaml#"
 
+  proximity:
+    $ref: "/schemas/iio/proximity/google,cros-ec-mkbp-proximity.yaml#"
+
   codecs:
     type: object
     additionalProperties: false
Signature · 1 line
https://chromeos.dev
#5 lore raw

Re: [PATCH v4 2/3] dt-bindings: iio: Add cros ec proximity yaml doc

Quoting Rob Herring (2021-02-09 13:13:47)

Quoted 10 lines · Stephen Boyd

Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml line 31

Quoted 7 lines
Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml new file +7 -0
+    description: Name for proximity sensor
+
+required:
+  - compatible
+
+unevaluatedProperties: false
+additionalProperties: false

Only need one. In this case 'additionalProperties'.

Got it.

Quoted 17 lines
Quoted 4 lines
Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml new file +3 -0
+
+examples:
+  - |

Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml line 44

Quoted 10 lines
Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml new file +10 -0
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+      ec@0 {
+        compatible = "google,cros-ec-spi";
+        reg = <0>;
+        proximity {
+          compatible = "google,cros-ec-mkbp-proximity";
+          label = "proximity-wifi-lte";
+        };

The complete examples I prefer is 1 example for the whole MFD in the MFD schema and no example here.

Alright. I can add it to the mfd binding instead.

Quoted 10 lines
Quoted 10 lines
(quoted diff) +2 -0
+      };
+    };
Documentation/devicetree/bindings/mfd/google,cros-ec.yaml +0 -0
index 76bf16ee27ec..479a9f15de32 100644
@@ -94,6 +94,9 @@ properties:
   keyboard-controller:
     $ref: "/schemas/input/google,cros-ec-keyb.yaml#"
#6 lore raw

PATCH v4 3/3 iio: proximity: Add a ChromeOS EC MKBP proximity driver

In reply to Stephen Boyd

Add support for a ChromeOS EC proximity driver that exposes a "front" proximity sensor via the IIO subsystem. The EC decides when front proximity is near and sets an MKBP switch 'EC_MKBP_FRONT_PROXIMITY' to notify the kernel of proximity. Similarly, when proximity detects something far away it sets the switch bit to 0. For now this driver exposes a single sensor, but it could be expanded in the future via more MKBP bits if desired.

Cc Dmitry Torokhov <[email protected]>
Cc Benson Leung <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Douglas Anderson <[email protected]>
Cc Gwendal Grignou <[email protected]>
---
 drivers/iio/proximity/Kconfig                 |  11 +
 drivers/iio/proximity/Makefile                |   1 +
 .../iio/proximity/cros_ec_mkbp_proximity.c    | 242 ++++++++++++++++++
 3 files changed, 254 insertions(+)
 create mode 100644 drivers/iio/proximity/cros_ec_mkbp_proximity.c
drivers/iio/proximity/Kconfig +11 -0
index 12672a0e89ed..7c7203ca3ac6 100644
@@ -21,6 +21,17 @@ endmenu
 
 menu "Proximity and distance sensors"
 
+config CROS_EC_MKBP_PROXIMITY
+	tristate "ChromeOS EC MKBP Proximity sensor"
+	depends on CROS_EC
+	help
+	  Say Y here to enable the proximity sensor implemented via the ChromeOS EC MKBP
+	  switches protocol. You must enable one bus option (CROS_EC_I2C or CROS_EC_SPI)
+	  to use this.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called cros_ec_mkbp_proximity.
+
 config ISL29501
 	tristate "Intersil ISL29501 Time Of Flight sensor"
 	depends on I2C
drivers/iio/proximity/Makefile +1 -0
index 9c1aca1a8b79..cbdac09433eb 100644
@@ -5,6 +5,7 @@
 
 # When adding new entries keep the list in alphabetical order
 obj-$(CONFIG_AS3935)		+= as3935.o
+obj-$(CONFIG_CROS_EC_MKBP_PROXIMITY) += cros_ec_mkbp_proximity.o
 obj-$(CONFIG_ISL29501)		+= isl29501.o
 obj-$(CONFIG_LIDAR_LITE_V2)	+= pulsedlight-lidar-lite-v2.o
 obj-$(CONFIG_MB1232)		+= mb1232.o
drivers/iio/proximity/cros_ec_mkbp_proximity.c new file +242 -0

242 lines not on this page · raw message

Signature · 1 line
https://chromeos.dev
maintainer
#7 lore raw

Re: [PATCH v4 3/3] iio: proximity: Add a ChromeOS EC MKBP proximity driver

Quoted 8 lines · On Tue, 2 Feb 2021 10:44:34 -0800 Stephen Boyd <[email protected]> wrote:

Add support for a ChromeOS EC proximity driver that exposes a "front" proximity sensor via the IIO subsystem. The EC decides when front proximity is near and sets an MKBP switch 'EC_MKBP_FRONT_PROXIMITY' to notify the kernel of proximity. Similarly, when proximity detects something far away it sets the switch bit to 0. For now this driver exposes a single sensor, but it could be expanded in the future via more MKBP bits if desired.

Quoted 7 lines
Cc Dmitry Torokhov <[email protected]>
Cc Benson Leung <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Douglas Anderson <[email protected]>
Cc Gwendal Grignou <[email protected]>

Just one thing noticed on a final read through. I'm happy to fix up whilst applying. Otherwise all I'm waiting for now is to give Rob time to look at the device tree binding if he wants to do so.

Jonathan

Quoted 6 lines
drivers/iio/proximity/cros_ec_mkbp_proximity.c new file +0 -0
new file mode 100644
index 000000000000..23bed4562b34
@@ -0,0 +1,242 @@

...

drivers/iio/proximity/cros_ec_mkbp_proximity.c line 234

Quoted 4 lines
drivers/iio/proximity/cros_ec_mkbp_proximity.c new file +4 -0
+static struct platform_driver cros_ec_mkbp_proximity_driver = {
+	.driver = {
+		.name = "cros-ec-mkbp-proximity",
+		.of_match_table = of_match_ptr(cros_ec_mkbp_proximity_of_match),

I'm going to assume we know no one is going to use this with ACPI via PRP0001 given presumably the firmware on these devices is tightly controlled.

However, we should should still drop the of_match_ptr
as it will lead to an unused warning for cros_ec_mkbp_proximity_of_match if anyone builds this without CONFIG_OF + it sets a general bad precedence that I'd rather wasn't around for people to copy. Note that in general we are slowly ripping these out of IIO but probably lots still there.

If this is all that is needed in this version I'll just do it whilst applying unless anyone shouts.

Jonathan

Quoted 8 lines
drivers/iio/proximity/cros_ec_mkbp_proximity.c new file +8 -0
+	},
+	.probe = cros_ec_mkbp_proximity_probe,
+	.remove = cros_ec_mkbp_proximity_remove,
+};
+module_platform_driver(cros_ec_mkbp_proximity_driver);
+
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("ChromeOS EC MKBP proximity sensor driver");
#8 lore raw

Re: [PATCH v4 3/3] iio: proximity: Add a ChromeOS EC MKBP proximity driver

Quoting Jonathan Cameron (2021-02-06 08:17:11)

Quoted 10 lines

drivers/iio/proximity/cros_ec_mkbp_proximity.c line 234

Quoted 4 lines · On Tue, 2 Feb 2021 10:44:34 -0800 Stephen Boyd <[email protected]> wrote:
drivers/iio/proximity/cros_ec_mkbp_proximity.c new file +4 -0
+static struct platform_driver cros_ec_mkbp_proximity_driver = {
+     .driver = {
+             .name = "cros-ec-mkbp-proximity",
+             .of_match_table = of_match_ptr(cros_ec_mkbp_proximity_of_match),

I'm going to assume we know no one is going to use this with ACPI via PRP0001 given presumably the firmware on these devices is tightly controlled.

Correct.

Quoted 11 lines

However, we should should still drop the of_match_ptr
as it will lead to an unused warning for cros_ec_mkbp_proximity_of_match if anyone builds this without CONFIG_OF + it sets a general bad precedence that I'd rather wasn't around for people to copy. Note that in general we are slowly ripping these out of IIO but probably lots still there.

If this is all that is needed in this version I'll just do it whilst applying unless anyone shouts.

Agreed. Thanks for fixing that last little bit.

#9 lore raw

Re: [PATCH v4 3/3] iio: proximity: Add a ChromeOS EC MKBP proximity driver

Quoting Stephen Boyd (2021-02-06 19:21:39)

Quoted 22 lines

Quoting Jonathan Cameron (2021-02-06 08:17:11)

Quoted 10 lines

drivers/iio/proximity/cros_ec_mkbp_proximity.c line 234

Quoted 4 lines · On Tue, 2 Feb 2021 10:44:34 -0800 Stephen Boyd <[email protected]> wrote:
drivers/iio/proximity/cros_ec_mkbp_proximity.c new file +4 -0
+static struct platform_driver cros_ec_mkbp_proximity_driver = {
+     .driver = {
+             .name = "cros-ec-mkbp-proximity",
+             .of_match_table = of_match_ptr(cros_ec_mkbp_proximity_of_match),

I'm going to assume we know no one is going to use this with ACPI via PRP0001 given presumably the firmware on these devices is tightly controlled.

Correct.

Quoted 8 lines

However, we should should still drop the of_match_ptr
as it will lead to an unused warning for cros_ec_mkbp_proximity_of_match if anyone builds this without CONFIG_OF + it sets a general bad precedence that I'd rather wasn't around for people to copy. Note that in general we are slowly ripping these out of IIO but probably lots still there.

Quoted 5 lines
Quoted 3 lines

If this is all that is needed in this version I'll just do it whilst applying unless anyone shouts.

Agreed. Thanks for fixing that last little bit.

Seems Rob wanted a small tweak to the binding so I'll resend this now and drop the of_match_ptr() usage.