cpu-freq-core.h 8.8 KB

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