ide.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * (C) Copyright 2000-2011
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. *
  23. */
  24. /* Code taken from cmd_ide.c */
  25. #include <common.h>
  26. #include <ata.h>
  27. #include "ide.h"
  28. #ifdef CONFIG_IDE_8xx_DIRECT
  29. #include <mpc8xx.h>
  30. #include <pcmcia.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. /* Timings for IDE Interface
  33. *
  34. * SETUP / LENGTH / HOLD - cycles valid for 50 MHz clk
  35. * 70 165 30 PIO-Mode 0, [ns]
  36. * 4 9 2 [Cycles]
  37. * 50 125 20 PIO-Mode 1, [ns]
  38. * 3 7 2 [Cycles]
  39. * 30 100 15 PIO-Mode 2, [ns]
  40. * 2 6 1 [Cycles]
  41. * 30 80 10 PIO-Mode 3, [ns]
  42. * 2 5 1 [Cycles]
  43. * 25 70 10 PIO-Mode 4, [ns]
  44. * 2 4 1 [Cycles]
  45. */
  46. static const pio_config_t pio_config_ns[IDE_MAX_PIO_MODE+1] = {
  47. /* Setup Length Hold */
  48. { 70, 165, 30 }, /* PIO-Mode 0, [ns] */
  49. { 50, 125, 20 }, /* PIO-Mode 1, [ns] */
  50. { 30, 101, 15 }, /* PIO-Mode 2, [ns] */
  51. { 30, 80, 10 }, /* PIO-Mode 3, [ns] */
  52. { 25, 70, 10 }, /* PIO-Mode 4, [ns] */
  53. };
  54. static pio_config_t pio_config_clk[IDE_MAX_PIO_MODE+1];
  55. #ifndef CONFIG_SYS_PIO_MODE
  56. #define CONFIG_SYS_PIO_MODE 0 /* use a relaxed default */
  57. #endif
  58. static int pio_mode = CONFIG_SYS_PIO_MODE;
  59. /* Make clock cycles and always round up */
  60. #define PCMCIA_MK_CLKS(t, T) (((t) * (T) + 999U) / 1000U)
  61. static void set_pcmcia_timing(int pmode)
  62. {
  63. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  64. volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
  65. ulong timings;
  66. debug("Set timing for PIO Mode %d\n", pmode);
  67. timings = PCMCIA_SHT(pio_config_clk[pmode].t_hold)
  68. | PCMCIA_SST(pio_config_clk[pmode].t_setup)
  69. | PCMCIA_SL(pio_config_clk[pmode].t_length);
  70. /*
  71. * IDE 0
  72. */
  73. pcmp->pcmc_pbr0 = CONFIG_SYS_PCMCIA_PBR0;
  74. #if (CONFIG_SYS_PCMCIA_POR0 != 0)
  75. pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0 | timings;
  76. #else
  77. pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0;
  78. #endif
  79. debug("PBR0: %08x POR0: %08x\n", pcmp->pcmc_pbr0, pcmp->pcmc_por0);
  80. pcmp->pcmc_pbr1 = CONFIG_SYS_PCMCIA_PBR1;
  81. #if (CONFIG_SYS_PCMCIA_POR1 != 0)
  82. pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1 | timings;
  83. #else
  84. pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1;
  85. #endif
  86. debug("PBR1: %08x POR1: %08x\n", pcmp->pcmc_pbr1, pcmp->pcmc_por1);
  87. pcmp->pcmc_pbr2 = CONFIG_SYS_PCMCIA_PBR2;
  88. #if (CONFIG_SYS_PCMCIA_POR2 != 0)
  89. pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2 | timings;
  90. #else
  91. pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2;
  92. #endif
  93. debug("PBR2: %08x POR2: %08x\n", pcmp->pcmc_pbr2, pcmp->pcmc_por2);
  94. pcmp->pcmc_pbr3 = CONFIG_SYS_PCMCIA_PBR3;
  95. #if (CONFIG_SYS_PCMCIA_POR3 != 0)
  96. pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3 | timings;
  97. #else
  98. pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3;
  99. #endif
  100. debug("PBR3: %08x POR3: %08x\n", pcmp->pcmc_pbr3, pcmp->pcmc_por3);
  101. /*
  102. * IDE 1
  103. */
  104. pcmp->pcmc_pbr4 = CONFIG_SYS_PCMCIA_PBR4;
  105. #if (CONFIG_SYS_PCMCIA_POR4 != 0)
  106. pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4 | timings;
  107. #else
  108. pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4;
  109. #endif
  110. debug("PBR4: %08x POR4: %08x\n", pcmp->pcmc_pbr4, pcmp->pcmc_por4);
  111. pcmp->pcmc_pbr5 = CONFIG_SYS_PCMCIA_PBR5;
  112. #if (CONFIG_SYS_PCMCIA_POR5 != 0)
  113. pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5 | timings;
  114. #else
  115. pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5;
  116. #endif
  117. debug("PBR5: %08x POR5: %08x\n", pcmp->pcmc_pbr5, pcmp->pcmc_por5);
  118. pcmp->pcmc_pbr6 = CONFIG_SYS_PCMCIA_PBR6;
  119. #if (CONFIG_SYS_PCMCIA_POR6 != 0)
  120. pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6 | timings;
  121. #else
  122. pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6;
  123. #endif
  124. debug("PBR6: %08x POR6: %08x\n", pcmp->pcmc_pbr6, pcmp->pcmc_por6);
  125. pcmp->pcmc_pbr7 = CONFIG_SYS_PCMCIA_PBR7;
  126. #if (CONFIG_SYS_PCMCIA_POR7 != 0)
  127. pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7 | timings;
  128. #else
  129. pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7;
  130. #endif
  131. debug("PBR7: %08x POR7: %08x\n", pcmp->pcmc_pbr7, pcmp->pcmc_por7);
  132. }
  133. int ide_preinit(void)
  134. {
  135. int i;
  136. /* Initialize PIO timing tables */
  137. for (i = 0; i <= IDE_MAX_PIO_MODE; ++i) {
  138. pio_config_clk[i].t_setup =
  139. PCMCIA_MK_CLKS(pio_config_ns[i].t_setup, gd->bus_clk);
  140. pio_config_clk[i].t_length =
  141. PCMCIA_MK_CLKS(pio_config_ns[i].t_length, gd->bus_clk);
  142. pio_config_clk[i].t_hold =
  143. PCMCIA_MK_CLKS(pio_config_ns[i].t_hold, gd->bus_clk);
  144. debug("PIO Mode %d: setup=%2d ns/%d clk" " len=%3d ns/%d clk"
  145. " hold=%2d ns/%d clk\n", i, pio_config_ns[i].t_setup,
  146. pio_config_clk[i].t_setup, pio_config_ns[i].t_length,
  147. pio_config_clk[i].t_length, pio_config_ns[i].t_hold,
  148. pio_config_clk[i].t_hold);
  149. }
  150. return 0;
  151. }
  152. int ide_init_postreset(void)
  153. {
  154. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  155. volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
  156. /* PCMCIA / IDE initialization for common mem space */
  157. pcmp->pcmc_pgcrb = 0;
  158. /* start in PIO mode 0 - most relaxed timings */
  159. pio_mode = 0;
  160. set_pcmcia_timing(pio_mode);
  161. return 0;
  162. }
  163. #endif /* CONFIG_IDE_8xx_DIRECT */
  164. #ifdef CONFIG_IDE_8xx_PCCARD
  165. int ide_preinit(void)
  166. {
  167. ide_devices_found = 0;
  168. /* initialize the PCMCIA IDE adapter card */
  169. pcmcia_on();
  170. if (!ide_devices_found)
  171. return 1;
  172. udelay(1000000);/* 1 s */
  173. return 0;
  174. }
  175. #endif