Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp971261rwl; Wed, 12 Apr 2023 06:43:17 -0700 (PDT) X-Google-Smtp-Source: AKy350a2BenzZr8jvP+tlwJ0Al60CpM17c4wtHAuAiLoq1yPFCg60hHSFhjoM8a6OcmifMro/XOC X-Received: by 2002:a17:906:f1d7:b0:94a:5c6d:3207 with SMTP id gx23-20020a170906f1d700b0094a5c6d3207mr12688225ejb.44.1681306996972; Wed, 12 Apr 2023 06:43:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681306996; cv=none; d=google.com; s=arc-20160816; b=d3goyPf/j6LMsKFzqOO495Cd1NNlYlzP8+ajZ1V3pO9cg8krBEiItntifmwQr9YNVa ID1xD7CqSx65n1TcqN92I45qrFP3sxfLFTfCtuGYeGJ3otBTVHX9AKg4rc3sFMCogTRp Sva1WDtaQoz6iz3OqKpaYJ+osQGx1XeK1tE+PiPznxGWmEvd0XI9zYSOUTfE8JvCPXhr 5UFLohh0JF8SJLM23DfWKHKE4atlYgsPguHtJcHXYixbRoFm6dxGUIbdRfhtqY1M/G9w LJxS7Y83p/+B/Mi2W+H9baryfeScXHDT2S7vLLOlQMEZkn2t5sMPxbSq2ulWBdZWpMAD dKwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=xpY9u1Hj5aya9MPjDqsYFbQbTpZwCuTdyF8lywSd+SY=; b=LP36AOOBNe+tzyrpSvUSrjV54P/L8xonbJ16ooTcYGO8Pl3kVunpK6b9dnLlsLInF+ LUyfDd9G34witPWBkpkBXvq/mNWVlCTxmjp+rHjDFe+5T5os0h60Ej2fPjbn3r5JMWAa 1Mo5JR5auGnJm3vwfH8LK+0JfCdsz2+rFBnXTz4T/IWJSopq3HoDRTrTnbZb1wInhE7r 0f5GkhhW3sYHYoUoWETyOzL3XWq8wpTRDdlAilW5AVAk7cYnoCBN2b15kOi3ChaSdWvZ lxPgR3G46DRCAy1vR3MrFJK87Ao1bBSPhvYQFy9H+wF6KdyAm5naw6U8Fw+oH7Xvb0aY 38zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=O3cSYzkt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 19-20020a170906209300b00946a18bb2dfsi1609612ejq.986.2023.04.12.06.42.51; Wed, 12 Apr 2023 06:43:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=O3cSYzkt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229864AbjDLNlr (ORCPT + 99 others); Wed, 12 Apr 2023 09:41:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230397AbjDLNln (ORCPT ); Wed, 12 Apr 2023 09:41:43 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C666183FC; Wed, 12 Apr 2023 06:41:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681306897; x=1712842897; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=vT0LqjKFDK/5Av6PJjxxq20lgHvDiGW3TQWTthosmyI=; b=O3cSYzkttwtPh1LQuYGfiDco8tjzLyF6ADMqxS7judXIDZVbXPj3oknV US4XRQNC/TnDytBzQN6xI2Mg0Jy8+GolePv4XxkojljtiQFP0jYKCJJEH ocubtNvYB4CGyiQdC0dqm0WSBXX8CvZaN0t9yB0iiNWC18Zl9oWFtCnM7 /gC0FDCioWY8hum4wnC2eeTe5eYOhxnRVdQhuY/E0UUrNEcFSQW7C/V2Z 5BUro3ZURUhJ7odB2oElJ+emFZ2KK8lGYBk2LOdwM1FSRzeIQtNH6EKxv oyCg5UJBiCnxiGQ8g/ggzA4X5xkw6SMMb6lxvAg6R/M2AYJdUWLVjXIyk A==; X-IronPort-AV: E=McAfee;i="6600,9927,10678"; a="343903492" X-IronPort-AV: E=Sophos;i="5.98,339,1673942400"; d="scan'208";a="343903492" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2023 06:41:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10678"; a="800330743" X-IronPort-AV: E=Sophos;i="5.98,339,1673942400"; d="scan'208";a="800330743" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga002.fm.intel.com with ESMTP; 12 Apr 2023 06:41:32 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1pmaj3-00Fxbw-1d; Wed, 12 Apr 2023 16:41:29 +0300 Date: Wed, 12 Apr 2023 16:41:29 +0300 From: Andy Shevchenko To: Okan Sahin Cc: Jonathan Cameron , Lee Jones , Rob Herring , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , Jonathan Cameron , Lars-Peter Clausen , Cosmin Tanislav , Ibrahim Tilki , Greg Kroah-Hartman , Ramona Bolboaca , Caleb Connolly , ChiYuan Huang , William Breathitt Gray , Arnd Bergmann , AngeloGioacchino Del Regno , Hugo Villeneuve , Haibo Chen , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Subject: Re: [PATCH v7 3/5] iio: adc: max77541: Add ADI MAX77541 ADC Support Message-ID: References: <20230412111256.40013-1-okan.sahin@analog.com> <20230412111256.40013-4-okan.sahin@analog.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230412111256.40013-4-okan.sahin@analog.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 12, 2023 at 02:12:44PM +0300, Okan Sahin wrote: > The MAX77541 has an 8-bit Successive Approximation Register (SAR) ADC > with four multiplexers for supporting the telemetry feature. Reviewed-by: Andy Shevchenko > Signed-off-by: Okan Sahin > Reviewed-by: Jonathan Cameron > --- > drivers/iio/adc/Kconfig | 11 ++ > drivers/iio/adc/Makefile | 1 + > drivers/iio/adc/max77541-adc.c | 194 +++++++++++++++++++++++++++++++++ > 3 files changed, 206 insertions(+) > create mode 100644 drivers/iio/adc/max77541-adc.c > > diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig > index 45af2302be53..518e7bd453aa 100644 > --- a/drivers/iio/adc/Kconfig > +++ b/drivers/iio/adc/Kconfig > @@ -735,6 +735,17 @@ config MAX1363 > To compile this driver as a module, choose M here: the module will be > called max1363. > > +config MAX77541_ADC > + tristate "Analog Devices MAX77541 ADC driver" > + depends on MFD_MAX77541 > + help > + This driver controls a Analog Devices MAX77541 ADC > + via I2C bus. This device has one adc. Say yes here to build > + support for Analog Devices MAX77541 ADC interface. > + > + To compile this driver as a module, choose M here: > + the module will be called max77541-adc. > + > config MAX9611 > tristate "Maxim max9611/max9612 ADC driver" > depends on I2C > diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile > index 36c18177322a..f8433b560c3b 100644 > --- a/drivers/iio/adc/Makefile > +++ b/drivers/iio/adc/Makefile > @@ -67,6 +67,7 @@ obj-$(CONFIG_MAX11205) += max11205.o > obj-$(CONFIG_MAX11410) += max11410.o > obj-$(CONFIG_MAX1241) += max1241.o > obj-$(CONFIG_MAX1363) += max1363.o > +obj-$(CONFIG_MAX77541_ADC) += max77541-adc.o > obj-$(CONFIG_MAX9611) += max9611.o > obj-$(CONFIG_MCP320X) += mcp320x.o > obj-$(CONFIG_MCP3422) += mcp3422.o > diff --git a/drivers/iio/adc/max77541-adc.c b/drivers/iio/adc/max77541-adc.c > new file mode 100644 > index 000000000000..21d024bde16b > --- /dev/null > +++ b/drivers/iio/adc/max77541-adc.c > @@ -0,0 +1,194 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2022 Analog Devices, Inc. > + * ADI MAX77541 ADC Driver with IIO interface > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > + > +enum max77541_adc_range { > + LOW_RANGE, > + MID_RANGE, > + HIGH_RANGE, > +}; > + > +enum max77541_adc_channel { > + MAX77541_ADC_VSYS_V, > + MAX77541_ADC_VOUT1_V, > + MAX77541_ADC_VOUT2_V, > + MAX77541_ADC_TEMP, > +}; > + > +static int max77541_adc_offset(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, > + int *val, int *val2) > +{ > + switch (chan->channel) { > + case MAX77541_ADC_TEMP: > + *val = DIV_ROUND_CLOSEST(ABSOLUTE_ZERO_MILLICELSIUS, 1725); > + return IIO_VAL_INT; > + default: > + return -EINVAL; > + } > +} > + > +static int max77541_adc_scale(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, > + int *val, int *val2) > +{ > + struct regmap **regmap = iio_priv(indio_dev); > + unsigned int reg_val; > + int ret; > + > + switch (chan->channel) { > + case MAX77541_ADC_VSYS_V: > + *val = 25; > + return IIO_VAL_INT; > + case MAX77541_ADC_VOUT1_V: > + case MAX77541_ADC_VOUT2_V: > + ret = regmap_read(*regmap, MAX77541_REG_M2_CFG1, ®_val); > + if (ret) > + return ret; > + > + reg_val = FIELD_GET(MAX77541_BITS_MX_CFG1_RNG, reg_val); > + switch (reg_val) { > + case LOW_RANGE: > + *val = 6; > + *val2 = 250000; > + break; > + case MID_RANGE: > + *val = 12; > + *val2 = 500000; > + break; > + case HIGH_RANGE: > + *val = 25; > + return IIO_VAL_INT; > + default: > + return -EINVAL; > + } > + > + return IIO_VAL_INT_PLUS_MICRO; > + case MAX77541_ADC_TEMP: > + *val = 1725; > + return IIO_VAL_INT; > + default: > + return -EINVAL; > + } > +} > + > +static int max77541_adc_raw(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, > + int *val) > +{ > + struct regmap **regmap = iio_priv(indio_dev); > + int ret; > + > + ret = regmap_read(*regmap, chan->address, val); > + if (ret) > + return ret; > + > + return IIO_VAL_INT; > +} > + > +#define MAX77541_ADC_CHANNEL_V(_channel, _name, _type, _reg) \ > + { \ > + .type = _type, \ > + .indexed = 1, \ > + .channel = _channel, \ > + .address = _reg, \ > + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ > + BIT(IIO_CHAN_INFO_SCALE), \ > + .datasheet_name = _name, \ > + } > + > +#define MAX77541_ADC_CHANNEL_TEMP(_channel, _name, _type, _reg) \ > + { \ > + .type = _type, \ > + .indexed = 1, \ > + .channel = _channel, \ > + .address = _reg, \ > + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ > + BIT(IIO_CHAN_INFO_SCALE) |\ > + BIT(IIO_CHAN_INFO_OFFSET),\ > + .datasheet_name = _name, \ > + } > + > +static const struct iio_chan_spec max77541_adc_channels[] = { > + MAX77541_ADC_CHANNEL_V(MAX77541_ADC_VSYS_V, "vsys_v", IIO_VOLTAGE, > + MAX77541_REG_ADC_DATA_CH1), > + MAX77541_ADC_CHANNEL_V(MAX77541_ADC_VOUT1_V, "vout1_v", IIO_VOLTAGE, > + MAX77541_REG_ADC_DATA_CH2), > + MAX77541_ADC_CHANNEL_V(MAX77541_ADC_VOUT2_V, "vout2_v", IIO_VOLTAGE, > + MAX77541_REG_ADC_DATA_CH3), > + MAX77541_ADC_CHANNEL_TEMP(MAX77541_ADC_TEMP, "temp", IIO_TEMP, > + MAX77541_REG_ADC_DATA_CH6), > +}; > + > +static int max77541_adc_read_raw(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, > + int *val, int *val2, long mask) > +{ > + switch (mask) { > + case IIO_CHAN_INFO_OFFSET: > + return max77541_adc_offset(indio_dev, chan, val, val2); > + case IIO_CHAN_INFO_SCALE: > + return max77541_adc_scale(indio_dev, chan, val, val2); > + case IIO_CHAN_INFO_RAW: > + return max77541_adc_raw(indio_dev, chan, val); > + default: > + return -EINVAL; > + } > +} > + > +static const struct iio_info max77541_adc_info = { > + .read_raw = max77541_adc_read_raw, > +}; > + > +static int max77541_adc_probe(struct platform_device *pdev) > +{ > + struct device *dev = &pdev->dev; > + struct iio_dev *indio_dev; > + struct regmap **regmap; > + > + indio_dev = devm_iio_device_alloc(dev, sizeof(*regmap)); > + if (!indio_dev) > + return -ENOMEM; > + > + regmap = iio_priv(indio_dev); > + > + *regmap = dev_get_regmap(dev->parent, NULL); > + indio_dev->modes = INDIO_DIRECT_MODE; > + > + indio_dev->name = "max77541"; > + indio_dev->info = &max77541_adc_info; > + indio_dev->channels = max77541_adc_channels; > + indio_dev->num_channels = ARRAY_SIZE(max77541_adc_channels); > + > + return devm_iio_device_register(dev, indio_dev); > +} > + > +static const struct platform_device_id max77541_adc_platform_id[] = { > + { "max77541-adc" }, > + { /* sentinel */ } > +}; > +MODULE_DEVICE_TABLE(platform, max77541_adc_platform_id); > + > +static struct platform_driver max77541_adc_driver = { > + .driver = { > + .name = "max77541-adc", > + }, > + .probe = max77541_adc_probe, > + .id_table = max77541_adc_platform_id, > +}; > +module_platform_driver(max77541_adc_driver); > + > +MODULE_AUTHOR("Okan Sahin "); > +MODULE_DESCRIPTION("MAX77541 ADC driver"); > +MODULE_LICENSE("GPL"); > -- > 2.30.2 > -- With Best Regards, Andy Shevchenko