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