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 567E13A6EFF for ; Tue, 7 Apr 2026 10:13:14 +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=1775556795; cv=none; b=S9hmjn+Mwfkb5xQsJ3R6u5ZL46R2pBqNw0lkSw7QJ4FyX0ZaaEl+fhZqcbUEdxYYNF08WeGS3csOe6u1APV6sLrYxax1MOhWnnT0wp1kiJKM858tmxYgyHqMDCQF2HLPddesiFuUfYYgXa0lmPmVfqZbpwXDb9GJ/ZKm5e/IId4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775556795; c=relaxed/simple; bh=BeRmkF1AixGu0dDOhZq+ut21Q+0Lj7EFqDNljeqWR/4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=OOdhx4ppcnFnJAOb6AZMSlX7DTcUgKmPvT00YoGC7tIAxZR+8FoO6JfukHGPFC+GDeO81fsdrSPhz3v+4roM0PJ7EfNtLfMyJgAfepiDP2UrVf65tBD+NV5aUDWtOxtzZl05TutMAW13TDvN7ehitrhlJTub9PfHsHYitQy/W1w= 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=ZrhP9xAJ; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=S84uXKaY; 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="ZrhP9xAJ"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="S84uXKaY" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6376HLh61407039 for ; Tue, 7 Apr 2026 10:13:14 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= UwM23ebfEnjAfxbCREGtqZRfmTKIBdktg+hDX1uVW00=; b=ZrhP9xAJlnYdFeYg 3TW2KaGhemua03DJuleHF3XLO0NhJ2L2EliJmwKUrNcm2C4Tgt2oDloldS87gkyv 5+X5whcXEPtJ5c4pNQDJe1OtP5NbcBV/bc0ntjKX6J/pqXKzxwtEiEgbpxYMChP7 V9CMcH4beGBp88W1ZsLzVPQO6XHKWy8gz9NpFeetZE6DJKNnu+NJiZR7ZjObJhTB YFD0LA20Vzk8+7RuOsdD9aNVOuVBrWhcuM5N0GNoSokWs/1omY9qMhiEj/dizZe9 YHPBzRl6dmyyoLsfrgQDXKIRligvbBT9+GaMNK6TC64LcJ18QZ9n4j/2AXz0aB5D V8dX+w== Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dcmrat7aw-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 07 Apr 2026 10:13:13 +0000 (GMT) Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-8a5bf7ee420so19649416d6.0 for ; Tue, 07 Apr 2026 03:13:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1775556793; x=1776161593; 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=UwM23ebfEnjAfxbCREGtqZRfmTKIBdktg+hDX1uVW00=; b=S84uXKaYxAU7AkxZR81c/hul6aaYgV9u32qlmsOSQ2zwKFC9MBRpFifLhiNDzckyvX 1qjcdpR2k+oruDkfjsyu7OOHoS38Im/niQyC3s2sHzC4IESDck1LoZne8/YWVReskFz9 893VREyLiagpRbozvtbrskcR8JKe8x8XuCGyeeKvlOaFyHW3R3N4DNG0A4KTJrn78/FF fP/fnA58IVKhBlfw04CRqovC4nSf5t44Uia0N+wsyAfM2x6b9LaB5j/OFtP3jyoSUUdm ijLyo4KdoJ9Q/nVYKDuYqbnkjJElocY7pTSJxUOYhrte4U0P+/+04Z2Pwt0a6UfSMyFP 2iRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775556793; x=1776161593; 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=UwM23ebfEnjAfxbCREGtqZRfmTKIBdktg+hDX1uVW00=; b=CjwcM5a55Z0kDtS3mDhUERUHBpOIMJV4MStyrwsFGgJZsjEpcIesrWv6IbO2CO+9hy O7r3MtNlXQ4XxjeljwFmX7+qAzTVG7dEjgKARmKrZ/XVZLg3nWkAN/6kSPv9aM58EiZg zvxB8P/+4PVTZatCqBZZcdxpjR4MEUyUdwx95r48Wh49lUSU8aHIIV7a/W6hWSn184Ox cDtV0Gsbuw4yIdPkDjwH5jLu3N/p3s6qrb88Lyh3pxNDXLVsuKApslIKkvafICwzbcRb gyaRjKaE9bEYr3u5s4QU/h1ZK4a7stY3nD83xIVghTwIB6Tn6Q6PMVtazuRbmZlXZHr1 0giQ== X-Forwarded-Encrypted: i=1; AJvYcCXVEWm3iNiQ8Rb6ua0iX/3WdRBVx/voVKsj3JC+ldRCz96LoYtDjWAaoxhQVLEH3kMkPXfJSjsIhF3/7WA=@vger.kernel.org X-Gm-Message-State: AOJu0YxXf/gp9Ye+2XIAowwk3CkRGmZ/sznXFdMs9Yd857g9ytHcD9de 0YVaLW36QSsEPeyMjhlrz2UwfLFhbDttWPNdJzdeg6Y0/548BU13puHdaUScan0/B9+aZZGYpmp kwdjiANrA4gaZ+645MN1SToOwAY9yzngQQ4k6uKZZEgldwrqW0IVIV7fT7idr00+GH4E= X-Gm-Gg: AeBDieuOTbmMfkiwqGj7CevUzMrTrUJDpid43S/fVdKZ3zyaVfYeoqxEfKQNi50H8Vc 38h3971hIslPwshkFz1dfiSeRDEW+h/Cw9wUHzOLca6yuiOuE07sUB8uBVsPgUjPvklGdb8n6Jg eWWEzUKBWedflV0PRJ5Kx56Q5opwVjC8vKiCI1f5lb/lJ34eqin5chULcaLSEBIndnL5mPospX1 AJiffWxjwJ70Rd5F2LlYo/cMQ0w4xja3orYBFYVX8BOiLnp/VUrXQYm7J4vmGud/xyf2Pq4GJot /5KyTr6sc5s5ctgG/nQ3UMn1xpr7oeLuSx1hZzawcTiRz162SK69w1cj2/+0ykVsF6dqtB4Moxo gJ7KkVD3ZXBS8C6vDhK8tw+h9p9bXMv8w0vnZ2bM5B+VwD+d7crrjtpBaF2CU4KHm8VTyJ4dO91 RPZ2Y= X-Received: by 2002:a05:622a:5507:b0:50b:5286:f757 with SMTP id d75a77b69052e-50d62c846cbmr168680121cf.4.1775556792547; Tue, 07 Apr 2026 03:13:12 -0700 (PDT) X-Received: by 2002:a05:622a:5507:b0:50b:5286:f757 with SMTP id d75a77b69052e-50d62c846cbmr168679951cf.4.1775556792094; Tue, 07 Apr 2026 03:13:12 -0700 (PDT) Received: from [192.168.119.254] (078088045245.garwolin.vectranet.pl. [78.88.45.245]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-66e445e5b8dsm3182110a12.12.2026.04.07.03.13.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 Apr 2026 03:13:11 -0700 (PDT) Message-ID: Date: Tue, 7 Apr 2026 12:13:09 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 4/5] clk: qcom: clk-rcg2: calculate timeout based on clock frequency To: Xilin Wu , Bjorn Andersson , Michael Turquette , Stephen Boyd , Dzmitry Sankouski , Taniya Das , Mike Turquette Cc: linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Stephen Boyd , Mike Tipton References: <20260406-clk-qcom-gpclk-fixes-v1-0-7a14fe64552d@radxa.com> <20260406-clk-qcom-gpclk-fixes-v1-4-7a14fe64552d@radxa.com> Content-Language: en-US From: Konrad Dybcio In-Reply-To: <20260406-clk-qcom-gpclk-fixes-v1-4-7a14fe64552d@radxa.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Proofpoint-ORIG-GUID: UUQ5SSkPcnjw07_xgYSZTp6BLyfJHYRC X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDA3MDA5NCBTYWx0ZWRfX0lit4EQUXxcl QyS+nPtHEYLt4hi3usMM0zykL9oRxkoAlwUoQjNbkWr7ONh7YKvWOEd5HtZzPMx7/+DPqXLODh3 UE3cnlka3f5K8W5Rg9RKt581n/GGlpjj4gaqkBVeK3/Xl3IiNoBrgwZW2wlg1EW1zFrZBi6RvPr wah0uCgx1vhayo0fVzLgRwdDgL66TECFdcOspOac9+ODaF79fCWllWIFtuqEe+hqxcN1pURvrP+ b9rF0OyccoceeE137tAhL42/XZVNNruT1cU3bpg4rRcKFH6SmEZwyQ6+KEZldVjx5vX+hbv51Xq Uh32EnvY9H9wu5ZpA+pJPpGWKraTKrdarJa4DlruBqr6gHIJ9ZzcY+SuLMPjmSWIa+/zCThS4fs NjowssW5BySXcy64VM6fyI0DHv5pa0I2kqeWBrfioOwWK1BMRJScSyXrLAy/8ZLQtjnaXciGcjf gDuYQbGdh/P/sx8oxkw== X-Proofpoint-GUID: UUQ5SSkPcnjw07_xgYSZTp6BLyfJHYRC X-Authority-Analysis: v=2.4 cv=D/d37PRj c=1 sm=1 tr=0 ts=69d4d8b9 cx=c_pps a=wEM5vcRIz55oU/E2lInRtA==:117 a=FpWmc02/iXfjRdCD7H54yg==:17 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=qC_FGOx9AAAA:8 a=COk6AnOGAAAA:8 a=Pc8_uKcFEXUdqOsFkrUA:9 a=QEXdDO2ut3YA:10 a=OIgjcC2v60KrkQgK7BGD:22 a=fsdK_YakeE02zTmptMdW:22 a=TjNXssC_j7lpFel5tvFf:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-07_02,2026-04-07_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 spamscore=0 phishscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604010000 definitions=main-2604070094 On 4/6/26 5:54 PM, Xilin Wu wrote: > RCGs with extremely low rates (tens of Hz to low kHz) take much longer > to update than the fixed 500 us timeout allows. A 1 kHz clock needs at > least 3 ms (3 cycles) for the configuration handshake. > > Instead of increasing the timeout to a huge fixed value for all clocks, > dynamically compute the required timeout based on both the old and new > clock rates, accounting for 3 cycles at each rate. > > Based on a downstream patch by Mike Tipton: > https://git.codelinaro.org/clo/la/kernel/qcom/-/commit/aa899c2d1fa31e247f04810f125ac9c60927c901 > > Fixes: bcd61c0f535a ("clk: qcom: Add support for root clock generators (RCGs)") > Signed-off-by: Mike Tipton Having Mike's s-o-b here is odd, given you've decided to go forward without his "From:" [...] > +static int get_update_timeout(const struct clk_rcg2 *rcg) Let's tack on a '_us' > +{ > + int timeout = 0; > + unsigned long current_freq; > + > + /* > + * The time it takes an RCG to update is roughly 3 clock cycles of the > + * old and new clock rates. > + */ > + current_freq = clk_hw_get_rate(&rcg->clkr.hw); > + if (current_freq) > + timeout += 3 * (USEC_PER_SEC / current_freq); > + if (rcg->configured_freq) > + timeout += 3 * (USEC_PER_SEC / rcg->configured_freq); I suppose both are nonzero if we end up in this path but a check for zerodiv is always welcome > + > + return max(timeout, 500); > +} > + > static int update_config(struct clk_rcg2 *rcg) > { > - int count, ret; > + int timeout, count, ret; > u32 cmd; > struct clk_hw *hw = &rcg->clkr.hw; > const char *name = clk_hw_get_name(hw); > @@ -123,8 +141,10 @@ static int update_config(struct clk_rcg2 *rcg) > if (ret) > return ret; > > + timeout = get_update_timeout(rcg); You can just assign count = get_update_timeout() below since you're not reusing this value Konrad