npcm_clk.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Nuvoton NPCM7xx Clock Control Registers.
  3. *
  4. * Copyright 2020 Google LLC
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * 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, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. * for more details.
  15. */
  16. #ifndef NPCM_CLK_H
  17. #define NPCM_CLK_H
  18. #include "exec/memory.h"
  19. #include "hw/clock.h"
  20. #include "hw/sysbus.h"
  21. #define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t))
  22. /*
  23. * Number of maximum registers in NPCM device state structure. Don't change
  24. * this without incrementing the version_id in the vmstate.
  25. */
  26. #define NPCM_CLK_MAX_NR_REGS NPCM7XX_CLK_NR_REGS
  27. #define NPCM7XX_WATCHDOG_RESET_GPIO_IN "npcm7xx-clk-watchdog-reset-gpio-in"
  28. /* Maximum amount of clock inputs in a SEL module. */
  29. #define NPCM7XX_CLK_SEL_MAX_INPUT 5
  30. /* PLLs in CLK module. */
  31. typedef enum NPCM7xxClockPLL {
  32. NPCM7XX_CLOCK_PLL0,
  33. NPCM7XX_CLOCK_PLL1,
  34. NPCM7XX_CLOCK_PLL2,
  35. NPCM7XX_CLOCK_PLLG,
  36. NPCM7XX_CLOCK_NR_PLLS,
  37. } NPCM7xxClockPLL;
  38. /* SEL/MUX in CLK module. */
  39. typedef enum NPCM7xxClockSEL {
  40. NPCM7XX_CLOCK_PIXCKSEL,
  41. NPCM7XX_CLOCK_MCCKSEL,
  42. NPCM7XX_CLOCK_CPUCKSEL,
  43. NPCM7XX_CLOCK_CLKOUTSEL,
  44. NPCM7XX_CLOCK_UARTCKSEL,
  45. NPCM7XX_CLOCK_TIMCKSEL,
  46. NPCM7XX_CLOCK_SDCKSEL,
  47. NPCM7XX_CLOCK_GFXMSEL,
  48. NPCM7XX_CLOCK_SUCKSEL,
  49. NPCM7XX_CLOCK_NR_SELS,
  50. } NPCM7xxClockSEL;
  51. /* Dividers in CLK module. */
  52. typedef enum NPCM7xxClockDivider {
  53. NPCM7XX_CLOCK_PLL1D2, /* PLL1/2 */
  54. NPCM7XX_CLOCK_PLL2D2, /* PLL2/2 */
  55. NPCM7XX_CLOCK_MC_DIVIDER,
  56. NPCM7XX_CLOCK_AXI_DIVIDER,
  57. NPCM7XX_CLOCK_AHB_DIVIDER,
  58. NPCM7XX_CLOCK_AHB3_DIVIDER,
  59. NPCM7XX_CLOCK_SPI0_DIVIDER,
  60. NPCM7XX_CLOCK_SPIX_DIVIDER,
  61. NPCM7XX_CLOCK_APB1_DIVIDER,
  62. NPCM7XX_CLOCK_APB2_DIVIDER,
  63. NPCM7XX_CLOCK_APB3_DIVIDER,
  64. NPCM7XX_CLOCK_APB4_DIVIDER,
  65. NPCM7XX_CLOCK_APB5_DIVIDER,
  66. NPCM7XX_CLOCK_CLKOUT_DIVIDER,
  67. NPCM7XX_CLOCK_UART_DIVIDER,
  68. NPCM7XX_CLOCK_TIMER_DIVIDER,
  69. NPCM7XX_CLOCK_ADC_DIVIDER,
  70. NPCM7XX_CLOCK_MMC_DIVIDER,
  71. NPCM7XX_CLOCK_SDHC_DIVIDER,
  72. NPCM7XX_CLOCK_GFXM_DIVIDER, /* divide by 3 */
  73. NPCM7XX_CLOCK_UTMI_DIVIDER,
  74. NPCM7XX_CLOCK_NR_DIVIDERS,
  75. } NPCM7xxClockConverter;
  76. typedef struct NPCMCLKState NPCMCLKState;
  77. /**
  78. * struct NPCM7xxClockPLLState - A PLL module in CLK module.
  79. * @name: The name of the module.
  80. * @clk: The CLK module that owns this module.
  81. * @clock_in: The input clock of this module.
  82. * @clock_out: The output clock of this module.
  83. * @reg: The control registers for this PLL module.
  84. */
  85. typedef struct NPCM7xxClockPLLState {
  86. DeviceState parent;
  87. const char *name;
  88. NPCMCLKState *clk;
  89. Clock *clock_in;
  90. Clock *clock_out;
  91. int reg;
  92. } NPCM7xxClockPLLState;
  93. /**
  94. * struct NPCM7xxClockSELState - A SEL module in CLK module.
  95. * @name: The name of the module.
  96. * @clk: The CLK module that owns this module.
  97. * @input_size: The size of inputs of this module.
  98. * @clock_in: The input clocks of this module.
  99. * @clock_out: The output clocks of this module.
  100. * @offset: The offset of this module in the control register.
  101. * @len: The length of this module in the control register.
  102. */
  103. typedef struct NPCM7xxClockSELState {
  104. DeviceState parent;
  105. const char *name;
  106. NPCMCLKState *clk;
  107. uint8_t input_size;
  108. Clock *clock_in[NPCM7XX_CLK_SEL_MAX_INPUT];
  109. Clock *clock_out;
  110. int offset;
  111. int len;
  112. } NPCM7xxClockSELState;
  113. /**
  114. * struct NPCM7xxClockDividerState - A Divider module in CLK module.
  115. * @name: The name of the module.
  116. * @clk: The CLK module that owns this module.
  117. * @clock_in: The input clock of this module.
  118. * @clock_out: The output clock of this module.
  119. * @divide: The function the divider uses to divide the input.
  120. * @reg: The index of the control register that contains the divisor.
  121. * @offset: The offset of the divisor in the control register.
  122. * @len: The length of the divisor in the control register.
  123. * @divisor: The divisor for a constant divisor
  124. */
  125. typedef struct NPCM7xxClockDividerState {
  126. DeviceState parent;
  127. const char *name;
  128. NPCMCLKState *clk;
  129. Clock *clock_in;
  130. Clock *clock_out;
  131. uint32_t (*divide)(struct NPCM7xxClockDividerState *s);
  132. union {
  133. struct {
  134. int reg;
  135. int offset;
  136. int len;
  137. };
  138. int divisor;
  139. };
  140. } NPCM7xxClockDividerState;
  141. struct NPCMCLKState {
  142. SysBusDevice parent;
  143. MemoryRegion iomem;
  144. /* Clock converters */
  145. NPCM7xxClockPLLState plls[NPCM7XX_CLOCK_NR_PLLS];
  146. NPCM7xxClockSELState sels[NPCM7XX_CLOCK_NR_SELS];
  147. NPCM7xxClockDividerState dividers[NPCM7XX_CLOCK_NR_DIVIDERS];
  148. uint32_t regs[NPCM_CLK_MAX_NR_REGS];
  149. /* Time reference for SECCNT and CNTR25M, initialized by power on reset */
  150. int64_t ref_ns;
  151. /* The incoming reference clock. */
  152. Clock *clkref;
  153. };
  154. #define TYPE_NPCM_CLK "npcm-clk"
  155. OBJECT_DECLARE_SIMPLE_TYPE(NPCMCLKState, NPCM_CLK)
  156. #define TYPE_NPCM7XX_CLK "npcm7xx-clk"
  157. #endif /* NPCM_CLK_H */