From patchwork Thu Apr 18 11:12:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Gorski X-Patchwork-Id: 10907045 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 12BD317E0 for ; Thu, 18 Apr 2019 11:12:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E92CA287C8 for ; Thu, 18 Apr 2019 11:12:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9C7428C24; Thu, 18 Apr 2019 11:12:53 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 89A8B287C8 for ; Thu, 18 Apr 2019 11:12:53 +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=VOczUz2DGY2/wWM3eqBdWAMeK5SXSiLDACFnRn/WpEY=; b=GSOk21oS6MlsQr13rlbMualuMR t0Kw4i5ploAATZOKAHL+7dYgj/9rnYD27JvYAdyJl2JNzQQotlLvWg5jaAGBsDvTHprGEQacBrCIw xRlENaFPL0yG3dgFPReelzeec9DiEQGUxAfzFBS1sgS4orBlZPvOosA82AbVgPSn5t/qwmYGaPyu4 fyQKyDGWU3mguoTCyiFsgP4T7ENOwXcZylq9rbnyVIHQAi6fOsNyz2z1hx6rQC0fswBfGOKDBaoBA sKdCqBBfL9Btqab4dJLC0DEaL7AXW+VlgYzsSeFNgHbbaHZIXw2zdAUliqUS8mYL5ADdf2Krb1vbo rp74t2Pg==; 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 1hH4yF-000782-Nw; Thu, 18 Apr 2019 11:12:47 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hH4xm-0006aK-9g; Thu, 18 Apr 2019 11:12:21 +0000 Received: by mail-wm1-x343.google.com with SMTP id n25so2413384wmk.4; Thu, 18 Apr 2019 04:12:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cm1EEGeZHsHeXdzknWNTewmHAGGaI1nGB6a7qRF/P7c=; b=R4nTJkPaGbHzkHhLqaoceUHq8NlF7Zxf8cy/R8GkIIKkUNdpxa1NUHv17CvdbutIuJ gpFKHKIEBWpsQGr8jtRBZignnQ4OumyZ73y9kJ6bBfx/a/dynf8FIBQDkcBuRJ2FN0LQ L8Ex8y/vjyBvap22CEh0VTK6oBsW7Rq1NJZmqriHu4Aq58nv2dMgMOI4IOSNc0zAmrhg 8fy9fNjEtiRREKSSI9DGE4VA1CN/rNiB+IqQN29LynUINmMeyv2xjTyp2tnCVMm7+PjI ntSvwuT2WmPsXmA0DUGUd2UtuuSQ5WaKzXb7OoVlykK/+DQy3OBK5Wv0xJ0teJGAV9nM 5DBA== 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=cm1EEGeZHsHeXdzknWNTewmHAGGaI1nGB6a7qRF/P7c=; b=X0G9RJwQ7WSu4ZqixBJqWGFjHtuGqxWNYlU6rsQ5N/jE2gWrj4gYokb5hquZSVU/MX P4+HAIx6SI88GQDSbmEuAy8j2/6l6kMdsjNuxD8GfhU7bJP/X2jcpJOYpUhaeu22oWmD uMCNdGuMQcX5gwMe404ytHYkD2BnbuB618bQFL2mYaoMSiyQkZ3PBp4CWBNnG38S9ORE ukf2V2vVhbxKJ0+H5bTfRONhJXI3hpLVHA8dzc1rPIRTiA67M64xo8u81oQOxeHjE22s 4QCs2DbDYcREEtaBx7OjgBRvv9QJAzQ8Rb+xP8IQpZ93i7ZKy7RJtlSjONfXAH2rMyPy Dnrg== X-Gm-Message-State: APjAAAXsmDYFxPdkIowszHSVVjr7gVSL1QyDisW0DUCjVTN4RLUpb21Y W9LLj6Vw2q5/2qt5qLF7f2c= X-Google-Smtp-Source: APXvYqzcxqiH4NfwjdJ93Bud895D2LmZXnP6SukbgtmppxptpSRARrAOSdr4F5mOJgEaaReIeCmaJQ== X-Received: by 2002:a1c:3d6:: with SMTP id 205mr2873697wmd.66.1555585937030; Thu, 18 Apr 2019 04:12:17 -0700 (PDT) Received: from localhost.localdomain ([2001:470:9e39::64]) by smtp.gmail.com with ESMTPSA id z63sm2005594wme.30.2019.04.18.04.12.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Apr 2019 04:12:16 -0700 (PDT) From: Jonas Gorski To: linux-clk@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-tegra@vger.kernel.org Subject: [PATCH RFT V3 2/8] clk: fractional-divider: add explicit big endian support Date: Thu, 18 Apr 2019 13:12:05 +0200 Message-Id: <20190418111211.10474-3-jonas.gorski@gmail.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20190418111211.10474-1-jonas.gorski@gmail.com> References: <20190418111211.10474-1-jonas.gorski@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190418_041218_537725_F8A98ACD X-CRM114-Status: GOOD ( 15.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter De Schrijver , Fabio Estevam , Heiko Stuebner , Stephen Boyd , Benjamin Herrenschmidt , Michael Turquette , Michal Simek , Jonathan Hunter , Prashant Gaikwad , Paul Mackerras , NXP Linux Team , Pengutronix Kernel Team , Michael Ellerman , Thierry Reding , Anatolij Gustschin , Shawn Guo , Sascha Hauer MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add a clock specific flag to switch register accesses to big endian, to allow runtime configuration of big endian fractional divider clocks. Signed-off-by: Jonas Gorski --- V2 -> V3: * drop unneeded else in clk_fd_readl V1 -> V2: * switch from global to local flag drivers/clk/clk-fractional-divider.c | 22 +++++++++++++++++++--- include/linux/clk-provider.h | 4 ++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c index fdfe2e423d15..f88df265e787 100644 --- a/drivers/clk/clk-fractional-divider.c +++ b/drivers/clk/clk-fractional-divider.c @@ -13,6 +13,22 @@ #include #include +static inline u32 clk_fd_readl(struct clk_fractional_divider *fd) +{ + if (fd->flags & CLK_FRAC_DIVIDER_BIG_ENDIAN) + return ioread32be(fd->reg); + + return clk_readl(fd->reg); +} + +static inline void clk_fd_writel(struct clk_fractional_divider *fd, u32 val) +{ + if (fd->flags & CLK_FRAC_DIVIDER_BIG_ENDIAN) + iowrite32be(val, fd->reg); + else + clk_writel(val, fd->reg); +} + static unsigned long clk_fd_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { @@ -27,7 +43,7 @@ static unsigned long clk_fd_recalc_rate(struct clk_hw *hw, else __acquire(fd->lock); - val = clk_readl(fd->reg); + val = clk_fd_readl(fd); if (fd->lock) spin_unlock_irqrestore(fd->lock, flags); @@ -115,10 +131,10 @@ static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate, else __acquire(fd->lock); - val = clk_readl(fd->reg); + val = clk_fd_readl(fd); val &= ~(fd->mmask | fd->nmask); val |= (m << fd->mshift) | (n << fd->nshift); - clk_writel(val, fd->reg); + clk_fd_writel(fd, val); if (fd->lock) spin_unlock_irqrestore(fd->lock, flags); diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 7117b8cc0c0c..8c07d810acf5 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -607,6 +607,9 @@ void clk_hw_unregister_fixed_factor(struct clk_hw *hw); * is the value read from the register. If CLK_FRAC_DIVIDER_ZERO_BASED * is set then the numerator and denominator are both the value read * plus one. + * CLK_FRAC_DIVIDER_BIG_ENDIAN - By default little endian register accesses are + * used for the divider register. Setting this flag makes the register + * accesses big endian. */ struct clk_fractional_divider { struct clk_hw hw; @@ -627,6 +630,7 @@ struct clk_fractional_divider { #define to_clk_fd(_hw) container_of(_hw, struct clk_fractional_divider, hw) #define CLK_FRAC_DIVIDER_ZERO_BASED BIT(0) +#define CLK_FRAC_DIVIDER_BIG_ENDIAN BIT(1) extern const struct clk_ops clk_fractional_divider_ops; struct clk *clk_register_fractional_divider(struct device *dev,