pfow.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* Primary function overlay window definitions
  2. * and service functions used by LPDDR chips
  3. */
  4. #ifndef __LINUX_MTD_PFOW_H
  5. #define __LINUX_MTD_PFOW_H
  6. #include <linux/mtd/qinfo.h>
  7. /* PFOW registers addressing */
  8. /* Address of symbol "P" */
  9. #define PFOW_QUERY_STRING_P 0x0000
  10. /* Address of symbol "F" */
  11. #define PFOW_QUERY_STRING_F 0x0002
  12. /* Address of symbol "O" */
  13. #define PFOW_QUERY_STRING_O 0x0004
  14. /* Address of symbol "W" */
  15. #define PFOW_QUERY_STRING_W 0x0006
  16. /* Identification info for LPDDR chip */
  17. #define PFOW_MANUFACTURER_ID 0x0020
  18. #define PFOW_DEVICE_ID 0x0022
  19. /* Address in PFOW where prog buffer can can be found */
  20. #define PFOW_PROGRAM_BUFFER_OFFSET 0x0040
  21. /* Size of program buffer in words */
  22. #define PFOW_PROGRAM_BUFFER_SIZE 0x0042
  23. /* Address command code register */
  24. #define PFOW_COMMAND_CODE 0x0080
  25. /* command data register */
  26. #define PFOW_COMMAND_DATA 0x0084
  27. /* command address register lower address bits */
  28. #define PFOW_COMMAND_ADDRESS_L 0x0088
  29. /* command address register upper address bits */
  30. #define PFOW_COMMAND_ADDRESS_H 0x008a
  31. /* number of bytes to be proggrammed lower address bits */
  32. #define PFOW_DATA_COUNT_L 0x0090
  33. /* number of bytes to be proggrammed higher address bits */
  34. #define PFOW_DATA_COUNT_H 0x0092
  35. /* command execution register, the only possible value is 0x01 */
  36. #define PFOW_COMMAND_EXECUTE 0x00c0
  37. /* 0x01 should be written at this address to clear buffer */
  38. #define PFOW_CLEAR_PROGRAM_BUFFER 0x00c4
  39. /* device program/erase suspend register */
  40. #define PFOW_PROGRAM_ERASE_SUSPEND 0x00c8
  41. /* device status register */
  42. #define PFOW_DSR 0x00cc
  43. /* LPDDR memory device command codes */
  44. /* They are possible values of PFOW command code register */
  45. #define LPDDR_WORD_PROGRAM 0x0041
  46. #define LPDDR_BUFF_PROGRAM 0x00E9
  47. #define LPDDR_BLOCK_ERASE 0x0020
  48. #define LPDDR_LOCK_BLOCK 0x0061
  49. #define LPDDR_UNLOCK_BLOCK 0x0062
  50. #define LPDDR_READ_BLOCK_LOCK_STATUS 0x0065
  51. #define LPDDR_INFO_QUERY 0x0098
  52. #define LPDDR_READ_OTP 0x0097
  53. #define LPDDR_PROG_OTP 0x00C0
  54. #define LPDDR_RESUME 0x00D0
  55. /* Defines possible value of PFOW command execution register */
  56. #define LPDDR_START_EXECUTION 0x0001
  57. /* Defines possible value of PFOW program/erase suspend register */
  58. #define LPDDR_SUSPEND 0x0001
  59. /* Possible values of PFOW device status register */
  60. /* access R - read; RC read & clearable */
  61. #define DSR_DPS (1<<1) /* RC; device protect status
  62. * 0 - not protected 1 - locked */
  63. #define DSR_PSS (1<<2) /* R; program suspend status;
  64. * 0-prog in progress/completed,
  65. * 1- prog suspended */
  66. #define DSR_VPPS (1<<3) /* RC; 0-Vpp OK, * 1-Vpp low */
  67. #define DSR_PROGRAM_STATUS (1<<4) /* RC; 0-successful, 1-error */
  68. #define DSR_ERASE_STATUS (1<<5) /* RC; erase or blank check status;
  69. * 0-success erase/blank check,
  70. * 1 blank check error */
  71. #define DSR_ESS (1<<6) /* R; erase suspend status;
  72. * 0-erase in progress/complete,
  73. * 1 erase suspended */
  74. #define DSR_READY_STATUS (1<<7) /* R; Device status
  75. * 0-busy,
  76. * 1-ready */
  77. #define DSR_RPS (0x3<<8) /* RC; region program status
  78. * 00 - Success,
  79. * 01-re-program attempt in region with
  80. * object mode data,
  81. * 10-object mode program w attempt in
  82. * region with control mode data
  83. * 11-attempt to program invalid half
  84. * with 0x41 command */
  85. #define DSR_AOS (1<<12) /* RC; 1- AO related failure */
  86. #define DSR_AVAILABLE (1<<15) /* R; Device availbility
  87. * 1 - Device available
  88. * 0 - not available */
  89. /* The superset of all possible error bits in DSR */
  90. #define DSR_ERR 0x133A
  91. static inline void send_pfow_command(struct map_info *map,
  92. unsigned long cmd_code, unsigned long adr,
  93. unsigned long len, map_word *datum)
  94. {
  95. int bits_per_chip = map_bankwidth(map) * 8;
  96. int chipnum;
  97. struct lpddr_private *lpddr = map->fldrv_priv;
  98. chipnum = adr >> lpddr->chipshift;
  99. map_write(map, CMD(cmd_code), map->pfow_base + PFOW_COMMAND_CODE);
  100. map_write(map, CMD(adr & ((1<<bits_per_chip) - 1)),
  101. map->pfow_base + PFOW_COMMAND_ADDRESS_L);
  102. map_write(map, CMD(adr>>bits_per_chip),
  103. map->pfow_base + PFOW_COMMAND_ADDRESS_H);
  104. if (len) {
  105. map_write(map, CMD(len & ((1<<bits_per_chip) - 1)),
  106. map->pfow_base + PFOW_DATA_COUNT_L);
  107. map_write(map, CMD(len>>bits_per_chip),
  108. map->pfow_base + PFOW_DATA_COUNT_H);
  109. }
  110. if (datum)
  111. map_write(map, *datum, map->pfow_base + PFOW_COMMAND_DATA);
  112. /* Command execution start */
  113. map_write(map, CMD(LPDDR_START_EXECUTION),
  114. map->pfow_base + PFOW_COMMAND_EXECUTE);
  115. }
  116. static inline void print_drs_error(unsigned dsr)
  117. {
  118. int prog_status = (dsr & DSR_RPS) >> 8;
  119. if (!(dsr & DSR_AVAILABLE))
  120. printk(KERN_NOTICE"DSR.15: (0) Device not Available\n");
  121. if (prog_status & 0x03)
  122. printk(KERN_NOTICE"DSR.9,8: (11) Attempt to program invalid "
  123. "half with 41h command\n");
  124. else if (prog_status & 0x02)
  125. printk(KERN_NOTICE"DSR.9,8: (10) Object Mode Program attempt "
  126. "in region with Control Mode data\n");
  127. else if (prog_status & 0x01)
  128. printk(KERN_NOTICE"DSR.9,8: (01) Program attempt in region "
  129. "with Object Mode data\n");
  130. if (!(dsr & DSR_READY_STATUS))
  131. printk(KERN_NOTICE"DSR.7: (0) Device is Busy\n");
  132. if (dsr & DSR_ESS)
  133. printk(KERN_NOTICE"DSR.6: (1) Erase Suspended\n");
  134. if (dsr & DSR_ERASE_STATUS)
  135. printk(KERN_NOTICE"DSR.5: (1) Erase/Blank check error\n");
  136. if (dsr & DSR_PROGRAM_STATUS)
  137. printk(KERN_NOTICE"DSR.4: (1) Program Error\n");
  138. if (dsr & DSR_VPPS)
  139. printk(KERN_NOTICE"DSR.3: (1) Vpp low detect, operation "
  140. "aborted\n");
  141. if (dsr & DSR_PSS)
  142. printk(KERN_NOTICE"DSR.2: (1) Program suspended\n");
  143. if (dsr & DSR_DPS)
  144. printk(KERN_NOTICE"DSR.1: (1) Aborted Erase/Program attempt "
  145. "on locked block\n");
  146. }
  147. #endif /* __LINUX_MTD_PFOW_H */