cpu-freq-core.h 7.9 KB

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