driver_chipcommon_sflash.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Broadcom specific AMBA
  3. * ChipCommon serial flash interface
  4. *
  5. * Licensed under the GNU/GPL. See COPYING for details.
  6. */
  7. #include <linux/platform_device.h>
  8. #include <linux/bcma/bcma.h>
  9. #include "bcma_private.h"
  10. static struct resource bcma_sflash_resource = {
  11. .name = "bcma_sflash",
  12. .start = BCMA_SFLASH,
  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 struct bcma_sflash_tbl_e bcma_sflash_st_tbl[] = {
  28. { "", 0x14, 0x10000, 32, },
  29. { 0 },
  30. };
  31. static struct bcma_sflash_tbl_e bcma_sflash_sst_tbl[] = {
  32. { 0 },
  33. };
  34. static struct bcma_sflash_tbl_e bcma_sflash_at_tbl[] = {
  35. { 0 },
  36. };
  37. static void bcma_sflash_cmd(struct bcma_drv_cc *cc, u32 opcode)
  38. {
  39. int i;
  40. bcma_cc_write32(cc, BCMA_CC_FLASHCTL,
  41. BCMA_CC_FLASHCTL_START | opcode);
  42. for (i = 0; i < 1000; i++) {
  43. if (!(bcma_cc_read32(cc, BCMA_CC_FLASHCTL) &
  44. BCMA_CC_FLASHCTL_BUSY))
  45. return;
  46. cpu_relax();
  47. }
  48. bcma_err(cc->core->bus, "SFLASH control command failed (timeout)!\n");
  49. }
  50. /* Initialize serial flash access */
  51. int bcma_sflash_init(struct bcma_drv_cc *cc)
  52. {
  53. struct bcma_bus *bus = cc->core->bus;
  54. struct bcma_sflash *sflash = &cc->sflash;
  55. struct bcma_sflash_tbl_e *e;
  56. u32 id, id2;
  57. switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
  58. case BCMA_CC_FLASHT_STSER:
  59. bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_DP);
  60. bcma_cc_write32(cc, BCMA_CC_FLASHADDR, 0);
  61. bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_RES);
  62. id = bcma_cc_read32(cc, BCMA_CC_FLASHDATA);
  63. bcma_cc_write32(cc, BCMA_CC_FLASHADDR, 1);
  64. bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_RES);
  65. id2 = bcma_cc_read32(cc, BCMA_CC_FLASHDATA);
  66. switch (id) {
  67. case 0xbf:
  68. for (e = bcma_sflash_sst_tbl; e->name; e++) {
  69. if (e->id == id2)
  70. break;
  71. }
  72. break;
  73. default:
  74. for (e = bcma_sflash_st_tbl; e->name; e++) {
  75. if (e->id == id)
  76. break;
  77. }
  78. break;
  79. }
  80. if (!e->name) {
  81. bcma_err(bus, "Unsupported ST serial flash (id: 0x%X, id2: 0x%X)\n", id, id2);
  82. return -ENOTSUPP;
  83. }
  84. break;
  85. case BCMA_CC_FLASHT_ATSER:
  86. bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_AT_STATUS);
  87. id = bcma_cc_read32(cc, BCMA_CC_FLASHDATA) & 0x3c;
  88. for (e = bcma_sflash_at_tbl; e->name; e++) {
  89. if (e->id == id)
  90. break;
  91. }
  92. if (!e->name) {
  93. bcma_err(bus, "Unsupported Atmel serial flash (id: 0x%X)\n", id);
  94. return -ENOTSUPP;
  95. }
  96. break;
  97. default:
  98. bcma_err(bus, "Unsupported flash type\n");
  99. return -ENOTSUPP;
  100. }
  101. sflash->window = BCMA_SFLASH;
  102. sflash->blocksize = e->blocksize;
  103. sflash->numblocks = e->numblocks;
  104. sflash->size = sflash->blocksize * sflash->numblocks;
  105. sflash->present = true;
  106. bcma_info(bus, "Found %s serial flash (size: %dKiB, blocksize: 0x%X, blocks: %d)\n",
  107. e->name, sflash->size / 1024, sflash->blocksize,
  108. sflash->numblocks);
  109. /* Prepare platform device, but don't register it yet. It's too early,
  110. * malloc (required by device_private_init) is not available yet. */
  111. bcma_sflash_dev.resource[0].end = bcma_sflash_dev.resource[0].start +
  112. sflash->size;
  113. bcma_sflash_dev.dev.platform_data = sflash;
  114. return 0;
  115. }