Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 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 | |
Mac Lin | 38e64ba | 2010-11-23 00:32:43 +0800 | [diff] [blame] | 9 | #include <linux/init.h> |
| 10 | #include <linux/module.h> |
Anton Vorontsov | 6eb5d14 | 2010-06-02 14:12:08 +0400 | [diff] [blame] | 11 | #include <linux/io.h> |
Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 12 | #include <linux/delay.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 13 | #include <linux/atomic.h> |
Arnd Bergmann | 3f9fb2a | 2013-03-13 13:15:25 +0100 | [diff] [blame] | 14 | #include "cns3xxx.h" |
| 15 | #include "pm.h" |
Russell King | 3921470 | 2011-11-05 15:32:23 +0000 | [diff] [blame] | 16 | #include "core.h" |
Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 17 | |
| 18 | void cns3xxx_pwr_clk_en(unsigned int block) |
| 19 | { |
Anton Vorontsov | 6eb5d14 | 2010-06-02 14:12:08 +0400 | [diff] [blame] | 20 | u32 reg = __raw_readl(PM_CLK_GATE_REG); |
| 21 | |
| 22 | reg |= (block & PM_CLK_GATE_REG_MASK); |
| 23 | __raw_writel(reg, PM_CLK_GATE_REG); |
Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 24 | } |
Mac Lin | 38e64ba | 2010-11-23 00:32:43 +0800 | [diff] [blame] | 25 | EXPORT_SYMBOL(cns3xxx_pwr_clk_en); |
| 26 | |
| 27 | void cns3xxx_pwr_clk_dis(unsigned int block) |
| 28 | { |
| 29 | u32 reg = __raw_readl(PM_CLK_GATE_REG); |
| 30 | |
| 31 | reg &= ~(block & PM_CLK_GATE_REG_MASK); |
| 32 | __raw_writel(reg, PM_CLK_GATE_REG); |
| 33 | } |
| 34 | EXPORT_SYMBOL(cns3xxx_pwr_clk_dis); |
Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 35 | |
| 36 | void cns3xxx_pwr_power_up(unsigned int block) |
| 37 | { |
Anton Vorontsov | 6eb5d14 | 2010-06-02 14:12:08 +0400 | [diff] [blame] | 38 | u32 reg = __raw_readl(PM_PLL_HM_PD_CTRL_REG); |
| 39 | |
| 40 | reg &= ~(block & CNS3XXX_PWR_PLL_ALL); |
| 41 | __raw_writel(reg, PM_PLL_HM_PD_CTRL_REG); |
Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 42 | |
| 43 | /* Wait for 300us for the PLL output clock locked. */ |
| 44 | udelay(300); |
| 45 | }; |
Mac Lin | 38e64ba | 2010-11-23 00:32:43 +0800 | [diff] [blame] | 46 | EXPORT_SYMBOL(cns3xxx_pwr_power_up); |
Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 47 | |
| 48 | void cns3xxx_pwr_power_down(unsigned int block) |
| 49 | { |
Anton Vorontsov | 6eb5d14 | 2010-06-02 14:12:08 +0400 | [diff] [blame] | 50 | u32 reg = __raw_readl(PM_PLL_HM_PD_CTRL_REG); |
| 51 | |
Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 52 | /* write '1' to power down */ |
Anton Vorontsov | 6eb5d14 | 2010-06-02 14:12:08 +0400 | [diff] [blame] | 53 | reg |= (block & CNS3XXX_PWR_PLL_ALL); |
| 54 | __raw_writel(reg, PM_PLL_HM_PD_CTRL_REG); |
Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 55 | }; |
Mac Lin | 38e64ba | 2010-11-23 00:32:43 +0800 | [diff] [blame] | 56 | EXPORT_SYMBOL(cns3xxx_pwr_power_down); |
Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 57 | |
| 58 | static void cns3xxx_pwr_soft_rst_force(unsigned int block) |
| 59 | { |
Anton Vorontsov | 6eb5d14 | 2010-06-02 14:12:08 +0400 | [diff] [blame] | 60 | u32 reg = __raw_readl(PM_SOFT_RST_REG); |
| 61 | |
Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 62 | /* |
| 63 | * bit 0, 28, 29 => program low to reset, |
| 64 | * the other else program low and then high |
| 65 | */ |
| 66 | if (block & 0x30000001) { |
Anton Vorontsov | 6eb5d14 | 2010-06-02 14:12:08 +0400 | [diff] [blame] | 67 | reg &= ~(block & PM_SOFT_RST_REG_MASK); |
Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 68 | } else { |
Anton Vorontsov | 6eb5d14 | 2010-06-02 14:12:08 +0400 | [diff] [blame] | 69 | reg &= ~(block & PM_SOFT_RST_REG_MASK); |
Anton Vorontsov | df8f4d2 | 2010-11-26 20:48:35 +0300 | [diff] [blame] | 70 | __raw_writel(reg, PM_SOFT_RST_REG); |
Anton Vorontsov | 6eb5d14 | 2010-06-02 14:12:08 +0400 | [diff] [blame] | 71 | reg |= (block & PM_SOFT_RST_REG_MASK); |
Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 72 | } |
Anton Vorontsov | 6eb5d14 | 2010-06-02 14:12:08 +0400 | [diff] [blame] | 73 | |
| 74 | __raw_writel(reg, PM_SOFT_RST_REG); |
Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void 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 Lin | 38e64ba | 2010-11-23 00:32:43 +0800 | [diff] [blame] | 89 | EXPORT_SYMBOL(cns3xxx_pwr_soft_rst); |
Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 90 | |
Robin Holt | 7b6d864 | 2013-07-08 16:01:40 -0700 | [diff] [blame] | 91 | void cns3xxx_restart(enum reboot_mode mode, const char *cmd) |
Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 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 | */ |
| 106 | int cns3xxx_cpu_clock(void) |
| 107 | { |
Anton Vorontsov | 6eb5d14 | 2010-06-02 14:12:08 +0400 | [diff] [blame] | 108 | u32 reg = __raw_readl(PM_CLK_CTRL_REG); |
Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 109 | int cpu; |
| 110 | int cpu_sel; |
| 111 | int div_sel; |
| 112 | |
Anton Vorontsov | 6eb5d14 | 2010-06-02 14:12:08 +0400 | [diff] [blame] | 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; |
Anton Vorontsov | d94f944 | 2010-03-25 17:12:41 +0300 | [diff] [blame] | 115 | |
| 116 | cpu = (300 + ((cpu_sel / 3) * 100) + ((cpu_sel % 3) * 33)) >> div_sel; |
| 117 | |
| 118 | return cpu; |
| 119 | } |
Mac Lin | 38e64ba | 2010-11-23 00:32:43 +0800 | [diff] [blame] | 120 | EXPORT_SYMBOL(cns3xxx_cpu_clock); |
Mac Lin | cf36797 | 2010-11-23 00:32:44 +0800 | [diff] [blame] | 121 | |
| 122 | atomic_t usb_pwr_ref = ATOMIC_INIT(0); |
| 123 | EXPORT_SYMBOL(usb_pwr_ref); |