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. { "MX25L25635F", 0x18, 0x10000, 512, },
  35. { NULL },
  36. };
  37. static const struct bcma_sflash_tbl_e bcma_sflash_sst_tbl[] = {
  38. { "SST25WF512", 1, 0x1000, 16, },
  39. { "SST25VF512", 0x48, 0x1000, 16, },
  40. { "SST25WF010", 2, 0x1000, 32, },
  41. { "SST25VF010", 0x49, 0x1000, 32, },
  42. { "SST25WF020", 3, 0x1000, 64, },
  43. { "SST25VF020", 0x43, 0x1000, 64, },
  44. { "SST25WF040", 4, 0x1000, 128, },
  45. { "SST25VF040", 0x44, 0x1000, 128, },
  46. { "SST25VF040B", 0x8d, 0x1000, 128, },
  47. { "SST25WF080", 5, 0x1000, 256, },
  48. { "SST25VF080B", 0x8e, 0x1000, 256, },
  49. { "SST25VF016", 0x41, 0x1000, 512, },
  50. { "SST25VF032", 0x4a, 0x1000, 1024, },
  51. { "SST25VF064", 0x4b, 0x1000, 2048, },
  52. { NULL },
  53. };
  54. static const struct bcma_sflash_tbl_e bcma_sflash_at_tbl[] = {
  55. { "AT45DB011", 0xc, 256, 512, },
  56. { "AT45DB021", 0x14, 256, 1024, },
  57. { "AT45DB041", 0x1c, 256, 2048, },
  58. { "AT45DB081", 0x24, 256, 4096, },
  59. { "AT45DB161", 0x2c, 512, 4096, },
  60. { "AT45DB321", 0x34, 512, 8192, },
  61. { "AT45DB642", 0x3c, 1024, 8192, },
  62. { NULL },
  63. };
  64. static void bcma_sflash_cmd(struct bcma_drv_cc *cc, u32 opcode)
  65. {
  66. int i;
  67. bcma_cc_write32(cc, BCMA_CC_FLASHCTL,
  68. BCMA_CC_FLASHCTL_START | opcode);
  69. for (i = 0; i < 1000; i++) {
  70. if (!(bcma_cc_read32(cc, BCMA_CC_FLASHCTL) &
  71. BCMA_CC_FLASHCTL_BUSY))
  72. return;
  73. cpu_relax();
  74. }
  75. bcma_err(cc->core->bus, "SFLASH control command failed (timeout)!\n");
  76. }
  77. /* Initialize serial flash access */
  78. int bcma_sflash_init(struct bcma_drv_cc *cc)
  79. {
  80. struct bcma_bus *bus = cc->core->bus;
  81. struct bcma_sflash *sflash = &cc->sflash;
  82. const struct bcma_sflash_tbl_e *e;
  83. u32 id, id2;
  84. switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
  85. case BCMA_CC_FLASHT_STSER:
  86. bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_DP);
  87. bcma_cc_write32(cc, BCMA_CC_FLASHADDR, 0);
  88. bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_RES);
  89. id = bcma_cc_read32(cc, BCMA_CC_FLASHDATA);
  90. bcma_cc_write32(cc, BCMA_CC_FLASHADDR, 1);
  91. bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_RES);
  92. id2 = bcma_cc_read32(cc, BCMA_CC_FLASHDATA);
  93. switch (id) {
  94. case 0xbf:
  95. for (e = bcma_sflash_sst_tbl; e->name; e++) {
  96. if (e->id == id2)
  97. break;
  98. }
  99. break;
  100. case 0x13:
  101. return -ENOTSUPP;
  102. default:
  103. for (e = bcma_sflash_st_tbl; e->name; e++) {
  104. if (e->id == id)
  105. break;
  106. }
  107. break;
  108. }
  109. if (!e->name) {
  110. bcma_err(bus, "Unsupported ST serial flash (id: 0x%X, id2: 0x%X)\n", id, id2);
  111. return -ENOTSUPP;
  112. }
  113. break;
  114. case BCMA_CC_FLASHT_ATSER:
  115. bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_AT_STATUS);
  116. id = bcma_cc_read32(cc, BCMA_CC_FLASHDATA) & 0x3c;
  117. for (e = bcma_sflash_at_tbl; e->name; e++) {
  118. if (e->id == id)
  119. break;
  120. }
  121. if (!e->name) {
  122. bcma_err(bus, "Unsupported Atmel serial flash (id: 0x%X)\n", id);
  123. return -ENOTSUPP;
  124. }
  125. break;
  126. default:
  127. bcma_err(bus, "Unsupported flash type\n");
  128. return -ENOTSUPP;
  129. }
  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. }