Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1365682pxb; Fri, 21 Jan 2022 16:38:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwAQDUT+EzOgeTWliqlx1I9HxGbdbOQZITneRJOdNP8srLY0IM+kHJf5KmwMwwF16+48Iz8 X-Received: by 2002:a63:6905:: with SMTP id e5mr4505778pgc.543.1642811893633; Fri, 21 Jan 2022 16:38:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642811893; cv=none; d=google.com; s=arc-20160816; b=pJm6qT4vGbp37+EEPNeg/NWgfODFpy4F1FRIfcoEViLSZSW3/+OIkPTb2gPSYycL/s rEMH01VO/9bytbbOqLyiLJZp0MjqwrFG7l9ctrvy8pap+qywg53xlrhY9ZTvmYHbSS8v tG+p/39nHohZ6cq3WGlSU21e3jr6DpOMOwjsRYbyqaMYLTVBW3zBUiPzaNii6l8g7A0g opakZhjTTsTyJrZUYZ8701tFWwTQr6jqEHOi005kzlGwKjoAIptwHp65GNISUGmr0bXA aMyAFZMY8D/fcj/JTTlnxbX1fTQbReKGN3v4OXeu4QZNsBQzn9U+1I8O1ewY6BAWElH7 2RAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=YuNkOT96O2U4vCIXPiZ9ilrUSzdyjwf63LEBojdxRlA=; b=KEzR+Kx0o2VsVj2sD9tShxK+JzdUkyal12LrA/KS3shZQkJshnKOisuBSfcsz5zytF fvg5SZcpX330LQDp90wuGx/pxfL2VCW+p/Jna2/BI2N1s4sAEmAhXdIPs4S3JHiJFxuH WRNLHW8+wiNQJ2Xqk/z8oQhXOAcIOux8QJoPKOgpXKVr+uEj82p90KERCY03d0svs435 X+2c4lvtzvR6kKzBOW2RspQA8AGIGBlFT7qrc3Y2huG/jM3v/J/4frlXWHHgKtf9SSut 2s0yx43F/z6YViEStiM8PNQ5ao4S/LOJ81ttjl1Sx0Kw+HNpoeLMi+yAam69bnOdVORU TiKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i1si5910561pfb.52.2022.01.21.16.38.02; Fri, 21 Jan 2022 16:38:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379130AbiAUHp1 (ORCPT + 99 others); Fri, 21 Jan 2022 02:45:27 -0500 Received: from mail-sz.amlogic.com ([211.162.65.117]:15116 "EHLO mail-sz.amlogic.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379093AbiAUHpT (ORCPT ); Fri, 21 Jan 2022 02:45:19 -0500 Received: from droid11-sz.amlogic.com (10.28.8.21) by mail-sz.amlogic.com (10.28.11.5) with Microsoft SMTP Server id 15.1.2176.2; Fri, 21 Jan 2022 15:45:17 +0800 From: Liang Yang To: Neil Armstrong , Jerome Brunet , Kevin Hilman , Michael Turquette , Stephen Boyd , Rob Herring , CC: Liang Yang , Martin Blumenstingl , Jianxin Pan , Victor Wan , XianWei Zhao , Kelvin Zhang , BiChao Zheng , YongHui Yu , , , Subject: [PATCH v10 2/4] clk: meson: add emmc sub clock phase delay driver Date: Fri, 21 Jan 2022 15:45:06 +0800 Message-ID: <20220121074508.42168-3-liang.yang@amlogic.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220121074508.42168-1-liang.yang@amlogic.com> References: <20220121074508.42168-1-liang.yang@amlogic.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.28.8.21] Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Export the emmc sub clock phase delay ops which will be used by the emmc sub clock driver itself. Signed-off-by: Liang Yang --- drivers/clk/meson/Kconfig | 4 ++ drivers/clk/meson/Makefile | 1 + drivers/clk/meson/clk-phase-delay.c | 69 +++++++++++++++++++++++++++++ drivers/clk/meson/clk-phase-delay.h | 20 +++++++++ 4 files changed, 94 insertions(+) create mode 100644 drivers/clk/meson/clk-phase-delay.c create mode 100644 drivers/clk/meson/clk-phase-delay.h diff --git a/drivers/clk/meson/Kconfig b/drivers/clk/meson/Kconfig index 3014e2f1fbb4..bb0f59eea366 100644 --- a/drivers/clk/meson/Kconfig +++ b/drivers/clk/meson/Kconfig @@ -18,6 +18,10 @@ config COMMON_CLK_MESON_PHASE tristate select COMMON_CLK_MESON_REGMAP +config COMMON_CLK_MESON_PHASE_DELAY + tristate + select COMMON_CLK_MESON_REGMAP + config COMMON_CLK_MESON_PLL tristate select COMMON_CLK_MESON_REGMAP diff --git a/drivers/clk/meson/Makefile b/drivers/clk/meson/Makefile index b3ef5f67820f..99fe4eeed000 100644 --- a/drivers/clk/meson/Makefile +++ b/drivers/clk/meson/Makefile @@ -9,6 +9,7 @@ obj-$(CONFIG_COMMON_CLK_MESON_MPLL) += clk-mpll.o obj-$(CONFIG_COMMON_CLK_MESON_PHASE) += clk-phase.o obj-$(CONFIG_COMMON_CLK_MESON_PLL) += clk-pll.o obj-$(CONFIG_COMMON_CLK_MESON_REGMAP) += clk-regmap.o +obj-$(CONFIG_COMMON_CLK_MESON_PHASE_DELAY) += clk-phase-delay.o obj-$(CONFIG_COMMON_CLK_MESON_SCLK_DIV) += sclk-div.o obj-$(CONFIG_COMMON_CLK_MESON_VID_PLL_DIV) += vid-pll-div.o diff --git a/drivers/clk/meson/clk-phase-delay.c b/drivers/clk/meson/clk-phase-delay.c new file mode 100644 index 000000000000..3c1ae0ee2a24 --- /dev/null +++ b/drivers/clk/meson/clk-phase-delay.c @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: (GPL-2.0+ OR MIT) +/* + * Copyright (c) 2019 Amlogic, Inc. All rights reserved. + */ + +#include +#include + +#include "clk-regmap.h" +#include "clk-phase-delay.h" + +static inline struct meson_clk_phase_delay_data * +meson_clk_get_phase_delay_data(struct clk_regmap *clk) +{ + return clk->data; +} + +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_ULL(NSEC_PER_SEC * 1000ull, + 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; + unsigned int p; + + ph = meson_clk_get_phase_delay_data(clk); + period_ps = DIV_ROUND_UP_ULL(NSEC_PER_SEC * 1000ull, + 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). + */ + p = 360 / 1 << (ph->phase.width); + degrees = degrees / p; + d = DIV_ROUND_CLOSEST((degrees % p) * 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/clk-phase-delay.h b/drivers/clk/meson/clk-phase-delay.h new file mode 100644 index 000000000000..b4f211d02c84 --- /dev/null +++ b/drivers/clk/meson/clk-phase-delay.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: (GPL-2.0+ OR MIT) */ +/* + * Copyright (c) 2019 Amlogic, Inc. All rights reserved. + */ + +#ifndef __MESON_CLK_PHASE_DELAY_H +#define __MESON_CLK_PHASE_DELAY_H + +#include +#include "parm.h" + +struct meson_clk_phase_delay_data { + struct parm phase; + struct parm delay; + unsigned int delay_step_ps; +}; + +extern const struct clk_ops meson_clk_phase_delay_ops; + +#endif /* __MESON_CLK_PHASE_DELAY_H */ -- 2.34.1