From patchwork Tue Mar 13 01:37:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 10277705 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 1D1F1602BD for ; Tue, 13 Mar 2018 01:37:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1660B286FE for ; Tue, 13 Mar 2018 01:37:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0ACED28786; Tue, 13 Mar 2018 01:37:35 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 9CA67286FE for ; Tue, 13 Mar 2018 01:37:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932222AbeCMBhP (ORCPT ); Mon, 12 Mar 2018 21:37:15 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:46839 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751758AbeCMBhO (ORCPT ); Mon, 12 Mar 2018 21:37:14 -0400 Received: by mail-qt0-f196.google.com with SMTP id m13so21051260qtg.13; Mon, 12 Mar 2018 18:37:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=AHM3HOK50OzrnKyYlyE6I0yYNYxIeH5QUEsBbPNf0Ws=; b=PRHn6FdrjxsJllwyOAdKUDQIXY0m29QFicXzoPJuXdwusHEaFAMf4APiiPzRDMC31/ nlMRQsdw0sSJD/gRhjoZ/DpdBmASrv0iBoHZ/En+k+gvOn+QLitSh1OjCwGGp+lhC2my 1eOfRG6nlgjp3rx00aVbO5xzhhtvlHx+5gcpT/N6S0JGYi3E6Iok3M0sZu3+9r1O+FTZ ArfiWEB0/nEPxfAxQHJ1p3RWrPqJrkhDqF07QOp13OaeV3KxUBWCH4DnHgFO6HA0AQG6 fD8gPuS5x6a8BqbFAW8aV7/GZqa1jv2kF1dqxylLeQQlQ+LDMFUksG5CqtusfMG7IlAC Ki5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=AHM3HOK50OzrnKyYlyE6I0yYNYxIeH5QUEsBbPNf0Ws=; b=IbbfBmfFWkZYRlL3mdObFvl4HD/jhfJmBsfNKaKB6rGNoFNwEebhxTZoxTachkoz5F 4rLDh29OAABrF0xcXQhuQt4JniM5O88nH8kAfmtGEXm1B9nQChxPGQl4civlvyGA66qY CS/EYFq6kXMK05YEZdYYms3ivGapwrbVMg8q6uSYh7/qfIhs8dd8Lrih8Yr+cbPTovca jiHWZZsjm9u1l5/nAPVORgAgJ5cZFCyxRMECehBJV5HP3BSZsknGOvzu6ae/l3VboNFP ELL5RJS77CW3dQLn6kLHBTnNVABfqe8oJkyN2LIBoOUPSbkU97r5GOF7yeue0SNDEDR0 ZruQ== X-Gm-Message-State: AElRT7GNOMcclo1ulop621sUEtKK1b77eaT9Z5+jlkRFbFMOHd9qOrOm asCxY0dV6ovY70Il1ZjxJLE= X-Google-Smtp-Source: AG47ELv2hWzxRAplvjnM8JU5Zr8GfzBbP/DE4PcJz1k7k/QHwtDNMLnGmQRG/2DinWDVk6JRmNVClg== X-Received: by 10.237.49.105 with SMTP id 96mr15569465qtg.192.1520905033522; Mon, 12 Mar 2018 18:37:13 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id 51sm2452314qtz.51.2018.03.12.18.37.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Mar 2018 18:37:12 -0700 (PDT) Date: Mon, 12 Mar 2018 22:37:09 -0300 From: Rodrigo Siqueira To: Srinivas Pandruvada , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler Cc: daniel.baluta@nxp.com, linux-iio@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] iio:magnetometer: Remove duplications in iio_chan_spec Message-ID: <20180313013709.ca7hxb5q56rbghch@smtp.gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20171215 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 The magn_3d_channels array has multiple declarations of iio_chan_spec. Most of the iio_chan_spec are very similar, changing only by the .type and .channel2 field. This patch reduces the code duplication by adding a macro that can replace the iio_chan_spec repetitions in the magn_3d_channels array. Signed-off-by: Rodrigo Siqueira --- Changes in v2: - Change IIO_MOD_NORTH_MAGN in the last element of iio_chan_info for IIO_MOD_NORTH_TRUE in the last parameter. drivers/iio/magnetometer/hid-sensor-magn-3d.c | 83 ++++++--------------------- 1 file changed, 19 insertions(+), 64 deletions(-) diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c index d55c4885211a..cdbcfc61a180 100644 --- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c +++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c @@ -74,72 +74,27 @@ static const u32 magn_3d_addresses[MAGN_3D_CHANNEL_MAX] = { HID_USAGE_SENSOR_ORIENT_TRUE_NORTH, }; +#define HID_SENSOR_MAGN_3D_AXIS_CHANNEL(channel_type, characteristic) \ + { \ + .type = channel_type, \ + .modified = 1, \ + .channel2 = characteristic, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | \ + BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ + BIT(IIO_CHAN_INFO_HYSTERESIS), \ + } \ + /* Channel definitions */ static const struct iio_chan_spec magn_3d_channels[] = { - { - .type = IIO_MAGN, - .modified = 1, - .channel2 = IIO_MOD_X, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | - BIT(IIO_CHAN_INFO_SCALE) | - BIT(IIO_CHAN_INFO_SAMP_FREQ) | - BIT(IIO_CHAN_INFO_HYSTERESIS), - }, { - .type = IIO_MAGN, - .modified = 1, - .channel2 = IIO_MOD_Y, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | - BIT(IIO_CHAN_INFO_SCALE) | - BIT(IIO_CHAN_INFO_SAMP_FREQ) | - BIT(IIO_CHAN_INFO_HYSTERESIS), - }, { - .type = IIO_MAGN, - .modified = 1, - .channel2 = IIO_MOD_Z, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | - BIT(IIO_CHAN_INFO_SCALE) | - BIT(IIO_CHAN_INFO_SAMP_FREQ) | - BIT(IIO_CHAN_INFO_HYSTERESIS), - }, { - .type = IIO_ROT, - .modified = 1, - .channel2 = IIO_MOD_NORTH_MAGN_TILT_COMP, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | - BIT(IIO_CHAN_INFO_SCALE) | - BIT(IIO_CHAN_INFO_SAMP_FREQ) | - BIT(IIO_CHAN_INFO_HYSTERESIS), - }, { - .type = IIO_ROT, - .modified = 1, - .channel2 = IIO_MOD_NORTH_TRUE_TILT_COMP, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | - BIT(IIO_CHAN_INFO_SCALE) | - BIT(IIO_CHAN_INFO_SAMP_FREQ) | - BIT(IIO_CHAN_INFO_HYSTERESIS), - }, { - .type = IIO_ROT, - .modified = 1, - .channel2 = IIO_MOD_NORTH_MAGN, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | - BIT(IIO_CHAN_INFO_SCALE) | - BIT(IIO_CHAN_INFO_SAMP_FREQ) | - BIT(IIO_CHAN_INFO_HYSTERESIS), - }, { - .type = IIO_ROT, - .modified = 1, - .channel2 = IIO_MOD_NORTH_TRUE, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | - BIT(IIO_CHAN_INFO_SCALE) | - BIT(IIO_CHAN_INFO_SAMP_FREQ) | - BIT(IIO_CHAN_INFO_HYSTERESIS), - } + HID_SENSOR_MAGN_3D_AXIS_CHANNEL(IIO_MAGN, IIO_MOD_X), + HID_SENSOR_MAGN_3D_AXIS_CHANNEL(IIO_MAGN, IIO_MOD_Y), + HID_SENSOR_MAGN_3D_AXIS_CHANNEL(IIO_MAGN, IIO_MOD_Z), + HID_SENSOR_MAGN_3D_AXIS_CHANNEL(IIO_ROT, IIO_MOD_NORTH_MAGN_TILT_COMP), + HID_SENSOR_MAGN_3D_AXIS_CHANNEL(IIO_ROT, IIO_MOD_NORTH_TRUE_TILT_COMP), + HID_SENSOR_MAGN_3D_AXIS_CHANNEL(IIO_ROT, IIO_MOD_NORTH_MAGN), + HID_SENSOR_MAGN_3D_AXIS_CHANNEL(IIO_ROT, IIO_MOD_NORTH_TRUE), }; /* Adjust channel real bits based on report descriptor */