From patchwork Tue Jan 26 02:01:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 12047983 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0987C433E6 for ; Tue, 26 Jan 2021 19:22:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CBF022228 for ; Tue, 26 Jan 2021 19:22:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732165AbhAZFt1 (ORCPT ); Tue, 26 Jan 2021 00:49:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732155AbhAZCF4 (ORCPT ); Mon, 25 Jan 2021 21:05:56 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04142C06121F for ; Mon, 25 Jan 2021 18:01:23 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id 11so9527764pfu.4 for ; Mon, 25 Jan 2021 18:01:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j0LasHSBnsU3ALa272OyzYW+m4IQeUHlxwjuI1lE7wc=; b=NCktlUhEX4O6P7penXk7JVIch+RP+QFg940peYApkOKGFZZ4i1pDtCLk2woG96vnFh sgzRwmnZ3R+frd92avauv/rSWTpMt/+cpItp/91yFHFTarinCFAnAE8WuejO3FwNBHCX 6xJ4KISABWuSrjD9oyQb9jHtw/ptgnd75NYRI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j0LasHSBnsU3ALa272OyzYW+m4IQeUHlxwjuI1lE7wc=; b=eaVU1EnAAGDpCfHSJsCDs8EvvCrPpQwjNnVeyLqChS9iPq2EjiifmegkISqsZ89e8o BJg93eJnYtmHjEsLMkxkwoZdu3ZoPUGdNcN6tPoHXE78UI4j47vI4QEQRdam/18aA6gF gaJ3VGNuz0FORGT9Sd25OmiHyieRDRejB3JP2flAvb3e/JAfOixiKgLP16L5o089qFI6 hGv6ZDveVBCH9ozZEN9qju3KDt02k2ILw6ch2IDosoY/cziAwD5hzk0SpAihBdErSiKI 9W36x0gLtHw5XR5Wtpi+cF7IkVaCmioSRps3llFD/oXYw0H0rfJBKAhM63ao42VhffP6 qMrA== X-Gm-Message-State: AOAM532VLD9aCGW4k3WHWbe7W/czT8fqB8AUdQb2Yq17d4gtPDbyGfJ7 dt6Rjss7qMVtwYNJpXFt4Jvarg== X-Google-Smtp-Source: ABdhPJxWcmF/fvsaQumL7NCcKePGkxjNd9CeNvBuAmr1vn1BGm427m1c0uEu0PsEjqhGG05z64k1nA== X-Received: by 2002:a62:7ac4:0:b029:1bc:309a:46d3 with SMTP id v187-20020a627ac40000b02901bc309a46d3mr2989448pfc.18.1611626482595; Mon, 25 Jan 2021 18:01:22 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:202:201:1066:b437:97cd:2278]) by smtp.gmail.com with ESMTPSA id n2sm16975028pfu.42.2021.01.25.18.01.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jan 2021 18:01:22 -0800 (PST) From: Stephen Boyd To: Jonathan Cameron Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Dmitry Torokhov , Benson Leung , Guenter Roeck , Douglas Anderson , Gwendal Grignou Subject: [PATCH v2 1/3] platform/chrome: cros_ec: Add SW_FRONT_PROXIMITY MKBP define Date: Mon, 25 Jan 2021 18:01:15 -0800 Message-Id: <20210126020117.2753615-3-swboyd@chromium.org> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog In-Reply-To: <20210126020117.2753615-1-swboyd@chromium.org> References: <20210126020117.2753615-1-swboyd@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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 Cc: Benson Leung Cc: Guenter Roeck Cc: Douglas Anderson Cc: Gwendal Grignou Signed-off-by: Stephen Boyd --- include/linux/platform_data/cros_ec_commands.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h index 86376779ab31..776e0b2be0e9 100644 --- a/include/linux/platform_data/cros_ec_commands.h +++ b/include/linux/platform_data/cros_ec_commands.h @@ -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 From patchwork Tue Jan 26 02:01:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 12045561 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0D6CC43381 for ; Tue, 26 Jan 2021 05:49:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 817DE206FA for ; Tue, 26 Jan 2021 05:49:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732134AbhAZFt0 (ORCPT ); Tue, 26 Jan 2021 00:49:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732132AbhAZCFz (ORCPT ); Mon, 25 Jan 2021 21:05:55 -0500 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64B1EC061221 for ; Mon, 25 Jan 2021 18:01:24 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id s15so8826415plr.9 for ; Mon, 25 Jan 2021 18:01:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wm686hw4j5jBSqd7g6ladOMIGoWP5gBh2lB4YQM5T54=; b=LTws3vDgcnnJwh5i3qvu2kkI6RqoXRxND4JDktxQgM3yKiZwheDz/EISwEaEyXjHOO pTAAv3jZW66k1+tHiC+BvlfIQHUaVp1mMe1Ag4ElqDk47Yc3ZzKA3QihhRJAx3j6CgZd vHI42ETF7GrSMq4ljzQOCkSPzYSenTxNcj1IE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wm686hw4j5jBSqd7g6ladOMIGoWP5gBh2lB4YQM5T54=; b=oq7U4raa2ETcXkl9OHkFm4bdmq/R4z/8h5lyl9VFedJIrbJCvmrVkTT+iCyDHlde0Q Vb1o7UYpyaH2ooR0CfQHTauChhcyyPGLQxVw1rv1L29d4en209D3rXvdC7HNQJVK9/fM RBlGOW2wGQ+Fwk2nvauebSQIBdZC3DvgnFj6OjH5tOaXCpk8XuvRAUkAQ2uiSL9VJB// w535C2K+jBWB4haR+uHpKcUF88rfEdz7+LeRlu4saRb9zl70EYj451Kp/Tk6T/omcDCL LYW6NorRIhF/BYAqm0gIMR/DivWAa2ZFqPzEH+GkF08R7itdwa/MH96Ap4/GhA7jlppF N+bw== X-Gm-Message-State: AOAM5332NhDR7TesiVM4OUnNmjW1YFFWKcGTySC/AHUcXCZ6YZj+2NC3 egl3UEg/UlD99MRtRwzCAvKHPQ== X-Google-Smtp-Source: ABdhPJywNUMbEQHIkLbDUwVCpu2O5SfY8LRfgGxByPbyXBlYnbqvlcNqMMo9n/A3xciukAOe2vuWyw== X-Received: by 2002:a17:90a:2f44:: with SMTP id s62mr3315525pjd.182.1611626484024; Mon, 25 Jan 2021 18:01:24 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:202:201:1066:b437:97cd:2278]) by smtp.gmail.com with ESMTPSA id n2sm16975028pfu.42.2021.01.25.18.01.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jan 2021 18:01:23 -0800 (PST) From: Stephen Boyd To: Jonathan Cameron Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Dmitry Torokhov , Benson Leung , Guenter Roeck , Douglas Anderson , Gwendal Grignou , devicetree@vger.kernel.org, Rob Herring Subject: [PATCH v2 2/3] dt-bindings: iio: Add cros ec proximity yaml doc Date: Mon, 25 Jan 2021 18:01:16 -0800 Message-Id: <20210126020117.2753615-4-swboyd@chromium.org> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog In-Reply-To: <20210126020117.2753615-1-swboyd@chromium.org> References: <20210126020117.2753615-1-swboyd@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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 Cc: Benson Leung Cc: Guenter Roeck Cc: Douglas Anderson Cc: Gwendal Grignou Cc: Cc: Rob Herring Signed-off-by: Stephen Boyd --- Changes from v1: * Added additionalProperties * Included proximity in cros-ec yaml .../google,cros-ec-mkbp-proximity.yaml | 38 +++++++++++++++++++ .../bindings/mfd/google,cros-ec.yaml | 3 ++ 2 files changed, 41 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml diff --git a/Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml b/Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml new file mode 100644 index 000000000000..c3141c2be286 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/proximity/google,cros-ec-mkbp-proximity.yaml @@ -0,0 +1,38 @@ +# 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 + - Benson Leung + - Enric Balletbo i Serra + +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: + - | + proximity { + compatible = "google,cros-ec-mkbp-proximity"; + label = "proximity-wifi-lte"; + }; diff --git a/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml b/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml index 76bf16ee27ec..479a9f15de32 100644 --- a/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml +++ b/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml @@ -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 From patchwork Tue Jan 26 02:01:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 12047947 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE7BEC433E0 for ; Tue, 26 Jan 2021 19:20:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64A3A22228 for ; Tue, 26 Jan 2021 19:20:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732283AbhAZFt2 (ORCPT ); Tue, 26 Jan 2021 00:49:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732121AbhAZCF4 (ORCPT ); Mon, 25 Jan 2021 21:05:56 -0500 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0E75C061223 for ; Mon, 25 Jan 2021 18:01:25 -0800 (PST) Received: by mail-pf1-x42d.google.com with SMTP id i63so9508968pfg.7 for ; Mon, 25 Jan 2021 18:01:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8b54P9GIkGKCedCV+9IXK9mS3hJ7SuH9lcmt0NSka3U=; b=deNrR4vH6Bt9lTiCeca1toKRSAMlDFT98VWfHbjWdBHAg/uoX5yZfc0LLhGTT81T7e Iuao3dyE8YDhRgaVtTkM4y6C2P+tma9RoNMnpx18AcDroiiZ0tjriWnAjX/RO0IscdwM sVWZx+lT5wyzZ/FhC6xDGcQ9JUUeWy7+93nsA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8b54P9GIkGKCedCV+9IXK9mS3hJ7SuH9lcmt0NSka3U=; b=U3hdD0j9CIpik+M6bm4OKb0oed0L2yZ49c9GkOEqP0D/BwPqfbL5i/Hc1PEXdkEgyp UrRXZ3sXSGLRw7+5EVh2q+FgUx5NVIFX81SAAsXwhWsCQcEkW+DUujuIMy5hSzpz44Yn 2ZY9I0QRmudbNzZ23onE996AiiJe1OnuWZ7wVWL2ktpnlR7FUmwuk0rr6IrHepjRExEg LscaZH8L/0xX3BD6QP10+VCOHOzPp7eMLMyWo5fG5gbiEIrzbvbA6P4fqOapavXjGdnW +sPrNJGNZj3kTKp0DlxgC4p9lhbX+gsyRfWlmvioiJCdFHjBvDnKgnsRK176+xkXpqwq c+hw== X-Gm-Message-State: AOAM533VsbiUxKBoy5jGHiUOJManPykQH9By6U5O/eFaF2SMhSD1ZdgR 88p9eBAajvKV75KEPZUmvQ6/dal58ZTKQw== X-Google-Smtp-Source: ABdhPJzPQqKmS+0qb5R5dR9sLDjyeEAUQaRnCbtX5QDKpMJTRUepH1pbqU55w1c3OCbLoECJmeYG0A== X-Received: by 2002:a63:2262:: with SMTP id t34mr3411934pgm.166.1611626485306; Mon, 25 Jan 2021 18:01:25 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:202:201:1066:b437:97cd:2278]) by smtp.gmail.com with ESMTPSA id n2sm16975028pfu.42.2021.01.25.18.01.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jan 2021 18:01:24 -0800 (PST) From: Stephen Boyd To: Jonathan Cameron Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Dmitry Torokhov , Benson Leung , Guenter Roeck , Douglas Anderson , Gwendal Grignou Subject: [PATCH v2 3/3] iio: proximity: Add a ChromeOS EC MKBP proximity driver Date: Mon, 25 Jan 2021 18:01:17 -0800 Message-Id: <20210126020117.2753615-5-swboyd@chromium.org> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog In-Reply-To: <20210126020117.2753615-1-swboyd@chromium.org> References: <20210126020117.2753615-1-swboyd@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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 Cc: Benson Leung Cc: Guenter Roeck Cc: Douglas Anderson Cc: Gwendal Grignou Signed-off-by: Stephen Boyd --- Changes from v1: * Sorted includes * Renamed to have MKBP everywhere * Use last_event_time for timestamp * Dropped claim calls * Dropped useless dev assignment drivers/iio/proximity/Kconfig | 11 + drivers/iio/proximity/Makefile | 1 + .../iio/proximity/cros_ec_mkbp_proximity.c | 243 ++++++++++++++++++ 3 files changed, 255 insertions(+) create mode 100644 drivers/iio/proximity/cros_ec_mkbp_proximity.c diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig index 12672a0e89ed..7c7203ca3ac6 100644 --- a/drivers/iio/proximity/Kconfig +++ b/drivers/iio/proximity/Kconfig @@ -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 diff --git a/drivers/iio/proximity/Makefile b/drivers/iio/proximity/Makefile index 9c1aca1a8b79..cbdac09433eb 100644 --- a/drivers/iio/proximity/Makefile +++ b/drivers/iio/proximity/Makefile @@ -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 diff --git a/drivers/iio/proximity/cros_ec_mkbp_proximity.c b/drivers/iio/proximity/cros_ec_mkbp_proximity.c new file mode 100644 index 000000000000..3c85d1843e3b --- /dev/null +++ b/drivers/iio/proximity/cros_ec_mkbp_proximity.c @@ -0,0 +1,243 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Driver for cros-ec proximity sensor exposed through MKBP switch + * + * Copyright 2021 Google LLC. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include + +struct cros_ec_mkbp_proximity_data { + struct cros_ec_device *ec; + struct iio_dev *indio_dev; + struct mutex lock; + struct notifier_block notifier; + bool enabled; +}; + +static const struct iio_event_spec cros_ec_mkbp_proximity_events[] = { + { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_EITHER, + .mask_separate = BIT(IIO_EV_INFO_ENABLE), + }, +}; + +static const struct iio_chan_spec cros_ec_mkbp_proximity_chan_spec[] = { + { + .type = IIO_PROXIMITY, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .event_spec = cros_ec_mkbp_proximity_events, + .num_event_specs = ARRAY_SIZE(cros_ec_mkbp_proximity_events), + }, +}; + +static int cros_ec_mkbp_proximity_parse_state(const void *data) +{ + u32 switches = get_unaligned_le32(data); + + return !!(switches & BIT(EC_MKBP_FRONT_PROXIMITY)); +} + +static int cros_ec_mkbp_proximity_query(struct cros_ec_device *ec_dev, + int *state) +{ + struct { + struct cros_ec_command msg; + union { + struct ec_params_mkbp_info params; + u32 switches; + }; + } __packed buf = { }; + struct ec_params_mkbp_info *params = &buf.params; + struct cros_ec_command *msg = &buf.msg; + u32 *switches = &buf.switches; + size_t insize = sizeof(*switches); + int ret; + + msg->command = EC_CMD_MKBP_INFO; + msg->version = 1; + msg->outsize = sizeof(*params); + msg->insize = insize; + + params->info_type = EC_MKBP_INFO_CURRENT; + params->event_type = EC_MKBP_EVENT_SWITCH; + + ret = cros_ec_cmd_xfer_status(ec_dev, msg); + if (ret < 0) + return ret; + + if (ret != insize) { + dev_warn(ec_dev->dev, "wrong result size: %d != %zu\n", ret, + insize); + return -EPROTO; + } + + *state = cros_ec_mkbp_proximity_parse_state(switches); + return IIO_VAL_INT; +} + +static int cros_ec_mkbp_proximity_notify(struct notifier_block *nb, + unsigned long queued_during_suspend, + void *_ec) +{ + struct cros_ec_mkbp_proximity_data *data; + struct cros_ec_device *ec = _ec; + u8 event_type = ec->event_data.event_type & EC_MKBP_EVENT_TYPE_MASK; + void *switches = &ec->event_data.data.switches; + struct iio_dev *indio_dev; + s64 timestamp; + int state, dir; + u64 ev; + + if (event_type == EC_MKBP_EVENT_SWITCH) { + data = container_of(nb, struct cros_ec_mkbp_proximity_data, + notifier); + indio_dev = data->indio_dev; + + mutex_lock(&data->lock); + if (data->enabled) { + timestamp = ktime_to_ns(ec->last_event_time); + state = cros_ec_mkbp_proximity_parse_state(switches); + dir = state ? IIO_EV_DIR_FALLING : IIO_EV_DIR_RISING; + + ev = IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 0, + IIO_EV_TYPE_THRESH, dir); + iio_push_event(indio_dev, ev, timestamp); + } + mutex_unlock(&data->lock); + } + + return NOTIFY_OK; +} + +static int cros_ec_mkbp_proximity_read_raw(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, int *val, + int *val2, long mask) +{ + struct cros_ec_mkbp_proximity_data *data = iio_priv(indio_dev); + struct cros_ec_device *ec = data->ec; + + if (chan->type != IIO_PROXIMITY) + return -EINVAL; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + return cros_ec_mkbp_proximity_query(ec, val); + } + + return -EINVAL; +} + +static int cros_ec_mkbp_proximity_read_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir) +{ + struct cros_ec_mkbp_proximity_data *data = iio_priv(indio_dev); + + return data->enabled; +} + +static int cros_ec_mkbp_proximity_write_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, int state) +{ + struct cros_ec_mkbp_proximity_data *data = iio_priv(indio_dev); + + mutex_lock(&data->lock); + data->enabled = state; + mutex_unlock(&data->lock); + + return 0; +} + +static const struct iio_info cros_ec_mkbp_proximity_info = { + .read_raw = cros_ec_mkbp_proximity_read_raw, + .read_event_config = cros_ec_mkbp_proximity_read_event_config, + .write_event_config = cros_ec_mkbp_proximity_write_event_config, +}; + +static int cros_ec_mkbp_proximity_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct cros_ec_device *ec = dev_get_drvdata(dev->parent); + struct iio_dev *indio_dev; + struct cros_ec_mkbp_proximity_data *data; + int ret; + + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + data = iio_priv(indio_dev); + data->ec = ec; + data->indio_dev = indio_dev; + mutex_init(&data->lock); + platform_set_drvdata(pdev, data); + + indio_dev->name = dev->driver->name; + indio_dev->info = &cros_ec_mkbp_proximity_info; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = cros_ec_mkbp_proximity_chan_spec; + indio_dev->num_channels = ARRAY_SIZE(cros_ec_mkbp_proximity_chan_spec); + + ret = devm_iio_device_register(dev, indio_dev); + if (ret) + return ret; + + data->notifier.notifier_call = cros_ec_mkbp_proximity_notify; + ret = blocking_notifier_chain_register(&ec->event_notifier, + &data->notifier); + if (ret) + dev_err(dev, "cannot register notifier: %d\n", ret); + + return ret; +} + +static int cros_ec_mkbp_proximity_remove(struct platform_device *pdev) +{ + struct cros_ec_mkbp_proximity_data *data = platform_get_drvdata(pdev); + struct cros_ec_device *ec = data->ec; + + blocking_notifier_chain_unregister(&ec->event_notifier, + &data->notifier); + + return 0; +} + +static const struct of_device_id cros_ec_mkbp_proximity_of_match[] = { + { .compatible = "google,cros-ec-mkbp-proximity" }, + {} +}; +MODULE_DEVICE_TABLE(of, cros_ec_mkbp_proximity_of_match); + +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), + }, + .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");