mxc_ata.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Freescale iMX51 ATA driver
  3. *
  4. * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
  5. *
  6. * Based on code by:
  7. * Mahesh Mahadevan <mahesh.mahadevan@freescale.com>
  8. *
  9. * Based on code from original FSL ATA driver, which is
  10. * part of eCos, the Embedded Configurable Operating System.
  11. * Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
  12. *
  13. * SPDX-License-Identifier: GPL-2.0+
  14. */
  15. #include <common.h>
  16. #include <command.h>
  17. #include <config.h>
  18. #include <asm/byteorder.h>
  19. #include <asm/io.h>
  20. #include <ide.h>
  21. #include <asm/arch/imx-regs.h>
  22. #include <asm/arch/clock.h>
  23. /* MXC ATA register offsets */
  24. struct mxc_ata_config_regs {
  25. u8 time_off; /* 0x00 */
  26. u8 time_on;
  27. u8 time_1;
  28. u8 time_2w;
  29. u8 time_2r;
  30. u8 time_ax;
  31. u8 time_pio_rdx;
  32. u8 time_4;
  33. u8 time_9;
  34. u8 time_m;
  35. u8 time_jn;
  36. u8 time_d;
  37. u8 time_k;
  38. u8 time_ack;
  39. u8 time_env;
  40. u8 time_udma_rdx;
  41. u8 time_zah; /* 0x10 */
  42. u8 time_mlix;
  43. u8 time_dvh;
  44. u8 time_dzfs;
  45. u8 time_dvs;
  46. u8 time_cvh;
  47. u8 time_ss;
  48. u8 time_cyc;
  49. u32 fifo_data_32; /* 0x18 */
  50. u32 fifo_data_16;
  51. u32 fifo_fill;
  52. u32 ata_control;
  53. u32 interrupt_pending;
  54. u32 interrupt_enable;
  55. u32 interrupt_clear;
  56. u32 fifo_alarm;
  57. };
  58. struct mxc_data_hdd_regs {
  59. u32 drive_data; /* 0xa0 */
  60. u32 drive_features;
  61. u32 drive_sector_count;
  62. u32 drive_sector_num;
  63. u32 drive_cyl_low;
  64. u32 drive_cyl_high;
  65. u32 drive_dev_head;
  66. u32 command;
  67. u32 status;
  68. u32 alt_status;
  69. };
  70. /* PIO timing table */
  71. #define NR_PIO_SPECS 5
  72. static uint16_t pio_t1[NR_PIO_SPECS] = { 70, 50, 30, 30, 25 };
  73. static uint16_t pio_t2_8[NR_PIO_SPECS] = { 290, 290, 290, 80, 70 };
  74. static uint16_t pio_t4[NR_PIO_SPECS] = { 30, 20, 15, 10, 10 };
  75. static uint16_t pio_t9[NR_PIO_SPECS] = { 20, 15, 10, 10, 10 };
  76. static uint16_t pio_tA[NR_PIO_SPECS] = { 50, 50, 50, 50, 50 };
  77. #define REG2OFF(reg) ((((uint32_t)reg) & 0x3) * 8)
  78. static void set_ata_bus_timing(unsigned char mode)
  79. {
  80. uint32_t T = 1000000000 / mxc_get_clock(MXC_IPG_CLK);
  81. struct mxc_ata_config_regs *ata_regs;
  82. ata_regs = (struct mxc_ata_config_regs *)CONFIG_SYS_ATA_BASE_ADDR;
  83. if (mode >= NR_PIO_SPECS)
  84. return;
  85. /* Write TIME_OFF/ON/1/2W */
  86. writeb(3, &ata_regs->time_off);
  87. writeb(3, &ata_regs->time_on);
  88. writeb((pio_t1[mode] + T) / T, &ata_regs->time_1);
  89. writeb((pio_t2_8[mode] + T) / T, &ata_regs->time_2w);
  90. /* Write TIME_2R/AX/RDX/4 */
  91. writeb((pio_t2_8[mode] + T) / T, &ata_regs->time_2r);
  92. writeb((pio_tA[mode] + T) / T + 2, &ata_regs->time_ax);
  93. writeb(1, &ata_regs->time_pio_rdx);
  94. writeb((pio_t4[mode] + T) / T, &ata_regs->time_4);
  95. /* Write TIME_9 ; the rest of timing registers is irrelevant for PIO */
  96. writeb((pio_t9[mode] + T) / T, &ata_regs->time_9);
  97. }
  98. int ide_preinit(void)
  99. {
  100. struct mxc_ata_config_regs *ata_regs;
  101. ata_regs = (struct mxc_ata_config_regs *)CONFIG_SYS_ATA_BASE_ADDR;
  102. /* 46.3.3.4 @ FSL iMX51 manual */
  103. /* FIFO normal op., drive reset */
  104. writel(0x80, &ata_regs->ata_control);
  105. /* FIFO normal op., drive not reset */
  106. writel(0xc0, &ata_regs->ata_control);
  107. /* Configure the PIO timing */
  108. set_ata_bus_timing(CONFIG_MXC_ATA_PIO_MODE);
  109. /* 46.3.3.4 @ FSL iMX51 manual */
  110. /* Drive not reset, IORDY handshake */
  111. writel(0x41, &ata_regs->ata_control);
  112. return 0;
  113. }