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

Merge tag 'mtd/fixes-for-5.2-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux

Pull mtd fixes from Miquel Raynal:

- Set the raw NAND number of targets to the right value

- Fix a bug uncovered by a recent patch on Spansion SPI-NOR flashes

* tag 'mtd/fixes-for-5.2-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux:
mtd: spi-nor: use 16-bit WRR command when QE is set on spansion flashes
mtd: rawnand: initialize ntargets with maxchips

+113 -12
+2 -1
drivers/mtd/nand/raw/nand_base.c
··· 4662 4662 memorg = nanddev_get_memorg(&chip->base); 4663 4663 memorg->planes_per_lun = 1; 4664 4664 memorg->luns_per_target = 1; 4665 - memorg->ntargets = 1; 4666 4665 4667 4666 /* 4668 4667 * Reset the chip, required by some chips (e.g. Micron MT29FxGxxxxx) ··· 5025 5026 ret = nand_legacy_check_hooks(chip); 5026 5027 if (ret) 5027 5028 return ret; 5029 + 5030 + memorg->ntargets = maxchips; 5028 5031 5029 5032 /* Read the flash type */ 5030 5033 ret = nand_detect(chip, table);
+108 -11
drivers/mtd/spi-nor/spi-nor.c
··· 1636 1636 return 0; 1637 1637 } 1638 1638 1639 + /** 1640 + * spi_nor_clear_sr_bp() - clear the Status Register Block Protection bits. 1641 + * @nor: pointer to a 'struct spi_nor' 1642 + * 1643 + * Read-modify-write function that clears the Block Protection bits from the 1644 + * Status Register without affecting other bits. 1645 + * 1646 + * Return: 0 on success, -errno otherwise. 1647 + */ 1648 + static int spi_nor_clear_sr_bp(struct spi_nor *nor) 1649 + { 1650 + int ret; 1651 + u8 mask = SR_BP2 | SR_BP1 | SR_BP0; 1652 + 1653 + ret = read_sr(nor); 1654 + if (ret < 0) { 1655 + dev_err(nor->dev, "error while reading status register\n"); 1656 + return ret; 1657 + } 1658 + 1659 + write_enable(nor); 1660 + 1661 + ret = write_sr(nor, ret & ~mask); 1662 + if (ret) { 1663 + dev_err(nor->dev, "write to status register failed\n"); 1664 + return ret; 1665 + } 1666 + 1667 + ret = spi_nor_wait_till_ready(nor); 1668 + if (ret) 1669 + dev_err(nor->dev, "timeout while writing status register\n"); 1670 + return ret; 1671 + } 1672 + 1673 + /** 1674 + * spi_nor_spansion_clear_sr_bp() - clear the Status Register Block Protection 1675 + * bits on spansion flashes. 1676 + * @nor: pointer to a 'struct spi_nor' 1677 + * 1678 + * Read-modify-write function that clears the Block Protection bits from the 1679 + * Status Register without affecting other bits. The function is tightly 1680 + * coupled with the spansion_quad_enable() function. Both assume that the Write 1681 + * Register with 16 bits, together with the Read Configuration Register (35h) 1682 + * instructions are supported. 1683 + * 1684 + * Return: 0 on success, -errno otherwise. 1685 + */ 1686 + static int spi_nor_spansion_clear_sr_bp(struct spi_nor *nor) 1687 + { 1688 + int ret; 1689 + u8 mask = SR_BP2 | SR_BP1 | SR_BP0; 1690 + u8 sr_cr[2] = {0}; 1691 + 1692 + /* Check current Quad Enable bit value. */ 1693 + ret = read_cr(nor); 1694 + if (ret < 0) { 1695 + dev_err(nor->dev, 1696 + "error while reading configuration register\n"); 1697 + return ret; 1698 + } 1699 + 1700 + /* 1701 + * When the configuration register Quad Enable bit is one, only the 1702 + * Write Status (01h) command with two data bytes may be used. 1703 + */ 1704 + if (ret & CR_QUAD_EN_SPAN) { 1705 + sr_cr[1] = ret; 1706 + 1707 + ret = read_sr(nor); 1708 + if (ret < 0) { 1709 + dev_err(nor->dev, 1710 + "error while reading status register\n"); 1711 + return ret; 1712 + } 1713 + sr_cr[0] = ret & ~mask; 1714 + 1715 + ret = write_sr_cr(nor, sr_cr); 1716 + if (ret) 1717 + dev_err(nor->dev, "16-bit write register failed\n"); 1718 + return ret; 1719 + } 1720 + 1721 + /* 1722 + * If the Quad Enable bit is zero, use the Write Status (01h) command 1723 + * with one data byte. 1724 + */ 1725 + return spi_nor_clear_sr_bp(nor); 1726 + } 1727 + 1639 1728 /* Used when the "_ext_id" is two bytes at most */ 1640 1729 #define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \ 1641 1730 .id = { \ ··· 3749 3660 default: 3750 3661 /* Kept only for backward compatibility purpose. */ 3751 3662 params->quad_enable = spansion_quad_enable; 3663 + if (nor->clear_sr_bp) 3664 + nor->clear_sr_bp = spi_nor_spansion_clear_sr_bp; 3752 3665 break; 3753 3666 } 3754 3667 ··· 4003 3912 { 4004 3913 int err; 4005 3914 4006 - /* 4007 - * Atmel, SST, Intel/Numonyx, and others serial NOR tend to power up 4008 - * with the software protection bits set 4009 - */ 4010 - if (JEDEC_MFR(nor->info) == SNOR_MFR_ATMEL || 4011 - JEDEC_MFR(nor->info) == SNOR_MFR_INTEL || 4012 - JEDEC_MFR(nor->info) == SNOR_MFR_SST || 4013 - nor->info->flags & SPI_NOR_HAS_LOCK) { 4014 - write_enable(nor); 4015 - write_sr(nor, 0); 4016 - spi_nor_wait_till_ready(nor); 3915 + if (nor->clear_sr_bp) { 3916 + err = nor->clear_sr_bp(nor); 3917 + if (err) { 3918 + dev_err(nor->dev, 3919 + "fail to clear block protection bits\n"); 3920 + return err; 3921 + } 4017 3922 } 4018 3923 4019 3924 if (nor->quad_enable) { ··· 4133 4046 */ 4134 4047 if (info->flags & SPI_S3AN) 4135 4048 nor->flags |= SNOR_F_READY_XSR_RDY; 4049 + 4050 + /* 4051 + * Atmel, SST, Intel/Numonyx, and others serial NOR tend to power up 4052 + * with the software protection bits set. 4053 + */ 4054 + if (JEDEC_MFR(nor->info) == SNOR_MFR_ATMEL || 4055 + JEDEC_MFR(nor->info) == SNOR_MFR_INTEL || 4056 + JEDEC_MFR(nor->info) == SNOR_MFR_SST || 4057 + nor->info->flags & SPI_NOR_HAS_LOCK) 4058 + nor->clear_sr_bp = spi_nor_clear_sr_bp; 4136 4059 4137 4060 /* Parse the Serial Flash Discoverable Parameters table. */ 4138 4061 ret = spi_nor_init_params(nor, &params);
+3
include/linux/mtd/spi-nor.h
··· 373 373 * @flash_unlock: [FLASH-SPECIFIC] unlock a region of the SPI NOR 374 374 * @flash_is_locked: [FLASH-SPECIFIC] check if a region of the SPI NOR is 375 375 * @quad_enable: [FLASH-SPECIFIC] enables SPI NOR quad mode 376 + * @clear_sr_bp: [FLASH-SPECIFIC] clears the Block Protection Bits from 377 + * the SPI NOR Status Register. 376 378 * completely locked 377 379 * @priv: the private data 378 380 */ ··· 412 410 int (*flash_unlock)(struct spi_nor *nor, loff_t ofs, uint64_t len); 413 411 int (*flash_is_locked)(struct spi_nor *nor, loff_t ofs, uint64_t len); 414 412 int (*quad_enable)(struct spi_nor *nor); 413 + int (*clear_sr_bp)(struct spi_nor *nor); 415 414 416 415 void *priv; 417 416 };