driver_chipcommon_sflash.c 4.2 KB

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