connectTheSignalSlot.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* linux/arch/arm/plat-s3c24xx/s3c2410-iotiming.c
  2. *
  3. * Copyright (c) 2006-2009 Simtec Electronics
  4. * http://armlinux.simtec.co.uk/
  5. * Ben Dooks <ben@simtec.co.uk>
  6. *
  7. * S3C24XX CPU Frequency scaling - IO timing for S3C2410/S3C2440/S3C2442
  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 <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <linux/errno.h>
  16. #include <linux/cpufreq.h>
  17. #include <linux/seq_file.h>
  18. #include <linux/io.h>
  19. #include <linux/slab.h>
  20. #include <mach/map.h>
  21. #include <mach/regs-mem.h>
  22. #include <mach/regs-clock.h>
  23. #include <plat/cpu-freq-core.h>
  24. #define print_ns(x) ((x) / 10), ((x) % 10)
  25. /**
  26. * s3c2410_print_timing - print bank timing data for debug purposes
  27. * @pfx: The prefix to put on the output
  28. * @timings: The timing inforamtion to print.
  29. */
  30. static void s3c2410_print_timing(const char *pfx,
  31. struct s3c_iotimings *timings)
  32. {
  33. struct s3c2410_iobank_timing *bt;
  34. int bank;
  35. for (bank = 0; bank < MAX_BANKS; bank++) {
  36. bt = timings->bank[bank].io_2410;
  37. if (!bt)
  38. continue;
  39. printk(KERN_DEBUG "%s %d: Tacs=%d.%d, Tcos=%d.%d, Tacc=%d.%d, "
  40. "Tcoh=%d.%d, Tcah=%d.%d\n", pfx, bank,
  41. print_ns(bt->tacs),
  42. print_ns(bt->tcos),
  43. print_ns(bt->tacc),
  44. print_ns(bt->tcoh),
  45. print_ns(bt->tcah));
  46. }
  47. }
  48. /**
  49. * bank_reg - convert bank number to pointer to the control register.
  50. * @bank: The IO bank number.
  51. */
  52. static inline void __iomem *bank_reg(unsigned int bank)
  53. {
  54. return S3C2410_BANKCON0 + (bank << 2);
  55. }
  56. /**
  57. * bank_is_io - test whether bank is used for IO
  58. * @bankcon: The bank control register.
  59. *
  60. * This is a simplistic test to see if any BANKCON[x] is not an IO
  61. * bank. It currently does not take into account whether BWSCON has
  62. * an illegal width-setting in it, or if the pin connected to nCS[x]
  63. * is actually being handled as a chip-select.
  64. */
  65. static inline int bank_is_io(unsigned long bankcon)
  66. {
  67. return !(bankcon & S3C2410_BANKCON_SDRAM);
  68. }
  69. /**
  70. * to_div - convert cycle time to divisor
  71. * @cyc: The cycle time, in 10ths of nanoseconds.
  72. * @hclk_tns: The cycle time for HCLK, in 10ths of nanoseconds.
  73. *
  74. * Convert the given cycle time into the divisor to use to obtain it from
  75. * HCLK.
  76. */
  77. static inline unsigned int to_div(unsigned int cyc, unsigned int hclk_tns)
  78. {
  79. if (cyc == 0)
  80. return 0;
  81. return DIV_ROUND_UP(cyc, hclk_tns);
  82. }
  83. /**
  84. * calc_0124 - calculate divisor control for divisors that do /0, /1. /2 and /4
  85. * @cyc: The cycle time, in 10ths of nanoseconds.
  86. * @hclk_tns: The cycle time for HCLK, in 10ths of nanoseconds.
  87. * @v: Pointer to register to alter.
  88. * @shift: The shift to get to the control bits.
  89. *
  90. * Calculate the divisor, and turn it into the correct control bits to
  91. * set in the result, @v.
  92. */
  93. static unsigned int calc_0124(unsigned int cyc, unsigned long hclk_tns,
  94. unsigned long *v, int shift)
  95. {
  96. unsigned int div = to_div(cyc, hclk_tns);
  97. unsigned long val;
  98. s3c_freq_iodbg("%s: cyc=%d, hclk=%lu, shift=%d => div %d\n",
  99. __func__, cyc, hclk_tns, shift, div);
  100. switch (div) {
  101. case 0:
  102. val = 0;
  103. break;
  104. case 1:
  105. val = 1;
  106. break;
  107. case 2:
  108. val = 2;
  109. break;
  110. case 3:
  111. case 4:
  112. val = 3;
  113. break;
  114. default:
  115. return -1;
  116. }
  117. *v |= val << shift;
  118. return 0;
  119. }
  120. int calc_tacp(unsigned int cyc, unsigned long hclk, unsigned long *v)
  121. {
  122. /* Currently no support for Tacp calculations. */
  123. return 0;
  124. }
  125. /**
  126. * calc_tacc - calculate divisor control for tacc.
  127. * @cyc: The cycle time, in 10ths of nanoseconds.
  128. * @nwait_en: IS nWAIT enabled for this bank.
  129. * @hclk_tns: The cycle time for HCLK, in 10ths of nanoseconds.
  130. * @v: Pointer to register to alter.
  131. *
  132. * Calculate the divisor control for tACC, taking into account whether
  133. * the bank has nWAIT enabled. The result is used to modify the value
  134. * pointed to by @v.
  135. */
  136. static int calc_tacc(unsigned int cyc, int nwait_en,
  137. unsigned long hclk_tns, unsigned long *v)
  138. {
  139. unsigned int div = to_div(cyc, hclk_tns);
  140. unsigned long val;
  141. s3c_freq_iodbg("%s: cyc=%u, nwait=%d, hclk=%lu => div=%u\n",
  142. __func__, cyc, nwait_en, hclk_tns, div);
  143. /* if nWait enabled on an bank, Tacc must be at-least 4 cycles. */
  144. if (nwait_en && div < 4)
  145. div = 4;
  146. switch (div) {
  147. case 0:
  148. val = 0;
  149. break;
  150. case 1:
  151. case 2:
  152. case 3:
  153. case 4:
  154. val = div - 1;
  155. break;
  156. case 5:
  157. case 6:
  158. val = 4;
  159. break;
  160. case 7:
  161. case 8:
  162. val = 5;
  163. break;
  164. case 9:
  165. case 10:
  166. val = 6;
  167. break;
  168. case 11:
  169. case 12:
  170. case 13:
  171. case 14:
  172. val = 7;
  173. break;
  174. default:
  175. return -1;
  176. }
  177. *v |= val << 8;
  178. return 0;
  179. }
  180. /**
  181. * s3c2410_calc_bank - calculate bank timing infromation
  182. * @cfg: The configuration we need to calculate for.
  183. * @bt: The bank timing information.
  184. *
  185. * Given the cycle timine for a bank @bt, calculate the new BANKCON
  186. * setting for the @cfg timing. This updates the timing information
  187. * ready for the cpu frequency change.
  188. */
  189. static int s3c2410_calc_bank(struct s3c_cpufreq_config *cfg,
  190. struct s3c2410_iobank_timing *bt)