From nobody Mon Nov 25 17:59:37 2024 Received: from BEUP281CU002.outbound.protection.outlook.com (mail-germanynorthazon11020111.outbound.protection.outlook.com [52.101.169.111]) (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 38DDF1BA89B; Fri, 25 Oct 2024 08:37:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.169.111 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729845430; cv=fail; b=daj2ohhOWjyw1hIryk71NVTMS/NRJiOzG9iTJamogmqT8XEahqJqcQQcQgF+e58d+UPOrqyjwtu8pLcTouaM70sPkuweP0b/owYiYgESw1DuHKZsuPIpvzFawtZwvTjLHxb+Q2HBqpVmvPEy0K+layxsruFFqldo0fNZ270KzhM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729845430; c=relaxed/simple; bh=ZSRIT/jeRnIARScqHi2syAgtXNsb5Qp+yMCFhdccpaY=; h=From:To:CC:Subject:Date:Message-ID:Content-Type:MIME-Version; b=a2yLY594I/G8VUTL1GeyqKLqeT6ok9Btn5HLiXunlcpvvF2/MF7CP7CjhiP+4wfteWlq3S+FaWrQNQwxZl9e5Qv0CQ2zlpVc8cKBFdQGwcQbG3TL/B5YAOYAHlYhYA9LxlYt3qJVZ8nvpcI3ReBIGQiwjjBZqA+YYchCl7PwW6Q= 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=52.101.169.111 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?B?Z0RjTmEvTzgyVTdpN29RTlVCVEEvU3BWekdKVEVWS1J1YWdrNWFzQnlTa2JP?= =?utf-8?B?amFvMlFNWWkzVm96b3ZaNWJ4b0QzNnNxQ1BNTEx4R3h0VWliY29UVlhJVG1B?= =?utf-8?B?cHd4K0hkK05DMkp4S21HLzlZYnBURmtrMVI5SnhoSXZWT2FUVGxRNnRqS3Zi?= =?utf-8?B?d1FLbTVmb0FoU2NkNXc5QTJPUW16S242R0VEZ1I1bjd2SWM1aXp2OFJOTVd0?= =?utf-8?B?NVh2TG96VS96djVCU2pTUXlseWJ1djNUd1RONk9WRkVGeWI5Y3BxdzZqQWlR?= =?utf-8?B?aFJwUlgwY0U2RkdmT25CcHc1YkxUdjJXeVNDT0xmTVdaRHR3Mno1ZE1FOWt6?= =?utf-8?B?R09DUlhpaUxoaitvU2ZQMjdXOG1USEg1YWhaaDZLUWYyblFsTjM2UXRmK2Nm?= =?utf-8?B?K0QrOW1LclZuNEJEZU81TVgvUnNmdEsyN05nZn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Xp5Zm42b0lvM1J0Z0FLTEI1TGRWZWpOWFRicWM1UW1rWkFjeXpP?= =?utf-8?B?d1o0b1dROVVtZlRDRk5sd1d6WjFOM0VtRktyOW5FNDVFaWZia0syS2dWNVo1?= =?utf-8?B?ZkVRY0hJbDNMUFpUd1RiMTlOM0FJZWJKN3pONUdOek1hR3hzRm9EZUo4c3J3?= =?utf-8?B?NHEyZDhVMlIzRHdKZXROQ1k2OFBKbFRkMjRqZm5tc3FkSTcxVjMvWkI1WS91?= =?utf-8?B?WUhsQi9ZbThLWHpSZ01wTlAyNTBPWi9qcXhTUnhLTUxzU3hwaHJxWE8rNTVF?= =?utf-8?B?THB6WkVFMkRQVFNCZnpFODcyNE85djhNa2xERU5hUG4vdnRsamwrM0hkUWNy?= =?utf-8?B?Q0JvQ0RxT21EZSs2YzMrQzl1QUlYMmRmaGlQY2F3Q1gxR3YrdmsxUVFvbnNV?= =?utf-8?B?MjkyTmpETjYxUEYzUjBZL2k0MWZpS3BPQldqUm5tZUJCZkZsK0tXbG45S21X?= =?utf-8?Q?QaphV/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?B?QXpPZnRDR1ZvZnJtbFZxTGg0d3FwQWx1dFc1d0N0b2F1TDQzSWhzRzRBbGM0?= =?utf-8?B?OTgwVm9qWFIvV1pqRlNyL29hMXkyTEtpK2lKNUdOMitoaHVJTFNKMVBWSkt2?= =?utf-8?B?cHhrUUUxR0xBSytEak5JTzFXYTlWTzN1MkZacHhHaTRUYnp5SlI0Y0hja3hG?= =?utf-8?B?UWJBZ2s0Mlhh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g1TTdmN1NXVFUzWDBC?= =?utf-8?B?VTl5Z3JaVmk1eWZGY0gwRFRGeTVrRUFRWkI1dHZBUGJsS1BsVkFrMXg2QnhE?= =?utf-8?B?eVdaMjdVTS9UTVZlSnR3aGI1aFY0Qkx4WWI5TC9UOFQxNWNORWhlQlRabk4v?= =?utf-8?B?c1F4c2Y0dTZSeW51SEN1U3NFZFM3QnZKRGx0OU13K3U1TGUzQVhrOGhXdGd1?= =?utf-8?Q?ofTppHKmLuYy8I3ztQfc8JA=3D?= Content-Type: text/plain; charset="utf-8" Content-ID: <8F12D5495ED5D3459CD66AF9EB43A60C@DEUP281.PROD.OUTLOOK.COM> Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org 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 =3D=3D 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 *chi= p, p->prescale =3D prescale; =20 period_count =3D (clock_unit + ((1 << prescale) >> 1)) >> prescale; - p->mod =3D period_count; + if (period_count =3D=3D 0) + return -EINVAL; + p->mod =3D period_count - 1; =20 /* calculate real period HW can support */ tmp =3D (u64)period_count << prescale; --=20 2.47.0