Received: by 10.223.164.221 with SMTP id h29csp3053215wrb; Fri, 3 Nov 2017 00:27:20 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QDiSq/Hup2Cd0j/lFPC0FgKMkxmqMlpB5WKknbH2VPev4ttE8t13OIbArUc5K2Us2b4QQf X-Received: by 10.84.133.165 with SMTP id f34mr5858705plf.268.1509694040413; Fri, 03 Nov 2017 00:27:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509694040; cv=none; d=google.com; s=arc-20160816; b=BGod3OVL8eVqSxRv1qm/lTv+0O3t/TKnNlaJKIHhwSLpApb8hMnHNBPy2eL8vq19jp /qnhI8Ik2RCHccVa8s8h97cYH2JR/lgXv5BrBY0w+7K4/qULYHNOWC060GxQlazB/nYh kTdnR8H5kC4K19CiQ237Vq6KamCxtDLb77cUvvnxtJSVou5m/m1XFUbcX1zrXUVoWi1r z5DRNfqm7hDpnRdzM1q+olyv1ShOok4gr/rh7CA05Af/mOR/hi5Rr+Q/CGKaxPpOdRGs MZp7il3zmH/G1TZr/ri36U7OyGpTkU/6FESVR8vADzkF8SlCf310g4A91lfrcXE+uIpA DczQ== 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=GdXqE9fT2xhAP6ycU9Ous6PZLHmVT8PHMJmhe+oE3zs=; b=XBH5l9mJ8ERhjtrbPO/iampL3niZY/xcuwCiESARJq0rfPiA+V7xp8kIG3LbhI5GXe yFebzO/1vUkOwvfkMGX2pwMInvMdVZle7Akx5bweK70gCrcWl7MTgsAfvkc1hgzS8QbA CiOJHwPY/Jx5hOaY2PnOHYUBOkop+yJNdpavQHQACy4rvb+W4TCUN6lc0gy+NsM8ECgu nljgnwiUXWtB10OsAgQ+l9PgbbqbE28DQvZEfuUuB2Ti5Z9wpKKeV0JT324obXNgaVdS B/ECoymV4nm0XzCie1IgWe/GDBoYX8LSwPALN6nhSjvd5ilwFsaA5Z267QWe6zSMgQTX d1sw== 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 j5si5462027pgc.544.2017.11.03.00.27.03; Fri, 03 Nov 2017 00:27:20 -0700 (PDT) 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 S1755091AbdKCH0R (ORCPT + 96 others); Fri, 3 Nov 2017 03:26:17 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:48175 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752238AbdKCH0O (ORCPT ); Fri, 3 Nov 2017 03:26:14 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 15C14B7A12336; Fri, 3 Nov 2017 15:26:01 +0800 (CST) Received: from vm167-7.huawei.com (10.177.167.7) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.361.1; Fri, 3 Nov 2017 15:25:09 +0800 From: Kaihua Zhong To: , , , , , , , , , , , , , CC: , , , , , , Subject: [PATCH 2/3] clk: hisilicon: Add support for Hi3660 stub clocks Date: Fri, 3 Nov 2017 15:25:06 +0800 Message-ID: <1509693907-90682-3-git-send-email-zhongkaihua@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509693907-90682-1-git-send-email-zhongkaihua@huawei.com> References: <1509693907-90682-1-git-send-email-zhongkaihua@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.177.167.7] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi3660 has four stub clocks, which are big and LITTLE cluster clocks, GPU clock and DDR clock. These clocks ask MCU for frequency scaling by sending message through mailbox. This commit adds support for stub clocks, it requests the dedicated mailbox channel at initialization; then later uses this channel to send message to MCU to execute frequency scaling. The four stub clocks share the same mailbox channel, but every stub clock has its own command id so MCU can distinguish the requirement coming for which clock. A shared memory is used to present effective frequency value, so the clock driver uses I/O mapping for the memory and reads back rate value. Reviewed-by: Leo Yan Signed-off-by: Kai Zhao Signed-off-by: Kevin Wang Signed-off-by: Ruyi Wang Signed-off-by: Kaihua Zhong --- drivers/clk/hisilicon/Kconfig | 6 + drivers/clk/hisilicon/Makefile | 1 + drivers/clk/hisilicon/clk-hi3660-stub.c | 195 +++++++++++++++++++++++++++++++ include/dt-bindings/clock/hi3660-clock.h | 7 ++ 4 files changed, 209 insertions(+) create mode 100644 drivers/clk/hisilicon/clk-hi3660-stub.c diff --git a/drivers/clk/hisilicon/Kconfig b/drivers/clk/hisilicon/Kconfig index 7098bfd..1bd4355 100644 --- a/drivers/clk/hisilicon/Kconfig +++ b/drivers/clk/hisilicon/Kconfig @@ -49,3 +49,9 @@ config STUB_CLK_HI6220 default ARCH_HISI help Build the Hisilicon Hi6220 stub clock driver. + +config STUB_CLK_HI3660 + bool "Hi3660 Stub Clock Driver" + depends on COMMON_CLK_HI3660 && MAILBOX + help + Build the Hisilicon Hi3660 stub clock driver. diff --git a/drivers/clk/hisilicon/Makefile b/drivers/clk/hisilicon/Makefile index 1e4c3dd..0a5b499 100644 --- a/drivers/clk/hisilicon/Makefile +++ b/drivers/clk/hisilicon/Makefile @@ -14,3 +14,4 @@ obj-$(CONFIG_COMMON_CLK_HI3798CV200) += crg-hi3798cv200.o obj-$(CONFIG_COMMON_CLK_HI6220) += clk-hi6220.o obj-$(CONFIG_RESET_HISI) += reset.o obj-$(CONFIG_STUB_CLK_HI6220) += clk-hi6220-stub.o +obj-$(CONFIG_STUB_CLK_HI3660) += clk-hi3660-stub.o diff --git a/drivers/clk/hisilicon/clk-hi3660-stub.c b/drivers/clk/hisilicon/clk-hi3660-stub.c new file mode 100644 index 0000000..0a21c91 --- /dev/null +++ b/drivers/clk/hisilicon/clk-hi3660-stub.c @@ -0,0 +1,195 @@ +/* + * Hisilicon clock driver + * + * Copyright (c) 2013-2017 Hisilicon Limited. + * Copyright (c) 2017 Linaro Limited. + * + * Author: Kai Zhao + * Author: Tao Wang + * Author: Leo Yan + * + * 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. + * + * This program is distributed in the hope that 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 + +#define HI3660_STUB_CLOCK_DATA (0x70) +#define MHZ (1000 * 1000) + +#define DEFINE_CLK_STUB(_id, _cmd, _name) \ + { \ + .id = (_id), \ + .cmd = (_cmd), \ + .hw.init = &(struct clk_init_data) { \ + .name = #_name, \ + .ops = &hi3660_stub_clk_ops, \ + .num_parents = 0, \ + .flags = CLK_GET_RATE_NOCACHE, \ + }, \ + }, + +#define to_stub_clk(_hw) container_of(_hw, struct hi3660_stub_clk, hw) + +struct hi3660_stub_clk_chan { + struct mbox_client cl; + struct mbox_chan *mbox; +}; + +struct hi3660_stub_clk { + unsigned int id; + struct device *dev; + struct clk_hw hw; + unsigned int cmd; + unsigned int msg[8]; + unsigned int rate; +}; + +static void __iomem *freq_reg; +static struct hi3660_stub_clk_chan *chan; + +static unsigned long hi3660_stub_clk_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct hi3660_stub_clk *stub_clk = to_stub_clk(hw); + + /* + * LPM3 writes back the CPU frequency in shared SRAM so read + * back the frequency. + */ + stub_clk->rate = readl(freq_reg + (stub_clk->id << 2)) * MHZ; + return stub_clk->rate; +} + +static long hi3660_stub_clk_round_rate(struct clk_hw *hw, unsigned long rate, + unsigned long *prate) +{ + /* + * LPM3 handles rate rounding so just return whatever + * rate is requested. + */ + return rate; +} + +static int hi3660_stub_clk_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + struct hi3660_stub_clk *stub_clk = to_stub_clk(hw); + + stub_clk->msg[0] = stub_clk->cmd; + stub_clk->msg[1] = rate / MHZ; + + dev_dbg(stub_clk->dev, "set rate msg[0]=0x%x msg[1]=0x%x\n", + stub_clk->msg[0], stub_clk->msg[1]); + + mbox_send_message(chan->mbox, stub_clk->msg); + mbox_client_txdone(chan->mbox, 0); + + stub_clk->rate = rate; + return 0; +} + +static const struct clk_ops hi3660_stub_clk_ops = { + .recalc_rate = hi3660_stub_clk_recalc_rate, + .round_rate = hi3660_stub_clk_round_rate, + .set_rate = hi3660_stub_clk_set_rate, +}; + +static struct hi3660_stub_clk hi3660_stub_clks[HI3660_CLK_STUB_NUM] = { + DEFINE_CLK_STUB(HI3660_CLK_STUB_CLUSTER0, 0x0001030A, "cpu-cluster.0") + DEFINE_CLK_STUB(HI3660_CLK_STUB_CLUSTER1, 0x0002030A, "cpu-cluster.1") + DEFINE_CLK_STUB(HI3660_CLK_STUB_GPU, 0x0003030A, "clk-g3d") + DEFINE_CLK_STUB(HI3660_CLK_STUB_DDR, 0x00040309, "clk-ddrc") +}; + +static struct clk_hw *hi3660_stub_clk_hw_get(struct of_phandle_args *clkspec, + void *data) +{ + unsigned int idx = clkspec->args[0]; + + if (idx > HI3660_CLK_STUB_NUM) { + pr_err("%s: invalid index %u\n", __func__, idx); + return ERR_PTR(-EINVAL); + } + + return &hi3660_stub_clks[idx].hw; +} + +static int hi3660_stub_clk_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct resource *res; + unsigned int i; + int ret; + + chan = devm_kzalloc(dev, sizeof(*chan), GFP_KERNEL); + if (!chan) + return -ENOMEM; + + /* Use mailbox client without blocking */ + chan->cl.dev = dev; + chan->cl.tx_done = NULL; + chan->cl.tx_block = false; + chan->cl.knows_txdone = false; + + /* Allocate mailbox channel */ + chan->mbox = mbox_request_channel(&chan->cl, 0); + if (IS_ERR(chan->mbox)) + return PTR_ERR(chan->mbox); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + freq_reg = devm_ioremap(dev, res->start, resource_size(res)); + if (IS_ERR(freq_reg)) + return -ENOMEM; + + freq_reg += HI3660_STUB_CLOCK_DATA; + + for (i = 0; i < HI3660_CLK_STUB_NUM; i++) { + hi3660_stub_clks[i].dev = dev; + ret = devm_clk_hw_register(&pdev->dev, &hi3660_stub_clks[i].hw); + if (ret) + return ret; + } + + ret = of_clk_add_hw_provider(pdev->dev.of_node, hi3660_stub_clk_hw_get, + hi3660_stub_clks); + if (ret) + return ret; + + return 0; +} + +static const struct of_device_id hi3660_stub_clk_of_match[] = { + { .compatible = "hisilicon,hi3660-stub-clk", }, + {} +}; + +static struct platform_driver hi3660_stub_clk_driver = { + .probe = hi3660_stub_clk_probe, + .driver = { + .name = "hi3660-stub-clk", + .of_match_table = hi3660_stub_clk_of_match, + }, +}; + +static int __init hi3660_stub_clk_init(void) +{ + return platform_driver_register(&hi3660_stub_clk_driver); +} +subsys_initcall(hi3660_stub_clk_init); diff --git a/include/dt-bindings/clock/hi3660-clock.h b/include/dt-bindings/clock/hi3660-clock.h index adb768d..75d583e 100644 --- a/include/dt-bindings/clock/hi3660-clock.h +++ b/include/dt-bindings/clock/hi3660-clock.h @@ -208,4 +208,11 @@ #define HI3660_CLK_I2C6_IOMCU 3 #define HI3660_CLK_IOMCU_PERI0 4 +/* clk in stub clock */ +#define HI3660_CLK_STUB_CLUSTER0 0 +#define HI3660_CLK_STUB_CLUSTER1 1 +#define HI3660_CLK_STUB_GPU 2 +#define HI3660_CLK_STUB_DDR 3 +#define HI3660_CLK_STUB_NUM 4 + #endif /* __DTS_HI3660_CLOCK_H */ -- 1.9.1 From 1583656284363450733@xxx Fri Nov 10 05:38:44 +0000 2017 X-GM-THRID: 1583656284363450733 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread