From patchwork Mon Aug 3 23:58:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Campello X-Patchwork-Id: 11699269 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 136CE13B1 for ; Mon, 3 Aug 2020 23:58:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D3ED2245C for ; Mon, 3 Aug 2020 23:58:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="DlJfuhKg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729168AbgHCX6X (ORCPT ); Mon, 3 Aug 2020 19:58:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729093AbgHCX6U (ORCPT ); Mon, 3 Aug 2020 19:58:20 -0400 Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A122C061756 for ; Mon, 3 Aug 2020 16:58:20 -0700 (PDT) Received: by mail-il1-x134.google.com with SMTP id t4so32659697iln.1 for ; Mon, 03 Aug 2020 16:58:20 -0700 (PDT) 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=EvWcLJLa3Y53Vay5RMNxPF61bNyr+HrQ2gp6EQOAsiA=; b=DlJfuhKgon2eBMn6wys5U+E13+Qrr+UPKm33xGWpyc3wpO2k+7/7Sx48mfCxuAe35q 3Jk59WDzBr2hJceHVzgOw/EQl9n3q75y+w8wXpuOLV3i3/sDmDLpL0nFcRx8tUhIOxRy JgKYVj706F2GN0ZeAz4cvKO8/R/yURiVXxHS0= 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=EvWcLJLa3Y53Vay5RMNxPF61bNyr+HrQ2gp6EQOAsiA=; b=P+16pEnLRc6Owxtdl2M6BViyDanZOldALGcOL+PBqAlTSoMdRa6hy0FAsbWvZ7bHEJ xhSbztXVP4WZh0GM0d7XNm1MtTvPD09b3RyXEja3/QMcZ8hojFxNoRX66ZPOAkPohU/z E1NdfzqCY1+cU+Ck1kYVHLdO11irj/Hpal70WNmidoVkiJ2oZ9DYG9+sb14p2ecpZV7y N4hEypgKkFnOgPypkP2jhubtGSYeTbPUnOO8eh1uBw3Rmv1Amuv9jtWvxLnjTJklnFba Q1l430ODI+KjO5d0ChrZp5e4biiShNHm2FP0rxbsbvy98UHNDjFABbLYh7dQRdgdiwJd ZRqw== X-Gm-Message-State: AOAM532GdPVBIDUT+sv2mwdfx9ipwHtOodmKVs/G48zWg5boPBuAk7IA q7kUyC2/WXTguTvCEpcU9HvfrA== X-Google-Smtp-Source: ABdhPJynJdzgOO3Mqe09VzRnogKDfLpOpKaW1TxTvVR6Wldca0tfZ2b5h89NUJboTDFs5nQDUtZraQ== X-Received: by 2002:a92:6c0b:: with SMTP id h11mr1990621ilc.66.1596499099673; Mon, 03 Aug 2020 16:58:19 -0700 (PDT) Received: from derch.Home (97-122-92-59.hlrn.qwest.net. [97.122.92.59]) by smtp.gmail.com with ESMTPSA id x185sm11075992iof.41.2020.08.03.16.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 16:58:19 -0700 (PDT) From: Daniel Campello To: LKML , LKML Cc: Jonathan Cameron , Daniel Campello , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Douglas Anderson , Stephen Boyd , Rob Herring , linux-iio@vger.kernel.org Subject: [PATCH v5 01/15] dt-bindings: iio: Add bindings for sx9310 sensor Date: Mon, 3 Aug 2020 17:58:01 -0600 Message-Id: <20200803175559.v5.1.I0925046377211b8b6f06764857f03b4ab592bddb@changeid> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog In-Reply-To: <20200803235815.778997-1-campello@chromium.org> References: <20200803235815.778997-1-campello@chromium.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Adds device tree bindings for sx9310 sensor. Signed-off-by: Daniel Campello Cc: Hartmut Knaack Cc: Lars-Peter Clausen Cc: Peter Meerwald-Stadler Cc: Rob Herring Reviewed-by: Douglas Anderson [swboyd@chromium.org: Add both regulators and make them optional] Signed-off-by: Stephen Boyd Reviewed-by: Rob Herring --- Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: - Added #io-channel-cells as a required property .../iio/proximity/semtech,sx9310.yaml | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/proximity/semtech,sx9310.yaml diff --git a/Documentation/devicetree/bindings/iio/proximity/semtech,sx9310.yaml b/Documentation/devicetree/bindings/iio/proximity/semtech,sx9310.yaml new file mode 100644 index 00000000000000..5739074d3592fe --- /dev/null +++ b/Documentation/devicetree/bindings/iio/proximity/semtech,sx9310.yaml @@ -0,0 +1,65 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/proximity/semtech,sx9310.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Semtech's SX9310 capacitive proximity sensor + +maintainers: + - Daniel Campello + +description: | + Semtech's SX9310/SX9311 capacitive proximity/button solution. + + Specifications about the devices can be found at: + https://www.semtech.com/products/smart-sensing/sar-sensors/sx9310 + +properties: + compatible: + enum: + - semtech,sx9310 + - semtech,sx9311 + + reg: + maxItems: 1 + + interrupts: + description: + The sole interrupt generated by the device used to announce the + preceding reading request has finished and that data is + available or that a close/far proximity event has happened. + maxItems: 1 + + vdd-supply: + description: Main power supply + + svdd-supply: + description: Host interface power supply + + "#io-channel-cells": + const: 1 + +required: + - compatible + - reg + - "#io-channel-cells" + +additionalProperties: false + +examples: + - | + #include + i2c { + #address-cells = <1>; + #size-cells = <0>; + proximity@28 { + compatible = "semtech,sx9310"; + reg = <0x28>; + interrupt-parent = <&pio>; + interrupts = <5 IRQ_TYPE_LEVEL_LOW 5>; + vdd-supply = <&pp3300_a>; + svdd-supply = <&pp1800_prox>; + #io-channel-cells = <1>; + }; + }; From patchwork Mon Aug 3 23:58:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Campello X-Patchwork-Id: 11699297 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 119B414E3 for ; Mon, 3 Aug 2020 23:59:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3274F20786 for ; Mon, 3 Aug 2020 23:59:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="MepWisbf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729186AbgHCX6Y (ORCPT ); Mon, 3 Aug 2020 19:58:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729096AbgHCX6W (ORCPT ); Mon, 3 Aug 2020 19:58:22 -0400 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B64B7C06179E for ; Mon, 3 Aug 2020 16:58:21 -0700 (PDT) Received: by mail-io1-xd41.google.com with SMTP id w12so26785474iom.4 for ; Mon, 03 Aug 2020 16:58:21 -0700 (PDT) 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=/61pn1CdLr1rzYhabfdSsEsfkPyuISE8XqB22ABJzx0=; b=MepWisbfRIY6K3OhlKfjczh0YapOUCkA94HG4WONpJJYVpmz0AxT6/uvH7si9S6oMc m2paZKeUi9aF5GGY0toDt7rwUmZjxTvavoVR5PRBs4833Taat4qlJTX6jcnt2At1mn6D uWLjIYCXkORzxY5EQxsFDbuhyUzgAFQsk+1hM= 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=/61pn1CdLr1rzYhabfdSsEsfkPyuISE8XqB22ABJzx0=; b=ntyMrTJDWxTmZ6p8qvF9hxEWwRiPm6aQfXUR23Ztqll9q8XZ0rSdr+4ojIYZjMt7sM mh+QqYkdws4SFZoj7W/T0B5+BdodivfRtfAaZFTMYb/C7IB/Exx9gRCZloUGF2O8HBTO +VIaSvBN1foxavzWpykZnr36oVFcfjytYXfmav/1WqKqzxfiv88S+1ImXDILnLAV1DYK Q1m05eHX1luiACgJoIO44Af5ieEPyN54nRki/QoAHxygJG0yuLMxWrto5zZzvFuM43AO ydy8/ybbxmBBhkqXXyO2FTZMrEo4TfXpKVMoScAzLsxO7QbUgqko+qJAf2EXsVMLyAVM SV/A== X-Gm-Message-State: AOAM530n7qV9soLgLQHyVIRFKSQpFiAlMi603K9+coQU4dO4xZom/4yp 3uZvojkKyPAEBAVAFW3MMDRz7w== X-Google-Smtp-Source: ABdhPJyPWsyIcFHAus0DnVFLAHNOXmhU+kCaprm9Ksy+0O7ybBKebHeeS8rZ9Y9yg//bzjOrQa+VkQ== X-Received: by 2002:a5e:9512:: with SMTP id r18mr2328168ioj.139.1596499100967; Mon, 03 Aug 2020 16:58:20 -0700 (PDT) Received: from derch.Home (97-122-92-59.hlrn.qwest.net. [97.122.92.59]) by smtp.gmail.com with ESMTPSA id x185sm11075992iof.41.2020.08.03.16.58.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 16:58:20 -0700 (PDT) From: Daniel Campello To: LKML , LKML Cc: Jonathan Cameron , Daniel Campello , Stephen Boyd , Andy Shevchenko , Douglas Anderson , Gwendal Grignou , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org Subject: [PATCH v5 02/15] iio: sx9310: Update macros declarations Date: Mon, 3 Aug 2020 17:58:02 -0600 Message-Id: <20200803175559.v5.2.I30721195b2f20ec785715f7a2757930302a2a7e8@changeid> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog In-Reply-To: <20200803235815.778997-1-campello@chromium.org> References: <20200803235815.778997-1-campello@chromium.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Follows spec sheet for macro declarations. Signed-off-by: Daniel Campello Reviewed-by: Stephen Boyd --- Changes in v5: - Added #include Changes in v4: - Updated macro SX9310_REG_STAT1_COMPSTAT_MASK at call site. - Use FIELD_GET/FIELD_PREP instead of manual shift. Changes in v3: None Changes in v2: None drivers/iio/proximity/sx9310.c | 146 +++++++++++++++------------------ 1 file changed, 68 insertions(+), 78 deletions(-) diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index d161f3061e353d..d7c77fc661ba86 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -11,6 +11,7 @@ */ #include +#include #include #include #include @@ -33,45 +34,44 @@ #define SX9310_REG_IRQ_SRC 0x00 #define SX9310_REG_STAT0 0x01 #define SX9310_REG_STAT1 0x02 +#define SX9310_REG_STAT1_COMPSTAT_MASK GENMASK(3, 0) #define SX9310_REG_IRQ_MSK 0x03 #define SX9310_CONVDONE_IRQ BIT(3) #define SX9310_FAR_IRQ BIT(5) #define SX9310_CLOSE_IRQ BIT(6) -#define SX9310_EVENT_IRQ (SX9310_FAR_IRQ | \ - SX9310_CLOSE_IRQ) #define SX9310_REG_IRQ_FUNC 0x04 #define SX9310_REG_PROX_CTRL0 0x10 -#define SX9310_REG_PROX_CTRL0_PROXSTAT2 0x10 -#define SX9310_REG_PROX_CTRL0_EN_MASK 0x0F +#define SX9310_REG_PROX_CTRL0_SENSOREN_MASK GENMASK(3, 0) +#define SX9310_REG_PROX_CTRL0_SCANPERIOD_MASK GENMASK(7, 4) +#define SX9310_REG_PROX_CTRL0_SCANPERIOD_15MS 0x01 #define SX9310_REG_PROX_CTRL1 0x11 #define SX9310_REG_PROX_CTRL2 0x12 -#define SX9310_REG_PROX_CTRL2_COMBMODE_ALL 0x80 -#define SX9310_REG_PROX_CTRL2_SHIELDEN_DYNAMIC 0x04 +#define SX9310_REG_PROX_CTRL2_COMBMODE_CS1_CS2 (0x02 << 6) +#define SX9310_REG_PROX_CTRL2_SHIELDEN_DYNAMIC (0x01 << 2) #define SX9310_REG_PROX_CTRL3 0x13 -#define SX9310_REG_PROX_CTRL3_GAIN0_X8 0x0c +#define SX9310_REG_PROX_CTRL3_GAIN0_X8 (0x03 << 2) #define SX9310_REG_PROX_CTRL3_GAIN12_X4 0x02 #define SX9310_REG_PROX_CTRL4 0x14 #define SX9310_REG_PROX_CTRL4_RESOLUTION_FINEST 0x07 #define SX9310_REG_PROX_CTRL5 0x15 -#define SX9310_REG_PROX_CTRL5_RANGE_SMALL 0xc0 -#define SX9310_REG_PROX_CTRL5_STARTUPSENS_CS1 0x04 +#define SX9310_REG_PROX_CTRL5_RANGE_SMALL (0x03 << 6) +#define SX9310_REG_PROX_CTRL5_STARTUPSENS_CS1 (0x01 << 2) #define SX9310_REG_PROX_CTRL5_RAWFILT_1P25 0x02 #define SX9310_REG_PROX_CTRL6 0x16 -#define SX9310_REG_PROX_CTRL6_COMP_COMMON 0x20 +#define SX9310_REG_PROX_CTRL6_AVGTHRESH_DEFAULT 0x20 #define SX9310_REG_PROX_CTRL7 0x17 -#define SX9310_REG_PROX_CTRL7_AVGNEGFILT_2 0x08 +#define SX9310_REG_PROX_CTRL7_AVGNEGFILT_2 (0x01 << 3) #define SX9310_REG_PROX_CTRL7_AVGPOSFILT_512 0x05 #define SX9310_REG_PROX_CTRL8 0x18 #define SX9310_REG_PROX_CTRL9 0x19 -#define SX9310_REG_PROX_CTRL8_9_PTHRESH12_28 0x40 -#define SX9310_REG_PROX_CTRL8_9_PTHRESH_96 0x88 +#define SX9310_REG_PROX_CTRL8_9_PTHRESH_28 (0x08 << 3) +#define SX9310_REG_PROX_CTRL8_9_PTHRESH_96 (0x11 << 3) #define SX9310_REG_PROX_CTRL8_9_BODYTHRESH_900 0x03 #define SX9310_REG_PROX_CTRL8_9_BODYTHRESH_1500 0x05 #define SX9310_REG_PROX_CTRL10 0x1a -#define SX9310_REG_PROX_CTRL10_HYST_6PCT 0x10 -#define SX9310_REG_PROX_CTRL10_CLOSE_DEBOUNCE_8 0x12 -#define SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_8 0x03 +#define SX9310_REG_PROX_CTRL10_HYST_6PCT (0x01 << 4) +#define SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_2 0x01 #define SX9310_REG_PROX_CTRL11 0x1b #define SX9310_REG_PROX_CTRL12 0x1c #define SX9310_REG_PROX_CTRL13 0x1d @@ -82,8 +82,8 @@ #define SX9310_REG_PROX_CTRL18 0x22 #define SX9310_REG_PROX_CTRL19 0x23 #define SX9310_REG_SAR_CTRL0 0x2a -#define SX9310_REG_SAR_CTRL0_SARDEB_4_SAMPLES 0x40 -#define SX9310_REG_SAR_CTRL0_SARHYST_8 0x10 +#define SX9310_REG_SAR_CTRL0_SARDEB_4_SAMPLES (0x02 << 5) +#define SX9310_REG_SAR_CTRL0_SARHYST_8 (0x02 << 3) #define SX9310_REG_SAR_CTRL1 0x2b /* Each increment of the slope register is 0.0078125. */ #define SX9310_REG_SAR_CTRL1_SLOPE(_hnslope) (_hnslope / 78125) @@ -107,7 +107,7 @@ #define SX9310_REG_SAR_MSB 0x39 #define SX9310_REG_SAR_LSB 0x3a -#define SX9310_REG_I2CADDR 0x40 +#define SX9310_REG_I2C_ADDR 0x40 #define SX9310_REG_PAUSE 0x41 #define SX9310_REG_WHOAMI 0x42 #define SX9310_WHOAMI_VALUE 0x01 @@ -116,14 +116,9 @@ #define SX9310_REG_RESET 0x7f #define SX9310_SOFT_RESET 0xde -#define SX9310_SCAN_PERIOD_MASK GENMASK(7, 4) -#define SX9310_SCAN_PERIOD_SHIFT 4 - -#define SX9310_COMPSTAT_MASK GENMASK(3, 0) /* 4 hardware channels, as defined in STAT0: COMB, CS2, CS1 and CS0. */ #define SX9310_NUM_CHANNELS 4 -#define SX9310_CHAN_ENABLED_MASK GENMASK(3, 0) struct sx9310_data { /* Serialize access to registers and channel configuration */ @@ -251,7 +246,7 @@ static const struct regmap_range sx9310_readable_reg_ranges[] = { regmap_reg_range(SX9310_REG_PROX_CTRL0, SX9310_REG_PROX_CTRL19), regmap_reg_range(SX9310_REG_SAR_CTRL0, SX9310_REG_SAR_CTRL2), regmap_reg_range(SX9310_REG_SENSOR_SEL, SX9310_REG_SAR_LSB), - regmap_reg_range(SX9310_REG_I2CADDR, SX9310_REG_WHOAMI), + regmap_reg_range(SX9310_REG_I2C_ADDR, SX9310_REG_WHOAMI), regmap_reg_range(SX9310_REG_RESET, SX9310_REG_RESET), }; @@ -292,7 +287,7 @@ static int sx9310_update_chan_en(struct sx9310_data *data, if ((data->chan_read | data->chan_event) != (chan_read | chan_event)) { ret = regmap_update_bits(data->regmap, SX9310_REG_PROX_CTRL0, - SX9310_CHAN_ENABLED_MASK, + SX9310_REG_PROX_CTRL0_SENSOREN_MASK, chan_read | chan_event); if (ret) return ret; @@ -361,7 +356,7 @@ static int sx9310_wait_for_sample(struct sx9310_data *data) if (ret < 0) return ret; - val = (val & SX9310_SCAN_PERIOD_MASK) >> SX9310_SCAN_PERIOD_SHIFT; + val = FIELD_GET(SX9310_REG_PROX_CTRL0_SCANPERIOD_MASK, val); msleep(sx9310_scan_period_table[val]); @@ -435,7 +430,7 @@ static int sx9310_read_samp_freq(struct sx9310_data *data, int *val, int *val2) if (ret < 0) return ret; - regval = (regval & SX9310_SCAN_PERIOD_MASK) >> SX9310_SCAN_PERIOD_SHIFT; + regval = FIELD_GET(SX9310_REG_PROX_CTRL0_SCANPERIOD_MASK, regval); *val = sx9310_samp_freq_table[regval].val; *val2 = sx9310_samp_freq_table[regval].val2; @@ -482,9 +477,10 @@ static int sx9310_set_samp_freq(struct sx9310_data *data, int val, int val2) mutex_lock(&data->mutex); - ret = regmap_update_bits(data->regmap, SX9310_REG_PROX_CTRL0, - SX9310_SCAN_PERIOD_MASK, - i << SX9310_SCAN_PERIOD_SHIFT); + ret = regmap_update_bits( + data->regmap, SX9310_REG_PROX_CTRL0, + SX9310_REG_PROX_CTRL0_SCANPERIOD_MASK, + FIELD_PREP(SX9310_REG_PROX_CTRL0_SCANPERIOD_MASK, i)); mutex_unlock(&data->mutex); @@ -572,7 +568,7 @@ static irqreturn_t sx9310_irq_thread_handler(int irq, void *private) goto out; } - if (val & SX9310_EVENT_IRQ) + if (val & (SX9310_FAR_IRQ | SX9310_CLOSE_IRQ)) sx9310_push_events(indio_dev); if (val & SX9310_CONVDONE_IRQ) @@ -600,6 +596,7 @@ static int sx9310_write_event_config(struct iio_dev *indio_dev, enum iio_event_direction dir, int state) { struct sx9310_data *data = iio_priv(indio_dev); + unsigned int eventirq = SX9310_FAR_IRQ | SX9310_CLOSE_IRQ; int ret; /* If the state hasn't changed, there's nothing to do. */ @@ -612,7 +609,7 @@ static int sx9310_write_event_config(struct iio_dev *indio_dev, if (ret < 0) goto out_unlock; if (!(data->chan_event & ~BIT(chan->channel))) { - ret = sx9310_enable_irq(data, SX9310_EVENT_IRQ); + ret = sx9310_enable_irq(data, eventirq); if (ret < 0) sx9310_put_event_channel(data, chan->channel); } @@ -621,7 +618,7 @@ static int sx9310_write_event_config(struct iio_dev *indio_dev, if (ret < 0) goto out_unlock; if (!data->chan_event) { - ret = sx9310_disable_irq(data, SX9310_EVENT_IRQ); + ret = sx9310_disable_irq(data, eventirq); if (ret < 0) sx9310_get_event_channel(data, chan->channel); } @@ -746,53 +743,46 @@ struct sx9310_reg_default { u8 def; }; -#define SX_INIT(_reg, _def) \ - { \ - .reg = SX9310_REG_##_reg, \ - .def = _def, \ - } - static const struct sx9310_reg_default sx9310_default_regs[] = { - SX_INIT(IRQ_MSK, 0x00), - SX_INIT(IRQ_FUNC, 0x00), + { SX9310_REG_IRQ_MSK, 0x00 }, + { SX9310_REG_IRQ_FUNC, 0x00 }, /* * The lower 4 bits should not be set as it enable sensors measurements. * Turning the detection on before the configuration values are set to * good values can cause the device to return erroneous readings. */ - SX_INIT(PROX_CTRL0, SX9310_REG_PROX_CTRL0_PROXSTAT2), - SX_INIT(PROX_CTRL1, 0x00), - SX_INIT(PROX_CTRL2, SX9310_REG_PROX_CTRL2_COMBMODE_ALL | - SX9310_REG_PROX_CTRL2_SHIELDEN_DYNAMIC), - SX_INIT(PROX_CTRL3, SX9310_REG_PROX_CTRL3_GAIN0_X8 | - SX9310_REG_PROX_CTRL3_GAIN12_X4), - SX_INIT(PROX_CTRL4, SX9310_REG_PROX_CTRL4_RESOLUTION_FINEST), - SX_INIT(PROX_CTRL5, SX9310_REG_PROX_CTRL5_RANGE_SMALL | - SX9310_REG_PROX_CTRL5_STARTUPSENS_CS1 | - SX9310_REG_PROX_CTRL5_RAWFILT_1P25), - SX_INIT(PROX_CTRL6, SX9310_REG_PROX_CTRL6_COMP_COMMON), - SX_INIT(PROX_CTRL7, SX9310_REG_PROX_CTRL7_AVGNEGFILT_2 | - SX9310_REG_PROX_CTRL7_AVGPOSFILT_512), - SX_INIT(PROX_CTRL8, SX9310_REG_PROX_CTRL8_9_PTHRESH_96 | - SX9310_REG_PROX_CTRL8_9_BODYTHRESH_1500), - SX_INIT(PROX_CTRL9, SX9310_REG_PROX_CTRL8_9_PTHRESH12_28 | - SX9310_REG_PROX_CTRL8_9_BODYTHRESH_900), - SX_INIT(PROX_CTRL10, SX9310_REG_PROX_CTRL10_HYST_6PCT | - SX9310_REG_PROX_CTRL10_CLOSE_DEBOUNCE_8 | - SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_8), - SX_INIT(PROX_CTRL11, 0x00), - SX_INIT(PROX_CTRL12, 0x00), - SX_INIT(PROX_CTRL13, 0x00), - SX_INIT(PROX_CTRL14, 0x00), - SX_INIT(PROX_CTRL15, 0x00), - SX_INIT(PROX_CTRL16, 0x00), - SX_INIT(PROX_CTRL17, 0x00), - SX_INIT(PROX_CTRL18, 0x00), - SX_INIT(PROX_CTRL19, 0x00), - SX_INIT(SAR_CTRL0, SX9310_REG_SAR_CTRL0_SARDEB_4_SAMPLES | - SX9310_REG_SAR_CTRL0_SARHYST_8), - SX_INIT(SAR_CTRL1, SX9310_REG_SAR_CTRL1_SLOPE(10781250)), - SX_INIT(SAR_CTRL2, SX9310_REG_SAR_CTRL2_SAROFFSET_DEFAULT), + { SX9310_REG_PROX_CTRL0, SX9310_REG_PROX_CTRL0_SCANPERIOD_15MS }, + { SX9310_REG_PROX_CTRL1, 0x00 }, + { SX9310_REG_PROX_CTRL2, SX9310_REG_PROX_CTRL2_COMBMODE_CS1_CS2 | + SX9310_REG_PROX_CTRL2_SHIELDEN_DYNAMIC }, + { SX9310_REG_PROX_CTRL3, SX9310_REG_PROX_CTRL3_GAIN0_X8 | + SX9310_REG_PROX_CTRL3_GAIN12_X4 }, + { SX9310_REG_PROX_CTRL4, SX9310_REG_PROX_CTRL4_RESOLUTION_FINEST }, + { SX9310_REG_PROX_CTRL5, SX9310_REG_PROX_CTRL5_RANGE_SMALL | + SX9310_REG_PROX_CTRL5_STARTUPSENS_CS1 | + SX9310_REG_PROX_CTRL5_RAWFILT_1P25 }, + { SX9310_REG_PROX_CTRL6, SX9310_REG_PROX_CTRL6_AVGTHRESH_DEFAULT }, + { SX9310_REG_PROX_CTRL7, SX9310_REG_PROX_CTRL7_AVGNEGFILT_2 | + SX9310_REG_PROX_CTRL7_AVGPOSFILT_512 }, + { SX9310_REG_PROX_CTRL8, SX9310_REG_PROX_CTRL8_9_PTHRESH_96 | + SX9310_REG_PROX_CTRL8_9_BODYTHRESH_1500 }, + { SX9310_REG_PROX_CTRL9, SX9310_REG_PROX_CTRL8_9_PTHRESH_28 | + SX9310_REG_PROX_CTRL8_9_BODYTHRESH_900 }, + { SX9310_REG_PROX_CTRL10, SX9310_REG_PROX_CTRL10_HYST_6PCT | + SX9310_REG_PROX_CTRL10_FAR_DEBOUNCE_2 }, + { SX9310_REG_PROX_CTRL11, 0x00 }, + { SX9310_REG_PROX_CTRL12, 0x00 }, + { SX9310_REG_PROX_CTRL13, 0x00 }, + { SX9310_REG_PROX_CTRL14, 0x00 }, + { SX9310_REG_PROX_CTRL15, 0x00 }, + { SX9310_REG_PROX_CTRL16, 0x00 }, + { SX9310_REG_PROX_CTRL17, 0x00 }, + { SX9310_REG_PROX_CTRL18, 0x00 }, + { SX9310_REG_PROX_CTRL19, 0x00 }, + { SX9310_REG_SAR_CTRL0, SX9310_REG_SAR_CTRL0_SARDEB_4_SAMPLES | + SX9310_REG_SAR_CTRL0_SARHYST_8 }, + { SX9310_REG_SAR_CTRL1, SX9310_REG_SAR_CTRL1_SLOPE(10781250) }, + { SX9310_REG_SAR_CTRL2, SX9310_REG_SAR_CTRL2_SAROFFSET_DEFAULT }, }; /* Activate all channels and perform an initial compensation. */ @@ -809,7 +799,7 @@ static int sx9310_init_compensation(struct iio_dev *indio_dev) /* run the compensation phase on all channels */ ret = regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, - ctrl0 | SX9310_REG_PROX_CTRL0_EN_MASK); + ctrl0 | SX9310_REG_PROX_CTRL0_SENSOREN_MASK); if (ret < 0) return ret; @@ -818,7 +808,7 @@ static int sx9310_init_compensation(struct iio_dev *indio_dev) ret = regmap_read(data->regmap, SX9310_REG_STAT1, &val); if (ret < 0) goto out; - if (!(val & SX9310_COMPSTAT_MASK)) + if (!(val & SX9310_REG_STAT1_COMPSTAT_MASK)) break; } @@ -992,7 +982,7 @@ static int __maybe_unused sx9310_suspend(struct device *dev) if (ret) goto out; - ctrl0 = data->suspend_ctrl0 & ~SX9310_REG_PROX_CTRL0_EN_MASK; + ctrl0 = data->suspend_ctrl0 & ~SX9310_REG_PROX_CTRL0_SENSOREN_MASK; ret = regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, ctrl0); if (ret) goto out; From patchwork Mon Aug 3 23:58:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Campello X-Patchwork-Id: 11699291 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3B5CE13B1 for ; Mon, 3 Aug 2020 23:59:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 660F3206F8 for ; Mon, 3 Aug 2020 23:59:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="MHUNxH6s" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729212AbgHCX6Z (ORCPT ); Mon, 3 Aug 2020 19:58:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729173AbgHCX6X (ORCPT ); Mon, 3 Aug 2020 19:58:23 -0400 Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD92BC0617A1 for ; Mon, 3 Aug 2020 16:58:22 -0700 (PDT) Received: by mail-il1-x144.google.com with SMTP id l17so22459879ilq.13 for ; Mon, 03 Aug 2020 16:58:22 -0700 (PDT) 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=bp6OwO92DPNru+lJBtL8+lflqmBd40LGlvDc78rVJ9c=; b=MHUNxH6sVnlzX16mnBO0Libr5RgVsQYv7/UqRC0xTEUbYCbo3sOqowucBA3nb+m5MX m8FwZqCpFUl/T08XoQJUnhJNTzHCdLOmUkdAV6Pnv+6WaOYjgLjlNOPBAK2MVIOrIRhP eQ1iYXdyJitiQUzJSNADJUzaWFUIrKDbJSCOU= 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=bp6OwO92DPNru+lJBtL8+lflqmBd40LGlvDc78rVJ9c=; b=mGbdq1zKpFWt5h0KiDU/d2mwr46AL9ZVbCR4cl4yfx8XitWDZPi/YxxuYQwcScbR2U mntyoCyz9Rs145fT/pKIIOqh5ys0Xj2T7hVK+zVIeySOk6J56q/klqSqITNPawWcxpjS Dux0s2PzqSb+n3zKbfqR/rN1mcqPX9ItTUcqB0ZJEoiae3ejpTei9d8/LuLFmN0QW2Hg ipZLsw3bbPNCMj9bK017eFScbLqogckrvzV3HaZvW0FHC5E3qgnVrS0oJrKCXxJI0HnK cm53+Adds0Z47ahRbraalGbYZmPEOMDDqjF5tZ8/u24FNP6/y4KhAvO+PGEO3fYJs4Q2 wKhw== X-Gm-Message-State: AOAM533PzTnQEOcwzVaCxpE27TMaMS3JVSyh5YysZna8tvL6tehvSAt2 eW7xbCkGQwh+bI2uX4xnt4LErQ== X-Google-Smtp-Source: ABdhPJxHGJNGeHI0qdX4nnx8eSv09ZJiDnvrlC0tQ13wHy6OexeBXFmXFY6nkq0UlgH4JqadZFUj6w== X-Received: by 2002:a92:3006:: with SMTP id x6mr2079172ile.260.1596499102078; Mon, 03 Aug 2020 16:58:22 -0700 (PDT) Received: from derch.Home (97-122-92-59.hlrn.qwest.net. [97.122.92.59]) by smtp.gmail.com with ESMTPSA id x185sm11075992iof.41.2020.08.03.16.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 16:58:21 -0700 (PDT) From: Daniel Campello To: LKML , LKML Cc: Jonathan Cameron , Daniel Campello , Stephen Boyd , Andy Shevchenko , Douglas Anderson , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org Subject: [PATCH v5 03/15] iio: sx9310: Fix irq handling Date: Mon, 3 Aug 2020 17:58:03 -0600 Message-Id: <20200803175559.v5.3.Idbfcd2e92d2fd89b6ed2e83211bd3e6c06852c33@changeid> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog In-Reply-To: <20200803235815.778997-1-campello@chromium.org> References: <20200803235815.778997-1-campello@chromium.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Fixes enable/disable irq handling at various points. The driver needs to only enable/disable irqs if there is an actual irq handler installed. Signed-off-by: Daniel Campello Reviewed-by: Stephen Boyd Reviewed-by: Andy Shevchenko --- Changes in v5: None Changes in v4: - Reverted condition check logic on enable/disable_irq methods. Changes in v3: - Moved irq presence check down to lower methods Changes in v2: - Reordered error handling on sx9310_resume() drivers/iio/proximity/sx9310.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index d7c77fc661ba86..dafee85018aa6d 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -323,11 +323,15 @@ static int sx9310_put_event_channel(struct sx9310_data *data, int channel) static int sx9310_enable_irq(struct sx9310_data *data, unsigned int irq) { + if (!data->client->irq) + return 0; return regmap_update_bits(data->regmap, SX9310_REG_IRQ_MSK, irq, irq); } static int sx9310_disable_irq(struct sx9310_data *data, unsigned int irq) { + if (!data->client->irq) + return 0; return regmap_update_bits(data->regmap, SX9310_REG_IRQ_MSK, irq, 0); } @@ -381,7 +385,7 @@ static int sx9310_read_proximity(struct sx9310_data *data, mutex_unlock(&data->mutex); - if (data->client->irq > 0) { + if (data->client->irq) { ret = wait_for_completion_interruptible(&data->completion); reinit_completion(&data->completion); } else { @@ -1010,10 +1014,11 @@ static int __maybe_unused sx9310_resume(struct device *dev) out: mutex_unlock(&data->mutex); + if (ret) + return ret; enable_irq(data->client->irq); - - return ret; + return 0; } static const struct dev_pm_ops sx9310_pm_ops = { From patchwork Mon Aug 3 23:58:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Campello X-Patchwork-Id: 11699299 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 982AA13B1 for ; Mon, 3 Aug 2020 23:59:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C36E520786 for ; Mon, 3 Aug 2020 23:59:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="V88DoAJz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729185AbgHCX7T (ORCPT ); Mon, 3 Aug 2020 19:59:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729175AbgHCX6Y (ORCPT ); Mon, 3 Aug 2020 19:58:24 -0400 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15142C06174A for ; Mon, 3 Aug 2020 16:58:24 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id s189so33168162iod.2 for ; Mon, 03 Aug 2020 16:58:24 -0700 (PDT) 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=5cSkoNniKNC956C/ks1iOGmqLlwslZdR0J6VVIESB2A=; b=V88DoAJzfQvpiH+5JxevlSU6EhKal8pET2oyqthvc2pFhCs3Sp9rwSgY5coM8nTZPO wruV+Ufx3cSmBIt+yyoql6iJzRJmTpmrYvBC0A1UF9XPu5pIFNda+pySkz8y5Vl6zA22 cITV089oYBOg5Togk9Qdt83DQPR/anpO6qYE4= 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=5cSkoNniKNC956C/ks1iOGmqLlwslZdR0J6VVIESB2A=; b=M7THWNpFAfeq2gDChUbWB1laVKsVRoNe601iefquXYTPPVv2EDVqN02YOQ8qPM8YYd 3L1sIm6a60JQCAdaAi/V0nNUVC6kpIE0Qx9s/VeZaPPbVWkGTOXfkeCtwpPc/ARaHx88 qGFbs4MUG/3nYC+nzu+RtXC4WJVJhdoGID5YL2nzU52lP9LpW99sg/0DM+Kys8E75d7u ncpu+qEpYG801FuLaC+Pc+W8DYvgP8WN5vvWLpMCbAoPJd/pUccgKtAXtVHBt7/gvyB3 WLvOseowpxp1sv1A3ieoLa7LTI6qU5AAOjiCJsedMKP9D1EjVP0F916j4zlmTKZsmMad B65Q== X-Gm-Message-State: AOAM531Eu/QHIYz4ycHyXA1WV7m8gpQS1h5PEwvWZpJTTYQy94zTZJCs VqX97SIqFQ2wMhPCEoHGvu4/vQ== X-Google-Smtp-Source: ABdhPJyqY7hE+U+7SMnQ+qMn5joVOAC/qjH45Yfs0wJshVR9Up1oVmmnvOB4rHGp4B9hYhCW0JjSJA== X-Received: by 2002:a05:6602:1343:: with SMTP id i3mr2388451iov.134.1596499103295; Mon, 03 Aug 2020 16:58:23 -0700 (PDT) Received: from derch.Home (97-122-92-59.hlrn.qwest.net. [97.122.92.59]) by smtp.gmail.com with ESMTPSA id x185sm11075992iof.41.2020.08.03.16.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 16:58:22 -0700 (PDT) From: Daniel Campello To: LKML , LKML Cc: Jonathan Cameron , Daniel Campello , kbuild test robot , Andy Shevchenko , Stephen Boyd , Douglas Anderson , Enrico Granata , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org Subject: [PATCH v5 04/15] iio: sx9310: Remove acpi and of table macros Date: Mon, 3 Aug 2020 17:58:04 -0600 Message-Id: <20200803175559.v5.4.I9bf713a86d6076b44441ef5f534f9c240271699a@changeid> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog In-Reply-To: <20200803235815.778997-1-campello@chromium.org> References: <20200803235815.778997-1-campello@chromium.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Avoids unused warnings due to acpi/of table macros. Reported-by: kbuild test robot Signed-off-by: Daniel Campello Reviewed-by: Andy Shevchenko Reviewed-by: Stephen Boyd --- Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: - Added #include drivers/iio/proximity/sx9310.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index dafee85018aa6d..9daf2b8591a0a0 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -16,8 +16,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -1049,8 +1049,8 @@ MODULE_DEVICE_TABLE(i2c, sx9310_id); static struct i2c_driver sx9310_driver = { .driver = { .name = "sx9310", - .acpi_match_table = ACPI_PTR(sx9310_acpi_match), - .of_match_table = of_match_ptr(sx9310_of_match), + .acpi_match_table = sx9310_acpi_match, + .of_match_table = sx9310_of_match, .pm = &sx9310_pm_ops, }, .probe = sx9310_probe, From patchwork Mon Aug 3 23:58:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Campello X-Patchwork-Id: 11699293 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D07413B1 for ; Mon, 3 Aug 2020 23:59:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8A6D20786 for ; Mon, 3 Aug 2020 23:59:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="nJyTQLv+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729221AbgHCX7J (ORCPT ); Mon, 3 Aug 2020 19:59:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729209AbgHCX6Z (ORCPT ); Mon, 3 Aug 2020 19:58:25 -0400 Received: from mail-il1-x143.google.com (mail-il1-x143.google.com [IPv6:2607:f8b0:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E13A0C06179E for ; Mon, 3 Aug 2020 16:58:24 -0700 (PDT) Received: by mail-il1-x143.google.com with SMTP id t4so32659817iln.1 for ; Mon, 03 Aug 2020 16:58:24 -0700 (PDT) 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=E2ctQerw1ZPbA2zuLIi6/rRsyLUTQ+gWJWVkQvyMgWY=; b=nJyTQLv+zLnyN/sgUDu1vGkZfpIZyEG+0giWMo3GXr58KTfEnInnWT+Jm1O4bVCeXx xRXevYa7KqxQRD2n69EgiW2IKfeXlizLx2kriE6DRfuobDnMjzBqLAZ7FsSXzWDwZIj1 XCy6MwGA9wLi4shT2nTr5Q3Ub2Q5arG0Fmdk8= 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=E2ctQerw1ZPbA2zuLIi6/rRsyLUTQ+gWJWVkQvyMgWY=; b=efmhTgXz0CBCumLujP3phHpHiRUvNeINgIPZ9B/SEHjru/VcmqM6Wpo+9yCfzVMeYp CErsS+cHBoHi2GSJbdLGR1fYJ6s4o203MQZzGhBlIwa6lRq19wzGGUgQXyYURcTys4v0 H1GOYolly3hr2ucC0d625pO1QwvXx/5Mo+n7p8FrpIiOdl6lMeMnj+wJg5QYyT21v1Gr +i9HJZcjRfPjE7JUv00RvTlrI/q0KB+W7N8greni4zrNEHAIdkfloTlDYSyMlmbgHT0f s+o8vho5gq7WGDmPAtIl5/lBSXfVdCUqqF4aXGHj4N6G3ws9W7BtBv8nbqDvWGvYrrTW gotA== X-Gm-Message-State: AOAM530YjL+3j1bVItfHpXQRz+/T4wICEHVYWtgQ0IfHiBBiNXUozVkm YilwYp1BsDKh+d4XwZJlr0D8Kg== X-Google-Smtp-Source: ABdhPJxFAphk+KFRD7qjdSBT20KaIKYyOBi1u10LiuUjabStMlRVk/lAVrWN5Z8QvENBdDFmmOmnLA== X-Received: by 2002:a92:4802:: with SMTP id v2mr1941457ila.32.1596499104315; Mon, 03 Aug 2020 16:58:24 -0700 (PDT) Received: from derch.Home (97-122-92-59.hlrn.qwest.net. [97.122.92.59]) by smtp.gmail.com with ESMTPSA id x185sm11075992iof.41.2020.08.03.16.58.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 16:58:23 -0700 (PDT) From: Daniel Campello To: LKML , LKML Cc: Jonathan Cameron , Daniel Campello , Andy Shevchenko , Stephen Boyd , Douglas Anderson , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org Subject: [PATCH v5 05/15] iio: sx9310: Change from .probe to .probe_new Date: Mon, 3 Aug 2020 17:58:05 -0600 Message-Id: <20200803175559.v5.5.Ieb5fdf7381764835dad0b3099c7b19ba754e4c47@changeid> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog In-Reply-To: <20200803235815.778997-1-campello@chromium.org> References: <20200803235815.778997-1-campello@chromium.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Uses .probe_new in place of .probe. Also uses device_get_match_data() for whoami matching. Signed-off-by: Daniel Campello Reviewed-by: Andy Shevchenko Reviewed-by: Stephen Boyd --- Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: - Added '\n' to dev_err() drivers/iio/proximity/sx9310.c | 39 ++++++++++++---------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index 9daf2b8591a0a0..66ecdd309e0ddc 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -139,7 +139,7 @@ struct sx9310_data { struct completion completion; unsigned int chan_read, chan_event; int channel_users[SX9310_NUM_CHANNELS]; - int whoami; + unsigned int whoami; }; static const struct iio_event_spec sx9310_events[] = { @@ -858,24 +858,15 @@ static int sx9310_init_device(struct iio_dev *indio_dev) static int sx9310_set_indio_dev_name(struct device *dev, struct iio_dev *indio_dev, - const struct i2c_device_id *id, int whoami) + unsigned int whoami) { - const struct acpi_device_id *acpi_id; - - /* id will be NULL when enumerated via ACPI */ - if (id) { - if (id->driver_data != whoami) - dev_err(dev, "WHOAMI does not match i2c_device_id: %s", - id->name); - } else if (ACPI_HANDLE(dev)) { - acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev); - if (!acpi_id) - return -ENODEV; - if (acpi_id->driver_data != whoami) - dev_err(dev, "WHOAMI does not match acpi_device_id: %s", - acpi_id->id); - } else + unsigned int long ddata; + + ddata = (uintptr_t)device_get_match_data(dev); + if (ddata != whoami) { + dev_err(dev, "WHOAMI does not match device data: %u\n", whoami); return -ENODEV; + } switch (whoami) { case SX9310_WHOAMI_VALUE: @@ -885,15 +876,14 @@ static int sx9310_set_indio_dev_name(struct device *dev, indio_dev->name = "sx9311"; break; default: - dev_err(dev, "unexpected WHOAMI response: %u", whoami); + dev_err(dev, "unexpected WHOAMI response: %u\n", whoami); return -ENODEV; } return 0; } -static int sx9310_probe(struct i2c_client *client, - const struct i2c_device_id *id) +static int sx9310_probe(struct i2c_client *client) { int ret; struct iio_dev *indio_dev; @@ -919,8 +909,7 @@ static int sx9310_probe(struct i2c_client *client, return ret; } - ret = sx9310_set_indio_dev_name(&client->dev, indio_dev, id, - data->whoami); + ret = sx9310_set_indio_dev_name(&client->dev, indio_dev, data->whoami); if (ret < 0) return ret; @@ -1033,8 +1022,8 @@ static const struct acpi_device_id sx9310_acpi_match[] = { MODULE_DEVICE_TABLE(acpi, sx9310_acpi_match); static const struct of_device_id sx9310_of_match[] = { - { .compatible = "semtech,sx9310" }, - { .compatible = "semtech,sx9311" }, + { .compatible = "semtech,sx9310", (void *)SX9310_WHOAMI_VALUE }, + { .compatible = "semtech,sx9311", (void *)SX9311_WHOAMI_VALUE }, {}, }; MODULE_DEVICE_TABLE(of, sx9310_of_match); @@ -1053,7 +1042,7 @@ static struct i2c_driver sx9310_driver = { .of_match_table = sx9310_of_match, .pm = &sx9310_pm_ops, }, - .probe = sx9310_probe, + .probe_new = sx9310_probe, .id_table = sx9310_id, }; module_i2c_driver(sx9310_driver); From patchwork Mon Aug 3 23:58:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Campello X-Patchwork-Id: 11699289 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AC85716B1 for ; Mon, 3 Aug 2020 23:59:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D889220786 for ; Mon, 3 Aug 2020 23:59:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="mOTd5An1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729227AbgHCX7J (ORCPT ); Mon, 3 Aug 2020 19:59:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729221AbgHCX60 (ORCPT ); Mon, 3 Aug 2020 19:58:26 -0400 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 052ECC061757 for ; Mon, 3 Aug 2020 16:58:26 -0700 (PDT) Received: by mail-io1-xd41.google.com with SMTP id z6so40449661iow.6 for ; Mon, 03 Aug 2020 16:58:25 -0700 (PDT) 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=2rN/d/4Ztn21EkbHD6dVPT8VsDxw/yLn4xET1uonrRo=; b=mOTd5An1Z+sPuy/vpHw9OIndbv2Qr1Ixek2fEEqWq9M8glS/doo0hBw070w8rHtDEB cJjEveE7pN/yBVmSOkC76eK0NhJJXQqkWYQNSfwPgT44M/ar/GngHyrhu5PCMf/2gTan gnHaXcNPfy2yhWKG3elyNK/qzSxDMGDaK8kMg= 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=2rN/d/4Ztn21EkbHD6dVPT8VsDxw/yLn4xET1uonrRo=; b=I6ChlKXUrQ50Z5ApHwk1ofTUDv8zuhsCOW+PasCFQVJbvdCqgHYjsJw/xDUZ5mOnf3 k9UZDtURvBT3Kk2CPrTvGDwfuS3KNF09S8colQTLBWlyTPmdvhueqwv0abKKdpwKBEKB PnmY5B7NW0+LyvIltSc+jHwMjhjAAmkNi8XT8VvDgrpTEVsDwxo0hEtrzfTpTvqAH2A+ Hy5HAJ7pdeUNa7gYM36s5BQq80t1fBZ999zK6Gb7LuQhO6PF4sddpScI/ymYq68Mfz+J bx7aTWOylwaLMRb8TjD8PqEAvvLXETuZnbuSP5BwReOqPDpC4QrbtA3y5IOVPqRK6qZo E3Wg== X-Gm-Message-State: AOAM531iGz3xtBWm3zWVn1W9AZoPJAiFcXe1eLDnevDm6Xf4kYknx+5H jlrN2R2BX4Iob8JktarUXuy5uQ== X-Google-Smtp-Source: ABdhPJyMFpx3vadGuvlAiinOybtGhpTSrLbfBcMLBRI2fj0uFKksxd/X3CrB6Za8JNA+hQZa/StRIw== X-Received: by 2002:a5d:9b05:: with SMTP id y5mr2415091ion.59.1596499105355; Mon, 03 Aug 2020 16:58:25 -0700 (PDT) Received: from derch.Home (97-122-92-59.hlrn.qwest.net. [97.122.92.59]) by smtp.gmail.com with ESMTPSA id x185sm11075992iof.41.2020.08.03.16.58.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 16:58:25 -0700 (PDT) From: Daniel Campello To: LKML , LKML Cc: Jonathan Cameron , Daniel Campello , Andy Shevchenko , Douglas Anderson , Enrico Granata , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Stephen Boyd , linux-iio@vger.kernel.org Subject: [PATCH v5 06/15] iio: sx9310: Fixes various memory handling Date: Mon, 3 Aug 2020 17:58:06 -0600 Message-Id: <20200803175559.v5.6.I8accffd77d616cb55b29bc3021cb0f5e1da3b68a@changeid> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog In-Reply-To: <20200803235815.778997-1-campello@chromium.org> References: <20200803235815.778997-1-campello@chromium.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Makes use __aligned(8) to ensure that the timestamp is correctly aligned when we call io_push_to_buffers_with_timestamp(). Also makes use of sizeof() for regmap_bulk_read instead of static value. Signed-off-by: Daniel Campello Reviewed-by: Andy Shevchenko --- Changes in v5: - Really use a pointer to buffer struct on iio_push_to_buffers_with_timestamp(). Changes in v4: - Use pointer to buffer struct on iio_push_to_buffers_with_timestamp(). Changes in v3: - Changed buffer to struct type to align timestamp memory properly. Changes in v2: - Fixed commit message from "iio: sx9310: Align memory" drivers/iio/proximity/sx9310.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index 66ecdd309e0ddc..127b1ba79e2dea 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -132,8 +132,11 @@ struct sx9310_data { */ bool prox_stat[SX9310_NUM_CHANNELS]; bool trigger_enabled; - __be16 buffer[SX9310_NUM_CHANNELS + - 4]; /* 64-bit data + 64-bit timestamp */ + /* Ensure correct alignment of timestamp when present. */ + struct { + __be16 channels[SX9310_NUM_CHANNELS]; + s64 ts __aligned(8); + } buffer; /* Remember enabled channels and sample rate during suspend. */ unsigned int suspend_ctrl0; struct completion completion; @@ -344,7 +347,7 @@ static int sx9310_read_prox_data(struct sx9310_data *data, if (ret < 0) return ret; - return regmap_bulk_read(data->regmap, chan->address, val, 2); + return regmap_bulk_read(data->regmap, chan->address, val, sizeof(*val)); } /* @@ -694,10 +697,10 @@ static irqreturn_t sx9310_trigger_handler(int irq, void *private) if (ret < 0) goto out; - data->buffer[i++] = val; + data->buffer.channels[i++] = val; } - iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, + iio_push_to_buffers_with_timestamp(indio_dev, &data->buffer, pf->timestamp); out: From patchwork Mon Aug 3 23:58:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Campello X-Patchwork-Id: 11699287 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5CBED13B1 for ; Mon, 3 Aug 2020 23:59:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8794E206F8 for ; Mon, 3 Aug 2020 23:59:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="QEBfx44U" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729267AbgHCX7I (ORCPT ); Mon, 3 Aug 2020 19:59:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729244AbgHCX61 (ORCPT ); Mon, 3 Aug 2020 19:58:27 -0400 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EB39C0617A2 for ; Mon, 3 Aug 2020 16:58:27 -0700 (PDT) Received: by mail-il1-x141.google.com with SMTP id t4so32659872iln.1 for ; Mon, 03 Aug 2020 16:58:27 -0700 (PDT) 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=UWzWGkh475eDnP3/JizWhFyPcCx/wKE7/hIAnqOcwN8=; b=QEBfx44UooFtfhTxwf1A4x4A9gi0hLVCA6qIkKxtH5k+4EKr8BXe28XPFAz3JNjnOM fCZG/bsMuWnRquSeVgkI69N8h1D3cq2RgeJB+0XtIWTZaZZoabYHF9bXazz4oI+RL0JM xYBzKT11MqPD94epC4MK0rkbD6mTKROxNqpEg= 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=UWzWGkh475eDnP3/JizWhFyPcCx/wKE7/hIAnqOcwN8=; b=sLFMiOzhOFXoNklAKMeZL0W5Lmb7wiN9p22DXUjXwFvoH18zQeKx0+A7oRR/hYTzzn FfbfMI2/4RGc8I5krADc9EC2Q3jNBJ2NLxK5Sej0Ib7c3d86G+rjjsg3+8yLQyw3WOJy 8WfQeuWu7n1eNh0H696Zcwwny/ert2r0DpUA79B9nxIyIzXYQpVTWMdYZO0Hmlk0mWXz WegUc5/U/paWalCb8KRdmDIYRdBpIq6a2e7IStg2QRpveCGo+8T410f1keiXCCr1w87o mKREc7wVQxW1z7ck9uqhZU1VQ6cmxvf83cqlGKNcQIwKo/zdQ/XGkY9s18i5Z1xeadQb xQsw== X-Gm-Message-State: AOAM5328u6WBZFujMw7h3KYqhDVFFVfEFZMtnnnoP1vBvuIS6m3BnJBq qujzIKAATBIwgbRq5CcihUwu8A== X-Google-Smtp-Source: ABdhPJzG3AEbRk3LQeUtcxS/Bon/dWfpCYq98jD/xg7No+VeQ8I8ceObrwztDfwhfaCsgN3PTBkVsw== X-Received: by 2002:a92:858d:: with SMTP id f135mr2002429ilh.257.1596499106394; Mon, 03 Aug 2020 16:58:26 -0700 (PDT) Received: from derch.Home (97-122-92-59.hlrn.qwest.net. [97.122.92.59]) by smtp.gmail.com with ESMTPSA id x185sm11075992iof.41.2020.08.03.16.58.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 16:58:26 -0700 (PDT) From: Daniel Campello To: LKML , LKML Cc: Jonathan Cameron , Daniel Campello , Andy Shevchenko , Stephen Boyd , Douglas Anderson , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org Subject: [PATCH v5 07/15] iio: sx9310: Use long instead of int for channel bitmaps Date: Mon, 3 Aug 2020 17:58:07 -0600 Message-Id: <20200803175559.v5.7.Iecaa50e469918a385b3e5dab375e442540ea2ad4@changeid> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog In-Reply-To: <20200803235815.778997-1-campello@chromium.org> References: <20200803235815.778997-1-campello@chromium.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Uses for_each_set_bit() macro to loop over channel bitmaps. Signed-off-by: Daniel Campello Reviewed-by: Andy Shevchenko Reviewed-by: Stephen Boyd --- Changes in v5: None Changes in v4: None Changes in v3: - Added static assert for number of channels. Changes in v2: - Changed prox_stat to chan_prox_stat bitmap. drivers/iio/proximity/sx9310.c | 39 ++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index 127b1ba79e2dea..f78500b8a5841e 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -119,6 +119,7 @@ /* 4 hardware channels, as defined in STAT0: COMB, CS2, CS1 and CS0. */ #define SX9310_NUM_CHANNELS 4 +static_assert(SX9310_NUM_CHANNELS < BITS_PER_LONG); struct sx9310_data { /* Serialize access to registers and channel configuration */ @@ -130,7 +131,7 @@ struct sx9310_data { * Last reading of the proximity status for each channel. * We only send an event to user space when this changes. */ - bool prox_stat[SX9310_NUM_CHANNELS]; + unsigned long chan_prox_stat; bool trigger_enabled; /* Ensure correct alignment of timestamp when present. */ struct { @@ -140,7 +141,8 @@ struct sx9310_data { /* Remember enabled channels and sample rate during suspend. */ unsigned int suspend_ctrl0; struct completion completion; - unsigned int chan_read, chan_event; + unsigned long chan_read; + unsigned long chan_event; int channel_users[SX9310_NUM_CHANNELS]; unsigned int whoami; }; @@ -283,15 +285,16 @@ static const struct regmap_config sx9310_regmap_config = { }; static int sx9310_update_chan_en(struct sx9310_data *data, - unsigned int chan_read, - unsigned int chan_event) + unsigned long chan_read, + unsigned long chan_event) { int ret; + unsigned long channels = chan_read | chan_event; - if ((data->chan_read | data->chan_event) != (chan_read | chan_event)) { + if ((data->chan_read | data->chan_event) != channels) { ret = regmap_update_bits(data->regmap, SX9310_REG_PROX_CTRL0, SX9310_REG_PROX_CTRL0_SENSOREN_MASK, - chan_read | chan_event); + channels); if (ret) return ret; } @@ -532,6 +535,7 @@ static void sx9310_push_events(struct iio_dev *indio_dev) unsigned int val, chan; struct sx9310_data *data = iio_priv(indio_dev); s64 timestamp = iio_get_time_ns(indio_dev); + unsigned long prox_changed; /* Read proximity state on all channels */ ret = regmap_read(data->regmap, SX9310_REG_STAT0, &val); @@ -540,24 +544,23 @@ static void sx9310_push_events(struct iio_dev *indio_dev) return; } - for (chan = 0; chan < SX9310_NUM_CHANNELS; chan++) { + /* + * Only iterate over channels with changes on proximity status that have + * events enabled. + */ + prox_changed = (data->chan_prox_stat ^ val) & data->chan_event; + + for_each_set_bit(chan, &prox_changed, SX9310_NUM_CHANNELS) { int dir; u64 ev; - bool new_prox = val & BIT(chan); - - if (!(data->chan_event & BIT(chan))) - continue; - if (new_prox == data->prox_stat[chan]) - /* No change on this channel. */ - continue; - dir = new_prox ? IIO_EV_DIR_FALLING : IIO_EV_DIR_RISING; + dir = val & BIT(chan) ? IIO_EV_DIR_FALLING : IIO_EV_DIR_RISING; ev = IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, chan, IIO_EV_TYPE_THRESH, dir); iio_push_event(indio_dev, ev, timestamp); - data->prox_stat[chan] = new_prox; } + data->chan_prox_stat = val; } static irqreturn_t sx9310_irq_thread_handler(int irq, void *private) @@ -714,13 +717,13 @@ static irqreturn_t sx9310_trigger_handler(int irq, void *private) static int sx9310_buffer_preenable(struct iio_dev *indio_dev) { struct sx9310_data *data = iio_priv(indio_dev); - unsigned int channels = 0; + unsigned long channels = 0; int bit, ret; mutex_lock(&data->mutex); for_each_set_bit(bit, indio_dev->active_scan_mask, indio_dev->masklength) - channels |= BIT(indio_dev->channels[bit].channel); + __set_bit(indio_dev->channels[bit].channel, &channels); ret = sx9310_update_chan_en(data, channels, data->chan_event); mutex_unlock(&data->mutex); From patchwork Mon Aug 3 23:58:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Campello X-Patchwork-Id: 11699285 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D256413B1 for ; Mon, 3 Aug 2020 23:59:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 09F0520786 for ; Mon, 3 Aug 2020 23:59:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="E7jVBRms" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729490AbgHCX7E (ORCPT ); Mon, 3 Aug 2020 19:59:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728928AbgHCX62 (ORCPT ); Mon, 3 Aug 2020 19:58:28 -0400 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0347EC06179E for ; Mon, 3 Aug 2020 16:58:28 -0700 (PDT) Received: by mail-io1-xd41.google.com with SMTP id a5so25140560ioa.13 for ; Mon, 03 Aug 2020 16:58:27 -0700 (PDT) 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=yik+aMIToEohV7wg7qvgTDzaja0eSR46JIGUiWz8tJI=; b=E7jVBRmsXsePU/j4COJ/CgUnuw/aUYFsKgjExjc4hD2pfJstPSKiaVgJ7X1URgMJyF xK1XM2aQC8CxxvBwJcRrRPT6jli+Sf6k1SsBeSxkpNHRGUwwhA6clyfLxNLzuT2VqCAF A3HnMdocMmQLStbcTkVzL9CgOMh1aXKK0cOPM= 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=yik+aMIToEohV7wg7qvgTDzaja0eSR46JIGUiWz8tJI=; b=AcRhhKiMdlV3IJvzR74ki+Rg0EN27ZZ7GaId7j4t/cXcw89ayYYXd1uuPnCzdrzMA5 mkVxJcvlDKPlclV3pOq17NDIkJfd4y/vQqvXmfQhwsvDfpMI3CUCXSiAA096hQ7bPTZJ +FQdRPcgkyRmgyDJH4Imna0uSPoLTrXHDlI2Zr/avA74J7zU8h6WFsR/IfQAAsN7U3yZ MpIWxFlYXUbsu3aPnBNJSDahehrPlnIiXe7kbJnnpePv7z3YkbwIbtgKzlDD3nF8ffiS 8CfPaYwEfaf14CGktwhd7vdcs6N5UmISoxr4wPix8GFipENEN01ignAfk0VlyZyf7kL1 T2vQ== X-Gm-Message-State: AOAM531wYOGY/dA/s4jaEoAsynerY+ZlyWbKe7aOxQoIsWuob0TNRQQp L6THdrin5F3xuFzQ5Bo6vJ7z4w== X-Google-Smtp-Source: ABdhPJx95HrouxJZl3V49xPt809qEmM/nrFASnWcwbUgmIIAxqSgr8eUcYm1t5PfpcCDeoLZv3grCw== X-Received: by 2002:a5e:dd4c:: with SMTP id u12mr2259195iop.93.1596499107453; Mon, 03 Aug 2020 16:58:27 -0700 (PDT) Received: from derch.Home (97-122-92-59.hlrn.qwest.net. [97.122.92.59]) by smtp.gmail.com with ESMTPSA id x185sm11075992iof.41.2020.08.03.16.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 16:58:27 -0700 (PDT) From: Daniel Campello To: LKML , LKML Cc: Jonathan Cameron , Daniel Campello , Andy Shevchenko , Stephen Boyd , Douglas Anderson , Gwendal Grignou , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org Subject: [PATCH v5 08/15] iio: sx9310: Use regmap_read_poll_timeout() for compensation Date: Mon, 3 Aug 2020 17:58:08 -0600 Message-Id: <20200803175559.v5.8.Ia205f0b0363bf663db7704026b5b7036b9748c56@changeid> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog In-Reply-To: <20200803235815.778997-1-campello@chromium.org> References: <20200803235815.778997-1-campello@chromium.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Simplify compensation stage by using regmap_read_poll_timeout(). Signed-off-by: Daniel Campello Reviewed-by: Andy Shevchenko Reviewed-by: Stephen Boyd --- Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: - Fixed dev_err() message drivers/iio/proximity/sx9310.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index f78500b8a5841e..cd7de40a55c2f6 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -799,7 +799,7 @@ static const struct sx9310_reg_default sx9310_default_regs[] = { static int sx9310_init_compensation(struct iio_dev *indio_dev) { struct sx9310_data *data = iio_priv(indio_dev); - int i, ret; + int ret; unsigned int val; unsigned int ctrl0; @@ -813,22 +813,17 @@ static int sx9310_init_compensation(struct iio_dev *indio_dev) if (ret < 0) return ret; - for (i = 100; i >= 0; i--) { - msleep(20); - ret = regmap_read(data->regmap, SX9310_REG_STAT1, &val); - if (ret < 0) - goto out; - if (!(val & SX9310_REG_STAT1_COMPSTAT_MASK)) - break; - } - - if (i < 0) { - dev_err(&data->client->dev, - "initial compensation timed out: 0x%02x", val); - ret = -ETIMEDOUT; + ret = regmap_read_poll_timeout(data->regmap, SX9310_REG_STAT1, val, + !(val & SX9310_REG_STAT1_COMPSTAT_MASK), + 20000, 2000000); + if (ret) { + if (ret == -ETIMEDOUT) + dev_err(&data->client->dev, + "initial compensation timed out: 0x%02x\n", + val); + return ret; } -out: regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, ctrl0); return ret; } From patchwork Mon Aug 3 23:58:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Campello X-Patchwork-Id: 11699277 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 029F014E3 for ; Mon, 3 Aug 2020 23:58:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2D0A820786 for ; Mon, 3 Aug 2020 23:58:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="AQG8WLSU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729331AbgHCX6d (ORCPT ); Mon, 3 Aug 2020 19:58:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729288AbgHCX63 (ORCPT ); Mon, 3 Aug 2020 19:58:29 -0400 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E88D1C0617A1 for ; Mon, 3 Aug 2020 16:58:28 -0700 (PDT) Received: by mail-il1-x141.google.com with SMTP id t18so32709025ilh.2 for ; Mon, 03 Aug 2020 16:58:28 -0700 (PDT) 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=2ELKF9ec+bgCGrmRBpVhFRB+v1oAdFtZBSJFoNpDtSg=; b=AQG8WLSUE7F0Y7lHcTLK/jOh4FqEm2TpRLngA4PjYTe8CiScStdPZmyzqkkuB4C21D HNLzSX4DSNToz51VKQfIA8n8wiZspry+1anoK/+DchHTMt6gEz1K8g5KZRq1E8jwd3vw Oaoc8w+FlMUl0QsHgB3FxzhPDsJJ4v72xaF3w= 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=2ELKF9ec+bgCGrmRBpVhFRB+v1oAdFtZBSJFoNpDtSg=; b=in9i45losQ7dOH0ymGyoRG1s3BJRixALbQ3yAANm/LUXeMBSQ1Up4CU+G8TCGLOEQv kIlMyoa9xt2dghvEz7fdqdmkDn2yUftO8wKs/0tS4DzwY/JoSTuKoqr4JeG2184KzG7f nWu4ILYV2NXd+IO5ORu7JqEkjyth8QJ7YoIXBvWieD44/P31zztHBdJ11h6QVrSuhXeF XtblvYpZX2EI7V1AHTcC0c15dkfJfeUHzJl9iOapk5x2KKeAXj0MntP16pCDUUZHykVG bCYfwIkQVsJGM41L/fbv/4v+W4BFcfYZcbCpxV+g00VM38jlEQFsBdIE0p5ArUZHOuJA 7y3w== X-Gm-Message-State: AOAM533pfdNjtWW/aRrC9s9Udw1eKrrbj8ocNEUQDxzgc3oiE9Yg1WON 3y+7cHMTVwGBAicWhEfhkv5Ngg== X-Google-Smtp-Source: ABdhPJzM3ewapIc/I387YNT8yLabRY71+pPRS2PREUOW3neIQ0APB+WeM5kZQzDQS9hcR8lhmPjT+A== X-Received: by 2002:a92:c811:: with SMTP id v17mr2116473iln.46.1596499108395; Mon, 03 Aug 2020 16:58:28 -0700 (PDT) Received: from derch.Home (97-122-92-59.hlrn.qwest.net. [97.122.92.59]) by smtp.gmail.com with ESMTPSA id x185sm11075992iof.41.2020.08.03.16.58.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 16:58:28 -0700 (PDT) From: Daniel Campello To: LKML , LKML Cc: Jonathan Cameron , Daniel Campello , Andy Shevchenko , Douglas Anderson , Gwendal Grignou , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Stephen Boyd , linux-iio@vger.kernel.org Subject: [PATCH v5 09/15] iio: sx9310: Update copyright Date: Mon, 3 Aug 2020 17:58:09 -0600 Message-Id: <20200803175559.v5.9.If88afce92bbc1e97a532874cca35e642a9566172@changeid> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog In-Reply-To: <20200803235815.778997-1-campello@chromium.org> References: <20200803235815.778997-1-campello@chromium.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Fixes wrong copyright year. Signed-off-by: Daniel Campello --- Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None drivers/iio/proximity/sx9310.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index cd7de40a55c2f6..87b2de0d7b55a3 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -1,13 +1,13 @@ // SPDX-License-Identifier: GPL-2.0 /* - * Copyright 2018 Google LLC. + * Copyright 2020 Google LLC. * * Driver for Semtech's SX9310/SX9311 capacitive proximity/button solution. * Based on SX9500 driver and Semtech driver using the input framework * . - * Reworked April 2019 by Evan Green - * and January 2020 by Daniel Campello + * Reworked in April 2019 by Evan Green + * and in January 2020 by Daniel Campello . */ #include From patchwork Mon Aug 3 23:58:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Campello X-Patchwork-Id: 11699283 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 065C316B1 for ; Mon, 3 Aug 2020 23:58:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2BCDD22CBB for ; Mon, 3 Aug 2020 23:58:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="TQRhsXhY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729313AbgHCX65 (ORCPT ); Mon, 3 Aug 2020 19:58:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729317AbgHCX6b (ORCPT ); Mon, 3 Aug 2020 19:58:31 -0400 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05DD2C0617A3 for ; Mon, 3 Aug 2020 16:58:30 -0700 (PDT) Received: by mail-il1-x142.google.com with SMTP id t18so32709049ilh.2 for ; Mon, 03 Aug 2020 16:58:29 -0700 (PDT) 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=OJszXsIKyYU0Uv7vZpHtfIjl+uNEiIAtSeERsmAU/hw=; b=TQRhsXhY4PVSvvJrMKnsUTwjSX6hVQRoUZ0VJuAJiDcM+qVfEuaSjQCDzvtwgYPhao A+WQF0I2E4iWUY4jzDX4Ld1zrYCn/oMHFXxOt4NlxjkWvFixSqgnrxdJxoVg4Ybq8SGN Y0Fz0D7caOq0W4OTJcMywQLLmYpTRaI9JKbu0= 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=OJszXsIKyYU0Uv7vZpHtfIjl+uNEiIAtSeERsmAU/hw=; b=DeQl7LxKQRzh6i/eLyASnjDmLp9pwfn2RQXNqZQIK6s/sq2xdQWNV1Jd8KtGSbmHuw cJQA0F08AhJYqTbFPb2jxej2yxhQISoVmDGRgkvhLn8Ke61s8UMnx1v9c7LaPtxL6zZZ nVQSCR8I1zhEaJpvEtX7Iz3ij8ZCbwChbW7YjV9nr2VS6UnQWdASe28nmWRzAmEQm770 RMNcyQjz9Uh2Hs6lHpfiQev8OrUgvAeSQ8q12LdRLzOrEKHXhkXXrgvfqTGD+sg+kwVA TruiEZUUrcRmnh6ANYz4ZJ41gkLo16Fqgl9mcZI3mz2zKKXuQF/eCUrsaEepW4JsfMZ1 OLQw== X-Gm-Message-State: AOAM531ZfJniSZP+F7/lxCgYq3SsMnW3OOiWCwDvMtnAin8goZNZ9H01 lRYJyV564JDpMKnlrZ9Pjs5pZw== X-Google-Smtp-Source: ABdhPJzhkMxtx+2V0/8hCJSJxi7ZdMVAiVUfkGHTruG1icoU3xo6IIEf8zcPO+pFUqGXgMsW2id+HA== X-Received: by 2002:a05:6e02:cac:: with SMTP id 12mr2023360ilg.175.1596499109328; Mon, 03 Aug 2020 16:58:29 -0700 (PDT) Received: from derch.Home (97-122-92-59.hlrn.qwest.net. [97.122.92.59]) by smtp.gmail.com with ESMTPSA id x185sm11075992iof.41.2020.08.03.16.58.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 16:58:28 -0700 (PDT) From: Daniel Campello To: LKML , LKML Cc: Jonathan Cameron , Daniel Campello , Andy Shevchenko , Stephen Boyd , Douglas Anderson , Gwendal Grignou , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org Subject: [PATCH v5 10/15] iio: sx9310: Simplify error return handling Date: Mon, 3 Aug 2020 17:58:10 -0600 Message-Id: <20200803175559.v5.10.I071b118136317d3ff77fc598079f21e4ed0e347f@changeid> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog In-Reply-To: <20200803235815.778997-1-campello@chromium.org> References: <20200803235815.778997-1-campello@chromium.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Checks for non-zero return values to signal error conditions. Signed-off-by: Daniel Campello Reviewed-by: Andy Shevchenko Reviewed-by: Stephen Boyd --- Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None drivers/iio/proximity/sx9310.c | 56 +++++++++++++++++----------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index 87b2de0d7b55a3..adb707e2d79612 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -347,7 +347,7 @@ static int sx9310_read_prox_data(struct sx9310_data *data, int ret; ret = regmap_write(data->regmap, SX9310_REG_SENSOR_SEL, chan->channel); - if (ret < 0) + if (ret) return ret; return regmap_bulk_read(data->regmap, chan->address, val, sizeof(*val)); @@ -363,7 +363,7 @@ static int sx9310_wait_for_sample(struct sx9310_data *data) unsigned int val; ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, &val); - if (ret < 0) + if (ret) return ret; val = FIELD_GET(SX9310_REG_PROX_CTRL0_SCANPERIOD_MASK, val); @@ -376,17 +376,17 @@ static int sx9310_wait_for_sample(struct sx9310_data *data) static int sx9310_read_proximity(struct sx9310_data *data, const struct iio_chan_spec *chan, int *val) { - int ret = 0; + int ret; __be16 rawval; mutex_lock(&data->mutex); ret = sx9310_get_read_channel(data, chan->channel); - if (ret < 0) + if (ret) goto out; ret = sx9310_enable_irq(data, SX9310_CONVDONE_IRQ); - if (ret < 0) + if (ret) goto out_put_channel; mutex_unlock(&data->mutex); @@ -400,22 +400,22 @@ static int sx9310_read_proximity(struct sx9310_data *data, mutex_lock(&data->mutex); - if (ret < 0) + if (ret) goto out_disable_irq; ret = sx9310_read_prox_data(data, chan, &rawval); - if (ret < 0) + if (ret) goto out_disable_irq; *val = sign_extend32(be16_to_cpu(rawval), (chan->address == SX9310_REG_DIFF_MSB ? 11 : 15)); ret = sx9310_disable_irq(data, SX9310_CONVDONE_IRQ); - if (ret < 0) + if (ret) goto out_put_channel; ret = sx9310_put_read_channel(data, chan->channel); - if (ret < 0) + if (ret) goto out; mutex_unlock(&data->mutex); @@ -437,7 +437,7 @@ static int sx9310_read_samp_freq(struct sx9310_data *data, int *val, int *val2) unsigned int regval; int ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, ®val); - if (ret < 0) + if (ret) return ret; regval = FIELD_GET(SX9310_REG_PROX_CTRL0_SCANPERIOD_MASK, regval); @@ -539,7 +539,7 @@ static void sx9310_push_events(struct iio_dev *indio_dev) /* Read proximity state on all channels */ ret = regmap_read(data->regmap, SX9310_REG_STAT0, &val); - if (ret < 0) { + if (ret) { dev_err(&data->client->dev, "i2c transfer error in irq\n"); return; } @@ -573,7 +573,7 @@ static irqreturn_t sx9310_irq_thread_handler(int irq, void *private) mutex_lock(&data->mutex); ret = regmap_read(data->regmap, SX9310_REG_IRQ_SRC, &val); - if (ret < 0) { + if (ret) { dev_err(&data->client->dev, "i2c transfer error in irq\n"); goto out; } @@ -616,20 +616,20 @@ static int sx9310_write_event_config(struct iio_dev *indio_dev, mutex_lock(&data->mutex); if (state) { ret = sx9310_get_event_channel(data, chan->channel); - if (ret < 0) + if (ret) goto out_unlock; if (!(data->chan_event & ~BIT(chan->channel))) { ret = sx9310_enable_irq(data, eventirq); - if (ret < 0) + if (ret) sx9310_put_event_channel(data, chan->channel); } } else { ret = sx9310_put_event_channel(data, chan->channel); - if (ret < 0) + if (ret) goto out_unlock; if (!data->chan_event) { ret = sx9310_disable_irq(data, eventirq); - if (ret < 0) + if (ret) sx9310_get_event_channel(data, chan->channel); } } @@ -668,7 +668,7 @@ static int sx9310_set_trigger_state(struct iio_trigger *trig, bool state) ret = sx9310_enable_irq(data, SX9310_CONVDONE_IRQ); else if (!data->chan_read) ret = sx9310_disable_irq(data, SX9310_CONVDONE_IRQ); - if (ret < 0) + if (ret) goto out; data->trigger_enabled = state; @@ -697,7 +697,7 @@ static irqreturn_t sx9310_trigger_handler(int irq, void *private) indio_dev->masklength) { ret = sx9310_read_prox_data(data, &indio_dev->channels[bit], &val); - if (ret < 0) + if (ret) goto out; data->buffer.channels[i++] = val; @@ -804,13 +804,13 @@ static int sx9310_init_compensation(struct iio_dev *indio_dev) unsigned int ctrl0; ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, &ctrl0); - if (ret < 0) + if (ret) return ret; /* run the compensation phase on all channels */ ret = regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, ctrl0 | SX9310_REG_PROX_CTRL0_SENSOREN_MASK); - if (ret < 0) + if (ret) return ret; ret = regmap_read_poll_timeout(data->regmap, SX9310_REG_STAT1, val, @@ -836,21 +836,21 @@ static int sx9310_init_device(struct iio_dev *indio_dev) unsigned int i, val; ret = regmap_write(data->regmap, SX9310_REG_RESET, SX9310_SOFT_RESET); - if (ret < 0) + if (ret) return ret; usleep_range(1000, 2000); /* power-up time is ~1ms. */ /* Clear reset interrupt state by reading SX9310_REG_IRQ_SRC. */ ret = regmap_read(data->regmap, SX9310_REG_IRQ_SRC, &val); - if (ret < 0) + if (ret) return ret; /* Program some sane defaults. */ for (i = 0; i < ARRAY_SIZE(sx9310_default_regs); i++) { initval = &sx9310_default_regs[i]; ret = regmap_write(data->regmap, initval->reg, initval->def); - if (ret < 0) + if (ret) return ret; } @@ -904,14 +904,14 @@ static int sx9310_probe(struct i2c_client *client) return PTR_ERR(data->regmap); ret = regmap_read(data->regmap, SX9310_REG_WHOAMI, &data->whoami); - if (ret < 0) { + if (ret) { dev_err(&client->dev, "error in reading WHOAMI register: %d", ret); return ret; } ret = sx9310_set_indio_dev_name(&client->dev, indio_dev, data->whoami); - if (ret < 0) + if (ret) return ret; ACPI_COMPANION_SET(&indio_dev->dev, ACPI_COMPANION(&client->dev)); @@ -923,7 +923,7 @@ static int sx9310_probe(struct i2c_client *client) i2c_set_clientdata(client, indio_dev); ret = sx9310_init_device(indio_dev); - if (ret < 0) + if (ret) return ret; if (client->irq) { @@ -932,7 +932,7 @@ static int sx9310_probe(struct i2c_client *client) sx9310_irq_thread_handler, IRQF_TRIGGER_LOW | IRQF_ONESHOT, "sx9310_event", indio_dev); - if (ret < 0) + if (ret) return ret; data->trig = @@ -954,7 +954,7 @@ static int sx9310_probe(struct i2c_client *client) iio_pollfunc_store_time, sx9310_trigger_handler, &sx9310_buffer_setup_ops); - if (ret < 0) + if (ret) return ret; return devm_iio_device_register(&client->dev, indio_dev); From patchwork Mon Aug 3 23:58:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Campello X-Patchwork-Id: 11699279 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1FA1316B1 for ; Mon, 3 Aug 2020 23:58:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B5102245C for ; Mon, 3 Aug 2020 23:58:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="WWduK9sQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729339AbgHCX6d (ORCPT ); Mon, 3 Aug 2020 19:58:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729240AbgHCX6b (ORCPT ); Mon, 3 Aug 2020 19:58:31 -0400 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2CF4C06179E for ; Mon, 3 Aug 2020 16:58:30 -0700 (PDT) Received: by mail-io1-xd44.google.com with SMTP id g19so28337429ioh.8 for ; Mon, 03 Aug 2020 16:58:30 -0700 (PDT) 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=nmtj0sseyg7k7nwiC3ScnQV6X/DUHeFjJUChBIXHSNQ=; b=WWduK9sQnxNNP3bdn7u4Rfx2zvEH8bs68k055k1JiwDuHJokBB5Vq3VDi2BfcpKV/T HsgYhfTh/25Ny9wHWDLkwd8Vi6DWvHFTomF69HcnZ8GtM9kz4taQLh9igdElZJ2ehfsr wSbFFqw/U/W1nDKmDmovKOyvwcsGBebOWHB3A= 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=nmtj0sseyg7k7nwiC3ScnQV6X/DUHeFjJUChBIXHSNQ=; b=r3jOmeDeF5sJ1AyeRAaU7KR8GSxhHzKHizglBGSOo/3RS5RZn/FQaNCUc0Kq12gQi6 +T05RmhHe1BktGNaMsFtkaatW0UILq5vC6uqGKfenG3r/qwJ1HXdvg61eKkapTAHTnTd jYFnipoiaita8eEWPtw0uanLKVh9/t0FqUYN4mvsKYlmvI0+XwEs2pxXTRCfhzXrgV9e 8vokSHw8GnFMymhRgty3U4xMGvB9w8KlMek8YAdLLaNew4V9mdqHed6Zefng3vJOwqTS RHHjZkaD+pSmlxCzB8UyfRYlDnJt63xPVBcdOgd9Cn9qvevKPXi7bOUqcu18byjkzFLX Zeug== X-Gm-Message-State: AOAM5323+fQxMX0gV2NSKtWlVaQsoDlD9/JvJL2UedsfR9zuSgyR+rR/ oENaV31opqrDVN7xTW07Ih9wXQ== X-Google-Smtp-Source: ABdhPJzIVeiiDh2BWRjrdbBkI52iMdmd5Dd4GVE1yS1GHTdhX4z94WqIQHI8nnWniLxUUXz/0MexAw== X-Received: by 2002:a6b:8dd2:: with SMTP id p201mr2461834iod.152.1596499110322; Mon, 03 Aug 2020 16:58:30 -0700 (PDT) Received: from derch.Home (97-122-92-59.hlrn.qwest.net. [97.122.92.59]) by smtp.gmail.com with ESMTPSA id x185sm11075992iof.41.2020.08.03.16.58.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 16:58:29 -0700 (PDT) From: Daniel Campello To: LKML , LKML Cc: Jonathan Cameron , Daniel Campello , Andy Shevchenko , Stephen Boyd , Douglas Anderson , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org Subject: [PATCH v5 11/15] iio: sx9310: Use variable to hold &client->dev Date: Mon, 3 Aug 2020 17:58:11 -0600 Message-Id: <20200803175559.v5.11.If9d9c0fe089e43ea2dbc7900b6d61cd05c66f1f7@changeid> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog In-Reply-To: <20200803235815.778997-1-campello@chromium.org> References: <20200803235815.778997-1-campello@chromium.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Improves readability by storing &client->dev in a local variable. Signed-off-by: Daniel Campello Reviewed-by: Andy Shevchenko Reviewed-by: Stephen Boyd --- Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: - Added '\n' to dev_err() drivers/iio/proximity/sx9310.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index adb707e2d79612..589052d2d1146e 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -887,11 +887,12 @@ static int sx9310_set_indio_dev_name(struct device *dev, static int sx9310_probe(struct i2c_client *client) { int ret; + struct device *dev = &client->dev; struct iio_dev *indio_dev; struct sx9310_data *data; - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); - if (indio_dev == NULL) + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); + if (!indio_dev) return -ENOMEM; data = iio_priv(indio_dev); @@ -905,17 +906,16 @@ static int sx9310_probe(struct i2c_client *client) ret = regmap_read(data->regmap, SX9310_REG_WHOAMI, &data->whoami); if (ret) { - dev_err(&client->dev, "error in reading WHOAMI register: %d", - ret); + dev_err(dev, "error in reading WHOAMI register: %d\n", ret); return ret; } - ret = sx9310_set_indio_dev_name(&client->dev, indio_dev, data->whoami); + ret = sx9310_set_indio_dev_name(dev, indio_dev, data->whoami); if (ret) return ret; - ACPI_COMPANION_SET(&indio_dev->dev, ACPI_COMPANION(&client->dev)); - indio_dev->dev.parent = &client->dev; + ACPI_COMPANION_SET(&indio_dev->dev, ACPI_COMPANION(dev)); + indio_dev->dev.parent = dev; indio_dev->channels = sx9310_channels; indio_dev->num_channels = ARRAY_SIZE(sx9310_channels); indio_dev->info = &sx9310_info; @@ -927,7 +927,7 @@ static int sx9310_probe(struct i2c_client *client) return ret; if (client->irq) { - ret = devm_request_threaded_irq(&client->dev, client->irq, + ret = devm_request_threaded_irq(dev, client->irq, sx9310_irq_handler, sx9310_irq_thread_handler, IRQF_TRIGGER_LOW | IRQF_ONESHOT, @@ -935,29 +935,29 @@ static int sx9310_probe(struct i2c_client *client) if (ret) return ret; - data->trig = - devm_iio_trigger_alloc(&client->dev, "%s-dev%d", - indio_dev->name, indio_dev->id); + data->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", + indio_dev->name, + indio_dev->id); if (!data->trig) return -ENOMEM; - data->trig->dev.parent = &client->dev; + data->trig->dev.parent = dev; data->trig->ops = &sx9310_trigger_ops; iio_trigger_set_drvdata(data->trig, indio_dev); - ret = devm_iio_trigger_register(&client->dev, data->trig); + ret = devm_iio_trigger_register(dev, data->trig); if (ret) return ret; } - ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, iio_pollfunc_store_time, sx9310_trigger_handler, &sx9310_buffer_setup_ops); if (ret) return ret; - return devm_iio_device_register(&client->dev, indio_dev); + return devm_iio_device_register(dev, indio_dev); } static int __maybe_unused sx9310_suspend(struct device *dev) From patchwork Mon Aug 3 23:58:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Campello X-Patchwork-Id: 11699271 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AB55214E3 for ; Mon, 3 Aug 2020 23:58:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB5622177B for ; Mon, 3 Aug 2020 23:58:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="csdSx6CE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729349AbgHCX6e (ORCPT ); Mon, 3 Aug 2020 19:58:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729336AbgHCX6d (ORCPT ); Mon, 3 Aug 2020 19:58:33 -0400 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7159C061757 for ; Mon, 3 Aug 2020 16:58:31 -0700 (PDT) Received: by mail-io1-xd41.google.com with SMTP id l17so40393647iok.7 for ; Mon, 03 Aug 2020 16:58:31 -0700 (PDT) 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=/KMpyivRSb9t1ozYXg3Qu6u4uWee/uI+WmauYjOrM+M=; b=csdSx6CE8v0jsLZjLsT72GkNNE2TlGv82/7hXbamWCuLj30mvLTxBhYCyBd050Qrw8 OMEsIquxVJQR83LuOIGAX3Aav+LbVjcK3Qoqqr34MCDSLcSwLBP6FYU83+1ztsLrvvmw 6s8xM3uCZ+4mh1B4GnNRE2mcgKmo2xTKqxz3A= 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=/KMpyivRSb9t1ozYXg3Qu6u4uWee/uI+WmauYjOrM+M=; b=kTkB6cU/GTfBX/xSFrLsQHvaK6Izp3uRsTS2vTKsiVKBWgH2MYUe8uk0/6pbtDWTAS seSAoKDXwg+N5ygffaLyfHuu2+4slegFufywXPw3OOpgVg06UVtZKST/DA5YZ7OLbcgU yAt9pph/bBJ9wWlRFQCABK1lrzcWSwwEjSSi0GM0uTwQfQVda0tXuwLyImDtqsDEM5nP nua+ul+fPNLBMAc6qfZtAnY90GbeOdggKk0BNAN5OqJDnBTC7sMUyZ+ffZmcI/dbFZJj SxFQd9a88aZyKjgS47nuilAwd122CbfiRVHipjakHIx6hRlG8OsYrkGJKcey65tnf8CC DGIg== X-Gm-Message-State: AOAM530jw0bfOywultCHcUJ4wzz2jLwYH+M8MSOD2QcoDSAXsWkvrmOW /j5+G3zhLg5DBP/Ev3FXYEkdeg== X-Google-Smtp-Source: ABdhPJxSKTzbFqcFwQ4MYaT2vPfGVap+/MWo/KK4zlh1BfMLjJ8ZvKLk7ZF5QVc/PPoFtI9QU9JMZg== X-Received: by 2002:a6b:be81:: with SMTP id o123mr2414732iof.64.1596499111287; Mon, 03 Aug 2020 16:58:31 -0700 (PDT) Received: from derch.Home (97-122-92-59.hlrn.qwest.net. [97.122.92.59]) by smtp.gmail.com with ESMTPSA id x185sm11075992iof.41.2020.08.03.16.58.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 16:58:30 -0700 (PDT) From: Daniel Campello To: LKML , LKML Cc: Jonathan Cameron , Daniel Campello , Andy Shevchenko , Stephen Boyd , Douglas Anderson , Enrico Granata , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org Subject: [PATCH v5 12/15] iio: sx9310: Miscellaneous format fixes Date: Mon, 3 Aug 2020 17:58:12 -0600 Message-Id: <20200803175559.v5.12.I426355a035f0394dfccba5bb2bc6f8db872c4be3@changeid> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog In-Reply-To: <20200803235815.778997-1-campello@chromium.org> References: <20200803235815.778997-1-campello@chromium.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Miscellaneous format fixes throughout the whole file. Signed-off-by: Daniel Campello Reviewed-by: Andy Shevchenko Reviewed-by: Stephen Boyd --- Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None drivers/iio/proximity/sx9310.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index 589052d2d1146e..e92017b51c6def 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -91,28 +91,21 @@ #define SX9310_REG_SAR_CTRL2_SAROFFSET_DEFAULT 0x3c #define SX9310_REG_SENSOR_SEL 0x30 - #define SX9310_REG_USE_MSB 0x31 #define SX9310_REG_USE_LSB 0x32 - #define SX9310_REG_AVG_MSB 0x33 #define SX9310_REG_AVG_LSB 0x34 - #define SX9310_REG_DIFF_MSB 0x35 #define SX9310_REG_DIFF_LSB 0x36 - #define SX9310_REG_OFFSET_MSB 0x37 #define SX9310_REG_OFFSET_LSB 0x38 - #define SX9310_REG_SAR_MSB 0x39 #define SX9310_REG_SAR_LSB 0x3a - #define SX9310_REG_I2C_ADDR 0x40 #define SX9310_REG_PAUSE 0x41 #define SX9310_REG_WHOAMI 0x42 #define SX9310_WHOAMI_VALUE 0x01 #define SX9311_WHOAMI_VALUE 0x02 - #define SX9310_REG_RESET 0x7f #define SX9310_SOFT_RESET 0xde @@ -408,7 +401,7 @@ static int sx9310_read_proximity(struct sx9310_data *data, goto out_disable_irq; *val = sign_extend32(be16_to_cpu(rawval), - (chan->address == SX9310_REG_DIFF_MSB ? 11 : 15)); + chan->address == SX9310_REG_DIFF_MSB ? 11 : 15); ret = sx9310_disable_irq(data, SX9310_CONVDONE_IRQ); if (ret) @@ -435,8 +428,9 @@ static int sx9310_read_proximity(struct sx9310_data *data, static int sx9310_read_samp_freq(struct sx9310_data *data, int *val, int *val2) { unsigned int regval; - int ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, ®val); + int ret; + ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, ®val); if (ret) return ret; @@ -521,10 +515,9 @@ static irqreturn_t sx9310_irq_handler(int irq, void *private) iio_trigger_poll(data->trig); /* - * Even if no event is enabled, we need to wake the thread to - * clear the interrupt state by reading SX9310_REG_IRQ_SRC. It - * is not possible to do that here because regmap_read takes a - * mutex. + * Even if no event is enabled, we need to wake the thread to clear the + * interrupt state by reading SX9310_REG_IRQ_SRC. + * It is not possible to do that here because regmap_read takes a mutex. */ return IRQ_WAKE_THREAD; } @@ -641,7 +634,7 @@ static int sx9310_write_event_config(struct iio_dev *indio_dev, static struct attribute *sx9310_attributes[] = { &iio_dev_attr_sampling_frequency_available.dev_attr.attr, - NULL, + NULL }; static const struct attribute_group sx9310_attribute_group = { @@ -972,7 +965,6 @@ static int __maybe_unused sx9310_suspend(struct device *dev) mutex_lock(&data->mutex); ret = regmap_read(data->regmap, SX9310_REG_PROX_CTRL0, &data->suspend_ctrl0); - if (ret) goto out; @@ -1018,21 +1010,21 @@ static const struct dev_pm_ops sx9310_pm_ops = { static const struct acpi_device_id sx9310_acpi_match[] = { { "STH9310", SX9310_WHOAMI_VALUE }, { "STH9311", SX9311_WHOAMI_VALUE }, - {}, + {} }; MODULE_DEVICE_TABLE(acpi, sx9310_acpi_match); static const struct of_device_id sx9310_of_match[] = { { .compatible = "semtech,sx9310", (void *)SX9310_WHOAMI_VALUE }, { .compatible = "semtech,sx9311", (void *)SX9311_WHOAMI_VALUE }, - {}, + {} }; MODULE_DEVICE_TABLE(of, sx9310_of_match); static const struct i2c_device_id sx9310_id[] = { { "sx9310", SX9310_WHOAMI_VALUE }, { "sx9311", SX9311_WHOAMI_VALUE }, - {}, + {} }; MODULE_DEVICE_TABLE(i2c, sx9310_id); From patchwork Mon Aug 3 23:58:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Campello X-Patchwork-Id: 11699281 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 974FA13B1 for ; Mon, 3 Aug 2020 23:58:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C212420786 for ; Mon, 3 Aug 2020 23:58:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="eSayUOKp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729455AbgHCX65 (ORCPT ); Mon, 3 Aug 2020 19:58:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729326AbgHCX6d (ORCPT ); Mon, 3 Aug 2020 19:58:33 -0400 Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0819C061756 for ; Mon, 3 Aug 2020 16:58:32 -0700 (PDT) Received: by mail-il1-x144.google.com with SMTP id y18so24240752ilp.10 for ; Mon, 03 Aug 2020 16:58:32 -0700 (PDT) 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=x0P/E9wXylBxFlPI7ObeCRrwNQSFwwnsYpwWvOTzQ68=; b=eSayUOKpyEjuoEmY3FnaGAEswN75bWwb5+F7SMrAWkZ4ha1ysyywWEcqob0Jq8u4e/ vp1UiA+/Ag/Xdak6ETpDNXInq4wKTY2b/f0oFFVPFzmOPDb2MRkcwWwRAiVAqAZfrYCG SprKOXNwm4GR0usF7zFS3ihJV85lK/xx2ZQn0= 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=x0P/E9wXylBxFlPI7ObeCRrwNQSFwwnsYpwWvOTzQ68=; b=RbTp6BhPOcX1mh/+cD75Jd8tcoxyliNV10aHQQiEEOs21QRw366Ge4UX+rYkbpBHYy kS2jLz80x2eyqMJMAwSOUjvba4mySBfGYzdtBhlTwJ2mSRrrhswkLOP70exAafNdvDr2 b+F7zXkOMmBiEXKl1/YjcotZmxBMRhX+E5FjM5asj339FQSLowKZYeY6M2qKG+RorukX ShgJ0Oz9uD9opMM2/Yy83IJJsbTlDlGuL3UaG/OK2O5UXgSO/5HLkVv5kYN9hmnUGVoj +0ZjDooqLr8imaz4BuB7NSqd3DkMLBW7p1a9myFtBS5aEq1taHR5pjuWINifZA01Th5B G7yg== X-Gm-Message-State: AOAM530sMfK+pDi8l9JM4Xcnc2/zrW/uhwWrW3XcLRrNYTNJKUFd+AQb 1XSC4yxdxd176oXGRmS3mmWj/g== X-Google-Smtp-Source: ABdhPJwMKIXrHNHaa3lv/hs5sbyt3ZtWIIJHJ0trFy+WjiQjbGJuBfzF8Q21t0XkkrvoJjKSmkEoxA== X-Received: by 2002:a05:6e02:52a:: with SMTP id h10mr2106475ils.259.1596499112322; Mon, 03 Aug 2020 16:58:32 -0700 (PDT) Received: from derch.Home (97-122-92-59.hlrn.qwest.net. [97.122.92.59]) by smtp.gmail.com with ESMTPSA id x185sm11075992iof.41.2020.08.03.16.58.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 16:58:31 -0700 (PDT) From: Daniel Campello To: LKML , LKML Cc: Jonathan Cameron , Stephen Boyd , Douglas Anderson , Daniel Campello , Andy Shevchenko , Enrico Granata , Gwendal Grignou , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org Subject: [PATCH v5 13/15] iio: sx9310: Drop channel_users[] Date: Mon, 3 Aug 2020 17:58:13 -0600 Message-Id: <20200803175559.v5.13.Ia5c5fdbdfff576ab5d034cde46c25cc66a4baf50@changeid> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog In-Reply-To: <20200803235815.778997-1-campello@chromium.org> References: <20200803235815.778997-1-campello@chromium.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Stephen Boyd This struct member isn't used. Drop it. Fixes: 72ad02b15d63 ("iio: Add SEMTECH SX9310/9311 sensor driver") Signed-off-by: Stephen Boyd Reviewed-by: Douglas Anderson Reviewed-by: Daniel Campello Signed-off-by: Daniel Campello Reviewed-by: Andy Shevchenko --- Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None drivers/iio/proximity/sx9310.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index e92017b51c6def..60ca32885b664b 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -136,7 +136,6 @@ struct sx9310_data { struct completion completion; unsigned long chan_read; unsigned long chan_event; - int channel_users[SX9310_NUM_CHANNELS]; unsigned int whoami; }; From patchwork Mon Aug 3 23:58:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Campello X-Patchwork-Id: 11699275 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 545C413B1 for ; Mon, 3 Aug 2020 23:58:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8012620786 for ; Mon, 3 Aug 2020 23:58:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="K/+QzAtd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729438AbgHCX6v (ORCPT ); Mon, 3 Aug 2020 19:58:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729345AbgHCX6e (ORCPT ); Mon, 3 Aug 2020 19:58:34 -0400 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4366C06174A for ; Mon, 3 Aug 2020 16:58:33 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id j8so28041101ioe.9 for ; Mon, 03 Aug 2020 16:58:33 -0700 (PDT) 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=VX3IFGCXLKQ3ciQfWuMzvjEwSKFjyXquwwCufu7gNeM=; b=K/+QzAtdFXjrAaJkDf+RUlpsgWfu+l71HO6iYOAg5+xvX2w0Dtb08xIPIh+49UwkwW XUbSOpD4TjxkBuMRztkm9Wn/PI+6r3TP6pfAA1IPkABBqIiQAJ5jJr1ZLteuFikejCqJ T9GkpAeZ6oNQTB/BuxcH4lPso6jzjYy7H0McI= 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=VX3IFGCXLKQ3ciQfWuMzvjEwSKFjyXquwwCufu7gNeM=; b=iRNeWXzHzv76e38iTTrbX+CSnnR+fgRU3y1khPLTGTDyY0kI1kCg9F7ooUhxywS+hD ZbxfRwh4JHRiHwY2njxXXoMYJslcLrb0dWSG5hC6kStpVAkvkwT9rxlMs0FMSrpPbdm5 i+7NR9nOmnZLyHOAvUEf6KToojNUWREfYKzQcMQPLk7BmfYoRAQpXAEfoQK4wm+O8+Dr clKDDtOAmyW6tM9xzsUDs0XYoZC0+NLdTAKOr2Dw3j4rJ4YOsBMAQ2KlHTe9ccIJ3iXi B3mbYvVmWxGnt62BleKJ7jIZaEL2aFTp137GUdR5UezxAzlz/XzeVnTKLKllt8Ud8YAl yNZg== X-Gm-Message-State: AOAM532RdwuLTFE7T6tQVfVAdN/HUv9S+5x7qaKg4TR/7RoGkP+hcmcl ntlWPD4srEWLnclomJPze0vejw== X-Google-Smtp-Source: ABdhPJz8wtmXY6tSGzp4CBkKD9BsMVRdic3yM1mUhcje+irH6PPP7bvUuLAGlxmIwsP0Mzv0obT+VA== X-Received: by 2002:a05:6602:1495:: with SMTP id a21mr2412821iow.46.1596499113294; Mon, 03 Aug 2020 16:58:33 -0700 (PDT) Received: from derch.Home (97-122-92-59.hlrn.qwest.net. [97.122.92.59]) by smtp.gmail.com with ESMTPSA id x185sm11075992iof.41.2020.08.03.16.58.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 16:58:32 -0700 (PDT) From: Daniel Campello To: LKML , LKML Cc: Jonathan Cameron , Stephen Boyd , Douglas Anderson , Daniel Campello , Andy Shevchenko , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org Subject: [PATCH v5 14/15] iio: sx9310: Enable vdd and svdd regulators at probe Date: Mon, 3 Aug 2020 17:58:14 -0600 Message-Id: <20200803175559.v5.14.Ib7bdc8340021d8515b430498fb6686eedf22c9f2@changeid> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog In-Reply-To: <20200803235815.778997-1-campello@chromium.org> References: <20200803235815.778997-1-campello@chromium.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Stephen Boyd Enable the main power supply (vdd) and digital IO power supply (svdd) during probe so that the i2c communication and device works properly on boards that aggressively power gate these supplies. Signed-off-by: Stephen Boyd Reviewed-by: Douglas Anderson Signed-off-by: Daniel Campello Reviewed-by: Andy Shevchenko --- Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None drivers/iio/proximity/sx9310.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index 60ca32885b664b..a68766708fb304 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -120,6 +121,7 @@ struct sx9310_data { struct i2c_client *client; struct iio_trigger *trig; struct regmap *regmap; + struct regulator_bulk_data supplies[2]; /* * Last reading of the proximity status for each channel. * We only send an event to user space when this changes. @@ -876,6 +878,13 @@ static int sx9310_set_indio_dev_name(struct device *dev, return 0; } +static void sx9310_regulator_disable(void *_data) +{ + struct sx9310_data *data = _data; + + regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies); +} + static int sx9310_probe(struct i2c_client *client) { int ret; @@ -889,6 +898,8 @@ static int sx9310_probe(struct i2c_client *client) data = iio_priv(indio_dev); data->client = client; + data->supplies[0].supply = "vdd"; + data->supplies[1].supply = "svdd"; mutex_init(&data->mutex); init_completion(&data->completion); @@ -896,6 +907,21 @@ static int sx9310_probe(struct i2c_client *client) if (IS_ERR(data->regmap)) return PTR_ERR(data->regmap); + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->supplies), + data->supplies); + if (ret) + return ret; + + ret = regulator_bulk_enable(ARRAY_SIZE(data->supplies), data->supplies); + if (ret) + return ret; + /* Must wait for Tpor time after initial power up */ + usleep_range(1000, 1100); + + ret = devm_add_action_or_reset(dev, sx9310_regulator_disable, data); + if (ret) + return ret; + ret = regmap_read(data->regmap, SX9310_REG_WHOAMI, &data->whoami); if (ret) { dev_err(dev, "error in reading WHOAMI register: %d\n", ret); From patchwork Mon Aug 3 23:58:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Campello X-Patchwork-Id: 11699273 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 45DD913B1 for ; Mon, 3 Aug 2020 23:58:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 70F4E20786 for ; Mon, 3 Aug 2020 23:58:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="AiShUQSX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728891AbgHCX6u (ORCPT ); Mon, 3 Aug 2020 19:58:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728419AbgHCX6f (ORCPT ); Mon, 3 Aug 2020 19:58:35 -0400 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0DAEC06179F for ; Mon, 3 Aug 2020 16:58:34 -0700 (PDT) Received: by mail-io1-xd44.google.com with SMTP id w12so26785825iom.4 for ; Mon, 03 Aug 2020 16:58:34 -0700 (PDT) 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=wsVqyjHcA1iKwUDBxCp9up0hP+cWrDA1sHvlf/BCc1I=; b=AiShUQSXnB6sCwZ0hjrv/cNhWcDpdxOe25FBTj9xmqPNXeVLzAbER2ihz09Fw2BE/h YCyLmXGXXdiSiLOx1Mrvd3H1roH+ItiZNmy7HKicnANGt6drgrndXYPcgDL3giO6mb4K JLMaHIv8CT3pyKRiMubXM+tZUjlW8GFAoAfy8= 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=wsVqyjHcA1iKwUDBxCp9up0hP+cWrDA1sHvlf/BCc1I=; b=fkFO9hi2MZhwU2wgPVvGPfv9u3VxIAi7ORw4Ms/00ea1XPjYuagjhngtaUEx0WBtLn U+8AQFc5dgrfAawly+YR0kRFseLnKDzdW6CJp1/VvGeA7YSyeQrrWOQ2SwVx0tlG5WvA V87Yyt81Wzn53ZTvMQIwInQE9Y+vSi4Hduu7rDA5gLX2KyxjaOrh7ezmYa+NdZgJnVA9 lWkZ0lbg5d2BeLdrrvojEGt7cWiXl6H/epfOk82njTTcm2a5knpvP13714nDR7p7oSYl I2ys3QrHKp0m7a489NxyHKlBc8+7aHkvAq4Kkzy0KHc8TPbPeG6W5uId/NyklPEpfgH2 1vug== X-Gm-Message-State: AOAM5310PXKbeiOfEs1XoVQFm1d6lbyLj/Y+H2aUrp9SQPUpOMjacavx lGQEHx6VtZkkdawIfOebgUfZ3Q== X-Google-Smtp-Source: ABdhPJxDqAh8c8N6NwS66oD3lSYhKYcAZzbzw5XKTWBN5KQaQPgLB22TF0PmY9OHGTOqtWAiSzHV+w== X-Received: by 2002:a05:6602:381:: with SMTP id f1mr2386096iov.193.1596499114281; Mon, 03 Aug 2020 16:58:34 -0700 (PDT) Received: from derch.Home (97-122-92-59.hlrn.qwest.net. [97.122.92.59]) by smtp.gmail.com with ESMTPSA id x185sm11075992iof.41.2020.08.03.16.58.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2020 16:58:33 -0700 (PDT) From: Daniel Campello To: LKML , LKML Cc: Jonathan Cameron , Stephen Boyd , Daniel Campello , Andy Shevchenko , Douglas Anderson , Gwendal Grignou , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org Subject: [PATCH v5 15/15] iio: sx9310: Use irq trigger flags from firmware Date: Mon, 3 Aug 2020 17:58:15 -0600 Message-Id: <20200803175559.v5.15.I4c344a6793007001bbb3c1c08e96d3acf893b36b@changeid> X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog In-Reply-To: <20200803235815.778997-1-campello@chromium.org> References: <20200803235815.778997-1-campello@chromium.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Stephen Boyd We shouldn't need to set default irq trigger flags here as the firmware should have properly indicated the trigger type, i.e. level low, in the DT or ACPI tables. Signed-off-by: Stephen Boyd Signed-off-by: Daniel Campello Reviewed-by: Andy Shevchenko --- Changes in v5: None Changes in v4: None Changes in v3: - Added irq trigger flags commit to the series. Changes in v2: None drivers/iio/proximity/sx9310.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c index a68766708fb304..db97b5339d0eff 100644 --- a/drivers/iio/proximity/sx9310.c +++ b/drivers/iio/proximity/sx9310.c @@ -948,7 +948,7 @@ static int sx9310_probe(struct i2c_client *client) ret = devm_request_threaded_irq(dev, client->irq, sx9310_irq_handler, sx9310_irq_thread_handler, - IRQF_TRIGGER_LOW | IRQF_ONESHOT, + IRQF_ONESHOT, "sx9310_event", indio_dev); if (ret) return ret;