17b8b2201SBoris Brezillon // SPDX-License-Identifier: GPL-2.0 27b8b2201SBoris Brezillon /* 37b8b2201SBoris Brezillon * Copyright (C) 2005, Intec Automation Inc. 47b8b2201SBoris Brezillon * Copyright (C) 2014, Freescale Semiconductor, Inc. 57b8b2201SBoris Brezillon */ 67b8b2201SBoris Brezillon 77b8b2201SBoris Brezillon #include <linux/mtd/spi-nor.h> 87b8b2201SBoris Brezillon 97b8b2201SBoris Brezillon #include "core.h" 107b8b2201SBoris Brezillon 11e8aec15dSMantas Pucka static int 12e8aec15dSMantas Pucka w25q256_post_bfpt_fixups(struct spi_nor *nor, 13e8aec15dSMantas Pucka const struct sfdp_parameter_header *bfpt_header, 14a580293aSTudor Ambarus const struct sfdp_bfpt *bfpt) 15e8aec15dSMantas Pucka { 16e8aec15dSMantas Pucka /* 17e8aec15dSMantas Pucka * W25Q256JV supports 4B opcodes but W25Q256FV does not. 18e8aec15dSMantas Pucka * Unfortunately, Winbond has re-used the same JEDEC ID for both 19e8aec15dSMantas Pucka * variants which prevents us from defining a new entry in the parts 20e8aec15dSMantas Pucka * table. 21e8aec15dSMantas Pucka * To differentiate between W25Q256JV and W25Q256FV check SFDP header 22e8aec15dSMantas Pucka * version: only JV has JESD216A compliant structure (version 5). 23e8aec15dSMantas Pucka */ 24e8aec15dSMantas Pucka if (bfpt_header->major == SFDP_JESD216_MAJOR && 25e8aec15dSMantas Pucka bfpt_header->minor == SFDP_JESD216A_MINOR) 26e8aec15dSMantas Pucka nor->flags |= SNOR_F_4B_OPCODES; 27e8aec15dSMantas Pucka 28e8aec15dSMantas Pucka return 0; 29e8aec15dSMantas Pucka } 30e8aec15dSMantas Pucka 31e8aec15dSMantas Pucka static struct spi_nor_fixups w25q256_fixups = { 32e8aec15dSMantas Pucka .post_bfpt = w25q256_post_bfpt_fixups, 33e8aec15dSMantas Pucka }; 34e8aec15dSMantas Pucka 357b8b2201SBoris Brezillon static const struct flash_info winbond_parts[] = { 367b8b2201SBoris Brezillon /* Winbond -- w25x "blocks" are 64K, "sectors" are 4KiB */ 377b8b2201SBoris Brezillon { "w25x05", INFO(0xef3010, 0, 64 * 1024, 1, SECT_4K) }, 387b8b2201SBoris Brezillon { "w25x10", INFO(0xef3011, 0, 64 * 1024, 2, SECT_4K) }, 397b8b2201SBoris Brezillon { "w25x20", INFO(0xef3012, 0, 64 * 1024, 4, SECT_4K) }, 407b8b2201SBoris Brezillon { "w25x40", INFO(0xef3013, 0, 64 * 1024, 8, SECT_4K) }, 417b8b2201SBoris Brezillon { "w25x80", INFO(0xef3014, 0, 64 * 1024, 16, SECT_4K) }, 427b8b2201SBoris Brezillon { "w25x16", INFO(0xef3015, 0, 64 * 1024, 32, SECT_4K) }, 437b8b2201SBoris Brezillon { "w25q16dw", INFO(0xef6015, 0, 64 * 1024, 32, 447b8b2201SBoris Brezillon SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | 457b8b2201SBoris Brezillon SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) }, 467b8b2201SBoris Brezillon { "w25x32", INFO(0xef3016, 0, 64 * 1024, 64, SECT_4K) }, 477b8b2201SBoris Brezillon { "w25q16jv-im/jm", INFO(0xef7015, 0, 64 * 1024, 32, 487b8b2201SBoris Brezillon SECT_4K | SPI_NOR_DUAL_READ | 497b8b2201SBoris Brezillon SPI_NOR_QUAD_READ | SPI_NOR_HAS_LOCK | 507b8b2201SBoris Brezillon SPI_NOR_HAS_TB) }, 517b8b2201SBoris Brezillon { "w25q20cl", INFO(0xef4012, 0, 64 * 1024, 4, SECT_4K) }, 527b8b2201SBoris Brezillon { "w25q20bw", INFO(0xef5012, 0, 64 * 1024, 4, SECT_4K) }, 537b8b2201SBoris Brezillon { "w25q20ew", INFO(0xef6012, 0, 64 * 1024, 4, SECT_4K) }, 547b8b2201SBoris Brezillon { "w25q32", INFO(0xef4016, 0, 64 * 1024, 64, SECT_4K) }, 557b8b2201SBoris Brezillon { "w25q32dw", INFO(0xef6016, 0, 64 * 1024, 64, 567b8b2201SBoris Brezillon SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | 57b206b82dSMichael Walle SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) 58b206b82dSMichael Walle OTP_INFO(256, 3, 0x1000, 0x1000) 59b206b82dSMichael Walle }, 60b206b82dSMichael Walle 617b8b2201SBoris Brezillon { "w25q32jv", INFO(0xef7016, 0, 64 * 1024, 64, 627b8b2201SBoris Brezillon SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | 637b8b2201SBoris Brezillon SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) 647b8b2201SBoris Brezillon }, 657b8b2201SBoris Brezillon { "w25q32jwm", INFO(0xef8016, 0, 64 * 1024, 64, 667b8b2201SBoris Brezillon SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | 67b206b82dSMichael Walle SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) 68b206b82dSMichael Walle OTP_INFO(256, 3, 0x1000, 0x1000) }, 696eedfd85SIkjoon Jang { "w25q64jwm", INFO(0xef8017, 0, 64 * 1024, 128, 706eedfd85SIkjoon Jang SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | 716eedfd85SIkjoon Jang SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) }, 726eedfd85SIkjoon Jang { "w25q128jwm", INFO(0xef8018, 0, 64 * 1024, 256, 736eedfd85SIkjoon Jang SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | 746eedfd85SIkjoon Jang SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) }, 756eedfd85SIkjoon Jang { "w25q256jwm", INFO(0xef8019, 0, 64 * 1024, 512, 766eedfd85SIkjoon Jang SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | 776eedfd85SIkjoon Jang SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) }, 787b8b2201SBoris Brezillon { "w25x64", INFO(0xef3017, 0, 64 * 1024, 128, SECT_4K) }, 7999eae48fSRayagonda Kokatanur { "w25q64", INFO(0xef4017, 0, 64 * 1024, 128, 8099eae48fSRayagonda Kokatanur SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, 817b8b2201SBoris Brezillon { "w25q64dw", INFO(0xef6017, 0, 64 * 1024, 128, 827b8b2201SBoris Brezillon SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | 837b8b2201SBoris Brezillon SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) }, 840ee2872fSSven Van Asbroeck { "w25q64jvm", INFO(0xef7017, 0, 64 * 1024, 128, SECT_4K) }, 857b8b2201SBoris Brezillon { "w25q128fw", INFO(0xef6018, 0, 64 * 1024, 256, 867b8b2201SBoris Brezillon SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | 877b8b2201SBoris Brezillon SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) }, 887b8b2201SBoris Brezillon { "w25q128jv", INFO(0xef7018, 0, 64 * 1024, 256, 897b8b2201SBoris Brezillon SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | 907b8b2201SBoris Brezillon SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) }, 917b8b2201SBoris Brezillon { "w25q80", INFO(0xef5014, 0, 64 * 1024, 16, SECT_4K) }, 927b8b2201SBoris Brezillon { "w25q80bl", INFO(0xef4014, 0, 64 * 1024, 16, SECT_4K) }, 937b8b2201SBoris Brezillon { "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, SECT_4K) }, 947b8b2201SBoris Brezillon { "w25q256", INFO(0xef4019, 0, 64 * 1024, 512, 95e8aec15dSMantas Pucka SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) 96e8aec15dSMantas Pucka .fixups = &w25q256_fixups }, 977b8b2201SBoris Brezillon { "w25q256jvm", INFO(0xef7019, 0, 64 * 1024, 512, 987b8b2201SBoris Brezillon SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, 997b8b2201SBoris Brezillon { "w25q256jw", INFO(0xef6019, 0, 64 * 1024, 512, 1007b8b2201SBoris Brezillon SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, 1017b8b2201SBoris Brezillon { "w25m512jv", INFO(0xef7119, 0, 64 * 1024, 1024, 1027b8b2201SBoris Brezillon SECT_4K | SPI_NOR_QUAD_READ | SPI_NOR_DUAL_READ) }, 103ff013330SShuhao Mai { "w25q512jvq", INFO(0xef4020, 0, 64 * 1024, 1024, 104ff013330SShuhao Mai SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, 1057b8b2201SBoris Brezillon }; 1067b8b2201SBoris Brezillon 1077b8b2201SBoris Brezillon /** 1087b8b2201SBoris Brezillon * winbond_set_4byte_addr_mode() - Set 4-byte address mode for Winbond flashes. 1097b8b2201SBoris Brezillon * @nor: pointer to 'struct spi_nor'. 1107b8b2201SBoris Brezillon * @enable: true to enter the 4-byte address mode, false to exit the 4-byte 1117b8b2201SBoris Brezillon * address mode. 1127b8b2201SBoris Brezillon * 1137b8b2201SBoris Brezillon * Return: 0 on success, -errno otherwise. 1147b8b2201SBoris Brezillon */ 1157b8b2201SBoris Brezillon static int winbond_set_4byte_addr_mode(struct spi_nor *nor, bool enable) 1167b8b2201SBoris Brezillon { 1177b8b2201SBoris Brezillon int ret; 1187b8b2201SBoris Brezillon 1197b8b2201SBoris Brezillon ret = spi_nor_set_4byte_addr_mode(nor, enable); 1207b8b2201SBoris Brezillon if (ret || enable) 1217b8b2201SBoris Brezillon return ret; 1227b8b2201SBoris Brezillon 1237b8b2201SBoris Brezillon /* 1247b8b2201SBoris Brezillon * On Winbond W25Q256FV, leaving 4byte mode causes the Extended Address 1257b8b2201SBoris Brezillon * Register to be set to 1, so all 3-byte-address reads come from the 1267b8b2201SBoris Brezillon * second 16M. We must clear the register to enable normal behavior. 1277b8b2201SBoris Brezillon */ 1287b8b2201SBoris Brezillon ret = spi_nor_write_enable(nor); 1297b8b2201SBoris Brezillon if (ret) 1307b8b2201SBoris Brezillon return ret; 1317b8b2201SBoris Brezillon 1327b8b2201SBoris Brezillon ret = spi_nor_write_ear(nor, 0); 1337b8b2201SBoris Brezillon if (ret) 1347b8b2201SBoris Brezillon return ret; 1357b8b2201SBoris Brezillon 1367b8b2201SBoris Brezillon return spi_nor_write_disable(nor); 1377b8b2201SBoris Brezillon } 1387b8b2201SBoris Brezillon 139b206b82dSMichael Walle static const struct spi_nor_otp_ops winbond_otp_ops = { 140b206b82dSMichael Walle .read = spi_nor_otp_read_secr, 141b206b82dSMichael Walle .write = spi_nor_otp_write_secr, 142*c6ec3e1eSMichael Walle .erase = spi_nor_otp_erase_secr, 143b206b82dSMichael Walle .lock = spi_nor_otp_lock_sr2, 144b206b82dSMichael Walle .is_locked = spi_nor_otp_is_locked_sr2, 145b206b82dSMichael Walle }; 146b206b82dSMichael Walle 1477b8b2201SBoris Brezillon static void winbond_default_init(struct spi_nor *nor) 1487b8b2201SBoris Brezillon { 149829ec640STudor Ambarus nor->params->set_4byte_addr_mode = winbond_set_4byte_addr_mode; 150b206b82dSMichael Walle if (nor->params->otp.org->n_regions) 151b206b82dSMichael Walle nor->params->otp.ops = &winbond_otp_ops; 1527b8b2201SBoris Brezillon } 1537b8b2201SBoris Brezillon 1547b8b2201SBoris Brezillon static const struct spi_nor_fixups winbond_fixups = { 1557b8b2201SBoris Brezillon .default_init = winbond_default_init, 1567b8b2201SBoris Brezillon }; 1577b8b2201SBoris Brezillon 1587b8b2201SBoris Brezillon const struct spi_nor_manufacturer spi_nor_winbond = { 1597b8b2201SBoris Brezillon .name = "winbond", 1607b8b2201SBoris Brezillon .parts = winbond_parts, 1617b8b2201SBoris Brezillon .nparts = ARRAY_SIZE(winbond_parts), 1627b8b2201SBoris Brezillon .fixups = &winbond_fixups, 1637b8b2201SBoris Brezillon }; 164