From patchwork Wed Dec 11 21:38:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11286485 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 D9EEA13B6 for ; Wed, 11 Dec 2019 21:38:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B7C3E20409 for ; Wed, 11 Dec 2019 21:38:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="oPSrqKo+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726141AbfLKVi1 (ORCPT ); Wed, 11 Dec 2019 16:38:27 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:34719 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726313AbfLKVi1 (ORCPT ); Wed, 11 Dec 2019 16:38:27 -0500 Received: by mail-lf1-f65.google.com with SMTP id l18so20278lfc.1 for ; Wed, 11 Dec 2019 13:38:25 -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=H+GJDsZn7GdT3QKoU6jRs2z6sFLUbUBmp9X/WhTZ+V4=; b=oPSrqKo+2GSBGR1G17CVAerVDDjTXe/ye/8of8naHxHWP5Qty/ljb7JQ27PYvmcwBo 8fwqPuA/Suk5DsJmk4z8tFuKq9lY11nttXCfN1VUYX5PagHUv8a1x8W3DZocqnuOZ63p iM73ksgLrXAiMJv26w8z/C2F75wtu63eVRNXXOrp2AC2U2HQrqGkiYlY1xXIJUN/70LA JGSa7dfXLHJwTQuiWKlWpFVgzfyRbywSFA3cHK5VOei/X/VoFKTG6MlLM//25EB6ktkt wS92HTOkr3rkYnzd/m6zWg1fqUlliw9ga39x1D1pnj4IxQ2lW3++lawJuLk3JXv6X248 Fhlg== 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=H+GJDsZn7GdT3QKoU6jRs2z6sFLUbUBmp9X/WhTZ+V4=; b=DM1sp9zwWHDXhEn+DIG9BAj8A0ctbgedSIb7zn+7iDCidzKxpMKV3UwBOwxK+VLeZj 3LaNcimEpde97nVZq6FU4PpAX/Dt6FrnSiaZ5zcFFiC3uHs8fZ33ImoLbfQuT6CsP4MQ KDbhHR/JX8dyA0v5G/775P61x/2J/kpgme9d9EZXQz80fRjTp8/FebH65AGe/uPmueEM lv4rZaLsouhbWhwCmsz0WTiVd2L8asgAInMbkmevV9Sxv4K4YVK+ri1KWxIlQYLot/3Q 5jZYFfBdJKSbXkFxybZALHviAoXLVPWwUn5PHZTtVwRP1vJGnjd5GbOa5fosFsm3jBLO MmZQ== X-Gm-Message-State: APjAAAVht/xX29Zbc0rCoRVsoXf2z+DuRYZq5GBXdY53zTI8L7xupj5J ZCoDYi0XX40OSauPMFljyBjgqg== X-Google-Smtp-Source: APXvYqy2AlkFND/4qNpWLvpqxMn1gFEW39r/0U4HO4wgQuS2f5wWr7AaBnzoo64lh9O59owU/C5EjA== X-Received: by 2002:a05:6512:41b:: with SMTP id u27mr3751238lfk.164.1576100305008; Wed, 11 Dec 2019 13:38:25 -0800 (PST) Received: from localhost.bredbandsbolaget (c-21cd225c.014-348-6c756e10.bbcust.telenor.se. [92.34.205.33]) by smtp.gmail.com with ESMTPSA id e8sm2074199ljb.45.2019.12.11.13.38.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 13:38:23 -0800 (PST) From: Linus Walleij To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Linus Walleij , Oleksandr Kravchenko Subject: [PATCH 1/4] iio: accel: bma180: Add dev helper variable Date: Wed, 11 Dec 2019 22:38:16 +0100 Message-Id: <20191211213819.14024-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Having a shorthand "dev" instead of &client->dev everywhere makes the code easier to read (more compact). Cc: Peter Meerwald Cc: Oleksandr Kravchenko Signed-off-by: Linus Walleij --- drivers/iio/accel/bma180.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c index 1574e4604a4f..518efbe4eaf6 100644 --- a/drivers/iio/accel/bma180.c +++ b/drivers/iio/accel/bma180.c @@ -712,12 +712,13 @@ static const struct iio_trigger_ops bma180_trigger_ops = { static int bma180_probe(struct i2c_client *client, const struct i2c_device_id *id) { + struct device *dev = &client->dev; struct bma180_data *data; struct iio_dev *indio_dev; enum chip_ids chip; int ret; - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); if (!indio_dev) return -ENOMEM; @@ -725,12 +726,12 @@ static int bma180_probe(struct i2c_client *client, i2c_set_clientdata(client, indio_dev); data->client = client; if (client->dev.of_node) - chip = (enum chip_ids)of_device_get_match_data(&client->dev); + chip = (enum chip_ids)of_device_get_match_data(dev); else chip = id->driver_data; data->part_info = &bma180_part_info[chip]; - ret = iio_read_mount_matrix(&client->dev, "mount-matrix", + ret = iio_read_mount_matrix(dev, "mount-matrix", &data->orientation); if (ret) return ret; @@ -740,7 +741,7 @@ static int bma180_probe(struct i2c_client *client, goto err_chip_disable; mutex_init(&data->mutex); - indio_dev->dev.parent = &client->dev; + indio_dev->dev.parent = dev; indio_dev->channels = data->part_info->channels; indio_dev->num_channels = data->part_info->num_channels; indio_dev->name = id->name; @@ -755,15 +756,15 @@ static int bma180_probe(struct i2c_client *client, goto err_chip_disable; } - ret = devm_request_irq(&client->dev, client->irq, + ret = devm_request_irq(dev, client->irq, iio_trigger_generic_data_rdy_poll, IRQF_TRIGGER_RISING, "bma180_event", data->trig); if (ret) { - dev_err(&client->dev, "unable to request IRQ\n"); + dev_err(dev, "unable to request IRQ\n"); goto err_trigger_free; } - data->trig->dev.parent = &client->dev; + data->trig->dev.parent = dev; data->trig->ops = &bma180_trigger_ops; iio_trigger_set_drvdata(data->trig, indio_dev); indio_dev->trig = iio_trigger_get(data->trig); @@ -776,13 +777,13 @@ static int bma180_probe(struct i2c_client *client, ret = iio_triggered_buffer_setup(indio_dev, NULL, bma180_trigger_handler, NULL); if (ret < 0) { - dev_err(&client->dev, "unable to setup iio triggered buffer\n"); + dev_err(dev, "unable to setup iio triggered buffer\n"); goto err_trigger_unregister; } ret = iio_device_register(indio_dev); if (ret < 0) { - dev_err(&client->dev, "unable to register iio device\n"); + dev_err(dev, "unable to register iio device\n"); goto err_buffer_cleanup; } From patchwork Wed Dec 11 21:38:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11286487 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 76E08138D for ; Wed, 11 Dec 2019 21:38:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 564E722527 for ; Wed, 11 Dec 2019 21:38:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="wlnXGgeX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726647AbfLKVia (ORCPT ); Wed, 11 Dec 2019 16:38:30 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:42774 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726313AbfLKVia (ORCPT ); Wed, 11 Dec 2019 16:38:30 -0500 Received: by mail-lf1-f68.google.com with SMTP id y19so17830962lfl.9 for ; Wed, 11 Dec 2019 13:38:28 -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=F+zPd04AQaeVHMLYY/Z5Njm+dB8FTeXRC+xGAD4RZWE=; b=wlnXGgeXt8DyEHHlhLeGdWHUf0BBscDXNEtLvaiilr+fwETcGiguKMdcxEDHtcZVgV JJxk+m01npRfmbGDV09sQk0LvCRGAUGNVg5RYBaUPz4GOT8qpqL0o8uDzlPtRoDGPrDY g66NB+pYRcOGL5K79Wyoa6d+jsOUUyOyDDz+12tPrQb6+tsXg28Bx+ZaIetgvVJo9l0Z SMj+zBI9EWgL85VCcF57rRmS6m4OwqZEMIRgflTwEmzHONODL1gIJb1ihXJCtR/oHOkQ kTq17JamK0ZKv8PtXLXKXcS0uuAKNztOeA8qmjga1EwwDY908G6HjganpESbcx4cMxsY 2+cw== 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=F+zPd04AQaeVHMLYY/Z5Njm+dB8FTeXRC+xGAD4RZWE=; b=kJt11qZr7JT9OCzt2gRO7RD4rZtJ9yulci51mJWtYiXhEpuX03eaSGjiwfP+sa8jJq H6IkD9npJIlyPp6TKYnd2UFMlmjd0y34cxVXbMKaU9RPuLFWta+WSvYk7RjkWsgEbNm4 LPW2JogaC+wDP68hT2UD5g/n/fTHvIkJ190/NY4X6pCofK/+c2fsBjO8bQxGKrp0TWRR eB3Lt5/weEl4Ac71LDzYlTPaFT2eT6WIF9Xta7AYlGcDA/SH+8VliZi40650p2DuzcMt zk/Qf9tL+CZi4lAp7QC9S6Ktfyt8OgozTYVbWD4IXis1R0olTvmqd4SpsvcX4BKCs88C D03g== X-Gm-Message-State: APjAAAWvbJerkybFvseNV2TVXCwlUmcWvFzUUKGHSRnsO4rK0T/lU9Mi RsFbDWmmT+Eh6dfB54pbH5ftgA== X-Google-Smtp-Source: APXvYqxNqBnBQrPBYd93vMdee+miAhMoTjd65AYnqUWECkNwKBsPMjm0EXMSXq5tc47KhGkWqX1l1g== X-Received: by 2002:ac2:5337:: with SMTP id f23mr3568694lfh.192.1576100308200; Wed, 11 Dec 2019 13:38:28 -0800 (PST) Received: from localhost.bredbandsbolaget (c-21cd225c.014-348-6c756e10.bbcust.telenor.se. [92.34.205.33]) by smtp.gmail.com with ESMTPSA id e8sm2074199ljb.45.2019.12.11.13.38.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 13:38:27 -0800 (PST) From: Linus Walleij To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Linus Walleij , Oleksandr Kravchenko Subject: [PATCH 2/4] iio: accel: bma180: Basic regulator support Date: Wed, 11 Dec 2019 22:38:17 +0100 Message-Id: <20191211213819.14024-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191211213819.14024-1-linus.walleij@linaro.org> References: <20191211213819.14024-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This brings up the VDD and VDDIO regulators using the regulator framework. Platforms that do not use regulators will provide stubs or dummy regulators. Cc: Peter Meerwald Cc: Oleksandr Kravchenko Signed-off-by: Linus Walleij --- drivers/iio/accel/bma180.c | 43 +++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c index 518efbe4eaf6..4a619b5a544a 100644 --- a/drivers/iio/accel/bma180.c +++ b/drivers/iio/accel/bma180.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -110,6 +111,8 @@ struct bma180_part_info { #define BMA250_INT_RESET_MASK BIT(7) /* Reset pending interrupts */ struct bma180_data { + struct regulator *vdd_supply; + struct regulator *vddio_supply; struct i2c_client *client; struct iio_trigger *trig; const struct bma180_part_info *part_info; @@ -736,6 +739,40 @@ static int bma180_probe(struct i2c_client *client, if (ret) return ret; + data->vdd_supply = devm_regulator_get(dev, "vdd"); + if (IS_ERR(data->vdd_supply)) { + if (PTR_ERR(data->vdd_supply) != -EPROBE_DEFER) + dev_err(dev, "Failed to get vdd regulator %d\n", + (int)PTR_ERR(data->vdd_supply)); + return PTR_ERR(data->vdd_supply); + } + data->vddio_supply = devm_regulator_get(dev, "vddio"); + if (IS_ERR(data->vddio_supply)) { + if (PTR_ERR(data->vddio_supply) != -EPROBE_DEFER) + dev_err(dev, "Failed to get vddio regulator %d\n", + (int)PTR_ERR(data->vddio_supply)); + return PTR_ERR(data->vddio_supply); + } + /* Typical voltage 2.4V these are min and max */ + ret = regulator_set_voltage(data->vdd_supply, 1620000, 3600000); + if (ret) + return ret; + ret = regulator_set_voltage(data->vddio_supply, 1200000, 3600000); + if (ret) + return ret; + ret = regulator_enable(data->vdd_supply); + if (ret) { + dev_err(dev, "Failed to enable vdd regulator: %d\n", ret); + return ret; + } + ret = regulator_enable(data->vddio_supply); + if (ret) { + dev_err(dev, "Failed to enable vddio regulator: %d\n", ret); + goto err_disable_vdd; + } + /* Wait to make sure we started up properly (3 ms at least) */ + usleep_range(3000, 5000); + ret = data->part_info->chip_config(data); if (ret < 0) goto err_chip_disable; @@ -798,7 +835,9 @@ static int bma180_probe(struct i2c_client *client, iio_trigger_free(data->trig); err_chip_disable: data->part_info->chip_disable(data); - + regulator_disable(data->vddio_supply); +err_disable_vdd: + regulator_disable(data->vdd_supply); return ret; } @@ -817,6 +856,8 @@ static int bma180_remove(struct i2c_client *client) mutex_lock(&data->mutex); data->part_info->chip_disable(data); mutex_unlock(&data->mutex); + regulator_disable(data->vddio_supply); + regulator_disable(data->vdd_supply); return 0; } From patchwork Wed Dec 11 21:38:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11286489 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 DAFA013B6 for ; Wed, 11 Dec 2019 21:38:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BA6B8222C4 for ; Wed, 11 Dec 2019 21:38:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="C8EKacdl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726674AbfLKVid (ORCPT ); Wed, 11 Dec 2019 16:38:33 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:35211 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726313AbfLKVid (ORCPT ); Wed, 11 Dec 2019 16:38:33 -0500 Received: by mail-lf1-f66.google.com with SMTP id 15so16181lfr.2 for ; Wed, 11 Dec 2019 13:38:31 -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=PtLeUHFiL+dOJNhxDIzcPZjSfJUnp/C7Q8G/2C52MTY=; b=C8EKacdlQMun5gl0woeKwdUKcpeiCJQ7wlzWPhen+8moSV6lXopcDAwWFiRN9AtZ/v bUkHJqo0Xvh4cy58+doNMFnJSxr4X81fobmdSqBDQD99Fz297/mVUwK/vWaIeyPvCqk7 wp2KBPUnwhFEgglmcr2IHcAwI1CPp2xFD0o73UWWNL4ynbNfnwwf1vN+OuhUn2tVAyLN 15VbgVVno0Yl96RP/ef8bm7U9N7sc0w+K7EQJ1RJMoc/VJGdfOZskrkkm8J/xKEFfCKi m9NjP06YUSTEv3ewUyiSRyUpwilZw9QrUbrg4qV4R4WrgQ6vGJQUrAP18JYLa4WIC18d VMaw== 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=PtLeUHFiL+dOJNhxDIzcPZjSfJUnp/C7Q8G/2C52MTY=; b=Z54wIgHPZOErfK5aMOVBLxQx/Od764oWoxv97diMZWpOXu4qC3mZfWPTsIbUCy1QPn y1fJIA6zgTHig8VCdOQfNocapmPXXRmV3kkws8pJnHkGhAIuYj2CqfzETeZc99Oy1wTQ 1w4ViN5TCgaMYmCS7eL6RbYRUWprFIuPIQqfe6xe3DtlXvnVYHtrnw1L6JlmoZlWPQrb h0XFXaUwNJB0QEhSBxcL8VYchYFiKRqpixfgjSeT7zhdo2By418lZchbAUHy3/VTh7lS jU8W/Gt7GEehVFA1o3cSh0Qgm4y6QdyFekUATz3wLfV+giEuJZV2uuyr6fqCUGGXu/au Y27A== X-Gm-Message-State: APjAAAVLs+P5JMPfhMgFSwW2EmRYkSyQCpIpHDDFzpLoExE6YTFKC3JE 7QrGqJBdozALwmJCOIhXuMMTUA== X-Google-Smtp-Source: APXvYqzaxegeLPBWr+pJHMguc3Ya6LVucqY915A6wj1Nr5hzm0XrtWNyVqgDLObVKohW7UZfbp9uAw== X-Received: by 2002:ac2:5a09:: with SMTP id q9mr3626549lfn.71.1576100310984; Wed, 11 Dec 2019 13:38:30 -0800 (PST) Received: from localhost.bredbandsbolaget (c-21cd225c.014-348-6c756e10.bbcust.telenor.se. [92.34.205.33]) by smtp.gmail.com with ESMTPSA id e8sm2074199ljb.45.2019.12.11.13.38.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 13:38:29 -0800 (PST) From: Linus Walleij To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Linus Walleij , Oleksandr Kravchenko Subject: [PATCH 3/4] iio: accel: bma180: Use explicit member assignment Date: Wed, 11 Dec 2019 22:38:18 +0100 Message-Id: <20191211213819.14024-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191211213819.14024-1-linus.walleij@linaro.org> References: <20191211213819.14024-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This uses the C99 explicit .member assignment for the variant data in struct bma180_part_info. This makes it easier to understand and add new variants. Cc: Peter Meerwald Cc: Oleksandr Kravchenko Signed-off-by: Linus Walleij --- drivers/iio/accel/bma180.c | 68 ++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c index 4a619b5a544a..f583f10ccbb9 100644 --- a/drivers/iio/accel/bma180.c +++ b/drivers/iio/accel/bma180.c @@ -632,32 +632,52 @@ static const struct iio_chan_spec bma250_channels[] = { static const struct bma180_part_info bma180_part_info[] = { [BMA180] = { - bma180_channels, ARRAY_SIZE(bma180_channels), - bma180_scale_table, ARRAY_SIZE(bma180_scale_table), - bma180_bw_table, ARRAY_SIZE(bma180_bw_table), - BMA180_CTRL_REG0, BMA180_RESET_INT, - BMA180_CTRL_REG0, BMA180_SLEEP, - BMA180_BW_TCS, BMA180_BW, - BMA180_OFFSET_LSB1, BMA180_RANGE, - BMA180_TCO_Z, BMA180_MODE_CONFIG, BMA180_LOW_POWER, - BMA180_CTRL_REG3, BMA180_NEW_DATA_INT, - BMA180_RESET, - bma180_chip_config, - bma180_chip_disable, + .channels = bma180_channels, + .num_channels = ARRAY_SIZE(bma180_channels), + .scale_table = bma180_scale_table, + .num_scales = ARRAY_SIZE(bma180_scale_table), + .bw_table = bma180_bw_table, + .num_bw = ARRAY_SIZE(bma180_bw_table), + .int_reset_reg = BMA180_CTRL_REG0, + .int_reset_mask = BMA180_RESET_INT, + .sleep_reg = BMA180_CTRL_REG0, + .sleep_mask = BMA180_SLEEP, + .bw_reg = BMA180_BW_TCS, + .bw_mask = BMA180_BW, + .scale_reg = BMA180_OFFSET_LSB1, + .scale_mask = BMA180_RANGE, + .power_reg = BMA180_TCO_Z, + .power_mask = BMA180_MODE_CONFIG, + .lowpower_val = BMA180_LOW_POWER, + .int_enable_reg = BMA180_CTRL_REG3, + .int_enable_mask = BMA180_NEW_DATA_INT, + .softreset_reg = BMA180_RESET, + .chip_config = bma180_chip_config, + .chip_disable = bma180_chip_disable, }, [BMA250] = { - bma250_channels, ARRAY_SIZE(bma250_channels), - bma250_scale_table, ARRAY_SIZE(bma250_scale_table), - bma250_bw_table, ARRAY_SIZE(bma250_bw_table), - BMA250_INT_RESET_REG, BMA250_INT_RESET_MASK, - BMA250_POWER_REG, BMA250_SUSPEND_MASK, - BMA250_BW_REG, BMA250_BW_MASK, - BMA250_RANGE_REG, BMA250_RANGE_MASK, - BMA250_POWER_REG, BMA250_LOWPOWER_MASK, 1, - BMA250_INT_ENABLE_REG, BMA250_DATA_INTEN_MASK, - BMA250_RESET_REG, - bma250_chip_config, - bma250_chip_disable, + .channels = bma250_channels, + .num_channels = ARRAY_SIZE(bma250_channels), + .scale_table = bma250_scale_table, + .num_scales = ARRAY_SIZE(bma250_scale_table), + .bw_table = bma250_bw_table, + .num_bw = ARRAY_SIZE(bma250_bw_table), + .int_reset_reg = BMA250_INT_RESET_REG, + .int_reset_mask = BMA250_INT_RESET_MASK, + .sleep_reg = BMA250_POWER_REG, + .sleep_mask = BMA250_SUSPEND_MASK, + .bw_reg = BMA250_BW_REG, + .bw_mask = BMA250_BW_MASK, + .scale_reg = BMA250_RANGE_REG, + .scale_mask = BMA250_RANGE_MASK, + .power_reg = BMA250_POWER_REG, + .power_mask = BMA250_LOWPOWER_MASK, + .lowpower_val = 1, + .int_enable_reg = BMA250_INT_ENABLE_REG, + .int_enable_mask = BMA250_DATA_INTEN_MASK, + .softreset_reg = BMA250_RESET_REG, + .chip_config = bma250_chip_config, + .chip_disable = bma250_chip_disable, }, }; From patchwork Wed Dec 11 21:38:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11286491 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 1C96A13B6 for ; Wed, 11 Dec 2019 21:38:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DB8A121556 for ; Wed, 11 Dec 2019 21:38:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="hqTkm8Gh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726313AbfLKVii (ORCPT ); Wed, 11 Dec 2019 16:38:38 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:46956 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726676AbfLKVii (ORCPT ); Wed, 11 Dec 2019 16:38:38 -0500 Received: by mail-lf1-f65.google.com with SMTP id f15so17039537lfl.13 for ; Wed, 11 Dec 2019 13:38:34 -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=R26EY7063ftF6OanXZF13KqC7WSutYgJ/cSOxLnyVS8=; b=hqTkm8GhFYskVJypRDlT94mghkQCelcHWpxduPE1aNlU7fXTvOtzfUlWVns0CYwQ4Y 2BXYXEhmmixSgkNFSnKc9xTafNOQzi9Z82s1zJvBO9Rm2if7x7mp8fAI/XTBN8vkxcuE qNhN0nvq2CcS0+X+il9RMXtdo3FJlhIPjh6326Nk+xOSY+LKoePjUShz7fEgu4j3qlTK CBwmLEZ5kzGJ6UEA3YAkl8LA4TkMiyAEOpBgwVTH+A7+mIUj9bUErbDuWBGA85pamnU2 LME3TWOqJIQVMl+caoEjBRK7y79ZshHqw9tU5OB+vvpuZyKNdGouo0wI1ktV1fXRRMh5 WA9Q== 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=R26EY7063ftF6OanXZF13KqC7WSutYgJ/cSOxLnyVS8=; b=ML6esuyyvYFicabNyYBkgEiAA/GYnVdUP+C+6xl1cUIeRCzTExG0A6JTUegU5MC5lY n4ITeeTD4mP21Y85tqsHkXwu5KATNktyw+5t7gWeXZBrbEkkIGDK/95iDiugpeFdZsWl ICKXdNuUeUC2e0JMcGioH80huds+lI0Cmn11/6C7aZQenQU1UsY/eK7FNZ+g/C9SIViJ 6ewbupThBou48Ck/i2dF2knpm2yqlDt2Wv+hLLSVDgn3KqqttVUzSRC+veRINJr76e2F XDqQl+9fIqeADuLXsv6m9nSHt3aq3It3vGMSc2WK3J82bLK9lxwqhMxijX4te5dxH4Tt 1cHA== X-Gm-Message-State: APjAAAUxX8RzBJXPD5vjdhXXnrY0x8fHBilmbDJtU/LM7QsnCF9ZgQxU g7faGsKSiZBLxUJ60KDANaUzaw== X-Google-Smtp-Source: APXvYqzJ1IAnbjjV+tYZon2wGYd5eWtvVB63gwh4N+DvRlPTGW9569s1+RJ0u8pDny6W+0rqiFe61A== X-Received: by 2002:ac2:5a43:: with SMTP id r3mr3721261lfn.150.1576100314067; Wed, 11 Dec 2019 13:38:34 -0800 (PST) Received: from localhost.bredbandsbolaget (c-21cd225c.014-348-6c756e10.bbcust.telenor.se. [92.34.205.33]) by smtp.gmail.com with ESMTPSA id e8sm2074199ljb.45.2019.12.11.13.38.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 13:38:32 -0800 (PST) From: Linus Walleij To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Linus Walleij , Oleksandr Kravchenko , devicetree@vger.kernel.org Subject: [PATCH 4/4] iio: accel: bma180: BMA254 support Date: Wed, 11 Dec 2019 22:38:19 +0100 Message-Id: <20191211213819.14024-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191211213819.14024-1-linus.walleij@linaro.org> References: <20191211213819.14024-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This adds support for the BMA254 variant of this accelerometer. The only difference for the simple IIO driver is that values are 12 bit and the temperature offset differs by 1 degree. Cc: Peter Meerwald Cc: Oleksandr Kravchenko Cc: devicetree@vger.kernel.org Signed-off-by: Linus Walleij Acked-by: Rob Herring --- .../devicetree/bindings/iio/accel/bma180.txt | 7 +- drivers/iio/accel/Kconfig | 4 +- drivers/iio/accel/bma180.c | 108 +++++++++++++++--- 3 files changed, 100 insertions(+), 19 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/accel/bma180.txt b/Documentation/devicetree/bindings/iio/accel/bma180.txt index 3b25b4c4d446..f53237270b32 100644 --- a/Documentation/devicetree/bindings/iio/accel/bma180.txt +++ b/Documentation/devicetree/bindings/iio/accel/bma180.txt @@ -1,11 +1,14 @@ -* Bosch BMA180 / BMA250 triaxial acceleration sensor +* Bosch BMA180 / BMA25x triaxial acceleration sensor http://omapworld.com/BMA180_111_1002839.pdf http://ae-bst.resource.bosch.com/media/products/dokumente/bma250/bst-bma250-ds002-05.pdf Required properties: - - compatible : should be "bosch,bma180" or "bosch,bma250" + - compatible : should be one of: + "bosch,bma180" + "bosch,bma250" + "bosch,bma254" - reg : the I2C address of the sensor Optional properties: diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index d4ef35aeb579..2f10fd7954fc 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -89,13 +89,13 @@ config ADXL372_I2C module will be called adxl372_i2c. config BMA180 - tristate "Bosch BMA180/BMA250 3-Axis Accelerometer Driver" + tristate "Bosch BMA180/BMA25x 3-Axis Accelerometer Driver" depends on I2C select IIO_BUFFER select IIO_TRIGGERED_BUFFER help Say Y here if you want to build a driver for the Bosch BMA180 or - BMA250 triaxial acceleration sensor. + BMA25x triaxial acceleration sensor. To compile this driver as a module, choose M here: the module will be called bma180. diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c index f583f10ccbb9..952b2918525b 100644 --- a/drivers/iio/accel/bma180.c +++ b/drivers/iio/accel/bma180.c @@ -9,6 +9,7 @@ * SPI is not supported by driver * BMA180: 7-bit I2C slave address 0x40 or 0x41 * BMA250: 7-bit I2C slave address 0x18 or 0x19 + * BMA254: 7-bit I2C slave address 0x18 or 0x19 */ #include @@ -34,17 +35,20 @@ enum chip_ids { BMA180, BMA250, + BMA254, }; struct bma180_data; struct bma180_part_info { + u8 chip_id; const struct iio_chan_spec *channels; unsigned int num_channels; const int *scale_table; unsigned int num_scales; const int *bw_table; unsigned int num_bw; + int center_temp; u8 int_reset_reg, int_reset_mask; u8 sleep_reg, sleep_mask; @@ -52,6 +56,7 @@ struct bma180_part_info { u8 scale_reg, scale_mask; u8 power_reg, power_mask, lowpower_val; u8 int_enable_reg, int_enable_mask; + u8 int_map_reg, int_enable_dataready_int1_mask; u8 softreset_reg; int (*chip_config)(struct bma180_data *data); @@ -90,6 +95,8 @@ struct bma180_part_info { #define BMA180_RESET_VAL 0xb6 #define BMA180_ID_REG_VAL 0x03 +#define BMA250_ID_REG_VAL 0x03 +#define BMA254_ID_REG_VAL 0xfa /* 250 decimal */ /* Chip power modes */ #define BMA180_LOW_POWER 0x03 @@ -110,6 +117,23 @@ struct bma180_part_info { #define BMA250_INT1_DATA_MASK BIT(0) #define BMA250_INT_RESET_MASK BIT(7) /* Reset pending interrupts */ +#define BMA254_RANGE_REG 0x0f +#define BMA254_BW_REG 0x10 +#define BMA254_POWER_REG 0x11 +#define BMA254_RESET_REG 0x14 +#define BMA254_INT_ENABLE_REG 0x17 +#define BMA254_INT_MAP_REG 0x1a +#define BMA254_INT_RESET_REG 0x21 + +#define BMA254_RANGE_MASK GENMASK(3, 0) /* Range of accel values */ +#define BMA254_BW_MASK GENMASK(4, 0) /* Accel bandwidth */ +#define BMA254_SUSPEND_MASK BIT(7) /* chip will sleep */ +#define BMA254_LOWPOWER_MASK BIT(6) +#define BMA254_DATA_INTEN_MASK BIT(4) +#define BMA254_INT2_DATA_MASK BIT(7) +#define BMA254_INT1_DATA_MASK BIT(0) +#define BMA254_INT_RESET_MASK BIT(7) /* Reset pending interrupts */ + struct bma180_data { struct regulator *vdd_supply; struct regulator *vddio_supply; @@ -135,8 +159,8 @@ enum bma180_chan { static int bma180_bw_table[] = { 10, 20, 40, 75, 150, 300 }; /* Hz */ static int bma180_scale_table[] = { 1275, 1863, 2452, 3727, 4903, 9709, 19417 }; -static int bma250_bw_table[] = { 8, 16, 31, 63, 125, 250 }; /* Hz */ -static int bma250_scale_table[] = { 0, 0, 0, 38344, 0, 76590, 0, 0, 153180, 0, +static int bma25x_bw_table[] = { 8, 16, 31, 63, 125, 250 }; /* Hz */ +static int bma25x_scale_table[] = { 0, 0, 0, 38344, 0, 76590, 0, 0, 153180, 0, 0, 0, 306458 }; static int bma180_get_data_reg(struct bma180_data *data, enum bma180_chan chan) @@ -310,8 +334,11 @@ static int bma180_chip_init(struct bma180_data *data) if (ret < 0) return ret; - if (ret != BMA180_ID_REG_VAL) + if (ret != data->part_info->chip_id) { + dev_err(&data->client->dev, "wrong chip ID %d expected %d\n", + ret, data->part_info->chip_id); return -ENODEV; + } ret = bma180_soft_reset(data); if (ret) @@ -358,7 +385,7 @@ static int bma180_chip_config(struct bma180_data *data) return ret; } -static int bma250_chip_config(struct bma180_data *data) +static int bma25x_chip_config(struct bma180_data *data) { int ret = bma180_chip_init(data); @@ -370,8 +397,12 @@ static int bma250_chip_config(struct bma180_data *data) ret = bma180_set_scale(data, 38344); /* 2 G */ if (ret) goto err; - ret = bma180_set_bits(data, BMA250_INT_MAP_REG, - BMA250_INT1_DATA_MASK, 1); + /* + * This enables dataready interrupt on the INT1 pin + * FIXME: support using the INT2 pin + */ + ret = bma180_set_bits(data, data->part_info->int_map_reg, + data->part_info->int_enable_dataready_int1_mask, 1); if (ret) goto err; @@ -397,7 +428,7 @@ static void bma180_chip_disable(struct bma180_data *data) dev_err(&data->client->dev, "failed to disable the chip\n"); } -static void bma250_chip_disable(struct bma180_data *data) +static void bma25x_chip_disable(struct bma180_data *data) { if (bma180_set_new_data_intr_state(data, false)) goto err; @@ -500,7 +531,7 @@ static int bma180_read_raw(struct iio_dev *indio_dev, return -EINVAL; } case IIO_CHAN_INFO_OFFSET: - *val = 48; /* 0 LSB @ 24 degree C */ + *val = data->part_info->center_temp; return IIO_VAL_INT; default: return -EINVAL; @@ -630,14 +661,24 @@ static const struct iio_chan_spec bma250_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(4), }; +static const struct iio_chan_spec bma254_channels[] = { + BMA180_ACC_CHANNEL(X, 12), + BMA180_ACC_CHANNEL(Y, 12), + BMA180_ACC_CHANNEL(Z, 12), + BMA180_TEMP_CHANNEL, + IIO_CHAN_SOFT_TIMESTAMP(4), +}; + static const struct bma180_part_info bma180_part_info[] = { [BMA180] = { + .chip_id = BMA180_ID_REG_VAL, .channels = bma180_channels, .num_channels = ARRAY_SIZE(bma180_channels), .scale_table = bma180_scale_table, .num_scales = ARRAY_SIZE(bma180_scale_table), .bw_table = bma180_bw_table, .num_bw = ARRAY_SIZE(bma180_bw_table), + .center_temp = 48, /* 0 LSB @ 24 degree C */ .int_reset_reg = BMA180_CTRL_REG0, .int_reset_mask = BMA180_RESET_INT, .sleep_reg = BMA180_CTRL_REG0, @@ -656,12 +697,14 @@ static const struct bma180_part_info bma180_part_info[] = { .chip_disable = bma180_chip_disable, }, [BMA250] = { + .chip_id = BMA250_ID_REG_VAL, .channels = bma250_channels, .num_channels = ARRAY_SIZE(bma250_channels), - .scale_table = bma250_scale_table, - .num_scales = ARRAY_SIZE(bma250_scale_table), - .bw_table = bma250_bw_table, - .num_bw = ARRAY_SIZE(bma250_bw_table), + .scale_table = bma25x_scale_table, + .num_scales = ARRAY_SIZE(bma25x_scale_table), + .bw_table = bma25x_bw_table, + .num_bw = ARRAY_SIZE(bma25x_bw_table), + .center_temp = 48, /* 0 LSB @ 24 degree C */ .int_reset_reg = BMA250_INT_RESET_REG, .int_reset_mask = BMA250_INT_RESET_MASK, .sleep_reg = BMA250_POWER_REG, @@ -675,9 +718,39 @@ static const struct bma180_part_info bma180_part_info[] = { .lowpower_val = 1, .int_enable_reg = BMA250_INT_ENABLE_REG, .int_enable_mask = BMA250_DATA_INTEN_MASK, + .int_map_reg = BMA250_INT_MAP_REG, + .int_enable_dataready_int1_mask = BMA250_INT1_DATA_MASK, .softreset_reg = BMA250_RESET_REG, - .chip_config = bma250_chip_config, - .chip_disable = bma250_chip_disable, + .chip_config = bma25x_chip_config, + .chip_disable = bma25x_chip_disable, + }, + [BMA254] = { + .chip_id = BMA254_ID_REG_VAL, + .channels = bma254_channels, + .num_channels = ARRAY_SIZE(bma254_channels), + .scale_table = bma25x_scale_table, + .num_scales = ARRAY_SIZE(bma25x_scale_table), + .bw_table = bma25x_bw_table, + .num_bw = ARRAY_SIZE(bma25x_bw_table), + .center_temp = 46, /* 0 LSB @ 23 degree C */ + .int_reset_reg = BMA254_INT_RESET_REG, + .int_reset_mask = BMA254_INT_RESET_MASK, + .sleep_reg = BMA254_POWER_REG, + .sleep_mask = BMA254_SUSPEND_MASK, + .bw_reg = BMA254_BW_REG, + .bw_mask = BMA254_BW_MASK, + .scale_reg = BMA254_RANGE_REG, + .scale_mask = BMA254_RANGE_MASK, + .power_reg = BMA254_POWER_REG, + .power_mask = BMA254_LOWPOWER_MASK, + .lowpower_val = 1, + .int_enable_reg = BMA254_INT_ENABLE_REG, + .int_enable_mask = BMA254_DATA_INTEN_MASK, + .int_map_reg = BMA254_INT_MAP_REG, + .int_enable_dataready_int1_mask = BMA254_INT1_DATA_MASK, + .softreset_reg = BMA254_RESET_REG, + .chip_config = bma25x_chip_config, + .chip_disable = bma25x_chip_disable, }, }; @@ -918,6 +991,7 @@ static SIMPLE_DEV_PM_OPS(bma180_pm_ops, bma180_suspend, bma180_resume); static const struct i2c_device_id bma180_ids[] = { { "bma180", BMA180 }, { "bma250", BMA250 }, + { "bma254", BMA254 }, { } }; @@ -932,6 +1006,10 @@ static const struct of_device_id bma180_of_match[] = { .compatible = "bosch,bma250", .data = (void *)BMA250 }, + { + .compatible = "bosch,bma254", + .data = (void *)BMA254 + }, { } }; MODULE_DEVICE_TABLE(of, bma180_of_match); @@ -951,5 +1029,5 @@ module_i2c_driver(bma180_driver); MODULE_AUTHOR("Kravchenko Oleksandr "); MODULE_AUTHOR("Texas Instruments, Inc."); -MODULE_DESCRIPTION("Bosch BMA180/BMA250 triaxial acceleration sensor"); +MODULE_DESCRIPTION("Bosch BMA180/BMA25x triaxial acceleration sensor"); MODULE_LICENSE("GPL");