From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 693AB5218BE for ; Tue, 29 Sep 2026 12:25:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790684762; cv=none; b=UrOF/FJ3bou1zj6rJQZtt2YDw0eDTf3QMvwYp5argSI0IMlosgEGFch31dLPgM2tFH3eHDe0GHqyQk4n/8IA5iA7/AhsiGyW3y6Bq7dwPEJn5/cQ6fjGBw+4RMmRK/R8ms/bHLUX0yeAMbluSRPXBR4P67tGYdtT+erb0fkMP1I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790684762; c=relaxed/simple; bh=VB1fq1RKiKGVJL/jXTuCtxqg6mIar30rpelwiVPPn4s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Fn8kRn7YDHpx9nR4eP04TcAcX5C1Au1CVSDOSONwJWLZGAxMlKhVTzo2YCmjKQG3fffcaJw5DM7ngrbmfiftesQ7BMionrrNpE+xGzDXb0UwHRXCUOAynRVz1guheQcZQ1MMm4FTN5A7Kc6uELUYQaA/M+qraM3zf1LvsiGCmTU= 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=YMYVkWXT; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=aV7agCs4; arc=none smtp.client-ip=205.220.180.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="YMYVkWXT"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="aV7agCs4" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 68TCDvr13756703 for ; Tue, 29 Sep 2026 12:25:57 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= 5Zd8H7pUQjwRPH2i35MnsVti9s3z6U0qbD41nLQ6bk4=; b=YMYVkWXTo2z2PNEj zV3iLKsbKemrzIx7Q1db+emmf7YZ/da6h04bH/qDFWcElGDBScFOptnChrONOtp8 Y0mY6l+gd6S2d0gkffkthpZ/oe7A4KzcNZeksP0p0BORInYfGvMX8hinsUuNsii/ Z8+EOzb21TDnDTBxJVWiPz3XzFJgU0c9H0eX2vriqfRcC1l0ZqDsLQirB/0FlGQX ooKlzWDmZQjy8Ws2l01Ffy2cmoc8pwzUwKmH7H1SAdr+lv34I+Dw70cBOzVWZTU+ Ju8MtJNi4kNgqjyd/xJKyUQ82Nc3VfGz5hhll538nD1PkMsMwmdrWU1sK33bUtbz 73gS1A== 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 4h0b0v8mgc-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 29 Sep 2026 12:25:57 +0000 (GMT) Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-91454ecbd2fso71374216d6.1 for ; Tue, 29 Sep 2026 05:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1790684757; x=1791289557; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=5Zd8H7pUQjwRPH2i35MnsVti9s3z6U0qbD41nLQ6bk4=; b=aV7agCs4o59hCS/5z1sI8DYqtkRcYMqggkarIqiK+B2SNbuftD4Jkimfu27NXkct4m eUHOpqE6lxSgP36EzWm+L/DJ3EJy41LryhJJwVxGfZfqXixuYKpZxcr7jfFGEXuTdfO1 Zh0GUpqIpRAUWH4dLG4pKZUPN4Ge5BASWOBGfTwAVsjPDfaN3Iwdi1Uv27sH1zQSD95U HcGwKBG38X/N4jA624JvQUbGxf+SUAfyHeF7bJDTcdBhQkxq9BpE2wEJwPL7Se0cICtj vVZRJjtIMR9xkxLGrpfdEM3C74/H78JlRkUj0+u7n2wcC7TKELv7wSfjTxuJc3pL6rKB bnKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790684757; x=1791289557; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=5Zd8H7pUQjwRPH2i35MnsVti9s3z6U0qbD41nLQ6bk4=; b=lJPiV81uZ5//Cc7Nad3Iktsh6B6BbNMPBTxSVGFInJAYMHAxNY7rT+AAgK5rBoiGei rbx5hny85Ip9nnKknCWcmkegduiq5iodc1jV2KP1xF8kmS0A4s60/zPJbGeXNBgl/8Hz Vi+geX2DEigfuqmRiNj21v3C+6sNiwG/n7y3ABYpRVG0qUJduvRt5TDJHkljznmCTesT yBikAtVK9xtJdlLzVlRS69nNScAoa44XIPDSS/v24qUVtQ8sAZED1yF1Qx1p2G1BbzYX Q3oAYds9xQRzzUW6csgn9+rtjrrFl/TKz/hIdQe1AD2E+HkdpDH0lzblwEt5BjC48mS9 qJMg== X-Forwarded-Encrypted: i=1; AKwUvBwFSa5LwvpO84TsqvOEUkF3HF7UuYJppRuhS9QtvmUn56KBHVO8/giLvBNcDpLY54tLs4qSRuvo6M8J1SM=@vger.kernel.org X-Gm-Message-State: AFuF++l/CgOkbmZ2MfpsjC6pAW1/n+LKM6iwS5+ZXxEKC7faN1hCMcvV vYrPD+p2GDQUJGdfMfOqkjcc+NVF6ywZ5g4WvZn+x/MIppQ2ROZ93/wo6ZcSdHcyWfKtqkfgfhm 8m46nh6nowDD4g5bVNqmCfwB7di5mjGpr22UkjRx4zLCNyaP/k5mk3SrIQEyIfW50riM= X-Gm-Gg: AYBFou1Vu09nM0gardjs7A/R6bL0+k2ADDNXoiwGhciwa72WJJhlJIN+wfgpq66mP62 Fj2Uw9nyqXCwQ+2sjDZjGG6UZ4j0Wwa8ol9A1belb97apTZuvwX4jI1rjlS5AMnJR3bPn4LuN8+ +6q89eeSbDVsrLf4dDrnwj6C7hP1iOS8un1J5otPA8FJi6f+T1AFvUPXFyHR4JxgysAI7IiGCvU gTBKV0/eDsniXuzOqbvif90I+i+pbQttEuk5AxM9KZxGYa3rS4C0NDm+9rKxcvr3ZsF3O4OaK3d aTZPgTOOxhE56PDZ9PL2GsO38scdbSjP0/NwptA1nmqN1+VUf9qU3AzFQvxC9T//wAb5kLPPL8E BJ19OcL5iiWSzN0IUat/rgJ8fvlkqp5dRUUIUcmyTpQm8IqaYbT24vCHFtLkc399p0zsGSrONMD 7kIhy4nCWxzp8KwJjDJ4as4mlYivRbAZ9Z/2SNPBZVz1ZzX9v/gXE= X-Received: by 2002:a05:6214:2528:b0:914:4c57:510e with SMTP id 6a1803df08f44-9144c577f72mr184412536d6.19.1790684756562; Tue, 29 Sep 2026 05:25:56 -0700 (PDT) X-Received: by 2002:a05:6214:2528:b0:914:4c57:510e with SMTP id 6a1803df08f44-9144c577f72mr184411926d6.19.1790684756033; Tue, 29 Sep 2026 05:25:56 -0700 (PDT) Received: from QCOM-eG0v1AUPpu.na.qualcomm.com ([2a01:e0a:830:450:5c1f:3897:a4a1:99e1]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-9178d302482sm9103956d6.12.2026.09.29.05.25.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 05:25:55 -0700 (PDT) From: Loic Poulain Date: Tue, 29 Sep 2026 14:25:46 +0200 Subject: [PATCH v6 2/5] i2c: qcom-cci: Support per-mode CCI clock rates Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260929-cci-clk-fix-v6-2-62a268cccb0f@oss.qualcomm.com> References: <20260929-cci-clk-fix-v6-0-62a268cccb0f@oss.qualcomm.com> In-Reply-To: <20260929-cci-clk-fix-v6-0-62a268cccb0f@oss.qualcomm.com> To: Robert Foss , Andi Shyti , Wolfram Sang , Dmitry Baryshkov , Luca Weiss Cc: linux-i2c@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, vladimir.zapolskiy@linaro.org, konradybcio@kernel.org, stephan.gerhold@linaro.org, Loic Poulain , Konrad Dybcio X-Mailer: b4 0.14.2 X-Proofpoint-ORIG-GUID: 2AtKieAyECg1OLiZnWeTeG9_UKaJVQeH X-Proofpoint-GUID: 2AtKieAyECg1OLiZnWeTeG9_UKaJVQeH X-Authority-Analysis: v=2.4 cv=Z+55j3RA c=1 sm=1 tr=0 ts=6abbae55 cx=c_pps a=wEM5vcRIz55oU/E2lInRtA==:117 a=xqWC_Br6kY4A:10 a=IkcTkHD0fZMA:10 a=VdqzKS8jKosA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yx91gb_oNiZeI1HMLzn7:22 a=KKAkSRfTAAAA:8 a=EUspDBNiAAAA:8 a=xxoTSpZZo30Qa_5IT24A:9 a=QEXdDO2ut3YA:10 a=OIgjcC2v60KrkQgK7BGD:22 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTI5MDA0OSBTYWx0ZWRfXx6QLFnm343nu DGmc5E5VkT8SjE4TZK+hl8CrKyX3ej+iKgViowQMWX4X0Kld9tYgMcUhmb4MA8VRb6Mu+MedW68 G2a/4b1C94f/anN9DgFdnZuqoClDxWIGADjPzbQZyNLbbgr/bWOzNZVjF9TqsoIElRRu6ofW8l4 GDAFiKHvlJrx3EoyFw9eI4Hr+pmEHpFzqeIz0DLVmXtIIMhuA3a29ed1JyDJ36kX/Mx8SJY1Oab pz26reTNodp8+fl/BMV64tWK4vwlGG68KOv/6+qbQq7Yw6iglVRpVxZalJbIsDHngNPXeCCYina Vwafce3bSUaDwN+kEYD+yilG0s7bOarKULsY2PSU0myt0TSSSFuadTPJCfQMrhyGoPGln6HZMX+ OyIyVd9qp7W1i3UfuFk1G9O7g2Ql11zOFQQzxygXaPZxAAdtN3V4CspmbIeKuQ8xDLP8protzry Zu/DCNgtRJJjoN8aIzA== X-Proofpoint-Spam-Info: AW1haW4tMjYwOTI5MDA0OSBTYWx0ZWRfXx3w907TK7inP JSrAcE83pAWy7c0FlqrNjC6cyHk69DA0PGlFBDJVf80t5se8yMSdQxQQhghsiOGuhNQleaEipNp XVdHawi4fgtPCxKF7INmMplv/PYj9qw= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-09-29_04,2026-09-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 phishscore=0 bulkscore=0 malwarescore=0 suspectscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609290049 The CCI hw_params timing values (thigh, tlow, etc.) are expressed in clock ticks and are only valid at the specific CCI clock rate they were calibrated for. Different I2C modes may be calibrated for different rates, and the single CCI clock is shared by all masters. Turn the timing table into a two-dimensional [rate][mode] matrix so a given rate can carry timing sets for each mode, and select the entry matching the currently running clock rate at init time. The existing per-variant values are moved under their calibrated rate (19.2 MHz for v1/v1.5, 37.5 MHz for v2), no timing values are changed. At this stage the driver only validates the running rate against the table, the timings are only valid at the exact rate they were calibrated for, so if the current rate has no matching entry for a master's mode, fail initialization rather than program incorrect timings. A following patch actively enforces the required rate so this becomes a safety net. Suggested-by: Vladimir Zapolskiy Reviewed-by: Konrad Dybcio Reviewed-by: Vladimir Zapolskiy Signed-off-by: Loic Poulain --- drivers/i2c/busses/i2c-qcom-cci.c | 74 +++++++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c index 0a216c4d08114f267c8441925e8811ca64f1a909..1092ce0371429ef64c7cc44cc23a42ba4c135af5 100644 --- a/drivers/i2c/busses/i2c-qcom-cci.c +++ b/drivers/i2c/busses/i2c-qcom-cci.c @@ -82,6 +82,13 @@ enum { I2C_MODE_STANDARD, I2C_MODE_FAST, I2C_MODE_FAST_PLUS, + NUM_I2C_MODES, +}; + +enum { + CCI_CLK_RATE_19_2MHZ, + CCI_CLK_RATE_37_5MHZ, + NUM_CCI_CLK_RATES, }; enum cci_i2c_queue_t { @@ -117,7 +124,7 @@ struct cci_data { unsigned int num_masters; struct i2c_adapter_quirks quirks; u16 queue_size[NUM_QUEUES]; - struct hw_params params[3]; + struct hw_params params[NUM_CCI_CLK_RATES][NUM_I2C_MODES]; }; struct cci { @@ -127,6 +134,7 @@ struct cci { const struct cci_data *data; struct clk_bulk_data *clocks; int nclocks; + struct clk *cci_clk; struct cci_master master[NUM_MASTERS]; }; @@ -225,7 +233,34 @@ static int cci_halt(struct cci *cci, u8 master_num) return 0; } -static void cci_init(struct cci *cci) +static const unsigned long cci_clk_rates[NUM_CCI_CLK_RATES] = { + [CCI_CLK_RATE_19_2MHZ] = 19200000, + [CCI_CLK_RATE_37_5MHZ] = 37500000, +}; + +static int cci_clk_rate_idx(unsigned long rate) +{ + int i; + + for (i = 0; i < NUM_CCI_CLK_RATES; i++) + if (cci_clk_rates[i] == rate) + return i; + + return -EINVAL; +} + +static const struct hw_params *cci_get_hw_params(struct cci *cci, int mode) +{ + unsigned long rate = clk_get_rate(cci->cci_clk); + int ri = cci_clk_rate_idx(rate); + + if (ri >= 0 && cci->data->params[ri][mode].thigh) + return &cci->data->params[ri][mode]; + + return NULL; +} + +static int cci_init(struct cci *cci) { u32 val = CCI_IRQ_MASK_0_I2C_M0_RD_DONE | CCI_IRQ_MASK_0_I2C_M0_Q0_REPORT | @@ -249,7 +284,12 @@ static void cci_init(struct cci *cci) if (!cci->master[i].cci) continue; - hw = &cci->data->params[mode]; + hw = cci_get_hw_params(cci, mode); + if (!hw) { + dev_err(cci->dev, "no timing for mode %d at CCI clock %lu Hz\n", + mode, clk_get_rate(cci->cci_clk)); + return -EOPNOTSUPP; + } val = hw->thigh << 16 | hw->tlow; writel(val, cci->base + CCI_I2C_Mm_SCL_CTL(i)); @@ -266,6 +306,8 @@ static void cci_init(struct cci *cci) val = hw->scl_stretch_en << 8 | hw->trdhld << 4 | hw->tsp; writel(val, cci->base + CCI_I2C_Mm_MISC_CTL(i)); } + + return 0; } static int cci_reset(struct cci *cci) @@ -283,9 +325,7 @@ static int cci_reset(struct cci *cci) return -ETIMEDOUT; } - cci_init(cci); - - return 0; + return cci_init(cci); } static int cci_run_queue(struct cci *cci, u8 master, u8 queue) @@ -488,8 +528,7 @@ static int __maybe_unused cci_resume_runtime(struct device *dev) if (ret) return ret; - cci_init(cci); - return 0; + return cci_init(cci); } static const struct dev_pm_ops qcom_cci_pm = { @@ -570,6 +609,11 @@ static int cci_probe(struct platform_device *pdev) return dev_err_probe(dev, -EINVAL, "not enough clocks in DT\n"); cci->nclocks = ret; + cci->cci_clk = devm_clk_get(dev, "cci"); + if (IS_ERR(cci->cci_clk)) + return dev_err_probe(dev, PTR_ERR(cci->cci_clk), + "failed to get CCI clock\n"); + ret = cci_enable_clocks(cci); if (ret < 0) return ret; @@ -652,7 +696,7 @@ static const struct cci_data cci_v1_data = { .max_write_len = 10, .max_read_len = 12, }, - .params[I2C_MODE_STANDARD] = { + .params[CCI_CLK_RATE_19_2MHZ][I2C_MODE_STANDARD] = { .thigh = 78, .tlow = 114, .tsu_sto = 28, @@ -664,7 +708,7 @@ static const struct cci_data cci_v1_data = { .trdhld = 6, .tsp = 1 }, - .params[I2C_MODE_FAST] = { + .params[CCI_CLK_RATE_19_2MHZ][I2C_MODE_FAST] = { .thigh = 20, .tlow = 28, .tsu_sto = 21, @@ -685,7 +729,7 @@ static const struct cci_data cci_v1_5_data = { .max_write_len = 10, .max_read_len = 12, }, - .params[I2C_MODE_STANDARD] = { + .params[CCI_CLK_RATE_19_2MHZ][I2C_MODE_STANDARD] = { .thigh = 78, .tlow = 114, .tsu_sto = 28, @@ -697,7 +741,7 @@ static const struct cci_data cci_v1_5_data = { .trdhld = 6, .tsp = 1 }, - .params[I2C_MODE_FAST] = { + .params[CCI_CLK_RATE_19_2MHZ][I2C_MODE_FAST] = { .thigh = 20, .tlow = 28, .tsu_sto = 21, @@ -718,7 +762,7 @@ static const struct cci_data cci_v2_data = { .max_write_len = 11, .max_read_len = 12, }, - .params[I2C_MODE_STANDARD] = { + .params[CCI_CLK_RATE_37_5MHZ][I2C_MODE_STANDARD] = { .thigh = 201, .tlow = 174, .tsu_sto = 204, @@ -730,7 +774,7 @@ static const struct cci_data cci_v2_data = { .trdhld = 6, .tsp = 3 }, - .params[I2C_MODE_FAST] = { + .params[CCI_CLK_RATE_37_5MHZ][I2C_MODE_FAST] = { .thigh = 38, .tlow = 56, .tsu_sto = 40, @@ -742,7 +786,7 @@ static const struct cci_data cci_v2_data = { .trdhld = 6, .tsp = 3 }, - .params[I2C_MODE_FAST_PLUS] = { + .params[CCI_CLK_RATE_37_5MHZ][I2C_MODE_FAST_PLUS] = { .thigh = 16, .tlow = 22, .tsu_sto = 17, -- 2.34.1