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>
|
|
|
|
#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
|
|
|
|
2013-07-25 09:32:07 +08:00
|
|
|
#define MAX_CMD_SIZE 6
|
2006-01-09 05:34:27 +08:00
|
|
|
struct m25p {
|
|
|
|
struct spi_device *spi;
|
2014-03-20 20:00:12 +08:00
|
|
|
struct spi_nor spi_nor;
|
|
|
|
u8 command[MAX_CMD_SIZE];
|
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;
|
|
|
|
struct spi_device *spi = flash->spi;
|
2013-11-06 22:35:35 +08:00
|
|
|
int ret;
|
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
ret = spi_write_then_read(spi, &code, 1, val, len);
|
|
|
|
if (ret < 0)
|
|
|
|
dev_err(&spi->dev, "error %d reading %x\n", ret, code);
|
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
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
static void m25p_addr2cmd(struct spi_nor *nor, unsigned int addr, u8 *cmd)
|
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
|
|
|
{
|
|
|
|
/* opcode is in cmd[0] */
|
2014-03-20 20:00:12 +08:00
|
|
|
cmd[1] = addr >> (nor->addr_width * 8 - 8);
|
|
|
|
cmd[2] = addr >> (nor->addr_width * 8 - 16);
|
|
|
|
cmd[3] = addr >> (nor->addr_width * 8 - 24);
|
|
|
|
cmd[4] = addr >> (nor->addr_width * 8 - 32);
|
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
|
|
|
}
|
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
static int m25p_cmdsz(struct spi_nor *nor)
|
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
|
|
|
{
|
2014-03-20 20:00:12 +08:00
|
|
|
return 1 + nor->addr_width;
|
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-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;
|
|
|
|
struct spi_device *spi = flash->spi;
|
2006-01-09 05:34:27 +08:00
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
flash->command[0] = opcode;
|
|
|
|
if (buf)
|
|
|
|
memcpy(&flash->command[1], buf, len);
|
2006-01-09 05:34:27 +08:00
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
return spi_write(spi, flash->command, len + 1);
|
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;
|
|
|
|
struct spi_device *spi = flash->spi;
|
|
|
|
struct spi_transfer t[2] = {};
|
|
|
|
struct spi_message m;
|
|
|
|
int cmd_sz = m25p_cmdsz(nor);
|
2016-05-06 08:31:48 +08:00
|
|
|
ssize_t ret;
|
2008-11-26 18:23:57 +08:00
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
spi_message_init(&m);
|
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)
|
2014-03-20 20:00:12 +08:00
|
|
|
cmd_sz = 1;
|
2008-08-11 16:59:13 +08:00
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
flash->command[0] = nor->program_opcode;
|
|
|
|
m25p_addr2cmd(nor, to, flash->command);
|
2006-01-09 05:34:27 +08:00
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
t[0].tx_buf = flash->command;
|
|
|
|
t[0].len = cmd_sz;
|
|
|
|
spi_message_add_tail(&t[0], &m);
|
2006-01-09 05:34:27 +08:00
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
t[1].tx_buf = buf;
|
|
|
|
t[1].len = len;
|
|
|
|
spi_message_add_tail(&t[1], &m);
|
2006-01-09 05:34:27 +08:00
|
|
|
|
2016-05-06 08:31:48 +08:00
|
|
|
ret = spi_sync(spi, &m);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2006-01-09 05:34:27 +08:00
|
|
|
|
2016-05-06 08:31:48 +08:00
|
|
|
ret = m.actual_length - cmd_sz;
|
|
|
|
if (ret < 0)
|
|
|
|
return -EIO;
|
|
|
|
return ret;
|
2013-11-06 22:35:34 +08:00
|
|
|
}
|
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
static inline unsigned int m25p80_rx_nbits(struct spi_nor *nor)
|
2014-01-21 20:59:17 +08:00
|
|
|
{
|
2014-03-20 20:00:12 +08:00
|
|
|
switch (nor->flash_read) {
|
|
|
|
case SPI_NOR_DUAL:
|
2014-01-21 20:59:18 +08:00
|
|
|
return 2;
|
2014-03-20 20:00:12 +08:00
|
|
|
case SPI_NOR_QUAD:
|
2014-01-21 20:59:17 +08:00
|
|
|
return 4;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
struct spi_device *spi = flash->spi;
|
2006-01-09 05:34:27 +08:00
|
|
|
struct spi_transfer t[2];
|
|
|
|
struct spi_message m;
|
2014-04-28 11:53:38 +08:00
|
|
|
unsigned int dummy = nor->read_dummy;
|
2016-05-06 08:31:48 +08:00
|
|
|
ssize_t ret;
|
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 */
|
|
|
|
dummy /= 8;
|
|
|
|
|
2016-03-29 13:46:17 +08:00
|
|
|
if (spi_flash_read_supported(spi)) {
|
|
|
|
struct spi_flash_read_message msg;
|
|
|
|
|
|
|
|
memset(&msg, 0, sizeof(msg));
|
|
|
|
|
|
|
|
msg.buf = buf;
|
|
|
|
msg.from = from;
|
|
|
|
msg.len = len;
|
|
|
|
msg.read_opcode = nor->read_opcode;
|
|
|
|
msg.addr_width = nor->addr_width;
|
|
|
|
msg.dummy_bytes = dummy;
|
|
|
|
/* TODO: Support other combinations */
|
|
|
|
msg.opcode_nbits = SPI_NBITS_SINGLE;
|
|
|
|
msg.addr_nbits = SPI_NBITS_SINGLE;
|
|
|
|
msg.data_nbits = m25p80_rx_nbits(nor);
|
|
|
|
|
|
|
|
ret = spi_flash_read(spi, &msg);
|
2016-05-06 08:31:48 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
return msg.retlen;
|
2016-03-29 13:46:17 +08:00
|
|
|
}
|
|
|
|
|
2006-01-09 05:34:28 +08:00
|
|
|
spi_message_init(&m);
|
|
|
|
memset(t, 0, (sizeof t));
|
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
flash->command[0] = nor->read_opcode;
|
|
|
|
m25p_addr2cmd(nor, from, flash->command);
|
2013-11-06 22:35:34 +08:00
|
|
|
|
2006-01-09 05:34:28 +08:00
|
|
|
t[0].tx_buf = flash->command;
|
2014-03-20 20:00:12 +08:00
|
|
|
t[0].len = m25p_cmdsz(nor) + dummy;
|
2006-01-09 05:34:28 +08:00
|
|
|
spi_message_add_tail(&t[0], &m);
|
|
|
|
|
|
|
|
t[1].rx_buf = buf;
|
2014-03-20 20:00:12 +08:00
|
|
|
t[1].rx_nbits = m25p80_rx_nbits(nor);
|
2016-05-06 08:31:56 +08:00
|
|
|
t[1].len = min(len, spi_max_transfer_size(spi));
|
2006-01-09 05:34:28 +08:00
|
|
|
spi_message_add_tail(&t[1], &m);
|
|
|
|
|
2016-05-06 08:31:48 +08:00
|
|
|
ret = spi_sync(spi, &m);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2006-01-09 05:34:27 +08:00
|
|
|
|
2016-05-06 08:31:48 +08:00
|
|
|
ret = m.actual_length - m25p_cmdsz(nor) - dummy;
|
|
|
|
if (ret < 0)
|
|
|
|
return -EIO;
|
|
|
|
return ret;
|
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).
|
|
|
|
*/
|
2012-11-20 02:23:07 +08:00
|
|
|
static int m25p_probe(struct spi_device *spi)
|
2006-01-09 05:34:27 +08:00
|
|
|
{
|
2014-03-20 20:00:12 +08:00
|
|
|
struct flash_platform_data *data;
|
|
|
|
struct m25p *flash;
|
|
|
|
struct spi_nor *nor;
|
|
|
|
enum read_mode mode = SPI_NOR_NORMAL;
|
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
|
|
|
|
2014-09-29 04:36:54 +08:00
|
|
|
data = dev_get_platdata(&spi->dev);
|
|
|
|
|
2013-07-25 09:32:07 +08:00
|
|
|
flash = devm_kzalloc(&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
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
nor->dev = &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
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
spi_set_drvdata(spi, flash);
|
|
|
|
flash->spi = spi;
|
2007-06-25 06:12:35 +08:00
|
|
|
|
2014-03-20 20:00:12 +08:00
|
|
|
if (spi->mode & SPI_RX_QUAD)
|
|
|
|
mode = SPI_NOR_QUAD;
|
2014-04-22 20:45:31 +08:00
|
|
|
else if (spi->mode & SPI_RX_DUAL)
|
|
|
|
mode = SPI_NOR_DUAL;
|
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
|
|
|
|
|
|
|
/* 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
|
|
|
|
2014-09-29 17:47:54 +08:00
|
|
|
ret = spi_nor_scan(nor, flash_name, mode);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-20 02:26:04 +08:00
|
|
|
static int m25p_remove(struct spi_device *spi)
|
2006-01-09 05:34:27 +08:00
|
|
|
{
|
2013-04-06 14:41:32 +08:00
|
|
|
struct m25p *flash = spi_get_drvdata(spi);
|
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
|
|
|
}
|
|
|
|
|
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"},
|
|
|
|
{"mr25h256"},
|
|
|
|
{"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
|
|
|
|
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);
|
|
|
|
|
2006-01-09 05:34:27 +08:00
|
|
|
static struct spi_driver m25p80_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "m25p80",
|
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
|
|
|
.of_match_table = m25p_of_table,
|
2006-01-09 05:34:27 +08:00
|
|
|
},
|
2014-09-30 10:14:55 +08:00
|
|
|
.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,
|
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
|
|
|
};
|
|
|
|
|
2012-01-27 15:45:20 +08:00
|
|
|
module_spi_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");
|