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=1796035042; b=V4vE6JDDvZSQoM8kMJmZD066V9sFSVuWl5mgOG7hrklyR5H/FnG4WJxM9tYSc0J4vJzq aVE8G5IZoo73RXn7/gZA2CuCV9/tFQ7QUjmxSqmuBvkVHAeWuFUZnH4xmhpNVzk4Yr2Ip DfDo5YgLHf9MskIalQBg0A0BEggnQn5lBkHV+87QnkHuU1IUcbRac+R4ONqxtk1QDEHoL azk3bVh8MOMPPo10Q8DeygjXq3HhYB4btIokXdoK8MscNIDY2wIRQ3gJDn0dWAJyVCJ0r 6zgkHFDJcf7fU0nOPYe929KoX8vWZAXjqmi0V5kDE7r5TaNUEBJq0NMAlQZxzqI0hWw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796035042; 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-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Spam-Info: X-Proofpoint-Virus-Version:X-Proofpoint-Spam-Details; bh=BetMbqIWHqcuP1LkRLh65FjtJMbbauKBZTg+V7On/dQ=; b=JiuRiqPilOi70AlElTZqGCQAkeSLBw3Zw1errpf7uH+EkT/2OLTlsQebPvqSjcZlaRPs VBXJD3Sa1I2OY0Sff7SSvCmVExFAVL0ft3sCQJGODrD4uYg35GesncKwXXpVAJxtYWE+O xYc5/ZLxUmcVkpWfn4Eo+MBQ03V2MYsJmi57CGTNRxUsqKvIJISwVWa+tiISzsWxX6TmX vP6qrfUvuHscqf3VwmhwSk6FpiSH33kFLOM9w11S598+GT8YVdg3Ec5wCZwzIYeL6mA/j ci4QYMiWICNf9ungW3mNv9s4gNzlepeCFlIbneabsHNaGPFWsm7etTmp+g9wYR/WUuQ== 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=fQ7HLKO1; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=T2kb0VgD; 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 A7D94606A337 for ; Mon, 30 Nov 2026 10:37:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A7D94606A337 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=fQ7HLKO1; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=T2kb0VgD Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AU9VBaG367338 for ; Mon, 30 Nov 2026 10:37:20 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= BetMbqIWHqcuP1LkRLh65FjtJMbbauKBZTg+V7On/dQ=; b=fQ7HLKO1ag4nget2 IcquZRIYrbwnTAwW3F9efnZ4t/bKMdoMSwbIZ8g5FiS3LijwiAxN1zAXcJQGVSdc 7opE51dNCnN2iyNCD+z0O8onepAvXaRDWO6xx/VFB0Kd6xTY4o/KCO5AOAdyzy0S F9m5jNdfnapVDb0Ob0SA1jiDjLo6VG4PwSyy+Py7/bZk2vTYs7cOcJXkLpxJ4U2E R3+2k5wlViEmQBNIoxsW1e/NIRT2OQ7KXdBo5Wvgq+hUX1WRUX9LZtsz9JrkSmcA q0Ecm5rXmXDSr1TLZiuBz5p/l6LRPzhXsS0vp4N72Kec9HH7gH51cEpawspsczmo Uqgjjw== Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j90c1snn5-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 30 Nov 2026 10:37:20 +0000 (GMT) Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-9495c71055bso1000199785a.2 for ; Mon, 30 Nov 2026 02:37:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796035040; x=1796639840; 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=BetMbqIWHqcuP1LkRLh65FjtJMbbauKBZTg+V7On/dQ=; b=T2kb0VgDico832B2y4PreBx6fhZuUiv9scsYNl5QsMXm5o3XejeI6zVGSQV68CCbqD UykQaeGeWlMiRo6XiY6qy6QN8svVYR0jhjg9lgRuCaZt4A9D+dN46Y2VQVM8bLykkyRO r8dUQZTgkAK6QPfWJs39z5lcohh2OlQhvslVABcnFWpOOyTEOMfHrtNAgmhuTFhz6G+L EEtR/SLMrXcKnm+dsxT0OlUoRw1PLht3mHwfYZJaFoOTgkHMFJCB/YNAA3Wkdwucv4ja 7uY9qLvWygQWYyWxHOzFXKsdZpmkfyZj9E2hOWsG4xLGoTVM+WqjfqIJKio2ZmxPLghQ yDaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796035040; x=1796639840; 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=BetMbqIWHqcuP1LkRLh65FjtJMbbauKBZTg+V7On/dQ=; b=AU+AB4GKOYrOng0e2HJ2vOHURBpYLJ2i8OcFrxzZpFqdijd8PHzciyPPS1apPXobx9 Ag1gXKJoG7XIozx4G6R2CPRN6HisgVx4y6m532wpQDPa0P2ZALivKvaWr7dOkDD/wbLf HEzBszFCXHh9btYyFMBQx8lSEpXcHQZtRdgMQAj7eafHsd1vxfUN5qFZm2ZPGrCrfMZ6 CDOErAzTCC/FQUyYFruHFGFMF+stkRiNJ/Trr3USHqPN9c/meTdVbsVhltIfJkyNlKR2 TKNNtVnn+23pfCuBNV/+U1xbJIZOtlRzdVzwNwzo/ELvQ9yYwgGI7+TTApuu4+do5Yrw /KeQ== X-Forwarded-Encrypted: i=1; AL+hErFwm7J7TZXMtTV+VTehsLhIWDi1WsW/3iNDCt7ea3henbTmHVHh1/3iAnyqXuMEeQtHcoGXVhwosBNn0kk=@vger.kernel.org X-Gm-Message-State: APuU4Z8FzqCQ8e1NKeh3DzZKj92IAjbWe6Ei09tSZ9//6yLs6kV22hHi ILLhYwkd/hd1VEcf0dC7aP20v24ge4v9/fqWuzC97bnwgzo5mIZsOSl4v+iapfClF4oGsmHxsrR A9w9FL86OFhuIlV62lS4NmjxtcvXN5dR3YOulWzrD16PbVHY0wIbrRfHOYg3MbLDL5AI= X-Gm-Gg: AZFdTZeuFe9OC6OrKXCBiEyZQpy7aBILXmObq9phuhwpSWb3icBJkxcsoH5PJcAxJwp dQQwfRncgJCP4VcyY/4VeMjoF5fVhn5CPN4dXpprqmT6dUakTDhzq1Mwo/dbJ5Uu2eyugNawxWN P+pBICULLUrISBPH8DBpg+TAb/je83XgLKBF+l/tGXZCckribX1QSwjGS8fo3A8BJY0Gt1fZsCK QkZrk+z4aEv0MlKeuKSQz4eJC4YmjpJ+vXZpAyWEZ1oo/aioEkihKBO2NCVElyWFDEKvzFNqWcD AZ52OERRmo9ZSIGmCUKlfhGv0z3GMneWWzJ6a5O/qnfvuUKYP6qT2g+Aiuu2ctJS2+fFxM+4jXj qhwLX01EUh/bqAuWPMBa9iY2Sx69z5Oew/+O/8ZyU+u+iK6iQ2JlG6PcbD7CllIk2MVOq4xMFfO lSLQ2rQU4qyqZaprzMYTrAAikoldWDEl5DGCQfJ9ZtIJaZfEYY7CkrEkf5Bg8MgoS0f2JDIphuf MXEQlah39q79gkNwOaTaFOonvNH X-Received: by 2002:a05:620a:649a:b0:949:752d:31e6 with SMTP id af79cd13be357-949bac8557bmr5459013185a.79.1796035039710; Mon, 30 Nov 2026 02:37:19 -0800 (PST) X-Received: by 2002:a05:620a:649a:b0:949:752d:31e6 with SMTP id af79cd13be357-949bac8557bmr5458975685a.79.1796035031246; Mon, 30 Nov 2026 02:37:11 -0800 (PST) Received: from QCOM-eG0v1AUPpu.na.qualcomm.com ([2a01:e0a:830:450:6046:9c83:ea4b:ae9c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbab390cf5sm486441005e9.7.2026.11.30.02.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 02:37:10 -0800 (PST) From: Loic Poulain Date: Mon, 30 Nov 2026 11:36:57 +0100 Subject: [PATCH v5 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: <20261130-cci-imp-v5-1-d2ac891f2bc6@oss.qualcomm.com> References: <20261130-cci-imp-v5-0-d2ac891f2bc6@oss.qualcomm.com> In-Reply-To: <20261130-cci-imp-v5-0-d2ac891f2bc6@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=R7+WitRX c=1 sm=1 tr=0 ts=6b0d51e0 cx=c_pps a=hnmNkyzTK/kJ09Xio7VxxA==:117 a=xqWC_Br6kY4A:10 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=rJkE3RaqiGZ5pbrm-msn:22 a=EUspDBNiAAAA:8 a=01CnRmabwqiQypAkSEwA:9 a=QEXdDO2ut3YA:10 a=PEH46H7Ffwr30OY-TuGO:22 X-Proofpoint-ORIG-GUID: A5waR-OJKziReZrI_OMN9TsWtwWF2CuW X-Proofpoint-GUID: A5waR-OJKziReZrI_OMN9TsWtwWF2CuW X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTMwMDA0MiBTYWx0ZWRfX/3Qsr0jtakXI F636tnHSSr/bJ4G36dq+50WLgpSi8T7Fr0jlEgSfIGuctLM7PO34keR7l0j/AU9WAoPrv4yLXTj w+neE04U23GaeWr1KyGSGfkUZrNrDeXjVc9I2o5Djij/JzIFLW8W7W5I5oaHRizCN9Cr2r887/k TqzQFW1mF9osO5yhOua2y7rr7+jfV9xqT55+vAZiwgKv5MQuZDt4MR+Fu9sbWurO7d9cDBNV2kM gbA33+aiVRBLYx/oXbRHKmeD+FWEDR+IlHek9oXPmtzWaT2kskp24YmmmlIHq3CjLYKPk6u/+C+ Qm0qKKmUDerVwEcVVG+x6xdKPAih488vHfROVN/Ix/In+ir+zK1MbR0PdsIjH/GHrTqV1N6ercz 5MCFMU1103SRxDuH9DLSxuw3lynI91AHTKDZfddweXyTEtu4YHN1DlBP4TXfaEfGEtgj2RNAMnj n8fvQLrICsK8DhB+rww== X-Proofpoint-Spam-Info: AW1haW4tMjYxMTMwMDA0MiBTYWx0ZWRfX9WRm+rzSeWc/ CEM4DoFWt1ZhRml9oZdKAllh78vG4oDOPIZW/RpIlE7O6PfFLHf5sYpDnp1TwAEttrN2csFoLA4 HYo/oXDkHG/ACcfNlBlU9dFXvMK3I6s= 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-30_03,2026-11-27_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 malwarescore=0 spamscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 suspectscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611300042 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 dfe8f6c712369b052f813e2ade1aec9ce5aacedd..baad17d8ec358535da9710c656facb3b28a087a2 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