mg_disk_prv.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * (C) Copyright 2009 mGine co.
  3. * unsik Kim <donari75@gmail.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #ifndef __MG_DISK_PRV_H__
  24. #define __MG_DISK_PRV_H__
  25. #include <mg_disk.h>
  26. /* name for block device */
  27. #define MG_DISK_NAME "mgd"
  28. /* name for platform device */
  29. #define MG_DEV_NAME "mg_disk"
  30. #define MG_DISK_MAJ 240
  31. #define MG_DISK_MAX_PART 16
  32. #define MG_SECTOR_SIZE 512
  33. #define MG_SECTOR_SIZE_MASK (512 - 1)
  34. #define MG_SECTOR_SIZE_SHIFT (9)
  35. #define MG_MAX_SECTS 256
  36. /* Register offsets */
  37. #define MG_BUFF_OFFSET 0x8000
  38. #define MG_STORAGE_BUFFER_SIZE 0x200
  39. #define MG_REG_OFFSET 0xC000
  40. #define MG_REG_FEATURE (MG_REG_OFFSET + 2) /* write case */
  41. #define MG_REG_ERROR (MG_REG_OFFSET + 2) /* read case */
  42. #define MG_REG_SECT_CNT (MG_REG_OFFSET + 4)
  43. #define MG_REG_SECT_NUM (MG_REG_OFFSET + 6)
  44. #define MG_REG_CYL_LOW (MG_REG_OFFSET + 8)
  45. #define MG_REG_CYL_HIGH (MG_REG_OFFSET + 0xA)
  46. #define MG_REG_DRV_HEAD (MG_REG_OFFSET + 0xC)
  47. #define MG_REG_COMMAND (MG_REG_OFFSET + 0xE) /* write case */
  48. #define MG_REG_STATUS (MG_REG_OFFSET + 0xE) /* read case */
  49. #define MG_REG_DRV_CTRL (MG_REG_OFFSET + 0x10)
  50. #define MG_REG_BURST_CTRL (MG_REG_OFFSET + 0x12)
  51. /* "Drive Select/Head Register" bit values */
  52. #define MG_REG_HEAD_MUST_BE_ON 0xA0 /* These 2 bits are always on */
  53. #define MG_REG_HEAD_DRIVE_MASTER (0x00 | MG_REG_HEAD_MUST_BE_ON)
  54. #define MG_REG_HEAD_DRIVE_SLAVE (0x10 | MG_REG_HEAD_MUST_BE_ON)
  55. #define MG_REG_HEAD_LBA_MODE (0x40 | MG_REG_HEAD_MUST_BE_ON)
  56. /* "Device Control Register" bit values */
  57. #define MG_REG_CTRL_INTR_ENABLE 0x0
  58. #define MG_REG_CTRL_INTR_DISABLE (0x1 << 1)
  59. #define MG_REG_CTRL_RESET (0x1 << 2)
  60. #define MG_REG_CTRL_INTR_POLA_ACTIVE_HIGH 0x0
  61. #define MG_REG_CTRL_INTR_POLA_ACTIVE_LOW (0x1 << 4)
  62. #define MG_REG_CTRL_DPD_POLA_ACTIVE_LOW 0x0
  63. #define MG_REG_CTRL_DPD_POLA_ACTIVE_HIGH (0x1 << 5)
  64. #define MG_REG_CTRL_DPD_DISABLE 0x0
  65. #define MG_REG_CTRL_DPD_ENABLE (0x1 << 6)
  66. /* Status register bit */
  67. /* error bit in status register */
  68. #define MG_REG_STATUS_BIT_ERROR 0x01
  69. /* corrected error in status register */
  70. #define MG_REG_STATUS_BIT_CORRECTED_ERROR 0x04
  71. /* data request bit in status register */
  72. #define MG_REG_STATUS_BIT_DATA_REQ 0x08
  73. /* DSC - Drive Seek Complete */
  74. #define MG_REG_STATUS_BIT_SEEK_DONE 0x10
  75. /* DWF - Drive Write Fault */
  76. #define MG_REG_STATUS_BIT_WRITE_FAULT 0x20
  77. #define MG_REG_STATUS_BIT_READY 0x40
  78. #define MG_REG_STATUS_BIT_BUSY 0x80
  79. /* handy status */
  80. #define MG_STAT_READY (MG_REG_STATUS_BIT_READY | MG_REG_STATUS_BIT_SEEK_DONE)
  81. #define MG_READY_OK(s) (((s) & (MG_STAT_READY | \
  82. (MG_REG_STATUS_BIT_BUSY | \
  83. MG_REG_STATUS_BIT_WRITE_FAULT | \
  84. MG_REG_STATUS_BIT_ERROR))) == MG_STAT_READY)
  85. /* Error register */
  86. #define MG_REG_ERR_AMNF 0x01
  87. #define MG_REG_ERR_ABRT 0x04
  88. #define MG_REG_ERR_IDNF 0x10
  89. #define MG_REG_ERR_UNC 0x40
  90. #define MG_REG_ERR_BBK 0x80
  91. /* error code for others */
  92. #define MG_ERR_NONE 0
  93. #define MG_ERR_TIMEOUT 0x100
  94. #define MG_ERR_INIT_STAT 0x101
  95. #define MG_ERR_TRANSLATION 0x102
  96. #define MG_ERR_CTRL_RST 0x103
  97. #define MG_ERR_NO_DRV_DATA 0x104
  98. #define MG_MAX_ERRORS 16 /* Max read/write errors/sector */
  99. #define MG_RESET_FREQ 4 /* Reset controller every 4th retry */
  100. /* command */
  101. #define MG_CMD_RD 0x20
  102. #define MG_CMD_WR 0x30
  103. #define MG_CMD_SLEEP 0x99
  104. #define MG_CMD_WAKEUP 0xC3
  105. #define MG_CMD_ID 0xEC
  106. #define MG_CMD_WR_CONF 0x3C
  107. #define MG_CMD_RD_CONF 0x40
  108. union mg_uniwb{
  109. u16 w;
  110. u8 b[2];
  111. };
  112. /* main structure for mflash driver */
  113. struct mg_host {
  114. struct mg_drv_data *drv_data;
  115. /* for future use */
  116. };
  117. /*
  118. * Debugging macro and defines
  119. */
  120. #undef DO_MG_DEBUG
  121. #ifdef DO_MG_DEBUG
  122. # define MG_DBG(fmt, args...) printf("%s:%d "fmt"\n", __func__, __LINE__,##args)
  123. #else /* CONFIG_MG_DEBUG */
  124. # define MG_DBG(fmt, args...) do { } while(0)
  125. #endif /* CONFIG_MG_DEBUG */
  126. #endif