From patchwork Thu Oct 3 11:15:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Wu X-Patchwork-Id: 833443 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> 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-i2c@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?q?msS0566LFYXxXibuRtqVaaxzYhP6TMM?= =?utf-8?q?7s/QVyB4ztK1NmHXZJpXilJ7oC5nxWhvGDecUKxgjgdKJdvOzCOQjxaesYFecE1LZ?= =?utf-8?q?zjAuRIaIwqNgfaQJkpp5PmbxvqgHh9wKXGTyXdfS2KAF+mZrdRvPRF4Q/sr+d3RMa?= =?utf-8?q?bGncrdb0oOCm950Q8Gu2xBeP64TJOxLJhUVEEWuCE0cviglfst04QOpchmwVwO2MD?= =?utf-8?q?z4jFJQ9OrQseKHiTFDEqe3ByKj9GOz3GWSv9cDN4CMPy0ZHef0+hRBPNN0sntfCMJ?= =?utf-8?q?59d6UbMXtq6oo3v7PH/vBuK4m6EHxSe4FcUjX1hD2mKIUcLD8VQM4K9Fh17MGiSCd?= =?utf-8?q?Wsufup1EecPAYIanCfLLlBuzs1xk6ycRH2x98Pb4bqrYRY/u3hTokELW4LKzTt2pq?= =?utf-8?q?h31GtrLSH3zz/efX4alhHLiLC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pdFYV+vqoi7d49odzrZpZXOWPTc2dAnY+S?= =?utf-8?q?XsUxiTTP/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?q?yDQmpscwearpi9B+SPAlDe9ucBf1?= =?utf-8?q?b7N7plreLSDgpa1qEmYVZOt4Lz5teTIUJFAygqfzXBJg3jgto4Yqu/Bffz22EkBlq?= =?utf-8?q?EiQdLjSKjGFPfl6Map60gTGM90VlAFgfLhuB7N3thbKDz6TypnYjpTQe1fvUKQ+pR?= =?utf-8?q?y+6bzougHTlLvtCRdckKWzjQyrrPAGnFeC5Fp5OiinQYbaG4HiXYgjzcEB48t46on?= =?utf-8?q?cJTVikFGfcEJa29mYIMfLKOju50Isge+eDKjzjq+0MbVInw1K/k991IH5iW4QXwap?= =?utf-8?q?5k+xkZp2go486D9LlqdQbvS9846hIY1GLM12dyR5HYp3nruptQx9AOtcDzh5in4lc?= =?utf-8?q?Qr/qTy8bPPR6MF7h88mEQgqH2u5Ht2NgDwDpmmCRpeoBrK7YdjqVApicAG5GzkKGP?= =?utf-8?q?XCOBmZgk6rZZrMS30wrX01ATNLZ2SRKI05S9teAK7xhukAjnWs3m3cU+vE+lcy6mA?= =?utf-8?q?iIYJC+N35TetaFcghQojw6ZL8OJDNUISOFPnoofrLa8g2uvTtj7qZ22tmfgj5aTbe?= =?utf-8?q?MFrjT1u3sRKe4EyLAbTLQwkOHUP5clBphxUwdK6q/J+D7fx3BDVAPx7SMt4OhdLPE?= =?utf-8?q?KQvGuCnLZYdq59C/i7Kilt34Z/YYx36Fh4HsMySjzfb9hmuL+k4/W3ePQc8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XMMP?= =?utf-8?q?4VPYLkDjvA6+?= 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 = 160 and tLOW = 120. 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 = 0, MIN_SCL_HIGHtime = 60 ns for 3.4 Mbps, bus loading = 100pF = 120 ns for 3.4 Mbps, bus loading = 400pF MIN_SCL_LOWtime = 160 ns for 3.4 Mbps, bus loading = 100pF = 320 ns for 3.4 Mbps, bus loading = 400pF and section 3.15.4.6 says that when IC_CLK_FREQ_OPTIMIZATION = 1, MIN_SCL_HIGHtime = 60 ns for 3.4 Mbps, bus loading = 100pF = 160 ns for 3.4 Mbps, bus loading = 400pF MIN_SCL_LOWtime = 120 ns for 3.4 Mbps, bus loading = 100pF = 320 ns for 3.4 Mbps, bus loading = 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 --- 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/busses/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 *dev) i2c_parse_fw_timings(device, t, false); + if (device_property_read_u32(device, "snps,bus-capacitance-pf", &dev->bus_capacitance_pF)) + dev->bus_capacitance_pF = 100; + + dev->clk_freq_optimized = device_property_read_bool(device, "snps,clk-freq-optimized"); + i2c_dw_adjust_bus_speed(dev); 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²C GPIO recovery information + * @bus_capacitance_pF: bus capacitance in picofarads + * @clk_freq_optimized: if this value is true, it means the hardware reduces + * 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; }; #define ACCESS_INTR_MASK BIT(0) diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/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_dev *dev) dev->hs_hcnt = 0; dev->hs_lcnt = 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 >= 400) { + /* assume bus capacitance is 400pF */ + t_high = dev->clk_freq_optimized ? 160 : 120; + t_low = 320; + } else { + /* assume bus capacitance is 100pF */ + t_high = 60; + t_low = dev->clk_freq_optimized ? 120 : 160; + } + ic_clk = i2c_dw_clk_rate(dev); dev->hs_hcnt = i2c_dw_scl_hcnt(dev, DW_IC_HS_SCL_HCNT, ic_clk, - 160, /* tHIGH = 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 = 320 ns */ + t_low, scl_falling_time, 0); /* No offset */ }