ide.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * (C) Copyright 2000-2011
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /* Code taken from cmd_ide.c */
  8. #include <common.h>
  9. #include <ata.h>
  10. #include "ide.h"
  11. #ifdef CONFIG_IDE_8xx_DIRECT
  12. #include <mpc8xx.h>
  13. #include <pcmcia.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. /* Timings for IDE Interface
  16. *
  17. * SETUP / LENGTH / HOLD - cycles valid for 50 MHz clk
  18. * 70 165 30 PIO-Mode 0, [ns]
  19. * 4 9 2 [Cycles]
  20. * 50 125 20 PIO-Mode 1, [ns]
  21. * 3 7 2 [Cycles]
  22. * 30 100 15 PIO-Mode 2, [ns]
  23. * 2 6 1 [Cycles]
  24. * 30 80 10 PIO-Mode 3, [ns]
  25. * 2 5 1 [Cycles]
  26. * 25 70 10 PIO-Mode 4, [ns]
  27. * 2 4 1 [Cycles]
  28. */
  29. static const pio_config_t pio_config_ns[IDE_MAX_PIO_MODE+1] = {
  30. /* Setup Length Hold */
  31. { 70, 165, 30 }, /* PIO-Mode 0, [ns] */
  32. { 50, 125, 20 }, /* PIO-Mode 1, [ns] */
  33. { 30, 101, 15 }, /* PIO-Mode 2, [ns] */
  34. { 30, 80, 10 }, /* PIO-Mode 3, [ns] */
  35. { 25, 70, 10 }, /* PIO-Mode 4, [ns] */
  36. };
  37. static pio_config_t pio_config_clk[IDE_MAX_PIO_MODE+1];
  38. #ifndef CONFIG_SYS_PIO_MODE
  39. #define CONFIG_SYS_PIO_MODE 0 /* use a relaxed default */
  40. #endif
  41. static int pio_mode = CONFIG_SYS_PIO_MODE;
  42. /* Make clock cycles and always round up */
  43. #define PCMCIA_MK_CLKS(t, T) (((t) * (T) + 999U) / 1000U)
  44. static void set_pcmcia_timing(int pmode)
  45. {
  46. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  47. volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
  48. ulong timings;
  49. debug("Set timing for PIO Mode %d\n", pmode);
  50. timings = PCMCIA_SHT(pio_config_clk[pmode].t_hold)
  51. | PCMCIA_SST(pio_config_clk[pmode].t_setup)
  52. | PCMCIA_SL(pio_config_clk[pmode].t_length);
  53. /*
  54. * IDE 0
  55. */
  56. pcmp->pcmc_pbr0 = CONFIG_SYS_PCMCIA_PBR0;
  57. #if (CONFIG_SYS_PCMCIA_POR0 != 0)
  58. pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0 | timings;
  59. #else
  60. pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0;
  61. #endif
  62. debug("PBR0: %08x POR0: %08x\n", pcmp->pcmc_pbr0, pcmp->pcmc_por0);
  63. pcmp->pcmc_pbr1 = CONFIG_SYS_PCMCIA_PBR1;
  64. #if (CONFIG_SYS_PCMCIA_POR1 != 0)
  65. pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1 | timings;
  66. #else
  67. pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1;
  68. #endif
  69. debug("PBR1: %08x POR1: %08x\n", pcmp->pcmc_pbr1, pcmp->pcmc_por1);
  70. pcmp->pcmc_pbr2 = CONFIG_SYS_PCMCIA_PBR2;
  71. #if (CONFIG_SYS_PCMCIA_POR2 != 0)
  72. pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2 | timings;
  73. #else
  74. pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2;
  75. #endif
  76. debug("PBR2: %08x POR2: %08x\n", pcmp->pcmc_pbr2, pcmp->pcmc_por2);
  77. pcmp->pcmc_pbr3 = CONFIG_SYS_PCMCIA_PBR3;
  78. #if (CONFIG_SYS_PCMCIA_POR3 != 0)
  79. pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3 | timings;
  80. #else
  81. pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3;
  82. #endif
  83. debug("PBR3: %08x POR3: %08x\n", pcmp->pcmc_pbr3, pcmp->pcmc_por3);
  84. /*
  85. * IDE 1
  86. */
  87. pcmp->pcmc_pbr4 = CONFIG_SYS_PCMCIA_PBR4;
  88. #if (CONFIG_SYS_PCMCIA_POR4 != 0)
  89. pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4 | timings;
  90. #else
  91. pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4;
  92. #endif
  93. debug("PBR4: %08x POR4: %08x\n", pcmp->pcmc_pbr4, pcmp->pcmc_por4);
  94. pcmp->pcmc_pbr5 = CONFIG_SYS_PCMCIA_PBR5;
  95. #if (CONFIG_SYS_PCMCIA_POR5 != 0)
  96. pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5 | timings;
  97. #else
  98. pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5;
  99. #endif
  100. debug("PBR5: %08x POR5: %08x\n", pcmp->pcmc_pbr5, pcmp->pcmc_por5);
  101. pcmp->pcmc_pbr6 = CONFIG_SYS_PCMCIA_PBR6;
  102. #if (CONFIG_SYS_PCMCIA_POR6 != 0)
  103. pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6 | timings;
  104. #else
  105. pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6;
  106. #endif
  107. debug("PBR6: %08x POR6: %08x\n", pcmp->pcmc_pbr6, pcmp->pcmc_por6);
  108. pcmp->pcmc_pbr7 = CONFIG_SYS_PCMCIA_PBR7;
  109. #if (CONFIG_SYS_PCMCIA_POR7 != 0)
  110. pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7 | timings;
  111. #else
  112. pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7;
  113. #endif
  114. debug("PBR7: %08x POR7: %08x\n", pcmp->pcmc_pbr7, pcmp->pcmc_por7);
  115. }
  116. int ide_preinit(void)
  117. {
  118. int i;
  119. /* Initialize PIO timing tables */
  120. for (i = 0; i <= IDE_MAX_PIO_MODE; ++i) {
  121. pio_config_clk[i].t_setup =
  122. PCMCIA_MK_CLKS(pio_config_ns[i].t_setup, gd->bus_clk);
  123. pio_config_clk[i].t_length =
  124. PCMCIA_MK_CLKS(pio_config_ns[i].t_length, gd->bus_clk);
  125. pio_config_clk[i].t_hold =
  126. PCMCIA_MK_CLKS(pio_config_ns[i].t_hold, gd->bus_clk);
  127. debug("PIO Mode %d: setup=%2d ns/%d clk" " len=%3d ns/%d clk"
  128. " hold=%2d ns/%d clk\n", i, pio_config_ns[i].t_setup,
  129. pio_config_clk[i].t_setup, pio_config_ns[i].t_length,
  130. pio_config_clk[i].t_length, pio_config_ns[i].t_hold,
  131. pio_config_clk[i].t_hold);
  132. }
  133. return 0;
  134. }
  135. int ide_init_postreset(void)
  136. {
  137. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  138. volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
  139. /* PCMCIA / IDE initialization for common mem space */
  140. pcmp->pcmc_pgcrb = 0;
  141. /* start in PIO mode 0 - most relaxed timings */
  142. pio_mode = 0;
  143. set_pcmcia_timing(pio_mode);
  144. return 0;
  145. }
  146. #endif /* CONFIG_IDE_8xx_DIRECT */
  147. #ifdef CONFIG_IDE_8xx_PCCARD
  148. int ide_preinit(void)
  149. {
  150. ide_devices_found = 0;
  151. /* initialize the PCMCIA IDE adapter card */
  152. pcmcia_on();
  153. if (!ide_devices_found)
  154. return 1;
  155. udelay(1000000);/* 1 s */
  156. return 0;
  157. }
  158. #endif