ide.c 2.9 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/io.h>
  26. #include <asm/processor.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. #if defined(CONFIG_IDE_RESET)
  29. void ide_set_reset (int idereset)
  30. {
  31. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  32. debug ("ide_set_reset(%d)\n", idereset);
  33. if (idereset) {
  34. out_be32(&im->pata.pata_ata_control, 0);
  35. } else {
  36. out_be32(&im->pata.pata_ata_control, FSL_ATA_CTRL_ATA_RST_B);
  37. }
  38. udelay(100);
  39. }
  40. void init_ide_reset (void)
  41. {
  42. debug ("init_ide_reset\n");
  43. /*
  44. * Clear the reset bit to reset the interface
  45. * cf. RefMan MPC5121EE: 28.4.1 Resetting the ATA Bus
  46. */
  47. ide_set_reset(1);
  48. /* Assert the reset bit to enable the interface */
  49. ide_set_reset(0);
  50. }
  51. #define CALC_TIMING(t) (t + period - 1) / period
  52. int ide_preinit (void)
  53. {
  54. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  55. long t;
  56. const struct {
  57. short t0;
  58. short t1;
  59. short t2_8;
  60. short t2_16;
  61. short t2i;
  62. short t4;
  63. short t9;
  64. short tA;
  65. } pio_specs = {
  66. .t0 = 600,
  67. .t1 = 70,
  68. .t2_8 = 290,
  69. .t2_16 = 165,
  70. .t2i = 0,
  71. .t4 = 30,
  72. .t9 = 20,
  73. .tA = 50,
  74. };
  75. union {
  76. u32 config;
  77. struct {
  78. u8 field1;
  79. u8 field2;
  80. u8 field3;
  81. u8 field4;
  82. }bytes;
  83. } cfg;
  84. debug ("IDE preinit using PATA peripheral at IMMR-ADDR %08x\n",
  85. (u32)&im->pata);
  86. /* Set the reset bit to 1 to enable the interface */
  87. ide_set_reset(0);
  88. /* Init timings : we use PIO mode 0 timings */
  89. t = 1000000000 / gd->ips_clk; /* period in ns */
  90. cfg.bytes.field1 = 3;
  91. cfg.bytes.field2 = 3;
  92. cfg.bytes.field3 = (pio_specs.t1 + t) / t;
  93. cfg.bytes.field4 = (pio_specs.t2_8 + t) / t;
  94. out_be32(&im->pata.pata_time1, cfg.config);
  95. cfg.bytes.field1 = (pio_specs.t2_8 + t) / t;
  96. cfg.bytes.field2 = (pio_specs.tA + t) / t + 2;
  97. cfg.bytes.field3 = 1;
  98. cfg.bytes.field4 = (pio_specs.t4 + t) / t;
  99. out_be32(&im->pata.pata_time2, cfg.config);
  100. cfg.config = in_be32(&im->pata.pata_time3);
  101. cfg.bytes.field1 = (pio_specs.t9 + t) / t;
  102. out_be32(&im->pata.pata_time3, cfg.config);
  103. debug ("PATA preinit complete.\n");
  104. return 0;
  105. }
  106. #endif /* defined(CONFIG_IDE_RESET) */