pm.c 1.9 KB

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