From patchwork Wed Aug 31 21:26:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salter X-Patchwork-Id: 1117802 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7VLYArK007149 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 31 Aug 2011 21:34:31 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QysP6-0001hh-Oe; Wed, 31 Aug 2011 21:33:02 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QysP5-0000Dl-VJ; Wed, 31 Aug 2011 21:32:59 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QysKL-0007bq-8S for linux-arm-kernel@lists.infradead.org; Wed, 31 Aug 2011 21:28:32 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p7VLS3lI006549 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 31 Aug 2011 17:28:03 -0400 Received: from deneb.redhat.com (ovpn-113-34.phx2.redhat.com [10.3.113.34]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p7VLRlt2026590; Wed, 31 Aug 2011 17:28:02 -0400 From: Mark Salter To: linux-kernel@vger.kernel.org Subject: [PATCH 23/24] C6X: Power and Sleep Controller Date: Wed, 31 Aug 2011 17:26:58 -0400 Message-Id: <1314826019-22330-24-git-send-email-msalter@redhat.com> In-Reply-To: <1314826019-22330-1-git-send-email-msalter@redhat.com> References: <1314826019-22330-1-git-send-email-msalter@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110831_172805_786923_3CCB8F18 X-CRM114-Status: GOOD ( 21.00 ) X-Spam-Score: -5.5 (-----) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-5.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [209.132.183.28 listed in list.dnswl.org] -0.5 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: ming.lei@canonical.com, stern@rowland.harvard.edu, linux-arm-kernel@lists.infradead.org, Mark Salter X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 31 Aug 2011 21:34:31 +0000 (UTC) This patch provides support for the Power/Sleep controller found on some SoCs. The PSC controls two basic things: power domains and peripheral clock gating and resets. The device tree is parsed at setup_arch tree to find any PSC node. The number and controllability of the power domains and peripheral reset/gating varies quite a bit from SoC to SoC. This driver tries to encapsulate the common bits and provide an API for the SoC specific code to use. Signed-off-by: Mark Salter --- arch/c6x/platforms/psc.c | 181 ++++++++++++++++++++++++++++++++++++++++++++++ arch/c6x/platforms/psc.h | 25 +++++++ 2 files changed, 206 insertions(+), 0 deletions(-) create mode 100644 arch/c6x/platforms/psc.c create mode 100644 arch/c6x/platforms/psc.h diff --git a/arch/c6x/platforms/psc.c b/arch/c6x/platforms/psc.c new file mode 100644 index 0000000..c3fd52c --- /dev/null +++ b/arch/c6x/platforms/psc.c @@ -0,0 +1,181 @@ +/* + * Power/Sleep Controller + * + * Copyright (C) 2011 Texas Instruments Incorporated + * Author: Mark Salter + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#include +#include +#include +#include +#include +#include "psc.h" + +#define PSC_PTCMD 0x0120 +#define PSC_PTSTAT 0x0128 + +#define PSC_PDSTAT0 0x0200 +#define PSC_PDCTL0 0x0300 + +#define PSC_MDSTAT0 0x0800 +#define PSC_MDCTL0 0x0a00 + +#define PD_NEXT_DISABLE 2 +#define PD_NEXT_ENABLE 3 + +#define MD_NEXT_SWRST_DISABLE 0 +#define MD_NEXT_SYNCRST 1 +#define MD_NEXT_DISABLE 2 +#define MD_NEXT_ENABLE 3 +#define MD_NEXT_MASK 0x1f + +#define LRSTZ 0x100 + +struct psc_data { + u32 phys_base; + void __iomem *base; + int num_domains; + int num_modules; + u8 module_domains[MAX_PSC_MODULES]; +}; + +static struct psc_data psc; + +static inline void psc_write(int offset, unsigned int val) +{ + if (psc.base) + soc_writel(val, psc.base + offset); +} + +static inline unsigned int psc_read(int offset) +{ + if (!psc.base) + return 0; + return soc_readl(psc.base + offset); +} + +static void __wait_for_gostat(int domain_mask) +{ + while (psc_read(PSC_PTSTAT) & domain_mask) + ; +} + +void psc_domain_on(int domain) +{ + int reg = PSC_PDCTL0 + (domain * 4); + + if (domain < 0 || domain >= psc.num_domains) + return; + + __wait_for_gostat(1 << domain); + psc_write(reg, psc_read(reg) | 1); +} + +void psc_domain_off(int domain) +{ + int reg = PSC_PDCTL0 + (domain * 4); + + if (domain < 0 || domain >= psc.num_domains) + return; + + __wait_for_gostat(1 << domain); + psc_write(reg, psc_read(reg) & ~1); +} + +void psc_transition_domains(int domain_mask) +{ + domain_mask &= (1 << psc.num_domains) - 1; + if (domain_mask == 0) + return; + + __wait_for_gostat(domain_mask); + psc_write(PSC_PTCMD, domain_mask); +} + +void psc_module_on(int module) +{ + u32 reg, val; + + if (module < 0 || module >= psc.num_modules) + return; + + __wait_for_gostat(1 << psc.module_domains[module]); + + reg = PSC_MDCTL0 + (module * 4); + val = psc_read(reg) & ~MD_NEXT_MASK; + psc_write(reg, val | MD_NEXT_ENABLE); +} + +void psc_module_off(int module) +{ + u32 reg, val; + + if (module < 0 || module >= psc.num_modules) + return; + + __wait_for_gostat(1 << psc.module_domains[module]); + + reg = PSC_MDCTL0 + (module * 4); + val = psc_read(reg) & ~MD_NEXT_MASK; + psc_write(reg, val | MD_NEXT_DISABLE); +} + +void psc_module_reset(int module) +{ + int reg = PSC_MDCTL0 + module * 4; + + if (module < 0 || module >= psc.num_modules) + return; + + psc_write(reg, psc_read(reg) & ~LRSTZ); +} + +void psc_module_reset_release(int module) +{ + int reg = PSC_MDCTL0 + module * 4; + + if (module < 0 || module >= psc.num_modules) + return; + + psc_write(reg, psc_read(reg) | LRSTZ); +} + +void __init psc_init(void) +{ + struct device_node *node; + const __be32 *p; + int i, len; + + node = of_find_compatible_node(NULL, NULL, "ti,c64x+psc"); + if (!node) + return; + + psc.base = of_iomap(node, 0); + if (!psc.base) { + of_node_put(node); + return; + } + + p = of_get_property(node, "ti,number-psc-domains", &len); + if (p && len == sizeof(u32)) + psc.num_domains = be32_to_cpup(p); + + p = of_get_property(node, "ti,number-psc-modules", &len); + if (p && len == sizeof(u32)) + psc.num_modules = be32_to_cpup(p); + + p = of_get_property(node, "ti,module-domain-map", &len); + if (p) { + len /= sizeof(u32); + if (len > MAX_PSC_MODULES) + len = MAX_PSC_MODULES; + for (i = 0; i <= len; i++) + psc.module_domains[i] = be32_to_cpup(&p[i]); + } + + of_node_put(node); +} diff --git a/arch/c6x/platforms/psc.h b/arch/c6x/platforms/psc.h new file mode 100644 index 0000000..7f4bd1d --- /dev/null +++ b/arch/c6x/platforms/psc.h @@ -0,0 +1,25 @@ +/* + * C6X Power/Sleep Controller + * + * Copyright (C) 2011 Texas Instruments Incorporated + * Author: Mark Salter + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#ifndef _C6X_PSC_H +#define _C6X_PSC_H + +#define MAX_PSC_MODULES 16 + +extern void psc_init(void); +extern void psc_domain_on(int domain); +extern void psc_domain_off(int domain); +extern void psc_transition_domains(int domain_mask); +extern void psc_module_on(int module); +extern void psc_module_off(int module); +extern void psc_module_reset(int module); +extern void psc_module_reset_release(int module); + +#endif /* _C6X_PSC_H */