ide.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * (C) Copyright 2007-2009 DENX Software Engineering
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. *
  22. */
  23. #include <common.h>
  24. #include <command.h>
  25. #include <asm/processor.h>
  26. DECLARE_GLOBAL_DATA_PTR;
  27. #if defined(CONFIG_IDE_RESET)
  28. void init_ide_reset (void)
  29. {
  30. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  31. debug ("init_ide_reset\n");
  32. /*
  33. * Clear the reset bit to reset the interface
  34. * cf. RefMan MPC5121EE: 28.4.1 Resetting the ATA Bus
  35. */
  36. immr->pata.pata_ata_control = 0;
  37. udelay(100);
  38. /* Assert the reset bit to enable the interface */
  39. immr->pata.pata_ata_control = FSL_ATA_CTRL_ATA_RST_B;
  40. udelay(100);
  41. }
  42. void ide_set_reset (int idereset)
  43. {
  44. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  45. debug ("ide_set_reset(%d)\n", idereset);
  46. if (idereset) {
  47. immr->pata.pata_ata_control = 0;
  48. udelay(100);
  49. } else {
  50. immr->pata.pata_ata_control = FSL_ATA_CTRL_ATA_RST_B;
  51. udelay(100);
  52. }
  53. }
  54. #define CALC_TIMING(t) (t + period - 1) / period
  55. int ide_preinit (void)
  56. {
  57. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  58. long t;
  59. const struct {
  60. short t0;
  61. short t1;
  62. short t2_8;
  63. short t2_16;
  64. short t2i;
  65. short t4;
  66. short t9;
  67. short tA;
  68. } pio_specs = {
  69. .t0 = 600,
  70. .t1 = 70,
  71. .t2_8 = 290,
  72. .t2_16 = 165,
  73. .t2i = 0,
  74. .t4 = 30,
  75. .t9 = 20,
  76. .tA = 50,
  77. };
  78. union {
  79. u32 config;
  80. struct {
  81. u8 field1;
  82. u8 field2;
  83. u8 field3;
  84. u8 field4;
  85. }bytes;
  86. }cfg;
  87. debug ("IDE preinit using PATA peripheral at IMMR-ADDR %08x\n",
  88. (u32)&immr->pata);
  89. /* Set the reset bit to 1 to enable the interface */
  90. immr->pata.pata_ata_control = FSL_ATA_CTRL_ATA_RST_B;
  91. /* Init timings : we use PIO mode 0 timings */
  92. t = 1000000000 / gd->ips_clk; /* period in ns */
  93. cfg.bytes.field1 = 3;
  94. cfg.bytes.field2 = 3;
  95. cfg.bytes.field3 = (pio_specs.t1 + t) / t;
  96. cfg.bytes.field4 = (pio_specs.t2_8 + t) / t;
  97. immr->pata.pata_time1 = cfg.config;
  98. cfg.bytes.field1 = (pio_specs.t2_8 + t) / t;
  99. cfg.bytes.field2 = (pio_specs.tA + t) / t + 2;
  100. cfg.bytes.field3 = 1;
  101. cfg.bytes.field4 = (pio_specs.t4 + t) / t;
  102. immr->pata.pata_time2 = cfg.config;
  103. cfg.config = immr->pata.pata_time3;
  104. cfg.bytes.field1 = (pio_specs.t9 + t) / t;
  105. immr->pata.pata_time3 = cfg.config;
  106. debug ("PATA preinit complete.\n");
  107. return 0;
  108. }
  109. #endif /* defined(CONFIG_IDE_RESET) */