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: 13850215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6A31DD0C5EB for ; Fri, 25 Oct 2024 08:47:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version: Content-Transfer-Encoding:Content-ID:Content-Type:Message-ID:Date:Subject:CC: To:From:Reply-To:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=ZSRIT/jeRnIARScqHi2syAgtXNsb5Qp+yMCFhdccpaY=; b=FcuAXIPwvru54i4/N02ZMyows9 2APNZOSrzQRaG8fRW9Qg+lCU9fqt9BI5cDM1o1gJdjrzVWRCIurvt7W5qoB9S+PDgB53NGHYNoGne /aCvHksKHxOvXnHFrzKlPhbd8kXfZcWEAS3YIZuRK1Li6rxeVB1wzqVKQMpeTAeLGg79WN2pgqTZn LnzbH5H8D6MUVdl9Kup3qYpYIXogEz2Ar27nyePzL7lrIZQRYgGGbsiX5ybFXn+7bFhzcbAYih+lt ipM+r0+dsHQLAR6QsVTAtnjy2UqKrTocFH87PNAjY7gCU85TIcpJqc1pXt/B5MT768N+yQg/+rdDw VRHa+kzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t4Fyf-0000000322p-0ARz; Fri, 25 Oct 2024 08:47:25 +0000 Received: from mail-germanywestcentralazlp170120004.outbound.protection.outlook.com ([2a01:111:f403:c20c::4] helo=FR5P281CU006.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t4Foi-0000000309b-3HOo for linux-arm-kernel@lists.infradead.org; Fri, 25 Oct 2024 08:37:10 +0000 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?=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?utf-8?q?OmDe+6c3+C9uAIX2dfhiPcawCX1Gv+vk1QQonsU292NjDN61PF3R0Y/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+ODqqMYxobn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APblKPlVA?= =?utf-8?q?k1x6BxDyWZ27UM/TMVeJtwhb5hV4BLxYb9L/T8T15cNEheBTZnN/sQxsf4u6RynuH?= =?utf-8?q?CuSsEdS7BvJDlt9Mw+u5Le3AXk8hWtguofTppHKmLuYy8I3ztQfc8JA=3D?= Content-ID: <8F12D5495ED5D3459CD66AF9EB43A60C@DEUP281.PROD.OUTLOOK.COM> 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241025_013708_863157_C45D4C01 X-CRM114-Status: GOOD ( 15.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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;