clock.h 4.9 KB

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