blob: dfccabbd959985f431086b1c914bf9ca2bf27b55 [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
Anton Vorontsov6eb5d142010-06-02 14:12:08 +04009#include <linux/io.h>
Anton Vorontsovd94f9442010-03-25 17:12:41 +030010#include <linux/delay.h>
11#include <mach/system.h>
12#include <mach/cns3xxx.h>
13
14void cns3xxx_pwr_clk_en(unsigned int block)
15{
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040016 u32 reg = __raw_readl(PM_CLK_GATE_REG);
17
18 reg |= (block & PM_CLK_GATE_REG_MASK);
19 __raw_writel(reg, PM_CLK_GATE_REG);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030020}
21
22void cns3xxx_pwr_power_up(unsigned int block)
23{
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040024 u32 reg = __raw_readl(PM_PLL_HM_PD_CTRL_REG);
25
26 reg &= ~(block & CNS3XXX_PWR_PLL_ALL);
27 __raw_writel(reg, PM_PLL_HM_PD_CTRL_REG);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030028
29 /* Wait for 300us for the PLL output clock locked. */
30 udelay(300);
31};
32
33void cns3xxx_pwr_power_down(unsigned int block)
34{
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040035 u32 reg = __raw_readl(PM_PLL_HM_PD_CTRL_REG);
36
Anton Vorontsovd94f9442010-03-25 17:12:41 +030037 /* write '1' to power down */
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040038 reg |= (block & CNS3XXX_PWR_PLL_ALL);
39 __raw_writel(reg, PM_PLL_HM_PD_CTRL_REG);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030040};
41
42static void cns3xxx_pwr_soft_rst_force(unsigned int block)
43{
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040044 u32 reg = __raw_readl(PM_SOFT_RST_REG);
45
Anton Vorontsovd94f9442010-03-25 17:12:41 +030046 /*
47 * bit 0, 28, 29 => program low to reset,
48 * the other else program low and then high
49 */
50 if (block & 0x30000001) {
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040051 reg &= ~(block & PM_SOFT_RST_REG_MASK);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030052 } else {
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040053 reg &= ~(block & PM_SOFT_RST_REG_MASK);
Anton Vorontsovdf8f4d22010-11-26 20:48:35 +030054 __raw_writel(reg, PM_SOFT_RST_REG);
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040055 reg |= (block & PM_SOFT_RST_REG_MASK);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030056 }
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040057
58 __raw_writel(reg, PM_SOFT_RST_REG);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030059}
60
61void cns3xxx_pwr_soft_rst(unsigned int block)
62{
63 static unsigned int soft_reset;
64
65 if (soft_reset & block) {
66 /* SPI/I2C/GPIO use the same block, reset once. */
67 return;
68 } else {
69 soft_reset |= block;
70 }
71 cns3xxx_pwr_soft_rst_force(block);
72}
73
74void arch_reset(char mode, const char *cmd)
75{
76 /*
77 * To reset, we hit the on-board reset register
78 * in the system FPGA.
79 */
80 cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(GLOBAL));
81}
82
83/*
84 * cns3xxx_cpu_clock - return CPU/L2 clock
85 * aclk: cpu clock/2
86 * hclk: cpu clock/4
87 * pclk: cpu clock/8
88 */
89int cns3xxx_cpu_clock(void)
90{
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040091 u32 reg = __raw_readl(PM_CLK_CTRL_REG);
Anton Vorontsovd94f9442010-03-25 17:12:41 +030092 int cpu;
93 int cpu_sel;
94 int div_sel;
95
Anton Vorontsov6eb5d142010-06-02 14:12:08 +040096 cpu_sel = (reg >> PM_CLK_CTRL_REG_OFFSET_PLL_CPU_SEL) & 0xf;
97 div_sel = (reg >> PM_CLK_CTRL_REG_OFFSET_CPU_CLK_DIV) & 0x3;
Anton Vorontsovd94f9442010-03-25 17:12:41 +030098
99 cpu = (300 + ((cpu_sel / 3) * 100) + ((cpu_sel % 3) * 33)) >> div_sel;
100
101 return cpu;
102}