From patchwork Thu Nov 12 21:54:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11901743 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 9A0391391 for ; Thu, 12 Nov 2020 21:55:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 733B5216FD for ; Thu, 12 Nov 2020 21:55:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="i90VJSA7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727294AbgKLVzT (ORCPT ); Thu, 12 Nov 2020 16:55:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727249AbgKLVzS (ORCPT ); Thu, 12 Nov 2020 16:55:18 -0500 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA78DC0613D4 for ; Thu, 12 Nov 2020 13:55:05 -0800 (PST) Received: by mail-lj1-x241.google.com with SMTP id i17so7003717ljd.3 for ; Thu, 12 Nov 2020 13:55:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=v/3CmVlipZFwgHhvcxuym7DjFXqNo5n9hsm6eQ+Z+yk=; b=i90VJSA79DqoRY0MYFhcvaAWxVXUBRbT4HSO1+XQM8Uk4+XrLGFgq7kaHiH9QUZd06 RKPW9IUmMOs+HaLVdlWx3LnfZKF4t61Nx6KuNu6Y09vyq8uYjHqgm/1atqO0e+5yT/v5 gS4jrqWD9DL+YDSNryxq+B/7C8BLawgUYVlWUxWAO7BpmYIg9w+3lO7AklGAr3wEc/mF b8a5TcjW6rCJGkLzeujPb/BWUllAdnCv6Xqaa2wK8FM3ZlxwHjJGoytvepePliy+XKRS 2MkLDeYJoAAfVJxAlXyFgFuYkAL07s9+ca7ZrXfo+OVk6KhhOlX4EQcVXshzJNWvoV7n B91g== 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:mime-version :content-transfer-encoding; bh=v/3CmVlipZFwgHhvcxuym7DjFXqNo5n9hsm6eQ+Z+yk=; b=buANfgIL9Tg0t1nuqlm3MSpOx43lvXID3EVYvl3vdUeGxkaDIK/btbPpsY9Tux6Rye gf0rq7SE7qbkjw5HJPUVBmWZhdVdGCpjK75KRDsXIQUuV0IV+1KSeYlUGOs0yGMiSZYr 2/MatpOJ4O6mb8r/kPo32K9V7jXgyhHdL2IhqR41arxllkIHU++2zWhbHGRCKwaHUQ5X xQOPjUZa9I8M/P4bNvScSInqwdt8fdMeXAtC8GZrtLTIRl3uemgTH3bIHJ2PB0zRa/lA Ec/3ddS+hwTfHpynQan1xykmVcvidUo88TxI6/0T+hVLOV0p3UyWW/8JwAylVV9atOOv nVTw== X-Gm-Message-State: AOAM530iW5l20ol6uATvbntp1HOkJM7I1ATDC5qZQHGVh2xyTN7rWi7E 6MxBaHS8ON5etQQbqA8v5zFM4g== X-Google-Smtp-Source: ABdhPJzzgpyzv2K/kYruF1QaR9zrulX98gMjoiTd9fiEkJPvmDbWFb8CTGYGZioT85nzerjVnl9iCw== X-Received: by 2002:a2e:3a08:: with SMTP id h8mr751990lja.263.1605218104173; Thu, 12 Nov 2020 13:55:04 -0800 (PST) Received: from localhost.bredbandsbolaget (c-92d7225c.014-348-6c756e10.bbcust.telenor.se. [92.34.215.146]) by smtp.gmail.com with ESMTPSA id x24sm967731ljj.112.2020.11.12.13.55.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 13:55:03 -0800 (PST) From: Linus Walleij To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Linus Walleij , devicetree@vger.kernel.org Subject: [PATCH 1/3 v2] iio: accel: bmc150-accel: Add DT bindings Date: Thu, 12 Nov 2020 22:54:49 +0100 Message-Id: <20201112215451.2606136-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org These accelerometers have bindings used in the kernel and several device trees but no proper bindings documentation. Add it. Also add a compatible for the BMA222 that I am right now adding support for in the driver. Cc: devicetree@vger.kernel.org Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rename to simply bosch,bma255.yaml after one of the common accelerometers. - Specify that the SPI uses a 4-wire interface. - Specify maximum SPI clock frequency to 10MHz. (Checked all the datasheets.) --- .../bindings/iio/accel/bosch,bma255.yaml | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml diff --git a/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml b/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml new file mode 100644 index 000000000000..5f48bdcf382c --- /dev/null +++ b/Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml @@ -0,0 +1,73 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/accel/bosch,bma255.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Bosch BMA255 and Similar Accelerometers + +maintainers: + - Linus Walleij + +description: + 3 axis accelerometers with varying range and I2C or SPI + 4-wire interface. + +properties: + compatible: + enum: + - bosch,bmc150 + - bosch,bmi055 + - bosch,bma255 + - bosch,bma250e + - bosch,bma222 + - bosch,bma222e + - bosch,bma280 + + reg: + maxItems: 1 + + vdd-supply: true + vddio-supply: true + + interrupts: + maxItems: 1 + + mount-matrix: + description: an optional 3x3 mounting rotation matrix. + + spi-max-frequency: + maximum: 10000000 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #include + #address-cells = <1>; + #size-cells = <0>; + accelerometer@8 { + compatible = "bosch,bma222"; + reg = <0x08>; + vddio-supply = <&vddio>; + vdd-supply = <&vdd>; + interrupts = <57 IRQ_TYPE_EDGE_FALLING>; + }; + }; + - | + # include + spi { + #address-cells = <1>; + #size-cells = <0>; + accel@0 { + compatible = "bosch,bma222"; + reg = <0>; + spi-max-frequency = <10000000>; + }; + }; +... From patchwork Thu Nov 12 21:54:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11901741 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 23588697 for ; Thu, 12 Nov 2020 21:55:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF58B22227 for ; Thu, 12 Nov 2020 21:55:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="JAZydcCJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727043AbgKLVzS (ORCPT ); Thu, 12 Nov 2020 16:55:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727249AbgKLVzS (ORCPT ); Thu, 12 Nov 2020 16:55:18 -0500 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E10D2C0613D6 for ; Thu, 12 Nov 2020 13:55:07 -0800 (PST) Received: by mail-lj1-x229.google.com with SMTP id v20so8065917ljk.8 for ; Thu, 12 Nov 2020 13:55:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AQ9kJjq8vdt06kdZLoqUGJ+vyt/6DNWO/fQqsAmMfO0=; b=JAZydcCJvlZGMujua67M50Pgnp5DsswCJJ+AllU7c/K+Z/fQT6Qv3X4q5+VFxdXJWB ZQSrJlB0KPaMQNVI8UdRuDeWEqeE0thmmv07+eESgZveON92Sd/crxDBlvkeCVI1xfv8 hQQLlue+sIVo638FKqlblgcadSJEH1sHshJuGR64nBPgUg2niEo1EcMniYNfT5bhD1LP XGg3tfYk9rwUtkKulUlcJMZbWEh+rKcJc1Fl7UzuxLc5KL7MkX6cKYt9zlaLMy4KNzee poNNDS7PnrXNlj5A8WmEvkRmOhud+BcVm9spRrMVCeuPggtbBXtMcm07GWK0Y+u58Zcs OhBQ== 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=AQ9kJjq8vdt06kdZLoqUGJ+vyt/6DNWO/fQqsAmMfO0=; b=KeUmm0BwwZA2L5upCIGhi6SqDD2IxLWJX6ygvdbwIcLlcbdP9ZbqVrLmGdObzif9dB IPD60ThoDG0h+hSc1LAdK6CZmCUfyK+9JeNhnANSQtw8vfvvkYqDKIo/iAqejcWEJdJN ojJidKT8gIMBRjFbhAKY2uA2nh8gE//E44byceEtdkG9fK0piBZg96U0ZE3oYRUI/NTd NWUetEj4aojEIQT2ymrc0VcfOTg33TNTNpg2VGFZNaE1bpbx8uboUH8869IJHbXjbIcv 5kRVMJdTY9DWx0g+GhW9HYWUC5kZbkmpL2iuPLex14FrC6H+nRcxEVLeZwUjrzQUleSZ JKug== X-Gm-Message-State: AOAM532C37PeV+U7PbMd+dV09E1Zn67ebf/y9WxHJy9bOakro7++UsVi E6MawBBVhEXq2CJjP52KK6vuCg== X-Google-Smtp-Source: ABdhPJx1atOw9utTuEhIU/mwb4fSfLJDhoqXygLmUEIgujWOhqWsuWTMWg3te1FYsu3D1AQUYbmxxQ== X-Received: by 2002:a05:651c:1074:: with SMTP id y20mr707965ljm.432.1605218105786; Thu, 12 Nov 2020 13:55:05 -0800 (PST) Received: from localhost.bredbandsbolaget (c-92d7225c.014-348-6c756e10.bbcust.telenor.se. [92.34.215.146]) by smtp.gmail.com with ESMTPSA id x24sm967731ljj.112.2020.11.12.13.55.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 13:55:05 -0800 (PST) From: Linus Walleij To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Linus Walleij Subject: [PATCH 2/3 v2] iio: accel: bmc150-accel: Add support for BMA222 Date: Thu, 12 Nov 2020 22:54:50 +0100 Message-Id: <20201112215451.2606136-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201112215451.2606136-1-linus.walleij@linaro.org> References: <20201112215451.2606136-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This adds support for the BMA222 version of this sensor, found in for example the Samsung GT-I9070 mobile phone. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - None, resend with the other patches. --- drivers/iio/accel/bmc150-accel-core.c | 17 +++++++++++++++++ drivers/iio/accel/bmc150-accel-i2c.c | 4 ++++ drivers/iio/accel/bmc150-accel-spi.c | 2 ++ drivers/iio/accel/bmc150-accel.h | 1 + 4 files changed, 24 insertions(+) diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c index 48435865fdaf..0dafe4052856 100644 --- a/drivers/iio/accel/bmc150-accel-core.c +++ b/drivers/iio/accel/bmc150-accel-core.c @@ -5,6 +5,7 @@ * - BMI055 * - BMA255 * - BMA250E + * - BMA222 * - BMA222E * - BMA280 * @@ -1013,6 +1014,8 @@ static const struct iio_event_spec bmc150_accel_event = { IIO_CHAN_SOFT_TIMESTAMP(3), \ } +static const struct iio_chan_spec bma222_accel_channels[] = + BMC150_ACCEL_CHANNELS(8); static const struct iio_chan_spec bma222e_accel_channels[] = BMC150_ACCEL_CHANNELS(8); static const struct iio_chan_spec bma250e_accel_channels[] = @@ -1063,6 +1066,20 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = { {153277, BMC150_ACCEL_DEF_RANGE_8G}, {306457, BMC150_ACCEL_DEF_RANGE_16G} }, }, + [bma222] = { + .name = "BMA222", + .chip_id = 0x03, + .channels = bma222_accel_channels, + .num_channels = ARRAY_SIZE(bma222_accel_channels), + /* + * The datasheet page 17 says: + * 15.6, 31.3, 62.5 and 125 mg per LSB. + */ + .scale_table = { {156000, BMC150_ACCEL_DEF_RANGE_2G}, + {313000, BMC150_ACCEL_DEF_RANGE_4G}, + {625000, BMC150_ACCEL_DEF_RANGE_8G}, + {1250000, BMC150_ACCEL_DEF_RANGE_16G} }, + }, [bma222e] = { .name = "BMA222E", .chip_id = 0xF8, diff --git a/drivers/iio/accel/bmc150-accel-i2c.c b/drivers/iio/accel/bmc150-accel-i2c.c index 06021c8685a7..bba92dd33179 100644 --- a/drivers/iio/accel/bmc150-accel-i2c.c +++ b/drivers/iio/accel/bmc150-accel-i2c.c @@ -5,6 +5,7 @@ * - BMI055 * - BMA255 * - BMA250E + * - BMA222 * - BMA222E * - BMA280 * @@ -54,6 +55,7 @@ static const struct acpi_device_id bmc150_accel_acpi_match[] = { {"BMI055A", bmi055}, {"BMA0255", bma255}, {"BMA250E", bma250e}, + {"BMA222", bma222}, {"BMA222E", bma222e}, {"BMA0280", bma280}, {"BOSC0200"}, @@ -66,6 +68,7 @@ static const struct i2c_device_id bmc150_accel_id[] = { {"bmi055_accel", bmi055}, {"bma255", bma255}, {"bma250e", bma250e}, + {"bma222", bma222}, {"bma222e", bma222e}, {"bma280", bma280}, {} @@ -78,6 +81,7 @@ static const struct of_device_id bmc150_accel_of_match[] = { { .compatible = "bosch,bmi055_accel" }, { .compatible = "bosch,bma255" }, { .compatible = "bosch,bma250e" }, + { .compatible = "bosch,bma222" }, { .compatible = "bosch,bma222e" }, { .compatible = "bosch,bma280" }, { }, diff --git a/drivers/iio/accel/bmc150-accel-spi.c b/drivers/iio/accel/bmc150-accel-spi.c index 2a8c311d6f5a..74a8aee4f612 100644 --- a/drivers/iio/accel/bmc150-accel-spi.c +++ b/drivers/iio/accel/bmc150-accel-spi.c @@ -39,6 +39,7 @@ static const struct acpi_device_id bmc150_accel_acpi_match[] = { {"BMI055A", bmi055}, {"BMA0255", bma255}, {"BMA250E", bma250e}, + {"BMA222", bma222}, {"BMA222E", bma222e}, {"BMA0280", bma280}, { }, @@ -50,6 +51,7 @@ static const struct spi_device_id bmc150_accel_id[] = { {"bmi055_accel", bmi055}, {"bma255", bma255}, {"bma250e", bma250e}, + {"bma222", bma222}, {"bma222e", bma222e}, {"bma280", bma280}, {} diff --git a/drivers/iio/accel/bmc150-accel.h b/drivers/iio/accel/bmc150-accel.h index ae6118ae11b1..f5427103574d 100644 --- a/drivers/iio/accel/bmc150-accel.h +++ b/drivers/iio/accel/bmc150-accel.h @@ -9,6 +9,7 @@ enum { bmi055, bma255, bma250e, + bma222, bma222e, bma280, }; From patchwork Thu Nov 12 21:54:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11901739 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 CFA1A1391 for ; Thu, 12 Nov 2020 21:55:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F42422227 for ; Thu, 12 Nov 2020 21:55:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="D0CLbcjt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727260AbgKLVzK (ORCPT ); Thu, 12 Nov 2020 16:55:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727043AbgKLVzJ (ORCPT ); Thu, 12 Nov 2020 16:55:09 -0500 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10D67C0617A6 for ; Thu, 12 Nov 2020 13:55:09 -0800 (PST) Received: by mail-lf1-x144.google.com with SMTP id v144so10703706lfa.13 for ; Thu, 12 Nov 2020 13:55:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SwkdEZKAvc8j5iPFuWkoVDjlnDMeZmYFzd85/LfuZ/Y=; b=D0CLbcjtMp/JuSGJRxAPMCSGwYEreqEULjgOjcBAL/4BjHzq1bmgIbcPhqpkuxEDrY Od4gpvBNlj+c9AvMfIxOPOvKVKQcqJRkKwpyG9jlkcRtXbTKh05zfZCXBUn568NHBUeL ONqS9F4oVDlqFzvd2MkFcmXToVoO3f9viX7C3MAe4hb8UL90vTT0PlRtS8Y4Ew3CPmJ5 w5Kz0LGM5PjezHQ5EQ8GgrEZMpFNkzLj4CVLAdAt1v/5VPA1ri9T/dr89AEfaogU1VEH bSxaTnBvW9JYUGpt+09BKnWqzcLDT/m9AsRXfk5Cv8bCf4YORluJIeCQznHHVyAs7JIQ jQBg== 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=SwkdEZKAvc8j5iPFuWkoVDjlnDMeZmYFzd85/LfuZ/Y=; b=V4eepkXueH9/s19EOSurzkRFdV1irN9OXBiu/AHgSfb5LdkWdr9L52/viOsuO26zU6 g1VECsSyVxWdb57PCjwHdjTNGHjBM9bBrkPonJkYsVQHf5j5ID/x1X5XQ5TDMWhbsovE jj4PioJE/WV6m1nnNe8ljRFSTw8kuKNAeLr8ZaGiR5eg8KUNXkGJLa00vvAsmO20uODH pytKeG/Oujlqjg6eTVq8KI6UM+QK6U2RmUDxy6zW93E9y3n1vl4KAPMcs4pIOVPG1jCH 459/hnTVxsjbrTY8Idt5lhCXswINX2wUDCwMUfgEDGkMKtTPnbURv+sz+WZRLafQlQJX v27w== X-Gm-Message-State: AOAM530/vtzJL8LjDV6XefESWrru/On0Jp8C4W+1NCYespjPxhkgKd2/ Ap9sEjK9/yn06dNng+2hK6eHcA== X-Google-Smtp-Source: ABdhPJwEz0Y/AEnYHH3L6uGPbG35kZxxqy75zavlMyltIKE/1G6hO64JMTqe1UEAiQGh1IChPoEfNw== X-Received: by 2002:ac2:4845:: with SMTP id 5mr641515lfy.402.1605218107568; Thu, 12 Nov 2020 13:55:07 -0800 (PST) Received: from localhost.bredbandsbolaget (c-92d7225c.014-348-6c756e10.bbcust.telenor.se. [92.34.215.146]) by smtp.gmail.com with ESMTPSA id x24sm967731ljj.112.2020.11.12.13.55.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 13:55:07 -0800 (PST) From: Linus Walleij To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Linus Walleij Subject: [PATCH 3/3 v2] iio: accel: bmc150-accel: Add rudimentary regulator support Date: Thu, 12 Nov 2020 22:54:51 +0100 Message-Id: <20201112215451.2606136-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201112215451.2606136-1-linus.walleij@linaro.org> References: <20201112215451.2606136-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org These Bosch accelerometers have two supplies, VDD and VDDIO. Add some rudimentary support to obtain and enable these regulators during probe() and disable them during remove() or on the errorpath. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Use dev_err_probe() to simplify the errorpath. --- drivers/iio/accel/bmc150-accel-core.c | 35 +++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c index 0dafe4052856..a9714cfacf4d 100644 --- a/drivers/iio/accel/bmc150-accel-core.c +++ b/drivers/iio/accel/bmc150-accel-core.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "bmc150-accel.h" @@ -184,6 +185,7 @@ enum bmc150_accel_trigger_id { struct bmc150_accel_data { struct regmap *regmap; + struct regulator_bulk_data regulators[2]; int irq; struct bmc150_accel_interrupt interrupts[BMC150_ACCEL_INTERRUPTS]; struct bmc150_accel_trigger triggers[BMC150_ACCEL_TRIGGERS]; @@ -1593,10 +1595,33 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, &data->orientation); if (ret) return ret; + /* + * VDD is the analog and digital domain voltage supply + * VDDIO is the digital I/O voltage supply + */ + data->regulators[0].supply = "vdd"; + data->regulators[1].supply = "vddio"; + ret = devm_regulator_bulk_get(dev, + ARRAY_SIZE(data->regulators), + data->regulators); + if (ret) + return dev_err_probe(dev, ret, "failed to get regulators\n"); + + ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators), + data->regulators); + if (ret) { + dev_err(dev, "failed to enable regulators: %d\n", ret); + return ret; + } + /* + * 2ms or 3ms power-on time according to datasheets, let's better + * be safe than sorry and set this delay to 5ms. + */ + msleep(5); ret = bmc150_accel_chip_init(data); if (ret < 0) - return ret; + goto err_disable_regulators; mutex_init(&data->mutex); @@ -1613,7 +1638,7 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, &bmc150_accel_buffer_ops); if (ret < 0) { dev_err(dev, "Failed: iio triggered buffer setup\n"); - return ret; + goto err_disable_regulators; } if (data->irq > 0) { @@ -1674,6 +1699,9 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq, bmc150_accel_unregister_triggers(data, BMC150_ACCEL_TRIGGERS - 1); err_buffer_cleanup: iio_triggered_buffer_cleanup(indio_dev); +err_disable_regulators: + regulator_bulk_disable(ARRAY_SIZE(data->regulators), + data->regulators); return ret; } @@ -1698,6 +1726,9 @@ int bmc150_accel_core_remove(struct device *dev) bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_DEEP_SUSPEND, 0); mutex_unlock(&data->mutex); + regulator_bulk_disable(ARRAY_SIZE(data->regulators), + data->regulators); + return 0; } EXPORT_SYMBOL_GPL(bmc150_accel_core_remove);