From patchwork Thu Feb 15 22:07:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 201795 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp154008dyb; Thu, 15 Feb 2024 14:16:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW2uosWCJrh4mQG0MX10RxKadJGTJkx85QZdHbJI2WptR6ornBzmqSyJaMYU31lFwtqOiV14SjUGWf/XTl90d9zOYKR9Q== X-Google-Smtp-Source: AGHT+IGBrSUudzk8KpDEwEA+dq+23rujye0oCFdhL8DTEcqiwireUXc/dHXQyIMPKpjLZqjgupIY X-Received: by 2002:ac8:7d03:0:b0:42b:ff38:775d with SMTP id g3-20020ac87d03000000b0042bff38775dmr4275103qtb.58.1708035383808; Thu, 15 Feb 2024 14:16:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708035383; cv=pass; d=google.com; s=arc-20160816; b=CtbdxWWGlyEnT4xJytCX7x3IyWCYWXYJdAtP/audtwZ3aCTcM/9LJzkmEKSmkKHuYw UF6rqJ7dMKbUhj5lq7dQccCEY4CZKzYia0oAWHvwNcRseFSj5BLgtmK6zZFWII4i4tlC FDRFK3PuRUxJsv8rqeAHNqyMe+icvbZGQv5THnNEB3TVp60CWJMVO7ZUTsl5p/KwXAJZ G7LWkBj55Ph1lcNr3SGCxXNVRz+QaU58zgdEJezAwf8og2CtaKoVSiQDD3UJJk0w9jrP efnosuDsA2cNzQkPcZmVnW95UGwQBPxmbTOeYlpXUa4Jnn7i7DrmJBZp4e8tlWXLMQEt iJWg== 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=0qbOHG7gDL7BluVHG6aIFuWkCkqtnciMO6tHFzvcS9c=; fh=Usz7XAB1EI7Q/DdLEXd449E1MLGpSzqdCCNe5XKh9R0=; b=SKc740l0bg11MBD8ClGqRR7ZEU3ZlRgrpyWptrEKUZYxHjChynMM/lmKUBcsLNuysn wVM2n/jwPaIzDGaOGzZdcszMCYltr8TvICniVxD+26JChPkMzZWwH8pJDVD6nQCvD5sl inTO2WZ+7ZASX3ynIYB6cZJ0BjurytY7PV2oBxcnybglrmZwaTfPnRRrD8y/BAOgHMAD cHxigmw9441io5qYsR73/iyQWQDpO7yCqi8meqxJhugltyt2PwwOuNAzM7lox13RQXWn 0nT0R27V2nHLa7LAfPokDryoMpCyTEIbapEpy+VmDQ3WIKEyTl6hh8+pFjxTeLbLIzTq BzyQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=e8MRdMO1; 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-67762-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67762-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 8-20020ac85648000000b0042c6ff662bcsi2282761qtt.257.2024.02.15.14.16.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 14:16:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67762-ouuuleilei=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=e8MRdMO1; 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-67762-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67762-ouuuleilei=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 86FD91C2149D for ; Thu, 15 Feb 2024 22:16:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B190D153513; Thu, 15 Feb 2024 22:08:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="e8MRdMO1" Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 9886214C592; Thu, 15 Feb 2024 22:08:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708034916; cv=none; b=gUF76IVwjQp1Qf9jrsf/3clcGLrnQG+BDZpLwOffIJ+XRZ8XyGUPa6ZcvCC5dnf6TeOtlq7dOa2vBY+PwUAa2GgTixmvXeyiCaeDhd7gTfOuNBvrFiUhwhOrJ7QPfIkv8OABE1qKL6/bgqWdWYeRqoDTCvYTUTHo1ilaBUze+A8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708034916; c=relaxed/simple; bh=T+M2Nn1CbVzGiWWZ25GQh8RxyvzQFAsyFI0vKdVAGuc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qGjt35gI4lb6QEw0zVacBhFik2zpgRxP+Y4Z1QXIWvyDthcCJiXI2/1II3VG5tKrnICr56mMayMCcE9TffO6Eoj5JN3gKw0VnGx3SdmIfBwIgKUhMTbWddTpRVJL9uiPaaVweRDrPmPLpGhd3pCin4848TRhxUVp00yAJ8FdK38= 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=e8MRdMO1; arc=none smtp.client-ip=148.163.158.5 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 (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41FK8lQW002054; Thu, 15 Feb 2024 22:08:15 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=0qbOHG7gDL7BluVHG6aIFuWkCkqtnciMO6tHFzvcS9c=; b=e8MRdMO1hbaviK8k/hers7rurq0QRJrMnBOOoCLA4AA64rghHbfTqBzZ5PpXXFhAQOvQ KX54O/WqsBKKnQzcVxjevUJ7XZEHh5wnGqrI3mjT1SApYpasla4jrJIFwqr/N7Opr2BL kGuM5qq340KaZkBpp6m8HvlPdb83nMx4s6tCC3eatDSh3hB3Od4M2i6fcFHOtG2rtpme RAYC6iXxAnU5oePkB7nNsAPsm8UjllfEOwn+JJoECvZDCstKiJXdlyK8brK88IFCmzFd 0OTe1HUqr3mu9o/QoWY3RLRDRiCRip1yjkM2XLa3MC6KqcP3FQL0bJ1zvMzkimZVswt2 cg== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3w9q8n59ad-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Feb 2024 22:08:14 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 41FJAQbL032596; Thu, 15 Feb 2024 22:08:14 GMT Received: from smtprelay04.dal12v.mail.ibm.com ([172.16.1.6]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3w6kftyuem-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Feb 2024 22:08:14 +0000 Received: from smtpav03.dal12v.mail.ibm.com (smtpav03.dal12v.mail.ibm.com [10.241.53.102]) by smtprelay04.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41FM8BZE19727026 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 15 Feb 2024 22:08:13 GMT Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7FA1958070; Thu, 15 Feb 2024 22:08:11 +0000 (GMT) Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 35DFA5807F; Thu, 15 Feb 2024 22:08:11 +0000 (GMT) Received: from slate16.aus.stglabs.ibm.com (unknown [9.61.14.18]) by smtpav03.dal12v.mail.ibm.com (Postfix) with ESMTP; Thu, 15 Feb 2024 22:08:11 +0000 (GMT) From: Eddie James To: linux-fsi@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, andi.shyti@kernel.org, eajames@linux.ibm.com, alistair@popple.id.au, joel@jms.id.au, jk@ozlabs.org, sboyd@kernel.org, mturquette@baylibre.com, robh@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org Subject: [PATCH 27/33] i2c: fsi: Calculate clock divider from local bus frequency Date: Thu, 15 Feb 2024 16:07:53 -0600 Message-Id: <20240215220759.976998-28-eajames@linux.ibm.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240215220759.976998-1-eajames@linux.ibm.com> References: <20240215220759.976998-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 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: h1yX6zc4QTXOHVkx21FJWZcSkuntX65z X-Proofpoint-ORIG-GUID: h1yX6zc4QTXOHVkx21FJWZcSkuntX65z X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-15_20,2024-02-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxlogscore=956 impostorscore=0 adultscore=0 suspectscore=0 bulkscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402150171 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791004910187607620 X-GMAIL-MSGID: 1791004910187607620 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 --- drivers/i2c/busses/i2c-fsi.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c index 10332693edf0..eaecf156ac31 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,20 @@ 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 = I2C_DEFAULT_CLK_RATE; + + if (!device_property_read_u32(dev, "clock-frequency", &clock)) { + if (!clock) + clock = I2C_DEFAULT_CLK_RATE; + } + + // i2c clock rate = local bus clock / (4 * (i2c clock div + 1)) + i2c->clock_div = (((lbus + (clock - 1)) / clock) / 4) - 1; + } rc = fsi_i2c_dev_init(i2c); if (rc)