From patchwork Tue May 22 16:34:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 10419159 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1A3CF60224 for ; Tue, 22 May 2018 16:38:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08B1F28F9B for ; Tue, 22 May 2018 16:38:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F127128FA6; Tue, 22 May 2018 16:38:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 60C7028F9B for ; Tue, 22 May 2018 16:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=RdKxq8K9flQykf+fUjTHi5DjJ4LNkVTcpLIpYCTgMG0=; b=MNMebqih4iPIBE3kJVQJqL+4/8 5d35cdfjlbJAql8uDw4gaL5K2a7GDYLCIURUvS3Zl3aiTNjCa3D40RL2EGF939ZGukHoHwd2vA4nj JRwqHnnudti6Pk0bY3IbyPdErTvSgf72XTif4mC52nTKHJHccZDAW8L4xDG74iQNcO/FhzvPI9ESQ XmM8wIfyVlW8bUPhYI0ClaXn1Wu++UuFN4mwYoUQXjrbs79I3cZkymQe4Sa89nn28vdOEhhO888K2 M2uHgVQUnRC1v8uauiraVKa3aZPbwCAmpQkWgUD87Xc+oY18y1UafZw93Ile9x2Ms/edY4NKtw2nI K9MNwVzg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fLAJ0-00030H-OI; Tue, 22 May 2018 16:38:34 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fLAIy-0002wk-MK for linux-amlogic@bombadil.infradead.org; Tue, 22 May 2018 16:38:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=mZwt/l2sYskTvAXoweC6k/82L0dm05FSwYW594SXjBc=; b=MSB5d7kJjNKXHnwFdQh9WTyAu ij3FVA/Mq9kvrP3+/Pcj6uks4udD/r9M/fLa58Kv1Qt+Fay/VkpghX3czBK+Mc3mMJ9bcHJ1xOH5g VMhW9yoNnAgK6qBYtOahFZKiwYxmxB7omn+36qb3VltlT5r/ZDlJZ/TMLaJfmnjuZ3HuYlwo1bjBK lFK+LXsserhLrtW2Fg0UMvKwV6oIBz60znXgSOguuHORS+moxgF+PkmdQcNh7YOcqrcEXdn03dAYp HAKQpN/7nD+CuvZ6ZxEp67fD8XAHMsARny+z1Q739o09uRy3B8d0DhRRx/fCHVEpV0aceLaRmkbP/ vE1k8Zunw==; Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fLAFn-0003zQ-GR for linux-amlogic@lists.infradead.org; Tue, 22 May 2018 16:35:17 +0000 Received: by mail-wm0-x244.google.com with SMTP id l1-v6so1550149wmb.2 for ; Tue, 22 May 2018 09:35:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mZwt/l2sYskTvAXoweC6k/82L0dm05FSwYW594SXjBc=; b=f4pLw/qJuzre33QTK9d5gpYVABZ0/bN/R7QOZo3WyxAOkZIozmhFJb6dkw44WWKoET qOVzS/vsBMc+ZMxjxJmQuwZBm1ItRIfth+wB0iXdsY3ZhitFeTXb9SvssupCroZeJPgS UIOIYY0IhZMtIfsWnDIfNiF8QtYNJ234rczeNuqrMhGHrdgn6tZjSLR7hMb6DjlhP4fc tdvW4JpenmMg2YUa9hluvi8QMtEHkUbOEOrkYCtitrGs8ev/s1HbLvRcxQoLZB5HWwZf /COkTl4sbR9b50WhFjnj3f4kJX8fUMRubGoLb3TXkHBl/hcMGM+j70wrJcQND8ZzorMb afSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mZwt/l2sYskTvAXoweC6k/82L0dm05FSwYW594SXjBc=; b=JeYR7wpLW6+z9BwZbXJ4BwS0YsccZK7DTt5ckKOaye94SvobPVvPmASFaLM7qYEwuV I8IcMJxTFeoTCnP0qecchghip+L5OtuCfj0p/HXmH0JR9P02yxYwHk1Fq0RJgnR2BSCw fmV/i8iMczX/JBGwVAUfUujM70pnpBqSNZlS8heOWG61FBFxw46362De9HNUDX7yqT07 jj0YqNmw6pikKpKlt+ue+drMM7FQY4AnrY4+2gQVq8R19V3JdA+RhC3lvqufgTRpzolr n2rRUBuqESMdjBCfr64xqqibnfkPGx7jzSuIYx1HmCR0rFX20MFpjqrACfaW4YftFmJp 5o5w== X-Gm-Message-State: ALKqPweui/s3Z/m0RZ1+OhOQplirn127R/n2CZlmzCUsdcBOxdqIZU/v angJvfOc1Bv/SIGaAZfDgFIcqg== X-Google-Smtp-Source: AB8JxZonfRi7KnRT6PLKWRvoXIJCCK3su00MjFtTQ8kC0WaBaMndLU2wBad74tQaqQY8RkPk6n1upw== X-Received: by 2002:a1c:7e8d:: with SMTP id z135-v6mr1723412wmc.6.1527006903933; Tue, 22 May 2018 09:35:03 -0700 (PDT) Received: from boomer.baylibre.local ([90.63.244.31]) by smtp.googlemail.com with ESMTPSA id h8-v6sm294062wmc.16.2018.05.22.09.35.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 May 2018 09:35:03 -0700 (PDT) From: Jerome Brunet To: Neil Armstrong , Carlo Caione , Kevin Hilman Subject: [PATCH v2 2/6] clk: meson: add clk-phase clock driver Date: Tue, 22 May 2018 18:34:53 +0200 Message-Id: <20180522163457.13834-3-jbrunet@baylibre.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180522163457.13834-1-jbrunet@baylibre.com> References: <20180522163457.13834-1-jbrunet@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180522_173515_540846_65263A79 X-CRM114-Status: GOOD ( 18.39 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Stephen Boyd , Michael Turquette , linux-kernel@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-clk@vger.kernel.org, Jerome Brunet MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add a driver based meson clk-regmap to control clock phase on amlogic SoCs Acked-by: Neil Armstrong Signed-off-by: Jerome Brunet --- drivers/clk/meson/Makefile | 1 + drivers/clk/meson/clk-phase.c | 63 +++++++++++++++++++++++++++++++++++++++++++ drivers/clk/meson/clkc.h | 8 ++++++ 3 files changed, 72 insertions(+) create mode 100644 drivers/clk/meson/clk-phase.c diff --git a/drivers/clk/meson/Makefile b/drivers/clk/meson/Makefile index d0d13aeb369a..162e4a6f5c55 100644 --- a/drivers/clk/meson/Makefile +++ b/drivers/clk/meson/Makefile @@ -3,6 +3,7 @@ # obj-$(CONFIG_COMMON_CLK_AMLOGIC) += clk-pll.o clk-mpll.o clk-audio-divider.o +obj-$(CONFIG_COMMON_CLK_AMLOGIC) += clk-phase.o obj-$(CONFIG_COMMON_CLK_MESON_AO) += meson-aoclk.o obj-$(CONFIG_COMMON_CLK_MESON8B) += meson8b.o obj-$(CONFIG_COMMON_CLK_GXBB) += gxbb.o gxbb-aoclk.o gxbb-aoclk-32k.o diff --git a/drivers/clk/meson/clk-phase.c b/drivers/clk/meson/clk-phase.c new file mode 100644 index 000000000000..cba43748ce3d --- /dev/null +++ b/drivers/clk/meson/clk-phase.c @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: (GPL-2.0 OR MIT) +/* + * Copyright (c) 2018 BayLibre, SAS. + * Author: Jerome Brunet + */ + +#include +#include "clkc.h" + +#define phase_step(_width) (360 / (1 << (_width))) + +static inline struct meson_clk_phase_data * +meson_clk_phase_data(struct clk_regmap *clk) +{ + return (struct meson_clk_phase_data *)clk->data; +} + +int meson_clk_degrees_from_val(unsigned int val, unsigned int width) +{ + return phase_step(width) * val; +} +EXPORT_SYMBOL_GPL(meson_clk_degrees_from_val); + +unsigned int meson_clk_degrees_to_val(int degrees, unsigned int width) +{ + unsigned int val = DIV_ROUND_CLOSEST(degrees, phase_step(width)); + + /* + * This last calculation is here for cases when degrees is rounded + * to 360, in which case val == (1 << width). + */ + return val % (1 << width); +} +EXPORT_SYMBOL_GPL(meson_clk_degrees_to_val); + +static int meson_clk_phase_get_phase(struct clk_hw *hw) +{ + struct clk_regmap *clk = to_clk_regmap(hw); + struct meson_clk_phase_data *phase = meson_clk_phase_data(clk); + unsigned int val; + + val = meson_parm_read(clk->map, &phase->ph); + + return meson_clk_degrees_from_val(val, phase->ph.width); +} + +static int meson_clk_phase_set_phase(struct clk_hw *hw, int degrees) +{ + struct clk_regmap *clk = to_clk_regmap(hw); + struct meson_clk_phase_data *phase = meson_clk_phase_data(clk); + unsigned int val; + + val = meson_clk_degrees_to_val(degrees, phase->ph.width); + meson_parm_write(clk->map, &phase->ph, val); + + return 0; +} + +const struct clk_ops meson_clk_phase_ops = { + .get_phase = meson_clk_phase_get_phase, + .set_phase = meson_clk_phase_set_phase, +}; +EXPORT_SYMBOL_GPL(meson_clk_phase_ops); diff --git a/drivers/clk/meson/clkc.h b/drivers/clk/meson/clkc.h index 2fb084330ee9..fd520ccdd1be 100644 --- a/drivers/clk/meson/clkc.h +++ b/drivers/clk/meson/clkc.h @@ -96,6 +96,13 @@ struct meson_clk_audio_div_data { u8 flags; }; +struct meson_clk_phase_data { + struct parm ph; +}; + +int meson_clk_degrees_from_val(unsigned int val, unsigned int width); +unsigned int meson_clk_degrees_to_val(int degrees, unsigned int width); + #define MESON_GATE(_name, _reg, _bit) \ struct clk_regmap _name = { \ .data = &(struct clk_regmap_gate_data){ \ @@ -119,5 +126,6 @@ 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_audio_divider_ro_ops; extern const struct clk_ops meson_clk_audio_divider_ops; +extern const struct clk_ops meson_clk_phase_ops; #endif /* __CLKC_H */