ide.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * (C) Copyright 2004
  3. * Pierre AUBERT, Staubli Faverges, <p.aubert@staubli.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. *
  7. * Init is derived from Linux code.
  8. */
  9. #include <common.h>
  10. #if defined(CONFIG_IDE)
  11. #include <mpc5xxx.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. #define CALC_TIMING(t) (t + period - 1) / period
  14. #ifdef CONFIG_IDE_RESET
  15. extern void init_ide_reset (void);
  16. #endif
  17. int ide_preinit (void)
  18. {
  19. long period, t0, t1, t2_8, t2_16, t4, ta;
  20. vu_long reg;
  21. struct mpc5xxx_sdma *psdma = (struct mpc5xxx_sdma *) MPC5XXX_SDMA;
  22. reg = *(vu_long *) MPC5XXX_GPS_PORT_CONFIG;
  23. #if defined(CONFIG_SYS_ATA_CS_ON_I2C2)
  24. /* ATA cs0/1 on i2c2 clk/io */
  25. reg = (reg & ~0x03000000ul) | 0x02000000ul;
  26. #elif defined(CONFIG_SYS_ATA_CS_ON_TIMER01)
  27. /* ATA cs0/1 on Timer 0/1 */
  28. reg = (reg & ~0x03000000ul) | 0x03000000ul;
  29. #else
  30. /* ATA cs0/1 on Local Plus cs4/5 */
  31. reg = (reg & ~0x03000000ul) | 0x01000000ul;
  32. #endif /* CONFIG_TOTAL5200 */
  33. *(vu_long *) MPC5XXX_GPS_PORT_CONFIG = reg;
  34. /* All sample codes do that... */
  35. *(vu_long *) MPC5XXX_ATA_SHARE_COUNT = 0;
  36. /* Configure and reset host */
  37. *(vu_long *) MPC5XXX_ATA_HOST_CONFIG = MPC5xxx_ATA_HOSTCONF_IORDY |
  38. MPC5xxx_ATA_HOSTCONF_SMR | MPC5xxx_ATA_HOSTCONF_FR;
  39. udelay (10);
  40. *(vu_long *) MPC5XXX_ATA_HOST_CONFIG = MPC5xxx_ATA_HOSTCONF_IORDY;
  41. /* Disable prefetch on Commbus */
  42. psdma->PtdCntrl |= 1;
  43. /* Init timings : we use PIO mode 0 timings */
  44. period = 1000000000 / gd->arch.ipb_clk; /* period in ns */
  45. t0 = CALC_TIMING (600);
  46. t2_8 = CALC_TIMING (290);
  47. t2_16 = CALC_TIMING (165);
  48. reg = (t0 << 24) | (t2_8 << 16) | (t2_16 << 8);
  49. *(vu_long *) MPC5XXX_ATA_PIO1 = reg;
  50. t4 = CALC_TIMING (30);
  51. t1 = CALC_TIMING (70);
  52. ta = CALC_TIMING (35);
  53. reg = (t4 << 24) | (t1 << 16) | (ta << 8);
  54. *(vu_long *) MPC5XXX_ATA_PIO2 = reg;
  55. #ifdef CONFIG_IDE_RESET
  56. init_ide_reset ();
  57. #endif /* CONFIG_IDE_RESET */
  58. return (0);
  59. }
  60. #endif