From patchwork Tue Mar 6 12:00:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 10261497 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 E151A6055D for ; Tue, 6 Mar 2018 12:00:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBCFE28FE4 for ; Tue, 6 Mar 2018 12:00:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B830728F4B; Tue, 6 Mar 2018 12:00:22 +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=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 4CD0728FE4 for ; Tue, 6 Mar 2018 12:00:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752936AbeCFMAR (ORCPT ); Tue, 6 Mar 2018 07:00:17 -0500 Received: from mail-vk0-f65.google.com ([209.85.213.65]:45982 "EHLO mail-vk0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750864AbeCFMAQ (ORCPT ); Tue, 6 Mar 2018 07:00:16 -0500 Received: by mail-vk0-f65.google.com with SMTP id k187so12089782vke.12; Tue, 06 Mar 2018 04:00:15 -0800 (PST) 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=YaTAmpqpqEZQy0dyF2qBLbAPDB6Bz6cIIpYO9UoYYo0=; b=nOq+n69Cn8QO3B/tpr1Al0DmAEwAubmcyNta4HSKudwlyN+0x3KyO8yK2ss/YPOVq2 geSh0cxDEjdHPjpsv5HZoRfABNYpkeh8p/UoirLPx3hknDFbnZ9YoDrQDx5ChmHHwQzE RlVBgJuWmT0TpVQNBaKyTBVmsLBxEWTLsLLzLKUVdaL8vV6zV0nkBSPxR+BnmQXg41TW JydziJKnNSwrOlToTAgv+nf4SwuZGmvq5Mu3MAsgU801StYCeyYQAoV1XGEoi+ZbBl1h qK/pwUQFYoqa52qhY0f08OqLq47SyjcQCrK3JZISdxd1ehh2h2iciE3M6glSaW1lu/FR OuxQ== 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=YaTAmpqpqEZQy0dyF2qBLbAPDB6Bz6cIIpYO9UoYYo0=; b=ar2kb6xPa+F6dkl9AnG+SVIkqjVMkJmPYzKA+KWtJauaiAFblYsL5s/3nelthzUsmF Y3+22tGQojBpECenHH91iS4CKV6e4qq/O8MGeJhlGZ9wrHy6u+pfG514tfdXnhfIJ6Oo gqEJ3Heo3Fb2GrijVaiKR1t1dIed7ZAiqnZVrLA5YDYOkpOHXZWvI0elxxo/WFt0BSmP 272gSPFC1SGyS0MAPovPXEgviyn5LqdnBdWoQSRcnwLEnmak6TCj7C/jnI1Fd15tFC4F 1Y/KgTbbVJtwQf271+UnTL1pJl9mA1/DtsbqunoErq0+xbsXVoW3cYYgWOyY4SIJQj5t qnYA== X-Gm-Message-State: APf1xPCSCoPLVVivkNYK/fvoUusR4dF9WDJMnpF4I/q8ElP/a2o3AItU WC/B+CfoTlwQDbLda59/uM4= X-Google-Smtp-Source: AG47ELvgA+K9nsxeJn6xyXpH8CfZoCrEGeoMqwlG0HlUKSOD1Oa3wwFVXIuSRYPKcmWWNr0ZoK/26g== X-Received: by 10.31.172.67 with SMTP id v64mr13398127vke.54.1520337615216; Tue, 06 Mar 2018 04:00:15 -0800 (PST) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id h74sm3645171vka.27.2018.03.06.04.00.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Mar 2018 04:00:14 -0800 (PST) Date: Tue, 6 Mar 2018 09:00:11 -0300 From: Rodrigo Siqueira To: 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] iio:magnetometer: Remove duplications in iio_chan_spec Message-ID: <20180306120011.pbnymd7izt2yxljl@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 --- 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 a1fd9d591818..fff64711a6c8 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_MAGN), }; /* Adjust channel real bits based on report descriptor */