blob: c047c1a2bc2a516023137a7fd5d324a9cb3f0067 [file] [log] [blame]
Anton Vorontsovd94f9442010-03-25 17:12:41 +03001/*
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
Mac Lin38e64ba2010-11-23 00:32:43 +08009#include <linux/init.h>
10#include <linux/module.h>
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040011#include <linux/io.h>
Anton Vorontsovd94f9442010-03-25 17:12:41 +030012#include <linux/delay.h>
13#include <mach/system.h>
14#include <mach/cns3xxx.h>
Mac Lin38e64ba2010-11-23 00:32:43 +080015#include <mach/pm.h>
Anton Vorontsovd94f9442010-03-25 17:12:41 +030016
17void cns3xxx_pwr_clk_en(unsigned int block)
18{
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040019 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);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030023}
Mac Lin38e64ba2010-11-23 00:32:43 +080024EXPORT_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);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030034
35void cns3xxx_pwr_power_up(unsigned int block)
36{
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040037 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);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030041
42 /* Wait for 300us for the PLL output clock locked. */
43 udelay(300);
44};
Mac Lin38e64ba2010-11-23 00:32:43 +080045EXPORT_SYMBOL(cns3xxx_pwr_power_up);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030046
47void cns3xxx_pwr_power_down(unsigned int block)
48{
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040049 u32 reg = __raw_readl(PM_PLL_HM_PD_CTRL_REG);
50
Anton Vorontsovd94f9442010-03-25 17:12:41 +030051 /* write '1' to power down */
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040052 reg |= (block & CNS3XXX_PWR_PLL_ALL);
53 __raw_writel(reg, PM_PLL_HM_PD_CTRL_REG);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030054};
Mac Lin38e64ba2010-11-23 00:32:43 +080055EXPORT_SYMBOL(cns3xxx_pwr_power_down);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030056
57static void cns3xxx_pwr_soft_rst_force(unsigned int block)
58{
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040059 u32 reg = __raw_readl(PM_SOFT_RST_REG);
60
Anton Vorontsovd94f9442010-03-25 17:12:41 +030061 /*
62 * bit 0, 28, 29 => program low to reset,
63 * the other else program low and then high
64 */
65 if (block & 0x30000001) {
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040066 reg &= ~(block & PM_SOFT_RST_REG_MASK);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030067 } else {
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040068 reg &= ~(block & PM_SOFT_RST_REG_MASK);
Anton Vorontsovdf8f4d22010-11-26 20:48:35 +030069 __raw_writel(reg, PM_SOFT_RST_REG);
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040070 reg |= (block & PM_SOFT_RST_REG_MASK);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030071 }
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040072
73 __raw_writel(reg, PM_SOFT_RST_REG);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030074}
Mac Lin38e64ba2010-11-23 00:32:43 +080075EXPORT_SYMBOL(cns3xxx_pwr_soft_rst_force);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030076
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}
Mac Lin38e64ba2010-11-23 00:32:43 +080089EXPORT_SYMBOL(cns3xxx_pwr_soft_rst);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030090
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{
Anton Vorontsov6eb5d142010-06-02 14:12:08 +0400108 u32 reg = __raw_readl(PM_CLK_CTRL_REG);
Anton Vorontsovd94f9442010-03-25 17:12:41 +0300109 int cpu;
110 int cpu_sel;
111 int div_sel;
112
Anton Vorontsov6eb5d142010-06-02 14:12:08 +0400113 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;
Anton Vorontsovd94f9442010-03-25 17:12:41 +0300115
116 cpu = (300 + ((cpu_sel / 3) * 100) + ((cpu_sel % 3) * 33)) >> div_sel;
117
118 return cpu;
119}
Mac Lin38e64ba2010-11-23 00:32:43 +0800120EXPORT_SYMBOL(cns3xxx_cpu_clock);