clock.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (C) 2010 ST-Ericsson
  3. * Copyright (C) 2009 STMicroelectronics
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. /**
  10. * struct clkops - ux500 clock operations
  11. * @enable: function to enable the clock
  12. * @disable: function to disable the clock
  13. * @get_rate: function to get the current clock rate
  14. *
  15. * This structure contains function pointers to functions that will be used to
  16. * control the clock. All of these functions are optional. If get_rate is
  17. * NULL, the rate in the struct clk will be used.
  18. */
  19. struct clkops {
  20. void (*enable) (struct clk *);
  21. void (*disable) (struct clk *);
  22. unsigned long (*get_rate) (struct clk *);
  23. };
  24. /**
  25. * struct clk - ux500 clock structure
  26. * @ops: pointer to clkops struct used to control this clock
  27. * @name: name, for debugging
  28. * @enabled: refcount. positive if enabled, zero if disabled
  29. * @get_rate: custom callback for getting the clock rate
  30. * @data: custom per-clock data for example for the get_rate
  31. * callback
  32. * @rate: fixed rate for clocks which don't implement
  33. * ops->getrate
  34. * @prcmu_cg_off: address offset of the combined enable/disable register
  35. * (used on u8500v1)
  36. * @prcmu_cg_bit: bit in the combined enable/disable register (used on
  37. * u8500v1)
  38. * @prcmu_cg_mgt: address of the enable/disable register (used on
  39. * u8500ed)
  40. * @cluster: peripheral cluster number
  41. * @prcc_bus: bit for the bus clock in the peripheral's CLKRST
  42. * @prcc_kernel: bit for the kernel clock in the peripheral's CLKRST.
  43. * -1 if no kernel clock exists.
  44. * @parent_cluster: pointer to parent's cluster clk struct
  45. * @parent_periph: pointer to parent's peripheral clk struct
  46. *
  47. * Peripherals are organised into clusters, and each cluster has an associated
  48. * bus clock. Some peripherals also have a parent peripheral clock.
  49. *
  50. * In order to enable a clock for a peripheral, we need to enable:
  51. * (1) the parent cluster (bus) clock at the PRCMU level
  52. * (2) the parent peripheral clock (if any) at the PRCMU level
  53. * (3) the peripheral's bus & kernel clock at the PRCC level
  54. *
  55. * (1) and (2) are handled by defining clk structs (DEFINE_PRCMU_CLK) for each
  56. * of the cluster and peripheral clocks, and hooking these as the parents of
  57. * the individual peripheral clocks.
  58. *
  59. * (3) is handled by specifying the bits in the PRCC control registers required
  60. * to enable these clocks and modifying them in the ->enable and
  61. * ->disable callbacks of the peripheral clocks (DEFINE_PRCC_CLK).
  62. *
  63. * This structure describes both the PRCMU-level clocks and PRCC-level clocks.
  64. * The prcmu_* fields are only used for the PRCMU clocks, and the cluster,
  65. * prcc, and parent pointers are only used for the PRCC-level clocks.
  66. */
  67. struct clk {
  68. const struct clkops *ops;
  69. const char *name;
  70. unsigned int enabled;
  71. unsigned long (*get_rate)(struct clk *);
  72. void *data;
  73. unsigned long rate;
  74. struct list_head list;
  75. /* These three are only for PRCMU clks */
  76. unsigned int prcmu_cg_off;
  77. unsigned int prcmu_cg_bit;
  78. unsigned int prcmu_cg_mgt;
  79. /* The rest are only for PRCC clks */
  80. int cluster;
  81. unsigned int prcc_bus;
  82. unsigned int prcc_kernel;
  83. struct clk *parent_cluster;
  84. struct clk *parent_periph;
  85. #if defined(CONFIG_DEBUG_FS)
  86. struct dentry *dent; /* For visible tree hierarchy */
  87. struct dentry *dent_bus; /* For visible tree hierarchy */
  88. #endif
  89. };
  90. #define DEFINE_PRCMU_CLK(_name, _cg_off, _cg_bit, _reg) \
  91. struct clk clk_##_name = { \
  92. .name = #_name, \
  93. .ops = &clk_prcmu_ops, \
  94. .prcmu_cg_off = _cg_off, \
  95. .prcmu_cg_bit = _cg_bit, \
  96. .prcmu_cg_mgt = PRCM_##_reg##_MGT \
  97. }
  98. #define DEFINE_PRCMU_CLK_RATE(_name, _cg_off, _cg_bit, _reg, _rate) \
  99. struct clk clk_##_name = { \
  100. .name = #_name, \
  101. .ops = &clk_prcmu_ops, \
  102. .prcmu_cg_off = _cg_off, \
  103. .prcmu_cg_bit = _cg_bit, \
  104. .rate = _rate, \
  105. .prcmu_cg_mgt = PRCM_##_reg##_MGT \
  106. }
  107. #define DEFINE_PRCC_CLK(_pclust, _name, _bus_en, _kernel_en, _kernclk) \
  108. struct clk clk_##_name = { \
  109. .name = #_name, \
  110. .ops = &clk_prcc_ops, \
  111. .cluster = _pclust, \
  112. .prcc_bus = _bus_en, \
  113. .prcc_kernel = _kernel_en, \
  114. .parent_cluster = &clk_per##_pclust##clk, \
  115. .parent_periph = _kernclk \
  116. }
  117. #define DEFINE_PRCC_CLK_CUSTOM(_pclust, _name, _bus_en, _kernel_en, _kernclk, _callback, _data) \
  118. struct clk clk_##_name = { \
  119. .name = #_name, \
  120. .ops = &clk_prcc_ops, \
  121. .cluster = _pclust, \
  122. .prcc_bus = _bus_en, \
  123. .prcc_kernel = _kernel_en, \
  124. .parent_cluster = &clk_per##_pclust##clk, \
  125. .parent_periph = _kernclk, \
  126. .get_rate = _callback, \
  127. .data = (void *) _data \
  128. }
  129. #define CLK(_clk, _devname, _conname) \
  130. { \
  131. .clk = &clk_##_clk, \
  132. .dev_id = _devname, \
  133. .con_id = _conname, \
  134. }
  135. int __init clk_db8500_ed_fixup(void);
  136. int __init clk_init(void);