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=rJ0gYR9IV2YkSCrH7ShFqXcg0LESOIMvZZ65tWyPNDw8u1tjkmIIz/JVqfJgUyw+0t09 AboCib657nQ+pRP5hwDlviJ2xHxiehw/EPB6M4Ui6Ts1TGgOU5Y6+knWe3wege8x2PfV7 mIIWs1bgxoL+FhXBCZ8AHblBql3VE+8DDPfGxH40wyBrCSbmvhIRNbKNX6ORRPvAiPV9w wUQUGAtZ/V4IE3f3adoZ7f0VU6n8Pi9nasBvznUuDM3tac3QEjjxPt+8U4p8abbPA+ck4 wMdNjHW+7au0vmeEfs4IS3BV/ekKuH0GBcWeYpjwaMcVsznI0o6o0nK2y9f3Mq2KNLw== 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-GUID:X-Authority-Analysis: X-Proofpoint-ORIG-GUID:X-Proofpoint-Spam-Details-Enc: X-Proofpoint-Spam-Info:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=0+gjw3hiXU15mERUgiThvnJCghcyT1trUrI1Bjby998=; b=2AU+VlIOYMNrTTpAU3481Sv1XutpHYy+/zG/9e0PMKF/uHTukjNJn4EvQiUSjKOYNERS BFtx+loQsjRJuiligU+ZIHiAkBGWPBxi6tD6sJE+SfnNWSsdklGwNoEol1OBdvR7azbdW uE60jHPADr4rv2i+KwohEkkGpV5Vz2VhKpK5i6lDhaexcY3KNj+wAluZUgWEYoqtsK/iD HTQKOOwF7m1ct1QpcYfZpCZXc0qRz0E6IwvwuJ6B/k0otN64Sp+83L+bklQ3ORA0CbAA/ /mChisi9ZH1ZVm9QxVnpQUUrwN5tbTXXGUNGXZeNxnARHk/d4E3EzDGpzAXC+380eJg== 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 8469D606A332 for ; Sun, 29 Nov 2026 14:12:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8469D606A332 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 (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6ATALLlc3020542 for ; Sun, 29 Nov 2026 14:12:47 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-f197.google.com (mail-dy1-f197.google.com [74.125.82.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j7qqek0nb-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-f197.google.com with SMTP id 5a478bee46e88-386ad819860so1788785eec.0 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=OU+beZSf9RZsOhmbBPxfMpa1z+ht4Whqir04le0aCHcoCOqdS3iJeXnMtOnCPJ7aPw X+QHLTBFDh1d1NxEW9hWclDvnIQMwJUzxV8d/bAUU1V1Y4Eph17VsvCLg0zX2/ANEWh9 5sLdXtDQ8tLylWATXOhE4Tnuy1Po9pr+rV3QTaT4eSq/FamUFYvUYLjVwb3QhdHIikvg MD2CtSq2bgjkk9F1y03zwkmvBiFqM48MOK5PqcAoOabKwcSnWRfrsi3+UlodcM7s2Dk3 tI14+b0RfPCxzkvY2mI+h9ja8y6Cm5UtzwrhrTlF01ixS4tDaQ59RsPDauU76HytNvkG hx8A== X-Forwarded-Encrypted: i=1; AL+hErFX1Naj7bQo6l+1ktbEctHlZA37alYgKWH3WO9DLm89QRAPrYzaJFY6WHeB7WpTA18p/OlxyC5zvQ==@vger.kernel.org X-Gm-Message-State: APuU4Z+9QDEsS56j4PIBlFxXKRrC4YaZJoQxqx9vbrVthIUMHl/320cv s553J1lRStTj0McSpk0Ckew9PCxJDR7rwginLGKUo7iPwACVnmL9vZXdmQV74HIbfo8MZJFu4vk GUL7zWphlPG/zPpqzBgdi7siKPdjo3c98sD/+c4LmHtT544uxASRji9HBaZwcVQ== X-Gm-Gg: AZFdTZdSlaE2OR42cJax5oIFx6PV6FGFi8z2oJmSElrPb5aheKvueHZCs7/PRZtjJIz 1bzdUNXvvcg/wR6aMWSZKie/TnwiNItmRG4pkOT1nDjnjEekXf6T70sef/2gXC2AjzZeUUFSquL tE0LX+U4b4EUE7N4w+uyUdlS/IISOYpkDo2bbivj8tgzFYIVHmMiHYNHjEBMRRsRzTqPOwtF2yR gR6f9caof8tv6zfS8h5m/wYJr+7F1NUtsF50AG+aNmO2NdyYbzPnJhtXnpgMGhpQMoAIBghtaIA 7dN63M/pSQY/dcDg4Q1MblnFkt/0B+wV5Pp0EY9995KerTbKynfqCI2RvFqfdFogehQ8kbgJKG2 j7oy7VxVwWika8MPDeQGYI/GyKznqcyrzzjv7ogPqXYkyy8ITvsntU1Dl6M3XAh0OTVV3yDct9q osr3FxtQj6 X-Received: by 2002:a05:7301:f10:b0:386:3817:354e with SMTP id 5a478bee46e88-386381738e6mr26438322eec.9.1795961565909; 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-pm@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-GUID: q8mh-Gv5vYHU3gVK4bsVt4GisX36W1BS X-Authority-Analysis: v=2.4 cv=Uv/2pOwB c=1 sm=1 tr=0 ts=6b0c32de cx=c_pps a=Uww141gWH0fZj/3QKPojxA==: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=_K5XuSEh1TEqbUxoQ0s3:22 a=EUspDBNiAAAA:8 a=M1wqZkrtfuGyWKx3LWkA:9 a=QEXdDO2ut3YA:10 a=PxkB5W3o20Ba91AHUih5:22 X-Proofpoint-ORIG-GUID: q8mh-Gv5vYHU3gVK4bsVt4GisX36W1BS X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTI5MDA1NiBTYWx0ZWRfXyYFUmXqWTD2J NouOxT3mkdFBewAzhm2JkwdT1CR4eUWUpQ3c54vd7E45IVuMnphwhJvlY2FMu9DzVNJHhDRqmH4 S/NE9nwbNENLyMqX0xCnfRSOTM7t+L5QzhMwfry0i+ETPe3eLYW+ZMRLdhrYQuMpjNj6nf6musL gS5ZvvPsW/Y9xrLhIcYRF6gp6WDAYN0rxSTUqG5R0dEN0Ym1hTwyBqnRGFj/SMkzzmrqYY+0ltB JWQ9RYlBUcPVnmVc563gBZ4fGLlFdqCQ8xMEqz8C4IJRYwz77mvMX6kJ8E8RbyzU62G2IebHyxu 4tja5LIT80d4B8x8ND9KXqjFR2a5OItBLlTg1nzM9UaryQKt2vWlYk+lnvk63qrFS3qvlLDiMck jXvlksJlyQIb6veWgH4S4rNaShW4WQp+I09Py/psv/58ELusZI2OXNWFO8VVFw5r2j9dkrldAyv 6Uc39cgUCSqWMKHAIQA== X-Proofpoint-Spam-Info: AW1haW4tMjYxMTI5MDA1NiBTYWx0ZWRfX1sh0JTGCWel4 nCmdtViR3RrlYppK5EQYkLH3nUrxBUixGJD/pVoxJiZOaV/S572J6oBELvwTnqcIY1kcE8OkUQH LEic0UoEZR9iiTcH7J2BvEep3apuAYw= 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 adultscore=0 spamscore=0 clxscore=1015 malwarescore=0 bulkscore=0 phishscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=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. > >> }; > >