pm.c 2.2 KB

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