ARM: cns3xxx: Add new and export the old power management functions
[deliverable/linux.git] / arch / arm / mach-cns3xxx / pm.c
CommitLineData
d94f944e
AV
1/*
2 * Copyright 2008 Cavium Networks
3 *
4 * This file is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, Version 2, as
6 * published by the Free Software Foundation.
7 */
8
38e64ba0
ML
9#include <linux/init.h>
10#include <linux/module.h>
6eb5d146 11#include <linux/io.h>
d94f944e
AV
12#include <linux/delay.h>
13#include <mach/system.h>
14#include <mach/cns3xxx.h>
38e64ba0 15#include <mach/pm.h>
d94f944e
AV
16
17void cns3xxx_pwr_clk_en(unsigned int block)
18{
6eb5d146
AV
19 u32 reg = __raw_readl(PM_CLK_GATE_REG);
20
21 reg |= (block & PM_CLK_GATE_REG_MASK);
22 __raw_writel(reg, PM_CLK_GATE_REG);
d94f944e 23}
38e64ba0
ML
24EXPORT_SYMBOL(cns3xxx_pwr_clk_en);
25
26void cns3xxx_pwr_clk_dis(unsigned int block)
27{
28 u32 reg = __raw_readl(PM_CLK_GATE_REG);
29
30 reg &= ~(block & PM_CLK_GATE_REG_MASK);
31 __raw_writel(reg, PM_CLK_GATE_REG);
32}
33EXPORT_SYMBOL(cns3xxx_pwr_clk_dis);
d94f944e
AV
34
35void cns3xxx_pwr_power_up(unsigned int block)
36{
6eb5d146
AV
37 u32 reg = __raw_readl(PM_PLL_HM_PD_CTRL_REG);
38
39 reg &= ~(block & CNS3XXX_PWR_PLL_ALL);
40 __raw_writel(reg, PM_PLL_HM_PD_CTRL_REG);
d94f944e
AV
41
42 /* Wait for 300us for the PLL output clock locked. */
43 udelay(300);
44};
38e64ba0 45EXPORT_SYMBOL(cns3xxx_pwr_power_up);
d94f944e
AV
46
47void cns3xxx_pwr_power_down(unsigned int block)
48{
6eb5d146
AV
49 u32 reg = __raw_readl(PM_PLL_HM_PD_CTRL_REG);
50
d94f944e 51 /* write '1' to power down */
6eb5d146
AV
52 reg |= (block & CNS3XXX_PWR_PLL_ALL);
53 __raw_writel(reg, PM_PLL_HM_PD_CTRL_REG);
d94f944e 54};
38e64ba0 55EXPORT_SYMBOL(cns3xxx_pwr_power_down);
d94f944e
AV
56
57static void cns3xxx_pwr_soft_rst_force(unsigned int block)
58{
6eb5d146
AV
59 u32 reg = __raw_readl(PM_SOFT_RST_REG);
60
d94f944e
AV
61 /*
62 * bit 0, 28, 29 => program low to reset,
63 * the other else program low and then high
64 */
65 if (block & 0x30000001) {
6eb5d146 66 reg &= ~(block & PM_SOFT_RST_REG_MASK);
d94f944e 67 } else {
6eb5d146 68 reg &= ~(block & PM_SOFT_RST_REG_MASK);
df8f4d2f 69 __raw_writel(reg, PM_SOFT_RST_REG);
6eb5d146 70 reg |= (block & PM_SOFT_RST_REG_MASK);
d94f944e 71 }
6eb5d146
AV
72
73 __raw_writel(reg, PM_SOFT_RST_REG);
d94f944e 74}
38e64ba0 75EXPORT_SYMBOL(cns3xxx_pwr_soft_rst_force);
d94f944e
AV
76
77void cns3xxx_pwr_soft_rst(unsigned int block)
78{
79 static unsigned int soft_reset;
80
81 if (soft_reset & block) {
82 /* SPI/I2C/GPIO use the same block, reset once. */
83 return;
84 } else {
85 soft_reset |= block;
86 }
87 cns3xxx_pwr_soft_rst_force(block);
88}
38e64ba0 89EXPORT_SYMBOL(cns3xxx_pwr_soft_rst);
d94f944e
AV
90
91void arch_reset(char mode, const char *cmd)
92{
93 /*
94 * To reset, we hit the on-board reset register
95 * in the system FPGA.
96 */
97 cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(GLOBAL));
98}
99
100/*
101 * cns3xxx_cpu_clock - return CPU/L2 clock
102 * aclk: cpu clock/2
103 * hclk: cpu clock/4
104 * pclk: cpu clock/8
105 */
106int cns3xxx_cpu_clock(void)
107{
6eb5d146 108 u32 reg = __raw_readl(PM_CLK_CTRL_REG);
d94f944e
AV
109 int cpu;
110 int cpu_sel;
111 int div_sel;
112
6eb5d146
AV
113 cpu_sel = (reg >> PM_CLK_CTRL_REG_OFFSET_PLL_CPU_SEL) & 0xf;
114 div_sel = (reg >> PM_CLK_CTRL_REG_OFFSET_CPU_CLK_DIV) & 0x3;
d94f944e
AV
115
116 cpu = (300 + ((cpu_sel / 3) * 100) + ((cpu_sel % 3) * 33)) >> div_sel;
117
118 return cpu;
119}
38e64ba0 120EXPORT_SYMBOL(cns3xxx_cpu_clock);
This page took 0.061385 seconds and 5 git commands to generate.