driver_chipcommon_sflash.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Sonics Silicon Backplane
  3. * ChipCommon serial flash interface
  4. *
  5. * Licensed under the GNU/GPL. See COPYING for details.
  6. */
  7. #include <linux/ssb/ssb.h>
  8. #include "ssb_private.h"
  9. static struct resource ssb_sflash_resource = {
  10. .name = "ssb_sflash",
  11. .start = SSB_FLASH2,
  12. .end = 0,
  13. .flags = IORESOURCE_MEM | IORESOURCE_READONLY,
  14. };
  15. struct platform_device ssb_sflash_dev = {
  16. .name = "ssb_sflash",
  17. .resource = &ssb_sflash_resource,
  18. .num_resources = 1,
  19. };
  20. struct ssb_sflash_tbl_e {
  21. char *name;
  22. u32 id;
  23. u32 blocksize;
  24. u16 numblocks;
  25. };
  26. static const struct ssb_sflash_tbl_e ssb_sflash_st_tbl[] = {
  27. { "M25P20", 0x11, 0x10000, 4, },
  28. { "M25P40", 0x12, 0x10000, 8, },
  29. { "M25P16", 0x14, 0x10000, 32, },
  30. { "M25P32", 0x15, 0x10000, 64, },
  31. { "M25P64", 0x16, 0x10000, 128, },
  32. { "M25FL128", 0x17, 0x10000, 256, },
  33. { NULL },
  34. };
  35. static const struct ssb_sflash_tbl_e ssb_sflash_sst_tbl[] = {
  36. { "SST25WF512", 1, 0x1000, 16, },
  37. { "SST25VF512", 0x48, 0x1000, 16, },
  38. { "SST25WF010", 2, 0x1000, 32, },
  39. { "SST25VF010", 0x49, 0x1000, 32, },
  40. { "SST25WF020", 3, 0x1000, 64, },
  41. { "SST25VF020", 0x43, 0x1000, 64, },
  42. { "SST25WF040", 4, 0x1000, 128, },
  43. { "SST25VF040", 0x44, 0x1000, 128, },
  44. { "SST25VF040B", 0x8d, 0x1000, 128, },
  45. { "SST25WF080", 5, 0x1000, 256, },
  46. { "SST25VF080B", 0x8e, 0x1000, 256, },
  47. { "SST25VF016", 0x41, 0x1000, 512, },
  48. { "SST25VF032", 0x4a, 0x1000, 1024, },
  49. { "SST25VF064", 0x4b, 0x1000, 2048, },
  50. { NULL },
  51. };
  52. static const struct ssb_sflash_tbl_e ssb_sflash_at_tbl[] = {
  53. { "AT45DB011", 0xc, 256, 512, },
  54. { "AT45DB021", 0x14, 256, 1024, },
  55. { "AT45DB041", 0x1c, 256, 2048, },
  56. { "AT45DB081", 0x24, 256, 4096, },
  57. { "AT45DB161", 0x2c, 512, 4096, },
  58. { "AT45DB321", 0x34, 512, 8192, },
  59. { "AT45DB642", 0x3c, 1024, 8192, },
  60. { NULL },
  61. };
  62. static void ssb_sflash_cmd(struct ssb_chipcommon *cc, u32 opcode)
  63. {
  64. int i;
  65. chipco_write32(cc, SSB_CHIPCO_FLASHCTL,
  66. SSB_CHIPCO_FLASHCTL_START | opcode);
  67. for (i = 0; i < 1000; i++) {
  68. if (!(chipco_read32(cc, SSB_CHIPCO_FLASHCTL) &
  69. SSB_CHIPCO_FLASHCTL_BUSY))
  70. return;
  71. cpu_relax();
  72. }
  73. pr_err("SFLASH control command failed (timeout)!\n");
  74. }
  75. /* Initialize serial flash access */
  76. int ssb_sflash_init(struct ssb_chipcommon *cc)
  77. {
  78. struct ssb_sflash *sflash = &cc->dev->bus->mipscore.sflash;
  79. const struct ssb_sflash_tbl_e *e;
  80. u32 id, id2;
  81. switch (cc->capabilities & SSB_CHIPCO_CAP_FLASHT) {
  82. case SSB_CHIPCO_FLASHT_STSER:
  83. ssb_sflash_cmd(cc, SSB_CHIPCO_FLASHCTL_ST_DP);
  84. chipco_write32(cc, SSB_CHIPCO_FLASHADDR, 0);
  85. ssb_sflash_cmd(cc, SSB_CHIPCO_FLASHCTL_ST_RES);
  86. id = chipco_read32(cc, SSB_CHIPCO_FLASHDATA);
  87. chipco_write32(cc, SSB_CHIPCO_FLASHADDR, 1);
  88. ssb_sflash_cmd(cc, SSB_CHIPCO_FLASHCTL_ST_RES);
  89. id2 = chipco_read32(cc, SSB_CHIPCO_FLASHDATA);
  90. switch (id) {
  91. case 0xbf:
  92. for (e = ssb_sflash_sst_tbl; e->name; e++) {
  93. if (e->id == id2)
  94. break;
  95. }
  96. break;
  97. case 0x13:
  98. return -ENOTSUPP;
  99. default:
  100. for (e = ssb_sflash_st_tbl; e->name; e++) {
  101. if (e->id == id)
  102. break;
  103. }
  104. break;
  105. }
  106. if (!e->name) {
  107. pr_err("Unsupported ST serial flash (id: 0x%X, id2: 0x%X)\n",
  108. id, id2);
  109. return -ENOTSUPP;
  110. }
  111. break;
  112. case SSB_CHIPCO_FLASHT_ATSER:
  113. ssb_sflash_cmd(cc, SSB_CHIPCO_FLASHCTL_AT_STATUS);
  114. id = chipco_read32(cc, SSB_CHIPCO_FLASHDATA) & 0x3c;
  115. for (e = ssb_sflash_at_tbl; e->name; e++) {
  116. if (e->id == id)
  117. break;
  118. }
  119. if (!e->name) {
  120. pr_err("Unsupported Atmel serial flash (id: 0x%X)\n",
  121. id);
  122. return -ENOTSUPP;
  123. }
  124. break;
  125. default:
  126. pr_err("Unsupported flash type\n");
  127. return -ENOTSUPP;
  128. }
  129. sflash->window = SSB_FLASH2;
  130. sflash->blocksize = e->blocksize;
  131. sflash->numblocks = e->numblocks;
  132. sflash->size = sflash->blocksize * sflash->numblocks;
  133. sflash->present = true;
  134. pr_info("Found %s serial flash (size: %dKiB, blocksize: 0x%X, blocks: %d)\n",
  135. e->name, sflash->size / 1024, e->blocksize, e->numblocks);
  136. /* Prepare platform device, but don't register it yet. It's too early,
  137. * malloc (required by device_private_init) is not available yet. */
  138. ssb_sflash_dev.resource[0].end = ssb_sflash_dev.resource[0].start +
  139. sflash->size;
  140. ssb_sflash_dev.dev.platform_data = sflash;
  141. return 0;
  142. }