Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp850039imu; Tue, 11 Dec 2018 08:30:26 -0800 (PST) X-Google-Smtp-Source: AFSGD/VJeo0D4IFeIutxR1SRRi64yHuYNvrsHUv5rA/eHIKbZ+RfxYLatqsfySMztf+TRuS357yZ X-Received: by 2002:a17:902:3181:: with SMTP id x1mr16572014plb.58.1544545826728; Tue, 11 Dec 2018 08:30:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544545826; cv=none; d=google.com; s=arc-20160816; b=RxxFu18v7Kx8l1bc8MmoKW762FcQfnHMkIC3ayJGTOCE8EBVt0Gc6Ig7Aajl6JV/iV xSPCCTGP6uPtau/Z0hmayolOQSuCwcvPWtAqrMNsD3g/HDJYtTEgO3pTbUsGExSgj17M rO9HAhG3l7Cfex9alYxOLtxqbYND+6Rhbz4yak9IRN5sx+F1XdZyyijs6UIRzexQMuEx hpzrLq8t4fTn9nDiZxNN6Ps5Hq3krjRaxuvavHgExFuOmEJIj21B017jh7iFTCzqIqpO W8jwE2rerHgGAvaBTmQHIiX6ic61AKdou2Qbt9FodVrrXE4qSVpX2UOuVIHw5JXECCEk jXcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=f7K6GN5/aa8DCXT+gCMZwybLJkMHYSJQth2S97vanzo=; b=mUMce5mnwJvn6KD5JfHIA3bK/m1X4KrTD0U+8BPaw6RbZEBFhBTLAgibyIB5DFSjVW lokE76GbFMP121UQoZFg9sjdDFpJ264CctNjISzWNB7GsuPCbqF3ypswOoKUa7OWz5qz IaK7dH6rBNcoqft+VGNXDJCIU1uApAOrP3e1KmY6qSy6IY+aHOJSwrHeajf3yp4PCSsK tuqmcn9Gf0lmeWzOxI8a4wJAsmjgAs1qFQUCYwkMtOrLIlNQPYtWnb6EA3fq7FsjVicr K3ca7677DU/7AmyJuVsNifh52zPxeskfhr4L2FKFQYXxJtm91drr0538RnLbutPyuQ6w s13A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=Np6rTVgq; 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 t17si12857619pfh.267.2018.12.11.08.30.10; Tue, 11 Dec 2018 08:30:26 -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=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=Np6rTVgq; 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 S1727357AbeLKQ2H (ORCPT + 99 others); Tue, 11 Dec 2018 11:28:07 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36127 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726628AbeLKQ2G (ORCPT ); Tue, 11 Dec 2018 11:28:06 -0500 Received: by mail-wr1-f68.google.com with SMTP id u3so14768347wrs.3 for ; Tue, 11 Dec 2018 08:28:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=f7K6GN5/aa8DCXT+gCMZwybLJkMHYSJQth2S97vanzo=; b=Np6rTVgqPxvJka6+7brT/Eim4w/Hd2CraROFW2i6SrUrrtDFf+5dxyKFNR3HTU+Zgt +vCWjDHnZGc+F2olDiYddyTEFyE/GNi7dXqazkNISskFklqX+tdSVgwQx266peIz9ct7 ePiHh0fyp/cbKyR8yoQ4JWkKDUdxboWNTu/CO7Kbc+hPD0HikMWm5UZWPVkPYk6KshBt TVAN4io2nE8969uKqKTlM9HJeuZ9HHUQjRUln6G/cYZK4DZW7daog3ijzWsGzvI107jG echLmz0tB9thiCWCCAyAPjjj65fhYTyfmOvQecfFe+330PeTTAP6+VfsaquG/0Z/GKzF cpTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=f7K6GN5/aa8DCXT+gCMZwybLJkMHYSJQth2S97vanzo=; b=LblpA5Ah9tM93hwDllq1RqnUuEE27joZdfvFtKLKjD2hxGtUjGpNjZShYVYhsQ1Lal zrnuOh5jOdHjgk2072Yf1QfGCYBsjkiPgi8FdW2Q9paqdnlhwgZID/LHiIuD5sFJwH4y VfTA+VGRoRZN29GGelkMGcNyyv2dR2HbpHLmK469h5FVe4XmJNki9u6u5UjpzN0/QL4n 9t0S+1g3MrhI2ViESubtoy7zxG8a3GXuKbFKpOZFG3tQwl8z8Bk3JrN1iLLS7eJ+bNAO UPyd1D1s/czQSvYAG9cszp+Wlhhy3/5wZwIMVM/RDyGispkCWnxAQ2ZfoLGclTZAwUyE h6Fg== X-Gm-Message-State: AA+aEWbRa/5vkUY5lFn925+k42zu5BHNqCRQER2M/0QET7HH6hDRvQ1l lxlADsaZFwmkXIxLW8QSCQ9XFA== X-Received: by 2002:adf:ce86:: with SMTP id r6mr14862307wrn.257.1544545683894; Tue, 11 Dec 2018 08:28:03 -0800 (PST) Received: from boomer.baylibre.com ([2a01:e34:eeb6:4690:106b:bae3:31ed:7561]) by smtp.gmail.com with ESMTPSA id y34sm44330957wrd.68.2018.12.11.08.28.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Dec 2018 08:28:02 -0800 (PST) Message-ID: <8e1c711b477eeee60809f33926cf9c6a52f530cd.camel@baylibre.com> Subject: Re: [PATCH RESEND v7 1/4] clk: meson: add emmc sub clock phase delay driver From: Jerome Brunet To: Jianxin Pan , Neil Armstrong Cc: Yixun Lan , Kevin Hilman , Carlo Caione , Michael Turquette , Stephen Boyd , Rob Herring , Miquel Raynal , Boris Brezillon , Martin Blumenstingl , Liang Yang , Jian Hu , Qiufang Dai , Hanjie Lin , Victor Wan , linux-clk@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Date: Tue, 11 Dec 2018 17:28:00 +0100 In-Reply-To: <1544457877-51301-2-git-send-email-jianxin.pan@amlogic.com> References: <1544457877-51301-1-git-send-email-jianxin.pan@amlogic.com> <1544457877-51301-2-git-send-email-jianxin.pan@amlogic.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.2 (3.30.2-2.fc29) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2018-12-11 at 00:04 +0800, Jianxin Pan wrote: > From: Yixun Lan > > Export the emmc sub clock phase delay ops which will be used > by the emmc sub clock driver itself. > > Signed-off-by: Yixun Lan > Signed-off-by: Jianxin Pan > --- > drivers/clk/meson/Makefile | 2 +- > drivers/clk/meson/clk-phase-delay.c | 64 > +++++++++++++++++++++++++++++++++++++ > drivers/clk/meson/clkc.h | 13 ++++++++ > 3 files changed, 78 insertions(+), 1 deletion(-) > create mode 100644 drivers/clk/meson/clk-phase-delay.c > > diff --git a/drivers/clk/meson/Makefile b/drivers/clk/meson/Makefile > index 72ec8c4..39ce566 100644 > --- a/drivers/clk/meson/Makefile > +++ b/drivers/clk/meson/Makefile > @@ -2,7 +2,7 @@ > # Makefile for Meson specific clk > # > > -obj-$(CONFIG_COMMON_CLK_AMLOGIC) += clk-pll.o clk-mpll.o clk-phase.o > +obj-$(CONFIG_COMMON_CLK_AMLOGIC) += clk-pll.o clk-mpll.o clk-phase.o clk- > phase-delay.o > obj-$(CONFIG_COMMON_CLK_AMLOGIC_AUDIO) += clk-triphase.o sclk-div.o > obj-$(CONFIG_COMMON_CLK_MESON_AO) += meson-aoclk.o > obj-$(CONFIG_COMMON_CLK_MESON8B) += meson8b.o > diff --git a/drivers/clk/meson/clk-phase-delay.c b/drivers/clk/meson/clk- > phase-delay.c > new file mode 100644 > index 0000000..84e7b63 > --- /dev/null > +++ b/drivers/clk/meson/clk-phase-delay.c > @@ -0,0 +1,64 @@ > +// SPDX-License-Identifier: (GPL-2.0+ OR MIT) > +/* > + * Amlogic Meson MMC Sub Clock Controller Driver > + * > + * Copyright (c) 2017 Baylibre SAS. > + * Author: Jerome Brunet > + * > + * Copyright (c) 2018 Amlogic, inc. > + * Author: Yixun Lan > + * Author: Jianxin Pan > + */ > + > +#include > +#include "clkc.h" > + > +static int meson_clk_phase_delay_get_phase(struct clk_hw *hw) > +{ > + struct clk_regmap *clk = to_clk_regmap(hw); > + struct meson_clk_phase_delay_data *ph; > + unsigned long period_ps, p, d; > + int degrees; > + > + ph = meson_clk_get_phase_delay_data(clk); > + p = meson_parm_read(clk->map, &ph->phase); > + degrees = p * 360 / (1 << (ph->phase.width)); > + > + period_ps = DIV_ROUND_UP(NSEC_PER_SEC * 1000, > + clk_hw_get_rate(hw)); > + > + d = meson_parm_read(clk->map, &ph->delay); > + degrees += d * ph->delay_step_ps * 360 / period_ps; > + degrees %= 360; > + > + return degrees; > +} > + > +static int meson_clk_phase_delay_set_phase(struct clk_hw *hw, int degrees) > +{ > + struct clk_regmap *clk = to_clk_regmap(hw); > + struct meson_clk_phase_delay_data *ph; > + unsigned long period_ps, d = 0, r; > + > + ph = meson_clk_get_phase_delay_data(clk); > + period_ps = DIV_ROUND_UP(NSEC_PER_SEC * 1000, clk_hw_get_rate(hw)); > + > + /* > + * First compute the phase index (p), the remainder (r) is the > + * part we'll try to acheive using the delays (d). > + */ > + r = do_div(degrees, 360 / 1 << (ph->phase.width)); > + d = DIV_ROUND_CLOSEST(r * period_ps, > + 360 * ph->delay_step_ps); > + d = min(d, PMASK(ph->delay.width)); > + > + meson_parm_write(clk->map, &ph->phase, degrees); > + meson_parm_write(clk->map, &ph->delay, d); > + return 0; > +} > + > +const struct clk_ops meson_clk_phase_delay_ops = { > + .get_phase = meson_clk_phase_delay_get_phase, > + .set_phase = meson_clk_phase_delay_set_phase, > +}; > +EXPORT_SYMBOL_GPL(meson_clk_phase_delay_ops); > diff --git a/drivers/clk/meson/clkc.h b/drivers/clk/meson/clkc.h > index 6b96d55..30470c6 100644 > --- a/drivers/clk/meson/clkc.h > +++ b/drivers/clk/meson/clkc.h > @@ -105,6 +105,18 @@ struct clk_regmap _name = { > \ > }, \ > }; > > +struct meson_clk_phase_delay_data { > + struct parm phase; > + struct parm delay; > + unsigned int delay_step_ps; > +}; > + > +static inline struct meson_clk_phase_delay_data * > +meson_clk_get_phase_delay_data(struct clk_regmap *clk) > +{ > + return clk->data; > +} This is only usefull in the related clock driver, no need to export it > + > /* clk_ops */ > extern const struct clk_ops meson_clk_pll_ro_ops; > extern const struct clk_ops meson_clk_pll_ops; > @@ -112,5 +124,6 @@ struct clk_regmap _name = { > \ > extern const struct clk_ops meson_clk_mpll_ro_ops; > extern const struct clk_ops meson_clk_mpll_ops; > extern const struct clk_ops meson_clk_phase_ops; > +extern const struct clk_ops meson_clk_phase_delay_ops; > > #endif /* __CLKC_H */