Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1497976ybt; Thu, 9 Jul 2020 08:25:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVCTHrePEv974Z+VrFQEV7B0JqfoY664h1mLA6FJyFAiHpRLaZy+PL897a0mGyFa9hubn3 X-Received: by 2002:aa7:dc46:: with SMTP id g6mr67742837edu.194.1594308354134; Thu, 09 Jul 2020 08:25:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594308354; cv=none; d=google.com; s=arc-20160816; b=I3Wb9nixG0bb5FHeWELcX5q26HvMjhl2TnOKPJ7IvPCRQE4GLsIc0T/n/yJjHK/zOR 0inAOQIJ/QNZePEzhTIevjySWUjt+pLnGk4oAKjmrRsTwglyyd7CZfmRdxs7sFCaALFg a6bCNg4+SyBdI3UbxPwdGLDfSrBXHP5QmcBoQ16w51dQQXrLzjbw/ta8b3Q5RRxYgufW 28enUJDKY8xjTUSIEKljzzCgKyqZqNURPFCp3O4sb9fTvXzs/t2xYWlPnpUZk/q/+xyo PcSLRf2lzkxFmzSHUSmj4p2A3QlJ+tmx2Gw9x2wfX7zf3mUOeaVF3nF/0HChIRstgryB o3lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ERL7pOe10xl9KA5WIjiGv4qmcZpYHCER3s8dgZ2cgcA=; b=MMoXhnrYjNFzj6sXQrar/KkH94sG7ScDaoxHPycVamc8XiCNnFkSXAlL2U5Zu5wJHC vyKRQl5k8wdgLM0ZGJ39Sj14MCmPH4ujSJ0KqWBdHmLZxK+XEx1KOI3HB/AwY872lOu0 pBAuroQjpl1eXryWjVfuaIVBTpc406Su7DYCOx/aX83GmdgVwmOTN5Aq+pYsyPFQ4C7I EYbFcGcqOa7Tugdzk3baHC/IVEFL7pGIoFmxkUMKMxMm2p097BZ8kKAnZu61dHgski19 n3fJ7Q7Qe5FCiiAM6aKUEThQz0FAmjqh6tTo2IOeFbbNWB5hbZSco/uS/bqVQ2HiTab3 m8zg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rv20si2267413ejb.420.2020.07.09.08.25.31; Thu, 09 Jul 2020 08:25:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728430AbgGIPW5 (ORCPT + 99 others); Thu, 9 Jul 2020 11:22:57 -0400 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:51177 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728097AbgGIPWv (ORCPT ); Thu, 9 Jul 2020 11:22:51 -0400 X-Originating-IP: 195.189.32.242 Received: from pc.localdomain (unknown [195.189.32.242]) (Authenticated sender: contact@artur-rojek.eu) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 6E3F1C001B; Thu, 9 Jul 2020 15:22:47 +0000 (UTC) From: Artur Rojek To: Dmitry Torokhov , Rob Herring , Mark Rutland , Jonathan Cameron , Paul Cercueil , Andy Shevchenko Cc: Heiko Stuebner , Ezequiel Garcia , devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Artur Rojek Subject: [PATCH v8 4/6] iio/adc: ingenic: Retrieve channels list from soc data struct Date: Thu, 9 Jul 2020 17:21:58 +0200 Message-Id: <20200709152200.10039-5-contact@artur-rojek.eu> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200709152200.10039-1-contact@artur-rojek.eu> References: <20200709152200.10039-1-contact@artur-rojek.eu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paul Cercueil Instead of having one array of struct iio_chan_spec for all SoCs, and have some SoCs remove the last item of the array as they can't use it, have each SoC define its array of supported channels. Signed-off-by: Paul Cercueil Tested-by: Artur Rojek --- Changes: v8: new patch drivers/iio/adc/ingenic-adc.c | 99 +++++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 34 deletions(-) diff --git a/drivers/iio/adc/ingenic-adc.c b/drivers/iio/adc/ingenic-adc.c index 89019fb59d48..0233a9055c86 100644 --- a/drivers/iio/adc/ingenic-adc.c +++ b/drivers/iio/adc/ingenic-adc.c @@ -55,6 +55,8 @@ struct ingenic_adc_soc_data { size_t battery_scale_avail_size; unsigned int battery_vref_mode: 1; unsigned int has_aux2: 1; + const struct iio_chan_spec *channels; + unsigned int num_channels; int (*init_clk_div)(struct device *dev, struct ingenic_adc *adc); }; @@ -262,6 +264,61 @@ static int jz4770_adc_init_clk_div(struct device *dev, struct ingenic_adc *adc) return 0; } +static const struct iio_chan_spec jz4740_channels[] = { + { + .extend_name = "aux", + .type = IIO_VOLTAGE, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + .indexed = 1, + .channel = INGENIC_ADC_AUX, + .scan_index = -1, + }, + { + .extend_name = "battery", + .type = IIO_VOLTAGE, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + .info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + .indexed = 1, + .channel = INGENIC_ADC_BATTERY, + .scan_index = -1, + }, +}; + +static const struct iio_chan_spec jz4770_channels[] = { + { + .extend_name = "aux", + .type = IIO_VOLTAGE, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + .indexed = 1, + .channel = INGENIC_ADC_AUX, + .scan_index = -1, + }, + { + .extend_name = "battery", + .type = IIO_VOLTAGE, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + .info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + .indexed = 1, + .channel = INGENIC_ADC_BATTERY, + .scan_index = -1, + }, + { + .extend_name = "aux2", + .type = IIO_VOLTAGE, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + .indexed = 1, + .channel = INGENIC_ADC_AUX2, + .scan_index = -1, + }, +}; + static const struct ingenic_adc_soc_data jz4725b_adc_soc_data = { .battery_high_vref = JZ4725B_ADC_BATTERY_HIGH_VREF, .battery_high_vref_bits = JZ4725B_ADC_BATTERY_HIGH_VREF_BITS, @@ -271,6 +328,8 @@ static const struct ingenic_adc_soc_data jz4725b_adc_soc_data = { .battery_scale_avail_size = ARRAY_SIZE(jz4725b_adc_battery_scale_avail), .battery_vref_mode = true, .has_aux2 = false, + .channels = jz4740_channels, + .num_channels = ARRAY_SIZE(jz4740_channels), .init_clk_div = jz4725b_adc_init_clk_div, }; @@ -283,6 +342,8 @@ static const struct ingenic_adc_soc_data jz4740_adc_soc_data = { .battery_scale_avail_size = ARRAY_SIZE(jz4740_adc_battery_scale_avail), .battery_vref_mode = true, .has_aux2 = false, + .channels = jz4740_channels, + .num_channels = ARRAY_SIZE(jz4740_channels), .init_clk_div = NULL, /* no ADCLK register on JZ4740 */ }; @@ -295,6 +356,8 @@ static const struct ingenic_adc_soc_data jz4770_adc_soc_data = { .battery_scale_avail_size = ARRAY_SIZE(jz4770_adc_battery_scale_avail), .battery_vref_mode = false, .has_aux2 = true, + .channels = jz4770_channels, + .num_channels = ARRAY_SIZE(jz4770_channels), .init_clk_div = jz4770_adc_init_clk_div, }; @@ -427,35 +490,6 @@ static const struct iio_info ingenic_adc_info = { .of_xlate = ingenic_adc_of_xlate, }; -static const struct iio_chan_spec ingenic_channels[] = { - { - .extend_name = "aux", - .type = IIO_VOLTAGE, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | - BIT(IIO_CHAN_INFO_SCALE), - .indexed = 1, - .channel = INGENIC_ADC_AUX, - }, - { - .extend_name = "battery", - .type = IIO_VOLTAGE, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | - BIT(IIO_CHAN_INFO_SCALE), - .info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW) | - BIT(IIO_CHAN_INFO_SCALE), - .indexed = 1, - .channel = INGENIC_ADC_BATTERY, - }, - { /* Must always be last in the array. */ - .extend_name = "aux2", - .type = IIO_VOLTAGE, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | - BIT(IIO_CHAN_INFO_SCALE), - .indexed = 1, - .channel = INGENIC_ADC_AUX2, - }, -}; - static int ingenic_adc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -517,11 +551,8 @@ static int ingenic_adc_probe(struct platform_device *pdev) iio_dev->dev.parent = dev; iio_dev->name = "jz-adc"; iio_dev->modes = INDIO_DIRECT_MODE; - iio_dev->channels = ingenic_channels; - iio_dev->num_channels = ARRAY_SIZE(ingenic_channels); - /* Remove AUX2 from the list of supported channels. */ - if (!adc->soc_data->has_aux2) - iio_dev->num_channels -= 1; + iio_dev->channels = soc_data->channels; + iio_dev->num_channels = soc_data->num_channels; iio_dev->info = &ingenic_adc_info; ret = devm_iio_device_register(dev, iio_dev); -- 2.27.0