mg_disk.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * include/linux/mg_disk.c
  3. *
  4. * Support for the mGine m[g]flash IO mode.
  5. * Based on legacy hd.c
  6. *
  7. * (c) 2008 mGine Co.,LTD
  8. * (c) 2008 unsik Kim <donari75@gmail.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #ifndef __MG_DISK_H__
  15. #define __MG_DISK_H__
  16. #include <linux/blkdev.h>
  17. #include <linux/ata.h>
  18. /* name for block device */
  19. #define MG_DISK_NAME "mgd"
  20. /* name for platform device */
  21. #define MG_DEV_NAME "mg_disk"
  22. #define MG_DISK_MAJ 0
  23. #define MG_DISK_MAX_PART 16
  24. #define MG_SECTOR_SIZE 512
  25. #define MG_MAX_SECTS 256
  26. /* Register offsets */
  27. #define MG_BUFF_OFFSET 0x8000
  28. #define MG_STORAGE_BUFFER_SIZE 0x200
  29. #define MG_REG_OFFSET 0xC000
  30. #define MG_REG_FEATURE (MG_REG_OFFSET + 2) /* write case */
  31. #define MG_REG_ERROR (MG_REG_OFFSET + 2) /* read case */
  32. #define MG_REG_SECT_CNT (MG_REG_OFFSET + 4)
  33. #define MG_REG_SECT_NUM (MG_REG_OFFSET + 6)
  34. #define MG_REG_CYL_LOW (MG_REG_OFFSET + 8)
  35. #define MG_REG_CYL_HIGH (MG_REG_OFFSET + 0xA)
  36. #define MG_REG_DRV_HEAD (MG_REG_OFFSET + 0xC)
  37. #define MG_REG_COMMAND (MG_REG_OFFSET + 0xE) /* write case */
  38. #define MG_REG_STATUS (MG_REG_OFFSET + 0xE) /* read case */
  39. #define MG_REG_DRV_CTRL (MG_REG_OFFSET + 0x10)
  40. #define MG_REG_BURST_CTRL (MG_REG_OFFSET + 0x12)
  41. /* "Drive Select/Head Register" bit values */
  42. #define MG_REG_HEAD_MUST_BE_ON 0xA0 /* These 2 bits are always on */
  43. #define MG_REG_HEAD_DRIVE_MASTER (0x00 | MG_REG_HEAD_MUST_BE_ON)
  44. #define MG_REG_HEAD_DRIVE_SLAVE (0x10 | MG_REG_HEAD_MUST_BE_ON)
  45. #define MG_REG_HEAD_LBA_MODE (0x40 | MG_REG_HEAD_MUST_BE_ON)
  46. /* "Device Control Register" bit values */
  47. #define MG_REG_CTRL_INTR_ENABLE 0x0
  48. #define MG_REG_CTRL_INTR_DISABLE (0x1<<1)
  49. #define MG_REG_CTRL_RESET (0x1<<2)
  50. #define MG_REG_CTRL_INTR_POLA_ACTIVE_HIGH 0x0
  51. #define MG_REG_CTRL_INTR_POLA_ACTIVE_LOW (0x1<<4)
  52. #define MG_REG_CTRL_DPD_POLA_ACTIVE_LOW 0x0
  53. #define MG_REG_CTRL_DPD_POLA_ACTIVE_HIGH (0x1<<5)
  54. #define MG_REG_CTRL_DPD_DISABLE 0x0
  55. #define MG_REG_CTRL_DPD_ENABLE (0x1<<6)
  56. /* Status register bit */
  57. /* error bit in status register */
  58. #define MG_REG_STATUS_BIT_ERROR 0x01
  59. /* corrected error in status register */
  60. #define MG_REG_STATUS_BIT_CORRECTED_ERROR 0x04
  61. /* data request bit in status register */
  62. #define MG_REG_STATUS_BIT_DATA_REQ 0x08
  63. /* DSC - Drive Seek Complete */
  64. #define MG_REG_STATUS_BIT_SEEK_DONE 0x10
  65. /* DWF - Drive Write Fault */
  66. #define MG_REG_STATUS_BIT_WRITE_FAULT 0x20
  67. #define MG_REG_STATUS_BIT_READY 0x40
  68. #define MG_REG_STATUS_BIT_BUSY 0x80
  69. /* handy status */
  70. #define MG_STAT_READY (MG_REG_STATUS_BIT_READY | MG_REG_STATUS_BIT_SEEK_DONE)
  71. #define MG_READY_OK(s) (((s) & (MG_STAT_READY | \
  72. (MG_REG_STATUS_BIT_BUSY | \
  73. MG_REG_STATUS_BIT_WRITE_FAULT | \
  74. MG_REG_STATUS_BIT_ERROR))) == MG_STAT_READY)
  75. /* Error register */
  76. #define MG_REG_ERR_AMNF 0x01
  77. #define MG_REG_ERR_ABRT 0x04
  78. #define MG_REG_ERR_IDNF 0x10
  79. #define MG_REG_ERR_UNC 0x40
  80. #define MG_REG_ERR_BBK 0x80
  81. /* error code for others */
  82. #define MG_ERR_NONE 0
  83. #define MG_ERR_TIMEOUT 0x100
  84. #define MG_ERR_INIT_STAT 0x101
  85. #define MG_ERR_TRANSLATION 0x102
  86. #define MG_ERR_CTRL_RST 0x103
  87. #define MG_ERR_INV_STAT 0x104
  88. #define MG_ERR_RSTOUT 0x105
  89. #define MG_MAX_ERRORS 6 /* Max read/write errors */
  90. /* command */
  91. #define MG_CMD_RD 0x20
  92. #define MG_CMD_WR 0x30
  93. #define MG_CMD_SLEEP 0x99
  94. #define MG_CMD_WAKEUP 0xC3
  95. #define MG_CMD_ID 0xEC
  96. #define MG_CMD_WR_CONF 0x3C
  97. #define MG_CMD_RD_CONF 0x40
  98. /* operation mode */
  99. #define MG_OP_CASCADE (1 << 0)
  100. #define MG_OP_CASCADE_SYNC_RD (1 << 1)
  101. #define MG_OP_CASCADE_SYNC_WR (1 << 2)
  102. #define MG_OP_INTERLEAVE (1 << 3)
  103. /* synchronous */
  104. #define MG_BURST_LAT_4 (3 << 4)
  105. #define MG_BURST_LAT_5 (4 << 4)
  106. #define MG_BURST_LAT_6 (5 << 4)
  107. #define MG_BURST_LAT_7 (6 << 4)
  108. #define MG_BURST_LAT_8 (7 << 4)
  109. #define MG_BURST_LEN_4 (1 << 1)
  110. #define MG_BURST_LEN_8 (2 << 1)
  111. #define MG_BURST_LEN_16 (3 << 1)
  112. #define MG_BURST_LEN_32 (4 << 1)
  113. #define MG_BURST_LEN_CONT (0 << 1)
  114. /* timeout value (unit: ms) */
  115. #define MG_TMAX_CONF_TO_CMD 1
  116. #define MG_TMAX_WAIT_RD_DRQ 10
  117. #define MG_TMAX_WAIT_WR_DRQ 500
  118. #define MG_TMAX_RST_TO_BUSY 10
  119. #define MG_TMAX_HDRST_TO_RDY 500
  120. #define MG_TMAX_SWRST_TO_RDY 500
  121. #define MG_TMAX_RSTOUT 3000
  122. /* device attribution */
  123. /* use mflash as boot device */
  124. #define MG_BOOT_DEV (1 << 0)
  125. /* use mflash as storage device */
  126. #define MG_STORAGE_DEV (1 << 1)
  127. /* same as MG_STORAGE_DEV, but bootloader already done reset sequence */
  128. #define MG_STORAGE_DEV_SKIP_RST (1 << 2)
  129. #define MG_DEV_MASK (MG_BOOT_DEV | MG_STORAGE_DEV | MG_STORAGE_DEV_SKIP_RST)
  130. /* names of GPIO resource */
  131. #define MG_RST_PIN "mg_rst"
  132. /* except MG_BOOT_DEV, reset-out pin should be assigned */
  133. #define MG_RSTOUT_PIN "mg_rstout"
  134. /* private driver data */
  135. struct mg_drv_data {
  136. /* disk resource */
  137. u32 use_polling;
  138. /* device attribution */
  139. u32 dev_attr;
  140. /* internally used */
  141. struct mg_host *host;
  142. };
  143. /* main structure for mflash driver */
  144. struct mg_host {
  145. struct device *dev;
  146. struct request_queue *breq;
  147. spinlock_t lock;
  148. struct gendisk *gd;
  149. struct timer_list timer;
  150. void (*mg_do_intr) (struct mg_host *);
  151. u16 id[ATA_ID_WORDS];
  152. u16 cyls;
  153. u16 heads;
  154. u16 sectors;
  155. u32 n_sectors;
  156. u32 nres_sectors;
  157. void __iomem *dev_base;
  158. unsigned int irq;
  159. unsigned int rst;
  160. unsigned int rstout;
  161. u32 major;
  162. u32 error;
  163. };
  164. /*
  165. * Debugging macro and defines
  166. */
  167. #undef DO_MG_DEBUG
  168. #ifdef DO_MG_DEBUG
  169. # define MG_DBG(fmt, args...) \
  170. printk(KERN_DEBUG "%s:%d "fmt, __func__, __LINE__, ##args)
  171. #else /* CONFIG_MG_DEBUG */
  172. # define MG_DBG(fmt, args...) do { } while (0)
  173. #endif /* CONFIG_MG_DEBUG */
  174. #endif