From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.180.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379587; b=1FZ0l4p2P91/tzXW9UnGnk9jzIMOjHzZ0v9NgKksz0BsswzPXIw0yqgsLEnuHPuG0Nx2 xOqlei+COorz8P0Cpo9Jv20jgFGr9V/hZtQo0ineVJRyv0xX4ql+X9Jz4cIDnPTKlKonK VOXezW8XGC/eOHJA0rjD3jqOMycziXnwaCTFPvSKZsn0MjATySrWSQf++sBSWyMvRVri8 JU4y20wL8M+1FUf2CtJI/ZQqztG6nVC6sLyQEQ9ZhEg5zPoh0lBB0my8sPR6GsPjlpeEx RmrLheVSmwNDFeaR2cusCZQk6sbguCjYp7rD/uaffgn3pXKiks4c5CarBJQ/I8JruOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379587; 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:From:Date: Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer:X-Authority-Analysis: X-Proofpoint-ORIG-GUID:X-Proofpoint-Spam-Details-Enc: X-Proofpoint-Spam-Info:X-Proofpoint-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=lh7AlKIwD3KYc7omCChQ7z05x2EMjpOwFhXXrblTJLw=; b=bUC1tzXdsI1mKlYuMcLRy+WCuPaTX9oLjWzVVpWJqCEDtUOCxdpzWIkOQaWFbWnYTwsg 8n8DNnbUBnmPFZj11EMOoAv85JmhMDl0AzcuJtOHtFkeUPrvgw4T5LaYZa+zcdTKZXX38 RBRvrI5zM6QtWQdbS8Ka3rh01ZPFnIya0aybRIwX/v0M4mPqYHQoIINdELWjYQM4+Rz2e yNIv9tZy2HPhtE0hMTDSBBnw/NptyM71JlnK+4Up1g2RZHyRlbFi8cLhwVmlgcaon3k9p i9pprq9kUcCAu6aPBSHZS1qLVOBAWNjhaSN5s8N/mzejjOX2pwwPoNon1OjgpLfdG7g== 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=EkM8iO1H; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=bMgLl0MQ; arc=none smtp.remote-ip=205.220.180.131 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 B6F23606A338 for ; Fri, 4 Dec 2026 10:19:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B6F23606A338 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=EkM8iO1H; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=bMgLl0MQ Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B45MMjh1698871 for ; Fri, 4 Dec 2026 10:19:45 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= lh7AlKIwD3KYc7omCChQ7z05x2EMjpOwFhXXrblTJLw=; b=EkM8iO1HP41J5lU9 GY/PjV3nuvh1er4I6Tv0QqzrUsa7TUvui/Zd78DK4vO1l3lwQ15/HMBIBGHEFmhO pYpFpmSNRErD/gXzzdWRqG1nMkyC+9FKvLQNx7CT8Ift20nfg4eqAo0YX4zXi0xE fEIVWBaRe1fBUayW1ZKGyAf9x12FG00XLA8C0ZyUw1avY9ZIqn4LLi9ijJ2XjzrL VaEdfU4TUPm2XpO4fScEzWloNVRykF7YvT63DSsazViIA9fNzRTA6TSSZEA5DV2M dR2QiIYd2n8lXWRc0KESXVRT0sVbDinKkl318S4/b6Ly48+5YlabALPmTr4s9G8X h9j71w== Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4jbq7xrw3h-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 04 Dec 2026 10:19:45 +0000 (GMT) Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-93f2005ce21so124281285a.3 for ; Fri, 04 Dec 2026 02:19:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796379585; x=1796984385; 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=lh7AlKIwD3KYc7omCChQ7z05x2EMjpOwFhXXrblTJLw=; b=bMgLl0MQUNHnm42Mw20l/qO0qVyG5hm/k5dTW7bt6TSGG3rh7XGE05sE4dQGeJfKgq IDZ97zAmfd6eES4aHmrtF2Lg5LLnRXJILa291H6Zmgxd47eS4FMEji6EZ8yP9QpXHFA3 7u5LR932vMYHDoTtFEXp427oaQEHoV67MsG2DTK2uxEGAbVHDDT6oIwgDm6IW4ByvQxc 8+5zD7b0EvgXjXh0M84YxuUOfVNoSJmkDoqhHADGWO5SRB+WaPBRNuoZyY9T7E2/pnEl 2e89ElXkXJo2ljqD6tCJjjdbW4VbVgmxKxhi27wkA/yV+jJ18afr3wpM0nsiOuiWMiG0 pl9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796379585; x=1796984385; 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=lh7AlKIwD3KYc7omCChQ7z05x2EMjpOwFhXXrblTJLw=; b=XE1fviBYeUHjDiknGhpjsGHhWatrsdqz+Ukl5hMAR5mLoJBm527b/ke4KCJVMvpA1q Cel7Kef8CsPglO6R2AyXEqoex8APsvJfqhGfhMYhsaBLqoQyDSEwjLjdAeNz/phWnkNh z24WaHtb9OEMmmcm2rOxw2BfyX6z1LjNX9PmupAllpRi+qOWeIn7q1LxuPE8s8wKaHGi 38ozdIAJx31CNiHW9PSvwxLe2rasQo9iDiSHO8det1uhewqQolvuXHZjZr8FbHeRKKMk y0I9iZVGcr0iar+CqRYR/h4nk4L1gN+PaOjj//s96TQ8yMHB9240sC09wj0ekhm9BgyS BTVQ== X-Forwarded-Encrypted: i=1; AL+hErHRWuTpu2/j9m8X7F4XpuXg4T8TWg4clpMJD6eMrTudnzI0lOHl54/7cpuWuwy7Hi9znMkFgKy3tL3Kybs=@vger.kernel.org X-Gm-Message-State: APuU4Z8p97oYsEY7epvoFiT3+j3ZrwdcVjjcP0/GRwQ+kqjat9d3kEtz 8lDOm/OosvVEA7AmAWUFLnX9LUHRDviztlhp0z9MADovhboboQPSUXjWZNUJ4yjTL/kivFIAJ9s R8Zu/GZUu0Am9yM8Jn2QApM4cqguFPW3pLmi9mSujLW3ijKbcgXA/OtQBcjf1gmCQd2g= X-Gm-Gg: AZFdTZdOty70n0Z/EucoS5DQFHHWyeAL+EOfTHbSbkbpvwNIX0O0fwgs+M4u3s1FAqY SPjNgyRPMFHxkluf2gpZ/CQpHrq1+JZUfvYbVYTD48VVwcFnDVNRHBEJ81XOKTiVvaNRcNsec6o b1MuNB4A7qBdN6Re7A67MahXciQIcFmbJ5ptz7C3qle6tnQjvq0HauLori0ndXayjUJMBK0+BTn 9Pjw1fE+PLW9zuAOoz9cA1JLre8pdT/XP6D/ZHSAk2jlKAfIhbh7yD6rwxx9jMNeBOfD0ohwuBk hYEw37BUBsWzth0vrIqoH1fL9exkScm621FvJ48Hr50lSGHSEjiv0+FIm4pXGLC+VvIi4HnoiDj jeH5J3Y3NW8uNjtKbiCDVHqa+ZYjFvHMJu/6Zd86XCvOi8r9lt3PIBDQ/1ay6yz00FdCGUKcq3H jts2+RhwfJRAEYZ7gwZ9tZ6QdH9pKdMkiWcaS6iid5rFBZCtO7cyHlbQHbJDMyTo3UaXE8Jrr0M jeO/wLuXd7R+hrQ3rROVZzPfAfN X-Received: by 2002:a05:620a:3190:b0:93e:fc4e:c48d with SMTP id af79cd13be357-94a82de452fmr223822485a.61.1796379584896; Fri, 04 Dec 2026 02:19:44 -0800 (PST) X-Received: by 2002:a05:620a:3190:b0:93e:fc4e:c48d with SMTP id af79cd13be357-94a82de452fmr223820585a.61.1796379584499; Fri, 04 Dec 2026 02:19:44 -0800 (PST) Received: from QCOM-eG0v1AUPpu.na.qualcomm.com ([2a01:e0a:830:450:2022:3328:5af7:2b49]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbea2886f6sm48049005e9.8.2026.12.04.02.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 02:19:43 -0800 (PST) From: Loic Poulain Date: Fri, 04 Dec 2026 11:19:40 +0100 Subject: [PATCH v6 1/7] i2c: qcom-cci: Factor out write command queue programming X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261204-cci-imp-v6-1-bed67559c66a@oss.qualcomm.com> References: <20261204-cci-imp-v6-0-bed67559c66a@oss.qualcomm.com> In-Reply-To: <20261204-cci-imp-v6-0-bed67559c66a@oss.qualcomm.com> To: Robert Foss , Andi Shyti , Konrad Dybcio Cc: linux-i2c@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Loic Poulain X-Mailer: b4 0.14.2 X-Authority-Analysis: v=2.4 cv=Jv1kP84C c=1 sm=1 tr=0 ts=6b1293c1 cx=c_pps a=qKBjSQ1v91RyAK45QCPf5w==:117 a=xqWC_Br6kY4A:10 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=ZpdpYltYx_vBUK5n70dp:22 a=EUspDBNiAAAA:8 a=EKMQ_w68-2WzcSmJptwA:9 a=QEXdDO2ut3YA:10 a=NFOGd7dJGGMPyQGDc5-O:22 X-Proofpoint-ORIG-GUID: t8O-C9Pp-pMxUahMkxDeC9nXf59YdUKo X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjA0MDA0MCBTYWx0ZWRfX5gpojFVmp4da 7oVn7ltYj+DyQWbwG/OGpcK9U5ksKLfDgs5bs7HUhivJ+1ToZlubj/JN75X/PFEk/Lg9h/j7bN8 LImjhw7y7ps+oBsXZgi5ySNYNtfS3WPYHXUHqy4MaEIxo4Zf5pjB4W+W9F/SYw6wie6RlHAPI1X oAa/5MyQ8RRCOutsk0E5JiY7+7vt4WVFyajBwanHpSQSJEKzXmJ+vzDhouoTbgJnWdvQZY1GksV eL7PEvZW4QCWr4zc9yH4q8DsXbDXAJiZBHVSmvnraGO8mAj5RyYpuJaODvGTmFdanlJ0EMEPmNb 2mw2uGD4xVCtgQgiWS54G595jnEd9bDc31FWy57yRbTQ4FXlCAHQEvHsOSn+D5gP5RvYC0lhJP6 fBHQXN6ICPZyu+J0RldG2ZbODawibkOGzwaTPaqhpprT1IrwdxaOdBCtxIbBUsYCARmp4vycDpE Q1d4NVeL/ByvgcFrGKg== X-Proofpoint-Spam-Info: AW1haW4tMjYxMjA0MDA0MCBTYWx0ZWRfX7PnmdaGruun+ bYVsShelaUWtGSvZuvFwUfC7TZl5294C4asHrB95hhlbOVvXbteFMmcAgJ2NeFXjP4iOv+Pd5Xe 63+NB3a9CxtAUP/0r2kvVlYSCdl/wg4= X-Proofpoint-GUID: t8O-C9Pp-pMxUahMkxDeC9nXf59YdUKo 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-12-04_01,2026-12-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 spamscore=0 impostorscore=0 adultscore=0 malwarescore=0 clxscore=1015 priorityscore=1501 bulkscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612040040 Factor out write-command queueing into a dedicated helper and replace the manual byte-to-word packing code with iowrite32_rep(). The resulting code is easier to follow and will be reused by upcoming burst-write support. A command can only carry as many data bytes as fit in its words, so validate the length before building one, and do so where an error can still be returned. The I2C core already rejects a transfer longer than the limit advertised through the adapter quirks, so this is only a guard against building a command that would corrupt the queue. Reviewed-by: Konrad Dybcio Signed-off-by: Loic Poulain --- drivers/i2c/busses/i2c-qcom-cci.c | 44 ++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c index 476526b099c3504243fb5c9ee2031a68b8acc02c..991744ab5ae766f8a311979c2dee07698c3f6451 100644 --- a/drivers/i2c/busses/i2c-qcom-cci.c +++ b/drivers/i2c/busses/i2c-qcom-cci.c @@ -78,6 +78,9 @@ #define CCI_I2C_WRITE 9 #define CCI_I2C_READ 10 +#define CCI_I2C_WRITE_WC 3 +#define CCI_I2C_WRITE_NWORDS(len) DIV_ROUND_UP((len) + 1, sizeof(u32)) + #define CCI_I2C_REPORT_IRQ_EN BIT(8) enum { @@ -480,42 +483,45 @@ static int cci_i2c_read(struct cci *cci, u16 master, return 0; } +static void cci_i2c_load_write(u8 *buf, u16 len, void __iomem *loadq) +{ + u32 cmd[CCI_I2C_WRITE_WC] = { }; + + cmd[0] = CCI_I2C_WRITE | len << 4; + memcpy((u8 *)cmd + 1, buf, len); + iowrite32_rep(loadq, cmd, CCI_I2C_WRITE_NWORDS(len)); +} + static int cci_i2c_write(struct cci *cci, u16 master, u16 addr, u8 *buf, u16 len) { - u8 queue = QUEUE_0; - u8 load[12] = { 0 }; - int i = 0, j, ret; + void __iomem *loadq = cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, QUEUE_0); + int ret; u32 val; + dev_dbg(cci->dev, "master %d write: len=%u\n", master, len); + + /* This condition should be guaranteed by the caller (i2c core) */ + if (WARN_ON(len > cci->data->quirks.max_write_len)) + return -EINVAL; + /* * Call validate queue to make sure queue is empty before starting. * This is to avoid overflow / underflow of queue. */ - ret = cci_validate_queue(cci, master, queue); + ret = cci_validate_queue(cci, master, QUEUE_0); if (ret < 0) return ret; val = CCI_I2C_SET_PARAM | (addr & 0x7f) << 4; - writel(val, cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, queue)); - - load[i++] = CCI_I2C_WRITE | len << 4; + writel(val, loadq); - for (j = 0; j < len; j++) - load[i++] = buf[j]; - - for (j = 0; j < i; j += 4) { - val = load[j]; - val |= load[j + 1] << 8; - val |= load[j + 2] << 16; - val |= load[j + 3] << 24; - writel(val, cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, queue)); - } + cci_i2c_load_write(buf, len, loadq); val = CCI_I2C_REPORT | CCI_I2C_REPORT_IRQ_EN; - writel(val, cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, queue)); + writel(val, loadq); - return cci_run_queue(cci, master, queue); + return cci_run_queue(cci, master, QUEUE_0); } static int cci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) -- 2.34.1