arm64: dts: Revert "specify console via command line"
[linux/fpc-iii.git] / arch / arm / mach-cns3xxx / pm.c
blob72e8a7ec7a38c393bcdda4f30eec3f407891d344
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright 2008 Cavium Networks
4 */
6 #include <linux/init.h>
7 #include <linux/module.h>
8 #include <linux/io.h>
9 #include <linux/delay.h>
10 #include <linux/atomic.h>
11 #include "cns3xxx.h"
12 #include "pm.h"
13 #include "core.h"
15 void cns3xxx_pwr_clk_en(unsigned int block)
17 u32 reg = __raw_readl(PM_CLK_GATE_REG);
19 reg |= (block & PM_CLK_GATE_REG_MASK);
20 __raw_writel(reg, PM_CLK_GATE_REG);
22 EXPORT_SYMBOL(cns3xxx_pwr_clk_en);
24 void cns3xxx_pwr_clk_dis(unsigned int block)
26 u32 reg = __raw_readl(PM_CLK_GATE_REG);
28 reg &= ~(block & PM_CLK_GATE_REG_MASK);
29 __raw_writel(reg, PM_CLK_GATE_REG);
31 EXPORT_SYMBOL(cns3xxx_pwr_clk_dis);
33 void cns3xxx_pwr_power_up(unsigned int block)
35 u32 reg = __raw_readl(PM_PLL_HM_PD_CTRL_REG);
37 reg &= ~(block & CNS3XXX_PWR_PLL_ALL);
38 __raw_writel(reg, PM_PLL_HM_PD_CTRL_REG);
40 /* Wait for 300us for the PLL output clock locked. */
41 udelay(300);
43 EXPORT_SYMBOL(cns3xxx_pwr_power_up);
45 void cns3xxx_pwr_power_down(unsigned int block)
47 u32 reg = __raw_readl(PM_PLL_HM_PD_CTRL_REG);
49 /* write '1' to power down */
50 reg |= (block & CNS3XXX_PWR_PLL_ALL);
51 __raw_writel(reg, PM_PLL_HM_PD_CTRL_REG);
53 EXPORT_SYMBOL(cns3xxx_pwr_power_down);
55 static void cns3xxx_pwr_soft_rst_force(unsigned int block)
57 u32 reg = __raw_readl(PM_SOFT_RST_REG);
60 * bit 0, 28, 29 => program low to reset,
61 * the other else program low and then high
63 if (block & 0x30000001) {
64 reg &= ~(block & PM_SOFT_RST_REG_MASK);
65 } else {
66 reg &= ~(block & PM_SOFT_RST_REG_MASK);
67 __raw_writel(reg, PM_SOFT_RST_REG);
68 reg |= (block & PM_SOFT_RST_REG_MASK);
71 __raw_writel(reg, PM_SOFT_RST_REG);
74 void cns3xxx_pwr_soft_rst(unsigned int block)
76 static unsigned int soft_reset;
78 if (soft_reset & block) {
79 /* SPI/I2C/GPIO use the same block, reset once. */
80 return;
81 } else {
82 soft_reset |= block;
84 cns3xxx_pwr_soft_rst_force(block);
86 EXPORT_SYMBOL(cns3xxx_pwr_soft_rst);
88 void cns3xxx_restart(enum reboot_mode mode, const char *cmd)
91 * To reset, we hit the on-board reset register
92 * in the system FPGA.
94 cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(GLOBAL));
98 * cns3xxx_cpu_clock - return CPU/L2 clock
99 * aclk: cpu clock/2
100 * hclk: cpu clock/4
101 * pclk: cpu clock/8
103 int cns3xxx_cpu_clock(void)
105 u32 reg = __raw_readl(PM_CLK_CTRL_REG);
106 int cpu;
107 int cpu_sel;
108 int div_sel;
110 cpu_sel = (reg >> PM_CLK_CTRL_REG_OFFSET_PLL_CPU_SEL) & 0xf;
111 div_sel = (reg >> PM_CLK_CTRL_REG_OFFSET_CPU_CLK_DIV) & 0x3;
113 cpu = (300 + ((cpu_sel / 3) * 100) + ((cpu_sel % 3) * 33)) >> div_sel;
115 return cpu;
117 EXPORT_SYMBOL(cns3xxx_cpu_clock);
119 atomic_t usb_pwr_ref = ATOMIC_INIT(0);
120 EXPORT_SYMBOL(usb_pwr_ref);