Received: by 10.223.164.221 with SMTP id h29csp1555215wrb; Wed, 25 Oct 2017 02:30:14 -0700 (PDT) X-Google-Smtp-Source: ABhQp+S0fd2llV5ekzzUlujnQVfET9E2x748FNjbpq1bBDlAllViVNruJbVk2E5BLkagRLvhlWlC X-Received: by 10.84.246.197 with SMTP id j5mr1258332plt.7.1508923814222; Wed, 25 Oct 2017 02:30:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508923814; cv=none; d=google.com; s=arc-20160816; b=AyjAtCRYtXD6Je6GbzpJIQWoIMf1pdK+GbzrHgH8XjzKwzRbgKvyEMrT9rPUSN38WA xuvkwz8KHpxcvukBpZYL0ylyV99YKpkQ6RdocrM8b//A9p0IR4nLq6bEirjvcSF4zX3Z BPUbHR5ssFIgzQdr4bTAiQpnchkTBDPMTlusgVfZqPzoFFsmMEOLKEoS92in0nyoLjiQ js266vqg04tPR6KXtO52BK7Wph2hdbzXjoLsLN7Q1mkK904KDXu0AO3OIo61Z1DECrdN uGH+HV+UVQ8ZYw3ndRgB4qDow2vhwyRkimT72koXKw8/v4mcmtE/ZUGJi8ni0VwQluSo RKtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=95+qyOL7y7lqScriBFNVVyxeK5MukHqoWSOnC9n6HbI=; b=UrT6/uDb27Zs/hVqjJnTYSLIo6CckG5BQPxkP37JWMMwhyoH64bVgs3SeOEmCEca5y 1kG0mUN+RseooMP5xqyZEbgD8xZr1lNtfBgVLULwwCaLeMNKA+wMyRL1+7a5xAjQVFId aVYPpeM+/oEhmxqyDp5aAACO+HXq+67WG7R8mCvECQgI3qd/y7tX3AEE4yhLZcmh8Vsx oLQja/Hj/UYxStE3aAWnG9etmdRyd/y3AUzDJ/AyKaM0nmq8NJ9Z8pbzwQ1Jb/Wiuhzg NN0FqSArqEgDQBjU6tnGLsGAvNr4qcD3qA4HGz3L5eXQR9c/Y4PeCIGnIk/6hUoI5TCm FHEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w124si1690163pfw.547.2017.10.25.02.29.58; Wed, 25 Oct 2017 02:30:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932473AbdJYJ3Q (ORCPT + 99 others); Wed, 25 Oct 2017 05:29:16 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:9891 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932315AbdJYJ3G (ORCPT ); Wed, 25 Oct 2017 05:29:06 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9P9Odod010444; Wed, 25 Oct 2017 11:28:06 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2dtg2q2mfe-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 25 Oct 2017 11:28:06 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 8627C31; Wed, 25 Oct 2017 09:28:05 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag5node3.st.com [10.75.127.15]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 4091015C1; Wed, 25 Oct 2017 09:28:05 +0000 (GMT) Received: from localhost (10.75.127.48) by SFHDAG5NODE3.st.com (10.75.127.15) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Wed, 25 Oct 2017 11:28:04 +0200 From: Fabrice Gasnier To: , CC: , , , , , , , , , , , , , Subject: [PATCH v2 2/3] iio: adc: stm32: remove const channel names definition Date: Wed, 25 Oct 2017 11:27:44 +0200 Message-ID: <1508923665-2274-3-git-send-email-fabrice.gasnier@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1508923665-2274-1-git-send-email-fabrice.gasnier@st.com> References: <1508923665-2274-1-git-send-email-fabrice.gasnier@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG6NODE1.st.com (10.75.127.16) To SFHDAG5NODE3.st.com (10.75.127.15) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-10-25_05:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Remove const array that defines channels. Build channels definition at probe time, when initializing channels (only for requested ones). This will ease adding differential channels support. Signed-off-by: Fabrice Gasnier --- Changes in v2: - Improve val variable names in stm32_adc_chan_init_one() definition as suggested by Jonathan. --- drivers/iio/adc/stm32-adc.c | 66 ++++++++++----------------------------------- 1 file changed, 14 insertions(+), 52 deletions(-) diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c index 4df32cf..417a894 100644 --- a/drivers/iio/adc/stm32-adc.c +++ b/drivers/iio/adc/stm32-adc.c @@ -153,6 +153,8 @@ enum stm32h7_adc_dmngt { /* BOOST bit must be set on STM32H7 when ADC clock is above 20MHz */ #define STM32H7_BOOST_CLKRATE 20000000UL +#define STM32_ADC_CH_MAX 20 /* max number of channels */ +#define STM32_ADC_CH_SZ 5 /* max channel name size */ #define STM32_ADC_MAX_SQ 16 /* SQ1..SQ16 */ #define STM32_ADC_MAX_SMP 7 /* SMPx range is [0..7] */ #define STM32_ADC_TIMEOUT_US 100000 @@ -300,6 +302,7 @@ struct stm32_adc_cfg { * @pcsel bitmask to preselect channels on some devices * @smpr_val: sampling time settings (e.g. smpr1 / smpr2) * @cal: optional calibration data on some devices + * @chan_name: channel name array */ struct stm32_adc { struct stm32_adc_common *common; @@ -321,69 +324,28 @@ struct stm32_adc { u32 pcsel; u32 smpr_val[2]; struct stm32_adc_calib cal; -}; - -/** - * struct stm32_adc_chan_spec - specification of stm32 adc channel - * @type: IIO channel type - * @channel: channel number (single ended) - * @name: channel name (single ended) - */ -struct stm32_adc_chan_spec { - enum iio_chan_type type; - int channel; - const char *name; + char chan_name[STM32_ADC_CH_MAX][STM32_ADC_CH_SZ]; }; /** * struct stm32_adc_info - stm32 ADC, per instance config data - * @channels: Reference to stm32 channels spec * @max_channels: Number of channels * @resolutions: available resolutions * @num_res: number of available resolutions */ struct stm32_adc_info { - const struct stm32_adc_chan_spec *channels; int max_channels; const unsigned int *resolutions; const unsigned int num_res; }; -/* - * Input definitions common for all instances: - * stm32f4 can have up to 16 channels - * stm32h7 can have up to 20 channels - */ -static const struct stm32_adc_chan_spec stm32_adc_channels[] = { - { IIO_VOLTAGE, 0, "in0" }, - { IIO_VOLTAGE, 1, "in1" }, - { IIO_VOLTAGE, 2, "in2" }, - { IIO_VOLTAGE, 3, "in3" }, - { IIO_VOLTAGE, 4, "in4" }, - { IIO_VOLTAGE, 5, "in5" }, - { IIO_VOLTAGE, 6, "in6" }, - { IIO_VOLTAGE, 7, "in7" }, - { IIO_VOLTAGE, 8, "in8" }, - { IIO_VOLTAGE, 9, "in9" }, - { IIO_VOLTAGE, 10, "in10" }, - { IIO_VOLTAGE, 11, "in11" }, - { IIO_VOLTAGE, 12, "in12" }, - { IIO_VOLTAGE, 13, "in13" }, - { IIO_VOLTAGE, 14, "in14" }, - { IIO_VOLTAGE, 15, "in15" }, - { IIO_VOLTAGE, 16, "in16" }, - { IIO_VOLTAGE, 17, "in17" }, - { IIO_VOLTAGE, 18, "in18" }, - { IIO_VOLTAGE, 19, "in19" }, -}; - static const unsigned int stm32f4_adc_resolutions[] = { /* sorted values so the index matches RES[1:0] in STM32F4_ADC_CR1 */ 12, 10, 8, 6, }; +/* stm32f4 can have up to 16 channels */ static const struct stm32_adc_info stm32f4_adc_info = { - .channels = stm32_adc_channels, .max_channels = 16, .resolutions = stm32f4_adc_resolutions, .num_res = ARRAY_SIZE(stm32f4_adc_resolutions), @@ -394,9 +356,9 @@ struct stm32_adc_info { 16, 14, 12, 10, 8, }; +/* stm32h7 can have up to 20 channels */ static const struct stm32_adc_info stm32h7_adc_info = { - .channels = stm32_adc_channels, - .max_channels = 20, + .max_channels = STM32_ADC_CH_MAX, .resolutions = stm32h7_adc_resolutions, .num_res = ARRAY_SIZE(stm32h7_adc_resolutions), }; @@ -1628,15 +1590,16 @@ static void stm32_adc_smpr_init(struct stm32_adc *adc, int channel, u32 smp_ns) } static void stm32_adc_chan_init_one(struct iio_dev *indio_dev, - struct iio_chan_spec *chan, - const struct stm32_adc_chan_spec *channel, + struct iio_chan_spec *chan, u32 vinp, int scan_index, u32 smp) { struct stm32_adc *adc = iio_priv(indio_dev); + char *name = adc->chan_name[vinp]; - chan->type = channel->type; - chan->channel = channel->channel; - chan->datasheet_name = channel->name; + chan->type = IIO_VOLTAGE; + chan->channel = vinp; + snprintf(name, STM32_ADC_CH_SZ, "in%d", vinp); + chan->datasheet_name = name; chan->scan_index = scan_index; chan->indexed = 1; chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); @@ -1699,8 +1662,7 @@ static int stm32_adc_chan_of_init(struct iio_dev *indio_dev) scan_index, &smp); stm32_adc_chan_init_one(indio_dev, &channels[scan_index], - &adc_info->channels[val], - scan_index, smp); + val, scan_index, smp); scan_index++; } -- 1.9.1 From 1584982146786034962@xxx Fri Nov 24 20:52:45 +0000 2017 X-GM-THRID: 1584982146786034962 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread