regs-s3c2443-clock.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2007 Simtec Electronics
  4. * Ben Dooks <[email protected]>
  5. * http://armlinux.simtec.co.uk/
  6. *
  7. * S3C2443 clock register definitions
  8. */
  9. #ifndef __ASM_ARM_REGS_S3C2443_CLOCK
  10. #define __ASM_ARM_REGS_S3C2443_CLOCK
  11. #include <linux/delay.h>
  12. #include "map-s3c.h"
  13. #define S3C2443_CLKREG(x) ((x) + S3C24XX_VA_CLKPWR)
  14. #define S3C2443_PLLCON_MDIVSHIFT 16
  15. #define S3C2443_PLLCON_PDIVSHIFT 8
  16. #define S3C2443_PLLCON_SDIVSHIFT 0
  17. #define S3C2443_PLLCON_MDIVMASK ((1<<(1+(23-16)))-1)
  18. #define S3C2443_PLLCON_PDIVMASK ((1<<(1+(9-8)))-1)
  19. #define S3C2443_PLLCON_SDIVMASK (3)
  20. #define S3C2443_MPLLCON S3C2443_CLKREG(0x10)
  21. #define S3C2443_EPLLCON S3C2443_CLKREG(0x18)
  22. #define S3C2443_CLKSRC S3C2443_CLKREG(0x20)
  23. #define S3C2443_CLKDIV0 S3C2443_CLKREG(0x24)
  24. #define S3C2443_CLKDIV1 S3C2443_CLKREG(0x28)
  25. #define S3C2443_HCLKCON S3C2443_CLKREG(0x30)
  26. #define S3C2443_PCLKCON S3C2443_CLKREG(0x34)
  27. #define S3C2443_SCLKCON S3C2443_CLKREG(0x38)
  28. #define S3C2443_PWRMODE S3C2443_CLKREG(0x40)
  29. #define S3C2443_SWRST S3C2443_CLKREG(0x44)
  30. #define S3C2443_BUSPRI0 S3C2443_CLKREG(0x50)
  31. #define S3C2443_SYSID S3C2443_CLKREG(0x5C)
  32. #define S3C2443_PWRCFG S3C2443_CLKREG(0x60)
  33. #define S3C2443_RSTCON S3C2443_CLKREG(0x64)
  34. #define S3C2443_PHYCTRL S3C2443_CLKREG(0x80)
  35. #define S3C2443_PHYPWR S3C2443_CLKREG(0x84)
  36. #define S3C2443_URSTCON S3C2443_CLKREG(0x88)
  37. #define S3C2443_UCLKCON S3C2443_CLKREG(0x8C)
  38. #define S3C2443_PLLCON_OFF (1<<24)
  39. #define S3C2443_CLKSRC_EPLLREF_XTAL (2<<7)
  40. #define S3C2443_CLKSRC_EPLLREF_EXTCLK (3<<7)
  41. #define S3C2443_CLKSRC_EPLLREF_MPLLREF (0<<7)
  42. #define S3C2443_CLKSRC_EPLLREF_MPLLREF2 (1<<7)
  43. #define S3C2443_CLKSRC_EPLLREF_MASK (3<<7)
  44. #define S3C2443_CLKSRC_EXTCLK_DIV (1<<3)
  45. #define S3C2443_CLKDIV0_HALF_HCLK (1<<3)
  46. #define S3C2443_CLKDIV0_HALF_PCLK (1<<2)
  47. #define S3C2443_CLKDIV0_HCLKDIV_MASK (3<<0)
  48. #define S3C2443_CLKDIV0_EXTDIV_MASK (3<<6)
  49. #define S3C2443_CLKDIV0_EXTDIV_SHIFT (6)
  50. #define S3C2443_CLKDIV0_PREDIV_MASK (3<<4)
  51. #define S3C2443_CLKDIV0_PREDIV_SHIFT (4)
  52. #define S3C2416_CLKDIV0_ARMDIV_MASK (7 << 9)
  53. #define S3C2443_CLKDIV0_ARMDIV_MASK (15<<9)
  54. #define S3C2443_CLKDIV0_ARMDIV_SHIFT (9)
  55. #define S3C2443_CLKDIV0_ARMDIV_1 (0<<9)
  56. #define S3C2443_CLKDIV0_ARMDIV_2 (8<<9)
  57. #define S3C2443_CLKDIV0_ARMDIV_3 (2<<9)
  58. #define S3C2443_CLKDIV0_ARMDIV_4 (9<<9)
  59. #define S3C2443_CLKDIV0_ARMDIV_6 (10<<9)
  60. #define S3C2443_CLKDIV0_ARMDIV_8 (11<<9)
  61. #define S3C2443_CLKDIV0_ARMDIV_12 (13<<9)
  62. #define S3C2443_CLKDIV0_ARMDIV_16 (15<<9)
  63. /* S3C2443_CLKDIV1 removed, only used in clock.c code */
  64. #define S3C2443_CLKCON_NAND
  65. #define S3C2443_HCLKCON_DMA0 (1<<0)
  66. #define S3C2443_HCLKCON_DMA1 (1<<1)
  67. #define S3C2443_HCLKCON_DMA2 (1<<2)
  68. #define S3C2443_HCLKCON_DMA3 (1<<3)
  69. #define S3C2443_HCLKCON_DMA4 (1<<4)
  70. #define S3C2443_HCLKCON_DMA5 (1<<5)
  71. #define S3C2443_HCLKCON_CAMIF (1<<8)
  72. #define S3C2443_HCLKCON_LCDC (1<<9)
  73. #define S3C2443_HCLKCON_USBH (1<<11)
  74. #define S3C2443_HCLKCON_USBD (1<<12)
  75. #define S3C2416_HCLKCON_HSMMC0 (1<<15)
  76. #define S3C2443_HCLKCON_HSMMC (1<<16)
  77. #define S3C2443_HCLKCON_CFC (1<<17)
  78. #define S3C2443_HCLKCON_SSMC (1<<18)
  79. #define S3C2443_HCLKCON_DRAMC (1<<19)
  80. #define S3C2443_PCLKCON_UART0 (1<<0)
  81. #define S3C2443_PCLKCON_UART1 (1<<1)
  82. #define S3C2443_PCLKCON_UART2 (1<<2)
  83. #define S3C2443_PCLKCON_UART3 (1<<3)
  84. #define S3C2443_PCLKCON_IIC (1<<4)
  85. #define S3C2443_PCLKCON_SDI (1<<5)
  86. #define S3C2443_PCLKCON_HSSPI (1<<6)
  87. #define S3C2443_PCLKCON_ADC (1<<7)
  88. #define S3C2443_PCLKCON_AC97 (1<<8)
  89. #define S3C2443_PCLKCON_IIS (1<<9)
  90. #define S3C2443_PCLKCON_PWMT (1<<10)
  91. #define S3C2443_PCLKCON_WDT (1<<11)
  92. #define S3C2443_PCLKCON_RTC (1<<12)
  93. #define S3C2443_PCLKCON_GPIO (1<<13)
  94. #define S3C2443_PCLKCON_SPI0 (1<<14)
  95. #define S3C2443_PCLKCON_SPI1 (1<<15)
  96. #define S3C2443_SCLKCON_DDRCLK (1<<16)
  97. #define S3C2443_SCLKCON_SSMCCLK (1<<15)
  98. #define S3C2443_SCLKCON_HSSPICLK (1<<14)
  99. #define S3C2443_SCLKCON_HSMMCCLK_EXT (1<<13)
  100. #define S3C2443_SCLKCON_HSMMCCLK_EPLL (1<<12)
  101. #define S3C2443_SCLKCON_CAMCLK (1<<11)
  102. #define S3C2443_SCLKCON_DISPCLK (1<<10)
  103. #define S3C2443_SCLKCON_I2SCLK (1<<9)
  104. #define S3C2443_SCLKCON_UARTCLK (1<<8)
  105. #define S3C2443_SCLKCON_USBHOST (1<<1)
  106. #define S3C2443_PWRCFG_SLEEP (1<<15)
  107. #define S3C2443_PWRCFG_USBPHY (1 << 4)
  108. #define S3C2443_URSTCON_FUNCRST (1 << 2)
  109. #define S3C2443_URSTCON_PHYRST (1 << 0)
  110. #define S3C2443_PHYCTRL_CLKSEL (1 << 3)
  111. #define S3C2443_PHYCTRL_EXTCLK (1 << 2)
  112. #define S3C2443_PHYCTRL_PLLSEL (1 << 1)
  113. #define S3C2443_PHYCTRL_DSPORT (1 << 0)
  114. #define S3C2443_PHYPWR_COMMON_ON (1 << 31)
  115. #define S3C2443_PHYPWR_ANALOG_PD (1 << 4)
  116. #define S3C2443_PHYPWR_PLL_REFCLK (1 << 3)
  117. #define S3C2443_PHYPWR_XO_ON (1 << 2)
  118. #define S3C2443_PHYPWR_PLL_PWRDN (1 << 1)
  119. #define S3C2443_PHYPWR_FSUSPEND (1 << 0)
  120. #define S3C2443_UCLKCON_DETECT_VBUS (1 << 31)
  121. #define S3C2443_UCLKCON_FUNC_CLKEN (1 << 2)
  122. #define S3C2443_UCLKCON_TCLKEN (1 << 0)
  123. #include <asm/div64.h>
  124. static inline unsigned int
  125. s3c2443_get_mpll(unsigned int pllval, unsigned int baseclk)
  126. {
  127. unsigned int mdiv, pdiv, sdiv;
  128. uint64_t fvco;
  129. mdiv = pllval >> S3C2443_PLLCON_MDIVSHIFT;
  130. pdiv = pllval >> S3C2443_PLLCON_PDIVSHIFT;
  131. sdiv = pllval >> S3C2443_PLLCON_SDIVSHIFT;
  132. mdiv &= S3C2443_PLLCON_MDIVMASK;
  133. pdiv &= S3C2443_PLLCON_PDIVMASK;
  134. sdiv &= S3C2443_PLLCON_SDIVMASK;
  135. fvco = (uint64_t)baseclk * (2 * (mdiv + 8));
  136. do_div(fvco, pdiv << sdiv);
  137. return (unsigned int)fvco;
  138. }
  139. static inline unsigned int
  140. s3c2443_get_epll(unsigned int pllval, unsigned int baseclk)
  141. {
  142. unsigned int mdiv, pdiv, sdiv;
  143. uint64_t fvco;
  144. mdiv = pllval >> S3C2443_PLLCON_MDIVSHIFT;
  145. pdiv = pllval >> S3C2443_PLLCON_PDIVSHIFT;
  146. sdiv = pllval >> S3C2443_PLLCON_SDIVSHIFT;
  147. mdiv &= S3C2443_PLLCON_MDIVMASK;
  148. pdiv &= S3C2443_PLLCON_PDIVMASK;
  149. sdiv &= S3C2443_PLLCON_SDIVMASK;
  150. fvco = (uint64_t)baseclk * (mdiv + 8);
  151. do_div(fvco, (pdiv + 2) << sdiv);
  152. return (unsigned int)fvco;
  153. }
  154. static inline void s3c_hsudc_init_phy(void)
  155. {
  156. u32 cfg;
  157. cfg = readl(S3C2443_PWRCFG) | S3C2443_PWRCFG_USBPHY;
  158. writel(cfg, S3C2443_PWRCFG);
  159. cfg = readl(S3C2443_URSTCON);
  160. cfg |= (S3C2443_URSTCON_FUNCRST | S3C2443_URSTCON_PHYRST);
  161. writel(cfg, S3C2443_URSTCON);
  162. mdelay(1);
  163. cfg = readl(S3C2443_URSTCON);
  164. cfg &= ~(S3C2443_URSTCON_FUNCRST | S3C2443_URSTCON_PHYRST);
  165. writel(cfg, S3C2443_URSTCON);
  166. cfg = readl(S3C2443_PHYCTRL);
  167. cfg &= ~(S3C2443_PHYCTRL_CLKSEL | S3C2443_PHYCTRL_DSPORT);
  168. cfg |= (S3C2443_PHYCTRL_EXTCLK | S3C2443_PHYCTRL_PLLSEL);
  169. writel(cfg, S3C2443_PHYCTRL);
  170. cfg = readl(S3C2443_PHYPWR);
  171. cfg &= ~(S3C2443_PHYPWR_FSUSPEND | S3C2443_PHYPWR_PLL_PWRDN |
  172. S3C2443_PHYPWR_XO_ON | S3C2443_PHYPWR_PLL_REFCLK |
  173. S3C2443_PHYPWR_ANALOG_PD);
  174. cfg |= S3C2443_PHYPWR_COMMON_ON;
  175. writel(cfg, S3C2443_PHYPWR);
  176. cfg = readl(S3C2443_UCLKCON);
  177. cfg |= (S3C2443_UCLKCON_DETECT_VBUS | S3C2443_UCLKCON_FUNC_CLKEN |
  178. S3C2443_UCLKCON_TCLKEN);
  179. writel(cfg, S3C2443_UCLKCON);
  180. }
  181. static inline void s3c_hsudc_uninit_phy(void)
  182. {
  183. u32 cfg;
  184. cfg = readl(S3C2443_PWRCFG) & ~S3C2443_PWRCFG_USBPHY;
  185. writel(cfg, S3C2443_PWRCFG);
  186. writel(S3C2443_PHYPWR_FSUSPEND, S3C2443_PHYPWR);
  187. cfg = readl(S3C2443_UCLKCON) & ~S3C2443_UCLKCON_FUNC_CLKEN;
  188. writel(cfg, S3C2443_UCLKCON);
  189. }
  190. #endif /* __ASM_ARM_REGS_S3C2443_CLOCK */