psc.c 3.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * TI DaVinci Power and Sleep Controller (PSC)
 *
 * Copyright (C) 2006 Texas Instruments.
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */
#include <linux/kernel.h>
#include <linux/init.h>
23
#include <linux/io.h>
24

25
#include <mach/cputype.h>
26
#include <mach/psc.h>
27

28 29 30 31 32 33 34 35
/* PSC register offsets */
#define EPCPR		0x070
#define PTCMD		0x120
#define PTSTAT		0x128
#define PDSTAT		0x200
#define PDCTL1		0x304
#define MDSTAT		0x800
#define MDCTL		0xA00
36

37
#define MDSTAT_STATE_MASK 0x1f
38

39
/* Return nonzero iff the domain's clock is active */
40
int __init davinci_psc_is_clk_active(unsigned int ctlr, unsigned int id)
41
{
42 43 44 45 46 47 48 49 50 51 52 53
	void __iomem *psc_base;
	u32 mdstat;
	struct davinci_soc_info *soc_info = &davinci_soc_info;

	if (!soc_info->psc_bases || (ctlr >= soc_info->psc_bases_num)) {
		pr_warning("PSC: Bad psc data: 0x%x[%d]\n",
				(int)soc_info->psc_bases, ctlr);
		return 0;
	}

	psc_base = soc_info->psc_bases[ctlr];
	mdstat = __raw_readl(psc_base + MDSTAT + 4 * id);
54 55 56

	/* if clocked, state can be "Enable" or "SyncReset" */
	return mdstat & BIT(12);
57 58 59
}

/* Enable or disable a PSC domain */
60 61
void davinci_psc_config(unsigned int domain, unsigned int ctlr,
		unsigned int id, char enable)
62
{
63
	u32 epcpr, ptcmd, ptstat, pdstat, pdctl1, mdstat, mdctl;
64 65
	void __iomem *psc_base;
	struct davinci_soc_info *soc_info = &davinci_soc_info;
66
	u32 next_state = enable ? 0x3 : 0x2; /* 0x3 enables, 0x2 disables */
67

68 69 70 71 72 73 74 75
	if (!soc_info->psc_bases || (ctlr >= soc_info->psc_bases_num)) {
		pr_warning("PSC: Bad psc data: 0x%x[%d]\n",
				(int)soc_info->psc_bases, ctlr);
		return;
	}

	psc_base = soc_info->psc_bases[ctlr];

76
	mdctl = __raw_readl(psc_base + MDCTL + 4 * id);
77 78
	mdctl &= ~MDSTAT_STATE_MASK;
	mdctl |= next_state;
79
	__raw_writel(mdctl, psc_base + MDCTL + 4 * id);
80

81
	pdstat = __raw_readl(psc_base + PDSTAT);
82
	if ((pdstat & 0x00000001) == 0) {
83
		pdctl1 = __raw_readl(psc_base + PDCTL1);
84
		pdctl1 |= 0x1;
85
		__raw_writel(pdctl1, psc_base + PDCTL1);
86 87

		ptcmd = 1 << domain;
88
		__raw_writel(ptcmd, psc_base + PTCMD);
89

90
		do {
91
			epcpr = __raw_readl(psc_base + EPCPR);
92
		} while ((((epcpr >> domain) & 1) == 0));
93

94
		pdctl1 = __raw_readl(psc_base + PDCTL1);
95
		pdctl1 |= 0x100;
96
		__raw_writel(pdctl1, psc_base + PDCTL1);
97 98

		do {
99
			ptstat = __raw_readl(psc_base +
100 101
					       PTSTAT);
		} while (!(((ptstat >> domain) & 1) == 0));
102
	} else {
103
		ptcmd = 1 << domain;
104
		__raw_writel(ptcmd, psc_base + PTCMD);
105 106

		do {
107
			ptstat = __raw_readl(psc_base + PTSTAT);
108
		} while (!(((ptstat >> domain) & 1) == 0));
109 110
	}

111
	do {
112
		mdstat = __raw_readl(psc_base + MDSTAT + 4 * id);
113
	} while (!((mdstat & MDSTAT_STATE_MASK) == next_state));
114
}