From patchwork Thu Oct 25 16:11:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murali Karicheri X-Patchwork-Id: 1645751 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id B0BBC3FE1C for ; Thu, 25 Oct 2012 16:18:02 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TRQ5x-0001TX-1n; Thu, 25 Oct 2012 16:15:46 +0000 Received: from bear.ext.ti.com ([192.94.94.41]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TRQ2Z-0008OC-68 for linux-arm-kernel@lists.infradead.org; Thu, 25 Oct 2012 16:12:35 +0000 Received: from dlelxv30.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id q9PGC4aw031040; Thu, 25 Oct 2012 11:12:04 -0500 Received: from DLEE74.ent.ti.com (dlee74.ent.ti.com [157.170.170.8]) by dlelxv30.itg.ti.com (8.13.8/8.13.8) with ESMTP id q9PGC3WG015891; Thu, 25 Oct 2012 11:12:03 -0500 Received: from dlelxv22.itg.ti.com (172.17.1.197) by DLEE74.ent.ti.com (157.170.170.8) with Microsoft SMTP Server id 14.1.323.3; Thu, 25 Oct 2012 11:12:03 -0500 Received: from ares-ubuntu.am.dhcp.ti.com (ares-ubuntu.am.dhcp.ti.com [158.218.103.17]) by dlelxv22.itg.ti.com (8.13.8/8.13.8) with ESMTP id q9PGC1Sc005705; Thu, 25 Oct 2012 11:12:01 -0500 Received: from a0868495 by ares-ubuntu.am.dhcp.ti.com with local (Exim 4.76) (envelope-from ) id 1TRQ2K-00036Y-Eo; Thu, 25 Oct 2012 12:12:00 -0400 From: Murali Karicheri To: , , , , , , , , , , , , , Subject: [PATCH v3 02/11] clk: davinci - add PSC clock driver Date: Thu, 25 Oct 2012 12:11:48 -0400 Message-ID: <1351181518-11882-3-git-send-email-m-karicheri2@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1351181518-11882-1-git-send-email-m-karicheri2@ti.com> References: <1351181518-11882-1-git-send-email-m-karicheri2@ti.com> MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -4.6 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [192.94.94.41 listed in list.dnswl.org] 3.0 KHOP_BIG_TO_CC Sent to 10+ recipients instaed of Bcc or a list -0.0 SPF_PASS SPF: sender matches SPF record -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Murali Karicheri , linux-keystone@list.ti.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This is the driver for the Power Sleep Controller (PSC) hardware found on DM SoCs as well Keystone SoCs (c6x). This driver borrowed code from arch/arm/mach-davinci/psc.c and implemented the driver as per common clock provider API. The PSC module is responsible for enabling/disabling the Power Domain and Clock domain for different IPs present in the SoC. The driver is configured through the clock data passed to the driver through struct clk_psc_data. Signed-off-by: Murali Karicheri Acked-by: Linus Walleij --- drivers/clk/davinci/clk-psc.c | 207 +++++++++++++++++++++++++++++++++++++++++ drivers/clk/davinci/clk-psc.h | 46 +++++++++ 2 files changed, 253 insertions(+) create mode 100644 drivers/clk/davinci/clk-psc.c create mode 100644 drivers/clk/davinci/clk-psc.h diff --git a/drivers/clk/davinci/clk-psc.c b/drivers/clk/davinci/clk-psc.c new file mode 100644 index 0000000..40d5f06 --- /dev/null +++ b/drivers/clk/davinci/clk-psc.c @@ -0,0 +1,207 @@ +/* + * PSC clk driver for DaVinci devices + * + * Copyright (C) 2006-2012 Texas Instruments. + * Copyright (C) 2008-2009 Deep Root Systems, LLC + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ +#include +#include +#include +#include +#include +#include + +#include "clk-psc.h" + +/* PSC register offsets */ +#define EPCPR 0x070 +#define PTCMD 0x120 +#define PTSTAT 0x128 +#define PDSTAT 0x200 +#define PDCTL 0x300 +#define MDSTAT 0x800 +#define MDCTL 0xA00 + +/* PSC module states */ +#define PSC_STATE_SWRSTDISABLE 0 +#define PSC_STATE_SYNCRST 1 +#define PSC_STATE_DISABLE 2 +#define PSC_STATE_ENABLE 3 + +#define MDSTAT_STATE_MASK 0x3f +#define PDSTAT_STATE_MASK 0x1f +#define MDCTL_FORCE BIT(31) +#define PDCTL_NEXT BIT(0) +#define PDCTL_EPCGOOD BIT(8) + +/** + * struct clk_psc - DaVinci PSC clock driver data + * + * @hw: clk_hw for the psc + * @psc_data: Driver specific data + */ +struct clk_psc { + struct clk_hw hw; + struct clk_psc_data *psc_data; + spinlock_t *lock; +}; + +#define to_clk_psc(_hw) container_of(_hw, struct clk_psc, hw) + +/** + * clk_psc_config() - configure psc hardware + * + * @base: io mapped base address of the psc + * @domain: Power Domain id of the module + * @id: lpsc id + * @enable: 1 - enable psc, 0 - disable psc + * @flags: psc driver specific flags + */ +static void clk_psc_config(void __iomem *base, unsigned int domain, + unsigned int id, bool enable, u32 flags) +{ + u32 epcpr, ptcmd, ptstat, pdstat, pdctl, mdstat, mdctl; + u32 next_state = PSC_STATE_ENABLE; + void __iomem *psc_base = base; + + if (!enable) { + if (flags & CLK_PSC_SWRSTDISABLE) + next_state = PSC_STATE_SWRSTDISABLE; + else + next_state = PSC_STATE_DISABLE; + } + + mdctl = readl(psc_base + MDCTL + 4 * id); + mdctl &= ~MDSTAT_STATE_MASK; + mdctl |= next_state; + if (flags & CLK_PSC_FORCE) + mdctl |= MDCTL_FORCE; + writel(mdctl, psc_base + MDCTL + 4 * id); + + pdstat = readl(psc_base + PDSTAT + 4 * domain); + if ((pdstat & PDSTAT_STATE_MASK) == 0) { + pdctl = readl(psc_base + PDCTL + 4 * domain); + pdctl |= PDCTL_NEXT; + writel(pdctl, psc_base + PDCTL + 4 * domain); + + ptcmd = 1 << domain; + writel(ptcmd, psc_base + PTCMD); + + if (flags & CLK_PSC_HAS_EXT_POWER_CNTL) { + do { + epcpr = readl(psc_base + EPCPR); + } while ((((epcpr >> domain) & 1) == 0)); + } + + pdctl = readl(psc_base + PDCTL + 4 * domain); + pdctl |= 0x100; + writel(pdctl, psc_base + PDCTL + 4 * domain); + + pdctl = readl(psc_base + PDCTL + 4 * domain); + pdctl |= PDCTL_EPCGOOD; + writel(pdctl, psc_base + PDCTL + 4 * domain); + } else { + ptcmd = 1 << domain; + writel(ptcmd, psc_base + PTCMD); + } + + do { + ptstat = readl(psc_base + PTSTAT); + } while (!(((ptstat >> domain) & 1) == 0)); + + do { + mdstat = readl(psc_base + MDSTAT + 4 * id); + } while (!((mdstat & MDSTAT_STATE_MASK) == next_state)); +} + +/** + * clk_psc_is_enabled() - Is psc clock enabled + * + * @hw: clk hw for the psc + */ +static int clk_psc_is_enabled(struct clk_hw *hw) +{ + struct clk_psc *psc = to_clk_psc(hw); + struct clk_psc_data *psc_data = psc->psc_data; + u32 mdstat; + + mdstat = readl(psc_data->reg_base + MDSTAT + 4 * psc_data->lpsc_id); + + /* if clocked, state can be "Enable" or "SyncReset" */ + return (mdstat & BIT(12)) ? 1 : 0; +} + +/** + * clk_psc_enable() - Enable psc clock + * + * @hw: clk hw for the psc + */ +static int clk_psc_enable(struct clk_hw *hw) +{ + struct clk_psc *psc = to_clk_psc(hw); + struct clk_psc_data *psc_data = psc->psc_data; + + clk_psc_config(psc_data->reg_base, psc_data->domain_id, + psc_data->lpsc_id, 1, psc_data->psc_flags); + return 0; +} + +/** + * clk_psc_disable() - disable psc clock + * + * @hw: clk hw for the psc + */ +static void clk_psc_disable(struct clk_hw *hw) +{ + struct clk_psc *psc = to_clk_psc(hw); + struct clk_psc_data *psc_data = psc->psc_data; + + clk_psc_config(psc_data->reg_base, psc_data->domain_id, + psc_data->lpsc_id, 0, psc_data->psc_flags); +} + +static const struct clk_ops clk_psc_ops = { + .enable = clk_psc_enable, + .disable = clk_psc_disable, + .is_enabled = clk_psc_is_enabled, +}; + +/** + * clk_register_davinci_psc() - register function for DaVinci PSC clock + * + * @dev: clk device + * @name: name of the clock + * @parent_name: name of the parent clock + * @psc_data: ptr to psc clk data + */ +struct clk *clk_register_davinci_psc(struct device *dev, const char *name, + const char *parent_name, struct clk_psc_data *psc_data) +{ + struct clk_init_data init; + struct clk_psc *psc; + struct clk *clk; + + psc = kzalloc(sizeof(*psc), GFP_KERNEL); + if (!psc) + return ERR_PTR(-ENOMEM); + + init.name = name; + init.ops = &clk_psc_ops; + init.flags = psc_data->flags; + init.parent_names = (parent_name ? &parent_name : NULL); + init.num_parents = (parent_name ? 1 : 0); + + psc->psc_data = psc_data; + psc->hw.init = &init; + + clk = clk_register(NULL, &psc->hw); + if (IS_ERR(clk)) + kfree(psc); + + return clk; +} diff --git a/drivers/clk/davinci/clk-psc.h b/drivers/clk/davinci/clk-psc.h new file mode 100644 index 0000000..26327d6 --- /dev/null +++ b/drivers/clk/davinci/clk-psc.h @@ -0,0 +1,46 @@ +/* + * PSC clk driver for DaVinci devices + * + * Copyright (C) 2006-2012 Texas Instruments. + * Copyright (C) 2008-2009 Deep Root Systems, LLC + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ +#ifndef __CLK_DAVINCI_PSC_H +#define __CLK_DAVINCI_PSC_H + +/* PSC flags */ + +/* Disable state is SwRstDisable */ +#define CLK_PSC_SWRSTDISABLE BIT(0) +/* Force module state transtition */ +#define CLK_PSC_FORCE BIT(1) +/* PSC has external power control available (for DM6446 SoC) */ +#define CLK_PSC_HAS_EXT_POWER_CNTL BIT(2) + +/** + * struct clk_psc_data - configuration for DaVinci psc clk driver + * + * @reg_base: io mapped address of psc register base + * @flags: clk driver base flags + * @psc_flags: clk_psc driver flags + * @lpsc_id: local power sleep controller id + * @gpsc_id: global power sleep controller id + * @domain_id: Power domain id + */ +struct clk_psc_data { + void __iomem *reg_base; + u32 flags; + u32 psc_flags; + u8 lpsc_id; + u8 gpsc_id; + u8 domain_id; +}; + +struct clk *clk_register_davinci_psc(struct device *dev, + const char *name, const char *parent_name, + struct clk_psc_data *psc_data); +#endif /* __CLK_DAVINCI_PSC_H */