From patchwork Fri Feb 17 15:34:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 58661 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp954192wrn; Fri, 17 Feb 2023 07:40:46 -0800 (PST) X-Google-Smtp-Source: AK7set9DUB76zW8FtKCJonYUmD6bBlW+3dzMJcxEK2dxXxYUzXSDXbF2cSvMD6TKpXHG5A82qeho X-Received: by 2002:a05:6a21:99a5:b0:c6:c0c1:b1fe with SMTP id ve37-20020a056a2199a500b000c6c0c1b1femr12544404pzb.57.1676648446163; Fri, 17 Feb 2023 07:40:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676648446; cv=none; d=google.com; s=arc-20160816; b=Tzps3t9idMKo1wB6VcLhfSTwEH/g/ZRb+GwlZBGUyXmO+Dp6D9dpRAtpFccI2z0g7E HhN8l72Vx2pQqZnuz5C0HnVmKHvAufB/baFgZV7gzw2S1vzFSFOFzrysSS1+remYy3kn TCDB9WxTCmxwphXGpGKW/FBNqcfS18cFemLDRchRbUlN2AZRqwy0GusRk+ynrpMoDpto RadeK3vj4dUEs5m5FJ0ZQekSOeocQogl8BAot0qJFQOIZ+D9dSAyiErutCL4JjTNBgHQ BudxChJLh/g8XN8BNIcifwO7LV/07uNcpZ2knGomWkHaUknz1t1OlVdcSsjYDgwqztiF ijMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=TPq7dANvniDbcU1+TXN1D5BHsJyiJgPU7gcflNsJ4wI=; b=J/fez/EqU9fXdlVCGOnRWJhsFkRq5WHXcyZgY1+DIrKLVcwA2Qo/9B4U3NPr6CN0a7 oR6+v81VpamqRx4x08803oXhKsEPY8HWQixyiBR0gGcqqeGLmbpn5wmx1t7GdiNrUnB5 8pa4Lm3AYCfA2jiyQikqbYGB0R1l8YhKmQIQrsJVyWEXo9N2HAkDvAObN+1b/YvHq1Sh k6E6+OkT1L92miC6ryaBIm2SzunuZclVShVE6KdYsBCIJhV2pROGoq33m6I7Haz7OuL4 qLlYneHBPVYMJ3wWiiCOxoifnVZfVzmNAt0iXQOOofgnGKrXhTWrfgA8WxpRg0GR4nTq 7XuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PlBMRRMP; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o20-20020a635d54000000b004febc1dea83si1420717pgm.55.2023.02.17.07.40.32; Fri, 17 Feb 2023 07:40:46 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=PlBMRRMP; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229714AbjBQPey (ORCPT + 99 others); Fri, 17 Feb 2023 10:34:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbjBQPex (ORCPT ); Fri, 17 Feb 2023 10:34:53 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 085FC6F3CE; Fri, 17 Feb 2023 07:34:52 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id a12so1488554wro.7; Fri, 17 Feb 2023 07:34:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TPq7dANvniDbcU1+TXN1D5BHsJyiJgPU7gcflNsJ4wI=; b=PlBMRRMPbTWSBPRIsBNsWlVarHpYWk6k0xpN4O3s2nD1tssvsA/oSWtHK+IwPq+JMY NZlLKryenwYyIV06+ROuY35hvLmFrXYwmkKSu4XntZfSTQpwyHxB98zmfJ1UfmFs5ga1 iWBsS30/OP7dKhFdATbKXPDPL1uj+MDsSl91CWmNS4ti5kYyp6CsimI5+O9rt3FS6BU6 ri7O1BQMbcoGk5yjbPRrH59wVyagfg723OUgw3fPWpl3VlY4udfvb8oVsJ6hzYmSEREx lDXMEmuqzNCCNW0nx1yDdOUH/lZQQcvU3Mli+JzUJPo0sBmTq7Rym457B+mHb2ssryd4 Egyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TPq7dANvniDbcU1+TXN1D5BHsJyiJgPU7gcflNsJ4wI=; b=GVvcE0bYYufqTYMIvwTk+JtkfpWrTuyvQZfMzdqWlUTnX6FFRd/mLeGUE3mmHSKT5d zBiHxaGErtu7AZbB6he7vhAJipTiaYPt7Vr3hxEnkZH5UX7i0k60Tn7bzTPBO0x2a1k3 cEvKhyIQ30Yt3dFREKrP7f4A6OfNwkzzys3kkneoMryhIStv+1SGXDETdfDXrKwJIRXf 5vdWRqDDuUw/Edjiam6nNvE5rOfQL+aLaF/MPEJktzwbC+eMd+kYAGIxMsU7U8hxqCFu Se3ctdenl6KRsXs6/lNegF5neIFOY0aiHxo2Ch/Ic5rkpsoaGgIzCXiRX4NuWTvXqZR4 M3GQ== X-Gm-Message-State: AO0yUKU4UkQYbOOObt2CzmerraYjrn+4G9kE4OcCC14SzAd7yeKk15Fr f3oijkCHmAVQnp4hjHpytZpJpxqwBxU= X-Received: by 2002:adf:f804:0:b0:2c5:5aef:2759 with SMTP id s4-20020adff804000000b002c55aef2759mr6939823wrp.53.1676648090421; Fri, 17 Feb 2023 07:34:50 -0800 (PST) Received: from localhost (94.197.16.234.threembb.co.uk. [94.197.16.234]) by smtp.gmail.com with ESMTPSA id j13-20020a056000124d00b002c54e26bca5sm4648633wrx.49.2023.02.17.07.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Feb 2023 07:34:50 -0800 (PST) From: Aidan MacDonald To: jic23@kernel.org Cc: wens@csie.org, lars@metafoo.de, andy.shevchenko@gmail.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Cameron Subject: [RESEND PATCH v6 1/2] iio: adc: axp20x_adc: Minor code cleanups Date: Fri, 17 Feb 2023 15:34:03 +0000 Message-Id: <20230217153404.32481-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758093320942371343?= X-GMAIL-MSGID: =?utf-8?q?1758093320942371343?= The code may be clearer if parameters are not re-purposed to hold temporary results like register values, so introduce local variables as necessary to avoid that. Regroup macros based on chip type, and use the FIELD_PREP() macro instead of a hand-rolled version. Suggested-by: Jonathan Cameron Reviewed-by: Chen-Yu Tsai Reviewed-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Signed-off-by: Aidan MacDonald --- This is a resend of a preparatory patch from a larger series adding support for the AXP192 PMIC[1]. Since I don't think there's much hope of getting it merged in one development cycle, there's no point letting these cleanups sit around unapplied -- apply them whenever convienient! [1] https://lore.kernel.org/all/20221016234335.904212-1-aidanmacdonald.0x0@gmail.com/ --- drivers/iio/adc/axp20x_adc.c | 61 +++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/drivers/iio/adc/axp20x_adc.c b/drivers/iio/adc/axp20x_adc.c index 53bf7d4899d2..ab25e6e1ff65 100644 --- a/drivers/iio/adc/axp20x_adc.c +++ b/drivers/iio/adc/axp20x_adc.c @@ -5,6 +5,7 @@ * Quentin Schulz */ +#include #include #include #include @@ -22,20 +23,20 @@ #include #define AXP20X_ADC_EN1_MASK GENMASK(7, 0) - #define AXP20X_ADC_EN2_MASK (GENMASK(3, 2) | BIT(7)) + #define AXP22X_ADC_EN1_MASK (GENMASK(7, 5) | BIT(0)) #define AXP20X_GPIO10_IN_RANGE_GPIO0 BIT(0) #define AXP20X_GPIO10_IN_RANGE_GPIO1 BIT(1) -#define AXP20X_GPIO10_IN_RANGE_GPIO0_VAL(x) ((x) & BIT(0)) -#define AXP20X_GPIO10_IN_RANGE_GPIO1_VAL(x) (((x) & BIT(0)) << 1) #define AXP20X_ADC_RATE_MASK GENMASK(7, 6) -#define AXP813_V_I_ADC_RATE_MASK GENMASK(5, 4) -#define AXP813_ADC_RATE_MASK (AXP20X_ADC_RATE_MASK | AXP813_V_I_ADC_RATE_MASK) #define AXP20X_ADC_RATE_HZ(x) ((ilog2((x) / 25) << 6) & AXP20X_ADC_RATE_MASK) + #define AXP22X_ADC_RATE_HZ(x) ((ilog2((x) / 100) << 6) & AXP20X_ADC_RATE_MASK) + +#define AXP813_V_I_ADC_RATE_MASK GENMASK(5, 4) +#define AXP813_ADC_RATE_MASK (AXP20X_ADC_RATE_MASK | AXP813_V_I_ADC_RATE_MASK) #define AXP813_TS_GPIO0_ADC_RATE_HZ(x) AXP20X_ADC_RATE_HZ(x) #define AXP813_V_I_ADC_RATE_HZ(x) ((ilog2((x) / 100) << 4) & AXP813_V_I_ADC_RATE_MASK) #define AXP813_ADC_RATE_HZ(x) (AXP20X_ADC_RATE_HZ(x) | AXP813_V_I_ADC_RATE_HZ(x)) @@ -234,7 +235,7 @@ static int axp20x_adc_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val) { struct axp20x_adc_iio *info = iio_priv(indio_dev); - int size = 12; + int ret, size; /* * N.B.: Unlike the Chinese datasheets tell, the charging current is @@ -246,10 +247,11 @@ static int axp20x_adc_raw(struct iio_dev *indio_dev, else size = 12; - *val = axp20x_read_variable_width(info->regmap, chan->address, size); - if (*val < 0) - return *val; + ret = axp20x_read_variable_width(info->regmap, chan->address, size); + if (ret < 0) + return ret; + *val = ret; return IIO_VAL_INT; } @@ -257,11 +259,13 @@ static int axp22x_adc_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val) { struct axp20x_adc_iio *info = iio_priv(indio_dev); + int ret; - *val = axp20x_read_variable_width(info->regmap, chan->address, 12); - if (*val < 0) - return *val; + ret = axp20x_read_variable_width(info->regmap, chan->address, 12); + if (ret < 0) + return ret; + *val = ret; return IIO_VAL_INT; } @@ -269,11 +273,13 @@ static int axp813_adc_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val) { struct axp20x_adc_iio *info = iio_priv(indio_dev); + int ret; - *val = axp20x_read_variable_width(info->regmap, chan->address, 12); - if (*val < 0) - return *val; + ret = axp20x_read_variable_width(info->regmap, chan->address, 12); + if (ret < 0) + return ret; + *val = ret; return IIO_VAL_INT; } @@ -443,27 +449,27 @@ static int axp20x_adc_offset_voltage(struct iio_dev *indio_dev, int channel, int *val) { struct axp20x_adc_iio *info = iio_priv(indio_dev); + unsigned int regval; int ret; - ret = regmap_read(info->regmap, AXP20X_GPIO10_IN_RANGE, val); + ret = regmap_read(info->regmap, AXP20X_GPIO10_IN_RANGE, ®val); if (ret < 0) return ret; switch (channel) { case AXP20X_GPIO0_V: - *val &= AXP20X_GPIO10_IN_RANGE_GPIO0; + regval = FIELD_GET(AXP20X_GPIO10_IN_RANGE_GPIO0, regval); break; case AXP20X_GPIO1_V: - *val &= AXP20X_GPIO10_IN_RANGE_GPIO1; + regval = FIELD_GET(AXP20X_GPIO10_IN_RANGE_GPIO1, regval); break; default: return -EINVAL; } - *val = *val ? 700000 : 0; - + *val = regval ? 700000 : 0; return IIO_VAL_INT; } @@ -548,7 +554,7 @@ static int axp20x_write_raw(struct iio_dev *indio_dev, long mask) { struct axp20x_adc_iio *info = iio_priv(indio_dev); - unsigned int reg, regval; + unsigned int regmask, regval; /* * The AXP20X PMIC allows the user to choose between 0V and 0.7V offsets @@ -560,25 +566,22 @@ static int axp20x_write_raw(struct iio_dev *indio_dev, if (val != 0 && val != 700000) return -EINVAL; - val = val ? 1 : 0; - switch (chan->channel) { case AXP20X_GPIO0_V: - reg = AXP20X_GPIO10_IN_RANGE_GPIO0; - regval = AXP20X_GPIO10_IN_RANGE_GPIO0_VAL(val); + regmask = AXP20X_GPIO10_IN_RANGE_GPIO0; + regval = FIELD_PREP(AXP20X_GPIO10_IN_RANGE_GPIO0, !!val); break; case AXP20X_GPIO1_V: - reg = AXP20X_GPIO10_IN_RANGE_GPIO1; - regval = AXP20X_GPIO10_IN_RANGE_GPIO1_VAL(val); + regmask = AXP20X_GPIO10_IN_RANGE_GPIO1; + regval = FIELD_PREP(AXP20X_GPIO10_IN_RANGE_GPIO1, !!val); break; default: return -EINVAL; } - return regmap_update_bits(info->regmap, AXP20X_GPIO10_IN_RANGE, reg, - regval); + return regmap_update_bits(info->regmap, AXP20X_GPIO10_IN_RANGE, regmask, regval); } static const struct iio_info axp20x_adc_iio_info = { From patchwork Fri Feb 17 15:34:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 58662 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp954212wrn; Fri, 17 Feb 2023 07:40:48 -0800 (PST) X-Google-Smtp-Source: AK7set+BjgqKVpMpRxOMFbbD76FEjL+dVz1qHGa40vUf6Seji3kTDUxFjoTnsfyjfawOFfTAVVwn X-Received: by 2002:a05:6a21:9994:b0:bc:a257:5b2a with SMTP id ve20-20020a056a21999400b000bca2575b2amr1376335pzb.31.1676648447763; Fri, 17 Feb 2023 07:40:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676648447; cv=none; d=google.com; s=arc-20160816; b=BEh9FtxWe3mFwRq8/oKd/CMqFsAmq5TqdzZLTA12fGPGn8dXlOt0PpfA5/JImW/669 3U1psN5ZnKuwrUfL2TuqOaJ2vaorSORXBTVH3SzsyZlxb8ROSPFa7yaOOJ/c/OvxDw4r 8w5wWduw+96WQTQx0XyWX/eZf5VaYwXFT0eITjHlSLmoTba1MDTXy007ABAxpZeBLDk3 dlE2jjLwaWPrn0cxut8TzXUiMq9Ps1NPN+hMkSS+YY/gbyyiblkZ3pOL5XXGHPrCDJ3P gt1J3X5eHLZ55YFjjK0bm+y1pEGJ7ZAmqXB1MFJRBgOLPQ31lhmH2XMiG0SSlfqVdM1J mQiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eoAGYS91FVNG59X2nIHtCAzt1nj2bSLTdLXaWRLOUNE=; b=nFayU2E5tQ6OiyPGoEOtUiMMLWrjTreCErrQEd2U09NYJ7iWVl32sj+01+5IPooi+W GYvsKfS16icnWS62xbqJEQ9wt+X+ytARC2RGX4skjHK+ywl9F8dSo1otaj4hoBkJyn/t AyhNA5Jhj2ry4gkFdvXA3rm5vG+fxzI0u5Oz8+zbknUG30ncxytCNHgxlb5ZaRBbPRSs dV4gopxKQzEeifmBrdUxAudtxTCTNdrFWOTE6A8bnyMsg6nv6CuX0hywPIsc2Pv0DH2T SZTXCMEiTUnJMejs3hod6XmfsNd50yM2z7Pe9Ki6vQOcEGxGitUCqLBFEu8uC3K9+qHC rjxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OavKJms6; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v135-20020a63618d000000b004a68aefb7b0si5622708pgb.173.2023.02.17.07.40.34; Fri, 17 Feb 2023 07:40:47 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=OavKJms6; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230262AbjBQPe5 (ORCPT + 99 others); Fri, 17 Feb 2023 10:34:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229745AbjBQPez (ORCPT ); Fri, 17 Feb 2023 10:34:55 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB8A76F3E9; Fri, 17 Feb 2023 07:34:52 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id f19so1211460wml.3; Fri, 17 Feb 2023 07:34:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eoAGYS91FVNG59X2nIHtCAzt1nj2bSLTdLXaWRLOUNE=; b=OavKJms6ALhkrMR1m9fe7oCgVuAoPgsTkYT46lgNtZSUcZzl8bKdOd+ZQq5so5vG6Z nQKU27ewVU8pxf/cGXeoFafzkwbbIHi/S9Uzqv5qcGTst8RmHAiDJ6SWIX0NuDQO1iwG 0LPMVNrW89XKFNa7dubcmjJnx/jsN0ZkJ/WmESBe+auYmqH+pApFUPbmkzf7OupRCBPe f3tTAT+jhgz57d2+BJpOfvHvR9+PI+wlHca8IjZulO/NnGb9MjGknxqWi8S5NwnYhpVS n/xXLSV9a/a8ocgINrB3+l/E1Yi7PHqt/RWaiPWvgzo/g18ESbPRGMgNSEKpTQX6B5e3 BghA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eoAGYS91FVNG59X2nIHtCAzt1nj2bSLTdLXaWRLOUNE=; b=O6QyfXP663O/QUKyg4Em2y0srH2NO693ka7kzvwqET12MEE0IFfeVESIOnhFShpAa/ T177UW6TiqX+wwtNbkqHWZ1K2vE0vylmLqaWfY/z8lbj0MIeSqnIoMYnIUEpwd2uA4sa NFKdjYk/oNEznl8leklUblgKR86/pGnsnI95XOIdPhUv+ofz85TlXfDT61FACqBdPwGB i/lCxyFmMEviKYMr8rDORCpinwGUkV59LXUFKXbhRCJehhHmJjBR2Fo0Wtxod68AGjY3 Dsu7r1Bcu87iCwM2wyNvplDi3ln75/UmqDcgRvkR7bMRQHqQFLAAVpcujKgJnAujZ0OP 6pjw== X-Gm-Message-State: AO0yUKUjeDkvSWMBIv73KRI7klllCtlClQFJPsaTpubW2fe8+4q0iECX 6y7dMM7SJv1HndwEPyM3aA8= X-Received: by 2002:a05:600c:502c:b0:3d1:caf1:3f56 with SMTP id n44-20020a05600c502c00b003d1caf13f56mr5302613wmr.9.1676648091421; Fri, 17 Feb 2023 07:34:51 -0800 (PST) Received: from localhost (94.197.16.234.threembb.co.uk. [94.197.16.234]) by smtp.gmail.com with ESMTPSA id f19-20020a1c6a13000000b003e0238d9101sm5031209wmc.31.2023.02.17.07.34.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Feb 2023 07:34:51 -0800 (PST) From: Aidan MacDonald To: jic23@kernel.org Cc: wens@csie.org, lars@metafoo.de, andy.shevchenko@gmail.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Cameron Subject: [RESEND PATCH v6 2/2] iio: adc: axp20x_adc: Replace adc_en2 flag with adc_en2_mask field Date: Fri, 17 Feb 2023 15:34:04 +0000 Message-Id: <20230217153404.32481-2-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20230217153404.32481-1-aidanmacdonald.0x0@gmail.com> References: <20230217153404.32481-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758093322956934679?= X-GMAIL-MSGID: =?utf-8?q?1758093322956934679?= The adc_en2 flag is essentially specific to axp20x-compatible devices because it hardcodes register values. Replace it with a mask field so the register value can be specified in device match data. Reviewed-by: Andy Shevchenko Reviewed-by: Jonathan Cameron Signed-off-by: Aidan MacDonald --- This is a resend of a preparatory patch from a larger series adding support for the AXP192 PMIC[1]. Since I don't think there's much hope of getting it merged in one development cycle, there's no point letting these cleanups sit around unapplied -- apply them whenever convienient! [1] https://lore.kernel.org/all/20221016234335.904212-1-aidanmacdonald.0x0@gmail.com/ --- drivers/iio/adc/axp20x_adc.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/iio/adc/axp20x_adc.c b/drivers/iio/adc/axp20x_adc.c index ab25e6e1ff65..75bda94dbce1 100644 --- a/drivers/iio/adc/axp20x_adc.c +++ b/drivers/iio/adc/axp20x_adc.c @@ -623,9 +623,9 @@ struct axp_data { int num_channels; struct iio_chan_spec const *channels; unsigned long adc_en1_mask; + unsigned long adc_en2_mask; int (*adc_rate)(struct axp20x_adc_iio *info, int rate); - bool adc_en2; struct iio_map *maps; }; @@ -634,8 +634,8 @@ static const struct axp_data axp20x_data = { .num_channels = ARRAY_SIZE(axp20x_adc_channels), .channels = axp20x_adc_channels, .adc_en1_mask = AXP20X_ADC_EN1_MASK, + .adc_en2_mask = AXP20X_ADC_EN2_MASK, .adc_rate = axp20x_adc_rate, - .adc_en2 = true, .maps = axp20x_maps, }; @@ -645,7 +645,6 @@ static const struct axp_data axp22x_data = { .channels = axp22x_adc_channels, .adc_en1_mask = AXP22X_ADC_EN1_MASK, .adc_rate = axp22x_adc_rate, - .adc_en2 = false, .maps = axp22x_maps, }; @@ -655,7 +654,6 @@ static const struct axp_data axp813_data = { .channels = axp813_adc_channels, .adc_en1_mask = AXP22X_ADC_EN1_MASK, .adc_rate = axp813_adc_rate, - .adc_en2 = false, .maps = axp22x_maps, }; @@ -713,10 +711,10 @@ static int axp20x_probe(struct platform_device *pdev) /* Enable the ADCs on IP */ regmap_write(info->regmap, AXP20X_ADC_EN1, info->data->adc_en1_mask); - if (info->data->adc_en2) - /* Enable GPIO0/1 and internal temperature ADCs */ + if (info->data->adc_en2_mask) regmap_update_bits(info->regmap, AXP20X_ADC_EN2, - AXP20X_ADC_EN2_MASK, AXP20X_ADC_EN2_MASK); + info->data->adc_en2_mask, + info->data->adc_en2_mask); /* Configure ADCs rate */ info->data->adc_rate(info, 100); @@ -741,7 +739,7 @@ static int axp20x_probe(struct platform_device *pdev) fail_map: regmap_write(info->regmap, AXP20X_ADC_EN1, 0); - if (info->data->adc_en2) + if (info->data->adc_en2_mask) regmap_write(info->regmap, AXP20X_ADC_EN2, 0); return ret; @@ -757,7 +755,7 @@ static int axp20x_remove(struct platform_device *pdev) regmap_write(info->regmap, AXP20X_ADC_EN1, 0); - if (info->data->adc_en2) + if (info->data->adc_en2_mask) regmap_write(info->regmap, AXP20X_ADC_EN2, 0); return 0;