2006-01-09 05:34:27 +08:00
|
|
|
/*
|
2007-06-25 06:12:35 +08:00
|
|
|
* MTD SPI driver for ST M25Pxx (and similar) serial flash chips
|
2006-01-09 05:34:27 +08:00
|
|
|
*
|
|
|
|
* Author: Mike Lavender, mike@steroidmicros.com
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005, Intec Automation Inc.
|
|
|
|
*
|
|
|
|
* Some parts are based on lart.c by Abraham Van Der Merwe
|
|
|
|
*
|
|
|
|
* Cleaned up and generalized based on mtd_dataflash.c
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-06-23 00:57:42 +08:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/errno.h>
|
2006-01-09 05:34:27 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/device.h>
|
2007-06-25 06:09:13 +08:00
|
|
|
|
2006-01-09 05:34:27 +08:00
|
|
|
#include <linux/mtd/mtd.h>
|
|
|
|
#include <linux/mtd/partitions.h>
|
2007-06-25 06:09:13 +08:00
|
|
|
|
2006-01-09 05:34:27 +08:00
|
|
|
#include <linux/spi/spi.h>
|
2018-04-27 00:18:19 +08:00
|
|
|
#include <linux/spi/spi-mem.h>
|
2006-01-09 05:34:27 +08:00
|
|
|
#include <linux/spi/flash.h>
|
2014-03-20 20:00:12 +08:00
|
|
|
#include <linux/mtd/spi-nor.h>
|
2006-01-09 05:34:27 +08:00
|
|
|
|
|
|
|
struct m25p {
|
2018-04-27 00:18:19 +08:00
|
|
|
struct spi_mem *spimem;
|
2014-03-20 20:00:12 +08:00
|
|
|
struct spi_nor spi_nor;
|
2006-01-09 05:34:27 +08:00
|
|
|
};
|
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
static int m25p80_read_reg(struct spi_nor *nor, u8 code, u8 *val, int len)
|
2013-11-06 22:35:35 +08:00
|
|
|
{
|
2014-03-20 20:00:12 +08:00
|
|
|
struct m25p *flash = nor->priv;
|
2018-04-27 00:18:19 +08:00
|
|
|
struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(code, 1),
|
|
|
|
SPI_MEM_OP_NO_ADDR,
|
|
|
|
SPI_MEM_OP_NO_DUMMY,
|
2018-09-17 22:31:30 +08:00
|
|
|
SPI_MEM_OP_DATA_IN(len, NULL, 1));
|
|
|
|
void *scratchbuf;
|
2013-11-06 22:35:35 +08:00
|
|
|
int ret;
|
|
|
|
|
2018-09-17 22:31:30 +08:00
|
|
|
scratchbuf = kmalloc(len, GFP_KERNEL);
|
|
|
|
if (!scratchbuf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
op.data.buf.in = scratchbuf;
|
2018-04-27 00:18:19 +08:00
|
|
|
ret = spi_mem_exec_op(flash->spimem, &op);
|
2014-03-20 20:00:12 +08:00
|
|
|
if (ret < 0)
|
2018-04-27 00:18:19 +08:00
|
|
|
dev_err(&flash->spimem->spi->dev, "error %d reading %x\n", ret,
|
|
|
|
code);
|
2018-09-17 22:31:30 +08:00
|
|
|
else
|
|
|
|
memcpy(val, scratchbuf, len);
|
|
|
|
|
|
|
|
kfree(scratchbuf);
|
2008-08-11 16:59:13 +08:00
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
return ret;
|
2008-08-11 16:59:13 +08:00
|
|
|
}
|
2006-01-09 05:34:27 +08:00
|
|
|
|
2015-08-19 17:56:44 +08:00
|
|
|
static int m25p80_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
|
2006-01-09 05:34:27 +08:00
|
|
|
{
|
2014-03-20 20:00:12 +08:00
|
|
|
struct m25p *flash = nor->priv;
|
2018-04-27 00:18:19 +08:00
|
|
|
struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(opcode, 1),
|
|
|
|
SPI_MEM_OP_NO_ADDR,
|
|
|
|
SPI_MEM_OP_NO_DUMMY,
|
2018-09-17 22:31:30 +08:00
|
|
|
SPI_MEM_OP_DATA_OUT(len, NULL, 1));
|
|
|
|
void *scratchbuf;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
scratchbuf = kmemdup(buf, len, GFP_KERNEL);
|
|
|
|
if (!scratchbuf)
|
|
|
|
return -ENOMEM;
|
2006-01-09 05:34:27 +08:00
|
|
|
|
2018-09-17 22:31:30 +08:00
|
|
|
op.data.buf.out = scratchbuf;
|
|
|
|
ret = spi_mem_exec_op(flash->spimem, &op);
|
|
|
|
kfree(scratchbuf);
|
|
|
|
|
|
|
|
return ret;
|
2006-01-09 05:34:27 +08:00
|
|
|
}
|
|
|
|
|
2016-05-06 08:31:47 +08:00
|
|
|
static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len,
|
2016-05-06 08:31:53 +08:00
|
|
|
const u_char *buf)
|
2006-01-09 05:34:27 +08:00
|
|
|
{
|
2014-03-20 20:00:12 +08:00
|
|
|
struct m25p *flash = nor->priv;
|
2018-04-27 00:18:19 +08:00
|
|
|
struct spi_mem_op op =
|
|
|
|
SPI_MEM_OP(SPI_MEM_OP_CMD(nor->program_opcode, 1),
|
|
|
|
SPI_MEM_OP_ADDR(nor->addr_width, to, 1),
|
2018-06-01 18:03:25 +08:00
|
|
|
SPI_MEM_OP_NO_DUMMY,
|
2018-04-27 00:18:19 +08:00
|
|
|
SPI_MEM_OP_DATA_OUT(len, buf, 1));
|
|
|
|
int ret;
|
2008-11-26 18:23:57 +08:00
|
|
|
|
2017-04-26 04:08:47 +08:00
|
|
|
/* get transfer protocols. */
|
2018-04-27 00:18:19 +08:00
|
|
|
op.cmd.buswidth = spi_nor_get_protocol_inst_nbits(nor->write_proto);
|
|
|
|
op.addr.buswidth = spi_nor_get_protocol_addr_nbits(nor->write_proto);
|
|
|
|
op.data.buswidth = spi_nor_get_protocol_data_nbits(nor->write_proto);
|
2008-11-26 18:23:57 +08:00
|
|
|
|
2014-04-09 09:15:31 +08:00
|
|
|
if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second)
|
2018-04-27 00:18:19 +08:00
|
|
|
op.addr.nbytes = 0;
|
2006-01-09 05:34:27 +08:00
|
|
|
|
2018-06-13 14:09:18 +08:00
|
|
|
ret = spi_mem_adjust_op_size(flash->spimem, &op);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
op.data.nbytes = len < op.data.nbytes ? len : op.data.nbytes;
|
2017-04-26 04:08:47 +08:00
|
|
|
|
2018-06-13 14:09:18 +08:00
|
|
|
ret = spi_mem_exec_op(flash->spimem, &op);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2017-04-26 04:08:47 +08:00
|
|
|
|
2018-06-13 14:09:18 +08:00
|
|
|
return op.data.nbytes;
|
2013-11-06 22:35:34 +08:00
|
|
|
}
|
|
|
|
|
2006-01-09 05:34:27 +08:00
|
|
|
/*
|
2014-03-20 20:00:12 +08:00
|
|
|
* Read an address range from the nor chip. The address range
|
2006-01-09 05:34:27 +08:00
|
|
|
* may be any size provided it is within the physical boundaries.
|
|
|
|
*/
|
2016-05-06 08:31:47 +08:00
|
|
|
static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
|
2016-05-06 08:31:53 +08:00
|
|
|
u_char *buf)
|
2006-01-09 05:34:27 +08:00
|
|
|
{
|
2014-03-20 20:00:12 +08:00
|
|
|
struct m25p *flash = nor->priv;
|
2018-04-27 00:18:19 +08:00
|
|
|
struct spi_mem_op op =
|
|
|
|
SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 1),
|
|
|
|
SPI_MEM_OP_ADDR(nor->addr_width, from, 1),
|
|
|
|
SPI_MEM_OP_DUMMY(nor->read_dummy, 1),
|
|
|
|
SPI_MEM_OP_DATA_IN(len, buf, 1));
|
|
|
|
size_t remaining = len;
|
|
|
|
int ret;
|
2017-04-26 04:08:47 +08:00
|
|
|
|
|
|
|
/* get transfer protocols. */
|
2018-04-27 00:18:19 +08:00
|
|
|
op.cmd.buswidth = spi_nor_get_protocol_inst_nbits(nor->read_proto);
|
|
|
|
op.addr.buswidth = spi_nor_get_protocol_addr_nbits(nor->read_proto);
|
|
|
|
op.dummy.buswidth = op.addr.buswidth;
|
|
|
|
op.data.buswidth = spi_nor_get_protocol_data_nbits(nor->read_proto);
|
2006-01-09 05:34:27 +08:00
|
|
|
|
2014-04-28 11:53:38 +08:00
|
|
|
/* convert the dummy cycles to the number of bytes */
|
2018-04-27 00:18:19 +08:00
|
|
|
op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8;
|
2016-03-29 13:46:17 +08:00
|
|
|
|
2018-04-27 00:18:19 +08:00
|
|
|
while (remaining) {
|
|
|
|
op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX;
|
|
|
|
ret = spi_mem_adjust_op_size(flash->spimem, &op);
|
|
|
|
if (ret)
|
2016-05-06 08:31:48 +08:00
|
|
|
return ret;
|
2016-03-29 13:46:17 +08:00
|
|
|
|
2018-04-27 00:18:19 +08:00
|
|
|
ret = spi_mem_exec_op(flash->spimem, &op);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2017-04-26 04:08:47 +08:00
|
|
|
|
2018-04-27 00:18:19 +08:00
|
|
|
op.addr.val += op.data.nbytes;
|
|
|
|
remaining -= op.data.nbytes;
|
|
|
|
op.data.buf.in += op.data.nbytes;
|
2017-04-26 04:08:47 +08:00
|
|
|
}
|
|
|
|
|
2018-04-27 00:18:19 +08:00
|
|
|
return len;
|
2006-01-09 05:34:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* board specific setup should have ensured the SPI clock used here
|
|
|
|
* matches what the READ command supports, at least until this driver
|
|
|
|
* understands FAST_READ (for clocks over 25 MHz).
|
|
|
|
*/
|
2018-04-27 00:18:19 +08:00
|
|
|
static int m25p_probe(struct spi_mem *spimem)
|
2006-01-09 05:34:27 +08:00
|
|
|
{
|
2018-04-27 00:18:19 +08:00
|
|
|
struct spi_device *spi = spimem->spi;
|
2014-03-20 20:00:12 +08:00
|
|
|
struct flash_platform_data *data;
|
|
|
|
struct m25p *flash;
|
|
|
|
struct spi_nor *nor;
|
2017-04-26 04:08:46 +08:00
|
|
|
struct spi_nor_hwcaps hwcaps = {
|
|
|
|
.mask = SNOR_HWCAPS_READ |
|
|
|
|
SNOR_HWCAPS_READ_FAST |
|
|
|
|
SNOR_HWCAPS_PP,
|
|
|
|
};
|
mtd: m25p80: fix module autoloading for "jedec, spi-nor" and "spi-nor"
Commit 43163022927b ("mtd: m25p80: allow arbitrary OF matching for
"jedec,spi-nor"") moved the "jedec,spi-nor" handling from the
spi_device_id table to the of_match_table, to better handle matching
complex device tree compatible strings. With that patch, device tree
support works as expected when m25p80.c is built into the kernel.
However, that commit ignored the fact that:
(1) (non-DT) platform devices might want to use the "spi-nor" string
for matching with this driver, rather than picking an arbitrary one
like "m25p80"
(2) the core SPI uevent/modalias code doesn't yet support kernel module
autoloading via of_match_table strings; so for DT-based devices, it
will only report (part of) the first compatible string used
Problem (1) has been reported previously, and I forgot to patch it up
afterward.
Problem (2) was noticed recently here:
http://lists.infradead.org/pipermail/linux-mtd/2015-October/062369.html
https://lkml.org/lkml/2015/11/12/574
Specifically, this patch fixes m25p80.ko module autoloading for cases
like this:
flash@xxx {
compatible = "jedec,spi-nor";
...
};
because modalias of "spi:spi-nor" (the only module loading info provided
by the SPI core for this device) will now be listed as an alias in
m25p80.ko.
Notably, it does *not* help cases like this:
flash@xxx {
compatible = "vendor,shiny-new-device", "jedec,spi-nor";
...
};
unless we also list "shiny-new-device" in m25p_ids[]. There has been
discussion on future work for this issue here:
https://lkml.org/lkml/2015/11/12/574
Cc: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
2015-11-17 06:34:50 +08:00
|
|
|
char *flash_name;
|
2013-11-06 22:35:35 +08:00
|
|
|
int ret;
|
2011-10-14 15:49:00 +08:00
|
|
|
|
2018-04-27 00:18:19 +08:00
|
|
|
data = dev_get_platdata(&spimem->spi->dev);
|
2014-09-29 04:36:54 +08:00
|
|
|
|
2018-04-27 00:18:19 +08:00
|
|
|
flash = devm_kzalloc(&spimem->spi->dev, sizeof(*flash), GFP_KERNEL);
|
2006-01-09 05:34:27 +08:00
|
|
|
if (!flash)
|
|
|
|
return -ENOMEM;
|
2013-07-25 09:32:07 +08:00
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
nor = &flash->spi_nor;
|
2008-07-04 14:54:42 +08:00
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
/* install the hooks */
|
|
|
|
nor->read = m25p80_read;
|
|
|
|
nor->write = m25p80_write;
|
|
|
|
nor->write_reg = m25p80_write_reg;
|
|
|
|
nor->read_reg = m25p80_read_reg;
|
2013-01-04 08:02:28 +08:00
|
|
|
|
2018-04-27 00:18:19 +08:00
|
|
|
nor->dev = &spimem->spi->dev;
|
2015-10-31 11:33:24 +08:00
|
|
|
spi_nor_set_flash_node(nor, spi->dev.of_node);
|
2014-03-20 20:00:12 +08:00
|
|
|
nor->priv = flash;
|
2006-01-09 05:34:27 +08:00
|
|
|
|
2018-05-22 18:55:14 +08:00
|
|
|
spi_mem_set_drvdata(spimem, flash);
|
2018-04-27 00:18:19 +08:00
|
|
|
flash->spimem = spimem;
|
2007-06-25 06:12:35 +08:00
|
|
|
|
2017-04-26 04:08:47 +08:00
|
|
|
if (spi->mode & SPI_RX_QUAD) {
|
2017-04-26 04:08:46 +08:00
|
|
|
hwcaps.mask |= SNOR_HWCAPS_READ_1_1_4;
|
2017-04-26 04:08:47 +08:00
|
|
|
|
|
|
|
if (spi->mode & SPI_TX_QUAD)
|
|
|
|
hwcaps.mask |= (SNOR_HWCAPS_READ_1_4_4 |
|
|
|
|
SNOR_HWCAPS_PP_1_1_4 |
|
|
|
|
SNOR_HWCAPS_PP_1_4_4);
|
|
|
|
} else if (spi->mode & SPI_RX_DUAL) {
|
2017-04-26 04:08:46 +08:00
|
|
|
hwcaps.mask |= SNOR_HWCAPS_READ_1_1_2;
|
2014-09-29 04:36:54 +08:00
|
|
|
|
2017-04-26 04:08:47 +08:00
|
|
|
if (spi->mode & SPI_TX_DUAL)
|
|
|
|
hwcaps.mask |= SNOR_HWCAPS_READ_1_2_2;
|
|
|
|
}
|
|
|
|
|
2014-09-29 04:36:54 +08:00
|
|
|
if (data && data->name)
|
2015-08-14 06:46:05 +08:00
|
|
|
nor->mtd.name = data->name;
|
2014-09-29 04:36:54 +08:00
|
|
|
|
2018-08-02 20:53:54 +08:00
|
|
|
if (!nor->mtd.name)
|
|
|
|
nor->mtd.name = spi_mem_get_name(spimem);
|
|
|
|
|
2014-09-29 04:36:54 +08:00
|
|
|
/* For some (historical?) reason many platforms provide two different
|
|
|
|
* names in flash_platform_data: "name" and "type". Quite often name is
|
|
|
|
* set to "m25p80" and then "type" provides a real chip name.
|
|
|
|
* If that's the case, respect "type" and ignore a "name".
|
|
|
|
*/
|
|
|
|
if (data && data->type)
|
2014-09-29 17:47:53 +08:00
|
|
|
flash_name = data->type;
|
mtd: m25p80: fix module autoloading for "jedec, spi-nor" and "spi-nor"
Commit 43163022927b ("mtd: m25p80: allow arbitrary OF matching for
"jedec,spi-nor"") moved the "jedec,spi-nor" handling from the
spi_device_id table to the of_match_table, to better handle matching
complex device tree compatible strings. With that patch, device tree
support works as expected when m25p80.c is built into the kernel.
However, that commit ignored the fact that:
(1) (non-DT) platform devices might want to use the "spi-nor" string
for matching with this driver, rather than picking an arbitrary one
like "m25p80"
(2) the core SPI uevent/modalias code doesn't yet support kernel module
autoloading via of_match_table strings; so for DT-based devices, it
will only report (part of) the first compatible string used
Problem (1) has been reported previously, and I forgot to patch it up
afterward.
Problem (2) was noticed recently here:
http://lists.infradead.org/pipermail/linux-mtd/2015-October/062369.html
https://lkml.org/lkml/2015/11/12/574
Specifically, this patch fixes m25p80.ko module autoloading for cases
like this:
flash@xxx {
compatible = "jedec,spi-nor";
...
};
because modalias of "spi:spi-nor" (the only module loading info provided
by the SPI core for this device) will now be listed as an alias in
m25p80.ko.
Notably, it does *not* help cases like this:
flash@xxx {
compatible = "vendor,shiny-new-device", "jedec,spi-nor";
...
};
unless we also list "shiny-new-device" in m25p_ids[]. There has been
discussion on future work for this issue here:
https://lkml.org/lkml/2015/11/12/574
Cc: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
2015-11-17 06:34:50 +08:00
|
|
|
else if (!strcmp(spi->modalias, "spi-nor"))
|
|
|
|
flash_name = NULL; /* auto-detect */
|
2014-09-29 17:47:53 +08:00
|
|
|
else
|
|
|
|
flash_name = spi->modalias;
|
2014-09-29 04:36:54 +08:00
|
|
|
|
2017-04-26 04:08:46 +08:00
|
|
|
ret = spi_nor_scan(nor, flash_name, &hwcaps);
|
2014-03-20 20:00:12 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
mtd: m25p80: Add support for CAT25xxx serial EEPROMs
CAT25 chips (as manufactured by On Semiconductor, previously Catalyst
Semiconductor) are similar to the original M25Px0 chips, except:
- Address width can vary (1-2 bytes, in contrast to 3 bytes in M25P
chips). So, implement convenient m25p_addr2cmd() and m25p_cmdsz()
calls, and place address width information into flash_info struct;
- Page size can vary, therefore we shouldn't hardcode it, so get rid
of FLASH_PAGESIZE definition, and place the page size information
into flash_info struct;
- CAT25 EEPROMs don't need to be erased, so add NO_ERASE flag, and
propagate it to the mtd subsystem.
[dwmw2: Fix up for conflicts with DMA safety patch]
Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
2009-10-13 00:24:40 +08:00
|
|
|
|
2015-10-31 11:33:26 +08:00
|
|
|
return mtd_device_register(&nor->mtd, data ? data->parts : NULL,
|
|
|
|
data ? data->nr_parts : 0);
|
2006-01-09 05:34:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-27 00:18:19 +08:00
|
|
|
static int m25p_remove(struct spi_mem *spimem)
|
2006-01-09 05:34:27 +08:00
|
|
|
{
|
2018-04-27 00:18:19 +08:00
|
|
|
struct m25p *flash = spi_mem_get_drvdata(spimem);
|
2006-01-09 05:34:27 +08:00
|
|
|
|
2017-12-06 10:53:42 +08:00
|
|
|
spi_nor_restore(&flash->spi_nor);
|
|
|
|
|
2006-01-09 05:34:27 +08:00
|
|
|
/* Clean up MTD stuff. */
|
2015-08-14 06:46:05 +08:00
|
|
|
return mtd_device_unregister(&flash->spi_nor.mtd);
|
2006-01-09 05:34:27 +08:00
|
|
|
}
|
|
|
|
|
2018-04-27 00:18:19 +08:00
|
|
|
static void m25p_shutdown(struct spi_mem *spimem)
|
2017-12-06 10:53:42 +08:00
|
|
|
{
|
2018-04-27 00:18:19 +08:00
|
|
|
struct m25p *flash = spi_mem_get_drvdata(spimem);
|
2017-12-06 10:53:42 +08:00
|
|
|
|
|
|
|
spi_nor_restore(&flash->spi_nor);
|
|
|
|
}
|
2014-09-30 10:14:55 +08:00
|
|
|
/*
|
2015-03-28 01:29:50 +08:00
|
|
|
* Do NOT add to this array without reading the following:
|
|
|
|
*
|
|
|
|
* Historically, many flash devices are bound to this driver by their name. But
|
|
|
|
* since most of these flash are compatible to some extent, and their
|
|
|
|
* differences can often be differentiated by the JEDEC read-ID command, we
|
|
|
|
* encourage new users to add support to the spi-nor library, and simply bind
|
2015-05-15 01:32:53 +08:00
|
|
|
* against a generic string here (e.g., "jedec,spi-nor").
|
2015-03-28 01:29:50 +08:00
|
|
|
*
|
|
|
|
* Many flash names are kept here in this list (as well as in spi-nor.c) to
|
|
|
|
* keep them available as module aliases for existing platforms.
|
2014-09-30 10:14:55 +08:00
|
|
|
*/
|
|
|
|
static const struct spi_device_id m25p_ids[] = {
|
mtd: m25p80: fix module autoloading for "jedec, spi-nor" and "spi-nor"
Commit 43163022927b ("mtd: m25p80: allow arbitrary OF matching for
"jedec,spi-nor"") moved the "jedec,spi-nor" handling from the
spi_device_id table to the of_match_table, to better handle matching
complex device tree compatible strings. With that patch, device tree
support works as expected when m25p80.c is built into the kernel.
However, that commit ignored the fact that:
(1) (non-DT) platform devices might want to use the "spi-nor" string
for matching with this driver, rather than picking an arbitrary one
like "m25p80"
(2) the core SPI uevent/modalias code doesn't yet support kernel module
autoloading via of_match_table strings; so for DT-based devices, it
will only report (part of) the first compatible string used
Problem (1) has been reported previously, and I forgot to patch it up
afterward.
Problem (2) was noticed recently here:
http://lists.infradead.org/pipermail/linux-mtd/2015-October/062369.html
https://lkml.org/lkml/2015/11/12/574
Specifically, this patch fixes m25p80.ko module autoloading for cases
like this:
flash@xxx {
compatible = "jedec,spi-nor";
...
};
because modalias of "spi:spi-nor" (the only module loading info provided
by the SPI core for this device) will now be listed as an alias in
m25p80.ko.
Notably, it does *not* help cases like this:
flash@xxx {
compatible = "vendor,shiny-new-device", "jedec,spi-nor";
...
};
unless we also list "shiny-new-device" in m25p_ids[]. There has been
discussion on future work for this issue here:
https://lkml.org/lkml/2015/11/12/574
Cc: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
2015-11-17 06:34:50 +08:00
|
|
|
/*
|
|
|
|
* Allow non-DT platform devices to bind to the "spi-nor" modalias, and
|
|
|
|
* hack around the fact that the SPI core does not provide uevent
|
|
|
|
* matching for .of_match_table
|
|
|
|
*/
|
|
|
|
{"spi-nor"},
|
|
|
|
|
2015-04-07 16:39:41 +08:00
|
|
|
/*
|
|
|
|
* Entries not used in DTs that should be safe to drop after replacing
|
2015-11-17 06:34:51 +08:00
|
|
|
* them with "spi-nor" in platform data.
|
2015-04-07 16:39:41 +08:00
|
|
|
*/
|
|
|
|
{"s25sl064a"}, {"w25x16"}, {"m25p10"}, {"m25px64"},
|
|
|
|
|
|
|
|
/*
|
2015-11-17 06:34:51 +08:00
|
|
|
* Entries that were used in DTs without "jedec,spi-nor" fallback and
|
|
|
|
* should be kept for backward compatibility.
|
2015-04-07 16:39:41 +08:00
|
|
|
*/
|
|
|
|
{"at25df321a"}, {"at25df641"}, {"at26df081a"},
|
|
|
|
{"mx25l4005a"}, {"mx25l1606e"}, {"mx25l6405d"}, {"mx25l12805d"},
|
|
|
|
{"mx25l25635e"},{"mx66l51235l"},
|
|
|
|
{"n25q064"}, {"n25q128a11"}, {"n25q128a13"}, {"n25q512a"},
|
|
|
|
{"s25fl256s1"}, {"s25fl512s"}, {"s25sl12801"}, {"s25fl008k"},
|
|
|
|
{"s25fl064k"},
|
|
|
|
{"sst25vf040b"},{"sst25vf016b"},{"sst25vf032b"},{"sst25wf040"},
|
|
|
|
{"m25p40"}, {"m25p80"}, {"m25p16"}, {"m25p32"},
|
|
|
|
{"m25p64"}, {"m25p128"},
|
|
|
|
{"w25x80"}, {"w25x32"}, {"w25q32"}, {"w25q32dw"},
|
|
|
|
{"w25q80bl"}, {"w25q128"}, {"w25q256"},
|
|
|
|
|
|
|
|
/* Flashes that can't be detected using JEDEC */
|
2014-09-30 10:14:55 +08:00
|
|
|
{"m25p05-nonjedec"}, {"m25p10-nonjedec"}, {"m25p20-nonjedec"},
|
|
|
|
{"m25p40-nonjedec"}, {"m25p80-nonjedec"}, {"m25p16-nonjedec"},
|
|
|
|
{"m25p32-nonjedec"}, {"m25p64-nonjedec"}, {"m25p128-nonjedec"},
|
2015-03-28 01:29:50 +08:00
|
|
|
|
2017-01-17 19:03:38 +08:00
|
|
|
/* Everspin MRAMs (non-JEDEC) */
|
2017-10-19 16:12:47 +08:00
|
|
|
{ "mr25h128" }, /* 128 Kib, 40 MHz */
|
2017-01-17 19:03:38 +08:00
|
|
|
{ "mr25h256" }, /* 256 Kib, 40 MHz */
|
|
|
|
{ "mr25h10" }, /* 1 Mib, 40 MHz */
|
|
|
|
{ "mr25h40" }, /* 4 Mib, 40 MHz */
|
|
|
|
|
2014-09-30 10:14:55 +08:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(spi, m25p_ids);
|
|
|
|
|
mtd: m25p80: allow arbitrary OF matching for "jedec,spi-nor"
When we added the "jedec,spi-nor" compatible string for use in this
driver, we added it as a modalias option. The modalias can be derived in
different ways for platform devices vs. device tree (of_*) matching. But
for device tree matching (the primary target of this identifier string),
the modalias is determined from the first entry in the 'compatible'
property. IOW, the following properties would bind to this driver:
// Option (a), modalias = "spi-nor"
compatible = "jedec,spi-nor";
// Option (b), modalias = "spi-nor"
compatible = "idontknowwhatimdoing,spi-nor";
But the following would not:
// Option (c), modalias = "shinynewdevice"
compatible = "myvendor,shinynewdevice", "jedec,spi-nor";
So, we'd like to match (a) and (c) (even when we don't have an explicit
entry for "shinynewdevice"), and we'd rather not allow (b).
To do this, we
(1) always (for devices without specific platform data) pass the
modalias to the spi-nor library;
(2) rework the spi-nor library to not reject "bad" names, and
instead just fall back to autodetection; and
(3) add the .of_match_table to properly catch all "jedec,spi-nor".
This allows (a) and (c) without warnings, and rejects (b).
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2015-05-20 05:38:22 +08:00
|
|
|
static const struct of_device_id m25p_of_table[] = {
|
|
|
|
/*
|
|
|
|
* Generic compatibility for SPI NOR that can be identified by the
|
|
|
|
* JEDEC READ ID opcode (0x9F). Use this, if possible.
|
|
|
|
*/
|
|
|
|
{ .compatible = "jedec,spi-nor" },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, m25p_of_table);
|
|
|
|
|
2018-04-27 00:18:19 +08:00
|
|
|
static struct spi_mem_driver m25p80_driver = {
|
|
|
|
.spidrv = {
|
|
|
|
.driver = {
|
|
|
|
.name = "m25p80",
|
|
|
|
.of_match_table = m25p_of_table,
|
|
|
|
},
|
|
|
|
.id_table = m25p_ids,
|
2006-01-09 05:34:27 +08:00
|
|
|
},
|
|
|
|
.probe = m25p_probe,
|
2012-11-20 02:21:24 +08:00
|
|
|
.remove = m25p_remove,
|
2017-12-06 10:53:42 +08:00
|
|
|
.shutdown = m25p_shutdown,
|
2007-06-25 06:12:35 +08:00
|
|
|
|
|
|
|
/* REVISIT: many of these chips have deep power-down modes, which
|
|
|
|
* should clearly be entered on suspend() to minimize power use.
|
|
|
|
* And also when they're otherwise idle...
|
|
|
|
*/
|
2006-01-09 05:34:27 +08:00
|
|
|
};
|
|
|
|
|
2018-04-27 00:18:19 +08:00
|
|
|
module_spi_mem_driver(m25p80_driver);
|
2006-01-09 05:34:27 +08:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Mike Lavender");
|
|
|
|
MODULE_DESCRIPTION("MTD SPI driver for ST M25Pxx flash chips");
|