cpu-freq-core.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2006-2009 Simtec Electronics
  4. * http://armlinux.simtec.co.uk/
  5. * Ben Dooks <ben@simtec.co.uk>
  6. *
  7. * S3C CPU frequency scaling support - core support
  8. */
  9. #include <plat/cpu-freq.h>
  10. struct seq_file;
  11. #define MAX_BANKS (8)
  12. #define S3C2412_MAX_IO (8)
  13. /**
  14. * struct s3c2410_iobank_timing - IO bank timings for S3C2410 style timings
  15. * @bankcon: The cached version of settings in this structure.
  16. * @tacp:
  17. * @tacs: Time from address valid to nCS asserted.
  18. * @tcos: Time from nCS asserted to nOE or nWE asserted.
  19. * @tacc: Time that nOE or nWE is asserted.
  20. * @tcoh: Time nCS is held after nOE or nWE are released.
  21. * @tcah: Time address is held for after
  22. * @nwait_en: Whether nWAIT is enabled for this bank.
  23. *
  24. * This structure represents the IO timings for a S3C2410 style IO bank
  25. * used by the CPU frequency support if it needs to change the settings
  26. * of the IO.
  27. */
  28. struct s3c2410_iobank_timing {
  29. unsigned long bankcon;
  30. unsigned int tacp;
  31. unsigned int tacs;
  32. unsigned int tcos;
  33. unsigned int tacc;
  34. unsigned int tcoh; /* nCS hold after nOE/nWE */
  35. unsigned int tcah; /* Address hold after nCS */
  36. unsigned char nwait_en; /* nWait enabled for bank. */
  37. };
  38. /**
  39. * struct s3c2412_iobank_timing - io timings for PL092 (S3C2412) style IO
  40. * @idcy: The idle cycle time between transactions.
  41. * @wstrd: nCS release to end of read cycle.
  42. * @wstwr: nCS release to end of write cycle.
  43. * @wstoen: nCS assertion to nOE assertion time.
  44. * @wstwen: nCS assertion to nWE assertion time.
  45. * @wstbrd: Burst ready delay.
  46. * @smbidcyr: Register cache for smbidcyr value.
  47. * @smbwstrd: Register cache for smbwstrd value.
  48. * @smbwstwr: Register cache for smbwstwr value.
  49. * @smbwstoen: Register cache for smbwstoen value.
  50. * @smbwstwen: Register cache for smbwstwen value.
  51. * @smbwstbrd: Register cache for smbwstbrd value.
  52. *
  53. * Timing information for a IO bank on an S3C2412 or similar system which
  54. * uses a PL093 block.
  55. */
  56. struct s3c2412_iobank_timing {
  57. unsigned int idcy;
  58. unsigned int wstrd;
  59. unsigned int wstwr;
  60. unsigned int wstoen;
  61. unsigned int wstwen;
  62. unsigned int wstbrd;
  63. /* register cache */
  64. unsigned char smbidcyr;
  65. unsigned char smbwstrd;
  66. unsigned char smbwstwr;
  67. unsigned char smbwstoen;
  68. unsigned char smbwstwen;
  69. unsigned char smbwstbrd;
  70. };
  71. union s3c_iobank {
  72. struct s3c2410_iobank_timing *io_2410;
  73. struct s3c2412_iobank_timing *io_2412;
  74. };
  75. /**
  76. * struct s3c_iotimings - Chip IO timings holder
  77. * @bank: The timings for each IO bank.
  78. */
  79. struct s3c_iotimings {
  80. union s3c_iobank bank[MAX_BANKS];
  81. };
  82. /**
  83. * struct s3c_plltab - PLL table information.
  84. * @vals: List of PLL values.
  85. * @size: Size of the PLL table @vals.
  86. */
  87. struct s3c_plltab {
  88. struct s3c_pllval *vals;
  89. int size;
  90. };
  91. /**
  92. * struct s3c_cpufreq_config - current cpu frequency configuration
  93. * @freq: The current settings for the core clocks.
  94. * @max: Maxium settings, derived from core, board and user settings.
  95. * @pll: The PLL table entry for the current PLL settings.
  96. * @divs: The divisor settings for the core clocks.
  97. * @info: The current core driver information.
  98. * @board: The information for the board we are running on.
  99. * @lock_pll: Set if the PLL settings cannot be changed.
  100. *
  101. * This is for the core drivers that need to know information about
  102. * the current settings and values. It should not be needed by any
  103. * device drivers.
  104. */
  105. struct s3c_cpufreq_config {
  106. struct s3c_freq freq;
  107. struct s3c_freq max;
  108. struct clk *mpll;
  109. struct cpufreq_frequency_table pll;
  110. struct s3c_clkdivs divs;
  111. struct s3c_cpufreq_info *info; /* for core, not drivers */
  112. struct s3c_cpufreq_board *board;
  113. unsigned int lock_pll:1;
  114. };
  115. /**
  116. * struct s3c_cpufreq_info - Information for the CPU frequency driver.
  117. * @name: The name of this implementation.
  118. * @max: The maximum frequencies for the system.
  119. * @latency: Transition latency to give to cpufreq.
  120. * @locktime_m: The lock-time in uS for the MPLL.
  121. * @locktime_u: The lock-time in uS for the UPLL.
  122. * @locttime_bits: The number of bits each LOCKTIME field.
  123. * @need_pll: Set if this driver needs to change the PLL values to achieve
  124. * any frequency changes. This is really only need by devices like the
  125. * S3C2410 where there is no or limited divider between the PLL and the
  126. * ARMCLK.
  127. * @get_iotiming: Get the current IO timing data, mainly for use at start.
  128. * @set_iotiming: Update the IO timings from the cached copies calculated
  129. * from the @calc_iotiming entry when changing the frequency.
  130. * @calc_iotiming: Calculate and update the cached copies of the IO timings
  131. * from the newly calculated frequencies.
  132. * @calc_freqtable: Calculate (fill in) the given frequency table from the
  133. * current frequency configuration. If the table passed in is NULL,
  134. * then the return is the number of elements to be filled for allocation
  135. * of the table.
  136. * @set_refresh: Set the memory refresh configuration.
  137. * @set_fvco: Set the PLL frequencies.
  138. * @set_divs: Update the clock divisors.
  139. * @calc_divs: Calculate the clock divisors.
  140. */
  141. struct s3c_cpufreq_info {
  142. const char *name;
  143. struct s3c_freq max;
  144. unsigned int latency;
  145. unsigned int locktime_m;
  146. unsigned int locktime_u;
  147. unsigned char locktime_bits;
  148. unsigned int need_pll:1;
  149. /* driver routines */
  150. int (*get_iotiming)(struct s3c_cpufreq_config *cfg,
  151. struct s3c_iotimings *timings);
  152. void (*set_iotiming)(struct s3c_cpufreq_config *cfg,
  153. struct s3c_iotimings *timings);
  154. int (*calc_iotiming)(struct s3c_cpufreq_config *cfg,
  155. struct s3c_iotimings *timings);
  156. int (*calc_freqtable)(struct s3c_cpufreq_config *cfg,
  157. struct cpufreq_frequency_table *t,
  158. size_t table_size);
  159. void (*debug_io_show)(struct seq_file *seq,
  160. struct s3c_cpufreq_config *cfg,
  161. union s3c_iobank *iob);
  162. void (*set_refresh)(struct s3c_cpufreq_config *cfg);
  163. void (*set_fvco)(struct s3c_cpufreq_config *cfg);
  164. void (*set_divs)(struct s3c_cpufreq_config *cfg);
  165. int (*calc_divs)(struct s3c_cpufreq_config *cfg);
  166. };
  167. extern int s3c_cpufreq_register(struct s3c_cpufreq_info *info);
  168. extern int s3c_plltab_register(struct cpufreq_frequency_table *plls,
  169. unsigned int plls_no);
  170. /* exports and utilities for debugfs */
  171. extern struct s3c_cpufreq_config *s3c_cpufreq_getconfig(void);
  172. extern struct s3c_iotimings *s3c_cpufreq_getiotimings(void);
  173. #ifdef CONFIG_ARM_S3C24XX_CPUFREQ_DEBUGFS
  174. #define s3c_cpufreq_debugfs_call(x) x
  175. #else
  176. #define s3c_cpufreq_debugfs_call(x) NULL
  177. #endif
  178. /* Useful utility functions. */
  179. extern struct clk *s3c_cpufreq_clk_get(struct device *, const char *);
  180. /* S3C2410 and compatible exported functions */
  181. extern void s3c2410_cpufreq_setrefresh(struct s3c_cpufreq_config *cfg);
  182. extern void s3c2410_set_fvco(struct s3c_cpufreq_config *cfg);
  183. #ifdef CONFIG_S3C2410_IOTIMING
  184. extern void s3c2410_iotiming_debugfs(struct seq_file *seq,
  185. struct s3c_cpufreq_config *cfg,
  186. union s3c_iobank *iob);
  187. extern int s3c2410_iotiming_calc(struct s3c_cpufreq_config *cfg,
  188. struct s3c_iotimings *iot);
  189. extern int s3c2410_iotiming_get(struct s3c_cpufreq_config *cfg,
  190. struct s3c_iotimings *timings);
  191. extern void s3c2410_iotiming_set(struct s3c_cpufreq_config *cfg,
  192. struct s3c_iotimings *iot);
  193. #else
  194. #define s3c2410_iotiming_debugfs NULL
  195. #define s3c2410_iotiming_calc NULL
  196. #define s3c2410_iotiming_get NULL
  197. #define s3c2410_iotiming_set NULL
  198. #endif /* CONFIG_S3C2410_IOTIMING */
  199. /* S3C2412 compatible routines */
  200. #ifdef CONFIG_S3C2412_IOTIMING
  201. extern void s3c2412_iotiming_debugfs(struct seq_file *seq,
  202. struct s3c_cpufreq_config *cfg,
  203. union s3c_iobank *iob);
  204. extern int s3c2412_iotiming_get(struct s3c_cpufreq_config *cfg,
  205. struct s3c_iotimings *timings);
  206. extern int s3c2412_iotiming_calc(struct s3c_cpufreq_config *cfg,
  207. struct s3c_iotimings *iot);
  208. extern void s3c2412_iotiming_set(struct s3c_cpufreq_config *cfg,
  209. struct s3c_iotimings *iot);
  210. #else
  211. #define s3c2412_iotiming_debugfs NULL
  212. #define s3c2412_iotiming_calc NULL
  213. #define s3c2412_iotiming_get NULL
  214. #define s3c2412_iotiming_set NULL
  215. #endif /* CONFIG_S3C2412_IOTIMING */
  216. #ifdef CONFIG_ARM_S3C24XX_CPUFREQ_DEBUG
  217. #define s3c_freq_dbg(x...) printk(KERN_INFO x)
  218. #else
  219. #define s3c_freq_dbg(x...) do { if (0) printk(x); } while (0)
  220. #endif /* CONFIG_ARM_S3C24XX_CPUFREQ_DEBUG */
  221. #ifdef CONFIG_ARM_S3C24XX_CPUFREQ_IODEBUG
  222. #define s3c_freq_iodbg(x...) printk(KERN_INFO x)
  223. #else
  224. #define s3c_freq_iodbg(x...) do { if (0) printk(x); } while (0)
  225. #endif /* CONFIG_ARM_S3C24XX_CPUFREQ_IODEBUG */
  226. static inline int s3c_cpufreq_addfreq(struct cpufreq_frequency_table *table,
  227. int index, size_t table_size,
  228. unsigned int freq)
  229. {
  230. if (index < 0)
  231. return index;
  232. if (table) {
  233. if (index >= table_size)
  234. return -ENOMEM;
  235. s3c_freq_dbg("%s: { %d = %u kHz }\n",
  236. __func__, index, freq);
  237. table[index].driver_data = index;
  238. table[index].frequency = freq;
  239. }
  240. return index + 1;
  241. }