Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: m25p80: Make fast read configurable via DT

Add DT property "m25p,fast-read" that signalises the particular
chip supports "fast read" opcode.

Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

authored by

Marek Vasut and committed by
Artem Bityutskiy
12ad2be9 2d350e5a

+50 -13
+29
Documentation/devicetree/bindings/mtd/m25p80.txt
··· 1 + * MTD SPI driver for ST M25Pxx (and similar) serial flash chips 2 + 3 + Required properties: 4 + - #address-cells, #size-cells : Must be present if the device has sub-nodes 5 + representing partitions. 6 + - compatible : Should be the manufacturer and the name of the chip. Bear in mind 7 + the DT binding is not Linux-only, but in case of Linux, see the 8 + "m25p_ids" table in drivers/mtd/devices/m25p80.c for the list of 9 + supported chips. 10 + - reg : Chip-Select number 11 + - spi-max-frequency : Maximum frequency of the SPI bus the chip can operate at 12 + 13 + Optional properties: 14 + - m25p,fast-read : Use the "fast read" opcode to read data from the chip instead 15 + of the usual "read" opcode. This opcode is not supported by 16 + all chips and support for it can not be detected at runtime. 17 + Refer to your chips' datasheet to check if this is supported 18 + by your chip. 19 + 20 + Example: 21 + 22 + flash: m25p80@0 { 23 + #address-cells = <1>; 24 + #size-cells = <1>; 25 + compatible = "spansion,m25p80"; 26 + reg = <0>; 27 + spi-max-frequency = <40000000>; 28 + m25p,fast-read; 29 + };
+21 -13
drivers/mtd/devices/m25p80.c
··· 73 73 #define MAX_READY_WAIT_JIFFIES (40 * HZ) /* M25P16 specs 40s max chip erase */ 74 74 #define MAX_CMD_SIZE 5 75 75 76 - #ifdef CONFIG_M25PXX_USE_FAST_READ 77 - #define OPCODE_READ OPCODE_FAST_READ 78 - #define FAST_READ_DUMMY_BYTE 1 79 - #else 80 - #define OPCODE_READ OPCODE_NORM_READ 81 - #define FAST_READ_DUMMY_BYTE 0 82 - #endif 83 - 84 76 #define JEDEC_MFR(_jedec_id) ((_jedec_id) >> 16) 85 77 86 78 /****************************************************************************/ ··· 85 93 u16 addr_width; 86 94 u8 erase_opcode; 87 95 u8 *command; 96 + bool fast_read; 88 97 }; 89 98 90 99 static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd) ··· 335 342 struct m25p *flash = mtd_to_m25p(mtd); 336 343 struct spi_transfer t[2]; 337 344 struct spi_message m; 345 + uint8_t opcode; 338 346 339 347 pr_debug("%s: %s from 0x%08x, len %zd\n", dev_name(&flash->spi->dev), 340 348 __func__, (u32)from, len); ··· 348 354 * Should add 1 byte DUMMY_BYTE. 349 355 */ 350 356 t[0].tx_buf = flash->command; 351 - t[0].len = m25p_cmdsz(flash) + FAST_READ_DUMMY_BYTE; 357 + t[0].len = m25p_cmdsz(flash) + (flash->fast_read ? 1 : 0); 352 358 spi_message_add_tail(&t[0], &m); 353 359 354 360 t[1].rx_buf = buf; ··· 370 376 */ 371 377 372 378 /* Set up the write data buffer. */ 373 - flash->command[0] = OPCODE_READ; 379 + opcode = flash->fast_read ? OPCODE_FAST_READ : OPCODE_NORM_READ; 380 + flash->command[0] = opcode; 374 381 m25p_addr2cmd(flash, from, flash->command); 375 382 376 383 spi_sync(flash->spi, &m); 377 384 378 - *retlen = m.actual_length - m25p_cmdsz(flash) - FAST_READ_DUMMY_BYTE; 385 + *retlen = m.actual_length - m25p_cmdsz(flash) - 386 + (flash->fast_read ? 1 : 0); 379 387 380 388 mutex_unlock(&flash->lock); 381 389 ··· 805 809 struct flash_info *info; 806 810 unsigned i; 807 811 struct mtd_part_parser_data ppdata; 812 + struct device_node __maybe_unused *np = spi->dev.of_node; 808 813 809 814 #ifdef CONFIG_MTD_OF_PARTS 810 - if (!of_device_is_available(spi->dev.of_node)) 815 + if (!of_device_is_available(np)) 811 816 return -ENODEV; 812 817 #endif 813 818 ··· 860 863 flash = kzalloc(sizeof *flash, GFP_KERNEL); 861 864 if (!flash) 862 865 return -ENOMEM; 863 - flash->command = kmalloc(MAX_CMD_SIZE + FAST_READ_DUMMY_BYTE, GFP_KERNEL); 866 + flash->command = kmalloc(MAX_CMD_SIZE + (flash->fast_read ? 1 : 0), 867 + GFP_KERNEL); 864 868 if (!flash->command) { 865 869 kfree(flash); 866 870 return -ENOMEM; ··· 917 919 flash->mtd.dev.parent = &spi->dev; 918 920 flash->page_size = info->page_size; 919 921 flash->mtd.writebufsize = flash->page_size; 922 + 923 + flash->fast_read = false; 924 + #ifdef CONFIG_OF 925 + if (np && of_property_read_bool(np, "m25p,fast-read")) 926 + flash->fast_read = true; 927 + #endif 928 + 929 + #ifdef CONFIG_M25PXX_USE_FAST_READ 930 + flash->fast_read = true; 931 + #endif 920 932 921 933 if (info->addr_width) 922 934 flash->addr_width = info->addr_width;