drv_clock.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 I2S_PRI_DIV 0xb0020030
  28. #define PCM_PRI_DIV 0xb0030014
  29. struct clk;
  30. struct clk_ops {
  31. int (*enable) (struct clk *,int);
  32. struct clk* (*get_parent) (struct clk *);
  33. int (*set_parent) (struct clk *,struct clk *);
  34. uint32_t (*get_rate) (struct clk *);
  35. int (*set_rate) (struct clk *,uint32_t);
  36. int (*set_round_rate) (struct clk *,uint32_t);
  37. };
  38. struct clk {
  39. const char *name;
  40. uint32_t rate;
  41. struct clk *parent;
  42. uint32_t flags;
  43. #define CLK_FLG_NOALLOC BIT(0)
  44. #define CLK_FLG_ENABLE BIT(1)
  45. #define CLK_GATE_BIT(flg) ((flg) >> 24)
  46. #define CLK_FLG_GATE BIT(2)
  47. #define CLK_CPCCR_NO(flg) (((flg) >> 24) & 0xff)
  48. #define CLK_FLG_CPCCR BIT(3)
  49. #define CLK_CGU_NO(flg) (((flg) >> 24) & 0xff)
  50. #define CLK_FLG_CGU BIT(4)
  51. #define CLK_PLL_NO(flg) (((flg) >> 24) & 0xff)
  52. #define CLK_FLG_PLL BIT(5)
  53. #define CLK_CGU_AUDIO_NO(flg) (((flg) >> 24) & 0xff)
  54. #define CLK_FLG_CGU_AUDIO BIT(6)
  55. #define CLK_PARENT(flg) (((flg) >> 16) & 0xff)
  56. #define CLK_RELATIVE(flg) (((flg) >> 16) & 0xff)
  57. #define CLK_FLG_PARENT BIT(7)
  58. #define CLK_FLG_RELATIVE BIT(8)
  59. struct clk_ops *ops;
  60. int count;
  61. int init_state;
  62. struct clk *source;
  63. struct clk *child;
  64. unsigned int CLK_ID;
  65. };
  66. int init_all_clk(void);
  67. struct clk *clk_get(const char *id);
  68. int clk_enable(struct clk *clk);
  69. int clk_is_enabled(struct clk *clk);
  70. void clk_disable(struct clk *clk);
  71. uint32_t clk_get_rate(struct clk *clk);
  72. void clk_put(struct clk *clk);
  73. int clk_set_rate(struct clk *clk, uint32_t rate);
  74. #endif