From patchwork Sun Nov 1 12:28:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11871967 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 2F4E96A2 for ; Sun, 1 Nov 2020 12:28:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 137F820882 for ; Sun, 1 Nov 2020 12:28:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="g30qIXbR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726541AbgKAM2n (ORCPT ); Sun, 1 Nov 2020 07:28:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726497AbgKAM2l (ORCPT ); Sun, 1 Nov 2020 07:28:41 -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 4386BC061A47 for ; Sun, 1 Nov 2020 04:28:39 -0800 (PST) Received: by mail-lf1-x144.google.com with SMTP id y184so11828943lfa.12 for ; Sun, 01 Nov 2020 04:28:39 -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=QOXieuuEEbc116u9FS/tLUaOZv79e9gqeLS9/EKUpZ8=; b=g30qIXbRJL5C/nXIrSgCkN0N2zOTkxTPyQtoJgI/5Bs7rNmuiZHb3TRDXdbcU36lLt 9RwLjV102npps2h+YPgU367k/Rn0pSGN7FMiiuHEf4cSBw81k9fLFCqeqxVz8nKCzz3r C+ykdFMM6CxcUhrSaD5g3DpUtdxESdL6I70DFTNScAk0sKExnQnd4Cu+ZqvpD3JW3S6W +NxYG9YqjtGggmB/EXO9wF9XkXyxxdpzz4WD2AEaZ1P51qXQ8iJ2U5b/pLiOBYZRVYkG AYC6uGz228NN8qb85OdO4jqZSgJrQqWMtQIjhZCARRJ/l9Nroc0+qXa60WxuRw97FjEX 7EcQ== 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=QOXieuuEEbc116u9FS/tLUaOZv79e9gqeLS9/EKUpZ8=; b=RuTmBbzbijnYj/YIAz/qxzKVGHvE16rbJyvm2bgzAMhsw1pRjgcQx6I2mB/7Tiv03I Uwdl+96Ez2ppqV8g/rNjWD67hliwBSO9WmXCcMVnmOtoVkZpVUkA8ONDXaoRuLz5G+wr 3REmJrLAdTUD2+Uz5RtvSm2+sxUC1ZF/7J7i+wUnyCAx9Gu0La5obiuXU/sDzpjSBbmK +2/xoSle9euZEInDuL7qzIQibcc4+8XNHDE51OJCrLEOq6AqDYJ317VHe9B4cayZYnjm rlpZhFCiLkeBaexdYfTtUiocHQ2OG6Jw/acJCZB23y1NVjDcw5tok2jdJfNfN2FpdfKn b3dg== X-Gm-Message-State: AOAM531Lb+B3dOAdp1CqXn1KBpNgJ27Y725XrZBHH/ddR1mYSLdqv9lB KTWAmvP2dWmvCo4miaPLSfg1Ew== X-Google-Smtp-Source: ABdhPJzyqdJNEAfRNvG2NWx0qtUEFOzaGXj1bTk+b/YuMCYpAyGYIrwcsmKj5sur8hrKyvNbOzljWg== X-Received: by 2002:ac2:4422:: with SMTP id w2mr3804297lfl.219.1604233717531; Sun, 01 Nov 2020 04:28:37 -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 190sm1480655lfk.238.2020.11.01.04.28.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Nov 2020 04:28:36 -0800 (PST) From: Linus Walleij To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-input@vger.kernel.org, Linus Walleij , devicetree@vger.kernel.org Subject: [PATCH 1/3] iio: accel: bmc150-accel: Add DT bindings Date: Sun, 1 Nov 2020 13:28:31 +0100 Message-Id: <20201101122833.1111424-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 --- .../bindings/iio/accel/bosch,bmc-bmi-bma.yaml | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/accel/bosch,bmc-bmi-bma.yaml diff --git a/Documentation/devicetree/bindings/iio/accel/bosch,bmc-bmi-bma.yaml b/Documentation/devicetree/bindings/iio/accel/bosch,bmc-bmi-bma.yaml new file mode 100644 index 000000000000..11b8b68aaf3e --- /dev/null +++ b/Documentation/devicetree/bindings/iio/accel/bosch,bmc-bmi-bma.yaml @@ -0,0 +1,72 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/accel/bosch,bmc-bmi-bma.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Bosch BMCxxx, BMIxxx and BMAxxx Accelerometers + +maintainers: + - Linus Walleij + +description: + 3 axis accelerometers with varying range and I2C or SPI + 3-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: true + +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 Sun Nov 1 12:28:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11871971 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 C7B89166C for ; Sun, 1 Nov 2020 12:28:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC39020B1F for ; Sun, 1 Nov 2020 12:28:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OUj2TIp/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726490AbgKAM2n (ORCPT ); Sun, 1 Nov 2020 07:28:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726521AbgKAM2m (ORCPT ); Sun, 1 Nov 2020 07:28:42 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9620C061A04 for ; Sun, 1 Nov 2020 04:28:40 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id l28so13752595lfp.10 for ; Sun, 01 Nov 2020 04:28:40 -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=C1h7tD4oiBs+mtjedWhyGqQzrspO0zTn8Dim8Rdes2w=; b=OUj2TIp/ohXcdhyUDwBAYjJoD7jDmxhbZmHC+LCnwQrsu91AmAnoUu8DdQGKswq916 pd4q30RKAWKmHlzkJVX72nt2YWmKgoqDO+ye7efx8vsQjarvgq6tJwniznEgNppiO2gG 1zA22L0ObT9AJcJKCbRXfSGeHRLtfDSD3Mh7IaFjnVSAEBhNToKgIMUKBTyeOPm0lUAq U0zoIdmXsV+eIsCJIOIX554dz43+Hbk4PFH1XNCnhZDVrqNa0gZUbrF9KQJxI1Lp6Nvb hVQykyX97Z6yvcO+k6UNSE8X+f7ld0mNNKqb3b2GveVOjccb6WhgH12geaglyXMwSWll xEbw== 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=C1h7tD4oiBs+mtjedWhyGqQzrspO0zTn8Dim8Rdes2w=; b=n80+hAjagJ8Vmc5gUOnJ3Rd01APPDiUG7Ze84bCfTju32OesZMXUp4QSQ9Fk4xX51D RNH91wnUtWyZ3qEIs6sj/0Kg+8Rw4MafqBklG5xYwCDmYPMgCp/urMNIcE79tgk8FMyu XatJRymsmNaArBZOfWujOPfVXQJoGbMr7vbKoJb59T7I4kjGcksg1D2hNW3Xe3/t1MkD RACEYTOpoPjNbvgBFJkLVHbkFqrwudoJmk8xHF0d+qu/1IunuzSXkZ8Hh9K8Ek6YumLH jcjyNZ0kpQCrrgxKkjwX341eMK3YFhj0j9jhLbD87ML5lsM3BmHiIIef8IiIs8LEuCRN kAeA== X-Gm-Message-State: AOAM531eSGkSPN3ELjV/dwIHci62DJN1c59hLxHr578UMPTnd8zgX4Gq fam4fMNdALHo53VQmbEi+f/55fScw5VwJrPC X-Google-Smtp-Source: ABdhPJzB8baLBtt5YFSzEoZE82l+qR2ZiDf8GynuaiaYbeMO8ypaeQClSONW2KvAevqf76foljON6A== X-Received: by 2002:ac2:4d58:: with SMTP id 24mr3908549lfp.32.1604233719423; Sun, 01 Nov 2020 04:28:39 -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 190sm1480655lfk.238.2020.11.01.04.28.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Nov 2020 04:28:38 -0800 (PST) From: Linus Walleij To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-input@vger.kernel.org, Linus Walleij Subject: [PATCH 2/3] iio: accel: bmc150-accel: Add support for BMA222 Date: Sun, 1 Nov 2020 13:28:32 +0100 Message-Id: <20201101122833.1111424-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201101122833.1111424-1-linus.walleij@linaro.org> References: <20201101122833.1111424-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 --- 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 Sun Nov 1 12:28:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11871975 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 B3C1914B4 for ; Sun, 1 Nov 2020 12:28:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 993F92085B for ; Sun, 1 Nov 2020 12:28:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="kGIyGZKe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726555AbgKAM2p (ORCPT ); Sun, 1 Nov 2020 07:28:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726521AbgKAM2o (ORCPT ); Sun, 1 Nov 2020 07:28:44 -0500 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A492BC061A48 for ; Sun, 1 Nov 2020 04:28:42 -0800 (PST) Received: by mail-lf1-x141.google.com with SMTP id b1so13741960lfp.11 for ; Sun, 01 Nov 2020 04:28:42 -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=D//csSkef/q1fmS2JF6nZIsqRiFshRpn9N22nb8nS5E=; b=kGIyGZKeEweHWzwL+H0LdhP4e14J8KJbxwtqgSIJIUOjduETuvRplH52h5hiVVZZ1q 7pprDNN9o2dzShN7Q+TWr95DB5630naYzfL4JXWNf5jNBo7+hfCxiHGJViTUNdHPyqss +OU0FvSflg/RTZY0khH+ckx2gIh99keG4GYgipQB9wmEgOd/VOBOmyFWh28plZT5i0w8 bI3jrd1YVPjqYExRPvjhvcDYH8tK2UogQd5id5J16E7wjEafGkU+JOPMk4OmkKv4XXC+ wtJdjrWcOI+FLPy8uJ1feTc+9Ps92cvmC9XCMeQ2wpGfwC4wYN2NK3/FdFKAwh4HHTk/ WxwQ== 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=D//csSkef/q1fmS2JF6nZIsqRiFshRpn9N22nb8nS5E=; b=Ob9lJoxoxIbMfVSRk6Mj70EdRjMoXsyaBOzWt0sQ8cdKPKumTTjxjc9c1LUKpYaFtX 5xWlhuWO+fvIR9NryTUS+WGq6QOOItmubhFo8wpHkZIQBmFdjFOLuBVWi/0FA5NAV8/m +crPVIdQ4YRgAWlqZFPy9n62Nrf18os/qt5vOQ9vblq26glwCVxR1hDLj5+OHoiMQYN5 DnoD8jkew3DrXytPAMxAm0oIkQEYaKeV7ceyjRCq2Y2R03wvbNxDuZOTE90krjLnfL4R Ov1p1Q/nya97hARYDOzkR6bB0rCzvVD1ufLp/kPNIdSaX+MkFTPoiNlFSB4ljNWmTgnJ dBIw== X-Gm-Message-State: AOAM531y5WdT5nszNlNAPXjDBNspYLtt8GqBLh7jWZZnP1rHkbZaDX4N oFFpxrkbetmS9dzBndel0K190g== X-Google-Smtp-Source: ABdhPJwhuNTY0jV6fjulkvIZnQ1RW5Oq8uFHGKx1pb6i8VdF0X7g3OKU7Xo4KnxH2y4uEhCAQ8uEkw== X-Received: by 2002:ac2:5c4c:: with SMTP id s12mr3756651lfp.174.1604233721157; Sun, 01 Nov 2020 04:28:41 -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 190sm1480655lfk.238.2020.11.01.04.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Nov 2020 04:28:40 -0800 (PST) From: Linus Walleij To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-input@vger.kernel.org, Linus Walleij Subject: [PATCH 3/3] iio: accel: bmc150-accel: Add rudimentary regulator support Date: Sun, 1 Nov 2020 13:28:33 +0100 Message-Id: <20201101122833.1111424-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201101122833.1111424-1-linus.walleij@linaro.org> References: <20201101122833.1111424-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 --- drivers/iio/accel/bmc150-accel-core.c | 37 +++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c index 0dafe4052856..a69a4f54d69a 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,35 @@ 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) { + if (ret != -EPROBE_DEFER) + dev_err(dev, "Failed to get regulators %d\n", ret); + return ret; + } + 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 +1640,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 +1701,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 +1728,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);