mtd: mchp23k256: Add driver for this SPI SRAM device
PATCH v3 1/1 mtd: mchp23k256: Add driver for this SPI SRAM device
The Microchip 23k256 is a 32K Byte SRAM connected via SPI.
---
v3: Add Reviewed-by:
No code changed
v2: Remove multiple blank lines.
Make MODULE_LICENSE() consistent with license text. Fix copyright year.
drivers/mtd/devices/Kconfig | 10 +++ drivers/mtd/devices/Makefile | 1 + drivers/mtd/devices/mchp23k256.c | 183 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 194 insertions(+) create mode 100644 drivers/mtd/devices/mchp23k256.c
drivers/mtd/devices/Kconfig +10 -0
@@ -95,6 +95,16 @@ config MTD_M25P80 if you want to specify device partitioning or to use a device which doesn't support the JEDEC ID instruction. +config MTD_MCHP23K256 + tristate "Microchip 23K256 SRAM" + depends on SPI_MASTER + help + This enables access to Microchip 23K256 SRAM chips, using SPI. + + Set up your spi devices with the right board-specific + platform data, or a device tree description if you want to + specify device partitioning + config MTD_SPEAR_SMI tristate "SPEAR MTD NOR Support through SMI controller" depends on PLAT_SPEAR
drivers/mtd/devices/Makefile +1 -0
@@ -12,6 +12,7 @@ obj-$(CONFIG_MTD_LART) += lart.o obj-$(CONFIG_MTD_BLOCK2MTD) += block2mtd.o obj-$(CONFIG_MTD_DATAFLASH) += mtd_dataflash.o obj-$(CONFIG_MTD_M25P80) += m25p80.o +obj-$(CONFIG_MTD_MCHP23K256) += mchp23k256.o obj-$(CONFIG_MTD_SPEAR_SMI) += spear_smi.o obj-$(CONFIG_MTD_SST25L) += sst25l.o obj-$(CONFIG_MTD_BCM47XXSFLASH) += bcm47xxsflash.o
drivers/mtd/devices/mchp23k256.c new file +183 -0
183 lines not on this page · raw message
Signature · 1 line
2.11.0
Quoted 4 lines · On Tue, 11 Apr 2017 23:30:12 +0200 Andrew Lunn <[email protected]> wrote:
The Microchip 23k256 is a 32K Byte SRAM connected via SPI.
Signed-off-by Andrew Lunn <[email protected]>Reviewed-by Boris Brezillon <[email protected]>
3 minor things I didn't spot in my previous review.
[...]
drivers/mtd/devices/mchp23k256.c line 70
Quoted 2 lines
drivers/mtd/devices/mchp23k256.c new file +2
-0+static int mchp23k256_read (struct mtd_info *mtd,loff_t from,size_t len, +size_t *retlen,unsigned char *buf)
Align 'size_t *retlen' to the open parenthesis.
Quoted 23 lines
drivers/mtd/devices/mchp23k256.c new file +23
-0+{ +struct mchp23k256_flash *flash =to_mchp23k256_flash (mtd); +struct spi_transfer transfer[2 ] = {}; +struct spi_message message; +unsigned char command[3 ]; + +spi_message_init (&message); + +memset (&transfer,0 ,sizeof (transfer)); + command[0 ] =MCHP23K256_CMD_READ ; + command[1 ] = from >>8 ; + command[2 ] = from; + + transfer[0 ].tx_buf = command; + transfer[0 ].len =sizeof (command); +spi_message_add_tail (&transfer[0 ], &message); + + transfer[1 ].rx_buf = buf; + transfer[1 ].len = len; +spi_message_add_tail (&transfer[1 ], &message); + +mutex_lock (&flash->lock); +
drivers/mtd/devices/mchp23k256.c line 103
Quoted 10 lines
drivers/mtd/devices/mchp23k256.c new file +10
-0+spi_sync (flash->spi, &message); + +if (retlen && message.actual_length >sizeof (command)) + *retlen += message.actual_length -sizeof (command); + +mutex_unlock (&flash->lock); +return 0 ; +} + +/* Set the device into sequential mode. This allows read/writes to
/*
* Set the device ...
Quoted 11 lines
+ * the entire SRAM in a single operation
+ */drivers/mtd/devices/mchp23k256.c new file +9
-0+static int mchp23k256_set_mode (struct spi_device *spi) +{ +struct spi_transfer transfer = {}; +struct spi_message message; +unsigned char command[2 ]; + +spi_message_init (&message); + + command[0 ] =MCHP23K256_CMD_WRITE_STATUS ;
drivers/mtd/devices/mchp23k256.c line 124
Quoted 10 lines
drivers/mtd/devices/mchp23k256.c new file +10
-0+ command[1 ] =MCHP23K256_MODE_SEQ ; + + transfer.tx_buf = command; + transfer.len =sizeof (command); +spi_message_add_tail (&transfer, &message); + +return spi_sync (spi, &message); +} + +
Remove these 2 extra empty lines.
Quoted 37 lines
drivers/mtd/devices/mchp23k256.c new file +37
-0+ +static int mchp23k256_probe (struct spi_device *spi) +{ +struct mchp23k256_flash *flash; +struct flash_platform_data *data; +int err; + + flash =devm_kzalloc (&spi->dev,sizeof (*flash),GFP_KERNEL ); +if (!flash) +return -ENOMEM ; + + flash->spi = spi; +mutex_init (&flash->lock); +spi_set_drvdata (spi, flash); + + err =mchp23k256_set_mode (spi); +if (err) +return err; + + data =dev_get_platdata (&spi->dev); + + flash->mtd.dev.parent = &spi->dev; + flash->mtd.type =MTD_RAM ; + flash->mtd.flags =MTD_CAP_RAM ; + flash->mtd.writesize =1 ; + flash->mtd.size =SZ_32K ; + flash->mtd._read = mchp23k256_read; + flash->mtd._write = mchp23k256_write; + + err =mtd_device_parse_register (&flash->mtd,NULL ,NULL , + data ? data->parts :NULL , + data ? data->nr_parts :0 ); +if (err) +return err; + +return 0 ; +}
drivers/mtd/devices/mchp23k256.c line 183
Quoted 4 lines · Andrew Lunn
drivers/mtd/devices/mchp23k256.c new file +4
-0+MODULE_DESCRIPTION ("MTD SPI driver for MCHP23K256 RAM chips" ); +MODULE_AUTHOR ("Andrew Lunn <[email protected]>" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("spi:mchp23k256" );
You got correct MODULE_LICENSE in V2 and it's back wrong in V3.
Quoted 7 lines · Rafa?? Mi??ecki
drivers/mtd/devices/mchp23k256.c line 183
Quoted 4 lines · Andrew Lunn
drivers/mtd/devices/mchp23k256.c new file +4
-0+MODULE_DESCRIPTION ("MTD SPI driver for MCHP23K256 RAM chips" ); +MODULE_AUTHOR ("Andrew Lunn <[email protected]>" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("spi:mchp23k256" );You got correct
MODULE_LICENSEin V2 and it's back wrong in V3.
And fixed again in v4
https://patchwork.ozlabs.org/patch/750053/
Andrew