From patchwork Tue Sep 10 15:24:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13798769 Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazon11012042.outbound.protection.outlook.com [52.101.66.42]) (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 77125199FB9 for ; Tue, 10 Sep 2024 15:25:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.66.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981920; cv=fail; b=Ntbl4R3j546dKKRX+UNsbLrtSW6KqeBdKFMzFlG5PHeG4ybbCL8ZiVuErkZoirqRwXi7b8dUCvaeeR5lFoAOmvVZCO59Ol4qBuAjyWFLesy8PXQ+Zz06owTo9VClLM7vU2TKFaLLP3Ul+1uWsKvohLOudDq084OmcN823MwDJow= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725981920; c=relaxed/simple; bh=H0AaA0v44wjGMn9Z5TJRIGEjSf55BVhlQMQWKo5fhPY=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=r08iXDRuSf5RJn0IPjqan/xteEGk7wxbTGtzZZ4FDJwndmO0FJhvLadoXFgDlrmiWF7hZVREIkF+IFEEybkBcnIJ4s1JS2Pb+E6Gk64Iak+88cVB831yBkGoCe2ksvGH/l57x9WHozqX03J/GOOvmM8udCvsd3A+GxDK9duB29w= 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=ADA6k/Z1; arc=fail smtp.client-ip=52.101.66.42 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="ADA6k/Z1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Vuudn8LSipgEr0RoeNfQOkiAoOOI9L00m33i7mmaMVRd+4nBUikYwJ7nNXGnIjwjEHl5QTwjq9n3jPlHXOdWvdREQet9LF3p4i8RzzeTjw39Zk0YqvWXy506fNUYsQQm5zO8edw2tnKi3lvXtsgxqEZXjXAZT3H7lpypSC9N6hrU/XtIp0rcCllpGye/N49YmEPW/5OtT+OhfYqqU1G6jwIIazQMT/3ZcKiPyH+KhbTha3P61a/sL/r8yNReMMzuJ20/Dt3TF90dGonr7J/Ij8OFo43ZzgK65YbE9Dl37RTRBzQA5Rsr33NSAz+Y/4/zwrekDhTjUKIhK+Oydv+Vkg== 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=9IBCqWIcx2ffUrxwzEvi3NnNp8Hmo35KQF6jfIl7GjQ=; b=uV9a8oayQ3NNdTPeMW0FGQITxYP61U+Q8GVjonz8eQxzT6ZdDA7d2HqZuqn1Ck2ZMAErotpwJIiD7vd3OwWA9u7dmgM5+Z/TakXU2YXRfWTcti3ockPHBWl+FQHu31LFTmNH1vUYkMo6OkrY3wKx4pHe0a/FQCCVgb8Y3wXBFhGWc1hQeSzNUxjeV/xn6D8PC62hTWGzpPvG3jnwHGmxYtkTCeyVhNPgI+o8IIIZ/xO3h1fKCS8aELONmyp3BSJ6YIvd+vm4xCgFwthvyxfIhJOhZPnXBa5fXss/oE5+92yLV1eR8qykj8rbyKa5ZMDwX+kHRMNmlsf66C74rYO+1A== 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=9IBCqWIcx2ffUrxwzEvi3NnNp8Hmo35KQF6jfIl7GjQ=; b=ADA6k/Z1Yd1gewHqffLnNL2AJdtGZP4gqOz+C9d+RYHdevyuXWLHZVqpDb20fGEZQMVg8nwI4WmP3T6cO5BLMuWNPBx+L9Y77QuPQawFBUsDAzI0UEEjOi0WMGPMNB+3RV6nlvpz61R4yfHTSHz1zDJK6+z2XV6daavvTLC0w6UNcoFwbwHskols5DITZjCfRXb4x2eDAoa/h76d0hEplrHcQmWxbfU7uazzd4+dLJtf3QlFNLrps1yINmlUXLMTA/D/m+eGII9UGmzJFpN43h6OP+eqjcQMCwZEnLkpa/gS+UFzxVbycq+SpBbimRBYuVK22Id/DDceRLgPVLUt9A== 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 AM9PR04MB8764.eurprd04.prod.outlook.com (2603:10a6:20b:40b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Tue, 10 Sep 2024 15:25:13 +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.7939.022; Tue, 10 Sep 2024 15:25:13 +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 v5 1/1] pwm: imx27: workaround of the pwm output bug when decrease the duty cycle Date: Tue, 10 Sep 2024 11:24:55 -0400 Message-Id: <20240910152455.2425152-1-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SJ0PR05CA0132.namprd05.prod.outlook.com (2603:10b6:a03:33d::17) 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_|AM9PR04MB8764:EE_ X-MS-Office365-Filtering-Correlation-Id: 9cb6ad1d-1ea3-44f2-e24a-08dcd1acc43c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|7416014|52116014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?2E95Y7dfDlRKZ+TSa+lXuECqvEz/wbN?= =?utf-8?q?eYNAmN190lFdOj6R2wpLLfJ6legPKNkoiuEQDi86Wx71wS0sh1+dXySVKhGTNLpoC?= =?utf-8?q?hhkSP5SJFxE74R5afQJPziO5nIGb9kk6XiOo7ZcloH2bj99YJfAGNpmiW9PnjrOab?= =?utf-8?q?2zqzXmj7xqcDhB/fkKo1CNuuu7oPzTM6eXHJCVExKLTncMWsG+kYCaanaBH1r7n8/?= =?utf-8?q?LCo+/5vzFEHdXiNkh4mwlQYu2pL7X3PD2u7R6h+fE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ZCcoj0NYepaEa+YBJlWz8daqiMH73b?= =?utf-8?q?0FxY1VSagmCi8VI+z6EwaZzPcJcgLDsLuxBHwSwtYtF/YtsjnH2v+z/xHV3kWZfUA?= =?utf-8?q?MRD3CjM6hEnJDQRcgca2qIYeA5OOyKESB1Sf9KtjxchubuxWQ+oXpLPosQvB1ie+D?= =?utf-8?q?MnanQmYQ27G21PMXEt+yB8OVz+sgpxg9i3Wo+DVF3Zr8ZLstRdKzjT95lhoWYZqft?= =?utf-8?q?Vk58S5ojA/eAZxx08MWzOAiMh7t3U/QpnA=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)(366016)(7416014)(52116014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?hugF7tXfeOwmoFOBMFtsMJ7PaRK/?= =?utf-8?q?5/+IoaPylvqIk4bcMYi1b6+uaRKaSQIJWXfXHn3QPoL5sAEJ2o9GWx1izlXyzyHCH?= =?utf-8?q?G71b5gT1yuXcz6hhjyR7GGbFac+Dpo1RfNuDSpWPf3RKp1Y15SNgkxQFtvIf07Z44?= =?utf-8?q?djJKkaYiMdkANFL7rxNuZIVo1HnnGK9n4tciXBgAAa5Cma8q8YTapQell7MlI96Wm?= =?utf-8?q?ihzOfndS0SDInlq70ZVGgocHkMDJWHHTrSJlRJ9zXhR+kVJ5n2IzwL3C9PuDdGtXO?= =?utf-8?q?qa87fnjjr59/zvEmtoy57KqLQ7Ume7rR0xbWduxA22LAxvovb73W5S113Sw9eYT/O?= =?utf-8?q?3Q4F3MizEqk43LDocMMCCLCSehAL+XI5W6bY8N4R7gFUH4wpywmh2+5sIfJrBjvHb?= =?utf-8?q?CVtyhjsVyer5ilphtZaiJQJh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FgLg8qo8Wg4hA4WLw9uHKuIJzBPLLw6SpT/cSouOUH?= =?utf-8?q?b5vV3Tca9otDtD9OQ2VqrAhc/I05HQGu0K393LsxAnKe/lDLgYY7fdFcMf6YqMwKT?= =?utf-8?q?Tq4ZRaoWCrR16E4l5mreXKUPSnhSnNGfrCYnqYHtCZpuLPdUwiN9UaY8ROYPHdL7D?= =?utf-8?q?tdBKD1ml9WJihs4f7YdovNXAkiTJBo7C8t/bKIRy0pv1Bvi1jgZKRSCIKbunzYjOj?= =?utf-8?q?j4YGLQOJr+D3?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9cb6ad1d-1ea3-44f2-e24a-08dcd1acc43c X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 15:25:13.8387 (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: mjGSczM3xpZka12oRRf168bfNwT0evK8Q6MhM1rBIHO4Nkmr5qUMBqYQn0dvLOBWAiEMLUTXY76VVqlqXeuKuA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8764 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 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 253afe94c4776..713d368f03931 100644 --- a/drivers/pwm/pwm-imx27.c +++ b/drivers/pwm/pwm-imx27.c @@ -27,6 +27,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) @@ -234,6 +235,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; @@ -274,7 +277,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 ((val + c >= duty_cycles && val < imx->duty_cycle) || + /* + * If counter is close to period, controller may roll over + * when next IO write. + */ + 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); /*