From patchwork Sat Mar 17 10:09:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 131964 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp490116ljb; Sat, 17 Mar 2018 03:11:55 -0700 (PDT) X-Google-Smtp-Source: AG47ELtZr8TEqqULD5Gl1g2/otJ2MQ93GT/FuX78Mxah7szApT9gb6EDx0r7CX8x53MF1XClbFuG X-Received: by 10.99.119.74 with SMTP id s71mr4016249pgc.321.1521281515824; Sat, 17 Mar 2018 03:11:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521281515; cv=none; d=google.com; s=arc-20160816; b=CHf3VG34rYQSOBB758Py8PnCr0P97wwK68gqtQzaIUBxVGeczpavd3TqiU5D6+40SM O54Sip5Z+yscoKeQWd/vkpsHvCuBe8n14F+etwMiR7Bglvrqx/hEzqgqjWFGaK6c44ip KI9Jw7aLGGyFsxHFLtx1ZEBfCTBT/kjKzKqBYQRscs9F4cvcVmVWXvnuPuB6PfN9xMIx ZfwPOTsX1paQNueMIG2H0jzRjs7HYzPrSX8+/R5XhnSaQX50BjbtOAu6/61HCIYBn1Yd 6KJB2jiAHHaOSuP3I5JwNPkKdS3bJLNtG29AmVkZqvk9amUwOMfOT1Mk2hAV5cqbP39P iZRA== 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=wachYY6LBU2xlKzkoKdIejvR6g2Rm6TUyFoysFpQFGhSrWwN7SNsB8na4pBGUgkix0 PUmX54v/DuUdkOIL4Ft7lop+1jVzJwzj6idg/uoTB0iMfCyPZsR+LQ5HDXKXKD1euOeR Gtg3mtjg7jzVqw26cmq5MzQR0uUSyHeFto3EWnxvjuZWT4sPmXvSLkPFTon+lKCRYATC rYppZ/e8kgZsIycJX8+TXBwLNPbScRfC2alN33qZGwrijiEIBEdIOwgc5Ja5e8zXNd9q ZzDwlq1srlODjW3E/E167/ZMtvU2BqqmMrh4tv7yMIz4BV+wOPTrGLgcsPAAtEeSdcTy uiGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=awsHA6Rx; 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 n3-v6si7848038pld.347.2018.03.17.03.11.55; Sat, 17 Mar 2018 03:11:55 -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=awsHA6Rx; 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 S1752723AbeCQKLw (ORCPT + 28 others); Sat, 17 Mar 2018 06:11:52 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:42107 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752674AbeCQKLr (ORCPT ); Sat, 17 Mar 2018 06:11:47 -0400 Received: by mail-pl0-f65.google.com with SMTP id w15-v6so7300854plq.9 for ; Sat, 17 Mar 2018 03:11:47 -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=awsHA6RxAGUZWq/zd2OjOVCMy1LwpomXwU5dsD1tORj1svjNp0ibhJQmXQ74iUbOCb rflIIyAxxix0vUMlZ82NmRmmIJiFckrMQ8EU76LNbU03gZBLfIkNgEfU83AP8JjeJqnG /00JI/3TVqeAoQioKXUj4FgPEDY24Ib1eDQAY= 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=sQxjh1tbOPyvHN+Vjxu0nDO2bU1GuQ6kcy6bpvVYgQk7Q0DBJRJDUQ3AZx7BqZ5kYM 6ATy+D/MXYE3q7qPAhoHPhf8VjOAtNDbVjyZgrEBwaGrBUCW+zAPJJN6RD/aR2A3+23F GbXG2l2d9ThIIP/PnIEi5PSOikkeJAmb0XtZ9l43mJOm5t1E0him0RJLHNfp5tvKPlg0 EzfO7tbV4DiTpG/20NqFvk1y+88IEX/g6E8lRG06yaG1XCgA5+QVA1Df7r0kIR3gOMj8 RwUhIsofgkLbKCivJ0PDND0oBuGHLGVAi+xEziCBxSJuBEWbAoM8HyQ+B+eBj2RXkac4 XrIg== X-Gm-Message-State: AElRT7FPCgDiKaitq+AuBqF/clWWi0xot9FffSXBUqmI8MzknRPe0U2R vf8Ub8DuqWMB3JwYzP7TLsuq X-Received: by 2002:a17:902:96a:: with SMTP id 97-v6mr5155853plm.183.1521281506931; Sat, 17 Mar 2018 03:11:46 -0700 (PDT) Received: from mani-Aspire-E5-573.domain.name ([171.49.203.57]) by smtp.gmail.com with ESMTPSA id i27sm3771625pfj.123.2018.03.17.03.11.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Mar 2018 03:11:46 -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 v5 06/12] clk: actions: Add mux clock support Date: Sat, 17 Mar 2018 15:39:46 +0530 Message-Id: <20180317100952.28538-7-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180317100952.28538-1-manivannan.sadhasivam@linaro.org> References: <20180317100952.28538-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_ */