Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 1 | /* |
David Brownell | fa0a8c7 | 2007-06-24 15:12:35 -0700 | [diff] [blame] | 2 | * MTD SPI driver for ST M25Pxx (and similar) serial flash chips |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 3 | * |
| 4 | * Author: Mike Lavender, mike@steroidmicros.com |
| 5 | * |
| 6 | * Copyright (c) 2005, Intec Automation Inc. |
| 7 | * |
| 8 | * Some parts are based on lart.c by Abraham Van Der Merwe |
| 9 | * |
| 10 | * Cleaned up and generalized based on mtd_dataflash.c |
| 11 | * |
| 12 | * This code is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License version 2 as |
| 14 | * published by the Free Software Foundation. |
| 15 | * |
| 16 | */ |
| 17 | |
Anton Vorontsov | 9d2c4f3 | 2010-06-22 20:57:42 +0400 | [diff] [blame] | 18 | #include <linux/err.h> |
| 19 | #include <linux/errno.h> |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 20 | #include <linux/module.h> |
| 21 | #include <linux/device.h> |
David Brownell | 7d5230e | 2007-06-24 15:09:13 -0700 | [diff] [blame] | 22 | |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 23 | #include <linux/mtd/mtd.h> |
| 24 | #include <linux/mtd/partitions.h> |
David Brownell | 7d5230e | 2007-06-24 15:09:13 -0700 | [diff] [blame] | 25 | |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 26 | #include <linux/spi/spi.h> |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 27 | #include <linux/spi/spi-mem.h> |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 28 | #include <linux/spi/flash.h> |
Brian Norris | 03e296f | 2014-03-20 05:00:12 -0700 | [diff] [blame] | 29 | #include <linux/mtd/spi-nor.h> |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 30 | |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 31 | struct m25p { |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 32 | struct spi_mem *spimem; |
Brian Norris | 03e296f | 2014-03-20 05:00:12 -0700 | [diff] [blame] | 33 | struct spi_nor spi_nor; |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 34 | }; |
| 35 | |
Brian Norris | 03e296f | 2014-03-20 05:00:12 -0700 | [diff] [blame] | 36 | static int m25p80_read_reg(struct spi_nor *nor, u8 code, u8 *val, int len) |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 37 | { |
Brian Norris | 03e296f | 2014-03-20 05:00:12 -0700 | [diff] [blame] | 38 | struct m25p *flash = nor->priv; |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 39 | struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(code, 1), |
| 40 | SPI_MEM_OP_NO_ADDR, |
| 41 | SPI_MEM_OP_NO_DUMMY, |
| 42 | SPI_MEM_OP_DATA_IN(len, val, 1)); |
Sourav Poddar | 3487a639 | 2013-11-06 20:05:35 +0530 | [diff] [blame] | 43 | int ret; |
Sourav Poddar | 3487a639 | 2013-11-06 20:05:35 +0530 | [diff] [blame] | 44 | |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 45 | ret = spi_mem_exec_op(flash->spimem, &op); |
Brian Norris | 03e296f | 2014-03-20 05:00:12 -0700 | [diff] [blame] | 46 | if (ret < 0) |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 47 | dev_err(&flash->spimem->spi->dev, "error %d reading %x\n", ret, |
| 48 | code); |
Sourav Poddar | 3487a639 | 2013-11-06 20:05:35 +0530 | [diff] [blame] | 49 | |
Brian Norris | 03e296f | 2014-03-20 05:00:12 -0700 | [diff] [blame] | 50 | return ret; |
Sourav Poddar | 3487a639 | 2013-11-06 20:05:35 +0530 | [diff] [blame] | 51 | } |
| 52 | |
Jagan Teki | f9f3ce8 | 2015-08-19 15:26:44 +0530 | [diff] [blame] | 53 | static int m25p80_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len) |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 54 | { |
Brian Norris | 03e296f | 2014-03-20 05:00:12 -0700 | [diff] [blame] | 55 | struct m25p *flash = nor->priv; |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 56 | struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(opcode, 1), |
| 57 | SPI_MEM_OP_NO_ADDR, |
| 58 | SPI_MEM_OP_NO_DUMMY, |
| 59 | SPI_MEM_OP_DATA_OUT(len, buf, 1)); |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 60 | |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 61 | return spi_mem_exec_op(flash->spimem, &op); |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Michal Suchanek | 59451e1 | 2016-05-05 17:31:47 -0700 | [diff] [blame] | 64 | static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len, |
Michal Suchanek | 2dd087b | 2016-05-05 17:31:53 -0700 | [diff] [blame] | 65 | const u_char *buf) |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 66 | { |
Brian Norris | 03e296f | 2014-03-20 05:00:12 -0700 | [diff] [blame] | 67 | struct m25p *flash = nor->priv; |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 68 | struct spi_mem_op op = |
| 69 | SPI_MEM_OP(SPI_MEM_OP_CMD(nor->program_opcode, 1), |
| 70 | SPI_MEM_OP_ADDR(nor->addr_width, to, 1), |
Boris Brezillon | 9882b53 | 2018-06-01 12:03:25 +0200 | [diff] [blame] | 71 | SPI_MEM_OP_NO_DUMMY, |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 72 | SPI_MEM_OP_DATA_OUT(len, buf, 1)); |
| 73 | size_t remaining = len; |
| 74 | int ret; |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 75 | |
Cyrille Pitchen | 138f5dc | 2017-04-25 22:08:47 +0200 | [diff] [blame] | 76 | /* get transfer protocols. */ |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 77 | op.cmd.buswidth = spi_nor_get_protocol_inst_nbits(nor->write_proto); |
| 78 | op.addr.buswidth = spi_nor_get_protocol_addr_nbits(nor->write_proto); |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 79 | op.data.buswidth = spi_nor_get_protocol_data_nbits(nor->write_proto); |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 80 | |
Brian Norris | b02e7f3 | 2014-04-08 18:15:31 -0700 | [diff] [blame] | 81 | if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second) |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 82 | op.addr.nbytes = 0; |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 83 | |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 84 | while (remaining) { |
| 85 | op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX; |
| 86 | ret = spi_mem_adjust_op_size(flash->spimem, &op); |
| 87 | if (ret) |
| 88 | return ret; |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 89 | |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 90 | ret = spi_mem_exec_op(flash->spimem, &op); |
| 91 | if (ret) |
| 92 | return ret; |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 93 | |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 94 | op.addr.val += op.data.nbytes; |
| 95 | remaining -= op.data.nbytes; |
| 96 | op.data.buf.out += op.data.nbytes; |
Cyrille Pitchen | 138f5dc | 2017-04-25 22:08:47 +0200 | [diff] [blame] | 97 | } |
| 98 | |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 99 | return len; |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Sourav Poddar | 8552b43 | 2013-11-06 20:05:34 +0530 | [diff] [blame] | 102 | /* |
Brian Norris | 03e296f | 2014-03-20 05:00:12 -0700 | [diff] [blame] | 103 | * Read an address range from the nor chip. The address range |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 104 | * may be any size provided it is within the physical boundaries. |
| 105 | */ |
Michal Suchanek | 59451e1 | 2016-05-05 17:31:47 -0700 | [diff] [blame] | 106 | static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len, |
Michal Suchanek | 2dd087b | 2016-05-05 17:31:53 -0700 | [diff] [blame] | 107 | u_char *buf) |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 108 | { |
Brian Norris | 03e296f | 2014-03-20 05:00:12 -0700 | [diff] [blame] | 109 | struct m25p *flash = nor->priv; |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 110 | struct spi_mem_op op = |
| 111 | SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 1), |
| 112 | SPI_MEM_OP_ADDR(nor->addr_width, from, 1), |
| 113 | SPI_MEM_OP_DUMMY(nor->read_dummy, 1), |
| 114 | SPI_MEM_OP_DATA_IN(len, buf, 1)); |
| 115 | size_t remaining = len; |
| 116 | int ret; |
Cyrille Pitchen | 138f5dc | 2017-04-25 22:08:47 +0200 | [diff] [blame] | 117 | |
| 118 | /* get transfer protocols. */ |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 119 | op.cmd.buswidth = spi_nor_get_protocol_inst_nbits(nor->read_proto); |
| 120 | op.addr.buswidth = spi_nor_get_protocol_addr_nbits(nor->read_proto); |
| 121 | op.dummy.buswidth = op.addr.buswidth; |
| 122 | op.data.buswidth = spi_nor_get_protocol_data_nbits(nor->read_proto); |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 123 | |
Huang Shijie | 0b78a2c | 2014-04-28 11:53:38 +0800 | [diff] [blame] | 124 | /* convert the dummy cycles to the number of bytes */ |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 125 | op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8; |
Huang Shijie | 0b78a2c | 2014-04-28 11:53:38 +0800 | [diff] [blame] | 126 | |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 127 | while (remaining) { |
| 128 | op.data.nbytes = remaining < UINT_MAX ? remaining : UINT_MAX; |
| 129 | ret = spi_mem_adjust_op_size(flash->spimem, &op); |
| 130 | if (ret) |
Michal Suchanek | 1992297b | 2016-05-05 17:31:48 -0700 | [diff] [blame] | 131 | return ret; |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 132 | |
| 133 | ret = spi_mem_exec_op(flash->spimem, &op); |
| 134 | if (ret) |
| 135 | return ret; |
| 136 | |
| 137 | op.addr.val += op.data.nbytes; |
| 138 | remaining -= op.data.nbytes; |
| 139 | op.data.buf.in += op.data.nbytes; |
Vignesh R | 08922f6 | 2016-03-29 11:16:17 +0530 | [diff] [blame] | 140 | } |
| 141 | |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 142 | return len; |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 143 | } |
| 144 | |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 145 | /* |
| 146 | * board specific setup should have ensured the SPI clock used here |
| 147 | * matches what the READ command supports, at least until this driver |
| 148 | * understands FAST_READ (for clocks over 25 MHz). |
| 149 | */ |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 150 | static int m25p_probe(struct spi_mem *spimem) |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 151 | { |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 152 | struct spi_device *spi = spimem->spi; |
Brian Norris | 03e296f | 2014-03-20 05:00:12 -0700 | [diff] [blame] | 153 | struct flash_platform_data *data; |
| 154 | struct m25p *flash; |
| 155 | struct spi_nor *nor; |
Cyrille Pitchen | cfc5604 | 2017-04-25 22:08:46 +0200 | [diff] [blame] | 156 | struct spi_nor_hwcaps hwcaps = { |
| 157 | .mask = SNOR_HWCAPS_READ | |
| 158 | SNOR_HWCAPS_READ_FAST | |
| 159 | SNOR_HWCAPS_PP, |
| 160 | }; |
Brian Norris | de57732 | 2015-11-16 14:34:50 -0800 | [diff] [blame] | 161 | char *flash_name; |
Sourav Poddar | 3487a639 | 2013-11-06 20:05:35 +0530 | [diff] [blame] | 162 | int ret; |
Shaohui Xie | 5f94913 | 2011-10-14 15:49:00 +0800 | [diff] [blame] | 163 | |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 164 | data = dev_get_platdata(&spimem->spi->dev); |
Rafał Miłecki | 32f1b7c | 2014-09-28 22:36:54 +0200 | [diff] [blame] | 165 | |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 166 | flash = devm_kzalloc(&spimem->spi->dev, sizeof(*flash), GFP_KERNEL); |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 167 | if (!flash) |
| 168 | return -ENOMEM; |
Brian Norris | 778d226 | 2013-07-24 18:32:07 -0700 | [diff] [blame] | 169 | |
Brian Norris | 03e296f | 2014-03-20 05:00:12 -0700 | [diff] [blame] | 170 | nor = &flash->spi_nor; |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 171 | |
Brian Norris | 03e296f | 2014-03-20 05:00:12 -0700 | [diff] [blame] | 172 | /* install the hooks */ |
| 173 | nor->read = m25p80_read; |
| 174 | nor->write = m25p80_write; |
Brian Norris | 03e296f | 2014-03-20 05:00:12 -0700 | [diff] [blame] | 175 | nor->write_reg = m25p80_write_reg; |
| 176 | nor->read_reg = m25p80_read_reg; |
| 177 | |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 178 | nor->dev = &spimem->spi->dev; |
Brian Norris | 9c7d787 | 2015-10-30 20:33:24 -0700 | [diff] [blame] | 179 | spi_nor_set_flash_node(nor, spi->dev.of_node); |
Brian Norris | 03e296f | 2014-03-20 05:00:12 -0700 | [diff] [blame] | 180 | nor->priv = flash; |
| 181 | |
Boris Brezillon | 1e07392 | 2018-05-22 12:55:14 +0200 | [diff] [blame] | 182 | spi_mem_set_drvdata(spimem, flash); |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 183 | flash->spimem = spimem; |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 184 | |
Cyrille Pitchen | 138f5dc | 2017-04-25 22:08:47 +0200 | [diff] [blame] | 185 | if (spi->mode & SPI_RX_QUAD) { |
Cyrille Pitchen | cfc5604 | 2017-04-25 22:08:46 +0200 | [diff] [blame] | 186 | hwcaps.mask |= SNOR_HWCAPS_READ_1_1_4; |
Cyrille Pitchen | 138f5dc | 2017-04-25 22:08:47 +0200 | [diff] [blame] | 187 | |
| 188 | if (spi->mode & SPI_TX_QUAD) |
| 189 | hwcaps.mask |= (SNOR_HWCAPS_READ_1_4_4 | |
| 190 | SNOR_HWCAPS_PP_1_1_4 | |
| 191 | SNOR_HWCAPS_PP_1_4_4); |
| 192 | } else if (spi->mode & SPI_RX_DUAL) { |
Cyrille Pitchen | cfc5604 | 2017-04-25 22:08:46 +0200 | [diff] [blame] | 193 | hwcaps.mask |= SNOR_HWCAPS_READ_1_1_2; |
Rafał Miłecki | 32f1b7c | 2014-09-28 22:36:54 +0200 | [diff] [blame] | 194 | |
Cyrille Pitchen | 138f5dc | 2017-04-25 22:08:47 +0200 | [diff] [blame] | 195 | if (spi->mode & SPI_TX_DUAL) |
| 196 | hwcaps.mask |= SNOR_HWCAPS_READ_1_2_2; |
| 197 | } |
| 198 | |
Rafał Miłecki | 32f1b7c | 2014-09-28 22:36:54 +0200 | [diff] [blame] | 199 | if (data && data->name) |
Brian Norris | 1976367 | 2015-08-13 15:46:05 -0700 | [diff] [blame] | 200 | nor->mtd.name = data->name; |
Rafał Miłecki | 32f1b7c | 2014-09-28 22:36:54 +0200 | [diff] [blame] | 201 | |
Frieder Schrempf | b02b17f | 2018-08-02 14:53:54 +0200 | [diff] [blame] | 202 | if (!nor->mtd.name) |
| 203 | nor->mtd.name = spi_mem_get_name(spimem); |
| 204 | |
Rafał Miłecki | 32f1b7c | 2014-09-28 22:36:54 +0200 | [diff] [blame] | 205 | /* For some (historical?) reason many platforms provide two different |
| 206 | * names in flash_platform_data: "name" and "type". Quite often name is |
| 207 | * set to "m25p80" and then "type" provides a real chip name. |
| 208 | * If that's the case, respect "type" and ignore a "name". |
| 209 | */ |
| 210 | if (data && data->type) |
Rafał Miłecki | 90e55b3 | 2014-09-29 11:47:53 +0200 | [diff] [blame] | 211 | flash_name = data->type; |
Brian Norris | de57732 | 2015-11-16 14:34:50 -0800 | [diff] [blame] | 212 | else if (!strcmp(spi->modalias, "spi-nor")) |
| 213 | flash_name = NULL; /* auto-detect */ |
Rafał Miłecki | 90e55b3 | 2014-09-29 11:47:53 +0200 | [diff] [blame] | 214 | else |
| 215 | flash_name = spi->modalias; |
Rafał Miłecki | 32f1b7c | 2014-09-28 22:36:54 +0200 | [diff] [blame] | 216 | |
Cyrille Pitchen | cfc5604 | 2017-04-25 22:08:46 +0200 | [diff] [blame] | 217 | ret = spi_nor_scan(nor, flash_name, &hwcaps); |
Brian Norris | 03e296f | 2014-03-20 05:00:12 -0700 | [diff] [blame] | 218 | if (ret) |
| 219 | return ret; |
Michael Hennerich | 7228982 | 2008-07-03 23:54:42 -0700 | [diff] [blame] | 220 | |
Brian Norris | df02c88 | 2015-10-30 20:33:26 -0700 | [diff] [blame] | 221 | return mtd_device_register(&nor->mtd, data ? data->parts : NULL, |
| 222 | data ? data->nr_parts : 0); |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 226 | static int m25p_remove(struct spi_mem *spimem) |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 227 | { |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 228 | struct m25p *flash = spi_mem_get_drvdata(spimem); |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 229 | |
Hou Zhiqiang | 59b356f | 2017-12-06 10:53:42 +0800 | [diff] [blame] | 230 | spi_nor_restore(&flash->spi_nor); |
| 231 | |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 232 | /* Clean up MTD stuff. */ |
Brian Norris | 1976367 | 2015-08-13 15:46:05 -0700 | [diff] [blame] | 233 | return mtd_device_unregister(&flash->spi_nor.mtd); |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 234 | } |
| 235 | |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 236 | static void m25p_shutdown(struct spi_mem *spimem) |
Hou Zhiqiang | 59b356f | 2017-12-06 10:53:42 +0800 | [diff] [blame] | 237 | { |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 238 | struct m25p *flash = spi_mem_get_drvdata(spimem); |
Hou Zhiqiang | 59b356f | 2017-12-06 10:53:42 +0800 | [diff] [blame] | 239 | |
| 240 | spi_nor_restore(&flash->spi_nor); |
| 241 | } |
Ben Hutchings | a5b7616 | 2014-09-30 03:14:55 +0100 | [diff] [blame] | 242 | /* |
Brian Norris | 1103b85 | 2015-03-27 10:29:50 -0700 | [diff] [blame] | 243 | * Do NOT add to this array without reading the following: |
| 244 | * |
| 245 | * Historically, many flash devices are bound to this driver by their name. But |
| 246 | * since most of these flash are compatible to some extent, and their |
| 247 | * differences can often be differentiated by the JEDEC read-ID command, we |
| 248 | * encourage new users to add support to the spi-nor library, and simply bind |
Brian Norris | 8947e39 | 2015-05-14 10:32:53 -0700 | [diff] [blame] | 249 | * against a generic string here (e.g., "jedec,spi-nor"). |
Brian Norris | 1103b85 | 2015-03-27 10:29:50 -0700 | [diff] [blame] | 250 | * |
| 251 | * Many flash names are kept here in this list (as well as in spi-nor.c) to |
| 252 | * keep them available as module aliases for existing platforms. |
Ben Hutchings | a5b7616 | 2014-09-30 03:14:55 +0100 | [diff] [blame] | 253 | */ |
| 254 | static const struct spi_device_id m25p_ids[] = { |
Rafał Miłecki | 3094fe1 | 2015-04-07 10:39:41 +0200 | [diff] [blame] | 255 | /* |
Brian Norris | de57732 | 2015-11-16 14:34:50 -0800 | [diff] [blame] | 256 | * Allow non-DT platform devices to bind to the "spi-nor" modalias, and |
| 257 | * hack around the fact that the SPI core does not provide uevent |
| 258 | * matching for .of_match_table |
| 259 | */ |
| 260 | {"spi-nor"}, |
| 261 | |
| 262 | /* |
Rafał Miłecki | 3094fe1 | 2015-04-07 10:39:41 +0200 | [diff] [blame] | 263 | * Entries not used in DTs that should be safe to drop after replacing |
Brian Norris | c1711b2 | 2015-11-16 14:34:51 -0800 | [diff] [blame] | 264 | * them with "spi-nor" in platform data. |
Rafał Miłecki | 3094fe1 | 2015-04-07 10:39:41 +0200 | [diff] [blame] | 265 | */ |
| 266 | {"s25sl064a"}, {"w25x16"}, {"m25p10"}, {"m25px64"}, |
| 267 | |
| 268 | /* |
Brian Norris | c1711b2 | 2015-11-16 14:34:51 -0800 | [diff] [blame] | 269 | * Entries that were used in DTs without "jedec,spi-nor" fallback and |
| 270 | * should be kept for backward compatibility. |
Rafał Miłecki | 3094fe1 | 2015-04-07 10:39:41 +0200 | [diff] [blame] | 271 | */ |
| 272 | {"at25df321a"}, {"at25df641"}, {"at26df081a"}, |
Rafał Miłecki | 3094fe1 | 2015-04-07 10:39:41 +0200 | [diff] [blame] | 273 | {"mx25l4005a"}, {"mx25l1606e"}, {"mx25l6405d"}, {"mx25l12805d"}, |
| 274 | {"mx25l25635e"},{"mx66l51235l"}, |
| 275 | {"n25q064"}, {"n25q128a11"}, {"n25q128a13"}, {"n25q512a"}, |
| 276 | {"s25fl256s1"}, {"s25fl512s"}, {"s25sl12801"}, {"s25fl008k"}, |
| 277 | {"s25fl064k"}, |
| 278 | {"sst25vf040b"},{"sst25vf016b"},{"sst25vf032b"},{"sst25wf040"}, |
| 279 | {"m25p40"}, {"m25p80"}, {"m25p16"}, {"m25p32"}, |
| 280 | {"m25p64"}, {"m25p128"}, |
| 281 | {"w25x80"}, {"w25x32"}, {"w25q32"}, {"w25q32dw"}, |
| 282 | {"w25q80bl"}, {"w25q128"}, {"w25q256"}, |
| 283 | |
| 284 | /* Flashes that can't be detected using JEDEC */ |
Ben Hutchings | a5b7616 | 2014-09-30 03:14:55 +0100 | [diff] [blame] | 285 | {"m25p05-nonjedec"}, {"m25p10-nonjedec"}, {"m25p20-nonjedec"}, |
| 286 | {"m25p40-nonjedec"}, {"m25p80-nonjedec"}, {"m25p16-nonjedec"}, |
| 287 | {"m25p32-nonjedec"}, {"m25p64-nonjedec"}, {"m25p128-nonjedec"}, |
Brian Norris | 1103b85 | 2015-03-27 10:29:50 -0700 | [diff] [blame] | 288 | |
Uwe Kleine-König | 3a08e93 | 2017-01-17 12:03:38 +0100 | [diff] [blame] | 289 | /* Everspin MRAMs (non-JEDEC) */ |
Philipp Puschmann | 282e45d | 2017-10-19 10:12:47 +0200 | [diff] [blame] | 290 | { "mr25h128" }, /* 128 Kib, 40 MHz */ |
Uwe Kleine-König | 3a08e93 | 2017-01-17 12:03:38 +0100 | [diff] [blame] | 291 | { "mr25h256" }, /* 256 Kib, 40 MHz */ |
| 292 | { "mr25h10" }, /* 1 Mib, 40 MHz */ |
| 293 | { "mr25h40" }, /* 4 Mib, 40 MHz */ |
| 294 | |
Ben Hutchings | a5b7616 | 2014-09-30 03:14:55 +0100 | [diff] [blame] | 295 | { }, |
| 296 | }; |
| 297 | MODULE_DEVICE_TABLE(spi, m25p_ids); |
| 298 | |
Brian Norris | 4316302 | 2015-05-19 14:38:22 -0700 | [diff] [blame] | 299 | static const struct of_device_id m25p_of_table[] = { |
| 300 | /* |
| 301 | * Generic compatibility for SPI NOR that can be identified by the |
| 302 | * JEDEC READ ID opcode (0x9F). Use this, if possible. |
| 303 | */ |
| 304 | { .compatible = "jedec,spi-nor" }, |
| 305 | {} |
| 306 | }; |
| 307 | MODULE_DEVICE_TABLE(of, m25p_of_table); |
| 308 | |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 309 | static struct spi_mem_driver m25p80_driver = { |
| 310 | .spidrv = { |
| 311 | .driver = { |
| 312 | .name = "m25p80", |
| 313 | .of_match_table = m25p_of_table, |
| 314 | }, |
| 315 | .id_table = m25p_ids, |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 316 | }, |
| 317 | .probe = m25p_probe, |
Bill Pemberton | 5153b88 | 2012-11-19 13:21:24 -0500 | [diff] [blame] | 318 | .remove = m25p_remove, |
Hou Zhiqiang | 59b356f | 2017-12-06 10:53:42 +0800 | [diff] [blame] | 319 | .shutdown = m25p_shutdown, |
David Brownell | fa0a8c7 | 2007-06-24 15:12:35 -0700 | [diff] [blame] | 320 | |
| 321 | /* REVISIT: many of these chips have deep power-down modes, which |
| 322 | * should clearly be entered on suspend() to minimize power use. |
| 323 | * And also when they're otherwise idle... |
| 324 | */ |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 325 | }; |
| 326 | |
Boris Brezillon | 4120f8d | 2018-04-26 18:18:19 +0200 | [diff] [blame] | 327 | module_spi_mem_driver(m25p80_driver); |
Mike Lavender | 2f9f762 | 2006-01-08 13:34:27 -0800 | [diff] [blame] | 328 | |
| 329 | MODULE_LICENSE("GPL"); |
| 330 | MODULE_AUTHOR("Mike Lavender"); |
| 331 | MODULE_DESCRIPTION("MTD SPI driver for ST M25Pxx flash chips"); |