From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796386364; b=KKj3aWPm8goov8I3QelbAyzDtr99VvQ+QuZ+MWxGHIQybJYJTlGXj9MSHNOXwoO6Z/u/ NgpFGBacSwWcvwJ+XNNbPGaQ9wOCY71mZpx5HGtD6NXdd4SnG5xZYmfyJ0iRrF4u0cvVg 1BrXdKCUU8iaOj2YmDDxPYqQSO47SwV3f0M/pLxqxa1BYoh3kKv0wxEU3HUiCtXJW00hA s7dP57BK0gM+NZrK8k+ZoWj4ioqiiJgN3cUQQG7sOJT7AWkoop60GC4bJK3gL2kEe1X5U 3a/yLQ2BXRBf/uSFIoQ26Xcin334oAv4eHQcKk3FxbAODTK2UnIlxwEHvOOnvml4eBA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386364; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:Content-Transfer-Encoding:In-Reply-To: Organization; bh=YQF3JDsi+gq7Pt5tRytAp7hcJEohEDbKqIUCOAfadGs=; b=zydC55aoDGClSMwXb7GEkd9rSeXFLTW282JLnXPOOqUHzHD5V6i/qshs6AdlmmZ/k5pB Nonohb7FENAy+lWGvnu71aXZG0iOGlLxjDQRs/vuU9fMpRppNLhhCNXhwHcoTupRXLM+D evGk73gIKyU6z8p0ZILjIXb31zcOts1rwYZjbbhojoau+sUWuIQL0Am1Tb9W/ecN7nc+x tCgcLDYeiO2ntxxYGWNgFQUxtwtNO1LfjQNEJqfDctuzPSzqCodO70EdAwfghpVCTDfW/ gxskhCPhGcTsgiY0mLLXYyqbDAgOi8J7QV80nVb4+sPZ64iL2HoOhY7EB+JroGuEE0A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=JXPbbcdU; arc=none smtp.remote-ip=198.175.65.17 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACA6E606A322; Fri, 4 Dec 2026 12:12:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ACA6E606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=JXPbbcdU DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796386363; x=1827922363; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=YQF3JDsi+gq7Pt5tRytAp7hcJEohEDbKqIUCOAfadGs=; b=JXPbbcdUJElSZsPfwkSk83aefjrNp8Fu0+8ZzFVk/OsGd8k/Bf5qDYWE qnbZlVcuNSBr7+tQZv+ch8aoIuxaa3a/JZX+4WQb1sPFGA6CnFnGGMHNp YWI/+1Egn3I/EbL2PeS1Co9cosV9rvnh15t9zUcHyUdYboqWXsqf8IxFR QLV7uHdj1GU+a0dEUdhNjt+XsozKLCtUDkZchAy7m3shDQyDSxvhKXzc6 l/PGh1kohFsKHiI706+r3fNPywejW9izGswNk0MzAJKHuBTrsSTzo3vA8 VBT8kLhF6yiGF4iKrKUzA7z9lBE1lElx+i7PqtrRJFOqvIjzwuvtEmOXa Q==; X-CSE-ConnectionGUID: AIkB14FtQ8qP2D4VU0Frmw== X-CSE-MsgGUID: /c+7fUk0RsO4hzaFOJdnNg== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5377292" X-IronPort-AV: E=Sophos;i="6.29,78,1794902400"; d="scan'208";a="5377292" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 04:12:15 -0800 X-CSE-ConnectionGUID: buF6tKdASqGFzUHEXichmw== X-CSE-MsgGUID: iYepNvYlRHy6mfAt21Q4lw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,78,1794902400"; d="scan'208";a="14546938" Received: from alekseim-mobl.ger.corp.intel.com (HELO localhost) ([10.245.245.10]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 04:12:11 -0800 Date: Fri, 4 Dec 2026 14:12:09 +0200 From: Andy Shevchenko To: Nuno =?iso-8859-1?Q?S=E1?= Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux@analog.com, Michael Hennerich , Jonathan Cameron , David Lechner , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Arnd Bergmann Subject: Re: [PATCH v2 11/11] iio: adc: ad7793: add firmware support Message-ID: References: <20261202-iio-adi-legacy-platdata-v2-0-0fd64abe73f4@analog.com> <20261202-iio-adi-legacy-platdata-v2-11-0fd64abe73f4@analog.com> X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20261202-iio-adi-legacy-platdata-v2-11-0fd64abe73f4@analog.com> Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo On Wed, Dec 02, 2026 at 05:05:43PM +0000, Nuno Sá wrote: > The driver refuses to probe without platform data, which no one can > provide anymore. That means the driver can not be used at all on a > modern system. > > Get the configuration from firmware properties instead, following the > binding: > > - The reference is REFIN (REFIN1) if refin-supply is present, REFIN2 if > refin2-supply is present, and the internal 1.17 V reference otherwise. > Parts without an internal reference need refin-supply. > - An external clock on the CLK pin is used if given. A 128 kHz clock > is divided by 2 internally. > - The input buffer stays enabled (as it is at power-up) unless > adi,low-source-impedance is set, and unipolar coding is used unless > bipolar is set. > - The bias voltage generator and the excitation current sources get > their own properties. > > Also add an OF match table. ... > +#include > #include > #include > #include > +#include > #include > +#include > #include > #include > #include > #include > #include > #include > +#include No. With so many additions, please cleanup the mess first with two additional patches: - sort each group alphabetically - rework in accordance with IWYU > #include > #include ... > +static int ad7793_parse_excitation(struct device *dev, > + struct ad7793_config *cfg) I would use a single line. > +{ > + static const char * const iout_pins[] = { "iout1", "iout2" }; > + u32 pins[] = { 1, 2 }; > + const char *names[2]; > + u32 val; > + int ret; > + ret = device_property_read_u32(dev, "adi,excitation-current-microamp", &val); > + /* Excitation pins only matter if the excitation current is enabled */ > + if (ret) > + return 0; All corner case errors (when property *is* there) are ignored. Instead, check for property presence. /* Excitation pins only matter if the excitation current is enabled */ if (!device_property_present(dev, propname)) return 0; ret = device_property_read_u32(dev, "adi,excitation-current-microamp", &val); if (ret) return ret; > + switch (val) { > + case 10: > + cfg->exitation_current = AD7793_IX_10uA; > + break; > + case 210: > + cfg->exitation_current = AD7793_IX_210uA; > + break; > + case 1000: > + cfg->exitation_current = AD7793_IX_1mA; > + break; > + default: > + return dev_err_probe(dev, -EINVAL, > + "Invalid excitation current: %u\n", val); > + } > + > + if (device_property_present(dev, "adi,excitation-pins")) { > + ret = device_property_read_string_array(dev, "adi,excitation-pins", > + names, ARRAY_SIZE(names)); > + if (ret != ARRAY_SIZE(names)) > + return dev_err_probe(dev, ret < 0 ? ret : -EINVAL, > + "Invalid adi,excitation-pins\n"); Unroll this mess. ret = device_property_read_string_array(dev, "adi,excitation-pins", names, ARRAY_SIZE(names)); if (ret < 0) return ret; > + /* IOUT pin number for IEXC1 and IEXC2 */ > + for (unsigned int i = 0; i < ARRAY_SIZE(names); i++) { > + ret = match_string(iout_pins, ARRAY_SIZE(iout_pins), > + names[i]); > + if (ret < 0) > + return dev_err_probe(dev, ret, > + "Invalid adi,excitation-pins\n"); > + > + pins[i] = ret + 1; > + } Hmm... Can device_property_match_property_string() be helpful here? Or maybe device_property_match_string() in a loop? > + } > + > + if (pins[0] == 1 && pins[1] == 2) > + cfg->current_source_direction = AD7793_IEXEC1_IOUT1_IEXEC2_IOUT2; > + else if (pins[0] == 2 && pins[1] == 1) > + cfg->current_source_direction = AD7793_IEXEC1_IOUT2_IEXEC2_IOUT1; > + else if (pins[0] == 1) > + cfg->current_source_direction = AD7793_IEXEC1_IEXEC2_IOUT1; > + else > + cfg->current_source_direction = AD7793_IEXEC1_IEXEC2_IOUT2; > + > + return 0; > +} ... > +static int ad7793_parse_fw(struct device *dev, struct ad7793_config *cfg, > + unsigned int *vref_mv) _mV > +{ > + static const char * const vbias_pins[] = { "ain1", "ain2", "ain3" }; > + static const char * const refin_names[] = { "refin", "refin2" }; > + unsigned long rate; > + struct clk *clk; > + int ret; > + > + cfg->refsel = AD7793_REFSEL_INTERNAL; > + for (unsigned int i = 0; i < ARRAY_SIZE(refin_names); i++) { > + ret = devm_regulator_get_enable_read_voltage(dev, refin_names[i]); > + if (ret < 0 && ret != -ENODEV) > + return dev_err_probe(dev, ret, "Failed to get %s voltage\n", > + refin_names[i]); > + if (ret == -ENODEV) > + continue; Deduplicate ENODEV check, we do this with if-else-if chain. > + cfg->refsel = i; > + *vref_mv = ret / 1000; Introduce MICROVOLT_PER_MILLIVOLT in units.h eventually and use it here. > + break; > + } > + > + if (cfg->refsel == AD7793_REFSEL_INTERNAL) > + *vref_mv = 1170; > + > + clk = devm_clk_get_optional_enabled(dev, NULL); > + if (IS_ERR(clk)) > + return dev_err_probe(dev, PTR_ERR(clk), "Failed to get clock\n"); > + > + if (clk) { > + rate = clk_get_rate(clk); > + if (rate == 64 * HZ_PER_KHZ) > + cfg->clock_src = AD7793_CLK_SRC_EXT; > + else if (rate == 128 * HZ_PER_KHZ) > + cfg->clock_src = AD7793_CLK_SRC_EXT_DIV2; > + else > + return dev_err_probe(dev, -EINVAL, > + "Invalid clock rate: %lu Hz\n", rate); > + } > + > + if (device_property_present(dev, "adi,vbias-pin")) { > + ret = device_property_match_property_string(dev, "adi,vbias-pin", > + vbias_pins, > + ARRAY_SIZE(vbias_pins)); > + if (ret < 0) > + return dev_err_probe(dev, ret, "Invalid adi,vbias-pin\n"); > + > + cfg->bias_voltage = AD7793_BIAS_VOLTAGE_AIN1 + ret; > + cfg->boost_enable = device_property_read_bool(dev, "adi,vbias-boost-enable"); > + } > + > + cfg->buffered = !device_property_read_bool(dev, "adi,low-source-impedance"); > + cfg->unipolar = !device_property_read_bool(dev, "bipolar"); > + > + return ad7793_parse_excitation(dev, cfg); > +} ... > static int ad7793_probe(struct spi_device *spi) > { > static const char * const supplies[] = { "avdd", "dvdd" }; > struct device *dev = &spi->dev; > - const struct ad7793_config *cfg = dev_get_platdata(dev); > + struct ad7793_config cfg = { }; > struct ad7793_state *st; > struct iio_dev *indio_dev; > - int ret, vref_mv = 0; > - > - if (!cfg) > - return dev_err_probe(dev, -ENODEV, "no platform data?\n"); > + unsigned int vref_mv; _mV > + int ret; ... > +static const struct of_device_id ad7793_of_match[] = { > + { .compatible = "adi,ad7785", .data = &ad7793_chip_info_tbl[ID_AD7785] }, > + { .compatible = "adi,ad7792", .data = &ad7793_chip_info_tbl[ID_AD7792] }, > + { .compatible = "adi,ad7793", .data = &ad7793_chip_info_tbl[ID_AD7793] }, > + { .compatible = "adi,ad7794", .data = &ad7793_chip_info_tbl[ID_AD7794] }, > + { .compatible = "adi,ad7795", .data = &ad7793_chip_info_tbl[ID_AD7795] }, > + { .compatible = "adi,ad7796", .data = &ad7793_chip_info_tbl[ID_AD7796] }, > + { .compatible = "adi,ad7797", .data = &ad7793_chip_info_tbl[ID_AD7797] }, > + { .compatible = "adi,ad7798", .data = &ad7793_chip_info_tbl[ID_AD7798] }, > + { .compatible = "adi,ad7799", .data = &ad7793_chip_info_tbl[ID_AD7799] }, > + { } > +}; I have a feeling that this patch may be split to more. -- With Best Regards, Andy Shevchenko