Received: by 10.223.164.202 with SMTP id h10csp1044113wrb; Thu, 9 Nov 2017 20:10:19 -0800 (PST) X-Google-Smtp-Source: ABhQp+TpFpuipoXKdKCHDoPahzsCZD+x1u5d1z0tDwNnpqsS0ENCgOpYKAU7kHuKDsFDN1jtkjxI X-Received: by 10.159.206.131 with SMTP id bg3mr2786093plb.124.1510287019553; Thu, 09 Nov 2017 20:10:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510287019; cv=none; d=google.com; s=arc-20160816; b=utpFKFGwFTvbsVIo5vnXy7me7tgEroDj/xzQRJn6SqgQwsX8bjctXcwyNPcScrK6N1 1XRvXbt5zkrwQWwLDtKwaKr53E/XeufJ5qf2i2liWPhBrwPmat4NWvqEAyMuNcuskzqI sQ4mw0dVD/V6Ua/2V4BbUPXfdrorjWdvKjbG4z8rdwEKK2nP79W5+aIKeHb90Guaurx3 ge5hY2sXAhjMHer/FRWLZhYtgKSLhfs1HeyuUH3ZGTAiOXfE2FDeHUkvu0qpMwri5Cg/ dKBms09tBSn74XVayW8Ad78xQAwZH8uO+IHDfhb9kyphXBnzQB1TlVJEocz3tEcaQf2E uZbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=lzyW32xbxFSeKwBoQyEr2jxmpOFDExkikKmE9R4xhiU=; b=eT+tD+gIbbhQIrwMAJvshRi9T+i5IYnHK6XhPZSYR/EW53P39/qyrSpQUR4D99j6WV 1lzETAQ/AFeAMilIS4Fv2ftxYj0K4X465BJ2IY91StLo9CyK+MxY2DjjeGXLaAdkLwl8 4yjUAX9pAyCaIdzhVCqCXXmdCIhFfyTEC7pMtwr+HUAkF4PjGFjxIXNBy0w3HFlcXZz0 2KRMkdQi7tOrl9TatXWRsrcrLS1YML+j+k81uiqMTgtMaP5H64mAxaiqmEprVEmxMZ/I DcTpkH3ItxQ4V1T1KTq71tLJJ7G4esJMqxgXYbrgemyrwwnefXJDNO1/sn7GK44+V41Z 4p+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SP/ifw1B; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y3si7399437pgp.202.2017.11.09.20.10.07; Thu, 09 Nov 2017 20:10: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; dkim=pass header.i=@linaro.org header.s=google header.b=SP/ifw1B; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755971AbdKJEIp (ORCPT + 83 others); Thu, 9 Nov 2017 23:08:45 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:45910 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754172AbdKJEIm (ORCPT ); Thu, 9 Nov 2017 23:08:42 -0500 Received: by mail-wr0-f194.google.com with SMTP id y9so7482557wrb.2 for ; Thu, 09 Nov 2017 20:08:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=lzyW32xbxFSeKwBoQyEr2jxmpOFDExkikKmE9R4xhiU=; b=SP/ifw1BhzPlpEeVf3u3+jc88LvW7Om7Pi/1dpNAhe15lqbgINvpJFu43QZGbUyz4N /+Tg2hDurenv4sWrToEYdiv3ATP/5Ir5o5sbVerjmbEJUGnm9ondZsm7UqCUrXMSsh3k p4yZ4DxlFlVvItqLj8sMbNZChS/EVAo0y1G4Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=lzyW32xbxFSeKwBoQyEr2jxmpOFDExkikKmE9R4xhiU=; b=OmKAlgTroEfoqragoCBKMH3tf0VxR2vgL1NrXiMS/mrPtgzmf54QmfxAjV3DJ/V9RH wICSMIVhx4s+OTEV8zt8bfUQna3BATP/GkDpi/tef5ZTkv+AsQnX+m0NIsjeG6kwWdaS vJr2HNZRDLgzi3To48rwneWv0r5wY9h2N+u12efnGclJkfK86+A2Pop/He+bwegd2p94 opT+haUh/5A4nN2uA0gjTTn3J8PWML/L6FHOFgAZ2P7XYz1c2d3b5nCKtOaYLDFkwJJW enQklSyRPjXyqv0RuRsdvqAbSz0gmTPRysPzt22lnawJFatKUi1jaZc4NySzkmq50pWQ rqcw== X-Gm-Message-State: AJaThX4Zy0zX15GGF7PhnYNI02JMO9ho8IL0KiEE9J1GQZ3UOjQquga5 z8SSRMHTaR2nWYtbBNEp/IHzLQ== X-Received: by 10.223.150.3 with SMTP id b3mr2280867wra.185.1510286921209; Thu, 09 Nov 2017 20:08:41 -0800 (PST) Received: from leoy-linaro (li1530-42.members.linode.com. [139.162.245.42]) by smtp.gmail.com with ESMTPSA id y15sm2665898wrc.96.2017.11.09.20.08.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2017 20:08:39 -0800 (PST) Date: Fri, 10 Nov 2017 12:08:31 +0800 From: Leo Yan To: Julien Thierry Cc: Kaihua Zhong , mturquette@baylibre.com, sboyd@codeaurora.org, robh+dt@kernel.org, mark.rutland@arm.com, xuwei5@hisilicon.com, catalin.marinas@arm.com, will.deacon@arm.com, xuejiancheng@hisilicon.com, wenpan@hisilicon.com, zhangfei.gao@linaro.org, guodong.xu@linaro.org, chenjun14@huawei.com, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, suzhuangluan@hisilicon.com, xuezhiliang@hisilicon.com, kevin.wangtao@hisilicon.com Subject: Re: [PATCH 2/3] clk: hisilicon: Add support for Hi3660 stub clocks Message-ID: <20171110040831.GA30162@leoy-linaro> References: <1509693907-90682-1-git-send-email-zhongkaihua@huawei.com> <1509693907-90682-3-git-send-email-zhongkaihua@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Julien, On Fri, Nov 03, 2017 at 05:37:34PM +0000, Julien Thierry wrote: > Hi Kaihua, > > On 03/11/17 07:25, Kaihua Zhong wrote: > >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; > > I don't understand why you need to keep this. The only place it is used it > for the debug message in hi3660_stub_clk_set_rate and you could get the > device pointer by doing chan->cl.dev since all the stub_clk point to the > same device. Kaihua might miss this email, so I checked all your comments; accept these comments and will spin for next version patch. Thank you for good suggestions. Thanks, Leo Yan > >+ 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; > > I would suggest having a slightly longer name than "chan" as this can easily > get shadowed which is bad for a non-local variable. > > Also, maybe you could not declare it as a pointer and avoid the need for > kzalloc in the probe function. > > >+ > >+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; > > Hmmm, you could just return ret here without needing the branch. > > Cheers, > > -- > Julien Thierry From 1583360409451236678@xxx Mon Nov 06 23:15:56 +0000 2017 X-GM-THRID: 1583028937937979948 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread