From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4ED05243968 for ; Thu, 18 Dec 2025 15:00:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766070002; cv=none; b=M6DmEJXKr3P4g0xxNOgb/E8xxX8pnOuVAcoLHPt9nUz5Z4w/cdS3EVnBmivMCcbOQp8LCiKZphB05+SVYkkjPPdFZwI8PPhOEo2VHvkPKO8/+kk8v7YVTnpEdaVRiYXQK2BREAz8h/z0bBwKQ7SeASC5lHKV0xOmXsOurUISuco= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766070002; c=relaxed/simple; bh=TTUSg9c7SQ25F3h6Y+3feZ9hKn8pWE0fflqhp8v8Lls=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=LJgxJ4b6UC8UXnlZp2ygWnBq4a7jYWrUidDhtgAR7hoiKyzhJTXp5sUOoTb4fi7h8hxFxHqFgkpI8DAovHKsj4GdbNzcfLNkNE4ZES/9SVB989Ws4hPFaZr/IkYgOcJLSb+FSdUD63/bUqUyvUbtZwhloyGk0ahUhhIAyOQPe+E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=W27VBbtq; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=TsTnk7du; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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.b="W27VBbtq"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="TsTnk7du" 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 5BI8rBvB3447060 for ; Thu, 18 Dec 2025 14:59:59 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= Pr6x/FHZNy2BKmBuWTvABEu0BkQWH32tUpuP8BZZdQI=; b=W27VBbtq5yugaGUu HZEFBmSyctDT2jwZHRQfRyyH64CkEQc3qj6Zw3GUAwgnbX0zC70tDe7OfIGucFZb MlO+YKy5cOB5Sr59IP83O26dWO+z+Z9TlVcfc/6i4rX0Ckzk5IukaeEhAAb8rJEb 1kQjNrKWc/lVyr6i/NW0TNkpXt/gNBhR60Afpl7IbnKSlztW3VBihDnCY/fYOlj8 h/GHQslpZgqRc55cZ1RYlu6ncm+GRNHGqaey9YaMWZFlHKUVc6fFC+rLh7OvW9hK My6GCq5s2sYPiqoh9Rfbwlq5Sj9OyVewoHgmDlbhNWr9SXjG1uiiorIjdw9duMrp L3pBhg== Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4b4egb97g9-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 18 Dec 2025 14:59:59 +0000 (GMT) Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-8b2fd6ec16aso16738285a.1 for ; Thu, 18 Dec 2025 06:59:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1766069998; x=1766674798; darn=vger.kernel.org; h=content-transfer-encoding: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; bh=Pr6x/FHZNy2BKmBuWTvABEu0BkQWH32tUpuP8BZZdQI=; b=TsTnk7du28m3TEP5XHfEQIdr0/lAwL3n7cqP8FAKueiXOUmrF5oIImd1XuQk5QZ3oi /ysw1Mni6gS6NZJ09Vw9MxaZVEpIdOCSqALKILGjzrHHpWs72GMFPp7T4/xUhWOQxxVn clHXY+ZhotLVhO/HAnTN9yXgsDuzNSjrE3Ty4Y/hHCo1r8Wo95oa8MzL9iPVYmquu1B2 pVKQRYgmOCXF2hae3+mnU06umoEVvoiyniD0hVjOkLh82CYDGgdKQIeXwz1h1V6Dc2Bl 3dISlpfQ6Kavjre1F6YgmydOrLQBVT8a7C87G6VR2I6RchpvNMBEq808CjJPXCgQkOje NPLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766069998; x=1766674798; h=content-transfer-encoding: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; bh=Pr6x/FHZNy2BKmBuWTvABEu0BkQWH32tUpuP8BZZdQI=; b=P317AxJv22mtX94ibaC3MmHAcQxbbYVn4CLyVKSpyT8aCgKPFIKLhSxpzMwBHliBiO oTH579lLjmc0Z0Or/y166gG4mEFaI+LeQp0JIEdKo0+zuIDhQB8nzVoBHqM1KKB4NtBt /i5VUyPQPKRatwoT/0O20fyeRNrpL1nWkSAL5tVM7Z6m4DvGvnPdEMhxbxfbEc8GrM8F LZf8Zw6KNwg1HgVwG47QLZzHo32SpPHIOfaDr6WnsNkrYI5PanUUWD73CMZOYg6HIU/E Bmq0pBKbfC5B2zY/PTMOTT0ydrp0rMYKb7R8VT+dzYkgVxe4UoRFODaeuDySF6e6aZ4S 43NA== X-Forwarded-Encrypted: i=1; AJvYcCV1kavT2MkmvwoRlIRYR7s+ZKfVnIdz0Jv+LYt1FB0l/dx5or2LIS43QQVBsVFlxQpMR6eYBQLWA25Jjkyz@vger.kernel.org X-Gm-Message-State: AOJu0YxBeI/JhhImnyCo4Pr/iQtjOAbzx5iZXO73ZtnAme8Xn/NNrV09 dpTNPYlnbznuoY3BMFDj0x6/BG5YB5Mij1Np3clP/o8K+yQjSYSrFp6kyb81bZT6agA2nmSDTvS OeA5A0BjMMke6lKmJ3VmjaV14y9baCEmju2I7fkwYqW8x8mbJre0r32ZisRzruB5PW8sT X-Gm-Gg: AY/fxX5nJlDTStJtt3/fXXJ2YzK0aglZ1aZOHDdV1i5rlukASA9CAWlwJq3RTE13CUF Sf0hGmPRG5lp1N76CJmDcZMhSeq3TEzlroZXzgH+O1ouqdIF8GHQGvESwLXNZIySbOSj+XchGFF 53RpRCuDQ0LHG46qbmyBVmP/T7Yo8SLHc2Dw9Kp73bzKWvCnk4YrFaBCKJc2Ns4SIOclRiMmbrX FcDcl1Sony5KwdLGRx6BMfbLhaKLmNKEQGBtNl6BDPdOlNPwYWcmnfJRYXjnoR9pmK/gulk37Gw Q0Q8TCm9qnLGbcVua7a7va/6NC+vm0oVm2jjLRRt7/yss4z+HMRqwedL69gYIK984pKWltaxHAE Ic4aIWOb2dDBKil/LNzwcOvVDSUxQ06k6d2YXJgOWyLos4z4TE0uED6h9lMMnyTn50g== X-Received: by 2002:a05:620a:c43:b0:8b2:e5c6:b4a2 with SMTP id af79cd13be357-8bef2348e2fmr288593185a.1.1766069998441; Thu, 18 Dec 2025 06:59:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGdbJaaEQGTSDHRIBxUjseFJ7FtDsKJ+MMYtyNHiM5OM/Tdv+vbo7kLGv97qZkIXFwVzKKyRA== X-Received: by 2002:a05:620a:c43:b0:8b2:e5c6:b4a2 with SMTP id af79cd13be357-8bef2348e2fmr288587885a.1.1766069997854; Thu, 18 Dec 2025 06:59:57 -0800 (PST) Received: from [192.168.119.72] (078088045245.garwolin.vectranet.pl. [78.88.45.245]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64b585d4a85sm2706715a12.12.2025.12.18.06.59.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 18 Dec 2025 06:59:57 -0800 (PST) Message-ID: Date: Thu, 18 Dec 2025 15:59:54 +0100 Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC 2/8] power: supply: Add driver for Qualcomm PMI8998 fuel gauge To: David Heidelberg , Sebastian Reichel , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Casey Connolly , Casey Connolly , Joel Selvaraj , Yassine Oudjana , Bjorn Andersson , Konrad Dybcio , Alexander Martinz , =?UTF-8?B?QmFybmFiw6FzIEN6w6ltw6Fu?= , Richard Acayan , Alexey Minnekhanov Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, phone-devel@vger.kernel.org References: <20251124-pmi8998_fuel_gauge-v1-0-dd3791f61478@ixit.cz> <20251124-pmi8998_fuel_gauge-v1-2-dd3791f61478@ixit.cz> <5d6c3dda-71cd-4684-8546-bc4918b560de@oss.qualcomm.com> Content-Language: en-US From: Konrad Dybcio In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMjE4MDEyNCBTYWx0ZWRfXw3S7NdsnSUSE w4f2Qv6K7T7oNWl9s65Ki3r86ayRwgGhkbYt3s70guMSS9BRuDz1czD/jjrZSFCpctQNMMKl36L SZGKzwNkAjXtWbf/yJscjhtG5Nn1K3o+Zsow49k9menfZgL8RZ87uNc1EQGba7z7iULsWphjkcG P+1crRoFpUG5dSrlBioeuMgy5DQPTUAopvCOyAvFcKC+yvIaxkpZoLGAdgpNxKDnRUdLd30Pdva VEvDkvBjH/h9d0CxksiCMXy2Lqw1oEoExvGlirX8+0ovDnYWDvlwRhiLwfiMoe11QI3UzNpsS13 grfe/hdTNCS0IZaaPgtXf1gz1AZffh2Tt7F0ftnTgghiiucbLWAMcpd2a6wQozaGKHFis6CTkTF gGqOMzV8fyyq8h0zwh91iTKpHJaHsQ== X-Authority-Analysis: v=2.4 cv=M9tA6iws c=1 sm=1 tr=0 ts=694416ef cx=c_pps a=50t2pK5VMbmlHzFWWp8p/g==:117 a=FpWmc02/iXfjRdCD7H54yg==:17 a=IkcTkHD0fZMA:10 a=wP3pNCr1ah4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=OQN141zOAAAA:20 a=WFa1dZBpAAAA:8 a=KKAkSRfTAAAA:8 a=HXtEcHK5oMWiseVRQrkA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=IoWCM6iH3mJn3m4BftBB:22 a=MZguhEFr_PtxzKXayD1K:22 a=cvBusfyB2V15izCimMoJ:22 a=bA3UWDv6hWIuX7UZL3qL:22 X-Proofpoint-GUID: sod-mVIdbqb65biLyvAp7XypoI3g-fmX X-Proofpoint-ORIG-GUID: sod-mVIdbqb65biLyvAp7XypoI3g-fmX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-12-18_02,2025-12-17_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 clxscore=1015 suspectscore=0 bulkscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2510240001 definitions=main-2512180124 On 12/12/25 4:22 PM, David Heidelberg wrote: > On 27/11/2025 16:28, Konrad Dybcio wrote: >> On 11/24/25 10:53 PM, David Heidelberg via B4 Relay wrote: >>> From: Joel Selvaraj >>> >>> Ths driver supports the fuel gauge hardware available on PMICs known as >>> 3rd generation fuel gauge hardware available on PMI8998. >>> > [...] > >> Downstream checks if the address is > 0xBA which is what you want >> at least for pmi8998 > > My downstream [1] checks this value. https://github.com/LineageOS/android_kernel_xiaomi_sdm845/blob/lineage-22.2/drivers/power/supply/qcom/fg-util.c#L434 I can quite surely tell you "> 0xBA" is the correct condition to check for.. both my work laptop and a downstream clone on my SSD concur that > > [1] https://github.com/LineageOS/android_kernel_xiaomi_sdm845/blob/lineage-22.2/drivers/power/supply/qcom/qpnp-fg.c#L760> >> You can de-abbreviate this to 'secure_access' (not to be confused >> with 'secondary' or so). There's a locking mechanism which needs a >> 0xa5 byte written to the base+0xd0 register (applies to all FG >> peripherals with the 'last non-secure register' value possibly >> varying). >> >> [...] >> >>> +    u8 sec_addr_val = 0xa5; >>> +    int ret; >>> + >>> +    if (((chip->base + addr) & 0xff00) == 0) >> >> The 'fuel gauge' consists of: >> >> FG_BATT_SOC @ 0x4000 (state of charge monitor) >> FG_BATT_INFO @ 0x4100 ("general fg minus SoC") >> FG_BCL @ 0x4200 (battery current limiter) >> FG_LMH @ 0x4300 (limits management hardware) >> FG_MEM_IF @ 0x4400 (DMA engine) >> RRADC @ 0x4500 (today handled by its own driver) >> >> and a couple other peripherals that Linux doesn't need to worry about >> >> Each one of them should have its own 'reg' entry (which is assumed >> to be 0x100-long), which will let you skip such interesting checks >> and rely on the regmap framework disallowing address spillover (or >> you can just then make the addr argument a u8) > > Sounds good. > >> >> It would be good to keep in mind their relationship and think about how >> to model them together. I don't think they must all necessarily be part >> of a single big "fg" dt node, particularly the LMH/BCL part seems to be >> rather self-contained > > Would you recommend some readings to prepare for this task? > > I see the FG_BATT* + FG_MEM_IF seems to be pretty relying on each other, so I assume I need to take good care of that relation, when spliting pieces up. It may be that a single "fuel-gauge@" device node may make the most sense to represent all three of batt_soc, batt_info and mem_if. You'll unfortunately find out whether this is a good idea as you write/port the drivers. Downstream has some hacks around plumbing various PMIC peripherals with just function exports between drivers, so don't read too hard into that, just try to understand what each piece/function is doing and how that fits into the power_supply framework. I'm a little unsure about bcl and lmh.. but downstream keeps them in a single node and it doesn't seem to be that bad of an idea. There's some LMH support today in the kernel.. but not for the PMIC peripheral. That said, the downstream driver seems to just make the same secure calls anyway (which may be incomplete for some platforms, I don't remember the details: <20230113031401.2336157-3-konrad.dybcio@linaro.org>) Konrad