From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795961568; b=bVYyhIoDy/4jZin6rOu42GFNe3Zlc1/hfdEsO9+vc2nTXADo2l0cVKJozsVpscHESYkB rhigg91mi6mR8p/sYn/32LQ95phxEcynsyYxTdlFpvHF8GSJ241SeRYj6g4PUTE1/gHCX IXZGeF+C9dZT2jSr6hvl9FqZO+ceV3PQ1RnYZcRCG0nQqR3lebU0UXOmUuso2dbPICDwj OCwkSgTOIy6cOTrmYNEgP1iLl2nGLhIY8jJw5jgrpsSZyzgOkph2Sh0v6aAksrDzWD9Kx BwHxr2RB6l8txaZmSUfmR09fmnbSKsDR6/833py39/y5J7lZC4dOVtSOUb5+zehLtAQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795961568; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:Message-ID: Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:X-Proofpoint-ORIG-GUID:X-Proofpoint-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Spam-Info: X-Authority-Analysis:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=0+gjw3hiXU15mERUgiThvnJCghcyT1trUrI1Bjby998=; b=PcbWO0kiWpJGG2YGLATXpEN3rcYeId109NmZYrGAslAudUL9k/cJssiIvUk4BkQvZ4dx EJgnliv6MPLIs8WOniqN1PYSg5b5VlFZY8vj/tRJr/fr0mx1PqVBtw1mnlyXEa5O27Z6c aeozgNQ0QVyxnOGhhDMg7bTbvfTiQb2MDT/nePKNkkETY9NY1gWIR+tEAW81zNUmBwY32 u8XntDt6u4AYt2L3xtELQMlFgkHLYT1WdYMEikfth+Sa9JIzs8gLY05/L9iTe8emk5e8k GOwCncORE5HYH4wq3rLraDc2IQRDaZVqgrksWcbH4YrB1oWtUbqW6GPEmrqeCi6P94w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=Rrp9nYG0; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=MfdmLq8P; arc=none smtp.remote-ip=205.220.168.131 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 845F4606A32F for ; Sun, 29 Nov 2026 14:12:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 845F4606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=Rrp9nYG0; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=MfdmLq8P Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6ATALveR1885897 for ; Sun, 29 Nov 2026 14:12:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 0+gjw3hiXU15mERUgiThvnJCghcyT1trUrI1Bjby998=; b=Rrp9nYG0IvV9RXrJ 1EJEotNGdnZNw7XwUny1EmyCRT1sqHwrv92NTvEAuik75irK8pU9UpRNZtqdkW0y tQw3nVimEGkLerdQR5ByHfrv4ADJRXFOXNqCbqOlgH2crAAViacqMu8q4Dg4J0Lf JfU7+uXJVxqIAKnOffBqtXGm8safc09gpC9GsRV93b6hqzTBk3DrAlzAfju4r5R1 lycM1sHLP1N6Bb/P8mLe0akBRfUljtnxQGMxuEg4r3Xbi9PUKOlJbQrAC/xP6TWA 1TnMAFyg/K9eWj+d7LBWMrxTnZwelSlTEETy1TSUij0Sdry8vLNDf5eOYiEwAY1K XPKiXg== Received: from mail-dy1-f198.google.com (mail-dy1-f198.google.com [74.125.82.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j7r4jawh8-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Sun, 29 Nov 2026 14:12:46 +0000 (GMT) Received: by mail-dy1-f198.google.com with SMTP id 5a478bee46e88-386b8624cf7so1850492eec.1 for ; Sun, 29 Nov 2026 06:12:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1795961566; x=1796566366; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0+gjw3hiXU15mERUgiThvnJCghcyT1trUrI1Bjby998=; b=MfdmLq8PQUirvojr1xs4Ht4go/ABd5p7h8rDHApJNx5FjXHJxgAxhHasXsiqcTXMDA CzrNTiMX0eV1pK9tZ2Yb1Reb+BCPgZsxO6P6efKoAf6Zgod2fwULqzGEme7SnTu2FGMR ZUpmAHuYWlwfHvjLlya6YUKWNy9IUOfLr2Q6GDcD3Qhvn/EfW/VUZIPLbdc0kAEsh0jh X9fqCIMB/Kt/Gt1o9066JWRoIm9hsgKLDsvXLa4cNY2jNA2HVsaFP8+HChxTMBZX9wtC ZbJViz21Ki124omZaVxUHYDUZ0uA8gkpTm8RGxh77hmqV+ZxDG0j2wVfoapvhMPxPjss zOCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795961566; x=1796566366; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0+gjw3hiXU15mERUgiThvnJCghcyT1trUrI1Bjby998=; b=M7gJUKjQM+zUaLhoJNave0iyqn4YKn9CotWHfW66ckRd8DIJnyGHBNxTvfZTgU7PR3 iPNohvhsd41eGeYMRxeAKvHD+nbjzva6CFzdxqYl1AuN7qL0jIzboTWY5LeN76Eq3GXE H+LyCuRemcEMtUjC2xzW/itrh1sIr/e5HlOcuE2j/pG1s69q8VgBROyRgHZjSgH39tLU NnKNWoxMiRFT0uBAdnGFr9bd7IiZeE2HdIxkzpFjUm5t1TmE1/OBAXLOifzUWaMzQVuz CYEWc/okO3VlV4exaQRQsFZF39yMZrjkO30HNR6xz+Mv//M/uRjecQZnT4SUsztbuGwH GoJQ== X-Forwarded-Encrypted: i=1; AL+hErFXIaqELT6UlCYPHNFnksd+igYm4umtPtEhMIy5Or7nb5bZ2cA9G3FVa41LtKFomeM07kTXGfknHHWpzX8=@vger.kernel.org X-Gm-Message-State: APuU4Z9BRFumLZ2QXYpD6mKSXLOTlgG78YHcrrtas/vMX3if/kBxyIfg azJy0T+6u/ykU6ouOPbKTg5e/nRlQNiNUtbNumCgYz2qIeTzkQ+ocW2mDMemcOTTHh3C+ArE5wY WPaOazXhjFrHlxxAdqclOEj8ShMhfQxUvohjpoJ1jyr2Y8lzaQcY7I3zTsw2a/6T2W4w= X-Gm-Gg: AZFdTZdDutv1WNLnDpRYUYkl4uDzOprskbhVWtWBi2lVuUoYYzhfnImdLK7b92aN1yi SmSqldpOx8jEh+1nHFGH/ZTOwIuMsWAblTjjBAk6n6mjd7bTNMfUE6eQYJRKoHIL21gwyOyCtA/ 3FnFFqPtTs7fvWBbkii162cnkUeF2CCPfv2rEcFXQhr3Srb+czbGec8nstQG9G5yOJUCBzwAp9c dxeOYqkT9bmRHP/Fx+KSqBEXSQqG3vZ4Jdez3bJrJ1yQespzz3tY/0EIGxkLa6kHS4CQUMkHc8c r5e1Yr74ocjfpaAb1ieH1hVB/b6d534LRPnbFWGVmpuJexhq3dl3LOcfXXaQXpmJMAYUd/eRHqW sLvcA2dZmmwe7HKWAqV+hkGlYhCqDJ3I+2/AlsRSJ3N+zDcmNlU3xBZE2gFDHt+yW2AhCcfoId2 EcjvWMVo8A X-Received: by 2002:a05:7301:f10:b0:386:3817:354e with SMTP id 5a478bee46e88-386381738e6mr26438308eec.9.1795961565882; Sun, 29 Nov 2026 06:12:45 -0800 (PST) X-Received: by 2002:a05:7301:f10:b0:386:3817:354e with SMTP id 5a478bee46e88-386381738e6mr26438282eec.9.1795961565343; Sun, 29 Nov 2026 06:12:45 -0800 (PST) Received: from [192.168.1.102] ([157.48.135.242]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385666e7fc3sm80684344eec.8.2026.11.29.06.12.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 Nov 2026 06:12:44 -0800 (PST) Message-ID: <53554280-019f-4dc7-b592-5915cfd06c97@oss.qualcomm.com> Date: Sun, 29 Nov 2026 19:42:34 +0530 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 3/7] iio: adc: qcom-spmi-adc5-gen3: Add support for QCOM PMIC5 Gen4 ADC To: Jonathan Cameron , Conor Dooley Cc: David Lechner , =?UTF-8?Q?Nuno_S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Amit Kucheria , Thara Gopinath , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, Kamal Wadhwa , Anjelique Melendez , Manaf Meethalavalappu Pallikunhi , Priyansh Jain References: <20261120-pmic5_gen4_adc-v2-0-94d0e1fd6847@oss.qualcomm.com> <20261120-pmic5_gen4_adc-v2-3-94d0e1fd6847@oss.qualcomm.com> <20261121205804.382bdb91@jic23-hlaptop> Content-Language: en-US From: Jishnu Prakash In-Reply-To: <20261121205804.382bdb91@jic23-hlaptop> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Proofpoint-ORIG-GUID: jhHdnjFgVXpuPprY8CKFlYQuGKzEXy9g X-Proofpoint-GUID: jhHdnjFgVXpuPprY8CKFlYQuGKzEXy9g X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTI5MDA1NiBTYWx0ZWRfX1OCBbgH0Ge86 cYCCrNtWpL5vk7NMuCUEHI3+N2cMMCWPJEh0bkai50m2vJh6eKKbIPu47EgEOLJRX7TCdFlpGqs L73GGCy+TPvY1+JsxJdmXEYS3tHAnwg/dHU4dP2d7Gm74Egega6xmBoKZA/TmMv4kU80qT+OjvD wLKD1ULAc9BtwjaTHKORvgvjt3ThDfhnvR+LjRbLbBfc+zcMCjAwYktFWTPSSIUU7aSxkrin0Dx 9ujh09nQdtDZs+ptZC9Ian3xd0dnGwWUpRW6RC7C6prAf+sx1p28PKfc97wGkcxiTlV+d3uVFbd JJI3GrIsHZNzzsdfl8Ygc9LRzpKDEs/2wsYMfvRMrx7rZ3t1tnqg7L5oPmNquYX5DYaP6i2NsIb vyx6dOuE6nCNfsSVJheXcFXukpILku1G5/fS3Kazwpfg3XPyUTnoAdaHtZvDW2aDFu4/tdIAJAO Mcl6gaB9KLx63ZxwOAA== X-Proofpoint-Spam-Info: AW1haW4tMjYxMTI5MDA1NiBTYWx0ZWRfX+D6QhphmEkch WLZSJVNT37ZNhhggPzzx2I/yuE5HAbsklSC5EJkBsDukPfj1OXBmGRYDuui2CxLeNulW/6W24do WopGSDm6Cb37LC1eau6oe0WtXjVW9Kw= X-Authority-Analysis: v=2.4 cv=Mdr5KJ/f c=1 sm=1 tr=0 ts=6b0c32de cx=c_pps a=wEP8DlPgTf/vqF+yE6f9lg==:117 a=nc1psVOndk8T/X+6wm4l9g==:17 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=EUspDBNiAAAA:8 a=M1wqZkrtfuGyWKx3LWkA:9 a=QEXdDO2ut3YA:10 a=bBxd6f-gb0O0v-kibOvt:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-29_03,2026-11-27_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 adultscore=0 malwarescore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 spamscore=0 bulkscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611290056 Hi Jonathan, On 11/22/2026 2:28 AM, Jonathan Cameron wrote: > On Fri, 20 Nov 2026 14:49:43 +0530 > Jishnu Prakash wrote: > >> PMIC5 Gen4 ADC is similar to PMIC5 Gen3 ADC, with several changes made >> for improved performance, mostly at the hardware level. >> ... >> + u16 *data) >> { >> u8 rslt[2]; >> int ret; >> @@ -98,9 +100,11 @@ static int adc5_gen3_read_voltage_data(struct adc5_chip *adc, u16 *data) >> >> *data = get_unaligned_le16(rslt); >> >> - if (*data == ADC5_USR_DATA_CHECK) { >> - dev_err(adc->dev, "Invalid data:%#x\n", *data); >> - return -EINVAL; >> + if (!(prop->generation == ADC5_GEN4 && prop->cal_method == ADC5_RATIOMETRIC_CAL)) { > > See below. I would not expect to see generation (so an enum ID type field( > as well as a structure representing the differences in hardware. > > Add something to the prop->data structure to represent this difference. > bool no_datacheck_with_ratcal > or something like that. > > Or can you derive this from other data already in there? I think we can derive this from other data, with a change we can make to eliminate the "generation" variable. I'll give more details of this change in replies below. > >> + if (*data == ADC5_USR_DATA_CHECK) { >> + dev_err(adc->dev, "Invalid data:%#x\n", *data); >> + return -EINVAL; >> + } >> } >> >> dev_dbg(adc->dev, "voltage raw code:%#x\n", *data); >> @@ -131,8 +135,9 @@ static int adc5_gen3_configure(struct adc5_chip *adc, >> if (ret) >> return ret; >> >> - /* Write SID */ >> - buf[0] = FIELD_PREP(ADC5_GEN3_SID_MASK, prop->sid); >> + /* Write SID and bus_id*/ >> + buf[0] = FIELD_PREP(ADC5_GEN4_BUS_INDEX_MASK, prop->bus_index) | >> + FIELD_PREP(ADC5_GEN4_SID_MASK, prop->sid); > > Similar to below. You are using the fact the SID_MASKS are the same > here but the defines don't enforce that. Simple change to make > one macro for the mask defined in terms of the other one and lock > in that relationship. > >> >> /* >> * Use channel 0 by default for immediate conversion and to indicate >> @@ -268,7 +273,7 @@ static int adc5_gen3_do_conversion(struct adc5_chip *adc, >> return -ETIMEDOUT; >> } >> >> - ret = adc5_gen3_read_voltage_data(adc, data_volt); >> + ret = adc5_gen3_read_voltage_data(adc, prop, data_volt); >> if (ret) >> return ret; >> >> @@ -325,7 +330,7 @@ static int adc5_gen3_fwnode_xlate(struct iio_dev *indio_dev, >> int i, v_channel; >> >> for (i = 0; i < adc->nchannels; i++) { >> - v_channel = ADC5_GEN3_V_CHAN(adc->chan_props[i].common_props); >> + v_channel = ADC5_GEN4_V_CHAN(adc->chan_props[i].common_props); > > Maybe should include a change to the ADC5_GEN3_V_CHAN() macro to be > defined in terms of the GEN4 one as might make it more obvious why > this change is fine. Also the masks that are the same and hence allow > that lack of differentiation between the two. As you mentioned in patch 5, I'll ignore this and the comment above as I'm removing the GEN3 virtual channel macros in patch 5. > >> if (v_channel == iiospec->args[0]) >> return i; >> } >> @@ -351,7 +356,7 @@ static int adc5_gen3_read_raw(struct iio_dev *indio_dev, >> return ret; >> >> ret = qcom_adc5_hw_scale(prop->scale_fn_type, prop->prescale, >> - adc->data, adc_code_volt, val); >> + prop->data, adc_code_volt, val); >> if (ret) >> return ret; >> > >> +static const struct adc5_data adc5_gen3_data_pmic = { >> + .full_scale_code_volt = 0x70e4, >> + .adc_chans = adc5_gen3_chans_pmic, >> + .info = &adc5_gen3_info, >> + .decimation = (unsigned int [ADC5_DECIMATION_SAMPLES_MAX]) >> + { 85, 340, 1360 }, > > See below. I'd expect the default decimation to be in here as well. > >> + .hw_settle_1 = (unsigned int [VADC_HW_SETTLE_SAMPLES_MAX]) >> + { 15, 100, 200, 300, >> + 400, 500, 600, 700, >> + 1000, 2000, 4000, 8000, >> + 16000, 32000, 64000, 128000 }, >> +}; >> + >> +static const struct adc5_data adc5_gen4_data_pmic = { >> + .full_scale_code_volt = 0x70e4, >> + .adc_chans = adc5_gen4_chans_pmic, >> + .info = &adc5_gen3_info, >> + .decimation = (unsigned int [ADC5_DECIMATION_SAMPLES_MAX]) >> + { 85, 340, 1360 }, >> + .hw_settle_1 = (unsigned int [VADC_HW_SETTLE_SAMPLES_MAX]) >> + { 15, 100, 200, 300, >> + 400, 500, 600, 700, >> + 1000, 2000, 4000, 8000, >> + 16000, 32000, 64000, 128000 }, >> +}; >> + >> static int adc5_gen3_get_fw_channel_data(struct adc5_chip *adc, >> struct adc5_channel_prop *prop, >> struct fwnode_handle *fwnode) >> { >> const char *name = fwnode_get_name(fwnode); >> - const struct adc5_data *data = adc->data; >> + const struct adc5_data *data; >> + u32 chan, value, sid, bus_index; >> struct device *dev = adc->dev; >> const char *channel_name; >> - u32 chan, value, sid; >> u32 varr[2]; >> int ret; >> >> @@ -452,27 +502,42 @@ static int adc5_gen3_get_fw_channel_data(struct adc5_chip *adc, >> >> /* >> * Value read from "reg" is virtual channel number >> - * virtual channel number = sid << 8 | channel number >> + * virtual channel number = bus index << 13 | sid << 8 | channel number >> + * For ADC5 GEN3 channels, bus index = 0 >> */ >> - sid = FIELD_GET(ADC5_GEN3_VIRTUAL_SID_MASK, chan); >> - chan = FIELD_GET(ADC5_GEN3_CHANNEL_MASK, chan); >> + bus_index = FIELD_GET(ADC5_GEN4_V_CHAN_BUS_INDEX_MASK, chan); >> + sid = FIELD_GET(ADC5_GEN4_V_CHAN_SID_MASK, chan); >> + chan = FIELD_GET(ADC5_GEN4_V_CHAN_CHANNEL_MASK, chan); >> >> if (chan >= ADC5_MAX_CHANNEL) >> return dev_err_probe(dev, -EINVAL, >> "%s invalid channel number %d\n", >> name, chan); >> >> + prop->common_props.bus_index = bus_index; >> prop->common_props.channel = chan; >> prop->common_props.sid = sid; >> >> - if (!adc->data->adc_chans[chan].info_mask) >> + if (fwnode_property_read_bool(fwnode, "qcom,adc5-gen4")) { >> + prop->common_props.generation = ADC5_GEN4; > > See below. That generation enum is a thing that makes me wonder > if they generalization is being handled as it should be. > >> + data = &adc5_gen4_data_pmic; >> + } else { >> + prop->common_props.generation = ADC5_GEN3; >> + data = &adc5_gen3_data_pmic; >> + } >> + prop->common_props.data = data; >> + >> + if (!data->adc_chans[chan].info_mask) >> return dev_err_probe(dev, -EINVAL, "Channel %#x not supported\n", chan); >> >> channel_name = name; >> fwnode_property_read_string(fwnode, "label", &channel_name); >> prop->common_props.label = channel_name; >> >> - value = data->decimation[ADC5_DECIMATION_DEFAULT]; >> + if (prop->common_props.generation == ADC5_GEN3) >> + value = data->decimation[ADC5_DECIMATION_DEFAULT]; >> + else >> + value = data->decimation[ADC5_GEN4_DECIMATION_DEFAULT]; > > I'm confused. I thought data was a structure that differentiated > between GEN4 and GEN5 PMIC supplied channels. If so why are both > decimation values in there? If both generations support same options > but the default has changed, add a default value to the data and this > becomes > > value = data->decimation[data->default_decimation]; > > That will mean updating the other adc5 drivers I think, but should be > fairly trivial and puts the values where they should be rather than > in defines at top of files. Yes, I can add a fix change to update the struct adc5_data to add default_decimation. > > >> fwnode_property_read_u32(fwnode, "qcom,decimation", &value); >> ret = qcom_adc5_decimation_from_dt(value, data->decimation); >> if (ret < 0) >> @@ -480,7 +545,7 @@ static int adc5_gen3_get_fw_channel_data(struct adc5_chip *adc, >> chan, value); >> prop->common_props.decimation = ret; >> >> - prop->common_props.prescale = adc->data->adc_chans[chan].prescale_index; >> + prop->common_props.prescale = data->adc_chans[chan].prescale_index; > > This could be a precursor change to use local data variable consistently in > this function. Perhaps it isn't wroth it though. > >> ret = fwnode_property_read_u32_array(fwnode, "qcom,pre-scaling", varr, 2); >> if (!ret) { >> ret = qcom_adc5_prescaling_from_dt(varr[0], varr[1]); >> @@ -526,19 +591,6 @@ static int adc5_gen3_get_fw_channel_data(struct adc5_chip *adc, >> return 0; >> } > >> diff --git a/include/linux/iio/adc/qcom-adc5-gen3-common.h b/include/linux/iio/adc/qcom-adc5-gen3-common.h >> index ec7238e93396..fa7e08d67f26 100644 >> --- a/include/linux/iio/adc/qcom-adc5-gen3-common.h >> +++ b/include/linux/iio/adc/qcom-adc5-gen3-common.h > >> @@ -117,6 +148,11 @@ enum adc5_time_select { >> MEAS_INT_NONE, >> }; >> >> +enum adc_generation { >> + ADC5_GEN3, >> + ADC5_GEN4, >> +}; > See below. Seeing an enum for variants is often a sign something > is less than ideal in how a driver had been made to deal with more > than one variant. It is too inflexible - much better to just > have one place where you describe what the actual differences are. > Then when GEN5-10 turn up you can avoid lots of inline code > changes to match on particular generations. We internally had a fix change adding a field to struct adc5_data for full scale raw code, which is the same for all ADC generations except Gen4. I think we could use that to distinguish Gen4 from Gen3 at most of the required places. I had a doubt initially if it was fine to modify struct adc5_data and older drivers using it as the fix change did, so I stuck with using the "generation" variable here. But since you have asked me to effectively do the same with default_decimation, I'll combine it with the fix change to add this raw code field to struct adc5_data and I'll also remove the "generation" variable and its enum. Thanks, Jishnu > >> + >> /** >> * struct adc5_sdam_data - data per SDAM allocated for adc usage >> * @base_addr: base address for the ADC SDAM peripheral. >> @@ -155,6 +191,9 @@ struct adc5_device_data { >> * that is an average of multiple measurements. >> * @scale_fn_type: Represents the scaling function to convert voltage >> * physical units desired by the client for the channel. >> + * @generation: Generation of the ADC HW of the channel. >> + * @bus_index: SPMI bus index of PMIC owning the channel. >> + * @data: top-level ADC data structure. >> */ >> struct adc5_channel_common_prop { >> unsigned int channel; >> @@ -166,6 +205,9 @@ struct adc5_channel_common_prop { >> unsigned int hw_settle_time_us; >> unsigned int avg_samples; >> enum vadc_scale_fn_type scale_fn_type; >> + enum adc_generation generation; >> + unsigned int bus_index; >> + const struct adc5_data *data; > > Having both generation and data in here suggests to me > that we have multiple sources of data for generation specific stuff. > See above. > >> }; > >