drv_clock.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * File : drv_clock.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2015-11-19 Urey the first version
  23. */
  24. #ifndef DRV_CLOCK_H_
  25. #define DRV_CLOCK_H_
  26. #include "board.h"
  27. #define CPM_CPCCR (0x00)
  28. #define CPM_CPCSR (0xd4)
  29. #define CPM_DDRCDR (0x2c)
  30. #define CPM_I2SCDR (0x60)
  31. #define CPM_I2SCDR1 (0x70)
  32. #define CPM_LPCDR (0x64)
  33. #define CPM_MSC0CDR (0x68)
  34. #define CPM_MSC1CDR (0xa4)
  35. #define CPM_USBCDR (0x50)
  36. #define CPM_MACCDR (0x54)
  37. #define CPM_UHCCDR (0x6c)
  38. #define CPM_SFCCDR (0x74)
  39. #define CPM_CIMCDR (0x7c)
  40. #define CPM_PCMCDR (0x84)
  41. #define CPM_PCMCDR1 (0xe0)
  42. #define CPM_MPHYC (0xe8)
  43. #define CPM_INTR (0xb0)
  44. #define CPM_INTRE (0xb4)
  45. #define CPM_DRCG (0xd0)
  46. #define CPM_CPSPPR (0x38)
  47. #define CPM_CPPSR (0x34)
  48. #define CPM_USBPCR (0x3c)
  49. #define CPM_USBRDT (0x40)
  50. #define CPM_USBVBFIL (0x44)
  51. #define CPM_USBPCR1 (0x48)
  52. #define CPM_CPAPCR (0x10)
  53. #define CPM_CPMPCR (0x14)
  54. #define CPM_LCR (0x04)
  55. #define CPM_PSWC0ST (0x90)
  56. #define CPM_PSWC1ST (0x94)
  57. #define CPM_PSWC2ST (0x98)
  58. #define CPM_PSWC3ST (0x9c)
  59. #define CPM_CLKGR (0x20)
  60. #define CPM_MESTSEL (0xec)
  61. #define CPM_SRBC (0xc4)
  62. #define CPM_ERNG (0xd8)
  63. #define CPM_RNG (0xdc)
  64. #define CPM_SLBC (0xc8)
  65. #define CPM_SLPC (0xcc)
  66. #define CPM_OPCR (0x24)
  67. #define CPM_RSR (0x08)
  68. #define LCR_LPM_MASK (0x3)
  69. #define LCR_LPM_SLEEP (0x1)
  70. #define OPCR_ERCS (0x1<<2)
  71. #define OPCR_PD (0x1<<3)
  72. #define OPCR_IDLE (0x1<<31)
  73. #define cpm_inl(off) readl(CPM_BASE + (off))
  74. #define cpm_outl(val,off) writel(val, CPM_BASE + (off))
  75. #define cpm_test_bit(bit,off) (cpm_inl(off) & 0x1<<(bit))
  76. #define cpm_set_bit(bit,off) (cpm_outl((cpm_inl(off) | 0x1<<(bit)),off))
  77. #define cpm_clear_bit(bit,off) (cpm_outl(cpm_inl(off) & ~(0x1 << bit), off))
  78. #define I2S_PRI_DIV 0xb0020030
  79. #define PCM_PRI_DIV 0xb0030014
  80. struct clk;
  81. struct clk_ops {
  82. int (*enable) (struct clk *,int);
  83. struct clk* (*get_parent) (struct clk *);
  84. int (*set_parent) (struct clk *,struct clk *);
  85. uint32_t (*get_rate) (struct clk *);
  86. int (*set_rate) (struct clk *,uint32_t);
  87. int (*set_round_rate) (struct clk *,uint32_t);
  88. };
  89. struct clk {
  90. const char *name;
  91. uint32_t rate;
  92. struct clk *parent;
  93. uint32_t flags;
  94. #define CLK_FLG_NOALLOC BIT(0)
  95. #define CLK_FLG_ENABLE BIT(1)
  96. #define CLK_GATE_BIT(flg) ((flg) >> 24)
  97. #define CLK_FLG_GATE BIT(2)
  98. #define CLK_CPCCR_NO(flg) (((flg) >> 24) & 0xff)
  99. #define CLK_FLG_CPCCR BIT(3)
  100. #define CLK_CGU_NO(flg) (((flg) >> 24) & 0xff)
  101. #define CLK_FLG_CGU BIT(4)
  102. #define CLK_PLL_NO(flg) (((flg) >> 24) & 0xff)
  103. #define CLK_FLG_PLL BIT(5)
  104. #define CLK_CGU_AUDIO_NO(flg) (((flg) >> 24) & 0xff)
  105. #define CLK_FLG_CGU_AUDIO BIT(6)
  106. #define CLK_PARENT(flg) (((flg) >> 16) & 0xff)
  107. #define CLK_RELATIVE(flg) (((flg) >> 16) & 0xff)
  108. #define CLK_FLG_PARENT BIT(7)
  109. #define CLK_FLG_RELATIVE BIT(8)
  110. struct clk_ops *ops;
  111. int count;
  112. int init_state;
  113. struct clk *source;
  114. struct clk *child;
  115. unsigned int CLK_ID;
  116. };
  117. int init_all_clk(void);
  118. struct clk *clk_get(const char *id);
  119. int clk_enable(struct clk *clk);
  120. int clk_is_enabled(struct clk *clk);
  121. void clk_disable(struct clk *clk);
  122. uint32_t clk_get_rate(struct clk *clk);
  123. void clk_put(struct clk *clk);
  124. int clk_set_rate(struct clk *clk, uint32_t rate);
  125. #endif