From patchwork Fri Oct 25 08:37:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erik Schumacher X-Patchwork-Id: 13850207 Received: from FR4P281CU032.outbound.protection.outlook.com (mail-germanywestcentralazon11022115.outbound.protection.outlook.com [40.107.149.115]) (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 3A0081D1E71 for ; Fri, 25 Oct 2024 08:37:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.149.115 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729845429; cv=fail; b=moryvsWPfJsphov75uktoFOJI3FLmo5vdZmlm+RMPno/VA/RvO1LMVoZ22YsNbmp2ZhHg0JYVymwPt6zq+GdRf4dbFQCYziqWmZlMjjDBduXK3AMllOiZ+g/pU9admt015MDuvk420Z8yW7cwl6jKI85hf4Q1AUK9cRPuK1rsl8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729845429; c=relaxed/simple; bh=ZSRIT/jeRnIARScqHi2syAgtXNsb5Qp+yMCFhdccpaY=; h=From:To:CC:Subject:Date:Message-ID:Content-Type:MIME-Version; b=oyQrJ3aK6TE1gAAr/B7IZgR9TkcR5RfznqlDt/Xs896WpNYml7MKS82gWryKIDORdPUIV6diWPASvN5Fq86gPvSHZb6dV9lBRsW2zmaE2jgQS6uk7e3RZajovABM0rj3hbqQNP2XJ34Jc78sxAhhLMIFfMa5mK38K9E/YrTBXUA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=iris-sensing.com; spf=pass smtp.mailfrom=iris-sensing.com; dkim=pass (2048-bit key) header.d=iris-sensing.com header.i=@iris-sensing.com header.b=PhVKrdm/; arc=fail smtp.client-ip=40.107.149.115 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=iris-sensing.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iris-sensing.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=iris-sensing.com header.i=@iris-sensing.com header.b="PhVKrdm/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XB4/f4C6x2mk0bHgGhLpMLHQ/AbSV5P9MhkjJ17qhyfc6O6lRj8a3ti98gSQK5gimDqw3UXR0slsI1KCSDWCrEPHfjYzceXqVAT6aHdIJk1mAPPhNipQDuuLOB3D9QzHUt0s8BAT6h9+yj6Vi5yROgRU0IPxy5h68OXVkGFJR6UfSnlBXfiW6kITSn4FJV7puDojot/YVK3ouFXRy0PqMuio28+g/ktmRsLPslzoQJh1925FGcpz3MaVQzVw6IlQswdAF+IVu8qe6P5lG+2x+AdlG5U+Krt4xQEf+SmtsY6dYo02MCYnUhrhNDfvtKhyVdtSdsBw3sWTXjPK3IRJZQ== 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=ZSRIT/jeRnIARScqHi2syAgtXNsb5Qp+yMCFhdccpaY=; b=bHZ3sLXVbAI3MGwZJJtxUuXNOI0Es6qdf0hC0abFD59MEV+eX2IjOG/WqBgCM4g0aPTf2na67MW278UnQmUMd2hYygsqX9BZlkzccflKsRjYvVVp0WLXex423walJYcXJxXgt1vtPtwAZqd/rYgi4Rd/pNaxMo6qJSR0qkxz0Se9Vqx9M/xN7J4DQtO86MA4bgmkx5oGhOfZke3QxsOh6QOVVXt2KP7a1h5Ddh8Wg9eicx1djmopgjIM0oasWrBFN+196t8Qdw/ICwIrV5B2j0a16zB23JUGrHC52L+gFhbxxzT7i64kLDmybPXes6MaPEafulszy1Myd0orFkw+sg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=iris-sensing.com; dmarc=pass action=none header.from=iris-sensing.com; dkim=pass header.d=iris-sensing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iris-sensing.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZSRIT/jeRnIARScqHi2syAgtXNsb5Qp+yMCFhdccpaY=; b=PhVKrdm/uZbYni+sjEfdvCMj6pVltvSG/O7vRuRdS/wcJRXVO2i4EDdzkP7QR+GXRhodlxQ8twIwkq1l/QUFZkS53erGNh+AKMmBCUdD0+k7b9eMKuJqs6CwjzMmhTrF3yUJgsLlNig5nt9snc7ItvEXshQ67ybq9m27afeRbuTwyOfeWbBIVzLTci3sD/tnnEjkAV8E8nHwywjtflg5qxJAIaDEufQWcQOLBfQK/du3ADdubMlLd2jAkFoAm5Ykopl6GhqymPqcFeAKBrEeUNTTm2CEEwAuGShIFMZeXfWmTpKXGF05zU5RvEGgi0ZTX7iK0qM96R6a4SZtL+iThw== Received: from FR0P281MB2809.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:23::8) by BEUP281MB3428.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:a0::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.21; Fri, 25 Oct 2024 08:37:00 +0000 Received: from FR0P281MB2809.DEUP281.PROD.OUTLOOK.COM ([fe80::d685:f312:e114:519e]) by FR0P281MB2809.DEUP281.PROD.OUTLOOK.COM ([fe80::d685:f312:e114:519e%4]) with mapi id 15.20.8093.018; Fri, 25 Oct 2024 08:37:00 +0000 From: Erik Schumacher To: "ukleinek@kernel.org" CC: "kernel@pengutronix.de" , "thierry.reding@gmail.com" , "s.hauer@pengutronix.de" , "festevam@gmail.com" , "shawnguo@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "imx@lists.linux.dev" , "linux-pwm@vger.kernel.org" Subject: [PATCH v3] pwm: imx-tpm: Use correct MODULO value for EPWM mode Thread-Topic: [PATCH v3] pwm: imx-tpm: Use correct MODULO value for EPWM mode Thread-Index: AQHbJrkPZIUl6hhjQE6BArXHpLZSvg== Date: Fri, 25 Oct 2024 08:37:00 +0000 Message-ID: <1a3890966d68b9f800d457cbf095746627495e18.camel@iris-sensing.com> Accept-Language: de-DE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=iris-sensing.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: FR0P281MB2809:EE_|BEUP281MB3428:EE_ x-ms-office365-filtering-correlation-id: ab1386fb-fc13-446f-d0f5-08dcf4d03187 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|366016|38070700018; x-microsoft-antispam-message-info: =?utf-8?q?gDcNa/O82U7i7oQNUBTA/SpVzGJTEVK?= =?utf-8?q?Ruagk5asBySkbOjao2QMYi3VozovZ5bxoD36sqCPMLLxGxtUibcoTVXITmApwx+Hd?= =?utf-8?q?+NC2JxKmG/9YbpTFkk1R9JxhIvVOaTTlQ6tjKvbwQKm5foAhScd5w9A2OQmzKn6GE?= =?utf-8?q?DgR5n7vIc5izv8RNMWt5XvLozU/zv5BSjSQylybuv3TwTN6OVFEFyb9cpqw6jAiQh?= =?utf-8?q?RpRX0cE6FGfOnBpw5bLTv2WySCOLfMWZDtw2z5dME9kzGOCRXiiLhj+oSfP27W8mT?= =?utf-8?q?HH5ahZh6KQf2nQlN36Qtf+cf+D+9mKrVn4BDeO5MX/RsftK27NgfyMdZPq2YSNihR?= =?utf-8?q?jsJajImNL2VLUi7KfbtYgDOWJwcRrDXU3vxIt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onsU292NjDN61PF3R0Y/i41fiKpOBW?= =?utf-8?q?jRnmeBBfFl+KWln9KmWQaphV/nNzqYTWug/cfyQsTi4bDPKSlxjoD/9Y=3D?= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:FR0P281MB2809.DEUP281.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(366016)(38070700018);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?AzOftCGVofrmlVqLh4wqpAlutW5w?= =?utf-8?q?CtoauL43IhsG4Alc4980VojXR/WZjFSr/oa1y2LKi+iJ5GN2+hhuILSJ1PVJKvpxk?= =?utf-8?q?QE1GLAK+DjNIO1Wa9VO3u2FZpxGi4TbzyJR4cHckxFQbAgk42XaRkal4MHfQBSeWy?= =?utf-8?q?xPgFryy2YWc3BNDym2u2J0xQI5zJwnQp7jTlLLPwZ4m2kwp1HRhiqsSoVscDaIV3B?= =?utf-8?q?n4ylLOlV2qNg/4RsO56CY4eBbuZNb4V+LrtJx1vP9y1JLy/aalPOjhHSU9hZv76w5?= =?utf-8?q?Lbip9PRyCiVKkUs8XNQw7pEkGckM2e4uSOjEkCaoaivgvJA1bv/HRCbCCBKzK7ckJ?= =?utf-8?q?Lxpi4ToPibOngEBEItb8i9FVX1MZJiNs/WvmCFaQgW4zXOimlt7ntD8/WbbIPyvnj?= =?utf-8?q?aGV9YjY8DyOkZpplL19PirIr25ZWA4juvFEHD6vqBk2xV7JIyLPaeRHWzMKVqoaKV?= =?utf-8?q?aRlFxwh2LLJYLpNK7tKO4YgclJgODHKnbkxlzKYq3YPI02FBaTQ3EuiRyHC7ixlYL?= =?utf-8?q?Colot3Y05XDM/b3OShIklGsG48JiepWrx5UKi9LzuJC+ODqqMYxobnQaB7VD22tTB?= =?utf-8?q?lJPOmwTufJ1uixhYaLfTFrL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5hV4BLxYb9L/T8T15cNEheBTZnN/sQxsf4u6RynuH?= =?utf-8?q?CuSsEdS7BvJDlt9Mw+u5Le3AXk8hWtguofTppHKmLuYy8I3ztQfc8JA=3D?= Content-ID: <8F12D5495ED5D3459CD66AF9EB43A60C@DEUP281.PROD.OUTLOOK.COM> Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginatorOrg: iris-sensing.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: FR0P281MB2809.DEUP281.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: ab1386fb-fc13-446f-d0f5-08dcf4d03187 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Oct 2024 08:37:00.0752 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 963f3913-ffae-43fd-856b-2dfd3f6604e3 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: MklkxNaifyVSi9kah6VqSur6IOaky9Eu6lRNV6Yj8Dx5FAm5zvH0w/FDaImu+Nus6M8EpnQU4XgfPHEWxu2UaWfhS9ktYzbcVEuFdAvDmL/ZBYnkI+6tcJK1JP8+eFFH X-MS-Exchange-Transport-CrossTenantHeadersStamped: BEUP281MB3428 The modulo register defines the period of the edge-aligned PWM mode (which is the only mode implemented). The reference manual states: "The EPWM period is determined by (MOD + 0001h) ..." So the value that is written to the MOD register must therefore be one less than the calculated period length. Return -EINVAL if the calculated length is already zero. A correct MODULO value is particularly relevant if the PWM has to output a high frequency due to a low period value. Fixes: 738a1cfec2ed ("pwm: Add i.MX TPM PWM driver support") Cc: stable@vger.kernel.org Signed-off-by: Erik Schumacher --- v2: - Add Fixes: and Cc: tags v3: - Add period_count == 0 check and return -EINVAL drivers/pwm/pwm-imx-tpm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/pwm/pwm-imx-tpm.c b/drivers/pwm/pwm-imx-tpm.c index 96ea343856f0..7ee7b65b9b90 100644 --- a/drivers/pwm/pwm-imx-tpm.c +++ b/drivers/pwm/pwm-imx-tpm.c @@ -106,7 +106,9 @@ static int pwm_imx_tpm_round_state(struct pwm_chip *chip, p->prescale = prescale; period_count = (clock_unit + ((1 << prescale) >> 1)) >> prescale; - p->mod = period_count; + if (period_count == 0) + return -EINVAL; + p->mod = period_count - 1; /* calculate real period HW can support */ tmp = (u64)period_count << prescale;