sa11xx_base.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*======================================================================
  2. Device driver for the PCMCIA control functionality of StrongARM
  3. SA-1100 microprocessors.
  4. The contents of this file are subject to the Mozilla Public
  5. License Version 1.1 (the "License"); you may not use this file
  6. except in compliance with the License. You may obtain a copy of
  7. the License at http://www.mozilla.org/MPL/
  8. Software distributed under the License is distributed on an "AS
  9. IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10. implied. See the License for the specific language governing
  11. rights and limitations under the License.
  12. The initial developer of the original code is John G. Dorsey
  13. <john+@cs.cmu.edu>. Portions created by John G. Dorsey are
  14. Copyright (C) 1999 John G. Dorsey. All Rights Reserved.
  15. Alternatively, the contents of this file may be used under the
  16. terms of the GNU Public License version 2 (the "GPL"), in which
  17. case the provisions of the GPL are applicable instead of the
  18. above. If you wish to allow the use of your version of this file
  19. only under the terms of the GPL and not to allow others to use
  20. your version of this file under the MPL, indicate your decision
  21. by deleting the provisions above and replace them with the notice
  22. and other provisions required by the GPL. If you do not delete
  23. the provisions above, a recipient may use your version of this
  24. file under either the MPL or the GPL.
  25. ======================================================================*/
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/cpufreq.h>
  29. #include <linux/ioport.h>
  30. #include <linux/kernel.h>
  31. #include <linux/spinlock.h>
  32. #include <asm/hardware.h>
  33. #include <asm/io.h>
  34. #include <asm/irq.h>
  35. #include <asm/system.h>
  36. #include "soc_common.h"
  37. #include "sa11xx_base.h"
  38. /*
  39. * sa1100_pcmcia_default_mecr_timing
  40. * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  41. *
  42. * Calculate MECR clock wait states for given CPU clock
  43. * speed and command wait state. This function can be over-
  44. * written by a board specific version.
  45. *
  46. * The default is to simply calculate the BS values as specified in
  47. * the INTEL SA1100 development manual
  48. * "Expansion Memory (PCMCIA) Configuration Register (MECR)"
  49. * that's section 10.2.5 in _my_ version of the manual ;)
  50. */
  51. static unsigned int
  52. sa1100_pcmcia_default_mecr_timing(struct soc_pcmcia_socket *skt,
  53. unsigned int cpu_speed,
  54. unsigned int cmd_time)
  55. {
  56. return sa1100_pcmcia_mecr_bs(cmd_time, cpu_speed);
  57. }
  58. /* sa1100_pcmcia_set_mecr()
  59. * ^^^^^^^^^^^^^^^^^^^^^^^^
  60. *
  61. * set MECR value for socket <sock> based on this sockets
  62. * io, mem and attribute space access speed.
  63. * Call board specific BS value calculation to allow boards
  64. * to tweak the BS values.
  65. */
  66. static int
  67. sa1100_pcmcia_set_mecr(struct soc_pcmcia_socket *skt, unsigned int cpu_clock)
  68. {
  69. struct soc_pcmcia_timing timing;
  70. u32 mecr, old_mecr;
  71. unsigned long flags;
  72. unsigned int bs_io, bs_mem, bs_attr;
  73. soc_common_pcmcia_get_timing(skt, &timing);
  74. bs_io = skt->ops->get_timing(skt, cpu_clock, timing.io);
  75. bs_mem = skt->ops->get_timing(skt, cpu_clock, timing.mem);
  76. bs_attr = skt->ops->get_timing(skt, cpu_clock, timing.attr);
  77. local_irq_save(flags);
  78. old_mecr = mecr = MECR;
  79. MECR_FAST_SET(mecr, skt->nr, 0);
  80. MECR_BSIO_SET(mecr, skt->nr, bs_io);
  81. MECR_BSA_SET(mecr, skt->nr, bs_attr);
  82. MECR_BSM_SET(mecr, skt->nr, bs_mem);
  83. if (old_mecr != mecr)
  84. MECR = mecr;
  85. local_irq_restore(flags);
  86. debug(skt, 2, "FAST %X BSM %X BSA %X BSIO %X\n",
  87. MECR_FAST_GET(mecr, skt->nr),
  88. MECR_BSM_GET(mecr, skt->nr), MECR_BSA_GET(mecr, skt->nr),
  89. MECR_BSIO_GET(mecr, skt->nr));
  90. return 0;
  91. }
  92. #ifdef CONFIG_CPU_FREQ
  93. static int
  94. sa1100_pcmcia_frequency_change(struct soc_pcmcia_socket *skt,
  95. unsigned long val,
  96. struct cpufreq_freqs *freqs)
  97. {
  98. switch (val) {
  99. case CPUFREQ_PRECHANGE:
  100. if (freqs->new > freqs->old)
  101. sa1100_pcmcia_set_mecr(skt, freqs->new);
  102. break;
  103. case CPUFREQ_POSTCHANGE:
  104. if (freqs->new < freqs->old)
  105. sa1100_pcmcia_set_mecr(skt, freqs->new);
  106. break;
  107. case CPUFREQ_RESUMECHANGE:
  108. sa1100_pcmcia_set_mecr(skt, freqs->new);
  109. break;
  110. }
  111. return 0;
  112. }
  113. #endif
  114. static int
  115. sa1100_pcmcia_set_timing(struct soc_pcmcia_socket *skt)
  116. {
  117. return sa1100_pcmcia_set_mecr(skt, cpufreq_get(0));
  118. }
  119. static int
  120. sa1100_pcmcia_show_timing(struct soc_pcmcia_socket *skt, char *buf)
  121. {
  122. struct soc_pcmcia_timing timing;
  123. unsigned int clock = cpufreq_get(0);
  124. unsigned long mecr = MECR;
  125. char *p = buf;
  126. soc_common_pcmcia_get_timing(skt, &timing);
  127. p+=sprintf(p, "I/O : %u (%u)\n", timing.io,
  128. sa1100_pcmcia_cmd_time(clock, MECR_BSIO_GET(mecr, skt->nr)));
  129. p+=sprintf(p, "attribute: %u (%u)\n", timing.attr,
  130. sa1100_pcmcia_cmd_time(clock, MECR_BSA_GET(mecr, skt->nr)));
  131. p+=sprintf(p, "common : %u (%u)\n", timing.mem,
  132. sa1100_pcmcia_cmd_time(clock, MECR_BSM_GET(mecr, skt->nr)));
  133. return p - buf;
  134. }
  135. int sa11xx_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops,
  136. int first, int nr)
  137. {
  138. /*
  139. * set default MECR calculation if the board specific
  140. * code did not specify one...
  141. */
  142. if (!ops->get_timing)
  143. ops->get_timing = sa1100_pcmcia_default_mecr_timing;
  144. /* Provide our SA11x0 specific timing routines. */
  145. ops->set_timing = sa1100_pcmcia_set_timing;
  146. ops->show_timing = sa1100_pcmcia_show_timing;
  147. #ifdef CONFIG_CPU_FREQ
  148. ops->frequency_change = sa1100_pcmcia_frequency_change;
  149. #endif
  150. return soc_common_drv_pcmcia_probe(dev, ops, first, nr);
  151. }
  152. EXPORT_SYMBOL(sa11xx_drv_pcmcia_probe);
  153. static int __init sa11xx_pcmcia_init(void)
  154. {
  155. return 0;
  156. }
  157. fs_initcall(sa11xx_pcmcia_init);
  158. static void __exit sa11xx_pcmcia_exit(void) {}
  159. module_exit(sa11xx_pcmcia_exit);
  160. MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>");
  161. MODULE_DESCRIPTION("Linux PCMCIA Card Services: SA-11xx core socket driver");
  162. MODULE_LICENSE("Dual MPL/GPL");