From patchwork Wed Nov 14 13:01:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aisheng Dong X-Patchwork-Id: 10682507 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 51EE214E2 for ; Wed, 14 Nov 2018 13:02:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 442232B0B2 for ; Wed, 14 Nov 2018 13:02:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3826D2B0BE; Wed, 14 Nov 2018 13:02:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CDB02B0B2 for ; Wed, 14 Nov 2018 13:02:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733244AbeKNXEx (ORCPT ); Wed, 14 Nov 2018 18:04:53 -0500 Received: from mail-eopbgr130083.outbound.protection.outlook.com ([40.107.13.83]:45216 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728203AbeKNXEw (ORCPT ); Wed, 14 Nov 2018 18:04:52 -0500 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=keQeZnA12ucPSlee+fWKuypU6DmryFB6Qug2eeyJuM4=; b=hYqou105ddfbhoDUtHJE70jLZB+efJjYs8xSsfv/4TzcVHMT8/yUKJFZ8ctYdA1lo0kpnlye1mnEFx9hi2txnlh7bNyYoum8E3o44N6nfLci8IsYDAoctci2iWOW4c1axXBw47/eZQ1PRzaMoKqsDwU01s+M86Co0yVF36Y7o7I= Received: from AM0PR04MB4211.eurprd04.prod.outlook.com (52.134.126.21) by AM0PR04MB4291.eurprd04.prod.outlook.com (52.134.126.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.28; Wed, 14 Nov 2018 13:01:39 +0000 Received: from AM0PR04MB4211.eurprd04.prod.outlook.com ([fe80::797a:f972:9281:6d10]) by AM0PR04MB4211.eurprd04.prod.outlook.com ([fe80::797a:f972:9281:6d10%2]) with mapi id 15.20.1294.045; Wed, 14 Nov 2018 13:01:39 +0000 From: "A.s. Dong" To: "linux-clk@vger.kernel.org" CC: "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "sboyd@kernel.org" , "mturquette@baylibre.com" , "shawnguo@kernel.org" , Anson Huang , Jacky Bai , dl-linux-imx , "A.s. Dong" , Stephen Boyd Subject: [PATCH V6 2/9] clk: fractional-divider: add CLK_FRAC_DIVIDER_ZERO_BASED flag support Thread-Topic: [PATCH V6 2/9] clk: fractional-divider: add CLK_FRAC_DIVIDER_ZERO_BASED flag support Thread-Index: AQHUfBouVmVtXn9prk2+fZptUJvH+g== Date: Wed, 14 Nov 2018 13:01:39 +0000 Message-ID: <1542200198-3017-3-git-send-email-aisheng.dong@nxp.com> References: <1542200198-3017-1-git-send-email-aisheng.dong@nxp.com> In-Reply-To: <1542200198-3017-1-git-send-email-aisheng.dong@nxp.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-clientproxiedby: HK0PR01CA0057.apcprd01.prod.exchangelabs.com (2603:1096:203:a6::21) To AM0PR04MB4211.eurprd04.prod.outlook.com (2603:10a6:208:66::21) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aisheng.dong@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.66] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;AM0PR04MB4291;6:sQ/wRgLDLcCzNEl1G5J1Ihu0h0vsmR7GW2Fc6g3JyMuWyIFM2Jyk1JmyP/WRBFuxbjhji38+Qpn94Yv1Mey8eUn5ua8mdaJ86BEkknBa1JfcXW8ktO+JiHHhEeX8eI89XktPOE0JgNT/00cZnzMfKNuwcF4v9tZMjhrFGQJh+hiSyWCeb8FlWOp/ml6EP2EE5o62Up2nZwId6Q2n316RuN3utI5MLgjTvy7tlZeLLE0DWzUnvN481lc6oJTl2Zfic7TNVjdWdgBBnRoMJSCZvS+6e73qJcjlUezKp5iF6uCxmG+f3q9p0l1KihcWPcR4DiUnmKP6vNBOq3BtEQ0vj4nLHNWh+gMdiJ96RVdK76UBlUOTjdfCFuwDQ+xfnbyUmNNla2TQE3Fq2BqnBuS5tFzsG28kxTglj+wUQPbxKBvLzh+tNm544eybhEvsaU9mBlItohcba3Ge+O5fSdiNNQ==;5:mDK9FkSNUIuBAvr+hgtNQdtnUIfOcu1FNSRaXR7C9p9tFrtnz8F7ZyggxK/K7XxLwEzqwpttwLdRktDhiYIgA6jqXLxDXq3jaGAab1Xi/khPrw60H21U9n/f0cc/JRcCnScxJ0u5W8wu8mqtwmxORpTJNSxlSRYdyyAejz1Xn+c=;7:c91m60UjtiJ/ssyG7fhLT1I1b6bu7Ef6cNimEGOHA18p9l9XImKmEQnhNpXjAWJIEci5WqhOLscpOYUVCCZki/okF0+LUHBswCxTu1y9o0STWn6AsiWBv/k70kXH02ILpGxD19h1tg5MLPwsoNrZOQ== x-ms-office365-filtering-correlation-id: a9e202ec-70ee-49be-7702-08d64a3150e1 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:AM0PR04MB4291; x-ms-traffictypediagnostic: AM0PR04MB4291: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(185117386973197); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(3231410)(944501410)(52105112)(10201501046)(6055026)(148016)(149066)(150057)(6041310)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(201708071742011)(7699051)(76991095);SRVR:AM0PR04MB4291;BCL:0;PCL:0;RULEID:;SRVR:AM0PR04MB4291; x-forefront-prvs: 085634EFF4 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(366004)(136003)(376002)(346002)(39860400002)(199004)(189003)(54534003)(476003)(2616005)(11346002)(2906002)(53936002)(486006)(446003)(386003)(52116002)(5640700003)(6512007)(6436002)(2351001)(6486002)(105586002)(305945005)(7736002)(316002)(6506007)(54906003)(106356001)(6116002)(102836004)(99286004)(76176011)(3846002)(81156014)(26005)(5660300001)(186003)(25786009)(86362001)(8936002)(97736004)(478600001)(2501003)(66066001)(256004)(71200400001)(71190400001)(81166006)(8676002)(14454004)(6916009)(4326008)(2900100001)(50226002)(36756003)(14444005)(68736007);DIR:OUT;SFP:1101;SCL:1;SRVR:AM0PR04MB4291;H:AM0PR04MB4211.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: IGdfaLWgiGcUhyl05LvI6/yYA0fJt0aFmbLfhrzXT/GmbYhOgl1ihs/pJ/cA1V3knXYHffGBZwCACYXAaa/O2v8EDV8xKP8gggJC0XB9TtriL8s/Lw0Gq5ZcBeY4mZ4rwlcMiffwjIkPeVlAXOhlbwzx4/5Fjd55TSMMKJt/+bb+kjWylBwJB8WtXp+6r664Lj0vK/7C73mKaweWYxXAoqxUhRl8Y4DnkpJYhekaJVigFXKgn0cGr9PRBwxYz1eYjL5vNzFrW+7L4isRsmeEzJkAhAGR1MjoUDlIvrv/zxQPvH6uJgklhG3Ms2QIYuqHh6mm0mTqgnnG1w6ulVvLN7TTr4zKj6nSpqALok73dXM= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a9e202ec-70ee-49be-7702-08d64a3150e1 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Nov 2018 13:01:39.3532 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4291 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Adding CLK_FRAC_DIVIDER_ZERO_BASED flag to indicate the numerator and denominator value in register are start from 0. This can be used to support frac dividers like below: Divider output clock = Divider input clock x [(frac +1) / (div +1)] where frac/div in register is: 000b - Divide by 1. 001b - Divide by 2. 010b - Divide by 3. Cc: Stephen Boyd Cc: Michael Turquette Signed-off-by: Dong Aisheng --- ChangeLog: v3->v4: * no changes v2->v3: * no changes v1->v2: * improve comments suggested by Stephen --- drivers/clk/clk-fractional-divider.c | 10 ++++++++++ include/linux/clk-provider.h | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c index fdf625f..7ccde6b 100644 --- a/drivers/clk/clk-fractional-divider.c +++ b/drivers/clk/clk-fractional-divider.c @@ -40,6 +40,11 @@ static unsigned long clk_fd_recalc_rate(struct clk_hw *hw, m = (val & fd->mmask) >> fd->mshift; n = (val & fd->nmask) >> fd->nshift; + if (fd->flags & CLK_FRAC_DIVIDER_ZERO_BASED) { + m++; + n++; + } + if (!n || !m) return parent_rate; @@ -103,6 +108,11 @@ static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate, GENMASK(fd->mwidth - 1, 0), GENMASK(fd->nwidth - 1, 0), &m, &n); + if (fd->flags & CLK_FRAC_DIVIDER_ZERO_BASED) { + m--; + n--; + } + if (fd->lock) spin_lock_irqsave(fd->lock, flags); else diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 08b1aa7..bee6453 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -594,6 +594,12 @@ void clk_hw_unregister_fixed_factor(struct clk_hw *hw); * @lock: register lock * * Clock with adjustable fractional divider affecting its output frequency. + * + * Flags: + * CLK_FRAC_DIVIDER_ZERO_BASED - by default the numerator and denominator + * is the value read from the register. If CLK_FRAC_DIVIDER_ZERO_BASED + * is set then the numerator and denominator are both the value read + * plus one. */ struct clk_fractional_divider { struct clk_hw hw; @@ -613,6 +619,8 @@ struct clk_fractional_divider { #define to_clk_fd(_hw) container_of(_hw, struct clk_fractional_divider, hw) +#define CLK_FRAC_DIVIDER_ZERO_BASED BIT(0) + extern const struct clk_ops clk_fractional_divider_ops; struct clk *clk_register_fractional_divider(struct device *dev, const char *name, const char *parent_name, unsigned long flags,