clock.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. * @rate: fixed rate for clocks which don't implement
  30. * ops->getrate
  31. * @prcmu_cg_off: address offset of the combined enable/disable register
  32. * (used on u8500v1)
  33. * @prcmu_cg_bit: bit in the combined enable/disable register (used on
  34. * u8500v1)
  35. * @prcmu_cg_mgt: address of the enable/disable register (used on
  36. * u8500ed)
  37. * @cluster: peripheral cluster number
  38. * @prcc_bus: bit for the bus clock in the peripheral's CLKRST
  39. * @prcc_kernel: bit for the kernel clock in the peripheral's CLKRST.
  40. * -1 if no kernel clock exists.
  41. * @parent_cluster: pointer to parent's cluster clk struct
  42. * @parent_periph: pointer to parent's peripheral clk struct
  43. *
  44. * Peripherals are organised into clusters, and each cluster has an associated
  45. * bus clock. Some peripherals also have a parent peripheral clock.
  46. *
  47. * In order to enable a clock for a peripheral, we need to enable:
  48. * (1) the parent cluster (bus) clock at the PRCMU level
  49. * (2) the parent peripheral clock (if any) at the PRCMU level
  50. * (3) the peripheral's bus & kernel clock at the PRCC level
  51. *
  52. * (1) and (2) are handled by defining clk structs (DEFINE_PRCMU_CLK) for each
  53. * of the cluster and peripheral clocks, and hooking these as the parents of
  54. * the individual peripheral clocks.
  55. *
  56. * (3) is handled by specifying the bits in the PRCC control registers required
  57. * to enable these clocks and modifying them in the ->enable and
  58. * ->disable callbacks of the peripheral clocks (DEFINE_PRCC_CLK).
  59. *
  60. * This structure describes both the PRCMU-level clocks and PRCC-level clocks.
  61. * The prcmu_* fields are only used for the PRCMU clocks, and the cluster,
  62. * prcc, and parent pointers are only used for the PRCC-level clocks.
  63. */
  64. struct clk {
  65. const struct clkops *ops;
  66. const char *name;
  67. unsigned int enabled;
  68. unsigned long rate;
  69. struct list_head list;
  70. /* These three are only for PRCMU clks */
  71. unsigned int prcmu_cg_off;
  72. unsigned int prcmu_cg_bit;
  73. unsigned int prcmu_cg_mgt;
  74. /* The rest are only for PRCC clks */
  75. int cluster;
  76. unsigned int prcc_bus;
  77. unsigned int prcc_kernel;
  78. struct clk *parent_cluster;
  79. struct clk *parent_periph;
  80. };
  81. #define DEFINE_PRCMU_CLK(_name, _cg_off, _cg_bit, _reg) \
  82. struct clk clk_##_name = { \
  83. .name = #_name, \
  84. .ops = &clk_prcmu_ops, \
  85. .prcmu_cg_off = _cg_off, \
  86. .prcmu_cg_bit = _cg_bit, \
  87. .prcmu_cg_mgt = PRCM_##_reg##_MGT \
  88. }
  89. #define DEFINE_PRCMU_CLK_RATE(_name, _cg_off, _cg_bit, _reg, _rate) \
  90. struct clk clk_##_name = { \
  91. .name = #_name, \
  92. .ops = &clk_prcmu_ops, \
  93. .prcmu_cg_off = _cg_off, \
  94. .prcmu_cg_bit = _cg_bit, \
  95. .rate = _rate, \
  96. .prcmu_cg_mgt = PRCM_##_reg##_MGT \
  97. }
  98. #define DEFINE_PRCC_CLK(_pclust, _name, _bus_en, _kernel_en, _kernclk) \
  99. struct clk clk_##_name = { \
  100. .name = #_name, \
  101. .ops = &clk_prcc_ops, \
  102. .cluster = _pclust, \
  103. .prcc_bus = _bus_en, \
  104. .prcc_kernel = _kernel_en, \
  105. .parent_cluster = &clk_per##_pclust##clk, \
  106. .parent_periph = _kernclk \
  107. }
  108. #define CLK(_clk, _devname, _conname) \
  109. { \
  110. .clk = &clk_##_clk, \
  111. .dev_id = _devname, \
  112. .con_id = _conname, \
  113. }