From patchwork Sat Nov 25 08:38:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Wunner X-Patchwork-Id: 10074719 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 84BE660375 for ; Sat, 25 Nov 2017 08:43:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D6E52952B for ; Sat, 25 Nov 2017 08:43:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F3DF29B7A; Sat, 25 Nov 2017 08:43:50 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 3EC472952B for ; Sat, 25 Nov 2017 08:43:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751080AbdKYInr (ORCPT ); Sat, 25 Nov 2017 03:43:47 -0500 Received: from mailout3.hostsharing.net ([176.9.242.54]:54285 "EHLO mailout3.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751048AbdKYInq (ORCPT ); Sat, 25 Nov 2017 03:43:46 -0500 X-Greylist: delayed 325 seconds by postgrey-1.27 at vger.kernel.org; Sat, 25 Nov 2017 03:43:45 EST Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by mailout3.hostsharing.net (Postfix) with ESMTPS id DAFA010195B96; Sat, 25 Nov 2017 09:38:39 +0100 (CET) Received: from localhost (6-38-90-81.adsl.cmo.de [81.90.38.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id 4A3C561656B8; Sat, 25 Nov 2017 09:38:18 +0100 (CET) X-Mailbox-Line: From 2f78166e4b54d5c0d139121c00a69ee033918da6 Mon Sep 17 00:00:00 2001 Message-Id: <2f78166e4b54d5c0d139121c00a69ee033918da6.1511598241.git.lukas@wunner.de> From: Lukas Wunner Date: Sat, 25 Nov 2017 09:38:17 +0100 Subject: [PATCH] iio: Add macro to populate struct iio_map array To: Jonathan Cameron Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Mathias Duckeck , linux-iio@vger.kernel.org, Chen-Yu Tsai , Jacob Pan 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 GPIO core provides a handy GPIO_LOOKUP() macro to populate a struct gpiod_lookup array without having to spell out attribute names (but still avoid breakage when attributes within the struct are rearranged or added). The axp288_adc.c driver uses a similar macro to populate a struct iio_map array. Make it available to others. Cc: Chen-Yu Tsai Cc: Jacob Pan Signed-off-by: Lukas Wunner Acked-by: Chen-Yu Tsai --- The motivation for this change is that we're using it in a module which is currently out-of-tree. I'm only converting axp288_adc.c here as it already has such a macro, and not all the other drivers which declare iio_map arrays because such trivial refactoring is not always welcome. I could convert these other drivers as well if desired. If so, please let me know if this should all be put in a single patch or split per driver. Note that I've replaced _adc_channel_label with _provider_channel, which is more apt in my opinion. Please shout if you disagree. Thanks! drivers/iio/adc/axp288_adc.c | 20 ++++++-------------- include/linux/iio/machine.h | 7 +++++++ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/iio/adc/axp288_adc.c b/drivers/iio/adc/axp288_adc.c index 60c9e853dd81..031d568b4972 100644 --- a/drivers/iio/adc/axp288_adc.c +++ b/drivers/iio/adc/axp288_adc.c @@ -92,22 +92,14 @@ static const struct iio_chan_spec axp288_adc_channels[] = { }, }; -#define AXP288_ADC_MAP(_adc_channel_label, _consumer_dev_name, \ - _consumer_channel) \ - { \ - .adc_channel_label = _adc_channel_label, \ - .consumer_dev_name = _consumer_dev_name, \ - .consumer_channel = _consumer_channel, \ - } - /* for consumer drivers */ static struct iio_map axp288_adc_default_maps[] = { - AXP288_ADC_MAP("TS_PIN", "axp288-batt", "axp288-batt-temp"), - AXP288_ADC_MAP("PMIC_TEMP", "axp288-pmic", "axp288-pmic-temp"), - AXP288_ADC_MAP("GPADC", "axp288-gpadc", "axp288-system-temp"), - AXP288_ADC_MAP("BATT_CHG_I", "axp288-chrg", "axp288-chrg-curr"), - AXP288_ADC_MAP("BATT_DISCHRG_I", "axp288-chrg", "axp288-chrg-d-curr"), - AXP288_ADC_MAP("BATT_V", "axp288-batt", "axp288-batt-volt"), + IIO_MAP("TS_PIN", "axp288-batt", "axp288-batt-temp"), + IIO_MAP("PMIC_TEMP", "axp288-pmic", "axp288-pmic-temp"), + IIO_MAP("GPADC", "axp288-gpadc", "axp288-system-temp"), + IIO_MAP("BATT_CHG_I", "axp288-chrg", "axp288-chrg-curr"), + IIO_MAP("BATT_DISCHRG_I", "axp288-chrg", "axp288-chrg-d-curr"), + IIO_MAP("BATT_V", "axp288-batt", "axp288-batt-volt"), {}, }; diff --git a/include/linux/iio/machine.h b/include/linux/iio/machine.h index 1601a2a63a72..5e1cfa75f652 100644 --- a/include/linux/iio/machine.h +++ b/include/linux/iio/machine.h @@ -28,4 +28,11 @@ struct iio_map { void *consumer_data; }; +#define IIO_MAP(_provider_channel, _consumer_dev_name, _consumer_channel) \ +{ \ + .adc_channel_label = _provider_channel, \ + .consumer_dev_name = _consumer_dev_name, \ + .consumer_channel = _consumer_channel, \ +} + #endif