pm.c 2.7 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * Copyright 2008 Cavium Networks
 *
 * This file 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.
 */

9 10
#include <linux/init.h>
#include <linux/module.h>
11
#include <linux/io.h>
12 13 14
#include <linux/delay.h>
#include <mach/system.h>
#include <mach/cns3xxx.h>
15
#include <mach/pm.h>
16 17 18

void cns3xxx_pwr_clk_en(unsigned int block)
{
19 20 21 22
	u32 reg = __raw_readl(PM_CLK_GATE_REG);

	reg |= (block & PM_CLK_GATE_REG_MASK);
	__raw_writel(reg, PM_CLK_GATE_REG);
23
}
24 25 26 27 28 29 30 31 32 33
EXPORT_SYMBOL(cns3xxx_pwr_clk_en);

void cns3xxx_pwr_clk_dis(unsigned int block)
{
	u32 reg = __raw_readl(PM_CLK_GATE_REG);

	reg &= ~(block & PM_CLK_GATE_REG_MASK);
	__raw_writel(reg, PM_CLK_GATE_REG);
}
EXPORT_SYMBOL(cns3xxx_pwr_clk_dis);
34 35 36

void cns3xxx_pwr_power_up(unsigned int block)
{
37 38 39 40
	u32 reg = __raw_readl(PM_PLL_HM_PD_CTRL_REG);

	reg &= ~(block & CNS3XXX_PWR_PLL_ALL);
	__raw_writel(reg, PM_PLL_HM_PD_CTRL_REG);
41 42 43 44

	/* Wait for 300us for the PLL output clock locked. */
	udelay(300);
};
45
EXPORT_SYMBOL(cns3xxx_pwr_power_up);
46 47 48

void cns3xxx_pwr_power_down(unsigned int block)
{
49 50
	u32 reg = __raw_readl(PM_PLL_HM_PD_CTRL_REG);

51
	/* write '1' to power down */
52 53
	reg |= (block & CNS3XXX_PWR_PLL_ALL);
	__raw_writel(reg, PM_PLL_HM_PD_CTRL_REG);
54
};
55
EXPORT_SYMBOL(cns3xxx_pwr_power_down);
56 57 58

static void cns3xxx_pwr_soft_rst_force(unsigned int block)
{
59 60
	u32 reg = __raw_readl(PM_SOFT_RST_REG);

61 62 63 64 65
	/*
	 * bit 0, 28, 29 => program low to reset,
	 * the other else program low and then high
	 */
	if (block & 0x30000001) {
66
		reg &= ~(block & PM_SOFT_RST_REG_MASK);
67
	} else {
68
		reg &= ~(block & PM_SOFT_RST_REG_MASK);
69
		__raw_writel(reg, PM_SOFT_RST_REG);
70
		reg |= (block & PM_SOFT_RST_REG_MASK);
71
	}
72 73

	__raw_writel(reg, PM_SOFT_RST_REG);
74
}
75
EXPORT_SYMBOL(cns3xxx_pwr_soft_rst_force);
76 77 78 79 80 81 82 83 84 85 86 87 88

void cns3xxx_pwr_soft_rst(unsigned int block)
{
	static unsigned int soft_reset;

	if (soft_reset & block) {
		/* SPI/I2C/GPIO use the same block, reset once. */
		return;
	} else {
		soft_reset |= block;
	}
	cns3xxx_pwr_soft_rst_force(block);
}
89
EXPORT_SYMBOL(cns3xxx_pwr_soft_rst);
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

void arch_reset(char mode, const char *cmd)
{
	/*
	 * To reset, we hit the on-board reset register
	 * in the system FPGA.
	 */
	cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(GLOBAL));
}

/*
 * cns3xxx_cpu_clock - return CPU/L2 clock
 *  aclk: cpu clock/2
 *  hclk: cpu clock/4
 *  pclk: cpu clock/8
 */
int cns3xxx_cpu_clock(void)
{
108
	u32 reg = __raw_readl(PM_CLK_CTRL_REG);
109 110 111 112
	int cpu;
	int cpu_sel;
	int div_sel;

113 114
	cpu_sel = (reg >> PM_CLK_CTRL_REG_OFFSET_PLL_CPU_SEL) & 0xf;
	div_sel = (reg >> PM_CLK_CTRL_REG_OFFSET_CPU_CLK_DIV) & 0x3;
115 116 117 118 119

	cpu = (300 + ((cpu_sel / 3) * 100) + ((cpu_sel % 3) * 33)) >> div_sel;

	return cpu;
}
120
EXPORT_SYMBOL(cns3xxx_cpu_clock);