From patchwork Thu Nov 19 10:21:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: huang lin X-Patchwork-Id: 7656201 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 291989F2E2 for ; Thu, 19 Nov 2015 10:22:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 19181204D5 for ; Thu, 19 Nov 2015 10:22:01 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 029AC20462 for ; Thu, 19 Nov 2015 10:22:00 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZzMLn-0007kB-K2; Thu, 19 Nov 2015 10:21:59 +0000 Received: from mail-wm0-f67.google.com ([74.125.82.67]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZzMLk-0007hR-Uv for linux-rockchip@lists.infradead.org; Thu, 19 Nov 2015 10:21:58 +0000 Received: by wmec201 with SMTP id c201so18839357wme.3 for ; Thu, 19 Nov 2015 02:21:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QZKgCdJ/gQO3VKJ3BnUZQJmhZxQvm6FcFQzXPNOC29M=; b=L/YoiifUQ4xU8MXnxMIvgGlSUfIBBOdZLs1RNWNL/BU7A+MT8yko1KTM/t0uWMTlcE 1pOggfEbOyY3ycuUemGjhuFJCDG/hChoaAr7UQHaojAjJzhmNl1NUt4+z8zdPI6OVOxd N63R7ig6PhC1laft3cw+DwzJ+F6lSZmb6nqxHj9mlDO349oZTVi3Vr93je/tBnrk7JVD e7b1OM0yM0VpWkE6bKf2g669SBukJe8GG76nGwtTz3A53sh/6Dlzrw8+gDzUh9i2BCFJ 8ZT2wxqnPa7G3r6EGrOvq1HMqNl3IcereLc+Zx04T/m5CXoXHIQKMDLmhQ3ZgTeKNPwz qS/w== X-Received: by 10.28.170.65 with SMTP id t62mr10254869wme.1.1447928495268; Thu, 19 Nov 2015 02:21:35 -0800 (PST) Received: from localhost.localdomain ([82.145.52.103]) by smtp.gmail.com with ESMTPSA id u134sm6495432wmd.0.2015.11.19.02.21.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Nov 2015 02:21:34 -0800 (PST) From: Lin Huang To: heiko@sntech.de, dianders@chromium.org, mturquette@baylibre.com, myungjoo.ham@samsung.com, kyungmin.park@samsung.com Subject: [PATCH 1/2] clk: rockchip: dmc: support rk3399 dmc clock driver Date: Thu, 19 Nov 2015 18:21:10 +0800 Message-Id: <1447928471-14448-2-git-send-email-hl@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1447928471-14448-1-git-send-email-hl@rock-chips.com> References: <1447928471-14448-1-git-send-email-hl@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151119_022157_339856_12F0289A X-CRM114-Status: GOOD ( 20.12 ) X-Spam-Score: -2.2 (--) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lin Huang , dbasehore@chromium.org, sboyd@codeaurora.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-clk@vger.kernel.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP support rk3399 dmc clock driver. Note, ddr set rate function will use dcf controller which run in ATF, it need to fishish it when rk3399 arm trust firmware ready. Signed-off-by: Lin Huang --- drivers/clk/rockchip/Makefile | 1 + drivers/clk/rockchip/clk-rk3399-dmc.c | 196 ++++++++++++++++++++++++++++++++++ include/soc/rockchip/rk3399-dmc-clk.h | 36 +++++++ 3 files changed, 233 insertions(+) create mode 100644 drivers/clk/rockchip/clk-rk3399-dmc.c create mode 100644 include/soc/rockchip/rk3399-dmc-clk.h diff --git a/drivers/clk/rockchip/Makefile b/drivers/clk/rockchip/Makefile index b27edd6..98bd955 100644 --- a/drivers/clk/rockchip/Makefile +++ b/drivers/clk/rockchip/Makefile @@ -13,3 +13,4 @@ obj-$(CONFIG_RESET_CONTROLLER) += softrst.o obj-y += clk-rk3188.o obj-y += clk-rk3288.o obj-y += clk-rk3368.o +obj-y += clk-rk3399-dmc.o diff --git a/drivers/clk/rockchip/clk-rk3399-dmc.c b/drivers/clk/rockchip/clk-rk3399-dmc.c new file mode 100644 index 0000000..03cc044 --- /dev/null +++ b/drivers/clk/rockchip/clk-rk3399-dmc.c @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define to_rk3399_dmcclk(obj) container_of(obj, struct rk3399_dmcclk, hw) + +/* CRU_CLKSEL6_CON*/ +#define CRU_CLKSEL6_CON 0x118 +#define CLK_DDRC_PLL_SEL_SHIFT 0x4 +#define CLK_DDRC_PLL_SEL_MASK 0x3 +#define CLK_DDRC_DIV_CON_SHIFT 0 +#define CLK_DDRC_DIV_CON_MASK 0x07 + +static unsigned long rk3399_dmcclk_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct rk3399_dmcclk *dmc = to_rk3399_dmcclk(&hw); + u32 val; + + /* + * Get parent rate since it changed in this clks set_rate op. The parent + * rate passed into this function is cached before set_rate is called in + * the common clk code, so we have to get it here. + */ + parent_rate = clk_get_rate(clk_get_parent(hw->clk)); + + val = readl(dmc->cru + CRU_CLKSEL6_CON); + val = (val >> CLK_DDRC_DIV_CON_SHIFT) & CLK_DDRC_DIV_CON_MASK; + + return parent_rate / (val + 1); +} + +/* + * TODO: set ddr frequcney in dcf which run in ATF + */ +static int rk3399_dmcclk_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + return 0; +} + +static u8 rk3399_dmcclk_get_parent(struct clk_hw *hw) +{ + struct rk3399_dmcclk *dmc = to_rk3399_dmcclk(&hw); + u32 val; + + val = readl(dmc->cru + CRU_CLKSEL6_CON); + + return (val >> CLK_DDRC_PLL_SEL_SHIFT) & + CLK_DDRC_PLL_SEL_MASK; +} + +static const struct clk_ops rk3399_dmcclk_ops = { + .recalc_rate = rk3399_dmcclk_recalc_rate, + .set_rate = rk3399_dmcclk_set_rate, + .get_parent = rk3399_dmcclk_get_parent, +}; + +static const char *parent_clk_names[] = { + "pll_dpll", + "pll_gpll", + "pll_alpll", + "pll_abpll", +}; + +static int rk3399_register_dmcclk(struct rk3399_dmcclk *dmc) +{ + struct clk_init_data init; + struct clk *clk; + + init.name = "dmc_clk"; + init.parent_names = parent_clk_names; + init.num_parents = ARRAY_SIZE(parent_clk_names); + init.ops = &rk3399_dmcclk_ops; + init.flags = 0; + dmc->hw->init = &init; + + clk = devm_clk_register(dmc->dev, dmc->hw); + if (IS_ERR(clk)) { + dev_err(dmc->dev, "could not register cpuclk dmc_clk\n"); + return PTR_ERR(clk); + } + clk_register_clkdev(clk, "dmc_clk", NULL); + of_clk_add_provider(dmc->dev->of_node, of_clk_src_simple_get, clk); + + return 0; +} + +static int rk3399_dmcclk_probe(struct platform_device *pdev) +{ + struct rk3399_dmcclk *dmc; + struct resource *res; + struct device_node *node; + int ret; + + dmc = devm_kzalloc(&pdev->dev, sizeof(*dmc), GFP_KERNEL); + if (!dmc) + return -ENOMEM; + + dmc->hw = devm_kzalloc(&pdev->dev, sizeof(*dmc->hw), GFP_KERNEL); + if (!dmc->hw) + return -ENOMEM; + + dmc->dev = &pdev->dev; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + dmc->ctrl_regs = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(dmc->ctrl_regs)) + return PTR_ERR(dmc->ctrl_regs); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); + dmc->dfi_regs = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(dmc->dfi_regs)) + return PTR_ERR(dmc->dfi_regs); + + node = of_parse_phandle(dmc->dev->of_node, "rockchip,cru", 0); + if (!node) + return -ENODEV; + + ret = of_address_to_resource(node, 0, res); + if (ret) + return ret; + + dmc->cru = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(dmc->cru)) + return PTR_ERR(dmc->cru); + + /* register dpllddr clock */ + ret = rk3399_register_dmcclk(dmc); + if (ret) { + dev_err(dmc->dev, "failed to register clk dmc_clk %d\n", ret); + return ret; + } + + platform_set_drvdata(pdev, dmc); + platform_device_register_data(dmc->dev, "rk3399-dmc-freq", + PLATFORM_DEVID_AUTO, NULL, 0); + + return 0; +} + +static const struct of_device_id rk3399_dmcclk_of_match[] = { + { .compatible = "rockchip,rk3399-dmc", }, + { }, +}; +MODULE_DEVICE_TABLE(of, rk3399_dmcclk_of_match); + + +static struct platform_driver rk3399_dmcclk_driver = { + .probe = rk3399_dmcclk_probe, + .driver = { + .name = "rk3399-dmc", + .of_match_table = rk3399_dmcclk_of_match, + .suppress_bind_attrs = true, + }, +}; + +static int __init rk3399_dmcclk_modinit(void) +{ + int ret; + + ret = platform_driver_register(&rk3399_dmcclk_driver); + if (ret < 0) + pr_err("Failed to register platform driver %s\n", + rk3399_dmcclk_driver.driver.name); + + return ret; +} + +module_init(rk3399_dmcclk_modinit); + +MODULE_DESCRIPTION("rockchip rk3399 DMC CLK driver"); +MODULE_LICENSE("GPL v2"); + diff --git a/include/soc/rockchip/rk3399-dmc-clk.h b/include/soc/rockchip/rk3399-dmc-clk.h new file mode 100644 index 0000000..b53fc23 --- /dev/null +++ b/include/soc/rockchip/rk3399-dmc-clk.h @@ -0,0 +1,36 @@ +/* +* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at your +* option) any later version. +*/ + +#ifndef _RK3399_DMC_CLK_H +#define _RK3399_DMC_CLK_H + +enum dram_type_tag { + DDR3 = 6, + LPDDR3 = 7, + LPDDR4 = 0x0b, +}; + +/* DENALI_CTL_00 */ +#define DENALI_CTL_00 0x00 +#define DRAM_CLASS_MASK 0x0f +#define DRAM_CLASS_SHIFT 0x8 + +struct rk3399_dmcclk { + struct device *dev; + struct clk_hw *hw; + u32 cur_freq; + u32 target_freq; + u32 ddr_type; + void __iomem *ctrl_regs; + void __iomem *dfi_regs; + void __iomem *cru; +}; + +#endif +