Skip to content

Commit 947e00c

Browse files
Graham MooreDinh Nguyen
authored andcommitted
mtd: m25p80: Add shutdown handler for m25p80 and spi-nor
Add shutdown handler for m25p80 and spi-nor so that 3-byte addressing mode is set before reboot. Signed-off-by: Graham Moore <[email protected]> [dinguyen] Cleaned up commit message Signed-off-by: Dinh Nguyen <[email protected]>
1 parent 425b1d9 commit 947e00c

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

drivers/mtd/devices/m25p80.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ static int m25p_remove(struct spi_device *spi)
227227
return mtd_device_unregister(&flash->spi_nor.mtd);
228228
}
229229

230+
static void m25p_shutdown(struct spi_device *spi)
231+
{
232+
struct m25p *flash = spi_get_drvdata(spi);
233+
flash->spi_nor.shutdown(&flash->spi_nor);
234+
}
235+
230236
/*
231237
* Do NOT add to this array without reading the following:
232238
*
@@ -297,6 +303,7 @@ static struct spi_driver m25p80_driver = {
297303
.id_table = m25p_ids,
298304
.probe = m25p_probe,
299305
.remove = m25p_remove,
306+
.shutdown = m25p_shutdown,
300307

301308
/* REVISIT: many of these chips have deep power-down modes, which
302309
* should clearly be entered on suspend() to minimize power use.

drivers/mtd/spi-nor/spi-nor.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,9 @@ static int macronix_quad_enable(struct spi_nor *nor)
11741174
return -EINVAL;
11751175
}
11761176

1177+
if (!nor->shutdown)
1178+
nor->shutdown = spi_nor_shutdown;
1179+
11771180
return 0;
11781181
}
11791182

@@ -1239,6 +1242,11 @@ static int set_quad_mode(struct spi_nor *nor, const struct flash_info *info)
12391242
}
12401243
}
12411244

1245+
static void spi_nor_shutdown(struct spi_nor *nor)
1246+
{
1247+
set_4byte(nor, nor->jedec_id, 0);
1248+
}
1249+
12421250
static int spi_nor_check(struct spi_nor *nor)
12431251
{
12441252
if (!nor->dev || !nor->read || !nor->write ||
@@ -1297,6 +1305,8 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
12971305

12981306
mutex_init(&nor->lock);
12991307

1308+
nor->jedec_id = info->jedec_id;
1309+
13001310
/*
13011311
* Atmel, SST, Intel/Numonyx, and others serial NOR tend to power up
13021312
* with the software protection bits set

include/linux/mtd/spi-nor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ struct spi_nor {
162162
u8 read_opcode;
163163
u8 read_dummy;
164164
u8 program_opcode;
165+
u32 jedec_id;
166+
165167
enum read_mode flash_read;
166168
bool sst_write_second;
167169
u32 flags;
@@ -171,6 +173,7 @@ struct spi_nor {
171173
void (*unprepare)(struct spi_nor *nor, enum spi_nor_ops ops);
172174
int (*read_reg)(struct spi_nor *nor, u8 opcode, u8 *buf, int len);
173175
int (*write_reg)(struct spi_nor *nor, u8 opcode, u8 *buf, int len);
176+
void (*shutdown)(struct spi_nor *nor);
174177

175178
int (*read)(struct spi_nor *nor, loff_t from,
176179
size_t len, size_t *retlen, u_char *read_buf);

0 commit comments

Comments
 (0)