ide.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * (C) Copyright 2007-2009 DENX Software Engineering
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <asm/io.h>
  9. #include <asm/processor.h>
  10. DECLARE_GLOBAL_DATA_PTR;
  11. #if defined(CONFIG_IDE_RESET)
  12. void ide_set_reset (int idereset)
  13. {
  14. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  15. debug ("ide_set_reset(%d)\n", idereset);
  16. if (idereset) {
  17. out_be32(&im->pata.pata_ata_control, 0);
  18. } else {
  19. out_be32(&im->pata.pata_ata_control, FSL_ATA_CTRL_ATA_RST_B);
  20. }
  21. udelay(100);
  22. }
  23. void init_ide_reset (void)
  24. {
  25. debug ("init_ide_reset\n");
  26. /*
  27. * Clear the reset bit to reset the interface
  28. * cf. RefMan MPC5121EE: 28.4.1 Resetting the ATA Bus
  29. */
  30. ide_set_reset(1);
  31. /* Assert the reset bit to enable the interface */
  32. ide_set_reset(0);
  33. }
  34. #define CALC_TIMING(t) (t + period - 1) / period
  35. int ide_preinit (void)
  36. {
  37. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  38. long t;
  39. const struct {
  40. short t0;
  41. short t1;
  42. short t2_8;
  43. short t2_16;
  44. short t2i;
  45. short t4;
  46. short t9;
  47. short tA;
  48. } pio_specs = {
  49. .t0 = 600,
  50. .t1 = 70,
  51. .t2_8 = 290,
  52. .t2_16 = 165,
  53. .t2i = 0,
  54. .t4 = 30,
  55. .t9 = 20,
  56. .tA = 50,
  57. };
  58. union {
  59. u32 config;
  60. struct {
  61. u8 field1;
  62. u8 field2;
  63. u8 field3;
  64. u8 field4;
  65. }bytes;
  66. } cfg;
  67. debug ("IDE preinit using PATA peripheral at IMMR-ADDR %08x\n",
  68. (u32)&im->pata);
  69. /* Set the reset bit to 1 to enable the interface */
  70. ide_set_reset(0);
  71. /* Init timings : we use PIO mode 0 timings */
  72. t = 1000000000 / gd->arch.ips_clk; /* period in ns */
  73. cfg.bytes.field1 = 3;
  74. cfg.bytes.field2 = 3;
  75. cfg.bytes.field3 = (pio_specs.t1 + t) / t;
  76. cfg.bytes.field4 = (pio_specs.t2_8 + t) / t;
  77. out_be32(&im->pata.pata_time1, cfg.config);
  78. cfg.bytes.field1 = (pio_specs.t2_8 + t) / t;
  79. cfg.bytes.field2 = (pio_specs.tA + t) / t + 2;
  80. cfg.bytes.field3 = 1;
  81. cfg.bytes.field4 = (pio_specs.t4 + t) / t;
  82. out_be32(&im->pata.pata_time2, cfg.config);
  83. cfg.config = in_be32(&im->pata.pata_time3);
  84. cfg.bytes.field1 = (pio_specs.t9 + t) / t;
  85. out_be32(&im->pata.pata_time3, cfg.config);
  86. debug ("PATA preinit complete.\n");
  87. return 0;
  88. }
  89. #endif /* defined(CONFIG_IDE_RESET) */