From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16C80C65BAE for ; Thu, 13 Dec 2018 15:44:24 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D8DFC20879 for ; Thu, 13 Dec 2018 15:44:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="s+jISmBN"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="xnl0c2Je" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D8DFC20879 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/6V+kOg/Ms2l1fxmwGLzjx6XCJNLv3TM7u+O5hjqrtE=; b=s+jISmBNLo3DvL Uf+4YU5qf92e8X3lYiLh3WKfaGzYe56X0z9uWjmYSqSyO5D2qsE//Epm0mcptplKY6zlHGgY53oTb +9Aoft5MGEAzdhXL96dF/dLsX564SkBNqg1Fri+CWKKsLqzWxjPTxn8gyrT1XkDCQNvfBHiqOuF/H LcAW9aiSuZS0LZb4iWJoxymRFQZH5ME83+O3//EQK/s7zvpfZUs+zSsffHYM7BDs/e5z4FKm10jiO /+m0mhDdQC+nA8Fh+uAZRjomlm4AhNQndtoNcILUOlMIAYiIXUq95POtV3fLryy1cKNBL+ky/HesK NFi2Tbt4Fi+x7fg7HD5w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gXT9w-0000Ze-Nb; Thu, 13 Dec 2018 15:44:20 +0000 Received: from mail-eopbgr70085.outbound.protection.outlook.com ([40.107.7.85] helo=EUR04-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gXT8u-0007xM-Gw for linux-arm-kernel@lists.infradead.org; Thu, 13 Dec 2018 15:43:18 +0000 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=8VQywlcMhuO7guuZgOpUzww6ax9AoEwkQfFe+tIfliQ=; b=xnl0c2JecIoeplDp/flFDuVeHmyodz1A4I0CMEPSbyCbCm4JVCHHYlrjniytQGMK/GRrnIDorfnqXtn0KwmpXyKtmJeKpP4cWID5YJEX62KRAkdSUVRMbI7TOTTY7nAK4ZBMea3+qFA2cQzz0L9fRjsLFGlggqFwnNtztsO7wgw= Received: from AM0PR04MB4211.eurprd04.prod.outlook.com (52.134.126.21) by AM0PR04MB5843.eurprd04.prod.outlook.com (20.178.118.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.18; Thu, 13 Dec 2018 15:43:01 +0000 Received: from AM0PR04MB4211.eurprd04.prod.outlook.com ([fe80::31e3:2aa6:8d93:9927]) by AM0PR04MB4211.eurprd04.prod.outlook.com ([fe80::31e3:2aa6:8d93:9927%2]) with mapi id 15.20.1404.026; Thu, 13 Dec 2018 15:43:01 +0000 From: Aisheng Dong To: "linux-clk@vger.kernel.org" Subject: [PATCH V12 4/5] clk: imx: add lpcg clock support Thread-Topic: [PATCH V12 4/5] clk: imx: add lpcg clock support Thread-Index: AQHUkvqHRDXRSU553k647B3txP4Dig== Date: Thu, 13 Dec 2018 15:43:01 +0000 Message-ID: <1544715442-8902-5-git-send-email-aisheng.dong@nxp.com> References: <1544715442-8902-1-git-send-email-aisheng.dong@nxp.com> In-Reply-To: <1544715442-8902-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: HK2PR04CA0086.apcprd04.prod.outlook.com (2603:1096:202:15::30) 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; AM0PR04MB5843; 6:EYux/9rEBiOD+ud4malCt3Uip98w4qF3gsZANgAlqy+025J9R/tZzTRmXMDMj1tK2cekRPTFiqy8gROK5LmtW6hwgETjoxzz8fmlrJqDojdzZJVFyHrdVn9rQfMxx1Hj6WITzJCzRBgAiRFjwfqFmQKizK43uAwmFivXWlhVfFk9VLMYzMTY1Prq+5HbiobSUdi3C6Vn3taQ9weYdwA4bQ/QWAl6X3KDIeE1w0lAqytITnDL4pB7Q4hQ6+OOMBJnrU7+9DBQ6KeUt9W7ixXe/8LwMzLKWb+qB3aYIaQL2ETCg/C8M8PzjiPPyVdmG/xAdIlTAoYoJpp+4MOk8P/NJF9sKRuWDWwvSdGS5VKQwp8eFWaFCHPip65n2nNjg6j/VItlBuA00cUJcclCqeWTxn7/Mm5aVOhyVPx4jpqYiW8R8t6E0BDXm74Vz4aD7P8iAa5PxpRwd5FS5IWo566k3g==; 5:V9CEdB0PrzU/wGCzFj5RymF8DrmvzF8rUudR1oVwyg1oHbVqRY4BUUcK5vAsj/8xLVfPd+hCXkCfVbwL8SOd870AArU3KfT3suqbwrs1gVs1eY7urL999ZJ+epMTIbDRFx0LQwTvB0i+c5PXfIlKozUMAV0hG5NA8LEDq5gWDk8=; 7:8QZA9KVt6/trFCWp9746mb7PFxdcwmdG2SN2qot0LiqgJWooLCa2IDdsh+DY7gD8o/aUnVGEjr37fDQP1MI2yGJu0tBnFMCFpyXsJQA4c/e3DVqfdv3oti9WkC3J0aTYymqBKcJx4DOgHcyBinHRoA== x-ms-office365-filtering-correlation-id: a6d2a27e-254e-49f7-498f-08d66111aa01 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:AM0PR04MB5843; x-ms-traffictypediagnostic: AM0PR04MB5843: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(3230021)(999002)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93001095)(3231475)(944501520)(52105112)(6055026)(148016)(149066)(150057)(6041310)(20161123564045)(20161123558120)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095); SRVR:AM0PR04MB5843; BCL:0; PCL:0; RULEID:; SRVR:AM0PR04MB5843; x-forefront-prvs: 088552DE73 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(979002)(39860400002)(396003)(376002)(136003)(346002)(366004)(199004)(189003)(54534003)(71190400001)(71200400001)(6916009)(6436002)(6486002)(97736004)(478600001)(14454004)(54906003)(4326008)(256004)(44832011)(14444005)(5640700003)(8676002)(106356001)(105586002)(2351001)(25786009)(8936002)(316002)(36756003)(81166006)(81156014)(2616005)(11346002)(53936002)(476003)(486006)(446003)(2906002)(50226002)(68736007)(7736002)(99286004)(76176011)(2501003)(305945005)(5660300001)(52116002)(3846002)(6116002)(186003)(86362001)(575784001)(6512007)(102836004)(66066001)(386003)(26005)(6506007)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR04MB5843; 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: vAUBaekckS5rJH9e/NwTqScDTAU8O7sMMdqj6TidwqzzN3j4JtIj7SESECo4tBnZqWnsKHGDxVLpoltdVneaOLeb2qNN73g5xoy+fVzATfEmlicdvxzU8d6om4TFfsEIr9f3iJRwmkypChv1yqVAgw3rl131MfAToponlsUEecHx7i64bF5Cmk/1ihJktz92d0PFpVjPjP6okFc2mgMwzd5hLuUTyk6uzlrgH6jrTF6TCItifxQaGDmlg5bGS401E4mhYiJckWWvUEsYbWgwUDnGZATWzZQGdKlDMLgcvOh4dI3NURwABsJz4m1ubzYH spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a6d2a27e-254e-49f7-498f-08d66111aa01 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Dec 2018 15:43:01.6825 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB5843 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181213_074316_681773_56000247 X-CRM114-Status: GOOD ( 18.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aisheng Dong , "sboyd@kernel.org" , "mturquette@baylibre.com" , dl-linux-imx , "kernel@pengutronix.de" , Fabio Estevam , "shawnguo@kernel.org" , "linux-arm-kernel@lists.infradead.org" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org The Low-Power Clock Gate (LPCG) modules contain a local programming model to control the clock gates for the peripherals. An LPCG module is used to locally gate the clocks for the associated peripheral. And they're bedind the SCU clock. Cc: Stephen Boyd Cc: Shawn Guo Cc: Sascha Hauer Cc: Fabio Estevam Cc: Michael Turquette Signed-off-by: Dong Aisheng --- ChangeLog: v9->v12: * no changes v8->v9: * use readl_relaxed() as it does not need insert barrier * a small code logic improvement suggested by Stephen v7->v8: * add doc for struct clk_lpcg_scu * remove unneccessary reg checking v6: separate from [PATCH V5 5/9] clk: imx: scu: add scu clock gate --- drivers/clk/imx/Makefile | 3 +- drivers/clk/imx/clk-lpcg-scu.c | 114 +++++++++++++++++++++++++++++++++++++++++ drivers/clk/imx/clk-scu.h | 3 ++ 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 drivers/clk/imx/clk-lpcg-scu.c diff --git a/drivers/clk/imx/Makefile b/drivers/clk/imx/Makefile index 31c19c5..657d82b5 100644 --- a/drivers/clk/imx/Makefile +++ b/drivers/clk/imx/Makefile @@ -21,7 +21,8 @@ obj-$(CONFIG_MXC_CLK) += \ clk-sccg-pll.o obj-$(CONFIG_MXC_CLK_SCU) += \ - clk-scu.o + clk-scu.o \ + clk-lpcg-scu.o obj-$(CONFIG_SOC_IMX1) += clk-imx1.o obj-$(CONFIG_SOC_IMX21) += clk-imx21.o diff --git a/drivers/clk/imx/clk-lpcg-scu.c b/drivers/clk/imx/clk-lpcg-scu.c new file mode 100644 index 0000000..fbf3416 --- /dev/null +++ b/drivers/clk/imx/clk-lpcg-scu.c @@ -0,0 +1,114 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2018 NXP + * Dong Aisheng + */ + +#include +#include +#include +#include +#include + +static DEFINE_SPINLOCK(imx_lpcg_scu_lock); + +#define CLK_GATE_SCU_LPCG_MASK 0x3 +#define CLK_GATE_SCU_LPCG_HW_SEL BIT(0) +#define CLK_GATE_SCU_LPCG_SW_SEL BIT(1) + +/* + * struct clk_lpcg_scu - Description of LPCG clock + * + * @hw: clk_hw of this LPCG + * @reg: register of this LPCG clock + * @bit_idx: bit index of this LPCG clock + * @hw_gate: HW auto gate enable + * + * This structure describes one LPCG clock + */ +struct clk_lpcg_scu { + struct clk_hw hw; + void __iomem *reg; + u8 bit_idx; + bool hw_gate; +}; + +#define to_clk_lpcg_scu(_hw) container_of(_hw, struct clk_lpcg_scu, hw) + +static int clk_lpcg_scu_enable(struct clk_hw *hw) +{ + struct clk_lpcg_scu *clk = to_clk_lpcg_scu(hw); + unsigned long flags; + u32 reg, val; + + spin_lock_irqsave(&imx_lpcg_scu_lock, flags); + + reg = readl_relaxed(clk->reg); + reg &= ~(CLK_GATE_SCU_LPCG_MASK << clk->bit_idx); + + val = CLK_GATE_SCU_LPCG_SW_SEL; + if (clk->hw_gate) + val |= CLK_GATE_SCU_LPCG_HW_SEL; + + reg |= val << clk->bit_idx; + writel(reg, clk->reg); + + spin_unlock_irqrestore(&imx_lpcg_scu_lock, flags); + + return 0; +} + +static void clk_lpcg_scu_disable(struct clk_hw *hw) +{ + struct clk_lpcg_scu *clk = to_clk_lpcg_scu(hw); + unsigned long flags; + u32 reg; + + spin_lock_irqsave(&imx_lpcg_scu_lock, flags); + + reg = readl_relaxed(clk->reg); + reg &= ~(CLK_GATE_SCU_LPCG_MASK << clk->bit_idx); + writel(reg, clk->reg); + + spin_unlock_irqrestore(&imx_lpcg_scu_lock, flags); +} + +static const struct clk_ops clk_lpcg_scu_ops = { + .enable = clk_lpcg_scu_enable, + .disable = clk_lpcg_scu_disable, +}; + +struct clk_hw *imx_clk_lpcg_scu(const char *name, const char *parent_name, + unsigned long flags, void __iomem *reg, + u8 bit_idx, bool hw_gate) +{ + struct clk_lpcg_scu *clk; + struct clk_init_data init; + struct clk_hw *hw; + int ret; + + clk = kzalloc(sizeof(*clk), GFP_KERNEL); + if (!clk) + return ERR_PTR(-ENOMEM); + + clk->reg = reg; + clk->bit_idx = bit_idx; + clk->hw_gate = hw_gate; + + init.name = name; + init.ops = &clk_lpcg_scu_ops; + init.flags = CLK_SET_RATE_PARENT | flags; + init.parent_names = parent_name ? &parent_name : NULL; + init.num_parents = parent_name ? 1 : 0; + + clk->hw.init = &init; + + hw = &clk->hw; + ret = clk_hw_register(NULL, hw); + if (ret) { + kfree(clk); + hw = ERR_PTR(ret); + } + + return hw; +} diff --git a/drivers/clk/imx/clk-scu.h b/drivers/clk/imx/clk-scu.h index 309b4de..52c1746 100644 --- a/drivers/clk/imx/clk-scu.h +++ b/drivers/clk/imx/clk-scu.h @@ -12,4 +12,7 @@ int imx_clk_scu_init(void); struct clk_hw *imx_clk_scu(const char *name, u32 rsrc_id, u8 clk_type); +struct clk_hw *imx_clk_lpcg_scu(const char *name, const char *parent_name, + unsigned long flags, void __iomem *reg, + u8 bit_idx, bool hw_gate); #endif -- 2.7.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel