From patchwork Tue Sep 17 19:25:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13806434 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2073.outbound.protection.outlook.com [40.107.22.73]) (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 8159F14A0A9 for ; Tue, 17 Sep 2024 19:25:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726601130; cv=fail; b=KGltTasgzuxSbl2jfSmVGFEmTeB8UsrnwrWmVt7QEvNwSOEru27CrXxIp6RhB2U9YYSocATOZqvZIHkXnb9URfKy8Pi/l9a1NDExO5tjoEuTD7s9XCadtY4iRIeNSQbzJp2SsqLYqDvMnjaqdoR0TtnNBEI8p5vjfqB3qe5HfQ8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726601130; c=relaxed/simple; bh=wSFzGHKe/hgZ8kMG92hZ9jPo//ANSFpE0e3tAwI489c=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=HPE4dH57L5ahWaieHkQgz1LWN3uzE6mNv6dPU/LLLVGbBpHinRcIEHuHJ81dTine+zxBAfFvDDdBoXGzq8DLGlzgKG0G33PzDD+jflZzZTjfcY8UtZtfQosHvZEHwfFOT8opz84BlR6wdulTOq3aLYtPOP/DdJhoUAyw31s6MXs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=PfwhWJuT; arc=fail smtp.client-ip=40.107.22.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="PfwhWJuT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iCv5dnFJJvRx/Ozgt/UsH9PLzEuZYw43EnO2bNZn4FR/hzNkh6b0jl2x/Tf5gJ2P1+f6PIEQpYsfvzCi/dJg5s1XasclsHc5SSF+tYNHwCnvly61ADEHFHlFBKhNlnB/KAFI+JM1qsyMRnzkAxYU4z7w9cF2Gvl+7nQtQlI+ZZ0QYCEb/ruX34cQgOV/ZZZxK/YzQoK4HHer5o3btwkgdIoJVp0Tpw9HhRqvBIEzsJWjtxRPv4/A99mZk3sVKhrLHgWne1y951bojA64/sxchIzWhknJvZPumvHTfBX0TRGluDzMkelFLu4ggqWp/K0f6/Jd+DrshhssY2MO+0aOpw== 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=4Q5RFAb0bcllYmPLhhzRlQ2AC2NOAzUEWBxZ/kYXeaE=; b=yRb7nsw/nI5qT3tGWl15yvNJF/0qhwHTA7qYMP26ICw/f0veYnxSzUwkA9oiO5Sm+e6xYCeVu3NDHzCK1Kga9SCX1gijL6Y9CNlefY7mckQN3oGGGRq51sWX/Js3vAasF6gsYWu9jkPZMDmZNU8Lv1JS0pJdFemNHNeITJU3Yq4I1N/KCea209mW8/x0wX4khutzPycSFXZa2r+JeGhoUUxu6EnGTbBCqFAw8DBwhYgzf72EmsNm8PSw/nmdQzHvJoO4NDYFjz7AelHAogATPl2983K0RKTZzgTJYXrKRVmhL2DWu5/0RGUoJleq1kHtIwNs/s6aPjFU4CuIcFpJsA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4Q5RFAb0bcllYmPLhhzRlQ2AC2NOAzUEWBxZ/kYXeaE=; b=PfwhWJuTNL/Kt1nK4F1Xf3lfv/EACJpe7ljgfp58kojNhVyylA9jHLNl9jJoQmwbCz7J6lOq6o//jX0znBB7eHThrXBPNxrX5/G9D4y6MxSz/3sgOheq0LoDMwtOS7Tk1pOZD6j7M4jRy6z5DbGEpvmvvpkYn9465sDOTTR2Z/WfC/Pd4TW1ILhtWx9RhMss8wR3ud/NI24HlX4dAfWJvjQV+bbyfvb79dUZh/CJFCA37T/+jzHXTQwtroa3I6ZkLJBgaeyhS3K9YXwT+X47BmaIk8DSby7URsBK0OcxUXr4+tTWNiBl94RjoBaZnMBA54DQ7Gg9BXLNz7nwFPHZYw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by AS8PR04MB7992.eurprd04.prod.outlook.com (2603:10a6:20b:2a4::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.24; Tue, 17 Sep 2024 19:25:25 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.7962.022; Tue, 17 Sep 2024 19:25:25 +0000 From: Frank Li To: marex@denx.de Cc: Frank.Li@nxp.com, conor+dt@kernel.org, devicetree@vger.kernel.org, festevam@gmail.com, francesco@dolcini.it, imx@lists.linux.dev, jun.li@nxp.com, kernel@pengutronix.de, krzk+dt@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, p.zabel@pengutronix.de, pratikmanvar09@gmail.com, robh@kernel.org, s.hauer@pengutronix.de, shawnguo@kernel.org, ukleinek@kernel.org, xiaoning.wang@nxp.com Subject: [PATCH v6 1/1] pwm: imx27: workaround of the pwm output bug when decrease the duty cycle Date: Tue, 17 Sep 2024 15:25:10 -0400 Message-Id: <20240917192510.3031493-1-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SJ0PR05CA0048.namprd05.prod.outlook.com (2603:10b6:a03:33f::23) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AS8PR04MB7992:EE_ X-MS-Office365-Filtering-Correlation-Id: 1de84318-b28b-4f75-81d7-08dcd74e7aff X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|366016|7416014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?SFAF3GA0Yhj/zlkxN9/iBsNHTJ/A9fj?= =?utf-8?q?eAAjqjU/awpDPGi6nQnYffUNjDRZgi9yXs9Nf+ldLltaOOAtvI5/4yve55Sxd2COi?= =?utf-8?q?1qbta0OhxoPaLjJu/i6Ef+cHnxrM9cusiPaPH/4IcPbNbxuXOGhOZWn0pfoDMdrJW?= =?utf-8?q?AN8XTFc22c9g/YLWzkwhd3rKGT2YytepKJj6hKwyroIQYoiy+XWYWWLyc9niHlj1L?= =?utf-8?q?78qhzL+5j7vD2gnFmH9jkChQ3jm3LNUxy5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zsP2jN/Afo5Op6eyJImujdfRJPN?= =?utf-8?q?ANRp2xoVxl+YKRt9w0SvWsdoCNQ/iUXSQttMUI0ZybXvJmvmXTHK3JF3f+6oAkusX?= =?utf-8?q?rxpCPk37vGT0tiqgOcdFDptTtAbiUOfZsQsiaqNzDT1RXzEaAbQoil97oTJqKs+kR?= =?utf-8?q?JIlW7w+wq76jafgBvwAdPuDbvCFPOyRdYJXghrP2E6Wb709zGdnX0lw8RiwERbDsG?= =?utf-8?q?5llrPGOt/2+Ja+hjMHptVYIktgaSLiwt9w=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(52116014)(366016)(7416014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?aJrJOLfeOi0pwXqKDSle9/jhxvsa?= =?utf-8?q?BT20/MG0zflrtWj3LR2vTZvSYVuGLqLgevyZIN5FNieC32yuRkZ27FU6DmZv2Ns83?= =?utf-8?q?dqOMUoJDf7chsoLm4gI8ML1rYgO6iwrZD0Xl4CvAnNBzFa5ns0A4+xQzMdQBa+4pG?= =?utf-8?q?ekxnzUJoZA38LJg0pN2TBM0z06CUU8FQFxb3sFRuFYgehzhf3P+sWxmmp0lTqlsgf?= =?utf-8?q?uDEHLw4yHa42qVJFnYnq/q2dhhDRwlTdgnVk/Y2aN4KhKUhxg/baG2vbRnOCpKtAV?= =?utf-8?q?iSytvC3bNDLgkq3wDT4ogxC8ITDya1z51e++BExEKDZSMD3tH0Sqg0CYfC8gThPgD?= =?utf-8?q?Js2S4uAU8KTtOf3MJ98cQHQZvSnWRyPvzBxc7znGJsmQ0UJ4tkigCm5pIPeJpq5eg?= =?utf-8?q?RlLdkMPFdfFQmgm1CUvex7/V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wyHme0da35rEzFBo5WLYCZobD7XJEex?= =?utf-8?q?+zqC/iADKKLjZFHEVlK4m2v2EXUUqxaf4o00SgAskFSj/gaWpRZlA+ptYYxC6fvWN?= =?utf-8?q?MsHMGRXP3djMNyj+ydBzd/p2tppNeyMR6qo56++NV0qRvluiMK2C7vb4tnihTvJXj?= =?utf-8?q?36tPPS1Xv6/vz7HGRBXK8lM6eDq853GmemI8H7Hd/CPyO4oE3udVVnZStNn9/q12Y?= =?utf-8?q?BLz/cfc0e2P2?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1de84318-b28b-4f75-81d7-08dcd74e7aff X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2024 19:25:25.2181 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /HyVIY+QV8DJP6JzsRXgWailiONYpNdAyu8AnrMXN++hFq5+tIp94L7UEvE5AQiL8p/4/UdEyX4IDmsMPjeFSg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7992 From: Clark Wang Implement workaround for ERR051198 (https://www.nxp.com/docs/en/errata/IMX8MN_0N14Y.pdf) PWM output may not function correctly if the FIFO is empty when a new SAR value is programmed Description: When the PWM FIFO is empty, a new value programmed to the PWM Sample register (PWM_PWMSAR) will be directly applied even if the current timer period has not expired. If the new SAMPLE value programmed in the PWM_PWMSAR register is less than the previous value, and the PWM counter register (PWM_PWMCNR) that contains the current COUNT value is greater than the new programmed SAMPLE value, the current period will not flip the level. This may result in an output pulse with a duty cycle of 100%. Workaround: Program the current SAMPLE value in the PWM_PWMSAR register before updating the new duty cycle to the SAMPLE value in the PWM_PWMSAR register. This will ensure that the new SAMPLE value is modified during a non-empty FIFO, and can be successfully updated after the period expires. Write the old SAR value before updating the new duty cycle to SAR. This avoids writing the new value into an empty FIFO. This only resolves the issue when the PWM period is longer than 2us (or <500kHz) because write register is not quick enough when PWM period is very short. Reproduce steps: cd /sys/class/pwm/pwmchip1/pwm0 echo 2000000000 > period # It is easy to observe by using long period echo 1000000000 > duty_cycle echo 1 > enable echo 800000000 > duty_cycle # One full high plus will be seen by scope Fixes: 166091b1894d ("[ARM] MXC: add pwm driver for i.MX SoCs") Reviewed-by: Jun Li Signed-off-by: Clark Wang Signed-off-by: Frank Li --- Change from v5 to v6 - KHz to KHz - sar to SAR - move comments above if Change from v4 to v5 - fix typo PMW & If - using imx->mmio_base + MX3_PWMSAR Change from v3 to v4 - none, wrong bump version number Change from v2 to v3 - simple workaround implement. - add reproduce steps. Change from v1 to v2 - address comments in https://lore.kernel.org/linux-pwm/20211221095053.uz4qbnhdqziftymw@pengutronix.de/ About disable/enable pwm instead of disable/enable irq: Some pmw periphal may sensitive to period. Disable/enable pwm will increase period, althouhg it is okay for most case, such as LED backlight or FAN speed. But some device such servo may require strict period. - address comments in https://lore.kernel.org/linux-pwm/d72d1ae5-0378-4bac-8b77-0bb69f55accd@gmx.net/ Using official errata number fix typo 'filp' add {} for else I supposed fixed all previous issues, let me know if I missed one. --- drivers/pwm/pwm-imx27.c | 67 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/drivers/pwm/pwm-imx27.c b/drivers/pwm/pwm-imx27.c index 9e2bbf5b4a8ce..bac09d40767b6 100644 --- a/drivers/pwm/pwm-imx27.c +++ b/drivers/pwm/pwm-imx27.c @@ -26,6 +26,7 @@ #define MX3_PWMSR 0x04 /* PWM Status Register */ #define MX3_PWMSAR 0x0C /* PWM Sample Register */ #define MX3_PWMPR 0x10 /* PWM Period Register */ +#define MX3_PWMCNR 0x14 /* PWM Counter Register */ #define MX3_PWMCR_FWM GENMASK(27, 26) #define MX3_PWMCR_STOPEN BIT(25) @@ -223,6 +224,8 @@ static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_imx27_chip *imx = to_pwm_imx27_chip(chip); unsigned long long c; unsigned long long clkrate; + unsigned long flags; + int val; int ret; u32 cr; @@ -263,7 +266,69 @@ static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm, pwm_imx27_sw_reset(chip); } - writel(duty_cycles, imx->mmio_base + MX3_PWMSAR); + /* + * This is a limited workaround. When the SAR FIFO is empty, the new + * write value will be directly applied to SAR even the current period + * is not over. + * + * ─────────────────────┐ + * PWM OUTPUT │ + * └───────────────────────── + * + * ┌──────────────────────────────────────────────┐ + * Counter │ XXXXXXXXXXXXXX │ + * └──────────────────────────────────────────────┘ + * ▲ ▲ + * │ │ + * New SAR Old SAR + * + * XXXX Errata happen window + * + * If the new SAR value is less than the old one, and the counter is + * greater than the new SAR value (see above diagram XXXX), the current + * period will not flip the level. This will result in a pulse with a + * duty cycle of 100%. + * + * Check new SAR less than old SAR and current counter is in errata + * windows, write extra old SAR into FIFO and new SAR will effect at + * next period. + * + * Sometime period is quite long, such as over 1 second. If add old SAR + * into FIFO unconditional, new SAR have to wait for next period. It + * may be too long. + * + * Turn off the interrupt to ensure that not IRQ and schedule happen + * during above operations. If any irq and schedule happen, counter + * in PWM will be out of data and take wrong action. + * + * Add a safety margin 1.5us because it needs some time to complete + * IO write. + * + * Use __raw_writel() to minimize the interval between two writes to + * the SAR register to increase the fastest PWM frequency supported. + * + * When the PWM period is longer than 2us(or <500kHz), this workaround + * can solve this problem. No software workaround is available if PWM + * period is shorter than IO write. + */ + c = clkrate * 1500; + do_div(c, NSEC_PER_SEC); + + local_irq_save(flags); + val = FIELD_GET(MX3_PWMSR_FIFOAV, readl_relaxed(imx->mmio_base + MX3_PWMSR)); + if (duty_cycles < imx->duty_cycle && val < MX3_PWMSR_FIFOAV_2WORDS) { + val = readl_relaxed(imx->mmio_base + MX3_PWMCNR); + /* + * If counter is close to period, controller may roll over when + * next IO write. + */ + if ((val + c >= duty_cycles && val < imx->duty_cycle) || + val + c >= period_cycles) + writel_relaxed(imx->duty_cycle, imx->mmio_base + MX3_PWMSAR); + } + writel_relaxed(duty_cycles, imx->mmio_base + MX3_PWMSAR); + local_irq_restore(flags); + writel(period_cycles, imx->mmio_base + MX3_PWMPR); /*