From nobody Thu Nov 28 08:48:38 2024 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2118.outbound.protection.outlook.com [40.107.237.118]) (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 AF63A170A15; Thu, 3 Oct 2024 11:16:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.118 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727954165; cv=fail; b=f40rAfXhRHOW+Q6ds3tMEyvN6Hp0GiVcP5eO8kO9nzvos7PzvK+5Dnlo1E11/YZDGo9rnBQLvuDi0Omdg7ZdVx3YVqwreWVT0QuEFd8uY5fDzERLgMBeoNUWyaqiwHC9oGPvHxJOTptZvVUA6g9/26q1J9Yex+zeh4EybpWmyDs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727954165; c=relaxed/simple; bh=U+B+1q7ZDeKvodRNEcYQ7I7bojSjXDHdNavB9zboOmY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=aA7j6ssKWA7PLLt22R+adProvz2Q2twl8INH+KM1KSF0tn2XL/tKy5S91nBftD0kVrEm67Lf5x/5eWjnEQLgUhoZ4HalgpDoObLxnLZ8UgbObw1oTfLwR9pczO8y+jihD6b8oagEvXuyOSCy+92KChsrR9oRrty9+yZmS3Nq36w= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kneron.us; spf=pass smtp.mailfrom=kneron.us; dkim=pass (1024-bit key) header.d=kneron.us header.i=@kneron.us header.b=GxNC82Hc; arc=fail smtp.client-ip=40.107.237.118 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kneron.us Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kneron.us Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=kneron.us header.i=@kneron.us header.b="GxNC82Hc" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hxhxH3t9NwmSjWnL/8fluwXHCrP1PYz8HY4QM9srlTOKACmsLDYQpqYQ6L+kory+hh+xWJKY60tWUpzIDN1bRAAEWrsXYX4bvaHlvrnLrPPgVUYmQkdZ2UjYsKWs785FjfWK3jCJHXeH19WxjiVa6xaJKW0xpiZlu5+WKhDiadK0GNRrCfBAtayi2P1UtkG4NfO8YASE/biGlTqbTOedyOMCQYBvatEkswTeiXZYUwk7nAk5HLtAzu3scJHq5wosJjq40xUi2pTO+YfN4bg+nfVamK+lvJtGb++TxGa3WhjMQtCNlpl1Mk9csjaJF/jJgoCUDa7LrLAFGFKFgFbjcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iDEe8WK7zt+LJRP5DnUfSE79XWyttZ5+iNLC5RxLMtQ=; b=y2f4X61qo/hNvyYI8rSfpX4aqeioEnuqOhfs3Q1fwHoLdIfNmTjlZplo9AWpnyuD5QnCUzXm/6lDCWA1uanhYrYSIzbsj0Vo+MSYi4wKC0+u0t8/eRIJbhmxcxHUuOyP30mR/XFoCbQaeiBdwLw0DqzECCWPaTeZ1HIk58Ptn5MvZLyFA1LdyQGY4pNFJ7bGwcsXjROGE9SsuOqmMTTbEh+uH+HWyjxRrZcYAOdewuBzIbNRQnf/88wRjF4LpwN5i91tGBkX29Ge1QlmpiCRlZGP7BN3G3VSamHCJJLMHBFw5TnBllBoBI/5J7LOv5T0B9xmzXKymomLAsHy2k1b1A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=kneron.us; dmarc=pass action=none header.from=kneron.us; dkim=pass header.d=kneron.us; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kneron.us; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iDEe8WK7zt+LJRP5DnUfSE79XWyttZ5+iNLC5RxLMtQ=; b=GxNC82Hc8LE5C6Q7EcLAnaHmqfu6a+Upfv0WzCy/s9SahzpHKWqGKtlolPjSd+ojGA7R22m2XTD6Dyvq6edvdNCZRJtwZDSGl1CwQJNMe7lopc/opZWzD6jvnXqt9upHrPKuxdb9S+MBJB564pTCZK3VBZMC6atnGouFnRrMEEc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=kneron.us; Received: from IA1PR14MB6224.namprd14.prod.outlook.com (2603:10b6:208:42b::6) by BL0PR14MB3714.namprd14.prod.outlook.com (2603:10b6:208:1ce::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.18; Thu, 3 Oct 2024 11:16:00 +0000 Received: from IA1PR14MB6224.namprd14.prod.outlook.com ([fe80::c527:653c:698d:3d94]) by IA1PR14MB6224.namprd14.prod.outlook.com ([fe80::c527:653c:698d:3d94%3]) with mapi id 15.20.8026.016; Thu, 3 Oct 2024 11:16:00 +0000 From: Michael Wu To: Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jarkko Nikula , Andy Shevchenko , Mika Westerberg , Jan Dabros , linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Morgan Chang , mvp.kutali@gmail.com, Michael Wu Subject: [PATCH v4 2/2] i2c: dwsignware: determine HS tHIGH and tLOW based on HW parameters Date: Thu, 3 Oct 2024 19:15:24 +0800 Message-ID: <20241003111525.779410-3-michael.wu@kneron.us> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241003111525.779410-1-michael.wu@kneron.us> References: <20241003111525.779410-1-michael.wu@kneron.us> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: TP0P295CA0055.TWNP295.PROD.OUTLOOK.COM (2603:1096:910:3::11) To IA1PR14MB6224.namprd14.prod.outlook.com (2603:10b6:208:42b::6) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: IA1PR14MB6224:EE_|BL0PR14MB3714:EE_ X-MS-Office365-Filtering-Correlation-Id: 333027e3-9f60-419f-9f8d-08dce39cc2ad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|52116014|7416014|376014|1800799024|921020|80162021|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?bXNTMDU2NkxGWVh4WGlidVJ0cVZhYXh6WWhQNlRNTTdzL1FWeUI0enRLMU5t?= =?utf-8?B?SFhaSnBYaWxKN29DNW54V2h2R0RlY1VLeGdqZ2RLSmR2T3pDT1FqeGFlc1lG?= =?utf-8?B?ZWNFMUxaempBdVJJYUl3cU5nZmFRSmtwcDVQbWJ4dnFnSGg5d0tYR1R5WGRm?= =?utf-8?B?UzJLQUYrbVpyZFJ2UFJGNFEvc3IrZDNSTWFiR25jcmRiMG9PQ205NTBROEd1?= =?utf-8?B?MnhCZVA2NFRKT3hMSmhVVkVFV3VDRTBjdmlnbGZzdDA0UU9wY2htd1Z3TzJN?= =?utf-8?B?RHo0akZKUTlPclFzZUtIaVRGREVxZTNCeUtqOUdPejNHV1N2OWNETjRDTVB5?= =?utf-8?B?MFpIZWYwK2hSQlBOTjBzbnRmQ01KNTlkNlViTVh0cTZvbzN2N1BIL3ZCdUs0?= =?utf-8?B?bTZFSHhTZTRGY1VqWDFoRDJtS0lVY0xEOFZRTTRLOUZoMTdNR2lTQ2RXc3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YzNEVy91dGRrbU5LcUdm?= =?utf-8?B?SlpGdmpxUVJxUlJsbHJUZFZvNW10WVgwNE44MXlnTUQxSlpDb2dHUDFmTHRq?= =?utf-8?B?MEk5dkp4QzdRbktWaHlMM2VnenJZL1F6OWlUMlNFTU96eHk2UkVFcDFrQzk0?= =?utf-8?B?SVRJV0NmbVF4T0xRTTh3K3Bvd1dxKzlGTVFrKzhTdGZ0ejFaRUdDUFpMOUxu?= =?utf-8?B?QmVhOEE2MU1qRnlndld6cEhyMm11MHRwbERMbzU3SzZKaUh4cTRCWFVlaFpZ?= =?utf-8?B?TW1TNlFyaFFQYmQ4N0YrWjFFNXZpa1Z5ZWNnZm9pMFMxcTBod0lQMU44NFZx?= =?utf-8?B?TkljR3lWZlVWL0xUU002bmw0RHJJcE1VSWlyTFJzdDgrSVZxRmt1c1M1cWQ2?= =?utf-8?B?L0MxWkV5bkw3cVREZWVJYU0wZUxkaFBiRXB4MXpmM2RhN0hxZWlyNGpGSzJ5?= =?utf-8?B?MXY3ZjZXdEJpdjl4cGRGWVYrdnFvaTdkNDlvZHpyWnBaWE9XUFRjMmRBblkr?= =?utf-8?Q?SXsUxiTTP/juC?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:IA1PR14MB6224.namprd14.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(52116014)(7416014)(376014)(1800799024)(921020)(80162021)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?eURRbXBzY3dlYXJwaTlCK1NQQWxEZTl1Y0JmMWI3TjdwbHJlTFNEZ3BhMXFF?= =?utf-8?B?bVlWWk90NEx6NXRlVElVSkZBeWdxZnpYQkpnM2pndG80WXF1L0JmZnoyMkVr?= =?utf-8?B?QmxxRWlRZExqU0tqR0ZQZmw2TWFwNjBnVEdNOTBWbEFG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MkFocHZVZm9nMDNiU0c2YkRrZUNvZ2QxRThDdkFP?= =?utf-8?B?aWlSSldnalJHZjcvYmlHM3p0UzJhT3RiNXNpSktXeWJNYWs0OWloek91YjVa?= =?utf-8?B?cGdZTXUrMXM1YkFKcHAxMUhHa1RGRktmOGIrd0lLQlVQZE5zdDZXNW56bmU4?= =?utf-8?Q?TBEX/G1QNXMMP4VPYLkDjvA6+?= X-OriginatorOrg: kneron.us X-MS-Exchange-CrossTenant-Network-Message-Id: 333027e3-9f60-419f-9f8d-08dce39cc2ad X-MS-Exchange-CrossTenant-AuthSource: IA1PR14MB6224.namprd14.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2024 11:16:00.5397 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f92b0f4b-650a-4d8a-bae3-0e64697d65f2 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Y9HRhaNhq1af7pNTu0jCDHVMBMK1EOa7SP7B6k23UIxTZUsgJDASKTHFvP1mOB9IlHpzxWKaDHxBzmonDQ+tpA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR14MB3714 In commit 35eba185fd1a ("i2c: designware: Calculate SCL timing parameter for High Speed Mode") the SCL high period count and low period count for high speed mode are calculated based on fixed tHIGH =3D 160 and tLOW =3D 12= 0. However, the set of two fixed values is only applicable to the combination of hardware parameters IC_CAP_LOADING is 400 and IC_CLK_FREQ_OPTIMIZATION is true. Outside of this combination, the SCL frequency may not reach 3.4 MHz because the fixed tHIGH and tLOW are not small enough. If IC_CAP_LOADING is 400, it means the bus capacitance is 400pF; Otherwise, 100 pF. If IC_CLK_FREQ_OPTIMIZATION is true, it means that the hardware reduces its internal clock frequency by reducing the internal latency required to generate the high period and low period of the SCL line. Section 3.15.4.5 in DesignWare DW_apb_i2b Databook v2.03 says that when IC_CLK_FREQ_OPTIMIZATION =3D 0, MIN_SCL_HIGHtime =3D 60 ns for 3.4 Mbps, bus loading =3D 100pF =3D 120 ns for 3.4 Mbps, bus loading =3D 400pF MIN_SCL_LOWtime =3D 160 ns for 3.4 Mbps, bus loading =3D 100pF =3D 320 ns for 3.4 Mbps, bus loading =3D 400pF and section 3.15.4.6 says that when IC_CLK_FREQ_OPTIMIZATION =3D 1, MIN_SCL_HIGHtime =3D 60 ns for 3.4 Mbps, bus loading =3D 100pF =3D 160 ns for 3.4 Mbps, bus loading =3D 400pF MIN_SCL_LOWtime =3D 120 ns for 3.4 Mbps, bus loading =3D 100pF =3D 320 ns for 3.4 Mbps, bus loading =3D 400pF In order to calculate more accurate SCL high period count and low period count for high speed mode, two hardware parameters IC_CAP_LOADING and IC_CLK_FREQ_OPTIMIZATION must be considered together. Since there're no registers controlliing these these two hardware parameters, users can declare them in the device tree so that the driver can obtain them. Signed-off-by: Michael Wu Acked-by: Jarkko Nikula Reviewed-by: Andy Shevchenko --- drivers/i2c/busses/i2c-designware-common.c | 5 +++++ drivers/i2c/busses/i2c-designware-core.h | 6 ++++++ drivers/i2c/busses/i2c-designware-master.c | 23 ++++++++++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busse= s/i2c-designware-common.c index 080204182bb5..ff3d83269ee7 100644 --- a/drivers/i2c/busses/i2c-designware-common.c +++ b/drivers/i2c/busses/i2c-designware-common.c @@ -380,6 +380,11 @@ int i2c_dw_fw_parse_and_configure(struct dw_i2c_dev *d= ev) =20 i2c_parse_fw_timings(device, t, false); =20 + if (device_property_read_u32(device, "snps,bus-capacitance-pf", &dev->bus= _capacitance_pF)) + dev->bus_capacitance_pF =3D 100; + + dev->clk_freq_optimized =3D device_property_read_bool(device, "snps,clk-f= req-optimized"); + i2c_dw_adjust_bus_speed(dev); =20 if (is_of_node(fwnode)) diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/= i2c-designware-core.h index 1ac2afd03a0a..d09e6ffb793d 100644 --- a/drivers/i2c/busses/i2c-designware-core.h +++ b/drivers/i2c/busses/i2c-designware-core.h @@ -240,6 +240,10 @@ struct reset_control; * @set_sda_hold_time: callback to retrieve IP specific SDA hold timing * @mode: operation mode - DW_IC_MASTER or DW_IC_SLAVE * @rinfo: I=C2=B2C GPIO recovery information + * @bus_capacitance_pF: bus capacitance in picofarads + * @clk_freq_optimized: if this value is true, it means the hardware reduc= es + * its internal clock frequency by reducing the internal latency required + * to generate the high period and low period of SCL line. * * HCNT and LCNT parameters can be used if the platform knows more accurate * values than the one computed based only on the input clock frequency. @@ -297,6 +301,8 @@ struct dw_i2c_dev { int (*set_sda_hold_time)(struct dw_i2c_dev *dev); int mode; struct i2c_bus_recovery_info rinfo; + u32 bus_capacitance_pF; + bool clk_freq_optimized; }; =20 #define ACCESS_INTR_MASK BIT(0) diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busse= s/i2c-designware-master.c index e46f1b22c360..b56f33297d5d 100644 --- a/drivers/i2c/busses/i2c-designware-master.c +++ b/drivers/i2c/busses/i2c-designware-master.c @@ -154,12 +154,31 @@ static int i2c_dw_set_timings_master(struct dw_i2c_de= v *dev) dev->hs_hcnt =3D 0; dev->hs_lcnt =3D 0; } else if (!dev->hs_hcnt || !dev->hs_lcnt) { + u32 t_high, t_low; + + /* + * The legal values stated in the databook for bus + * capacitance are only 100pF and 400pF. + * If dev->bus_capacitance_pF is greater than or equals + * to 400, t_high and t_low are assumed to be + * appropriate values for 400pF, otherwise 100pF. + */ + if (dev->bus_capacitance_pF >=3D 400) { + /* assume bus capacitance is 400pF */ + t_high =3D dev->clk_freq_optimized ? 160 : 120; + t_low =3D 320; + } else { + /* assume bus capacitance is 100pF */ + t_high =3D 60; + t_low =3D dev->clk_freq_optimized ? 120 : 160; + } + ic_clk =3D i2c_dw_clk_rate(dev); dev->hs_hcnt =3D i2c_dw_scl_hcnt(dev, DW_IC_HS_SCL_HCNT, ic_clk, - 160, /* tHIGH =3D 160 ns */ + t_high, sda_falling_time, 0, /* DW default */ 0); /* No offset */ @@ -167,7 +186,7 @@ static int i2c_dw_set_timings_master(struct dw_i2c_dev = *dev) i2c_dw_scl_lcnt(dev, DW_IC_HS_SCL_LCNT, ic_clk, - 320, /* tLOW =3D 320 ns */ + t_low, scl_falling_time, 0); /* No offset */ } --=20 2.43.0