From patchwork Tue Jul 3 14:57:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yixun Lan X-Patchwork-Id: 10503209 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 B942D60225 for ; Tue, 3 Jul 2018 07:03:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1FA028AD9 for ; Tue, 3 Jul 2018 07:03:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93A2B28AE0; Tue, 3 Jul 2018 07:03:13 +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=-1.0 required=2.0 tests=BAYES_00, DATE_IN_FUTURE_06_12, DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1ABB628AD9 for ; Tue, 3 Jul 2018 07:03:13 +0000 (UTC) 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:References:In-Reply-To: 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=icadEKFe1vgpdWlg/NMXjHf8BnYtsXEBlYalXLMBY9o=; b=F/uOlmZPWZYqHl jdZ4Npt+cofOHUUF3kczqEeV2fU307kKMPDorWwqaVXoNDCETwROidrK/fVz99tBtsnwk9pxBPy7m dg1TQtV4uQpyJsrn1I8kIAAVQO9UJyujsD2pA0xgbXmlzLToIfHxiRnIYh47B44hDegmPNLhYXxDD nnLJ/F07uhENmAwsAly3RNP42E7YiXGP1B+CLujqbSX2APfSyRv4unB07YR8zhZuth5kFoj/FaBXS 0otCJXPgWu1eEBaYOaTuArz0WUjwYVh6vEDBUe8pZjYLYnxUqWmSWf3usR2/Q1gqxmWZ5wFIEfcdq lsrpBhEFdeRIkpKEfYxg==; 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 1faFLB-0005Zm-Gb; Tue, 03 Jul 2018 07:03:09 +0000 Received: from mail-sh2.amlogic.com ([58.32.228.45]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1faFKS-0004rj-Bm; Tue, 03 Jul 2018 07:02:45 +0000 Received: from localhost.localdomain (10.18.20.250) by mail-sh2.amlogic.com (10.18.11.6) with Microsoft SMTP Server id 15.0.1320.4; Tue, 3 Jul 2018 14:59:34 +0800 From: Yixun Lan To: Jerome Brunet , Neil Armstrong Subject: [PATCH 3/3] clk: meson: add sub EMMC clock controller driver Date: Tue, 3 Jul 2018 14:57:16 +0000 Message-ID: <20180703145716.31860-4-yixun.lan@amlogic.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180703145716.31860-1-yixun.lan@amlogic.com> References: <20180703145716.31860-1-yixun.lan@amlogic.com> MIME-Version: 1.0 X-Originating-IP: [10.18.20.250] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180703_000225_688297_A7C7DD2E X-CRM114-Status: GOOD ( 15.39 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Herring , Stephen Boyd , Kevin Hilman , Michael Turquette , Yixun Lan , linux-kernel@vger.kernel.org, Boris Brezillon , Liang Yang , Qiufang Dai , Miquel Raynal , Carlo Caione , linux-amlogic@lists.infradead.org, Martin Blumenstingl , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jian Hu Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch will add a EMMC clock controller driver support, It provide a mux and divider clock. This clock driver can be protentially used by either EMMC and NAND driver. Signed-off-by: Yixun Lan --- drivers/clk/meson/Kconfig | 9 +++ drivers/clk/meson/Makefile | 1 + drivers/clk/meson/emmc-clkc.c | 136 ++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 drivers/clk/meson/emmc-clkc.c diff --git a/drivers/clk/meson/Kconfig b/drivers/clk/meson/Kconfig index efaa70f682b4..2f27ff08e4eb 100644 --- a/drivers/clk/meson/Kconfig +++ b/drivers/clk/meson/Kconfig @@ -15,6 +15,15 @@ config COMMON_CLK_MESON_AO select COMMON_CLK_REGMAP_MESON select RESET_CONTROLLER +config COMMON_CLK_EMMC_MESON + tristate "Meson EMMC Sub Clock Controller Driver" + depends on COMMON_CLK_AMLOGIC + select MFD_SYSCON + select REGMAP + help + Support for the EMMC sub clock controller on AmLogic Meson Platform, + Say Y if you want this clock enabled. + config COMMON_CLK_REGMAP_MESON bool select REGMAP diff --git a/drivers/clk/meson/Makefile b/drivers/clk/meson/Makefile index 72ec8c40d848..2f04f77ba4de 100644 --- a/drivers/clk/meson/Makefile +++ b/drivers/clk/meson/Makefile @@ -9,4 +9,5 @@ obj-$(CONFIG_COMMON_CLK_MESON8B) += meson8b.o obj-$(CONFIG_COMMON_CLK_GXBB) += gxbb.o gxbb-aoclk.o gxbb-aoclk-32k.o obj-$(CONFIG_COMMON_CLK_AXG) += axg.o axg-aoclk.o obj-$(CONFIG_COMMON_CLK_AXG_AUDIO) += axg-audio.o +obj-$(CONFIG_COMMON_CLK_EMMC_MESON) += emmc-clkc.o obj-$(CONFIG_COMMON_CLK_REGMAP_MESON) += clk-regmap.o diff --git a/drivers/clk/meson/emmc-clkc.c b/drivers/clk/meson/emmc-clkc.c new file mode 100644 index 000000000000..cf5bb9f34327 --- /dev/null +++ b/drivers/clk/meson/emmc-clkc.c @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: (GPL-2.0+ OR MIT) +/* + * Amlogic Meson EMMC Sub Clock Controller Driver + * + * Copyright (c) 2018 Amlogic, inc. + * Author: Yixun Lan + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "clkc.h" + +#define SD_EMMC_CLOCK 0 +#define MUX_CLK_NUM_PARENTS 2 +#define EMMC_MAX_CLKS 2 +#define CLK_NAME_LEN 48 + +static struct clk_regmap_mux_data emmc_clkc_mux_data = { + .offset = SD_EMMC_CLOCK, + .mask = 0x3, + .shift = 6, +}; + +static struct clk_regmap_div_data emmc_clkc_div_data = { + .offset = SD_EMMC_CLOCK, + .shift = 0, + .width = 6, + .flags = CLK_DIVIDER_ROUND_CLOSEST | CLK_DIVIDER_ONE_BASED, +}; + +static const struct of_device_id clkc_match_table[] = { + { .compatible = "amlogic,emmc-clkc" }, + {} +}; + +static int emmc_clkc_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct clk_regmap *mux, *div; + struct regmap *map; + struct clk *clk; + int i, ret; + const char *parent_names[MUX_CLK_NUM_PARENTS]; + struct clk_init_data init; + char mux_name[CLK_NAME_LEN], div_name[CLK_NAME_LEN]; + struct clk_hw_onecell_data *onecell_data; + + map = syscon_node_to_regmap(dev->of_node); + + mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); + div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL); + + onecell_data = devm_kzalloc(dev, sizeof(*onecell_data) + + sizeof(*onecell_data->hws) * EMMC_MAX_CLKS, + GFP_KERNEL); + + if (!mux || !div || !onecell_data) + return -ENOMEM; + + for (i = 0; i < MUX_CLK_NUM_PARENTS; i++) { + char name[8]; + + snprintf(name, sizeof(name), "clkin%d", i); + clk = devm_clk_get(dev, name); + if (IS_ERR(clk)) { + if (clk != ERR_PTR(-EPROBE_DEFER)) + dev_err(dev, "Missing clock %s\n", name); + return PTR_ERR(clk); + } + + parent_names[i] = __clk_get_name(clk); + } + + mux->map = map; + mux->data = &emmc_clkc_mux_data; + + snprintf(mux_name, CLK_NAME_LEN, "%s#emmc_mux", dev_name(dev)); + + init.name = mux_name; + init.ops = &clk_regmap_mux_ops; + init.flags = CLK_SET_RATE_PARENT; + init.parent_names = parent_names; + init.num_parents = MUX_CLK_NUM_PARENTS; + + mux->hw.init = &init; + ret = devm_clk_hw_register(dev, &mux->hw); + if (ret) { + dev_err(dev, "Mux clock registration failed\n"); + return ret; + } + + parent_names[0] = mux_name; + div->map = map; + div->data = &emmc_clkc_div_data; + + snprintf(div_name, CLK_NAME_LEN, "%s#emmc_div", dev_name(dev)); + + init.name = div_name; + init.ops = &clk_regmap_divider_ops; + init.flags = CLK_SET_RATE_PARENT; + init.parent_names = parent_names; + init.num_parents = 1; + + div->hw.init = &init; + ret = devm_clk_hw_register(dev, &div->hw); + if (ret) { + dev_err(dev, "Div clock registration failed\n"); + return ret; + } + + onecell_data->hws[CLKID_EMMC_C_MUX] = &mux->hw, + onecell_data->hws[CLKID_EMMC_C_DIV] = &div->hw, + onecell_data->num = EMMC_MAX_CLKS; + + return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, + onecell_data); +} + +static struct platform_driver emmc_clkc_driver = { + .probe = emmc_clkc_probe, + .driver = { + .name = "emmc-clkc", + .of_match_table = clkc_match_table, + }, +}; + +builtin_platform_driver(emmc_clkc_driver);