From patchwork Mon Jul 13 00:25:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Van Asbroeck X-Patchwork-Id: 11658473 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0133617C5 for ; Mon, 13 Jul 2020 00:27:06 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CDB1A2067D for ; Mon, 13 Jul 2020 00:27:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="PraUMSJM"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IlJdPzO5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CDB1A2067D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.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=Gy+eTv61Q0XN0C0FPfMi6LHUG3vOoGmCnACZ5CeiV60=; b=PraUMSJM5mldH3IHHO6LCViPJ8 GnZHhKFPtANAay93wNPeAOmwN9/5Ud9SI86Qi2fuLF1svs0Bgi9IYMFVM3yfs7zFil6U9SmljJDdw VMqzDSLR4f79convhQQ7G7Nr8kFLOR65Oi0FJEH/EmVR94Nh4/L//pH+xTCniyqcS6Xiw208AP5Gv dsdVqR1ht5IUGyvsEh7HuY4sC1DfSNCP4gz2BHMeUmAsPd3iiSzkUHCrA9RJ+wMiALJ44EUb13J+Z 0Cx3lV11LgHsxskp8HxK6q+ZfY1v0lP90tsfb3msT5IB9OSZTZ7orxX2/YGmlM/01sh+ohfO9AcBD dcsTkZqQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jumHd-00022r-I5; Mon, 13 Jul 2020 00:25:25 +0000 Received: from mail-qt1-x844.google.com ([2607:f8b0:4864:20::844]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jumHY-00020b-Lf for linux-arm-kernel@lists.infradead.org; Mon, 13 Jul 2020 00:25:21 +0000 Received: by mail-qt1-x844.google.com with SMTP id d27so8783062qtg.4 for ; Sun, 12 Jul 2020 17:25:20 -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=Es3z9+6oVEd9P5UxAlvjZy0XJ5zCI0VHL9FYRbRC/gM=; b=IlJdPzO5QN7ZJv3oZFIrdJ8Ooyp6hmgwNxdNNCmoWDrI49jF5NJyowmC7EBAwvpYu8 tzLkDTdCWiaTD+UG/P6cPjHiQ0MISCRBeLXCmCBWq+cfn48mENt7txm4+Cv19PL8NGKA tSeYnD8H2Z/ZTld/FUk98oxtzJP5UITe8TS1OPzxgx4NZMexAbQGhYRIwwokCHabJr19 nNFEO7L34uU6NBWYP1N+4zs8uqWBflFXa/rtGCSmJqA9xZF52aUBiuPCxEX0J/kuN/MQ AjsWOLI807IumCgu/g3Ys+kuXPoBMUMLBkkpWjuxQrT7++BeDDuU1R2YQpxbXX7HCy1X QJNg== 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=Es3z9+6oVEd9P5UxAlvjZy0XJ5zCI0VHL9FYRbRC/gM=; b=hlnDLHrnodVdbYlW+XJWxV0xlODb1okLO71d0HwzEdYMGjq4fyae20P4cHpBPGVhox uAjuye5GUZs7lNux9RpZnwbFiR04fsmTWmJk0IzMKVPM3YkJecSmHwp9db/lM1MLB1Qf A6bLIs+rvQ1xa3fAD3C8ZbKPc9ZZTrvgjMdZcUfax0Bn7w+bE5o3DfyNZWNAs9aOsruI vgKik1JQfPuqU9S9W73srvgL1+biG8rY7jw5lL3fN4UTTft+j0W0cJ94F0PTu4LrXuuy YCBzLcdcxUJ+VutMmEdtjWghOl6PgAt2BMPLQziydLqgkg2Ql0HE641y6N/tMZPDTHph cMcQ== X-Gm-Message-State: AOAM533bR/DqKQJiFqXNvIEJonjASmt4Gg9WaNbgZS14ZomySasuVjVa VzTkEXy1oDk8WOVmpqkDmX8= X-Google-Smtp-Source: ABdhPJzLZ8gpYiloumiaSUnCaORV7qMNuoZlWRNacT/kz53QHdc4auTOpe2lawDgPHMLC0FEszmxzQ== X-Received: by 2002:ac8:4316:: with SMTP id z22mr81424171qtm.121.1594599918561; Sun, 12 Jul 2020 17:25:18 -0700 (PDT) Received: from localhost.localdomain ([72.53.229.195]) by smtp.gmail.com with ESMTPSA id u5sm17044309qke.32.2020.07.12.17.25.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jul 2020 17:25:18 -0700 (PDT) From: Sven Van Asbroeck X-Google-Original-From: Sven Van Asbroeck To: shawnguo@kernel.org, s.hauer@pengutronix.de Subject: [PATCH v1 2/5] clk: imx: add simple regmap-backed clock mux Date: Sun, 12 Jul 2020 20:25:09 -0400 Message-Id: <20200713002512.28742-3-TheSven73@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200713002512.28742-1-TheSven73@gmail.com> References: <20200713002512.28742-1-TheSven73@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200712_202520_733862_29677151 X-CRM114-Status: GOOD ( 21.59 ) X-Spam-Score: 0.1 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thesven73[at]gmail.com] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [thesven73[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:844 listed in] [list.dnswl.org] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, NXP Linux Team , Pengutronix Kernel Team , Fabio Estevam , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org On the imx6 QuadPlus, some clocktree muxes have control bits located in the GPR area. This area is already modelled as a syscon regmap. To control these muxes, add a simple regmap-backed clock mux. Signed-off-by: Sven Van Asbroeck --- Tree: v5.8-rc4 To: Shawn Guo To: Sascha Hauer Cc: Pengutronix Kernel Team Cc: Fabio Estevam Cc: NXP Linux Team Cc: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-clk@vger.kernel.org drivers/clk/imx/Makefile | 1 + drivers/clk/imx/clk-mux-regmap.c | 110 +++++++++++++++++++++++++++++++ drivers/clk/imx/clk.h | 7 ++ 3 files changed, 118 insertions(+) create mode 100644 drivers/clk/imx/clk-mux-regmap.c diff --git a/drivers/clk/imx/Makefile b/drivers/clk/imx/Makefile index 928f874c73d2..3d36740c1efd 100644 --- a/drivers/clk/imx/Makefile +++ b/drivers/clk/imx/Makefile @@ -19,6 +19,7 @@ obj-$(CONFIG_MXC_CLK) += \ clk-pllv3.o \ clk-pllv4.o \ clk-sscg-pll.o \ + clk-mux-regmap.o \ clk-pll14xx.o obj-$(CONFIG_MXC_CLK_SCU) += \ diff --git a/drivers/clk/imx/clk-mux-regmap.c b/drivers/clk/imx/clk-mux-regmap.c new file mode 100644 index 000000000000..ba5fde525999 --- /dev/null +++ b/drivers/clk/imx/clk-mux-regmap.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020 Sven Van Asbroeck + * + * Simple clock multiplexer, backed by a regmap + */ + +#include +#include +#include + +#include "clk.h" + +struct clk_mux_regmap { + struct clk_hw hw; + struct regmap *regmap; + unsigned int reg; + u8 shift; + u32 mask; +}; + +#define to_clk_mux_regmap(_hw) container_of(_hw, struct clk_mux_regmap, hw) + +static u8 clk_regmap_read_index(struct clk_mux_regmap *clk) +{ + unsigned int val; + + if (regmap_read(clk->regmap, clk->reg, &val)) + return 0; + + val >>= clk->shift; + val &= clk->mask; + + return (u8)val; +} + +static u8 clk_mux_regmap_get_parent(struct clk_hw *hw) +{ + struct clk_mux_regmap *clk = to_clk_mux_regmap(hw); + + return clk_regmap_read_index(clk); +} + +static int clk_mux_regmap_set_parent(struct clk_hw *hw, u8 index) +{ + struct clk_mux_regmap *clk = to_clk_mux_regmap(hw); + + return regmap_update_bits(clk->regmap, clk->reg, + clk->mask << clk->shift, + (unsigned int)index << clk->shift); +} + +static int clk_mux_regmap_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + struct clk_mux_regmap *clk = to_clk_mux_regmap(hw); + struct clk_hw *parent; + u8 index; + + index = clk_regmap_read_index(clk); + parent = clk_hw_get_parent_by_index(hw, index); + if (!parent) + return -EINVAL; + req->rate = clk_hw_get_rate(parent); + + return 0; +} + +static const struct clk_ops clk_mux_regmap_ops = { + .get_parent = clk_mux_regmap_get_parent, + .set_parent = clk_mux_regmap_set_parent, + .determine_rate = clk_mux_regmap_determine_rate, +}; + +struct clk_hw * +imx_clk_hw_mux_regmap(const char *name, struct regmap *regmap, unsigned int reg, + u8 shift, u8 width, const char * const *parent_names, + int num_parents) +{ + struct clk_mux_regmap *clk_regmap; + struct clk_init_data init = {}; + struct clk_hw *hw; + int ret; + + if (num_parents > (1 << width)) + return ERR_PTR(-EINVAL); + + clk_regmap = kzalloc(sizeof(*clk_regmap), GFP_KERNEL); + if (!clk_regmap) + return ERR_PTR(-ENOMEM); + + init.name = name; + init.parent_names = parent_names; + init.num_parents = num_parents; + init.ops = &clk_mux_regmap_ops; + clk_regmap->regmap = regmap; + clk_regmap->reg = reg; + clk_regmap->shift = shift; + clk_regmap->mask = BIT(width) - 1; + clk_regmap->hw.init = &init; + + hw = &clk_regmap->hw; + ret = clk_hw_register(NULL, hw); + if (ret) { + kfree(clk_regmap); + hw = ERR_PTR(ret); + } + + return hw; +} diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h index 16adbc34e05f..4df766abbe16 100644 --- a/drivers/clk/imx/clk.h +++ b/drivers/clk/imx/clk.h @@ -5,6 +5,8 @@ #include #include +struct regmap; + #define IMX_CLK_GATE2_SINGLE_BIT 1 extern spinlock_t imx_ccm_lock; @@ -447,6 +449,11 @@ static inline struct clk_hw *imx_dev_clk_hw_mux(struct device *dev, reg, shift, width, 0, &imx_ccm_lock); } +struct clk_hw * +imx_clk_hw_mux_regmap(const char *name, struct regmap *regmap, unsigned int reg, + u8 shift, u8 width, const char * const *parent_names, + int num_parents); + static inline struct clk *imx_clk_mux2(const char *name, void __iomem *reg, u8 shift, u8 width, const char * const *parents, int num_parents)