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=CrlEagmSglUWp1Zn6A60gRgh27hIs1o0x5n43q8yw/HCelis42NRBaw07r2FAc+TXEQI 7QuuaJN5n19sJW4S0OW90NE8p5sHeYQxPoBkl2I67onW6/WkrxHXYjIAjhMIXUyJ28o25 wrQZ1XQjgkaGIVkoDrMWuNnkUYJhgpjfQaQdhcApkcTaYq5OI1kaMTZzx7P8Im3L9Rx6r JKcEPRUo/hi4kKmwXUTAuDYVeUg/OEyt7m07xUzo4Rly54bYGSSPwaYx0XDnGj6GZ+Fp2 JfyvPFHDpcIlGSJw6XdnQlcH8y4govwVPtHiVojZ6hUWYETG1Ye7mQit5e0SCjaJvkw== 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-Spam-Details-Enc: X-Proofpoint-GUID:X-Proofpoint-Spam-Info:X-Proofpoint-ORIG-GUID: X-Authority-Analysis:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=0+gjw3hiXU15mERUgiThvnJCghcyT1trUrI1Bjby998=; b=X+qUcdfmX2ciGgLfzY3K7Au8Tu2NqxDo8+ERd/BcWDKqvltgttwTAmxE29n1ndiTuu0a lcpVGHXoNdBL0KqM1wj3QOPIB1gPYRubQy4ptJg3rJx1rScdzd3b2a9HDnGh9G2QJOBnN WFnVCRREL6TSBWiQ4L/NyeE/57LTjreEsbqmVqI7K6wElLYCVyl4LV/U7hlWbeb3Lg6xE F8Atz2VlE+jZ5ey/G7ltnDLEm6vhz/NHNKYwRXQ/47JZ8Ia7gCJXGhAv3jYG3UDzZVM+u NkjrGAGLsdhM2rzR0U5Bq+wyGaebluUrR3rM9qu5CujupBCblAhYwDZcGRkCq8alRNQ== 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 84635606A330 for ; Sun, 29 Nov 2026 14:12:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 84635606A330 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 (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6ATALCK13907473 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-f200.google.com (mail-dy1-f200.google.com [74.125.82.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j7nwsua37-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-f200.google.com with SMTP id 5a478bee46e88-386b8624cf7so1850506eec.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=vgI78CBWsf3Lfon3BR3LupqZBI8X2LBY9qFu5oKQ99Th+0KHj2PZAje/VRYEUmVC2U pD9xUbj9nYGtRiStb72oMlIQP1sped+qZbRMPi+r6SVemuopEZObxBsHSCnbEkPv0MXC qlo8feiXMSoTdMsgJZ43ep6QNzA5FLioU13ZDt8Xi/DPsGsMY9KTfiVQATMHFmfWdoDB 4Wx7+uy1IPWYTvqc/qkx+818L947HtksKo/GupJUtMLxdW+x1gjX/nr4WlL5QXdHEV5X VIduaBAIyzuCRvQcySHaH8yMVtrKSA3Cf7rE0G9NbT+tA9A6ak9/7vMcyuguDNuHHo0P S5vQ== X-Forwarded-Encrypted: i=1; AL+hErEmLxUiXualWwfAWSTcEkrGmw7n2lDpHg1P7M++z5D2aZthA5ktjL6DwzTse9A5ukX39Z54Jiuw4Vfj@vger.kernel.org X-Gm-Message-State: APuU4Z9wSh8NjxDwKTPTZD4Zs/+ClQeJxtb6IN+9B7UxEjD6Ob8EHQCk u1INMwNem6vMthh1kdCl4h+/mS7fhWXD5xTK6Ks71Hoj1mW8KY2WXZZAB4IJsf2qfKOxH/tUWIH vSQPnwJUad0IbcbIBnzkthJ3z/7BbXEVv+3ifMnknahNjmfur3d4WHHPrC8nhNLlu X-Gm-Gg: AZFdTZfkc4uG7/2Ru9U3p3dvFfXd92oqi+rAPC/XbM1nzl0sTj4HoxyjPsbZiuhw8j5 h/GixxQ0ZBUFa4gGqs8WQlHGsnQlkI6VqkQ1/DGm9x/N7a8CxzJrJ9ZBdQruInFbdH2Pm0q8qhV wjFIWZMzVbYtvDI+MWxjQrL85TEJu4RiLP/t5cbFt+n05wX0QXK/mIJAZtTnJ4xPBHHSiSS5QfA UEalV9I8xEnpfrDl5tU2XdtDOf2qdy5HZ7pp1goDr07+I/jJ5CotZ63gVUr7rZdxYMxoNbfAJqj Gr0Rt94ymUoWI9CAzVq6MGyF9aH+JcNZB25vtTTNu+uDnKLNUPVhNUH8VRevP3C5NLXlMlzwiX5 B53vNkwwjWhVbinO/XuzGj/CgkNTLYhvlQPbf8cONu+Qjj9wSQI1apNUy+LEo444RFnkkp2gN4X LArWDc8Q0S X-Received: by 2002:a05:7301:f10:b0:386:3817:354e with SMTP id 5a478bee46e88-386381738e6mr26438333eec.9.1795961566100; Sun, 29 Nov 2026 06:12:46 -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: devicetree@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-Spam-Details-Enc: AW1haW4tMjYxMTI5MDA1NiBTYWx0ZWRfX+dAKq5WxbaH4 jXVQzNABq6g03re8uXoU0cFoDCb5nT4iWSKmf6A64tBeHYGi2cMxEiPACzt3LzpUJYdLU3G4nnh AyKSH5e+IcOWIu94+U7IqFmf3JLt5cqTCcAsBSXFE14snUfemCSgK4p2dVMpRaHw2ZicWyJmMh1 QEqti4tvuM41oZHiIl6uGmvWmEAlWX9+yT2RfBNGa1smTqlLsr5gHVfBHIG6LI3b/A59UiIoMtV gXW4gsnPP+2RhnP5uXqgtbjqUUbXtxIckymHHiG0bFre51Gsha4qnorj4Wxnx41qEmrgQOXulm4 50SXtSoYw7kU7vooXw4nxg6OhBQoSQsKnOCWGkdbzJdwMPF2AkOHX5S4bbZt8REfc9OPd1jarWB ZfNlVNDWzrPYhr2PC7QPL6iGvrDgARHAfYZ03RwJPqAvGtM0DMfHBfidKlPCHc+voPhgjerWf63 L0yR5i8mbNXPSIvaaEQ== X-Proofpoint-GUID: ycwg9SKk3E77AWb6F9rYdaWhCBHVTjn1 X-Proofpoint-Spam-Info: AW1haW4tMjYxMTI5MDA1NiBTYWx0ZWRfX5KtOPayyZtpZ YuTujaYhqn/bFe9Omce36gq8ARFMLIuKOzlKOiRDtPXDX4u2BvXzNwuwQnWV9U8S8Qyo33P/0mq D4S/tt9Zz5hH9g0K98pwNtd9tbx0Km4= X-Proofpoint-ORIG-GUID: ycwg9SKk3E77AWb6F9rYdaWhCBHVTjn1 X-Authority-Analysis: v=2.4 cv=To1zFzXh c=1 sm=1 tr=0 ts=6b0c32de cx=c_pps a=PfFC4Oe2JQzmKTvty2cRDw==: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=Um2Pa8k9VHT-vaBCBUpS:22 a=EUspDBNiAAAA:8 a=M1wqZkrtfuGyWKx3LWkA:9 a=QEXdDO2ut3YA:10 a=6Ab_bkdmUrQuMsNx7PHu: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 suspectscore=0 priorityscore=1501 bulkscore=0 clxscore=1015 malwarescore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 adultscore=0 phishscore=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. > >> }; > >