sa11xx_base.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 <linux/io.h>
  33. #include <linux/slab.h>
  34. #include <mach/hardware.h>
  35. #include <asm/irq.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. }
  108. return 0;
  109. }
  110. #endif
  111. static int
  112. sa1100_pcmcia_set_timing(struct soc_pcmcia_socket *skt)
  113. {
  114. unsigned long clk = clk_get_rate(skt->clk);
  115. return sa1100_pcmcia_set_mecr(skt, clk / 1000);
  116. }
  117. static int
  118. sa1100_pcmcia_show_timing(struct soc_pcmcia_socket *skt, char *buf)
  119. {
  120. struct soc_pcmcia_timing timing;
  121. unsigned int clock = clk_get_rate(skt->clk) / 1000;
  122. unsigned long mecr = MECR;
  123. char *p = buf;
  124. soc_common_pcmcia_get_timing(skt, &timing);
  125. p+=sprintf(p, "I/O : %uns (%uns)\n", timing.io,
  126. sa1100_pcmcia_cmd_time(clock, MECR_BSIO_GET(mecr, skt->nr)));
  127. p+=sprintf(p, "attribute: %uns (%uns)\n", timing.attr,
  128. sa1100_pcmcia_cmd_time(clock, MECR_BSA_GET(mecr, skt->nr)));
  129. p+=sprintf(p, "common : %uns (%uns)\n", timing.mem,
  130. sa1100_pcmcia_cmd_time(clock, MECR_BSM_GET(mecr, skt->nr)));
  131. return p - buf;
  132. }
  133. static const char *skt_names[] = {
  134. "PCMCIA socket 0",
  135. "PCMCIA socket 1",
  136. };
  137. #define SKT_DEV_INFO_SIZE(n) \
  138. (sizeof(struct skt_dev_info) + (n)*sizeof(struct soc_pcmcia_socket))
  139. int sa11xx_drv_pcmcia_add_one(struct soc_pcmcia_socket *skt)
  140. {
  141. skt->res_skt.start = _PCMCIA(skt->nr);
  142. skt->res_skt.end = _PCMCIA(skt->nr) + PCMCIASp - 1;
  143. skt->res_skt.name = skt_names[skt->nr];
  144. skt->res_skt.flags = IORESOURCE_MEM;
  145. skt->res_io.start = _PCMCIAIO(skt->nr);
  146. skt->res_io.end = _PCMCIAIO(skt->nr) + PCMCIAIOSp - 1;
  147. skt->res_io.name = "io";
  148. skt->res_io.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  149. skt->res_mem.start = _PCMCIAMem(skt->nr);
  150. skt->res_mem.end = _PCMCIAMem(skt->nr) + PCMCIAMemSp - 1;
  151. skt->res_mem.name = "memory";
  152. skt->res_mem.flags = IORESOURCE_MEM;
  153. skt->res_attr.start = _PCMCIAAttr(skt->nr);
  154. skt->res_attr.end = _PCMCIAAttr(skt->nr) + PCMCIAAttrSp - 1;
  155. skt->res_attr.name = "attribute";
  156. skt->res_attr.flags = IORESOURCE_MEM;
  157. return soc_pcmcia_add_one(skt);
  158. }
  159. EXPORT_SYMBOL(sa11xx_drv_pcmcia_add_one);
  160. void sa11xx_drv_pcmcia_ops(struct pcmcia_low_level *ops)
  161. {
  162. /*
  163. * set default MECR calculation if the board specific
  164. * code did not specify one...
  165. */
  166. if (!ops->get_timing)
  167. ops->get_timing = sa1100_pcmcia_default_mecr_timing;
  168. /* Provide our SA11x0 specific timing routines. */
  169. ops->set_timing = sa1100_pcmcia_set_timing;
  170. ops->show_timing = sa1100_pcmcia_show_timing;
  171. #ifdef CONFIG_CPU_FREQ
  172. ops->frequency_change = sa1100_pcmcia_frequency_change;
  173. #endif
  174. }
  175. EXPORT_SYMBOL(sa11xx_drv_pcmcia_ops);
  176. int sa11xx_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops,
  177. int first, int nr)
  178. {
  179. struct skt_dev_info *sinfo;
  180. struct soc_pcmcia_socket *skt;
  181. int i, ret = 0;
  182. struct clk *clk;
  183. clk = devm_clk_get(dev, NULL);
  184. if (IS_ERR(clk))
  185. return PTR_ERR(clk);
  186. sa11xx_drv_pcmcia_ops(ops);
  187. sinfo = devm_kzalloc(dev, SKT_DEV_INFO_SIZE(nr), GFP_KERNEL);
  188. if (!sinfo)
  189. return -ENOMEM;
  190. sinfo->nskt = nr;
  191. /* Initialize processor specific parameters */
  192. for (i = 0; i < nr; i++) {
  193. skt = &sinfo->skt[i];
  194. skt->nr = first + i;
  195. skt->clk = clk;
  196. soc_pcmcia_init_one(skt, ops, dev);
  197. ret = sa11xx_drv_pcmcia_add_one(skt);
  198. if (ret)
  199. break;
  200. }
  201. if (ret) {
  202. while (--i >= 0)
  203. soc_pcmcia_remove_one(&sinfo->skt[i]);
  204. } else {
  205. dev_set_drvdata(dev, sinfo);
  206. }
  207. return ret;
  208. }
  209. EXPORT_SYMBOL(sa11xx_drv_pcmcia_probe);
  210. MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>");
  211. MODULE_DESCRIPTION("Linux PCMCIA Card Services: SA-11xx core socket driver");
  212. MODULE_LICENSE("Dual MPL/GPL");