blob: fa7ac8c9322fd20ef39ef786b0fffd1ae9192b1b [file] [log] [blame]
Mingkai Hu6805e4b2009-03-31 14:09:41 +08001/*
2 * Copyright (C) 2009 Freescale Semiconductor, Inc.
3 *
4 * Author: Mingkai Hu (Mingkai.hu@freescale.com)
5 * Based on stmicro.c by Wolfgang Denk (wd@denx.de),
6 * TsiChung Liew (Tsi-Chung.Liew@freescale.com),
7 * and Jason McMullan (mcmullan@netapp.com)
8 *
Jagannadha Sutradharudu Teki5928b9a2013-07-29 22:43:57 +05309 * SPDX-License-Identifier: GPL-2.0+
Mingkai Hu6805e4b2009-03-31 14:09:41 +080010 */
11
12#include <common.h>
13#include <malloc.h>
14#include <spi_flash.h>
15
16#include "spi_flash_internal.h"
17
Mingkai Hu6805e4b2009-03-31 14:09:41 +080018struct spansion_spi_flash_params {
19 u16 idcode1;
20 u16 idcode2;
Mingkai Hu6805e4b2009-03-31 14:09:41 +080021 u16 pages_per_sector;
22 u16 nr_sectors;
23 const char *name;
24};
25
Mingkai Hu6805e4b2009-03-31 14:09:41 +080026static const struct spansion_spi_flash_params spansion_spi_flash_table[] = {
27 {
Mike Frysinger7d72b802012-01-28 16:32:18 -080028 .idcode1 = 0x0213,
Mingkai Hu6805e4b2009-03-31 14:09:41 +080029 .idcode2 = 0,
Mingkai Hu6805e4b2009-03-31 14:09:41 +080030 .pages_per_sector = 256,
31 .nr_sectors = 16,
32 .name = "S25FL008A",
33 },
34 {
Mike Frysinger7d72b802012-01-28 16:32:18 -080035 .idcode1 = 0x0214,
Mingkai Hu6805e4b2009-03-31 14:09:41 +080036 .idcode2 = 0,
Mingkai Hu6805e4b2009-03-31 14:09:41 +080037 .pages_per_sector = 256,
38 .nr_sectors = 32,
39 .name = "S25FL016A",
40 },
41 {
Mike Frysinger7d72b802012-01-28 16:32:18 -080042 .idcode1 = 0x0215,
Mingkai Hu6805e4b2009-03-31 14:09:41 +080043 .idcode2 = 0,
Mingkai Hu6805e4b2009-03-31 14:09:41 +080044 .pages_per_sector = 256,
45 .nr_sectors = 64,
46 .name = "S25FL032A",
47 },
48 {
Mike Frysinger7d72b802012-01-28 16:32:18 -080049 .idcode1 = 0x0216,
Mingkai Hu6805e4b2009-03-31 14:09:41 +080050 .idcode2 = 0,
Mingkai Hu6805e4b2009-03-31 14:09:41 +080051 .pages_per_sector = 256,
52 .nr_sectors = 128,
53 .name = "S25FL064A",
54 },
55 {
Mike Frysinger7d72b802012-01-28 16:32:18 -080056 .idcode1 = 0x2018,
57 .idcode2 = 0x0301,
Mingkai Hu6805e4b2009-03-31 14:09:41 +080058 .pages_per_sector = 256,
59 .nr_sectors = 256,
60 .name = "S25FL128P_64K",
61 },
62 {
Mike Frysinger7d72b802012-01-28 16:32:18 -080063 .idcode1 = 0x2018,
64 .idcode2 = 0x0300,
Mingkai Hu6805e4b2009-03-31 14:09:41 +080065 .pages_per_sector = 1024,
66 .nr_sectors = 64,
67 .name = "S25FL128P_256K",
68 },
David Janderff0dc2c2010-08-23 15:12:16 +020069 {
Mike Frysinger7d72b802012-01-28 16:32:18 -080070 .idcode1 = 0x0215,
71 .idcode2 = 0x4d00,
David Janderff0dc2c2010-08-23 15:12:16 +020072 .pages_per_sector = 256,
73 .nr_sectors = 64,
74 .name = "S25FL032P",
75 },
Shaohui Xie9445ce02011-04-20 20:07:11 +000076 {
Marek Vasute90f7bd2012-08-28 15:13:37 +000077 .idcode1 = 0x0216,
78 .idcode2 = 0x4d00,
79 .pages_per_sector = 256,
80 .nr_sectors = 128,
81 .name = "S25FL064P",
82 },
83 {
Mike Frysinger7d72b802012-01-28 16:32:18 -080084 .idcode1 = 0x2018,
85 .idcode2 = 0x4d01,
Shaohui Xie9445ce02011-04-20 20:07:11 +000086 .pages_per_sector = 256,
87 .nr_sectors = 256,
Jagannadha Sutradharudu Teki6fd10002013-06-14 21:03:51 +053088 .name = "S25FL129P_64K/S25FL128S_64K",
Shaohui Xie9445ce02011-04-20 20:07:11 +000089 },
Michal Simek4a4cb4e2012-08-14 13:11:22 +020090 {
Jagannadha Sutradharudu Teki4e994c12012-09-14 20:46:11 +053091 .idcode1 = 0x0219,
Michal Simek4a4cb4e2012-08-14 13:11:22 +020092 .idcode2 = 0x4d01,
93 .pages_per_sector = 256,
94 .nr_sectors = 512,
Jagannadha Sutradharudu Teki59120ca2013-05-25 23:03:11 +053095 .name = "S25FL256S_64K",
Michal Simek4a4cb4e2012-08-14 13:11:22 +020096 },
Jagannadha Sutradharudu Teki76e98d42013-06-10 23:41:57 +053097 {
98 .idcode1 = 0x0220,
99 .idcode2 = 0x4d01,
100 .pages_per_sector = 256,
101 .nr_sectors = 1024,
102 .name = "S25FL512S_64K",
103 },
Mingkai Hu6805e4b2009-03-31 14:09:41 +0800104};
105
Mingkai Hu6805e4b2009-03-31 14:09:41 +0800106struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
107{
108 const struct spansion_spi_flash_params *params;
Mike Frysingerb06afa72011-06-28 07:38:10 +0000109 struct spi_flash *flash;
Mingkai Hu6805e4b2009-03-31 14:09:41 +0800110 unsigned int i;
111 unsigned short jedec, ext_jedec;
Mingkai Hu6805e4b2009-03-31 14:09:41 +0800112
Mike Frysinger0dcdbb12009-03-28 06:41:09 -0400113 jedec = idcode[1] << 8 | idcode[2];
114 ext_jedec = idcode[3] << 8 | idcode[4];
Mingkai Hu6805e4b2009-03-31 14:09:41 +0800115
116 for (i = 0; i < ARRAY_SIZE(spansion_spi_flash_table); i++) {
117 params = &spansion_spi_flash_table[i];
118 if (params->idcode1 == jedec) {
119 if (params->idcode2 == ext_jedec)
120 break;
121 }
122 }
123
124 if (i == ARRAY_SIZE(spansion_spi_flash_table)) {
Jagannadha Sutradharudu Teki5a9109f2013-05-25 22:03:39 +0530125 debug("SF: Unsupported SPANSION ID %04x %04x\n",
126 jedec, ext_jedec);
Mingkai Hu6805e4b2009-03-31 14:09:41 +0800127 return NULL;
128 }
129
Simon Glassc0f87dd2013-03-11 06:08:03 +0000130 flash = spi_flash_alloc_base(spi, params->name);
Mike Frysingerb06afa72011-06-28 07:38:10 +0000131 if (!flash) {
Mingkai Hu6805e4b2009-03-31 14:09:41 +0800132 debug("SF: Failed to allocate memory\n");
133 return NULL;
134 }
135
Mike Frysingera4ed3b62012-03-04 22:56:52 -0500136 flash->page_size = 256;
137 flash->sector_size = 256 * params->pages_per_sector;
Mike Frysingerb06afa72011-06-28 07:38:10 +0000138 flash->size = flash->sector_size * params->nr_sectors;
Mingkai Hu6805e4b2009-03-31 14:09:41 +0800139
Mike Frysingerb06afa72011-06-28 07:38:10 +0000140 return flash;
Mingkai Hu6805e4b2009-03-31 14:09:41 +0800141}