From patchwork Thu Apr 18 11:12:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Gorski X-Patchwork-Id: 10907043 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 0B1001390 for ; Thu, 18 Apr 2019 11:12:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2530287C8 for ; Thu, 18 Apr 2019 11:12:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D653D28C24; Thu, 18 Apr 2019 11:12:42 +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 8104A287C8 for ; Thu, 18 Apr 2019 11:12:42 +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=jQRjnpOr2sN+tDVRJYtFw3X5fSYISoJOIYVcMWxrz2Y=; b=na1DoBz8UGrN/M1ZtRFR709RMu PKjNkrCxWCufcjIPqtQGFrDafGBkw0S+2Jh/vwzJRU071TGiLP3UO5bFfUHWtjkg+JEqQRhhUtSXh 6vnUTVKhQ2qvev0FT95ImWiVuQrpLFRsnYoHleLWOxyGYele7AO1/eWhL6o7sehepJElzY2RO/6X3 AP+VN98vDJAmHirh7VJNviqp9LiRHpNQcBG2+PFkSgddNcIqdvIPD85WoufnAH0LiU8bP6JcAPoC8 3Ay5ZWthZWf0hAKRTNTV3lqnBTW3R7U/SLlkjhLu/y8/dUlUhTMmZkYiQOVXonsDyUqoFxuCyjp5p ccVHKr3w==; 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 1hH4y8-00070p-BY; Thu, 18 Apr 2019 11:12:40 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hH4xk-0006a0-W5; Thu, 18 Apr 2019 11:12:18 +0000 Received: by mail-wm1-x342.google.com with SMTP id q16so2307303wmj.3; Thu, 18 Apr 2019 04:12:16 -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=KT4IxCbsdb20vxjXV3Yb4q905/4eUjLcCpAjIqK4bV0=; b=Y0dp+VAQWLfpErhF5KeNWFfcBtdaMQvfr9DnX6fKs/x/daooxvyFFobx/p0lK4b1su sL3/oMGDNvEAQDpMWWoSMgYLEAs8HzpjSQH8Oa4cHmI9qOUN1VRi9QqSScgfCArJud6+ OjuhRAikaH4eI+ba1oTlYRBm68ubvsAJEYgHe+0u7Ob7hB3F1ipgC3nGw1GsHjsQ8sCM eQdfS55oeRT/OxLSmob0RZUskqtAMwiFDQiR2ONAhTLL2ZPBWr4jKLLytpon1nX4K90s 3geEjI7yvYIxF8SiuwTIg0Vszc/6KJzlKwPCd6EIjh9XCkSn37wVEFOaSdky5ipCyvyp amrg== 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=KT4IxCbsdb20vxjXV3Yb4q905/4eUjLcCpAjIqK4bV0=; b=TPr28HuTGndJsQgGeB9JbgaTPSail7rnnPDZQcMB6pzLryS/jL7TcR9jcP1bcqBVzK 1ERT7os7rQ+MeOj+U76IhEBNmEU9tPYPT8KSpmkOVYoIBmXwv1IpErrDfTW9FQGUpw3y 8Q7d2yvWXiWVt0TGsO8TSj38OOf6ps8cNpNaisGHqqfVD8TQFqKxvO8ga6l1HW8L1XFC nHjUOXkroIflQb4+sxb745yq64RTYNnU6wUJi+p/f6+vVYRRhi7kxAU1xw6CpK0y16mS FYqmBh/S5s1eNJRzg3lPnju+xlC5bbFEcQK/Xs9K4CrwyHO5FCen7whElB3lkFq3T7Sx /hqA== X-Gm-Message-State: APjAAAXDhaw+HjaTSDlvm26T1w7AbVQGQhQ2obKITgEpvbDZCyhF2AhY 7z0QPhJmcYwoNqNP/+CXq6s= X-Google-Smtp-Source: APXvYqxs6Cf3sKJNDaD7WXuqSj31uua0iWy7oJoeMqG8rWXkMXo9aCMr9fbPBHKpXW7mg3Uayp8TLg== X-Received: by 2002:a1c:1b10:: with SMTP id b16mr2760179wmb.90.1555585935442; Thu, 18 Apr 2019 04:12:15 -0700 (PDT) Received: from localhost.localdomain ([2001:470:9e39::64]) by smtp.gmail.com with ESMTPSA id z63sm2005594wme.30.2019.04.18.04.12.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Apr 2019 04:12:14 -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 1/8] clk: divider: add explicit big endian support Date: Thu, 18 Apr 2019 13:12:04 +0200 Message-Id: <20190418111211.10474-2-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_041217_028785_1B80ED16 X-CRM114-Status: GOOD ( 15.37 ) 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 divider clocks. Signed-off-by: Jonas Gorski --- V2 -> V3: * fix passed arguments to clk_div_readl found by kbuild * drop unneeded else in clk_div_readl V1 -> V2: * switch from global to local flag drivers/clk/clk-divider.c | 26 ++++++++++++++++++++++---- include/linux/clk-provider.h | 4 ++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index e5a17265cfaf..25c7404e376c 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c @@ -25,6 +25,24 @@ * parent - fixed parent. No clk_set_parent support */ +static inline u32 clk_div_readl(struct clk_divider *divider) +{ + if (divider->flags & CLK_DIVIDER_BIG_ENDIAN) + return ioread32be(divider->reg); + + return clk_readl(divider->reg); +} + +static inline void clk_div_writel(struct clk_divider *divider, u32 val) +{ + if (divider->flags & CLK_DIVIDER_BIG_ENDIAN) + iowrite32be(val, divider->reg); + else + clk_writel(val, divider->reg); +} + +#define div_mask(width) ((1 << (width)) - 1) + static unsigned int _get_table_maxdiv(const struct clk_div_table *table, u8 width) { @@ -135,7 +153,7 @@ static unsigned long clk_divider_recalc_rate(struct clk_hw *hw, struct clk_divider *divider = to_clk_divider(hw); unsigned int val; - val = clk_readl(divider->reg) >> divider->shift; + val = clk_div_readl(divider) >> divider->shift; val &= clk_div_mask(divider->width); return divider_recalc_rate(hw, parent_rate, val, divider->table, @@ -370,7 +388,7 @@ static long clk_divider_round_rate(struct clk_hw *hw, unsigned long rate, if (divider->flags & CLK_DIVIDER_READ_ONLY) { u32 val; - val = clk_readl(divider->reg) >> divider->shift; + val = clk_div_readl(divider) >> divider->shift; val &= clk_div_mask(divider->width); return divider_ro_round_rate(hw, rate, prate, divider->table, @@ -420,11 +438,11 @@ static int clk_divider_set_rate(struct clk_hw *hw, unsigned long rate, if (divider->flags & CLK_DIVIDER_HIWORD_MASK) { val = clk_div_mask(divider->width) << (divider->shift + 16); } else { - val = clk_readl(divider->reg); + val = clk_div_readl(divider); val &= ~(clk_div_mask(divider->width) << divider->shift); } val |= (u32)value << divider->shift; - clk_writel(val, divider->reg); + clk_div_writel(divider, val); if (divider->lock) spin_unlock_irqrestore(divider->lock, flags); diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index db21437c77e2..7117b8cc0c0c 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -416,6 +416,9 @@ struct clk_div_table { * CLK_DIVIDER_MAX_AT_ZERO - For dividers which are like CLK_DIVIDER_ONE_BASED * except when the value read from the register is zero, the divisor is * 2^width of the field. + * CLK_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_divider { struct clk_hw hw; @@ -437,6 +440,7 @@ struct clk_divider { #define CLK_DIVIDER_ROUND_CLOSEST BIT(4) #define CLK_DIVIDER_READ_ONLY BIT(5) #define CLK_DIVIDER_MAX_AT_ZERO BIT(6) +#define CLK_DIVIDER_BIG_ENDIAN BIT(7) extern const struct clk_ops clk_divider_ops; extern const struct clk_ops clk_divider_ro_ops;