From patchwork Mon Jun 18 15:59:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10472167 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 19D376032A for ; Mon, 18 Jun 2018 15:59:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A9CE289E8 for ; Mon, 18 Jun 2018 15:59:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F35F728A0C; Mon, 18 Jun 2018 15:59:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98121289E8 for ; Mon, 18 Jun 2018 15:59:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755286AbeFRP72 (ORCPT ); Mon, 18 Jun 2018 11:59:28 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:42085 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755025AbeFRP71 (ORCPT ); Mon, 18 Jun 2018 11:59:27 -0400 Received: by mail-pg0-f68.google.com with SMTP id c10-v6so7732865pgu.9 for ; Mon, 18 Jun 2018 08:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FHfK6FeiPoMyOudkrJFBM68t0ZeolxRVGLAjhSKwBHM=; b=KAu9EJHSvOx2rWvnrdA3R0hclFYh+aiZuEHxPYQd9HNoXva4cFENkWAP76zGvch9RA oGG8eKSVygks3f2TEnYaxc/W+GQ9h7O7VE2t3CvXAFrDX2Ra7/BtcJbW8dVfXEjiLn7q Y8uzFKbIuEnfPs+fROO6Q4YN2Vv59G1uxPzrR9qb+GVZ+0BY4XzKux3HOF00d7gN0SkJ r4IX3qUPGPgnM8LxxvIT/ITBdwcmLZNXAV7F+M/uopI3O4OVh0zUtRhIwvMf4ajfn4Mn qRB1y1R7gylNOdhSCGgYavKyNLrPwLpUuGPON4kDjCoeGssSWBzRvTSRAPAvSHZq5vg3 bvfA== 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; bh=FHfK6FeiPoMyOudkrJFBM68t0ZeolxRVGLAjhSKwBHM=; b=REZ89d5c9/VXIRG8dyXzwjKJdXadtCrGbfgwmPvaIO7l9AxJw8BA5UO3p2r1lJC0PD CZNLenEu8b7mXGGY3xQvxDoenlmszQbVDxffk3lfXMOXoNXZuHfHIpjMxvsO4b7rMpse BBw/ZiWm9sJrFmRnPdZyh5lsSJWmulgVzQNrmww+/rqKXRUbdYs2hNIYb36sbBwCEWY9 de2pFCVy88SC0PN61hT4BpBoZUs4Yl8B2lmKS0FhefyQxvQNkLg0lxtkLPzNvRZ+ZhTQ 3a/PXgIRrL6R3jwWpjzmtQ5xaLuz+jfyYa30e3nv6fqlCPYaOfEdm5WXL0kziBqoawYc Nf6w== X-Gm-Message-State: APt69E352is0xK8U+iUvNaIdkG23iCy/RRBbWSX+w3WZw0fupS3p+Qhk cvi1h2M3P6pwMp1sCuPmAUZllg== X-Google-Smtp-Source: ADUXVKJ5+CNvCpU14il1Kkv+W0CXGQAtmhFUM1Nl8Dk8dF3CRpouRGrZsn1lXq3laGgdS9n2FZvf4A== X-Received: by 2002:a65:4784:: with SMTP id e4-v6mr11362986pgs.58.1529337567009; Mon, 18 Jun 2018 08:59:27 -0700 (PDT) Received: from localhost.localdomain ([240f:34:212d:1:e9ea:30c2:7286:e591]) by smtp.gmail.com with ESMTPSA id a27-v6sm26395643pfc.18.2018.06.18.08.59.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Jun 2018 08:59:26 -0700 (PDT) From: Akinobu Mita To: linux-iio@vger.kernel.org Cc: Akinobu Mita , Eva Rachel Retuya , Andy Shevchenko , Jonathan Cameron Subject: [PATCH v2 2/4] iio: accel: adxl345: use scan_index for accessing accel registers Date: Tue, 19 Jun 2018 00:59:10 +0900 Message-Id: <1529337552-23726-3-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529337552-23726-1-git-send-email-akinobu.mita@gmail.com> References: <1529337552-23726-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently the address field in iio_chan_spec is filled with an accel data register address for the corresponding axis. In preparation for adding calibration offset support, this makes use of scan_index field to access accel data registers instead of using address field. This change makes it easier to access both accel registers and calibration offset registers with fewer lines of code as these are located in X-axis, Y-axis, Z-axis order. Cc: Eva Rachel Retuya Cc: Andy Shevchenko Cc: Jonathan Cameron Signed-off-by: Akinobu Mita --- * v2 - No changes from v1 drivers/iio/accel/adxl345_core.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c index 8e0d56b..6b62f82 100644 --- a/drivers/iio/accel/adxl345_core.c +++ b/drivers/iio/accel/adxl345_core.c @@ -49,19 +49,19 @@ struct adxl345_data { u8 data_range; }; -#define ADXL345_CHANNEL(reg, axis) { \ +#define ADXL345_CHANNEL(si, axis) { \ .type = IIO_ACCEL, \ .modified = 1, \ .channel2 = IIO_MOD_##axis, \ - .address = reg, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .scan_index = si, \ } static const struct iio_chan_spec adxl345_channels[] = { - ADXL345_CHANNEL(ADXL345_REG_DATAX0, X), - ADXL345_CHANNEL(ADXL345_REG_DATAY0, Y), - ADXL345_CHANNEL(ADXL345_REG_DATAZ0, Z), + ADXL345_CHANNEL(0, X), + ADXL345_CHANNEL(1, Y), + ADXL345_CHANNEL(2, Z), }; static int adxl345_read_raw(struct iio_dev *indio_dev, @@ -79,8 +79,9 @@ static int adxl345_read_raw(struct iio_dev *indio_dev, * ADXL345_REG_DATA(X0/Y0/Z0) contain the least significant byte * and ADXL345_REG_DATA(X0/Y0/Z0) + 1 the most significant byte */ - ret = regmap_bulk_read(data->regmap, chan->address, ®val, - sizeof(regval)); + ret = regmap_bulk_read(data->regmap, ADXL345_REG_DATAX0 + + sizeof(regval) * chan->scan_index, + ®val, sizeof(regval)); if (ret < 0) return ret;