aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorHuang Shijie <shijie.huang@intel.com>2014-11-05 22:24:33 -0500
committerBrian Norris <computersforpeace@gmail.com>2014-12-01 03:10:39 -0500
commitd928a259385dc6fca3956b7775c588f21c0b50fc (patch)
tree0cbece16e9ee37a801134a617d8426adff4171e0 /drivers/mtd
parent09ffafb6977dc930770af2910edc3b469651131d (diff)
mtd: spi-nor: remove the jedec_id/ext_id
The "id" array contains all the information about the JEDEC and the manufacturer ID info. This patch removes the jedec_id/ext_id from flash_info. Signed-off-by: Huang Shijie <shijie.huang@intel.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/spi-nor/spi-nor.c98
1 files changed, 45 insertions, 53 deletions
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 786344f08675..6d03622d9965 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -26,7 +26,38 @@
26/* Define max times to check status register before we give up. */ 26/* Define max times to check status register before we give up. */
27#define MAX_READY_WAIT_JIFFIES (40 * HZ) /* M25P16 specs 40s max chip erase */ 27#define MAX_READY_WAIT_JIFFIES (40 * HZ) /* M25P16 specs 40s max chip erase */
28 28
29#define JEDEC_MFR(_jedec_id) ((_jedec_id) >> 16) 29#define SPI_NOR_MAX_ID_LEN 6
30
31struct flash_info {
32 /*
33 * This array stores the ID bytes.
34 * The first three bytes are the JEDIC ID.
35 * JEDEC ID zero means "no ID" (mostly older chips).
36 */
37 u8 id[SPI_NOR_MAX_ID_LEN];
38 u8 id_len;
39
40 /* The size listed here is what works with SPINOR_OP_SE, which isn't
41 * necessarily called a "sector" by the vendor.
42 */
43 unsigned sector_size;
44 u16 n_sectors;
45
46 u16 page_size;
47 u16 addr_width;
48
49 u16 flags;
50#define SECT_4K 0x01 /* SPINOR_OP_BE_4K works uniformly */
51#define SPI_NOR_NO_ERASE 0x02 /* No erase command needed */
52#define SST_WRITE 0x04 /* use SST byte programming */
53#define SPI_NOR_NO_FR 0x08 /* Can't do fastread */
54#define SECT_4K_PMC 0x10 /* SPINOR_OP_BE_4K_PMC works uniformly */
55#define SPI_NOR_DUAL_READ 0x20 /* Flash supports Dual Read */
56#define SPI_NOR_QUAD_READ 0x40 /* Flash supports Quad Read */
57#define USE_FSR 0x80 /* use flag status register */
58};
59
60#define JEDEC_MFR(info) ((info)->id[0])
30 61
31static const struct spi_device_id *spi_nor_match_id(const char *name); 62static const struct spi_device_id *spi_nor_match_id(const char *name);
32 63
@@ -138,13 +169,14 @@ static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd)
138} 169}
139 170
140/* Enable/disable 4-byte addressing mode. */ 171/* Enable/disable 4-byte addressing mode. */
141static inline int set_4byte(struct spi_nor *nor, u32 jedec_id, int enable) 172static inline int set_4byte(struct spi_nor *nor, struct flash_info *info,
173 int enable)
142{ 174{
143 int status; 175 int status;
144 bool need_wren = false; 176 bool need_wren = false;
145 u8 cmd; 177 u8 cmd;
146 178
147 switch (JEDEC_MFR(jedec_id)) { 179 switch (JEDEC_MFR(info)) {
148 case CFI_MFR_ST: /* Micron, actually */ 180 case CFI_MFR_ST: /* Micron, actually */
149 /* Some Micron need WREN command; all will accept it */ 181 /* Some Micron need WREN command; all will accept it */
150 need_wren = true; 182 need_wren = true;
@@ -418,49 +450,9 @@ err:
418 return ret; 450 return ret;
419} 451}
420 452
421#define SPI_NOR_MAX_ID_LEN 6
422
423struct flash_info {
424 /* JEDEC id zero means "no ID" (most older chips); otherwise it has
425 * a high byte of zero plus three data bytes: the manufacturer id,
426 * then a two byte device id.
427 */
428 u32 jedec_id;
429 u16 ext_id;
430
431 /*
432 * This array stores the ID bytes.
433 * The first three bytes are the JEDIC ID.
434 * JEDEC ID zero means "no ID" (mostly older chips).
435 */
436 u8 id[SPI_NOR_MAX_ID_LEN];
437 u8 id_len;
438
439 /* The size listed here is what works with SPINOR_OP_SE, which isn't
440 * necessarily called a "sector" by the vendor.
441 */
442 unsigned sector_size;
443 u16 n_sectors;
444
445 u16 page_size;
446 u16 addr_width;
447
448 u16 flags;
449#define SECT_4K 0x01 /* SPINOR_OP_BE_4K works uniformly */
450#define SPI_NOR_NO_ERASE 0x02 /* No erase command needed */
451#define SST_WRITE 0x04 /* use SST byte programming */
452#define SPI_NOR_NO_FR 0x08 /* Can't do fastread */
453#define SECT_4K_PMC 0x10 /* SPINOR_OP_BE_4K_PMC works uniformly */
454#define SPI_NOR_DUAL_READ 0x20 /* Flash supports Dual Read */
455#define SPI_NOR_QUAD_READ 0x40 /* Flash supports Quad Read */
456#define USE_FSR 0x80 /* use flag status register */
457};
458
459/* Used when the "_ext_id" is two bytes at most */ 453/* Used when the "_ext_id" is two bytes at most */
460#define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \ 454#define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \
461 ((kernel_ulong_t)&(struct flash_info) { \ 455 ((kernel_ulong_t)&(struct flash_info) { \
462 .jedec_id = (_jedec_id), \
463 .ext_id = (_ext_id), \
464 .id = { \ 456 .id = { \
465 ((_jedec_id) >> 16) & 0xff, \ 457 ((_jedec_id) >> 16) & 0xff, \
466 ((_jedec_id) >> 8) & 0xff, \ 458 ((_jedec_id) >> 8) & 0xff, \
@@ -878,11 +870,11 @@ static int spansion_quad_enable(struct spi_nor *nor)
878 return 0; 870 return 0;
879} 871}
880 872
881static int set_quad_mode(struct spi_nor *nor, u32 jedec_id) 873static int set_quad_mode(struct spi_nor *nor, struct flash_info *info)
882{ 874{
883 int status; 875 int status;
884 876
885 switch (JEDEC_MFR(jedec_id)) { 877 switch (JEDEC_MFR(info)) {
886 case CFI_MFR_MACRONIX: 878 case CFI_MFR_MACRONIX:
887 status = macronix_quad_enable(nor); 879 status = macronix_quad_enable(nor);
888 if (status) { 880 if (status) {
@@ -931,7 +923,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
931 923
932 info = (void *)id->driver_data; 924 info = (void *)id->driver_data;
933 925
934 if (info->jedec_id) { 926 if (info->id_len) {
935 const struct spi_device_id *jid; 927 const struct spi_device_id *jid;
936 928
937 jid = spi_nor_read_id(nor); 929 jid = spi_nor_read_id(nor);
@@ -959,9 +951,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
959 * up with the software protection bits set 951 * up with the software protection bits set
960 */ 952 */
961 953
962 if (JEDEC_MFR(info->jedec_id) == CFI_MFR_ATMEL || 954 if (JEDEC_MFR(info) == CFI_MFR_ATMEL ||
963 JEDEC_MFR(info->jedec_id) == CFI_MFR_INTEL || 955 JEDEC_MFR(info) == CFI_MFR_INTEL ||
964 JEDEC_MFR(info->jedec_id) == CFI_MFR_SST) { 956 JEDEC_MFR(info) == CFI_MFR_SST) {
965 write_enable(nor); 957 write_enable(nor);
966 write_sr(nor, 0); 958 write_sr(nor, 0);
967 } 959 }
@@ -976,7 +968,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
976 mtd->_read = spi_nor_read; 968 mtd->_read = spi_nor_read;
977 969
978 /* nor protection support for STmicro chips */ 970 /* nor protection support for STmicro chips */
979 if (JEDEC_MFR(info->jedec_id) == CFI_MFR_ST) { 971 if (JEDEC_MFR(info) == CFI_MFR_ST) {
980 mtd->_lock = spi_nor_lock; 972 mtd->_lock = spi_nor_lock;
981 mtd->_unlock = spi_nor_unlock; 973 mtd->_unlock = spi_nor_unlock;
982 } 974 }
@@ -1029,7 +1021,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
1029 1021
1030 /* Quad/Dual-read mode takes precedence over fast/normal */ 1022 /* Quad/Dual-read mode takes precedence over fast/normal */
1031 if (mode == SPI_NOR_QUAD && info->flags & SPI_NOR_QUAD_READ) { 1023 if (mode == SPI_NOR_QUAD && info->flags & SPI_NOR_QUAD_READ) {
1032 ret = set_quad_mode(nor, info->jedec_id); 1024 ret = set_quad_mode(nor, info);
1033 if (ret) { 1025 if (ret) {
1034 dev_err(dev, "quad mode not supported\n"); 1026 dev_err(dev, "quad mode not supported\n");
1035 return ret; 1027 return ret;
@@ -1065,7 +1057,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
1065 else if (mtd->size > 0x1000000) { 1057 else if (mtd->size > 0x1000000) {
1066 /* enable 4-byte addressing if the device exceeds 16MiB */ 1058 /* enable 4-byte addressing if the device exceeds 16MiB */
1067 nor->addr_width = 4; 1059 nor->addr_width = 4;
1068 if (JEDEC_MFR(info->jedec_id) == CFI_MFR_AMD) { 1060 if (JEDEC_MFR(info) == CFI_MFR_AMD) {
1069 /* Dedicated 4-byte command set */ 1061 /* Dedicated 4-byte command set */
1070 switch (nor->flash_read) { 1062 switch (nor->flash_read) {
1071 case SPI_NOR_QUAD: 1063 case SPI_NOR_QUAD:
@@ -1086,7 +1078,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
1086 nor->erase_opcode = SPINOR_OP_SE_4B; 1078 nor->erase_opcode = SPINOR_OP_SE_4B;
1087 mtd->erasesize = info->sector_size; 1079 mtd->erasesize = info->sector_size;
1088 } else 1080 } else
1089 set_4byte(nor, info->jedec_id, 1); 1081 set_4byte(nor, info, 1);
1090 } else { 1082 } else {
1091 nor->addr_width = 3; 1083 nor->addr_width = 3;
1092 } 1084 }