Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6650904imu; Wed, 14 Nov 2018 05:03:56 -0800 (PST) X-Google-Smtp-Source: AJdET5fsRVYpYpC+Q4TdwOe+JGy6oiMJBOKKGkJRU+VTN5+8kOib9Nupf1VyvfRPihW5K9kZP85x X-Received: by 2002:a17:902:b943:: with SMTP id h3-v6mr1755361pls.124.1542200635963; Wed, 14 Nov 2018 05:03:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542200635; cv=none; d=google.com; s=arc-20160816; b=hnHBMCs6Dr1WGas2VJ7Y6oOkNA/IjjhJPKYJyYke2dPAiG0LWEpq+znOcQJMTRlaPf pW9WpY+4+4DbNjhsRJSLA68sNtyDul2Hc4BGSNoHckMrYB/jfm/CQ8tGcaDp73XrdwPB G5qeRE2ywZAoaZkQM3h/2m9zECEpUfan2zHZTfJKWof+wx8J879tVihUf1QvVRVV58uF 4R5tPoM0MDHjLyaT/2rUmJFbPcipuI1Lm+PWsozM6rOQ6d9zY55fRDqXT2e0OV/WKsqW a2YYoQM+e4hmhmWlKAByv8p0CkCfhS3HFfuO6P14On04JqDec7tHxHV6rO+3wtldjllg sOpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature; bh=keQeZnA12ucPSlee+fWKuypU6DmryFB6Qug2eeyJuM4=; b=U6olEZOLVu0C/Qj43T72YPc8wZYcwpR/gUmOe7778JyUZ5RMEDiAH3VutSbd7YdD8h H5ZyaaXFBk9En0Rwt5eq+V55pNcf1xNe6TFdMDPnMDwfgNKtSx+kMWQi+CLj4HCMlwTc kJ0PzdnX8AlEb9YWTUrNFM9M/9/yDVyTkqP+hIc6jN/f5T7P1eiapmg7PMqupukPTiSn mwEFpXyLh9i9Aiv879vr40UPq4zjS6GVmVDSoGGpZh10s9hZXBh9QJ45qgV8068hEzJr 5NXl3OJjsNVIGfe3I3MjcnaSpTpr44HeFBI2CZrKYd2NHLW6fdSDD//ceu8163RwWIyb 6Jzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=hYqou105; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u22si22614250pgk.335.2018.11.14.05.03.39; Wed, 14 Nov 2018 05:03:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=hYqou105; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733235AbeKNXEx (ORCPT + 99 others); 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 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 =3D 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-fractio= nal-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 *h= w, m =3D (val & fd->mmask) >> fd->mshift; n =3D (val & fd->nmask) >> fd->nshift; =20 + if (fd->flags & CLK_FRAC_DIVIDER_ZERO_BASED) { + m++; + n++; + } + if (!n || !m) return parent_rate; =20 @@ -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); =20 + 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 { =20 #define to_clk_fd(_hw) container_of(_hw, struct clk_fractional_divider, hw= ) =20 +#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, --=20 2.7.4