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: 314956 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90051C5517A 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 55A0E2085B 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 S1726549AbgKAM2o (ORCPT ); Sun, 1 Nov 2020 07:28:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726529AbgKAM2n (ORCPT ); Sun, 1 Nov 2020 07:28:43 -0500 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7746C061A49 for ; Sun, 1 Nov 2020 04:28:42 -0800 (PST) Received: by mail-lf1-x142.google.com with SMTP id f9so13806209lfq.2 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=sgstg3z9nvuhQhcwD3mk9fI/zRLVuES9eEr0qWqoHJCoZxEjIowNbAnKvUmzz0kI0C e+ZWfvsbMiJ/MksnLSDFFZYicS641BXAacUpUwMCBB6VsED8Z/J3bdhpTgRE+2aiyKuF /q46P8ZH7Rdz1kz3gYEvvErrvGxzVX/nlP8v5QNHw+PFUWQt4ebno/AfskJLhcR0557E jJgxXGVj1WtWZlyGjUF54HQeqiAv6EFY9grExb//Td4mFFOMtwXBr20XeN7obtZy5t8O X+rNrTGPVQcMtbsAp32heb4VPSwJQjwN63IngpTW9faN41Ln2IXErHyIxmj5khWuO364 d8sw== X-Gm-Message-State: AOAM531tz++RuLCngi88QByweBPCSa4Cjiu/VZtqlwIfVtkClynPgI/w udxB+Hpc+BHcr1rqJTPHZuLMbOT3Dv/OPvw3 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-input@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);