pm.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. #include <linux/init.h>
  9. #include <linux/module.h>
  10. #include <linux/io.h>
  11. #include <linux/delay.h>
  12. #include <linux/atomic.h>
  13. #include "cns3xxx.h"
  14. #include "pm.h"
  15. #include "core.h"
  16. void cns3xxx_pwr_clk_en(unsigned int block)
  17. {
  18. u32 reg = __raw_readl(PM_CLK_GATE_REG);
  19. reg |= (block & PM_CLK_GATE_REG_MASK);
  20. __raw_writel(reg, PM_CLK_GATE_REG);
  21. }
  22. EXPORT_SYMBOL(cns3xxx_pwr_clk_en);
  23. void cns3xxx_pwr_clk_dis(unsigned int block)
  24. {
  25. u32 reg = __raw_readl(PM_CLK_GATE_REG);
  26. reg &= ~(block & PM_CLK_GATE_REG_MASK);
  27. __raw_writel(reg, PM_CLK_GATE_REG);
  28. }
  29. EXPORT_SYMBOL(cns3xxx_pwr_clk_dis);
  30. void cns3xxx_pwr_power_up(unsigned int block)
  31. {
  32. u32 reg = __raw_readl(PM_PLL_HM_PD_CTRL_REG);
  33. reg &= ~(block & CNS3XXX_PWR_PLL_ALL);
  34. __raw_writel(reg, PM_PLL_HM_PD_CTRL_REG);
  35. /* Wait for 300us for the PLL output clock locked. */
  36. udelay(300);
  37. };
  38. EXPORT_SYMBOL(cns3xxx_pwr_power_up);
  39. void cns3xxx_pwr_power_down(unsigned int block)
  40. {
  41. u32 reg = __raw_readl(PM_PLL_HM_PD_CTRL_REG);
  42. /* write '1' to power down */
  43. reg |= (block & CNS3XXX_PWR_PLL_ALL);
  44. __raw_writel(reg, PM_PLL_HM_PD_CTRL_REG);
  45. };
  46. EXPORT_SYMBOL(cns3xxx_pwr_power_down);
  47. static void cns3xxx_pwr_soft_rst_force(unsigned int block)
  48. {
  49. u32 reg = __raw_readl(PM_SOFT_RST_REG);
  50. /*
  51. * bit 0, 28, 29 => program low to reset,
  52. * the other else program low and then high
  53. */
  54. if (block & 0x30000001) {
  55. reg &= ~(block & PM_SOFT_RST_REG_MASK);
  56. } else {
  57. reg &= ~(block & PM_SOFT_RST_REG_MASK);
  58. __raw_writel(reg, PM_SOFT_RST_REG);
  59. reg |= (block & PM_SOFT_RST_REG_MASK);
  60. }
  61. __raw_writel(reg, PM_SOFT_RST_REG);
  62. }
  63. void cns3xxx_pwr_soft_rst(unsigned int block)
  64. {
  65. static unsigned int soft_reset;
  66. if (soft_reset & block) {
  67. /* SPI/I2C/GPIO use the same block, reset once. */
  68. return;
  69. } else {
  70. soft_reset |= block;
  71. }
  72. cns3xxx_pwr_soft_rst_force(block);
  73. }
  74. EXPORT_SYMBOL(cns3xxx_pwr_soft_rst);
  75. void cns3xxx_restart(enum reboot_mode mode, const char *cmd)
  76. {
  77. /*
  78. * To reset, we hit the on-board reset register
  79. * in the system FPGA.
  80. */
  81. cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(GLOBAL));
  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. */
  89. int cns3xxx_cpu_clock(void)
  90. {
  91. u32 reg = __raw_readl(PM_CLK_CTRL_REG);
  92. int cpu;
  93. int cpu_sel;
  94. int div_sel;
  95. cpu_sel = (reg >> PM_CLK_CTRL_REG_OFFSET_PLL_CPU_SEL) & 0xf;
  96. div_sel = (reg >> PM_CLK_CTRL_REG_OFFSET_CPU_CLK_DIV) & 0x3;
  97. cpu = (300 + ((cpu_sel / 3) * 100) + ((cpu_sel % 3) * 33)) >> div_sel;
  98. return cpu;
  99. }
  100. EXPORT_SYMBOL(cns3xxx_cpu_clock);
  101. atomic_t usb_pwr_ref = ATOMIC_INIT(0);
  102. EXPORT_SYMBOL(usb_pwr_ref);