From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752147AbbBRNHA (ORCPT ); Wed, 18 Feb 2015 08:07:00 -0500 Received: from mail-am1on0148.outbound.protection.outlook.com ([157.56.112.148]:35366 "EHLO emea01-am1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751568AbbBRNG6 (ORCPT ); Wed, 18 Feb 2015 08:06:58 -0500 X-Greylist: delayed 17270 seconds by postgrey-1.27 at vger.kernel.org; Wed, 18 Feb 2015 08:06:57 EST From: Gaetan Hug To: CC: , , , , Gaetan Hug Subject: [PATCH] pwm: mxs: fix period divider computation Date: Wed, 18 Feb 2015 14:06:34 +0100 Message-ID: <1424264794-12167-1-git-send-email-ghug@induct.be> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [91.183.127.4] X-ClientProxiedBy: DB4PR04CA0034.eurprd04.prod.outlook.com (25.160.41.44) To DB4PR01MB0686.eurprd01.prod.exchangelabs.com (10.141.44.153) Authentication-Results: gmail.com; dkim=none (message not signed) header.d=none; X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:DB4PR01MB0686; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005003);SRVR:DB4PR01MB0686; X-Forefront-PRVS: 04916EA04C X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6009001)(40100003)(53416004)(229853001)(48376002)(92566002)(77096005)(50466002)(42186005)(2351001)(66066001)(87976001)(33646002)(86362001)(47776003)(77156002)(62966003)(50986999)(110136001)(122386002)(50226001)(36756003)(46102003)(74482002)(7059030);DIR:OUT;SFP:1102;SCL:1;SRVR:DB4PR01MB0686;H:ind-lt-007.induct.loc;FPR:;SPF:None;MLV:sfv;LANG:en; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:;SRVR:DB4PR01MB0686; X-OriginatorOrg: induct.be X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Feb 2015 13:06:54.6998 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR01MB0686 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The driver computes which clock divider it sould be using from the requested period. This computation assumes that the link between the register value and the actual divider value is raising 2 to the power of the registry value. div = 1 << regvalue This is true only for the first 5 values out of 8. Next values are 64, 256 and, 1024 - instead of 32, 64, 128. This affects only the users requesting a period > 0.04369s. Replace the computation with a look-up table. --- drivers/pwm/pwm-mxs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/pwm/pwm-mxs.c b/drivers/pwm/pwm-mxs.c index f75ecb0..c65e183 100644 --- a/drivers/pwm/pwm-mxs.c +++ b/drivers/pwm/pwm-mxs.c @@ -35,6 +35,8 @@ #define PERIOD_CDIV(div) (((div) & 0x7) << 20) #define PERIOD_CDIV_MAX 8 +static unsigned const int cdiv[PERIOD_CDIV_MAX] = {1, 2, 4, 8, 16, 64, 256, 1024}; + struct mxs_pwm_chip { struct pwm_chip chip; struct clk *clk; @@ -54,13 +56,13 @@ static int mxs_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, rate = clk_get_rate(mxs->clk); while (1) { - c = rate / (1 << div); + c = rate / cdiv[div]; c = c * period_ns; do_div(c, 1000000000); if (c < PERIOD_PERIOD_MAX) break; div++; - if (div > PERIOD_CDIV_MAX) + if (div >= PERIOD_CDIV_MAX) return -EINVAL; } -- 1.7.10.4