pm.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. reg |= (block & PM_SOFT_RST_REG_MASK);
  45. }
  46. __raw_writel(reg, PM_SOFT_RST_REG);
  47. }
  48. void cns3xxx_pwr_soft_rst(unsigned int block)
  49. {
  50. static unsigned int soft_reset;
  51. if (soft_reset & block) {
  52. /* SPI/I2C/GPIO use the same block, reset once. */
  53. return;
  54. } else {
  55. soft_reset |= block;
  56. }
  57. cns3xxx_pwr_soft_rst_force(block);
  58. }
  59. void arch_reset(char mode, const char *cmd)
  60. {
  61. /*
  62. * To reset, we hit the on-board reset register
  63. * in the system FPGA.
  64. */
  65. cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(GLOBAL));
  66. }
  67. /*
  68. * cns3xxx_cpu_clock - return CPU/L2 clock
  69. * aclk: cpu clock/2
  70. * hclk: cpu clock/4
  71. * pclk: cpu clock/8
  72. */
  73. int cns3xxx_cpu_clock(void)
  74. {
  75. u32 reg = __raw_readl(PM_CLK_CTRL_REG);
  76. int cpu;
  77. int cpu_sel;
  78. int div_sel;
  79. cpu_sel = (reg >> PM_CLK_CTRL_REG_OFFSET_PLL_CPU_SEL) & 0xf;
  80. div_sel = (reg >> PM_CLK_CTRL_REG_OFFSET_CPU_CLK_DIV) & 0x3;
  81. cpu = (300 + ((cpu_sel / 3) * 100) + ((cpu_sel % 3) * 33)) >> div_sel;
  82. return cpu;
  83. }