From patchwork Sat Mar 24 13:31:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 132378 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp1790318ljb; Sat, 24 Mar 2018 06:33:50 -0700 (PDT) X-Google-Smtp-Source: AG47ELty9gtWLO+3DARFMhHYdIZPy47aR6JswG6jfvBvcTiuD1Yx36eCDHjHzk7QMYOM1Jt4EJPm X-Received: by 2002:a17:902:b901:: with SMTP id bf1-v6mr32874776plb.175.1521898430425; Sat, 24 Mar 2018 06:33:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521898430; cv=none; d=google.com; s=arc-20160816; b=ZOkdlV/oqud1s263b758v8bXUhaFTTkMTvMFBjfWosjx4L9j7t4dH9wVkUrieycJJs grhZEupmmeawoiDIOt1IasiHZKGLu4vMeaRMi50aYW42mq5RG+z6N+y2+xFErfChYelq gRhv0kchX7NAaEl5pkJ8HZDXMhB4SSx1tfvINLhI0JoE5TwO9apQ/HGwcbsWroCjRcbe A+QgR0NJ81bQQxihzWem88s+glc1YJEt3J7uXyH1SbJnSq2LTbnCvyDw++s8JQA1s25A +lKc7HJftvMeU8ejRNX3R3Qh9+5vnQI+T9cK0hbbtFgUE/dWgUfFbLYa9jHF+q0Ly7NS cG0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=seVTnliGJc5xELZw9oAHHFfw1Sv3N8ggokUwzyYYyCM=; b=EW3brN1BXo6nrxo2bDIgBaqC7JBSlTB47Kxt4DjzTfaNz0uhiO9Ed7IcVTfJblEz61 /XmybImFDiMrt5IPB1H6GloEnP1sqCUHelqxOMDwWjf0wLym9kHlWUErFRiJySD5wZdK cy8gH/rBbVZ3t0FR3ssPD7V1wNMjqzsh1J2vThuCJxPRipHZkJH9Qf3DwSRFtw/4fEuc QRN1BIO54ReuULRNG/mRJOoqQewUbMIqsxsjUSxTVQLkNg7JIZPYHPrEGUV7JQTouwbd NikL2cVWdiVY5JRhi/GGxjGqth2bpWmxWjXmG1cGylqKn+hng7uYkrxGwi6JEEYeLepI I+xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZuALBRur; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l13-v6si11545280pln.437.2018.03.24.06.33.50; Sat, 24 Mar 2018 06:33:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZuALBRur; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752478AbeCXNdq (ORCPT + 28 others); Sat, 24 Mar 2018 09:33:46 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:44802 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752416AbeCXNdm (ORCPT ); Sat, 24 Mar 2018 09:33:42 -0400 Received: by mail-pl0-f65.google.com with SMTP id 9-v6so9114905ple.11 for ; Sat, 24 Mar 2018 06:33:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=seVTnliGJc5xELZw9oAHHFfw1Sv3N8ggokUwzyYYyCM=; b=ZuALBRurLUzRDzSxmSVr3a8Tdpp5NcnXEuunWysk+ZOwU7YwSMZYJiws5FpubwMdbX 8pQA/cAi23B58QdmzSCbYxNPKYu7EE++WbmW7NlA8G2wUWTqXGU0FjJ8kj7zVaVEHm5V +nuGznsXFolfXQKjLDYuSX4f/Br4ZhODe6CIM= 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=seVTnliGJc5xELZw9oAHHFfw1Sv3N8ggokUwzyYYyCM=; b=fKVl6zkZUhX6SH+z5FkOPqxDpKUZt4y+AMr0ky7L1mIHLqMa4bEhW9Z6uqLNDnI9tn gKHB4mOf9kBHN1uDryqtLy3dT9r7iXFaa6ST96gEDa3L+9BoevA14Yr5TFXm/X93xs+j awjxmW/3Sl7sBMrREV7cFYYFPP1t6Dl/5aJCVfG2a23nPcenSvYVVKpiluxr5vfv3RXJ mcKKsQyjXC2grZLfNFKpua/LCLxuAerHUcWlgjOfAJuv3babidMeyTXsmiSKMp0x+w+/ sArZPxxY/VC/AVHHFybAdRcy8GGS+BRoK4HUwjwFw2KbiGWhAHS/e2I/fbB2NCjUpDXg h0AA== X-Gm-Message-State: AElRT7EAUnSDzncw0WfN4em6LmcmhN2PR5w9myB8sZU9oh3MqlstSxCL W8PRUnk8asJyCdq6JZR48VVf X-Received: by 2002:a17:902:5409:: with SMTP id d9-v6mr21558960pli.176.1521898421835; Sat, 24 Mar 2018 06:33:41 -0700 (PDT) Received: from localhost.localdomain ([2405:204:7401:11e6:b12d:f551:4edc:7f21]) by smtp.gmail.com with ESMTPSA id a76sm4133980pfc.97.2018.03.24.06.33.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 06:33:41 -0700 (PDT) From: Manivannan Sadhasivam To: mturquette@baylibre.com, sboyd@kernel.org, afaerber@suse.de, robh+dt@kernel.org, mark.rutland@arm.com Cc: liuwei@actions-semi.com, mp-cs@actions-semi.com, 96boards@ucrobotics.com, devicetree@vger.kernel.org, davem@davemloft.net, mchehab@kernel.org, daniel.thompson@linaro.org, amit.kucheria@linaro.org, viresh.kumar@linaro.org, hzhang@ucrobotics.com, bdong@ucrobotics.com, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, manivannanece23@gmail.com, Manivannan Sadhasivam Subject: [PATCH v6 05/11] clk: actions: Add mux clock support Date: Sat, 24 Mar 2018 19:01:53 +0530 Message-Id: <20180324133159.4824-6-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180324133159.4824-1-manivannan.sadhasivam@linaro.org> References: <20180324133159.4824-1-manivannan.sadhasivam@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for Actions Semi mux clock together with helper functions to be used in composite clock. Signed-off-by: Manivannan Sadhasivam --- drivers/clk/actions/Makefile | 1 + drivers/clk/actions/owl-mux.c | 60 ++++++++++++++++++++++++++++++++++++++++++ drivers/clk/actions/owl-mux.h | 61 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 drivers/clk/actions/owl-mux.c create mode 100644 drivers/clk/actions/owl-mux.h -- 2.14.1 diff --git a/drivers/clk/actions/Makefile b/drivers/clk/actions/Makefile index 1f0917872c9d..2d4aa8f35d90 100644 --- a/drivers/clk/actions/Makefile +++ b/drivers/clk/actions/Makefile @@ -2,3 +2,4 @@ obj-$(CONFIG_CLK_ACTIONS) += clk-owl.o clk-owl-y += owl-common.o clk-owl-y += owl-gate.o +clk-owl-y += owl-mux.o diff --git a/drivers/clk/actions/owl-mux.c b/drivers/clk/actions/owl-mux.c new file mode 100644 index 000000000000..f9c6cf2540e4 --- /dev/null +++ b/drivers/clk/actions/owl-mux.c @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0+ +// +// OWL mux clock driver +// +// Copyright (c) 2014 Actions Semi Inc. +// Author: David Liu +// +// Copyright (c) 2018 Linaro Ltd. +// Author: Manivannan Sadhasivam + +#include +#include + +#include "owl-mux.h" + +u8 owl_mux_helper_get_parent(const struct owl_clk_common *common, + const struct owl_mux_hw *mux_hw) +{ + u32 reg; + u8 parent; + + regmap_read(common->regmap, mux_hw->reg, ®); + parent = reg >> mux_hw->shift; + parent &= BIT(mux_hw->width) - 1; + + return parent; +} + +static u8 owl_mux_get_parent(struct clk_hw *hw) +{ + struct owl_mux *mux = hw_to_owl_mux(hw); + + return owl_mux_helper_get_parent(&mux->common, &mux->mux_hw); +} + +int owl_mux_helper_set_parent(const struct owl_clk_common *common, + struct owl_mux_hw *mux_hw, u8 index) +{ + u32 reg; + + regmap_read(common->regmap, mux_hw->reg, ®); + reg &= ~GENMASK(mux_hw->width + mux_hw->shift - 1, mux_hw->shift); + regmap_write(common->regmap, mux_hw->reg, + reg | (index << mux_hw->shift)); + + return 0; +} + +static int owl_mux_set_parent(struct clk_hw *hw, u8 index) +{ + struct owl_mux *mux = hw_to_owl_mux(hw); + + return owl_mux_helper_set_parent(&mux->common, &mux->mux_hw, index); +} + +const struct clk_ops owl_mux_ops = { + .get_parent = owl_mux_get_parent, + .set_parent = owl_mux_set_parent, + .determine_rate = __clk_mux_determine_rate, +}; diff --git a/drivers/clk/actions/owl-mux.h b/drivers/clk/actions/owl-mux.h new file mode 100644 index 000000000000..834284c8c3ae --- /dev/null +++ b/drivers/clk/actions/owl-mux.h @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0+ +// +// OWL mux clock driver +// +// Copyright (c) 2014 Actions Semi Inc. +// Author: David Liu +// +// Copyright (c) 2018 Linaro Ltd. +// Author: Manivannan Sadhasivam + +#ifndef _OWL_MUX_H_ +#define _OWL_MUX_H_ + +#include "owl-common.h" + +struct owl_mux_hw { + u32 reg; + u8 shift; + u8 width; +}; + +struct owl_mux { + struct owl_mux_hw mux_hw; + struct owl_clk_common common; +}; + +#define OWL_MUX_HW(_reg, _shift, _width) \ + { \ + .reg = _reg, \ + .shift = _shift, \ + .width = _width, \ + } + +#define OWL_MUX(_struct, _name, _parents, _reg, \ + _shift, _width, _flags) \ + struct owl_mux _struct = { \ + .mux_hw = OWL_MUX_HW(_reg, _shift, _width), \ + .common = { \ + .regmap = NULL, \ + .hw.init = CLK_HW_INIT_PARENTS(_name, \ + _parents, \ + &owl_mux_ops, \ + _flags), \ + }, \ + } + +static inline struct owl_mux *hw_to_owl_mux(const struct clk_hw *hw) +{ + struct owl_clk_common *common = hw_to_owl_clk_common(hw); + + return container_of(common, struct owl_mux, common); +} + +u8 owl_mux_helper_get_parent(const struct owl_clk_common *common, + const struct owl_mux_hw *mux_hw); +int owl_mux_helper_set_parent(const struct owl_clk_common *common, + struct owl_mux_hw *mux_hw, u8 index); + +extern const struct clk_ops owl_mux_ops; + +#endif /* _OWL_MUX_H_ */