Received: by 10.223.164.221 with SMTP id h29csp1763877wrb; Thu, 2 Nov 2017 00:05:29 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QNUnjNge0OukUORppgIdegRiexWQn+dKaQFBwIakE+7Cgh04n5lpngMRj1QjHTOfWx3JWM X-Received: by 10.98.162.26 with SMTP id m26mr2757631pff.0.1509606329405; Thu, 02 Nov 2017 00:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509606329; cv=none; d=google.com; s=arc-20160816; b=Tzk3ZV46BiC9Je+p/8seSGZVaAhdIYExfzkQnKzzG2dyYGtvuUKBc7V0yhfZ6ntUe7 RBV1BMV4ry1zNdppQvnpnF/iu2t1yTkLBn9ZPu2tx0AecacfnPZQjwMGwDizi1+kNgQh QEe6qxGiAs6AD1m/xELTQu/pZuCrGS3lYLgkFiw0kJ1POc3y5WxlsWpTCr2RvtvXxmRi LlcXiLA5e+vtTIdXGbftPL7riqFE0ITMLUlm+M0ykMwtLq89TpfwxhRU8lfyCCcFW3X0 IobifUBV+BbJ7AFI/vTEOOjXZ5HZ9baFHg33sKN8u4XTlwiqL7LZCFU7JHiCttps9aw6 m4Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=MEgqsbQWQs3Seda2VFVudk++eyeIKLFZuR/dsADMKs4=; b=uwj6qAI7QZT5wl1qPOPNaZBuX5l5mns4z0ghebDbH3l2iseE+4G9tQadPEk8q40Aa7 LoM+pd2Gg7Jal9lKKHqYh7FUoG5FxrHmYfJizjInstUQJVVPnPPW+Av0rcTX/VoH0FSL a9T4H3TtC6fjEsi/n64agsrxSBFe9A9fFKwirym+ZGGCJJoE1ype+VGSm1twwGFpgbxB QcFoUgibpIJ8+s5rOp/y8KXvL/0BNYTGrM5V+AOKt+HCFyP7ngDCdom+foa13RDNM0Kx 6Xa5dIimPAZ8yGAEEHfvbbX5xwGm2+RYZh1RSo02uBFwsI1menTcUcYu4jVXHEZbgZl/ GvDA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o28si2761991pgc.521.2017.11.02.00.05.15; Thu, 02 Nov 2017 00:05:29 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755431AbdKBHEQ (ORCPT + 99 others); Thu, 2 Nov 2017 03:04:16 -0400 Received: from sci-ig2.spreadtrum.com ([222.66.158.135]:34053 "EHLO SHSQR01.spreadtrum.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1755410AbdKBHEM (ORCPT ); Thu, 2 Nov 2017 03:04:12 -0400 Received: from SHSQR01.spreadtrum.com (localhost [127.0.0.2] (may be forged)) by SHSQR01.spreadtrum.com with ESMTP id vA2747SG020438 for ; Thu, 2 Nov 2017 15:04:07 +0800 (CST) (envelope-from Chunyan.Zhang@spreadtrum.com) Received: from ig2.spreadtrum.com (shmbx01.spreadtrum.com [10.0.1.203]) by SHSQR01.spreadtrum.com with ESMTP id vA272PXD015654 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 2 Nov 2017 15:02:25 +0800 (CST) (envelope-from Chunyan.Zhang@spreadtrum.com) Received: from SHCAS02.spreadtrum.com (10.0.1.202) by SHMBX01.spreadtrum.com (10.0.1.203) with Microsoft SMTP Server (TLS) id 15.0.847.32; Thu, 2 Nov 2017 15:02:26 +0800 Received: from localhost (10.0.73.143) by SHCAS02.spreadtrum.com (10.0.1.250) with Microsoft SMTP Server (TLS) id 15.0.847.32 via Frontend Transport; Thu, 2 Nov 2017 15:02:27 +0800 From: Chunyan Zhang To: Stephen Boyd , Michael Turquette , Rob Herring , Mark Rutland CC: Catalin Marinas , Will Deacon , , , Arnd Bergmann , Mark Brown , Xiaolong Zhang , Ben Li , , , Orson Zhai , Chunyan Zhang Subject: [PATCH V3 05/11] clk: sprd: add mux clock support Date: Thu, 2 Nov 2017 14:56:20 +0800 Message-ID: <20171102065626.21835-6-chunyan.zhang@spreadtrum.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20171102065626.21835-1-chunyan.zhang@spreadtrum.com> References: <20171102065626.21835-1-chunyan.zhang@spreadtrum.com> MIME-Version: 1.0 Content-Type: text/plain X-MAIL: SHSQR01.spreadtrum.com vA272PXD015654 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds clock multiplexor support for Spreadtrum platforms, the mux clocks also can be found in sprd composite clocks, so provides two helpers that can be reused later on. Signed-off-by: Chunyan Zhang --- drivers/clk/sprd/Makefile | 1 + drivers/clk/sprd/mux.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/clk/sprd/mux.h | 65 ++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 drivers/clk/sprd/mux.c create mode 100644 drivers/clk/sprd/mux.h diff --git a/drivers/clk/sprd/Makefile b/drivers/clk/sprd/Makefile index 8cd5592..cee36b5 100644 --- a/drivers/clk/sprd/Makefile +++ b/drivers/clk/sprd/Makefile @@ -2,3 +2,4 @@ obj-$(CONFIG_SPRD_COMMON_CLK) += clk-sprd.o clk-sprd-y += common.o clk-sprd-y += gate.o +clk-sprd-y += mux.o diff --git a/drivers/clk/sprd/mux.c b/drivers/clk/sprd/mux.c new file mode 100644 index 0000000..5a344e0 --- /dev/null +++ b/drivers/clk/sprd/mux.c @@ -0,0 +1,89 @@ +/* + * Spreadtrum multiplexer clock driver + * + * Copyright (C) 2017 Spreadtrum, Inc. + * Author: Chunyan Zhang + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include +#include +#include + +#include "mux.h" + +DEFINE_SPINLOCK(sprd_mux_lock); +EXPORT_SYMBOL_GPL(sprd_mux_lock); + +u8 sprd_mux_helper_get_parent(const struct sprd_clk_common *common, + const struct sprd_mux_internal *mux) +{ + unsigned int reg; + u8 parent; + int num_parents; + int i; + + sprd_regmap_read(common->regmap, common->reg, ®); + parent = reg >> mux->shift; + parent &= (1 << mux->width) - 1; + + if (mux->table) { + num_parents = clk_hw_get_num_parents(&common->hw); + + for (i = 0; i < num_parents; i++) + if (parent == mux->table[i] || + (i < (num_parents - 1) && parent > mux->table[i] && + parent < mux->table[i + 1])) + return i; + if (i == num_parents) + return i - 1; + } + + return parent; +} +EXPORT_SYMBOL_GPL(sprd_mux_helper_get_parent); + +static u8 sprd_mux_get_parent(struct clk_hw *hw) +{ + struct sprd_mux *cm = hw_to_sprd_mux(hw); + + return sprd_mux_helper_get_parent(&cm->common, &cm->mux); +} + +int sprd_mux_helper_set_parent(const struct sprd_clk_common *common, + const struct sprd_mux_internal *mux, + u8 index) +{ + unsigned long flags = 0; + unsigned int reg; + + if (mux->table) + index = mux->table[index]; + + spin_lock_irqsave(common->lock, flags); + + sprd_regmap_read(common->regmap, common->reg, ®); + reg &= ~GENMASK(mux->width + mux->shift - 1, mux->shift); + sprd_regmap_write(common->regmap, common->reg, + reg | (index << mux->shift)); + + spin_unlock_irqrestore(common->lock, flags); + + return 0; +} +EXPORT_SYMBOL_GPL(sprd_mux_helper_set_parent); + +static int sprd_mux_set_parent(struct clk_hw *hw, u8 index) +{ + struct sprd_mux *cm = hw_to_sprd_mux(hw); + + return sprd_mux_helper_set_parent(&cm->common, &cm->mux, index); +} + +const struct clk_ops sprd_mux_ops = { + .get_parent = sprd_mux_get_parent, + .set_parent = sprd_mux_set_parent, + .determine_rate = __clk_mux_determine_rate, +}; +EXPORT_SYMBOL_GPL(sprd_mux_ops); diff --git a/drivers/clk/sprd/mux.h b/drivers/clk/sprd/mux.h new file mode 100644 index 0000000..148ca8c --- /dev/null +++ b/drivers/clk/sprd/mux.h @@ -0,0 +1,65 @@ +/* + * Spreadtrum multiplexer clock driver + * + * Copyright (C) 2017 Spreadtrum, Inc. + * Author: Chunyan Zhang + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef _SPRD_MUX_H_ +#define _SPRD_MUX_H_ + +#include "common.h" + +struct sprd_mux_internal { + u8 shift; + u8 width; + const u8 *table; +}; + +struct sprd_mux { + struct sprd_mux_internal mux; + struct sprd_clk_common common; +}; + +#define _SPRD_MUX_CLK(_shift, _width, _table) \ + { \ + .shift = _shift, \ + .width = _width, \ + .table = _table, \ + } + +#define SPRD_MUX_CLK(_struct, _name, _parents, _table, \ + _reg, _shift, _width, \ + _flags) \ + struct sprd_mux _struct = { \ + .mux = _SPRD_MUX_CLK(_shift, _width, _table), \ + .common = { \ + .regmap = NULL, \ + .reg = _reg, \ + .lock = &sprd_mux_lock, \ + .hw.init = CLK_HW_INIT_PARENTS(_name, \ + _parents, \ + &sprd_mux_ops, \ + _flags), \ + } \ + } + +static inline struct sprd_mux *hw_to_sprd_mux(const struct clk_hw *hw) +{ + struct sprd_clk_common *common = hw_to_sprd_clk_common(hw); + + return container_of(common, struct sprd_mux, common); +} + +extern const struct clk_ops sprd_mux_ops; +extern spinlock_t sprd_mux_lock; + +u8 sprd_mux_helper_get_parent(const struct sprd_clk_common *common, + const struct sprd_mux_internal *mux); +int sprd_mux_helper_set_parent(const struct sprd_clk_common *common, + const struct sprd_mux_internal *mux, + u8 index); + +#endif /* _SPRD_MUX_H_ */ -- 2.7.4 From 1582932671022909347@xxx Thu Nov 02 05:57:12 +0000 2017 X-GM-THRID: 1582159648805349431 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread