Lines Matching +full:spi +full:- +full:flash
2 * MTD SPI driver for ST M25Pxx (and similar) serial flash chips
26 #include <linux/spi/spi.h>
27 #include <linux/spi/spi-mem.h>
28 #include <linux/spi/flash.h>
29 #include <linux/mtd/spi-nor.h>
38 struct m25p *flash = nor->priv; in m25p80_read_reg() local
48 return -ENOMEM; in m25p80_read_reg()
51 ret = spi_mem_exec_op(flash->spimem, &op); in m25p80_read_reg()
53 dev_err(&flash->spimem->spi->dev, "error %d reading %x\n", ret, in m25p80_read_reg()
65 struct m25p *flash = nor->priv; in m25p80_write_reg() local
75 return -ENOMEM; in m25p80_write_reg()
78 ret = spi_mem_exec_op(flash->spimem, &op); in m25p80_write_reg()
87 struct m25p *flash = nor->priv; in m25p80_write() local
89 SPI_MEM_OP(SPI_MEM_OP_CMD(nor->program_opcode, 1), in m25p80_write()
90 SPI_MEM_OP_ADDR(nor->addr_width, to, 1), in m25p80_write()
96 op.cmd.buswidth = spi_nor_get_protocol_inst_nbits(nor->write_proto); in m25p80_write()
97 op.addr.buswidth = spi_nor_get_protocol_addr_nbits(nor->write_proto); in m25p80_write()
98 op.data.buswidth = spi_nor_get_protocol_data_nbits(nor->write_proto); in m25p80_write()
100 if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second) in m25p80_write()
103 ret = spi_mem_adjust_op_size(flash->spimem, &op); in m25p80_write()
108 ret = spi_mem_exec_op(flash->spimem, &op); in m25p80_write()
122 struct m25p *flash = nor->priv; in m25p80_read() local
124 SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 1), in m25p80_read()
125 SPI_MEM_OP_ADDR(nor->addr_width, from, 1), in m25p80_read()
126 SPI_MEM_OP_DUMMY(nor->read_dummy, 1), in m25p80_read()
132 op.cmd.buswidth = spi_nor_get_protocol_inst_nbits(nor->read_proto); in m25p80_read()
133 op.addr.buswidth = spi_nor_get_protocol_addr_nbits(nor->read_proto); in m25p80_read()
135 op.data.buswidth = spi_nor_get_protocol_data_nbits(nor->read_proto); in m25p80_read()
138 op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8; in m25p80_read()
142 ret = spi_mem_adjust_op_size(flash->spimem, &op); in m25p80_read()
146 ret = spi_mem_exec_op(flash->spimem, &op); in m25p80_read()
151 remaining -= op.data.nbytes; in m25p80_read()
159 * board specific setup should have ensured the SPI clock used here
165 struct spi_device *spi = spimem->spi; in m25p_probe() local
167 struct m25p *flash; in m25p_probe() local
177 data = dev_get_platdata(&spimem->spi->dev); in m25p_probe()
179 flash = devm_kzalloc(&spimem->spi->dev, sizeof(*flash), GFP_KERNEL); in m25p_probe()
180 if (!flash) in m25p_probe()
181 return -ENOMEM; in m25p_probe()
183 nor = &flash->spi_nor; in m25p_probe()
186 nor->read = m25p80_read; in m25p_probe()
187 nor->write = m25p80_write; in m25p_probe()
188 nor->write_reg = m25p80_write_reg; in m25p_probe()
189 nor->read_reg = m25p80_read_reg; in m25p_probe()
191 nor->dev = &spimem->spi->dev; in m25p_probe()
192 spi_nor_set_flash_node(nor, spi->dev.of_node); in m25p_probe()
193 nor->priv = flash; in m25p_probe()
195 spi_mem_set_drvdata(spimem, flash); in m25p_probe()
196 flash->spimem = spimem; in m25p_probe()
198 if (spi->mode & SPI_RX_QUAD) { in m25p_probe()
201 if (spi->mode & SPI_TX_QUAD) in m25p_probe()
205 } else if (spi->mode & SPI_RX_DUAL) { in m25p_probe()
208 if (spi->mode & SPI_TX_DUAL) in m25p_probe()
212 if (data && data->name) in m25p_probe()
213 nor->mtd.name = data->name; in m25p_probe()
215 if (!nor->mtd.name) in m25p_probe()
216 nor->mtd.name = spi_mem_get_name(spimem); in m25p_probe()
223 if (data && data->type) in m25p_probe()
224 flash_name = data->type; in m25p_probe()
225 else if (!strcmp(spi->modalias, "spi-nor")) in m25p_probe()
226 flash_name = NULL; /* auto-detect */ in m25p_probe()
228 flash_name = spi->modalias; in m25p_probe()
234 return mtd_device_register(&nor->mtd, data ? data->parts : NULL, in m25p_probe()
235 data ? data->nr_parts : 0); in m25p_probe()
241 struct m25p *flash = spi_mem_get_drvdata(spimem); in m25p_remove() local
243 spi_nor_restore(&flash->spi_nor); in m25p_remove()
246 return mtd_device_unregister(&flash->spi_nor.mtd); in m25p_remove()
251 struct m25p *flash = spi_mem_get_drvdata(spimem); in m25p_shutdown() local
253 spi_nor_restore(&flash->spi_nor); in m25p_shutdown()
258 * Historically, many flash devices are bound to this driver by their name. But
259 * since most of these flash are compatible to some extent, and their
260 * differences can often be differentiated by the JEDEC read-ID command, we
261 * encourage new users to add support to the spi-nor library, and simply bind
262 * against a generic string here (e.g., "jedec,spi-nor").
264 * Many flash names are kept here in this list (as well as in spi-nor.c) to
269 * Allow non-DT platform devices to bind to the "spi-nor" modalias, and
270 * hack around the fact that the SPI core does not provide uevent
273 {"spi-nor"},
277 * them with "spi-nor" in platform data.
282 * Entries that were used in DTs without "jedec,spi-nor" fallback and
298 {"m25p05-nonjedec"}, {"m25p10-nonjedec"}, {"m25p20-nonjedec"},
299 {"m25p40-nonjedec"}, {"m25p80-nonjedec"}, {"m25p16-nonjedec"},
300 {"m25p32-nonjedec"}, {"m25p64-nonjedec"}, {"m25p128-nonjedec"},
302 /* Everspin MRAMs (non-JEDEC) */
310 MODULE_DEVICE_TABLE(spi, m25p_ids);
314 * Generic compatibility for SPI NOR that can be identified by the
317 { .compatible = "jedec,spi-nor" },
334 /* REVISIT: many of these chips have deep power-down modes, which
344 MODULE_DESCRIPTION("MTD SPI driver for ST M25Pxx flash chips");