Received: by 10.223.176.46 with SMTP id f43csp980712wra; Fri, 19 Jan 2018 05:12:41 -0800 (PST) X-Google-Smtp-Source: ACJfBosZflRgnb4jlckLXlICEyTtMY2aTAbdYj5WldaWlxDq034ChuXWfVR6LYo0o+vguMUSq2Rp X-Received: by 10.101.98.148 with SMTP id f20mr39927033pgv.392.1516367561512; Fri, 19 Jan 2018 05:12:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516367561; cv=none; d=google.com; s=arc-20160816; b=qhDziWiDKN2vjvcUGQy3LBHArHVzimB2wAxFJNqu7l/xfZZFG9W/A/c6fDcdWZDXWP 1T95bj6sxq3z4Vn7UCkhJOFsaC7hqlsb75HmsZM7hg+dX1couq7mvj/leHpKrFot3Xdr NQ1Jjy+WYqQO//p394lW1/M0Y+nNNs6oNgf5TtNqbBGP/2GFMD0EruSk2EbgVttav/7g qtVeTNbueKc1IMKxnQSje5d7/BrhRZj+pXgKlyzmD1umkDCK/rwLci1pro5VX/+wAD0X RkUmyf2a8w5uA0Er73iMhMG+vTqA4HBEDbHGFPokxcvmFhbNm1OZ9u64YaH/O29LcAwp sPHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results; bh=VPNm5zqXcqvf4JS0PHRgEFlb6yPiqQkniMs30mG18GE=; b=e+/hKT0LakFQbd9VdkUTJlYNGD3O0em1jeVnD+7+zzlhh/FEogA8gAgX/P1b5JfUg4 gkK+7L+hLrkOQep/wEIY1mcFmqioV7x9xj7i9TMTJw4YIn3CBax4VOx7C0FtlWQKCOsF 3UoPLPdTWTdf+rcPFvjolbuXxfCH5YBedwPVRgz4Q/S0EUxkZxmSzYntBE7xE6XXCRkn 2OUf4EfgDLvCVNwTRiXtYKNY1UjdJy2c+WCPmx1KfqUnNPKnA1Zo15zjjPTFPejxzAt8 ep0mY4kd6RGuX2Hue9hepvtBC28mhqEL6ZLTcZz3o6A9AxVd6cBODZm5aejEDBYa+qyY 2ccw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 v63si9281489pfd.399.2018.01.19.05.12.27; Fri, 19 Jan 2018 05:12:41 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755665AbeASNLq (ORCPT + 99 others); Fri, 19 Jan 2018 08:11:46 -0500 Received: from mail-bl2nam02on0060.outbound.protection.outlook.com ([104.47.38.60]:52048 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755439AbeASNLa (ORCPT ); Fri, 19 Jan 2018 08:11:30 -0500 Received: from BN3PR03CA0103.namprd03.prod.outlook.com (2603:10b6:400:4::21) by SN2PR03MB2365.namprd03.prod.outlook.com (2603:10b6:804:e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.428.17; Fri, 19 Jan 2018 13:11:28 +0000 Received: from BL2FFO11FD051.protection.gbl (2a01:111:f400:7c09::128) by BN3PR03CA0103.outlook.office365.com (2603:10b6:400:4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.428.17 via Frontend Transport; Fri, 19 Jan 2018 13:11:28 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11FD051.mail.protection.outlook.com (10.173.161.213) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.345.12 via Frontend Transport; Fri, 19 Jan 2018 13:11:28 +0000 Received: from b29396-OptiPlex-7040.ap.freescale.net (b29396-OptiPlex-7040.ap.freescale.net [10.192.242.1]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id w0JDBGiM013190; Fri, 19 Jan 2018 06:11:24 -0700 From: Dong Aisheng To: CC: , , , , , , , , , Dong Aisheng Subject: [PATCH V3 02/10] clk: fractional-divider: add CLK_FRAC_DIVIDER_ZERO_BASED flag support Date: Fri, 19 Jan 2018 21:11:02 +0800 Message-ID: <1516367470-24340-3-git-send-email-aisheng.dong@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516367470-24340-1-git-send-email-aisheng.dong@nxp.com> References: <1516367470-24340-1-git-send-email-aisheng.dong@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131608410885369875;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(7966004)(346002)(376002)(39380400002)(39860400002)(396003)(2980300002)(1109001)(1110001)(339900001)(189003)(54534003)(199004)(97736004)(47776003)(5660300001)(36756003)(508600001)(6916009)(2950100002)(6666003)(8656006)(48376002)(50466002)(59450400001)(16586007)(86362001)(26005)(77096007)(54906003)(85426001)(51416003)(316002)(76176011)(53936002)(2906002)(8676002)(81156014)(50226002)(81166006)(105606002)(8936002)(7416002)(305945005)(2351001)(106466001)(4326008)(104016004)(68736007)(356003);DIR:OUT;SFP:1101;SCL:1;SRVR:SN2PR03MB2365;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD051;1:g2E/pakxapS0Ikz16TZs0RrKanHdV58F+aLPZi7cPJfDtm6NaXWBBN/haMrn7R1EQyiJTKzV3c07K3O4sLiPdWxD3ovTHhzM+X07iQldlXtd40IuZNVQvsMDe1/BVSQN MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a87f4bf0-3da2-4094-b013-08d55f3e26bd X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(5600026)(4604075)(2017052603307);SRVR:SN2PR03MB2365; X-Microsoft-Exchange-Diagnostics: 1;SN2PR03MB2365;3:X3b2B75nWY79XitpqzDnDOMfWXBhNmktR8PXHrWkb7Cesk4EZFVQdoWGEz/K1uZPawZmsgcXQ9hiVChwqfaq5OmLQq0IyLE2jzsnrPb9ChfYsJFYktTNT+HBLyQyYImnpI0LwEo1OYSLXsUdhYOVZzhOMIjwK/XNKiHREUgYdXfzkvkxfQkWd/geIs+Z7aSPNOAVgtaDd1tzRieJpfogJ+GxZwJHXXzvcu3QTmHGLp3A4O/njVceSmEqu2BrnXMeOchkfD4gONMvRSejOMOxYiqgcDzzvF+N9GBc1/+dLGrjy+TgyoTUsTD+pEEDWKKgBEUaZnZyoYUH3hvQNGS8JQfzpvxY/1G6OQCUfeIFUYg=;25:61bvOfCTYEjdCOrkGtc+FjWfFASbL4xrLRB/gLRmtLRLIWAU4/gspT57VT3IjxL2EtZC3nRSqBI3AON/mynLyQo0FEBbGzVvQXEjn/dGP1BaWRWqPncXvt/Mad90ySz04KKqDbaTku9Gr0uWQ/76tMoDn17QzOwr7z0UGmroxKDjDaVo6vJE7fxRc8LbqaWiu42T1JmwnRPC9PkMCNgJXxxqEM7JTiTGA38i7Dp/gpVtlcvJ0wvYDwhl6A78BOx2dhC0ZEcVWngwdP3UT0h/7QFn9S6lSMtph3b21X/orztFIO93DGGqNDULxzeameHBSFo4wqRAHyPYLlG16FMtew== X-MS-TrafficTypeDiagnostic: SN2PR03MB2365: X-Microsoft-Exchange-Diagnostics: 1;SN2PR03MB2365;31:Gsx6y8ChE6lYx/4as2faXyh/9nOHcRuiLutKgKOJRVBSw1qaj6KqwnhwHyHx0xv4nEx0z380w1L5fHqPbh8nKj47iPbr2Q+3o6lfjrU2wjv6SA/cATA0BKOLZaxUHvCvbgyO/e84fzdvE9LUj6JhlsSYNQWh2jOORH+uXLQARo2F5BDgBvlwq9UCpM+8VMNeVggrl/z4WLlyBRLK4bhhuLI9VZ19sKKU2FAAlquFmZo=;4:kYrYAkHnm0oUoVR6haPe2Zm/unBINgvbLxRlT9d4rNHW4ifkdM+3rCF6dfbq6Mfk6ax+geEUyaurwVvcEWCBleqVRrHFzTYLeUhbhfdMZ9KzXO9D2633aiVAmI/JL6uAC9q+1YO+62NDgeXIGBcbGeKRRVDP1hrhwbW3ZpcGsIlDMbpILMCTm0pdx2d/J8WVyOgech9W7Q9nqQD4JORDIwxrPxdf1slZ7C1g8y8NFxrhLtK8eP9o1BoO9n5araqSQ7V8aMWyaUz3GgIlEe5xEJqirkygiEr2GPG82LnjPmNtVEFcV+tQVflGCDm+ymSD X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6095135)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231023)(2400077)(944501161)(10201501046)(3002001)(6055026)(6096035)(20161123565025)(20161123556025)(20161123561025)(20161123559100)(20161123563025)(201703131430075)(201703131441075)(201703131448075)(201703131433075)(201708071742011);SRVR:SN2PR03MB2365;BCL:0;PCL:0;RULEID:(100000803101)(100110400095)(400006);SRVR:SN2PR03MB2365; X-Forefront-PRVS: 0557CBAD84 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN2PR03MB2365;23:JM1tHsEi5RJ838yaw2wFSqUpKxyMOzhsLwVf5HTHT?= =?us-ascii?Q?Z3KhOhJvhq5Aoil/FaHXwY5AnxPUVD81STWL5oxupFtbOimNM6Cz2mc90xt3?= =?us-ascii?Q?J/b3j+wyTahnfIsdAgAI4e7ZFzCmC6RvU8oFzHUpC828uLVIHFd4btqWOtDy?= =?us-ascii?Q?W9epWsl8XpVha0F/dP7xy3nra2s9Gve843N7Zw2CfxIMgTLIYvAlfkGW+WpW?= =?us-ascii?Q?fyh43KZcFngROLhv6a2kZ/Xs8pdllgk53DDfxoQmry0v854+wWuYlus3JIRY?= =?us-ascii?Q?1JnvmnzqUm5tl3AqiVu1RgK+o2W6rj8qtGOGxSlit0KZX5zFdujNyX3eFsO5?= =?us-ascii?Q?hXUu5cSZdJP2KHZmzs262u77hxMGIzvYktPgQMk54qaueGBJPSZFkezsS6OZ?= =?us-ascii?Q?qx8fpnoAFl11kJGW/SntjTEMmB9WbmAjkShPusUpjgrSk28P13fDGk4gls6q?= =?us-ascii?Q?wg8K8hKSyb8swZnMaoeQDM9FdZLNUHYS8hk0iDY2ixMr0o9m2wgQhYCLBzm/?= =?us-ascii?Q?B3HJk4XVhq3YwIR1nZ+c4EOjTYQvtVa5CmExx8xYgE433JEvIu2QHqTSshmG?= =?us-ascii?Q?GxPPE2qCiiQ8Lh72ZBS/5KwDdSN66GsvenoKtTqDAjO6jwZe2Wb7TWIoNZ2g?= =?us-ascii?Q?c3R16BqmDep4dXt7PEIBfbbNLR1Xvu3CSxwNaratQ1XnPDAxOkYzGYhZ3Bpv?= =?us-ascii?Q?lcC3RKEKCkZoEyAGkYES21pJevicKyw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yOf2Mpd7BWnXZx48m56Pka+jUqBuYTw9uKje60y/1dgFw=;24:jW7Q5jzZ1CQdeNJbHOAPM7EJtrGrhC42GrgKBZoDdDUBly9xwL1iw91Rcb9eyTldKKMqNsZg86acX7XvD0+d/F5Lk5OolTZll66C5g2Hb8k=;7:OoIdy44WTJy5z1DLGoXmjlua3cp3ZgBckJrg5TxiqqR47FECt6Yh+HJDVC0fQtOjA91DZ9pWE2OHc5ThGACnWGNl+ztRdn0QBhZrLxLBWh/H7hgCY3e3j8x/8iWIso0Pt1UsxjIc2VxtOE09Gjhl+4eGLyfznHhkgFpM+i+Tzt3T1+88gddRuAobDUSaPHoJZEeaNEJfBnyYlieMiJSsAZXxxiqZxgNkon0AOr2efUk1uc3lbSc+RPQI5wkmDTYu SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2018 13:11:28.3497 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a87f4bf0-3da2-4094-b013-08d55f3e26bd X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2365 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 = 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: 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 68ccd36..cb55b67 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -566,6 +566,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; @@ -585,6 +591,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, -- 2.7.4