Received: by 10.223.164.202 with SMTP id h10csp3431526wrb; Sun, 19 Nov 2017 22:13:20 -0800 (PST) X-Google-Smtp-Source: AGs4zMYmp59fE5ZcWNcT0zThOaKLJqm3KoCfic2UxxWrCZTSU4fJBtCO+AZGKtgnEzCv48L+zH0/ X-Received: by 10.98.41.194 with SMTP id p185mr10216802pfp.140.1511158399948; Sun, 19 Nov 2017 22:13:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511158399; cv=none; d=google.com; s=arc-20160816; b=GFOJGin+kgBb5otRHMQHRcpJmwgRrqCV7VoFothEPQQwgLAd8+h2L0I0Offr7umLT8 DnEP5+Wubx4/TbmfP9hX0rU+rez4+nfhrPXArxMYznwn9VttF4WPG6iX1gCub7+pFlFp 3cHwADH0Mk76Lynwiq6LoLhhFg09ZsOYBHo3w6h8khz6XF/9iQUO7dNLWQaOJ3l1Egis uaBDSGqhUIiVKwH35Km8E2hxF8meILndPQILN4Q4jgka9HltueAzqw45F9lWBZAZRDSg DeVfznVzKRZrVx4McxYYwntGvPhxlCASKINg13xY213Ej+UtDe8C5qVsNekzhMfO7fpG tepw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=Htw3WnkyY/8XD8eIxT3HMKa9lkQqIKfmbxxh3Cnt6y8=; b=dsjZYCK+a5yt1zjnGgeL9Hasw0yIrGQUfkm3JTghujAsw/s9X0wRIZC53Rqd/pEQeK BpVcvZXX1Sgsfej7sKd0QO0z1Yf6q3OI6c5II9KEmRZF+QfytY8xDGSN32/sT+dy3G7p s5BmoVTF9tJeKmkJcDG4ha7HoZnKtFQaSap2jCm6Ml0fdX3BTXzTEUIaOryPmhBmnSPH 2oBDI/q9UPCCFgM0UzCdnV/9DIXOVpp4ozlDx5FGE6GhdSxDPxAnUU3zkIQ4oztRWZJK 374pWZSzLOi3rOq5BDgghzjupaFpSdvA4+Vsx/M5+a8ctpZi8c6U5nplZQdX2ge/lQQQ vuKw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e90si3356420pfj.4.2017.11.19.22.13.09; Sun, 19 Nov 2017 22:13:19 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751297AbdKTGIP (ORCPT + 68 others); Mon, 20 Nov 2017 01:08:15 -0500 Received: from sci-ig2.spreadtrum.com ([222.66.158.135]:26545 "EHLO SHSQR01.spreadtrum.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751231AbdKTGIM (ORCPT ); Mon, 20 Nov 2017 01:08:12 -0500 Received: from ig2.spreadtrum.com (shmbx03.spreadtrum.com [10.0.1.208]) by SHSQR01.spreadtrum.com with ESMTP id vAK67eHL060695 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 20 Nov 2017 14:07:40 +0800 (CST) (envelope-from Chunyan.Zhang@spreadtrum.com) Received: from SHCAS02.spreadtrum.com (10.0.1.202) by SHMBX03.spreadtrum.com (10.0.1.208) with Microsoft SMTP Server (TLS) id 15.0.847.32; Mon, 20 Nov 2017 14:07:48 +0800 Received: from localhost (10.0.73.143) by SHCAS02.spreadtrum.com (10.0.1.250) with Microsoft SMTP Server (TLS) id 15.0.847.32 via Frontend Transport; Mon, 20 Nov 2017 14:07:48 +0800 From: Chunyan Zhang To: Stephen Boyd , Michael Turquette , Rob Herring , Mark Rutland CC: Catalin Marinas , Will Deacon , , , , , Arnd Bergmann , Mark Brown , Xiaolong Zhang , Ben Li , Orson Zhai , Chunyan Zhang Subject: [PATCH V5 02/12] clk: sprd: Add common infrastructure Date: Mon, 20 Nov 2017 14:01:27 +0800 Message-ID: <20171120060137.27380-3-chunyan.zhang@spreadtrum.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20171120060137.27380-1-chunyan.zhang@spreadtrum.com> References: <20171120060137.27380-1-chunyan.zhang@spreadtrum.com> MIME-Version: 1.0 Content-Type: text/plain X-MAIL: SHSQR01.spreadtrum.com vAK67eHL060695 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Added Spreadtrum's clock driver framework together with common structures and interface functions. Signed-off-by: Chunyan Zhang --- drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/sprd/Kconfig | 4 ++ drivers/clk/sprd/Makefile | 3 ++ drivers/clk/sprd/common.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/clk/sprd/common.h | 53 ++++++++++++++++++++++ 6 files changed, 175 insertions(+) create mode 100644 drivers/clk/sprd/Kconfig create mode 100644 drivers/clk/sprd/Makefile create mode 100644 drivers/clk/sprd/common.c create mode 100644 drivers/clk/sprd/common.h diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig index 1c4e1aa..ce1a32be 100644 --- a/drivers/clk/Kconfig +++ b/drivers/clk/Kconfig @@ -236,6 +236,7 @@ source "drivers/clk/mvebu/Kconfig" source "drivers/clk/qcom/Kconfig" source "drivers/clk/renesas/Kconfig" source "drivers/clk/samsung/Kconfig" +source "drivers/clk/sprd/Kconfig" source "drivers/clk/sunxi-ng/Kconfig" source "drivers/clk/tegra/Kconfig" source "drivers/clk/ti/Kconfig" diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index c99f363..fa33891 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -84,6 +84,7 @@ obj-$(CONFIG_COMMON_CLK_SAMSUNG) += samsung/ obj-$(CONFIG_ARCH_SIRF) += sirf/ obj-$(CONFIG_ARCH_SOCFPGA) += socfpga/ obj-$(CONFIG_PLAT_SPEAR) += spear/ +obj-$(CONFIG_ARCH_SPRD) += sprd/ obj-$(CONFIG_ARCH_STI) += st/ obj-$(CONFIG_ARCH_SUNXI) += sunxi/ obj-$(CONFIG_ARCH_SUNXI) += sunxi-ng/ diff --git a/drivers/clk/sprd/Kconfig b/drivers/clk/sprd/Kconfig new file mode 100644 index 0000000..67a3287 --- /dev/null +++ b/drivers/clk/sprd/Kconfig @@ -0,0 +1,4 @@ +config SPRD_COMMON_CLK + tristate "Clock support for Spreadtrum SoCs" + depends on ARCH_SPRD || COMPILE_TEST + default ARCH_SPRD diff --git a/drivers/clk/sprd/Makefile b/drivers/clk/sprd/Makefile new file mode 100644 index 0000000..74f4b80 --- /dev/null +++ b/drivers/clk/sprd/Makefile @@ -0,0 +1,3 @@ +obj-$(CONFIG_SPRD_COMMON_CLK) += clk-sprd.o + +clk-sprd-y += common.o diff --git a/drivers/clk/sprd/common.c b/drivers/clk/sprd/common.c new file mode 100644 index 0000000..c003f09 --- /dev/null +++ b/drivers/clk/sprd/common.c @@ -0,0 +1,113 @@ +/* + * Spreadtrum clock infrastructure + * + * Copyright (C) 2017 Spreadtrum, Inc. + * Author: Chunyan Zhang + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include +#include +#include +#include +#include + +#include "common.h" + +static const struct regmap_config sprdclk_regmap_config = { + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 32, + .max_register = 0xffff, + .fast_io = true, +}; + +static void sprd_clk_set_regmap(const struct sprd_clk_desc *desc, + struct regmap *regmap) +{ + int i; + struct sprd_clk_common *cclk; + + for (i = 0; i < desc->num_clk_clks; i++) { + cclk = desc->clk_clks[i]; + if (!cclk) + continue; + + cclk->regmap = regmap; + } +} + +int sprd_clk_regmap_init(struct platform_device *pdev, + const struct sprd_clk_desc *desc) +{ + void __iomem *base; + struct device_node *node = pdev->dev.of_node; + struct regmap *regmap = NULL; + + if (of_find_property(node, "sprd,syscon", NULL)) { + regmap = syscon_regmap_lookup_by_phandle(node, "sprd,syscon"); + if (IS_ERR(regmap)) { + pr_err("%s: failed to get syscon regmap\n", __func__); + return PTR_ERR(regmap); + } + } else { + base = of_iomap(node, 0); + regmap = devm_regmap_init_mmio(&pdev->dev, base, + &sprdclk_regmap_config); + if (IS_ERR(regmap)) { + pr_err("failed to init regmap.\n"); + return PTR_ERR(regmap); + } + } + + sprd_clk_set_regmap(desc, regmap); + + return 0; +} +EXPORT_SYMBOL_GPL(sprd_clk_regmap_init); + +int sprd_clk_probe(struct device_node *node, + struct clk_hw_onecell_data *clkhw) +{ + int i, ret = 0; + struct clk_hw *hw; + + for (i = 0; i < clkhw->num; i++) { + + hw = clkhw->hws[i]; + + if (!hw) + continue; + + ret = clk_hw_register(NULL, hw); + if (ret) { + pr_err("Couldn't register clock %d - %s\n", + i, hw->init->name); + goto err_clk_unreg; + } + } + + ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, + clkhw); + if (ret) { + pr_err("Failed to add clock provider.\n"); + goto err_clk_unreg; + } + + return 0; + +err_clk_unreg: + while (--i >= 0) { + hw = clkhw->hws[i]; + if (!hw) + continue; + + clk_hw_unregister(hw); + } + + return ret; +} +EXPORT_SYMBOL_GPL(sprd_clk_probe); + +MODULE_LICENSE("GPL v2"); diff --git a/drivers/clk/sprd/common.h b/drivers/clk/sprd/common.h new file mode 100644 index 0000000..a25634a --- /dev/null +++ b/drivers/clk/sprd/common.h @@ -0,0 +1,53 @@ +/* + * Spreadtrum clock infrastructure + * + * Copyright (C) 2017 Spreadtrum, Inc. + * Author: Chunyan Zhang + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef _SPRD_CLK_COMMON_H_ +#define _SPRD_CLK_COMMON_H_ + +#include +#include +#include + +#include "../clk_common.h" + +struct device_node; + +struct sprd_clk_common { + struct regmap *regmap; + u32 reg; + struct clk_hw hw; +}; + +struct sprd_clk_desc { + struct sprd_clk_common **clk_clks; + unsigned long num_clk_clks; + struct clk_hw_onecell_data *hw_clks; +}; + +#define sprd_regmap_read(map, reg, val) \ +({ \ + (map) ? regmap_read((map), (reg), (val)) : (-EINVAL); \ +}) + +#define sprd_regmap_write(map, reg, val) \ +({ \ + (map) ? regmap_write((map), (reg), (val)) : (-EINVAL); \ +}) + +static inline struct sprd_clk_common * + hw_to_sprd_clk_common(const struct clk_hw *hw) +{ + return container_of(hw, struct sprd_clk_common, hw); +} +int sprd_clk_regmap_init(struct platform_device *pdev, + const struct sprd_clk_desc *desc); +int sprd_clk_probe(struct device_node *node, + struct clk_hw_onecell_data *clkhw); + +#endif /* _SPRD_CLK_COMMON_H_ */ -- 2.7.4 From 1584619486495217387@xxx Mon Nov 20 20:48:25 +0000 2017 X-GM-THRID: 1583404742770019749 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread