Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp472969lqo; Thu, 16 May 2024 11:22:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVe2Yic4ynMYfMGN98grA/8NNqH25iJ71UKe3AEMpk0r6LvN3roYfvWifF5Ni1faPSlpK3mTkDdrT6/DdvbgIl8er9HI3UguVn0qAgSIg== X-Google-Smtp-Source: AGHT+IGkJ0bfAsuHTATJikRwUdVOSXguW41YnfWVSD7rQyavRMbsr8HTydux+OR5N2KUACwfxBPv X-Received: by 2002:a25:b1a3:0:b0:dee:5cb6:483c with SMTP id 3f1490d57ef6-dee5cb64977mr17774233276.49.1715883733935; Thu, 16 May 2024 11:22:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715883733; cv=pass; d=google.com; s=arc-20160816; b=KJUw7Yw/R9M23Jd4I7b1+r/IcszzujImBR8Err8mM8rcdPNoMwZdEqb9q4s/ejjfzp XFoqNbJcH1y28c7ES0EhLkUHz7qEYNr8yKD/sN29un+Q0DPr+Tp4X0HufOSl9x/bqAlx mhpBSZBYkdhMqg/Eq8qGGmQgFPOzSWX1RkV3e8nGVoZv92I/Y4rquw1sD9p8L9/A2exE i2JFQgeZ6STGVZxGu/Icbdpp9qXvC0pKV8kpV9IzCC217z1VdrTjyPI1L2rwIS8I5EkX /+O9Dq+Cm2pDfSn4PyDSY79EvU5rLDh/swb3BQQ/tQ8wFAVjCj7BSazqdZCXH6q9bJqZ M2EQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=n2ELCBKlduOnR5wTkTQugicJX8taWF2bAtKMB7UJJcw=; fh=r7jucx4EDwcx4QmKdJY/B/BWs7eG+xdxvoZ3FO/I2uA=; b=Hl7gA2bA2a21Vyk2PzYR5hgG0UzG0xYrwVO408dN1qMJ1mNqMCtzDyyZlW1E4OPz0M Bs2J9UNjTSoIysHzsij+kHHU6P2NWbYqQ8wKWh2WzIJTOiz4d1eAVofqXHe2m9rDAR6O A9BTITrkqm7k+1b2syvYd3CELy+oeeZP6AAbwqxxsYxvV9TZ8fUIfkieQewKO69YktSb SM8hIwvXyPVevIqDUtrrC2jcm/QeoiRTkSNkNS5/Du9yIYzOXxW77Yar+EpnXfU/t38i RDZqpO1+/AAL9cqvVhO1206X+2OYeeroVSiiagOnFh19OSLmWQTHCrxlDF7CbtFc8BbQ iAXw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=sBJAxE5Z; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-181443-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181443-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6a15f30570bsi171267556d6.607.2024.05.16.11.22.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 11:22:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181443-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=sBJAxE5Z; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-181443-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181443-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 889741C21335 for ; Thu, 16 May 2024 18:22:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 60B9F158D6A; Thu, 16 May 2024 18:19:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="sBJAxE5Z" Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 E824E15746D; Thu, 16 May 2024 18:19:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715883574; cv=none; b=neknQf6Pf3THOF/SotvvXOQ+H3/ajnuP4x9jkNpsxE5sN7ANYliLHmeQ4pE+hMPOgObtznnCgXzf7UfXUvcubMomlmlY12MOnH+ejWpmZkoKDoHZx7qi2a3cDnvlLe/PJKVudcvH3e7c7v18uSg52n7sWWg1pZ4+41Z8HU7Zdk8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715883574; c=relaxed/simple; bh=VhedKvPFFiUAnj/wYMChhGaaPqdpO862oYKVIuAtwT8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s55vn3i+9TvQFRJ9Vr8pi9dXlQd1HD3H3x77vEpQ+y13upsGrbVOipmMrSpBxW3XmkCfytxSAmanUrd0f9n1ySimLS9xQI+Z6DOSw/Vl3toUMZfbjT0oGsSTJvBtG8jjrCNhTCA/+MLrgCETsleex7+PkkvXNVSuPoOHRNiGwqI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=sBJAxE5Z; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44GICPfw024570; Thu, 16 May 2024 18:19:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=n2ELCBKlduOnR5wTkTQugicJX8taWF2bAtKMB7UJJcw=; b=sBJAxE5ZoH6IdcpM1X7hY97NnK7sToMDpUx1x6/cCDi60IPOBRJU3mVdmt4wI+lppWE0 PLZhSbMCzsxktvtrR2CTzwNkW6Gub0pCFMzz880+iD1j8Sn0lhwNx48SgFgpz27ezyhk FVaNeqbPjkhsoxirDtTGXb3PpkywGWHiVZMaz9dJbrHT6tgwR8Ilrq8ieQnC9G+iWZA+ M/zYy+BvqAFHMPP/WS9gU+SpVKBFL/HELiYMi3v3pJ2QSbO6pVE8WxTxPLLgu6yl4Len 3V/7OVHD22NG2MytKVbhwIObh/ZsJvX28x9IeUOdgOGaicRAXvU+zdXVHW06G1uKA9OF 1g== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3y5q79g0bb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 May 2024 18:19:19 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 44GHkRCF006189; Thu, 16 May 2024 18:19:18 GMT Received: from smtprelay02.dal12v.mail.ibm.com ([172.16.1.4]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3y2mgmud37-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 May 2024 18:19:18 +0000 Received: from smtpav05.dal12v.mail.ibm.com (smtpav05.dal12v.mail.ibm.com [10.241.53.104]) by smtprelay02.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 44GIJFjv49807692 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 May 2024 18:19:17 GMT Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 59FA858075; Thu, 16 May 2024 18:19:15 +0000 (GMT) Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1B4D658077; Thu, 16 May 2024 18:19:15 +0000 (GMT) Received: from slate16.aus.stglabs.ibm.com (unknown [9.61.107.19]) by smtpav05.dal12v.mail.ibm.com (Postfix) with ESMTP; Thu, 16 May 2024 18:19:15 +0000 (GMT) From: Eddie James To: linux-fsi@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, linux-spi@vger.kernel.org, broonie@kernel.org, andi.shyti@kernel.org, joel@jms.id.au, alistair@popple.id.au, jk@ozlabs.org, andrew@codeconstruct.com.au, linux-aspeed@lists.ozlabs.org, eajames@linux.ibm.com Subject: [PATCH v3 26/40] i2c: fsi: Calculate clock divider from local bus frequency Date: Thu, 16 May 2024 13:18:53 -0500 Message-Id: <20240516181907.3468796-27-eajames@linux.ibm.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240516181907.3468796-1-eajames@linux.ibm.com> References: <20240516181907.3468796-1-eajames@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: bPWYMTGIlqxK3UuxeMX-IKBR1b99g0vy X-Proofpoint-GUID: bPWYMTGIlqxK3UuxeMX-IKBR1b99g0vy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-16_07,2024-05-15_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 adultscore=0 suspectscore=0 phishscore=0 mlxlogscore=977 impostorscore=0 spamscore=0 priorityscore=1501 bulkscore=0 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2405160132 Use the new FSI device local bus clock to calculate the proper i2c clock divder and look up an optional clock-frequency property from device tree. Change the default clock divider to 7 now that the default local bus clock divider has been reduced as well. Signed-off-by: Eddie James --- Changes since v2: - Change minimum clock div to 3 - Use DIV_ROUND_UP instead of re-implementing it - Better logic for checking for clock-frequency property drivers/i2c/busses/i2c-fsi.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c index 10332693edf0d..2404ace8c56fa 100644 --- a/drivers/i2c/busses/i2c-fsi.c +++ b/drivers/i2c/busses/i2c-fsi.c @@ -27,7 +27,8 @@ #define FSI_ENGID_I2C 0x7 -#define I2C_DEFAULT_CLK_DIV 6 +#define I2C_DEFAULT_CLK_DIV 7 +#define I2C_DEFAULT_CLK_RATE 400000 /* i2c registers */ #define I2C_FSI_FIFO 0x00 @@ -150,6 +151,7 @@ struct fsi_i2c_master { u8 fifo_size; struct list_head ports; struct mutex lock; + u32 clock_div; }; struct fsi_i2c_port { @@ -194,7 +196,7 @@ static int fsi_i2c_dev_init(struct fsi_i2c_master *i2c) if (rc) return rc; - mode |= FIELD_PREP(I2C_MODE_CLKDIV, I2C_DEFAULT_CLK_DIV); + mode |= FIELD_PREP(I2C_MODE_CLKDIV, i2c->clock_div); rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_MODE, &mode); if (rc) return rc; @@ -680,6 +682,7 @@ static int fsi_i2c_probe(struct device *dev) struct fsi_i2c_port *port; struct device_node *np; u32 port_no, ports, stat; + u32 lbus; int rc; i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); @@ -689,6 +692,19 @@ static int fsi_i2c_probe(struct device *dev) mutex_init(&i2c->lock); i2c->fsi = to_fsi_dev(dev); INIT_LIST_HEAD(&i2c->ports); + i2c->clock_div = I2C_DEFAULT_CLK_DIV; + + lbus = fsi_device_local_bus_frequency(i2c->fsi); + if (lbus) { + u32 clock; + + if (device_property_read_u32(dev, "clock-frequency", &clock) || !clock) + clock = I2C_DEFAULT_CLK_RATE; + + i2c->clock_div = DIV_ROUND_UP(DIV_ROUND_UP(lbus, clock), 4) - 1; + if (i2c->clock_div <= 2) + i2c->clock_div = 3; + } rc = fsi_i2c_dev_init(i2c); if (rc) -- 2.39.3