a701262c02
* Fix refcounting for unpartitioned MTDs * Fix misspelled function parameter 'section' * Remove unneeded break * cmdline parser: Fix parsing of part-names with colons * mtdpart: Fix misdocumented function parameter 'mtd' MTD devices: * phram: - Allow the user to set the erase page size - File headers are not good candidates for kernel-doc * physmap-bt1-rom: Fix __iomem addrspace removal warning * plat-ram: correctly free memory on error path in platram_probe() * powernv_flash: Add function names to headers and fix 'dev' * docg3: Fix kernel-doc 'bad line' and 'excessive doc' issues UBI cleanup fixes: * gluebi: Fix misnamed function parameter documentation * wl: Fix a couple of kernel-doc issues * eba: Fix a couple of misdocumentation issues * kapi: Correct documentation for 'ubi_leb_read_sg's 'sgl' parameter * Document 'ubi_num' in struct mtd_dev_param Generic NAND core: * ECC management: - Add an I/O request tweaking mechanism - Entire rework of the software BCH ECC driver, creation of a real ECC engine, getting rid of raw NAND structures, migration to more generic prototypes, misc fixes and style cleanup. Moved now to the Generic NAND layer. - Entire rework of the software Hamming ECC driver, creation of a real ECC engine, getting rid of raw NAND structures, misc renames, comment updates, cleanup, and style fixes. Moved now to the generic NAND layer. - Necessary plumbing at the NAND level to retrieve generic NAND ECC engines (softwares and on-die). - Update of the bindings. Raw NAND core: * Geting rid of the chip->ecc.priv entry. * Fix miscellaneous typos in kernel-doc Raw NAND controller drivers: * Arasan: Document 'anfc_op's 'buf' member * AU1550: Ensure the presence of the right includes * Brcmnand: Demote non-conformant kernel-doc headers * Cafe: Remove superfluous param doc and add another * Davinci: Do not use extra dereferencing * Diskonchip: Marking unused variables as __always_unused * GPMI: - Fix the driver only sense CS0 R/B issue - Fix the random DMA timeout issue - Use a single line for of_device_id - Use of_device_get_match_data() - Fix reference count leak in gpmi ops - Cleanup makefile - Fix binding matching of clocks on different SoCs * Ingenic: remove redundant get_device() in ingenic_ecc_get() * Intel LGM: New NAND controller driver * Marvell: Drop useless line * Meson: - Fix a resource leak in init - Fix meson_nfc_dma_buffer_release() arguments * mxc: - Use device_get_match_data() - Use a single line for of_device_id - Remove platform data support * Omap: - Fix a bunch of kernel-doc misdemeanours - Finish ELM half populated function header, demote empty ones * s3c2410: Add documentation for 2 missing struct members * Sunxi: Document 'sunxi_nfc's 'caps' member * Qcom: - Add support for SDX55 - Support for IPQ6018 QPIC NAND controller - Fix DMA sync on FLASH_STATUS register read * Rockchip: New NAND controller driver for RK3308, RK2928 and others * Sunxi: Add MDMA support ONENAND: * bbt: Fix expected kernel-doc formatting * Fix some kernel-doc misdemeanours * Fix expected kernel-doc formatting * Use mtd->oops_panic_write as condition SPI-NAND core: * Creation of a SPI-NAND on-die ECC engine * Move ECC related definitions earlier in the driver * Fix typo in comment * Fill a default ECC provider/algorithm * Remove outdated comment * Fix OOB read * Allow the case where there is no ECC engine * Use the external ECC engine logic SPI-NAND chip drivers: * Micron: - Add support for MT29F2G01AAAED - Use more specific names * Macronix: - Add support for MX35LFxG24AD - Add support for MX35LFxGE4AD * Toshiba: Demote non-conformant kernel-doc header SPI-NOR core: * Initial support for stateful Octal DTR mode using volatile settings * Preliminary support for JEDEC 251 (xSPI) and JEDEC 216D standards * Support for Cypress Semper flash * Support to specify ECC block size of SPI NOR flashes * Fixes to avoid clearing of non-volatile Block Protection bits at probe * hisi-sfc: Demote non-conformant kernel-doc -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE9HuaYnbmDhq/XIDIJWrqGEe9VoQFAl/aS1sACgkQJWrqGEe9 VoTOqQgAiu3XfM7iHvFDiz0SVL+RFzqi2jnwXHgGDATTq+vOPwAMaqnqF6xZZZLA BIKsLwVRJnZ9Vu6Xl2vAPaVob+QKbsvvP9kkk9H/dZJ6IW4XsWFqYotPSQQ/6ZBO 2bmw9nQ0ZcksyUkdASGHuYlW/H5DAtQNQuQxGF5ywlZMxTEnD0wxUD5tccf1o3xk UYvQsQ0MNMriWCxbcdUXUmDOE9DuPdDysuLDPJs0WLnlNGgwZ/mnLvSRm6wm4nRT Y/pB6VcTMMEYAsujdf89LjCHlfCQuH5Zls9pxic8GkHjOcEqUeMLLXkkbQ1+61AO 93QsOhKAsju49/aHpbpvwu5SEmLojA== =1fie -----END PGP SIGNATURE----- Merge tag 'mtd/for-5.11' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux Pull MTD updates from Miquel Raynal: "MTD core: - Fix refcounting for unpartitioned MTDs - Fix misspelled function parameter 'section' - Remove unneeded break - cmdline parser: Fix parsing of part-names with colons - mtdpart: Fix misdocumented function parameter 'mtd' MTD devices: - phram: - Allow the user to set the erase page size - File headers are not good candidates for kernel-doc - physmap-bt1-rom: Fix __iomem addrspace removal warning - plat-ram: correctly free memory on error path in platram_probe() - powernv_flash: Add function names to headers and fix 'dev' - docg3: Fix kernel-doc 'bad line' and 'excessive doc' issues UBI cleanup fixes: - gluebi: Fix misnamed function parameter documentation - wl: Fix a couple of kernel-doc issues - eba: Fix a couple of misdocumentation issues - kapi: Correct documentation for 'ubi_leb_read_sg's 'sgl' parameter - Document 'ubi_num' in struct mtd_dev_param Generic NAND core ECC management: - Add an I/O request tweaking mechanism - Entire rework of the software BCH ECC driver, creation of a real ECC engine, getting rid of raw NAND structures, migration to more generic prototypes, misc fixes and style cleanup. Moved now to the Generic NAND layer. - Entire rework of the software Hamming ECC driver, creation of a real ECC engine, getting rid of raw NAND structures, misc renames, comment updates, cleanup, and style fixes. Moved now to the generic NAND layer. - Necessary plumbing at the NAND level to retrieve generic NAND ECC engines (softwares and on-die). - Update of the bindings. Raw NAND core: - Geting rid of the chip->ecc.priv entry. - Fix miscellaneous typos in kernel-doc Raw NAND controller drivers: - Arasan: Document 'anfc_op's 'buf' member - AU1550: Ensure the presence of the right includes - Brcmnand: Demote non-conformant kernel-doc headers - Cafe: Remove superfluous param doc and add another - Davinci: Do not use extra dereferencing - Diskonchip: Marking unused variables as __always_unused - GPMI: - Fix the driver only sense CS0 R/B issue - Fix the random DMA timeout issue - Use a single line for of_device_id - Use of_device_get_match_data() - Fix reference count leak in gpmi ops - Cleanup makefile - Fix binding matching of clocks on different SoCs - Ingenic: remove redundant get_device() in ingenic_ecc_get() - Intel LGM: New NAND controller driver - Marvell: Drop useless line - Meson: - Fix a resource leak in init - Fix meson_nfc_dma_buffer_release() arguments - mxc: - Use device_get_match_data() - Use a single line for of_device_id - Remove platform data support - Omap: - Fix a bunch of kernel-doc misdemeanours - Finish ELM half populated function header, demote empty ones - s3c2410: Add documentation for 2 missing struct members - Sunxi: Document 'sunxi_nfc's 'caps' member - Qcom: - Add support for SDX55 - Support for IPQ6018 QPIC NAND controller - Fix DMA sync on FLASH_STATUS register read - Rockchip: New NAND controller driver for RK3308, RK2928 and others - Sunxi: Add MDMA support ONENAND: - bbt: Fix expected kernel-doc formatting - Fix some kernel-doc misdemeanours - Fix expected kernel-doc formatting - Use mtd->oops_panic_write as condition SPI-NAND core: - Creation of a SPI-NAND on-die ECC engine - Move ECC related definitions earlier in the driver - Fix typo in comment - Fill a default ECC provider/algorithm - Remove outdated comment - Fix OOB read - Allow the case where there is no ECC engine - Use the external ECC engine logic SPI-NAND chip drivers: - Micron: - Add support for MT29F2G01AAAED - Use more specific names - Macronix: - Add support for MX35LFxG24AD - Add support for MX35LFxGE4AD - Toshiba: Demote non-conformant kernel-doc header SPI-NOR core: - Initial support for stateful Octal DTR mode using volatile settings - Preliminary support for JEDEC 251 (xSPI) and JEDEC 216D standards - Support for Cypress Semper flash - Support to specify ECC block size of SPI NOR flashes - Fixes to avoid clearing of non-volatile Block Protection bits at probe - hisi-sfc: Demote non-conformant kernel-doc" * tag 'mtd/for-5.11' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux: (120 commits) mtd: spinand: macronix: Add support for MX35LFxG24AD mtd: rawnand: rockchip: NFC driver for RK3308, RK2928 and others dt-bindings: mtd: Describe Rockchip RK3xxx NAND flash controller mtd: rawnand: gpmi: Use a single line for of_device_id mtd: rawnand: gpmi: Fix the random DMA timeout issue mtd: rawnand: gpmi: Fix the driver only sense CS0 R/B issue mtd: rawnand: qcom: Add NAND controller support for SDX55 dt-bindings: qcom_nandc: Add SDX55 QPIC NAND documentation mtd: rawnand: mxc: Use a single line for of_device_id mtd: rawnand: mxc: Use device_get_match_data() mtd: rawnand: meson: Fix a resource leak in init mtd: rawnand: gpmi: Use of_device_get_match_data() mtd: rawnand: Add NAND controller support on Intel LGM SoC dt-bindings: mtd: Add Nand Flash Controller support for Intel LGM SoC mtd: spinand: micron: Add support for MT29F2G01AAAED mtd: spinand: micron: Use more specific names mtd: rawnand: gpmi: fix reference count leak in gpmi ops dt-bindings: mtd: gpmi-nand: Fix matching of clocks on different SoCs mtd: spinand: macronix: Add support for MX35LFxGE4AD mtd: plat-ram: correctly free memory on error path in platram_probe() ...
237 lines
5.0 KiB
C
237 lines
5.0 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (C) 2006-2007 PA Semi, Inc
|
|
*
|
|
* Author: Egor Martovetsky <egor@pasemi.com>
|
|
* Maintained by: Olof Johansson <olof@lixom.net>
|
|
*
|
|
* Driver for the PWRficient onchip NAND flash interface
|
|
*/
|
|
|
|
#undef DEBUG
|
|
|
|
#include <linux/slab.h>
|
|
#include <linux/module.h>
|
|
#include <linux/mtd/mtd.h>
|
|
#include <linux/mtd/rawnand.h>
|
|
#include <linux/of_address.h>
|
|
#include <linux/of_irq.h>
|
|
#include <linux/of_platform.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/pci.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#define LBICTRL_LPCCTL_NR 0x00004000
|
|
#define CLE_PIN_CTL 15
|
|
#define ALE_PIN_CTL 14
|
|
|
|
static unsigned int lpcctl;
|
|
static struct mtd_info *pasemi_nand_mtd;
|
|
static struct nand_controller controller;
|
|
static const char driver_name[] = "pasemi-nand";
|
|
|
|
static void pasemi_read_buf(struct nand_chip *chip, u_char *buf, int len)
|
|
{
|
|
while (len > 0x800) {
|
|
memcpy_fromio(buf, chip->legacy.IO_ADDR_R, 0x800);
|
|
buf += 0x800;
|
|
len -= 0x800;
|
|
}
|
|
memcpy_fromio(buf, chip->legacy.IO_ADDR_R, len);
|
|
}
|
|
|
|
static void pasemi_write_buf(struct nand_chip *chip, const u_char *buf,
|
|
int len)
|
|
{
|
|
while (len > 0x800) {
|
|
memcpy_toio(chip->legacy.IO_ADDR_R, buf, 0x800);
|
|
buf += 0x800;
|
|
len -= 0x800;
|
|
}
|
|
memcpy_toio(chip->legacy.IO_ADDR_R, buf, len);
|
|
}
|
|
|
|
static void pasemi_hwcontrol(struct nand_chip *chip, int cmd,
|
|
unsigned int ctrl)
|
|
{
|
|
if (cmd == NAND_CMD_NONE)
|
|
return;
|
|
|
|
if (ctrl & NAND_CLE)
|
|
out_8(chip->legacy.IO_ADDR_W + (1 << CLE_PIN_CTL), cmd);
|
|
else
|
|
out_8(chip->legacy.IO_ADDR_W + (1 << ALE_PIN_CTL), cmd);
|
|
|
|
/* Push out posted writes */
|
|
eieio();
|
|
inl(lpcctl);
|
|
}
|
|
|
|
static int pasemi_device_ready(struct nand_chip *chip)
|
|
{
|
|
return !!(inl(lpcctl) & LBICTRL_LPCCTL_NR);
|
|
}
|
|
|
|
static int pasemi_attach_chip(struct nand_chip *chip)
|
|
{
|
|
chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
|
|
|
|
if (chip->ecc.algo == NAND_ECC_ALGO_UNKNOWN)
|
|
chip->ecc.algo = NAND_ECC_ALGO_HAMMING;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct nand_controller_ops pasemi_ops = {
|
|
.attach_chip = pasemi_attach_chip,
|
|
};
|
|
|
|
static int pasemi_nand_probe(struct platform_device *ofdev)
|
|
{
|
|
struct device *dev = &ofdev->dev;
|
|
struct pci_dev *pdev;
|
|
struct device_node *np = dev->of_node;
|
|
struct resource res;
|
|
struct nand_chip *chip;
|
|
int err = 0;
|
|
|
|
err = of_address_to_resource(np, 0, &res);
|
|
|
|
if (err)
|
|
return -EINVAL;
|
|
|
|
/* We only support one device at the moment */
|
|
if (pasemi_nand_mtd)
|
|
return -ENODEV;
|
|
|
|
dev_dbg(dev, "pasemi_nand at %pR\n", &res);
|
|
|
|
/* Allocate memory for MTD device structure and private data */
|
|
chip = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
|
|
if (!chip) {
|
|
err = -ENOMEM;
|
|
goto out;
|
|
}
|
|
|
|
controller.ops = &pasemi_ops;
|
|
nand_controller_init(&controller);
|
|
chip->controller = &controller;
|
|
|
|
pasemi_nand_mtd = nand_to_mtd(chip);
|
|
|
|
/* Link the private data with the MTD structure */
|
|
pasemi_nand_mtd->dev.parent = dev;
|
|
|
|
chip->legacy.IO_ADDR_R = of_iomap(np, 0);
|
|
chip->legacy.IO_ADDR_W = chip->legacy.IO_ADDR_R;
|
|
|
|
if (!chip->legacy.IO_ADDR_R) {
|
|
err = -EIO;
|
|
goto out_mtd;
|
|
}
|
|
|
|
pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa008, NULL);
|
|
if (!pdev) {
|
|
err = -ENODEV;
|
|
goto out_ior;
|
|
}
|
|
|
|
lpcctl = pci_resource_start(pdev, 0);
|
|
pci_dev_put(pdev);
|
|
|
|
if (!request_region(lpcctl, 4, driver_name)) {
|
|
err = -EBUSY;
|
|
goto out_ior;
|
|
}
|
|
|
|
chip->legacy.cmd_ctrl = pasemi_hwcontrol;
|
|
chip->legacy.dev_ready = pasemi_device_ready;
|
|
chip->legacy.read_buf = pasemi_read_buf;
|
|
chip->legacy.write_buf = pasemi_write_buf;
|
|
chip->legacy.chip_delay = 0;
|
|
|
|
/* Enable the following for a flash based bad block table */
|
|
chip->bbt_options = NAND_BBT_USE_FLASH;
|
|
|
|
/* Scan to find existence of the device */
|
|
err = nand_scan(chip, 1);
|
|
if (err)
|
|
goto out_lpc;
|
|
|
|
if (mtd_device_register(pasemi_nand_mtd, NULL, 0)) {
|
|
dev_err(dev, "Unable to register MTD device\n");
|
|
err = -ENODEV;
|
|
goto out_cleanup_nand;
|
|
}
|
|
|
|
dev_info(dev, "PA Semi NAND flash at %pR, control at I/O %x\n", &res,
|
|
lpcctl);
|
|
|
|
return 0;
|
|
|
|
out_cleanup_nand:
|
|
nand_cleanup(chip);
|
|
out_lpc:
|
|
release_region(lpcctl, 4);
|
|
out_ior:
|
|
iounmap(chip->legacy.IO_ADDR_R);
|
|
out_mtd:
|
|
kfree(chip);
|
|
out:
|
|
return err;
|
|
}
|
|
|
|
static int pasemi_nand_remove(struct platform_device *ofdev)
|
|
{
|
|
struct nand_chip *chip;
|
|
int ret;
|
|
|
|
if (!pasemi_nand_mtd)
|
|
return 0;
|
|
|
|
chip = mtd_to_nand(pasemi_nand_mtd);
|
|
|
|
/* Release resources, unregister device */
|
|
ret = mtd_device_unregister(pasemi_nand_mtd);
|
|
WARN_ON(ret);
|
|
nand_cleanup(chip);
|
|
|
|
release_region(lpcctl, 4);
|
|
|
|
iounmap(chip->legacy.IO_ADDR_R);
|
|
|
|
/* Free the MTD device structure */
|
|
kfree(chip);
|
|
|
|
pasemi_nand_mtd = NULL;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct of_device_id pasemi_nand_match[] =
|
|
{
|
|
{
|
|
.compatible = "pasemi,localbus-nand",
|
|
},
|
|
{},
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, pasemi_nand_match);
|
|
|
|
static struct platform_driver pasemi_nand_driver =
|
|
{
|
|
.driver = {
|
|
.name = driver_name,
|
|
.of_match_table = pasemi_nand_match,
|
|
},
|
|
.probe = pasemi_nand_probe,
|
|
.remove = pasemi_nand_remove,
|
|
};
|
|
|
|
module_platform_driver(pasemi_nand_driver);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_AUTHOR("Egor Martovetsky <egor@pasemi.com>");
|
|
MODULE_DESCRIPTION("NAND flash interface driver for PA Semi PWRficient");
|