mirror of
https://github.com/edk2-porting/linux-next.git
synced 2025-01-26 15:45:14 +08:00
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() ...
363 lines
7.9 KiB
C
363 lines
7.9 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (C) 2004 Embedded Edge, LLC
|
|
*/
|
|
|
|
#include <linux/delay.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/module.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/mtd/mtd.h>
|
|
#include <linux/mtd/rawnand.h>
|
|
#include <linux/mtd/partitions.h>
|
|
#include <linux/platform_device.h>
|
|
#include <asm/io.h>
|
|
#include <asm/mach-au1x00/au1000.h>
|
|
#include <asm/mach-au1x00/au1550nd.h>
|
|
|
|
|
|
struct au1550nd_ctx {
|
|
struct nand_controller controller;
|
|
struct nand_chip chip;
|
|
|
|
int cs;
|
|
void __iomem *base;
|
|
};
|
|
|
|
static struct au1550nd_ctx *chip_to_au_ctx(struct nand_chip *this)
|
|
{
|
|
return container_of(this, struct au1550nd_ctx, chip);
|
|
}
|
|
|
|
/**
|
|
* au_write_buf - write buffer to chip
|
|
* @this: NAND chip object
|
|
* @buf: data buffer
|
|
* @len: number of bytes to write
|
|
*
|
|
* write function for 8bit buswidth
|
|
*/
|
|
static void au_write_buf(struct nand_chip *this, const void *buf,
|
|
unsigned int len)
|
|
{
|
|
struct au1550nd_ctx *ctx = chip_to_au_ctx(this);
|
|
const u8 *p = buf;
|
|
int i;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
writeb(p[i], ctx->base + MEM_STNAND_DATA);
|
|
wmb(); /* drain writebuffer */
|
|
}
|
|
}
|
|
|
|
/**
|
|
* au_read_buf - read chip data into buffer
|
|
* @this: NAND chip object
|
|
* @buf: buffer to store date
|
|
* @len: number of bytes to read
|
|
*
|
|
* read function for 8bit buswidth
|
|
*/
|
|
static void au_read_buf(struct nand_chip *this, void *buf,
|
|
unsigned int len)
|
|
{
|
|
struct au1550nd_ctx *ctx = chip_to_au_ctx(this);
|
|
u8 *p = buf;
|
|
int i;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
p[i] = readb(ctx->base + MEM_STNAND_DATA);
|
|
wmb(); /* drain writebuffer */
|
|
}
|
|
}
|
|
|
|
/**
|
|
* au_write_buf16 - write buffer to chip
|
|
* @this: NAND chip object
|
|
* @buf: data buffer
|
|
* @len: number of bytes to write
|
|
*
|
|
* write function for 16bit buswidth
|
|
*/
|
|
static void au_write_buf16(struct nand_chip *this, const void *buf,
|
|
unsigned int len)
|
|
{
|
|
struct au1550nd_ctx *ctx = chip_to_au_ctx(this);
|
|
const u16 *p = buf;
|
|
unsigned int i;
|
|
|
|
len >>= 1;
|
|
for (i = 0; i < len; i++) {
|
|
writew(p[i], ctx->base + MEM_STNAND_DATA);
|
|
wmb(); /* drain writebuffer */
|
|
}
|
|
}
|
|
|
|
/**
|
|
* au_read_buf16 - read chip data into buffer
|
|
* @this: NAND chip object
|
|
* @buf: buffer to store date
|
|
* @len: number of bytes to read
|
|
*
|
|
* read function for 16bit buswidth
|
|
*/
|
|
static void au_read_buf16(struct nand_chip *this, void *buf, unsigned int len)
|
|
{
|
|
struct au1550nd_ctx *ctx = chip_to_au_ctx(this);
|
|
unsigned int i;
|
|
u16 *p = buf;
|
|
|
|
len >>= 1;
|
|
for (i = 0; i < len; i++) {
|
|
p[i] = readw(ctx->base + MEM_STNAND_DATA);
|
|
wmb(); /* drain writebuffer */
|
|
}
|
|
}
|
|
|
|
static int find_nand_cs(unsigned long nand_base)
|
|
{
|
|
void __iomem *base =
|
|
(void __iomem *)KSEG1ADDR(AU1000_STATIC_MEM_PHYS_ADDR);
|
|
unsigned long addr, staddr, start, mask, end;
|
|
int i;
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
addr = 0x1000 + (i * 0x10); /* CSx */
|
|
staddr = __raw_readl(base + addr + 0x08); /* STADDRx */
|
|
/* figure out the decoded range of this CS */
|
|
start = (staddr << 4) & 0xfffc0000;
|
|
mask = (staddr << 18) & 0xfffc0000;
|
|
end = (start | (start - 1)) & ~(start ^ mask);
|
|
if ((nand_base >= start) && (nand_base < end))
|
|
return i;
|
|
}
|
|
|
|
return -ENODEV;
|
|
}
|
|
|
|
static int au1550nd_waitrdy(struct nand_chip *this, unsigned int timeout_ms)
|
|
{
|
|
unsigned long timeout_jiffies = jiffies;
|
|
|
|
timeout_jiffies += msecs_to_jiffies(timeout_ms) + 1;
|
|
do {
|
|
if (alchemy_rdsmem(AU1000_MEM_STSTAT) & 0x1)
|
|
return 0;
|
|
|
|
usleep_range(10, 100);
|
|
} while (time_before(jiffies, timeout_jiffies));
|
|
|
|
return -ETIMEDOUT;
|
|
}
|
|
|
|
static int au1550nd_exec_instr(struct nand_chip *this,
|
|
const struct nand_op_instr *instr)
|
|
{
|
|
struct au1550nd_ctx *ctx = chip_to_au_ctx(this);
|
|
unsigned int i;
|
|
int ret = 0;
|
|
|
|
switch (instr->type) {
|
|
case NAND_OP_CMD_INSTR:
|
|
writeb(instr->ctx.cmd.opcode,
|
|
ctx->base + MEM_STNAND_CMD);
|
|
/* Drain the writebuffer */
|
|
wmb();
|
|
break;
|
|
|
|
case NAND_OP_ADDR_INSTR:
|
|
for (i = 0; i < instr->ctx.addr.naddrs; i++) {
|
|
writeb(instr->ctx.addr.addrs[i],
|
|
ctx->base + MEM_STNAND_ADDR);
|
|
/* Drain the writebuffer */
|
|
wmb();
|
|
}
|
|
break;
|
|
|
|
case NAND_OP_DATA_IN_INSTR:
|
|
if ((this->options & NAND_BUSWIDTH_16) &&
|
|
!instr->ctx.data.force_8bit)
|
|
au_read_buf16(this, instr->ctx.data.buf.in,
|
|
instr->ctx.data.len);
|
|
else
|
|
au_read_buf(this, instr->ctx.data.buf.in,
|
|
instr->ctx.data.len);
|
|
break;
|
|
|
|
case NAND_OP_DATA_OUT_INSTR:
|
|
if ((this->options & NAND_BUSWIDTH_16) &&
|
|
!instr->ctx.data.force_8bit)
|
|
au_write_buf16(this, instr->ctx.data.buf.out,
|
|
instr->ctx.data.len);
|
|
else
|
|
au_write_buf(this, instr->ctx.data.buf.out,
|
|
instr->ctx.data.len);
|
|
break;
|
|
|
|
case NAND_OP_WAITRDY_INSTR:
|
|
ret = au1550nd_waitrdy(this, instr->ctx.waitrdy.timeout_ms);
|
|
break;
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (instr->delay_ns)
|
|
ndelay(instr->delay_ns);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int au1550nd_exec_op(struct nand_chip *this,
|
|
const struct nand_operation *op,
|
|
bool check_only)
|
|
{
|
|
struct au1550nd_ctx *ctx = chip_to_au_ctx(this);
|
|
unsigned int i;
|
|
int ret;
|
|
|
|
if (check_only)
|
|
return 0;
|
|
|
|
/* assert (force assert) chip enable */
|
|
alchemy_wrsmem((1 << (4 + ctx->cs)), AU1000_MEM_STNDCTL);
|
|
/* Drain the writebuffer */
|
|
wmb();
|
|
|
|
for (i = 0; i < op->ninstrs; i++) {
|
|
ret = au1550nd_exec_instr(this, &op->instrs[i]);
|
|
if (ret)
|
|
break;
|
|
}
|
|
|
|
/* deassert chip enable */
|
|
alchemy_wrsmem(0, AU1000_MEM_STNDCTL);
|
|
/* Drain the writebuffer */
|
|
wmb();
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int au1550nd_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 au1550nd_ops = {
|
|
.exec_op = au1550nd_exec_op,
|
|
.attach_chip = au1550nd_attach_chip,
|
|
};
|
|
|
|
static int au1550nd_probe(struct platform_device *pdev)
|
|
{
|
|
struct au1550nd_platdata *pd;
|
|
struct au1550nd_ctx *ctx;
|
|
struct nand_chip *this;
|
|
struct mtd_info *mtd;
|
|
struct resource *r;
|
|
int ret, cs;
|
|
|
|
pd = dev_get_platdata(&pdev->dev);
|
|
if (!pd) {
|
|
dev_err(&pdev->dev, "missing platform data\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
|
|
if (!ctx)
|
|
return -ENOMEM;
|
|
|
|
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
if (!r) {
|
|
dev_err(&pdev->dev, "no NAND memory resource\n");
|
|
ret = -ENODEV;
|
|
goto out1;
|
|
}
|
|
if (request_mem_region(r->start, resource_size(r), "au1550-nand")) {
|
|
dev_err(&pdev->dev, "cannot claim NAND memory area\n");
|
|
ret = -ENOMEM;
|
|
goto out1;
|
|
}
|
|
|
|
ctx->base = ioremap(r->start, 0x1000);
|
|
if (!ctx->base) {
|
|
dev_err(&pdev->dev, "cannot remap NAND memory area\n");
|
|
ret = -ENODEV;
|
|
goto out2;
|
|
}
|
|
|
|
this = &ctx->chip;
|
|
mtd = nand_to_mtd(this);
|
|
mtd->dev.parent = &pdev->dev;
|
|
|
|
/* figure out which CS# r->start belongs to */
|
|
cs = find_nand_cs(r->start);
|
|
if (cs < 0) {
|
|
dev_err(&pdev->dev, "cannot detect NAND chipselect\n");
|
|
ret = -ENODEV;
|
|
goto out3;
|
|
}
|
|
ctx->cs = cs;
|
|
|
|
nand_controller_init(&ctx->controller);
|
|
ctx->controller.ops = &au1550nd_ops;
|
|
this->controller = &ctx->controller;
|
|
|
|
if (pd->devwidth)
|
|
this->options |= NAND_BUSWIDTH_16;
|
|
|
|
ret = nand_scan(this, 1);
|
|
if (ret) {
|
|
dev_err(&pdev->dev, "NAND scan failed with %d\n", ret);
|
|
goto out3;
|
|
}
|
|
|
|
mtd_device_register(mtd, pd->parts, pd->num_parts);
|
|
|
|
platform_set_drvdata(pdev, ctx);
|
|
|
|
return 0;
|
|
|
|
out3:
|
|
iounmap(ctx->base);
|
|
out2:
|
|
release_mem_region(r->start, resource_size(r));
|
|
out1:
|
|
kfree(ctx);
|
|
return ret;
|
|
}
|
|
|
|
static int au1550nd_remove(struct platform_device *pdev)
|
|
{
|
|
struct au1550nd_ctx *ctx = platform_get_drvdata(pdev);
|
|
struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
struct nand_chip *chip = &ctx->chip;
|
|
int ret;
|
|
|
|
ret = mtd_device_unregister(nand_to_mtd(chip));
|
|
WARN_ON(ret);
|
|
nand_cleanup(chip);
|
|
iounmap(ctx->base);
|
|
release_mem_region(r->start, 0x1000);
|
|
kfree(ctx);
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver au1550nd_driver = {
|
|
.driver = {
|
|
.name = "au1550-nand",
|
|
},
|
|
.probe = au1550nd_probe,
|
|
.remove = au1550nd_remove,
|
|
};
|
|
|
|
module_platform_driver(au1550nd_driver);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_AUTHOR("Embedded Edge, LLC");
|
|
MODULE_DESCRIPTION("Board-specific glue layer for NAND flash on Pb1550 board");
|