From patchwork Fri Apr 27 18:56:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aisheng Dong X-Patchwork-Id: 10369647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 86257602DC for ; Fri, 27 Apr 2018 18:57:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5AB7629285 for ; Fri, 27 Apr 2018 18:57:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F15229289; Fri, 27 Apr 2018 18:57:28 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 8904129285 for ; Fri, 27 Apr 2018 18:57:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758574AbeD0S50 (ORCPT ); Fri, 27 Apr 2018 14:57:26 -0400 Received: from mail-db5eur01on0051.outbound.protection.outlook.com ([104.47.2.51]:44880 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758522AbeD0S5X (ORCPT ); Fri, 27 Apr 2018 14:57:23 -0400 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; bh=ZuwfTBOI1mxVllVGh9X0E2c+H958eNxvFqkPdM0D610=; b=NYOqg4FOoWJTIHrPfYIweBR/bIvvPkwkL+EFXKSp1SUC79uFTEQzCXRL9ZuQ3Xy+sbRi+wfclcfgtn1N9oq3E22trO5jQS1KCJEt2XGU7+fxLrUXk5vKwveGZJJdifayb0n9frej4JC85NpI7X86LPVMmgWp+7IkVouf8lPGTns= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=aisheng.dong@nxp.com; Received: from b29396-OptiPlex-7040.ap.freescale.net (119.31.174.66) by AM6PR04MB4213.eurprd04.prod.outlook.com (2603:10a6:209:4f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.715.18; Fri, 27 Apr 2018 18:57:17 +0000 From: Dong Aisheng To: linux-clk@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, sboyd@kernel.org, mturquette@baylibre.com, shawnguo@kernel.org, fabio.estevam@nxp.com, linux-imx@nxp.com, kernel@pengutronix.de, Dong Aisheng Subject: [PATCH 03/12] clk: imx: scu: add scu clock divider Date: Sat, 28 Apr 2018 02:56:34 +0800 Message-Id: <1524855403-15301-4-git-send-email-aisheng.dong@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524855403-15301-1-git-send-email-aisheng.dong@nxp.com> References: <1524855403-15301-1-git-send-email-aisheng.dong@nxp.com> MIME-Version: 1.0 X-Originating-IP: [119.31.174.66] X-ClientProxiedBy: TYAPR01CA0025.jpnprd01.prod.outlook.com (2603:1096:404:28::13) To AM6PR04MB4213.eurprd04.prod.outlook.com (2603:10a6:209:4f::11) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:AM6PR04MB4213; X-Microsoft-Exchange-Diagnostics: 1; AM6PR04MB4213; 3:3dECOmpoiBHgDd932dMAKbuySn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CdMyudP12jlmw3Nw1xJd06Q0h5P+U9+WvJOeFDE1izSB4xq+WlOwgm1b8T/ARO++kuZR34Hsz+/08XkJ490eQW8axQxn/u/dRQCBFXgjNhS9VSMhhF2ScunFS5s5f0yUHfnR7sOC1i7xGV+abpQFOWI9hLarG+eoGMHhS2iExsiNcyQHSmBYL4ptIv54z+K98ZFHhleVW3jfGjBZYMEmOe8c04SdpOHetiPexo0GzjVRO6mw1i/8h1fT2Qf8Yu2Kxjp+Ss3fCx8ak0hRjbLj27I2aQvVquxReU0CKduH9DMo/CPv1/xkXqFB/ia8oojpMSevF; 4:kIq8jsUn5YzvnBbm/TKjDSwx/zNNB5ga1fXZQkqJMnrU6X3DTGFIYNwcaVjKs521xD26P1D/WltvNbYRqS7FCy+bYSeO7pvchPiMHbX7/AgCVPI/rtHCjcfQsEkd3TtZWl2Ru2u6hApFF6DPyzZ5KBT4Vg57M5Aad1+wXxpfpNUaCJ+Sc0b+fy7Vp2hmY+IovNb1Gw7ChCogPSWvqsGV88wmKXKCSXXPxySGWHE5uwAi5GOBPdukT0VAMh6MaWDhZLAV9n/WCRUpVHIb26LpNAZpooT4gj2XHMv8v54B3XXbesTTB8hYjTYn0A+lclVx X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(3231232)(944501410)(52105095)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011); SRVR:AM6PR04MB4213; BCL:0; PCL:0; RULEID:; SRVR:AM6PR04MB4213; X-Forefront-PRVS: 0655F9F006 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39860400002)(39380400002)(366004)(396003)(346002)(376002)(199004)(189003)(76176011)(97736004)(26005)(305945005)(48376002)(47776003)(16526019)(186003)(6116002)(50226002)(7736002)(16586007)(106356001)(36756003)(50466002)(2906002)(51416003)(66066001)(3846002)(52116002)(316002)(6506007)(105586002)(386003)(25786009)(8936002)(4326008)(5660300001)(81156014)(81166006)(486006)(8676002)(6916009)(11346002)(6666003)(446003)(476003)(2351001)(956004)(86362001)(2616005)(2361001)(68736007)(6486002)(6512007)(59450400001)(478600001)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR04MB4213; H:b29396-OptiPlex-7040.ap.freescale.net; 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-Exchange-Diagnostics: =?us-ascii?Q?1; AM6PR04MB4213; 23:dJTtMc6QimjOY75elUp0ItLdwI2K3wso3dAiQ2BIC?= =?us-ascii?Q?mUVMLmvpFEiBdf3cYVxpi4ITkIGZtMYmGc81YAq60d/Py62NfXBp7De2sf9+?= =?us-ascii?Q?1Ua5fsH0+Sw2rJ9Te9WMPfrPwWk3lTRz22Wh6KbpUGLKsJ4JRfdpWSFmf70s?= =?us-ascii?Q?wVzEQv2ota34b6gh7JN06JY6GNeC6r/IS8J0MAMo99pQzzamesICUP+wRaXA?= =?us-ascii?Q?RcPWGGBG9najCgJLH9xdBNEWXAIJvs15UZEyE/rYfLO3HFBv7Tk70P259naq?= =?us-ascii?Q?Ms1Df+hdik/x1Cl1tprmfeJp4HLhU9rE7/WuGi42W4gDDUIbF2BhpZ9G+/8y?= =?us-ascii?Q?0tpaK+zkeRD//3ZpETevSyrCM3enwGp12nQnBmNUUxPFbrs8oz1ioci2ZDlT?= =?us-ascii?Q?1E5x6Stp+24gZyn6L6kFnXXYyGbeHbL3U/z6MwKdodlNRlA8VDeImwWfUR51?= =?us-ascii?Q?02MOQzARJ4As7TJeRO6/qm0VYtp6TtAgprM8dPHKX1rxpz0Txr4S59gJrA1j?= =?us-ascii?Q?bVMKbZ48/Ex9p8GEAm1tMxCC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kg1ZaR/emCZlxpeX2vou2Rxvf1hHL4uapsis3mwff3a4yZ/yAcw02iLxOu0HBfWow0cuwLHF66VAbVhmMPHgP/ovTRTRxU X-MS-Office365-Filtering-Correlation-Id: 1320b252-d46b-4202-a290-08d5ac70b4ca X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2018 18:57:17.7285 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1320b252-d46b-4202-a290-08d5ac70b4ca X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB4213 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 Add scu based clock divider. Cc: Shawn Guo Cc: Sascha Hauer Cc: Fabio Estevam Cc: Stephen Boyd Cc: Michael Turquette Signed-off-by: Dong Aisheng --- drivers/clk/imx/scu/Makefile | 3 +- drivers/clk/imx/scu/clk-divider-scu.c | 129 ++++++++++++++++++++++++++++++++++ drivers/clk/imx/scu/clk-scu.h | 18 +++++ 3 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 drivers/clk/imx/scu/clk-divider-scu.c diff --git a/drivers/clk/imx/scu/Makefile b/drivers/clk/imx/scu/Makefile index 7dead13..7e360e2 100644 --- a/drivers/clk/imx/scu/Makefile +++ b/drivers/clk/imx/scu/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_MXC_CLK_SCU) += \ - clk-scu.o + clk-scu.o \ + clk-divider-scu.o diff --git a/drivers/clk/imx/scu/clk-divider-scu.c b/drivers/clk/imx/scu/clk-divider-scu.c new file mode 100644 index 0000000..c1afd32 --- /dev/null +++ b/drivers/clk/imx/scu/clk-divider-scu.c @@ -0,0 +1,129 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2016 Freescale Semiconductor, Inc. + * Copyright 2017~2018 NXP + * Dong Aisheng + * + */ +#include +#include +#include +#include +#include +#include +#include + +#include "clk-scu.h" + +struct clk_divider_scu { + struct clk_hw hw; + sc_rsrc_t rsrc_id; + sc_pm_clk_t clk_type; +}; + +static inline struct clk_divider_scu *to_clk_divider_scu(struct clk_hw *hw) +{ + return container_of(hw, struct clk_divider_scu, hw); +} + +/* + * clk_divider_scu_recalc_rate - Get clock rate for a SCU clock + * @hw: clock to get rate for + * @parent_rate: parent rate provided by common clock framework, not used + * + * Gets the current clock rate of a SCU clock. Returns the current + * clock rate, or zero in failure. + */ +static unsigned long clk_divider_scu_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct clk_divider_scu *div = to_clk_divider_scu(hw); + sc_pm_clock_rate_t rate = 0; + sc_err_t sci_err; + + sci_err = sc_pm_get_clock_rate(ccm_ipc_handle, div->rsrc_id, + div->clk_type, &rate); + + return sci_err ? 0 : rate; +} + +/* + * clk_divider_scu_round_rate - Round clock rate for a SCU clock + * @hw: clock to round rate for + * @rate: rate to round + * @parent_rate: parent rate provided by common clock framework, not used + * + * Gets the current clock rate of a SCU clock. Returns the current + * clock rate, or zero in failure. + */ +static long clk_divider_scu_round_rate(struct clk_hw *hw, unsigned long rate, + unsigned long *parent_rate) +{ + /* + * Assume we support all the requested rate and let the SCU firmware + * to handle the left work + */ + return rate; +} + +/* + * clk_divider_scu_set_rate - Set rate for a SCU clock + * @hw: clock to change rate for + * @rate: target rate for the clock + * @parent_rate: rate of the clock parent, not used for SCU clocks + * + * Sets a clock frequency for a SCU clock. Returns the SCU + * protocol status. + */ +static int clk_divider_scu_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + struct clk_divider_scu *div = to_clk_divider_scu(hw); + sc_err_t sci_err; + + sci_err = sc_pm_set_clock_rate(ccm_ipc_handle, div->rsrc_id, + div->clk_type, + (sc_pm_clock_rate_t *)&rate); + + return sci_err ? -EINVAL : 0; +} + +static const struct clk_ops clk_divider_scu_ops = { + .recalc_rate = clk_divider_scu_recalc_rate, + .round_rate = clk_divider_scu_round_rate, + .set_rate = clk_divider_scu_set_rate, +}; + +struct clk_hw *imx_clk_register_divider_scu(const char *name, + const char *parent_name, + sc_rsrc_t rsrc_id, + sc_pm_clk_t clk_type) +{ + struct clk_divider_scu *div; + struct clk_init_data init; + struct clk_hw *hw; + int ret; + + div = kzalloc(sizeof(*div), GFP_KERNEL); + if (!div) + return ERR_PTR(-ENOMEM); + + div->rsrc_id = rsrc_id; + div->clk_type = clk_type; + + init.name = name; + init.ops = &clk_divider_scu_ops; + init.flags = CLK_GET_RATE_NOCACHE; + init.parent_names = parent_name ? &parent_name : NULL; + init.num_parents = parent_name ? 1 : 0; + div->hw.init = &init; + + hw = &div->hw; + ret = clk_hw_register(NULL, hw); + if (ret) { + kfree(div); + hw = ERR_PTR(ret); + } + + return hw; +} diff --git a/drivers/clk/imx/scu/clk-scu.h b/drivers/clk/imx/scu/clk-scu.h index 6b39e4a..ee197f9 100644 --- a/drivers/clk/imx/scu/clk-scu.h +++ b/drivers/clk/imx/scu/clk-scu.h @@ -7,6 +7,7 @@ #ifndef __IMX_CLK_SCU_H #define __IMX_CLK_SCU_H +#include #include #include @@ -15,4 +16,21 @@ extern sc_ipc_t ccm_ipc_handle; int imx_clk_scu_init(void); +struct clk_hw *imx_clk_register_divider_scu(const char *name, + const char *parent_name, sc_rsrc_t rsrc_id, + sc_pm_clk_t clk_type); + +static inline struct clk_hw *imx_clk_divider_scu(const char *name, + sc_rsrc_t rsrc_id, sc_pm_clk_t clk_type) +{ + return imx_clk_register_divider_scu(name, NULL, rsrc_id, clk_type); +} + +static inline struct clk_hw *imx_clk_divider2_scu(const char *name, + const char *parent_name, + sc_rsrc_t rsrc_id, sc_pm_clk_t clk_type) +{ + return imx_clk_register_divider_scu(name, parent_name, rsrc_id, clk_type); +} + #endif