mtd: mchp23k256: How to follow a more generic approach?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi altogether,

I'm using currently the CONFIG_MTD_MCHP23K256 driver to access an 
ANV32AA1W 1Mb Serial SPI nvSRAM from Anvo-Systems Dresden.

I did some changes to the driver as seen below to make it work.


diff --git a/drivers/mtd/devices/mchp23k256.c 
b/drivers/mtd/devices/mchp23k256.c
index 9d8306a..6140973 100644
--- a/drivers/mtd/devices/mchp23k256.c
+++ b/drivers/mtd/devices/mchp23k256.c
@@ -28,6 +28,7 @@ struct mchp23k256_flash {
  };

  #define MCHP23K256_CMD_WRITE_STATUS    0x01
+#define MCHP23K256_CMD_WREN            0x06
  #define MCHP23K256_CMD_WRITE           0x02
  #define MCHP23K256_CMD_READ            0x03
  #define MCHP23K256_MODE_SEQ            BIT(6)
@@ -40,13 +41,14 @@ static int mchp23k256_write(struct mtd_info *mtd, 
loff_t to, size_t len,
         struct mchp23k256_flash *flash = to_mchp23k256_flash(mtd);
         struct spi_transfer transfer[2] = {};
         struct spi_message message;
-       unsigned char command[3];
+       unsigned char command[4];

         spi_message_init(&message);

         command[0] = MCHP23K256_CMD_WRITE;
-       command[1] = to >> 8;
-       command[2] = to;
+       command[1] = to >> 16;
+       command[2] = to >> 8;
+       command[3] = to;

         transfer[0].tx_buf = command;
         transfer[0].len = sizeof(command);
@@ -73,14 +75,15 @@ static int mchp23k256_read(struct mtd_info *mtd, 
loff_t from, size_t len,
         struct mchp23k256_flash *flash = to_mchp23k256_flash(mtd);
         struct spi_transfer transfer[2] = {};
         struct spi_message message;
-       unsigned char command[3];
+       unsigned char command[4];

         spi_message_init(&message);

         memset(&transfer, 0, sizeof(transfer));
         command[0] = MCHP23K256_CMD_READ;
-       command[1] = from >> 8;
-       command[2] = from;
+       command[1] = from >> 16;
+       command[2] = from >> 8;
+       command[3] = from;

         transfer[0].tx_buf = command;
         transfer[0].len = sizeof(command);
@@ -104,17 +107,18 @@ static int mchp23k256_read(struct mtd_info *mtd, 
loff_t from, size_t len,
  /*
   * Set the device into sequential mode. This allows read/writes to the
   * entire SRAM in a single operation
+ *
+ * CHANGE: Enable Write Mode in the device
   */
  static int mchp23k256_set_mode(struct spi_device *spi)
  {
         struct spi_transfer transfer = {};
         struct spi_message message;
-       unsigned char command[2];
+       unsigned char command[1];

         spi_message_init(&message);

-       command[0] = MCHP23K256_CMD_WRITE_STATUS;
-       command[1] = MCHP23K256_MODE_SEQ;
+       command[0] = MCHP23K256_CMD_WREN;

         transfer.tx_buf = command;
         transfer.len = sizeof(command);
@@ -147,7 +151,7 @@ static int mchp23k256_probe(struct spi_device *spi)
         flash->mtd.type         = MTD_RAM;
         flash->mtd.flags        = MTD_CAP_RAM;
         flash->mtd.writesize    = 1;
-       flash->mtd.size         = SZ_32K;
+       flash->mtd.size         = SZ_128K;
         flash->mtd._read        = mchp23k256_read;
         flash->mtd._write       = mchp23k256_write;


What would be the best approach to add a more generic solution to the 
kernel in order to be able to address different SPI SRAM devices?

Thanks.


Greetings,

	Heinrich Toews
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux