Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Sonics Silicon Backplane
0003  * ChipCommon serial flash interface
0004  *
0005  * Licensed under the GNU/GPL. See COPYING for details.
0006  */
0007 
0008 #include "ssb_private.h"
0009 
0010 #include <linux/ssb/ssb.h>
0011 
0012 static struct resource ssb_sflash_resource = {
0013     .name   = "ssb_sflash",
0014     .start  = SSB_FLASH2,
0015     .end    = 0,
0016     .flags  = IORESOURCE_MEM | IORESOURCE_READONLY,
0017 };
0018 
0019 struct platform_device ssb_sflash_dev = {
0020     .name       = "ssb_sflash",
0021     .resource   = &ssb_sflash_resource,
0022     .num_resources  = 1,
0023 };
0024 
0025 struct ssb_sflash_tbl_e {
0026     char *name;
0027     u32 id;
0028     u32 blocksize;
0029     u16 numblocks;
0030 };
0031 
0032 static const struct ssb_sflash_tbl_e ssb_sflash_st_tbl[] = {
0033     { "M25P20", 0x11, 0x10000, 4, },
0034     { "M25P40", 0x12, 0x10000, 8, },
0035 
0036     { "M25P16", 0x14, 0x10000, 32, },
0037     { "M25P32", 0x15, 0x10000, 64, },
0038     { "M25P64", 0x16, 0x10000, 128, },
0039     { "M25FL128", 0x17, 0x10000, 256, },
0040     { NULL },
0041 };
0042 
0043 static const struct ssb_sflash_tbl_e ssb_sflash_sst_tbl[] = {
0044     { "SST25WF512", 1, 0x1000, 16, },
0045     { "SST25VF512", 0x48, 0x1000, 16, },
0046     { "SST25WF010", 2, 0x1000, 32, },
0047     { "SST25VF010", 0x49, 0x1000, 32, },
0048     { "SST25WF020", 3, 0x1000, 64, },
0049     { "SST25VF020", 0x43, 0x1000, 64, },
0050     { "SST25WF040", 4, 0x1000, 128, },
0051     { "SST25VF040", 0x44, 0x1000, 128, },
0052     { "SST25VF040B", 0x8d, 0x1000, 128, },
0053     { "SST25WF080", 5, 0x1000, 256, },
0054     { "SST25VF080B", 0x8e, 0x1000, 256, },
0055     { "SST25VF016", 0x41, 0x1000, 512, },
0056     { "SST25VF032", 0x4a, 0x1000, 1024, },
0057     { "SST25VF064", 0x4b, 0x1000, 2048, },
0058     { NULL },
0059 };
0060 
0061 static const struct ssb_sflash_tbl_e ssb_sflash_at_tbl[] = {
0062     { "AT45DB011", 0xc, 256, 512, },
0063     { "AT45DB021", 0x14, 256, 1024, },
0064     { "AT45DB041", 0x1c, 256, 2048, },
0065     { "AT45DB081", 0x24, 256, 4096, },
0066     { "AT45DB161", 0x2c, 512, 4096, },
0067     { "AT45DB321", 0x34, 512, 8192, },
0068     { "AT45DB642", 0x3c, 1024, 8192, },
0069     { NULL },
0070 };
0071 
0072 static void ssb_sflash_cmd(struct ssb_chipcommon *cc, u32 opcode)
0073 {
0074     int i;
0075     chipco_write32(cc, SSB_CHIPCO_FLASHCTL,
0076                SSB_CHIPCO_FLASHCTL_START | opcode);
0077     for (i = 0; i < 1000; i++) {
0078         if (!(chipco_read32(cc, SSB_CHIPCO_FLASHCTL) &
0079               SSB_CHIPCO_FLASHCTL_BUSY))
0080             return;
0081         cpu_relax();
0082     }
0083     dev_err(cc->dev->dev, "SFLASH control command failed (timeout)!\n");
0084 }
0085 
0086 /* Initialize serial flash access */
0087 int ssb_sflash_init(struct ssb_chipcommon *cc)
0088 {
0089     struct ssb_sflash *sflash = &cc->dev->bus->mipscore.sflash;
0090     const struct ssb_sflash_tbl_e *e;
0091     u32 id, id2;
0092 
0093     switch (cc->capabilities & SSB_CHIPCO_CAP_FLASHT) {
0094     case SSB_CHIPCO_FLASHT_STSER:
0095         ssb_sflash_cmd(cc, SSB_CHIPCO_FLASHCTL_ST_DP);
0096 
0097         chipco_write32(cc, SSB_CHIPCO_FLASHADDR, 0);
0098         ssb_sflash_cmd(cc, SSB_CHIPCO_FLASHCTL_ST_RES);
0099         id = chipco_read32(cc, SSB_CHIPCO_FLASHDATA);
0100 
0101         chipco_write32(cc, SSB_CHIPCO_FLASHADDR, 1);
0102         ssb_sflash_cmd(cc, SSB_CHIPCO_FLASHCTL_ST_RES);
0103         id2 = chipco_read32(cc, SSB_CHIPCO_FLASHDATA);
0104 
0105         switch (id) {
0106         case 0xbf:
0107             for (e = ssb_sflash_sst_tbl; e->name; e++) {
0108                 if (e->id == id2)
0109                     break;
0110             }
0111             break;
0112         case 0x13:
0113             return -ENOTSUPP;
0114         default:
0115             for (e = ssb_sflash_st_tbl; e->name; e++) {
0116                 if (e->id == id)
0117                     break;
0118             }
0119             break;
0120         }
0121         if (!e->name) {
0122             pr_err("Unsupported ST serial flash (id: 0x%X, id2: 0x%X)\n",
0123                    id, id2);
0124             return -ENOTSUPP;
0125         }
0126 
0127         break;
0128     case SSB_CHIPCO_FLASHT_ATSER:
0129         ssb_sflash_cmd(cc, SSB_CHIPCO_FLASHCTL_AT_STATUS);
0130         id = chipco_read32(cc, SSB_CHIPCO_FLASHDATA) & 0x3c;
0131 
0132         for (e = ssb_sflash_at_tbl; e->name; e++) {
0133             if (e->id == id)
0134                 break;
0135         }
0136         if (!e->name) {
0137             pr_err("Unsupported Atmel serial flash (id: 0x%X)\n",
0138                    id);
0139             return -ENOTSUPP;
0140         }
0141 
0142         break;
0143     default:
0144         pr_err("Unsupported flash type\n");
0145         return -ENOTSUPP;
0146     }
0147 
0148     sflash->window = SSB_FLASH2;
0149     sflash->blocksize = e->blocksize;
0150     sflash->numblocks = e->numblocks;
0151     sflash->size = sflash->blocksize * sflash->numblocks;
0152     sflash->present = true;
0153 
0154     pr_info("Found %s serial flash (size: %dKiB, blocksize: 0x%X, blocks: %d)\n",
0155         e->name, sflash->size / 1024, e->blocksize, e->numblocks);
0156 
0157     /* Prepare platform device, but don't register it yet. It's too early,
0158      * malloc (required by device_private_init) is not available yet. */
0159     ssb_sflash_dev.resource[0].end = ssb_sflash_dev.resource[0].start +
0160                      sflash->size;
0161     ssb_sflash_dev.dev.platform_data = sflash;
0162 
0163     return 0;
0164 }