Path: blob/master/drivers/bcma/driver_chipcommon_sflash.c
26278 views
/*1* Broadcom specific AMBA2* ChipCommon serial flash interface3*4* Licensed under the GNU/GPL. See COPYING for details.5*/67#include "bcma_private.h"89#include <linux/platform_device.h>10#include <linux/bcma/bcma.h>1112static struct resource bcma_sflash_resource = {13.name = "bcma_sflash",14.start = BCMA_SOC_FLASH2,15.end = 0,16.flags = IORESOURCE_MEM | IORESOURCE_READONLY,17};1819struct platform_device bcma_sflash_dev = {20.name = "bcma_sflash",21.resource = &bcma_sflash_resource,22.num_resources = 1,23};2425struct bcma_sflash_tbl_e {26char *name;27u32 id;28u32 blocksize;29u16 numblocks;30};3132static const struct bcma_sflash_tbl_e bcma_sflash_st_tbl[] = {33{ "M25P20", 0x11, 0x10000, 4, },34{ "M25P40", 0x12, 0x10000, 8, },3536{ "M25P16", 0x14, 0x10000, 32, },37{ "M25P32", 0x15, 0x10000, 64, },38{ "M25P64", 0x16, 0x10000, 128, },39{ "M25FL128", 0x17, 0x10000, 256, },40{ "MX25L25635F", 0x18, 0x10000, 512, },41{ NULL },42};4344static const struct bcma_sflash_tbl_e bcma_sflash_sst_tbl[] = {45{ "SST25WF512", 1, 0x1000, 16, },46{ "SST25VF512", 0x48, 0x1000, 16, },47{ "SST25WF010", 2, 0x1000, 32, },48{ "SST25VF010", 0x49, 0x1000, 32, },49{ "SST25WF020", 3, 0x1000, 64, },50{ "SST25VF020", 0x43, 0x1000, 64, },51{ "SST25WF040", 4, 0x1000, 128, },52{ "SST25VF040", 0x44, 0x1000, 128, },53{ "SST25VF040B", 0x8d, 0x1000, 128, },54{ "SST25WF080", 5, 0x1000, 256, },55{ "SST25VF080B", 0x8e, 0x1000, 256, },56{ "SST25VF016", 0x41, 0x1000, 512, },57{ "SST25VF032", 0x4a, 0x1000, 1024, },58{ "SST25VF064", 0x4b, 0x1000, 2048, },59{ NULL },60};6162static const struct bcma_sflash_tbl_e bcma_sflash_at_tbl[] = {63{ "AT45DB011", 0xc, 256, 512, },64{ "AT45DB021", 0x14, 256, 1024, },65{ "AT45DB041", 0x1c, 256, 2048, },66{ "AT45DB081", 0x24, 256, 4096, },67{ "AT45DB161", 0x2c, 512, 4096, },68{ "AT45DB321", 0x34, 512, 8192, },69{ "AT45DB642", 0x3c, 1024, 8192, },70{ NULL },71};7273static void bcma_sflash_cmd(struct bcma_drv_cc *cc, u32 opcode)74{75int i;76bcma_cc_write32(cc, BCMA_CC_FLASHCTL,77BCMA_CC_FLASHCTL_START | opcode);78for (i = 0; i < 1000; i++) {79if (!(bcma_cc_read32(cc, BCMA_CC_FLASHCTL) &80BCMA_CC_FLASHCTL_BUSY))81return;82cpu_relax();83}84bcma_err(cc->core->bus, "SFLASH control command failed (timeout)!\n");85}8687/* Initialize serial flash access */88int bcma_sflash_init(struct bcma_drv_cc *cc)89{90struct bcma_bus *bus = cc->core->bus;91struct bcma_sflash *sflash = &cc->sflash;92const struct bcma_sflash_tbl_e *e;93u32 id, id2;9495switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {96case BCMA_CC_FLASHT_STSER:97bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_DP);9899bcma_cc_write32(cc, BCMA_CC_FLASHADDR, 0);100bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_RES);101id = bcma_cc_read32(cc, BCMA_CC_FLASHDATA);102103bcma_cc_write32(cc, BCMA_CC_FLASHADDR, 1);104bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_RES);105id2 = bcma_cc_read32(cc, BCMA_CC_FLASHDATA);106107switch (id) {108case 0xbf:109for (e = bcma_sflash_sst_tbl; e->name; e++) {110if (e->id == id2)111break;112}113break;114case 0x13:115return -ENOTSUPP;116default:117for (e = bcma_sflash_st_tbl; e->name; e++) {118if (e->id == id)119break;120}121break;122}123if (!e->name) {124bcma_err(bus, "Unsupported ST serial flash (id: 0x%X, id2: 0x%X)\n", id, id2);125return -ENOTSUPP;126}127128break;129case BCMA_CC_FLASHT_ATSER:130bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_AT_STATUS);131id = bcma_cc_read32(cc, BCMA_CC_FLASHDATA) & 0x3c;132133for (e = bcma_sflash_at_tbl; e->name; e++) {134if (e->id == id)135break;136}137if (!e->name) {138bcma_err(bus, "Unsupported Atmel serial flash (id: 0x%X)\n", id);139return -ENOTSUPP;140}141142break;143default:144bcma_err(bus, "Unsupported flash type\n");145return -ENOTSUPP;146}147148sflash->blocksize = e->blocksize;149sflash->numblocks = e->numblocks;150sflash->size = sflash->blocksize * sflash->numblocks;151sflash->present = true;152153bcma_info(bus, "Found %s serial flash (size: %dKiB, blocksize: 0x%X, blocks: %d)\n",154e->name, sflash->size / 1024, sflash->blocksize,155sflash->numblocks);156157/* Prepare platform device, but don't register it yet. It's too early,158* malloc (required by device_private_init) is not available yet. */159bcma_sflash_dev.resource[0].end = bcma_sflash_dev.resource[0].start +160sflash->size;161bcma_sflash_dev.dev.platform_data = sflash;162163return 0;164}165166167