2008-10-14 20:23:26 +08:00
|
|
|
/*
|
|
|
|
* SuperH FLCTL nand controller
|
|
|
|
*
|
2010-02-02 12:01:25 +08:00
|
|
|
* Copyright (c) 2008 Renesas Solutions Corp.
|
|
|
|
* Copyright (c) 2008 Atom Create Engineering Co., Ltd.
|
2008-10-14 20:23:26 +08:00
|
|
|
*
|
2010-02-02 12:01:25 +08:00
|
|
|
* Based on fsl_elbc_nand.c, Copyright (c) 2006-2007 Freescale Semiconductor
|
2008-10-14 20:23:26 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
2012-10-19 18:15:35 +08:00
|
|
|
#include <linux/completion.h>
|
2008-10-14 20:23:26 +08:00
|
|
|
#include <linux/delay.h>
|
2012-10-19 18:15:35 +08:00
|
|
|
#include <linux/dmaengine.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
2012-05-14 20:14:41 +08:00
|
|
|
#include <linux/interrupt.h>
|
2008-10-14 20:23:26 +08:00
|
|
|
#include <linux/io.h>
|
2012-10-19 18:15:36 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
2008-10-14 20:23:26 +08:00
|
|
|
#include <linux/platform_device.h>
|
2012-03-18 22:13:20 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
2012-10-19 18:15:35 +08:00
|
|
|
#include <linux/sh_dma.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2012-07-05 18:41:01 +08:00
|
|
|
#include <linux/string.h>
|
2008-10-14 20:23:26 +08:00
|
|
|
|
|
|
|
#include <linux/mtd/mtd.h>
|
|
|
|
#include <linux/mtd/nand.h>
|
|
|
|
#include <linux/mtd/partitions.h>
|
|
|
|
#include <linux/mtd/sh_flctl.h>
|
|
|
|
|
2016-02-04 03:03:47 +08:00
|
|
|
static int flctl_4secc_ooblayout_sp_ecc(struct mtd_info *mtd, int section,
|
|
|
|
struct mtd_oob_region *oobregion)
|
|
|
|
{
|
|
|
|
struct nand_chip *chip = mtd_to_nand(mtd);
|
|
|
|
|
|
|
|
if (section)
|
|
|
|
return -ERANGE;
|
|
|
|
|
|
|
|
oobregion->offset = 0;
|
|
|
|
oobregion->length = chip->ecc.bytes;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int flctl_4secc_ooblayout_sp_free(struct mtd_info *mtd, int section,
|
|
|
|
struct mtd_oob_region *oobregion)
|
|
|
|
{
|
|
|
|
if (section)
|
|
|
|
return -ERANGE;
|
|
|
|
|
|
|
|
oobregion->offset = 12;
|
|
|
|
oobregion->length = 4;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct mtd_ooblayout_ops flctl_4secc_oob_smallpage_ops = {
|
|
|
|
.ecc = flctl_4secc_ooblayout_sp_ecc,
|
|
|
|
.free = flctl_4secc_ooblayout_sp_free,
|
2008-10-14 20:23:26 +08:00
|
|
|
};
|
|
|
|
|
2016-02-04 03:03:47 +08:00
|
|
|
static int flctl_4secc_ooblayout_lp_ecc(struct mtd_info *mtd, int section,
|
|
|
|
struct mtd_oob_region *oobregion)
|
|
|
|
{
|
|
|
|
struct nand_chip *chip = mtd_to_nand(mtd);
|
|
|
|
|
|
|
|
if (section >= chip->ecc.steps)
|
|
|
|
return -ERANGE;
|
|
|
|
|
|
|
|
oobregion->offset = (section * 16) + 6;
|
|
|
|
oobregion->length = chip->ecc.bytes;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int flctl_4secc_ooblayout_lp_free(struct mtd_info *mtd, int section,
|
|
|
|
struct mtd_oob_region *oobregion)
|
|
|
|
{
|
|
|
|
struct nand_chip *chip = mtd_to_nand(mtd);
|
|
|
|
|
|
|
|
if (section >= chip->ecc.steps)
|
|
|
|
return -ERANGE;
|
|
|
|
|
|
|
|
oobregion->offset = section * 16;
|
|
|
|
oobregion->length = 6;
|
|
|
|
|
|
|
|
if (!section) {
|
|
|
|
oobregion->offset += 2;
|
|
|
|
oobregion->length -= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct mtd_ooblayout_ops flctl_4secc_oob_largepage_ops = {
|
|
|
|
.ecc = flctl_4secc_ooblayout_lp_ecc,
|
|
|
|
.free = flctl_4secc_ooblayout_lp_free,
|
2008-10-14 20:23:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
|
|
|
|
|
|
|
|
static struct nand_bbt_descr flctl_4secc_smallpage = {
|
|
|
|
.options = NAND_BBT_SCAN2NDPAGE,
|
|
|
|
.offs = 11,
|
|
|
|
.len = 1,
|
|
|
|
.pattern = scan_ff_pattern,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct nand_bbt_descr flctl_4secc_largepage = {
|
2009-03-24 17:27:24 +08:00
|
|
|
.options = NAND_BBT_SCAN2NDPAGE,
|
2012-05-14 20:14:42 +08:00
|
|
|
.offs = 0,
|
2008-10-14 20:23:26 +08:00
|
|
|
.len = 2,
|
|
|
|
.pattern = scan_ff_pattern,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void empty_fifo(struct sh_flctl *flctl)
|
|
|
|
{
|
2012-05-14 20:14:41 +08:00
|
|
|
writel(flctl->flintdmacr_base | AC1CLR | AC0CLR, FLINTDMACR(flctl));
|
|
|
|
writel(flctl->flintdmacr_base, FLINTDMACR(flctl));
|
2008-10-14 20:23:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void start_translation(struct sh_flctl *flctl)
|
|
|
|
{
|
|
|
|
writeb(TRSTRT, FLTRCR(flctl));
|
|
|
|
}
|
|
|
|
|
2010-02-02 12:01:25 +08:00
|
|
|
static void timeout_error(struct sh_flctl *flctl, const char *str)
|
|
|
|
{
|
2011-03-31 09:57:33 +08:00
|
|
|
dev_err(&flctl->pdev->dev, "Timeout occurred in %s\n", str);
|
2010-02-02 12:01:25 +08:00
|
|
|
}
|
|
|
|
|
2008-10-14 20:23:26 +08:00
|
|
|
static void wait_completion(struct sh_flctl *flctl)
|
|
|
|
{
|
|
|
|
uint32_t timeout = LOOP_TIMEOUT_MAX;
|
|
|
|
|
|
|
|
while (timeout--) {
|
|
|
|
if (readb(FLTRCR(flctl)) & TREND) {
|
|
|
|
writeb(0x0, FLTRCR(flctl));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
udelay(1);
|
|
|
|
}
|
|
|
|
|
2010-02-02 12:01:25 +08:00
|
|
|
timeout_error(flctl, __func__);
|
2008-10-14 20:23:26 +08:00
|
|
|
writeb(0x0, FLTRCR(flctl));
|
|
|
|
}
|
|
|
|
|
2012-10-19 18:15:35 +08:00
|
|
|
static void flctl_dma_complete(void *param)
|
|
|
|
{
|
|
|
|
struct sh_flctl *flctl = param;
|
|
|
|
|
|
|
|
complete(&flctl->dma_complete);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flctl_release_dma(struct sh_flctl *flctl)
|
|
|
|
{
|
|
|
|
if (flctl->chan_fifo0_rx) {
|
|
|
|
dma_release_channel(flctl->chan_fifo0_rx);
|
|
|
|
flctl->chan_fifo0_rx = NULL;
|
|
|
|
}
|
|
|
|
if (flctl->chan_fifo0_tx) {
|
|
|
|
dma_release_channel(flctl->chan_fifo0_tx);
|
|
|
|
flctl->chan_fifo0_tx = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flctl_setup_dma(struct sh_flctl *flctl)
|
|
|
|
{
|
|
|
|
dma_cap_mask_t mask;
|
|
|
|
struct dma_slave_config cfg;
|
|
|
|
struct platform_device *pdev = flctl->pdev;
|
2013-07-30 16:18:33 +08:00
|
|
|
struct sh_flctl_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
2012-10-19 18:15:35 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!pdata)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (pdata->slave_id_fifo0_tx <= 0 || pdata->slave_id_fifo0_rx <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* We can only either use DMA for both Tx and Rx or not use it at all */
|
|
|
|
dma_cap_zero(mask);
|
|
|
|
dma_cap_set(DMA_SLAVE, mask);
|
|
|
|
|
|
|
|
flctl->chan_fifo0_tx = dma_request_channel(mask, shdma_chan_filter,
|
2013-11-27 18:17:28 +08:00
|
|
|
(void *)(uintptr_t)pdata->slave_id_fifo0_tx);
|
2012-10-19 18:15:35 +08:00
|
|
|
dev_dbg(&pdev->dev, "%s: TX: got channel %p\n", __func__,
|
|
|
|
flctl->chan_fifo0_tx);
|
|
|
|
|
|
|
|
if (!flctl->chan_fifo0_tx)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(&cfg, 0, sizeof(cfg));
|
|
|
|
cfg.direction = DMA_MEM_TO_DEV;
|
2015-12-08 23:38:12 +08:00
|
|
|
cfg.dst_addr = flctl->fifo;
|
2012-10-19 18:15:35 +08:00
|
|
|
cfg.src_addr = 0;
|
|
|
|
ret = dmaengine_slave_config(flctl->chan_fifo0_tx, &cfg);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
flctl->chan_fifo0_rx = dma_request_channel(mask, shdma_chan_filter,
|
2013-11-27 18:17:28 +08:00
|
|
|
(void *)(uintptr_t)pdata->slave_id_fifo0_rx);
|
2012-10-19 18:15:35 +08:00
|
|
|
dev_dbg(&pdev->dev, "%s: RX: got channel %p\n", __func__,
|
|
|
|
flctl->chan_fifo0_rx);
|
|
|
|
|
|
|
|
if (!flctl->chan_fifo0_rx)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
cfg.direction = DMA_DEV_TO_MEM;
|
|
|
|
cfg.dst_addr = 0;
|
2015-12-08 23:38:12 +08:00
|
|
|
cfg.src_addr = flctl->fifo;
|
2012-10-19 18:15:35 +08:00
|
|
|
ret = dmaengine_slave_config(flctl->chan_fifo0_rx, &cfg);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
init_completion(&flctl->dma_complete);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
flctl_release_dma(flctl);
|
|
|
|
}
|
|
|
|
|
2008-10-14 20:23:26 +08:00
|
|
|
static void set_addr(struct mtd_info *mtd, int column, int page_addr)
|
|
|
|
{
|
|
|
|
struct sh_flctl *flctl = mtd_to_flctl(mtd);
|
|
|
|
uint32_t addr = 0;
|
|
|
|
|
|
|
|
if (column == -1) {
|
|
|
|
addr = page_addr; /* ERASE1 */
|
|
|
|
} else if (page_addr != -1) {
|
|
|
|
/* SEQIN, READ0, etc.. */
|
2010-01-27 17:17:21 +08:00
|
|
|
if (flctl->chip.options & NAND_BUSWIDTH_16)
|
|
|
|
column >>= 1;
|
2008-10-14 20:23:26 +08:00
|
|
|
if (flctl->page_size) {
|
|
|
|
addr = column & 0x0FFF;
|
|
|
|
addr |= (page_addr & 0xff) << 16;
|
|
|
|
addr |= ((page_addr >> 8) & 0xff) << 24;
|
|
|
|
/* big than 128MB */
|
|
|
|
if (flctl->rw_ADRCNT == ADRCNT2_E) {
|
|
|
|
uint32_t addr2;
|
|
|
|
addr2 = (page_addr >> 16) & 0xff;
|
|
|
|
writel(addr2, FLADR2(flctl));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
addr = column;
|
|
|
|
addr |= (page_addr & 0xff) << 8;
|
|
|
|
addr |= ((page_addr >> 8) & 0xff) << 16;
|
|
|
|
addr |= ((page_addr >> 16) & 0xff) << 24;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
writel(addr, FLADR(flctl));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wait_rfifo_ready(struct sh_flctl *flctl)
|
|
|
|
{
|
|
|
|
uint32_t timeout = LOOP_TIMEOUT_MAX;
|
|
|
|
|
|
|
|
while (timeout--) {
|
|
|
|
uint32_t val;
|
|
|
|
/* check FIFO */
|
|
|
|
val = readl(FLDTCNTR(flctl)) >> 16;
|
|
|
|
if (val & 0xFF)
|
|
|
|
return;
|
|
|
|
udelay(1);
|
|
|
|
}
|
2010-02-02 12:01:25 +08:00
|
|
|
timeout_error(flctl, __func__);
|
2008-10-14 20:23:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wait_wfifo_ready(struct sh_flctl *flctl)
|
|
|
|
{
|
|
|
|
uint32_t len, timeout = LOOP_TIMEOUT_MAX;
|
|
|
|
|
|
|
|
while (timeout--) {
|
|
|
|
/* check FIFO */
|
|
|
|
len = (readl(FLDTCNTR(flctl)) >> 16) & 0xFF;
|
|
|
|
if (len >= 4)
|
|
|
|
return;
|
|
|
|
udelay(1);
|
|
|
|
}
|
2010-02-02 12:01:25 +08:00
|
|
|
timeout_error(flctl, __func__);
|
2008-10-14 20:23:26 +08:00
|
|
|
}
|
|
|
|
|
2012-05-14 20:14:46 +08:00
|
|
|
static enum flctl_ecc_res_t wait_recfifo_ready
|
|
|
|
(struct sh_flctl *flctl, int sector_number)
|
2008-10-14 20:23:26 +08:00
|
|
|
{
|
|
|
|
uint32_t timeout = LOOP_TIMEOUT_MAX;
|
|
|
|
void __iomem *ecc_reg[4];
|
|
|
|
int i;
|
2012-05-14 20:14:46 +08:00
|
|
|
int state = FL_SUCCESS;
|
2008-10-14 20:23:26 +08:00
|
|
|
uint32_t data, size;
|
|
|
|
|
2012-05-14 20:14:46 +08:00
|
|
|
/*
|
|
|
|
* First this loops checks in FLDTCNTR if we are ready to read out the
|
|
|
|
* oob data. This is the case if either all went fine without errors or
|
|
|
|
* if the bottom part of the loop corrected the errors or marked them as
|
|
|
|
* uncorrectable and the controller is given time to push the data into
|
|
|
|
* the FIFO.
|
|
|
|
*/
|
2008-10-14 20:23:26 +08:00
|
|
|
while (timeout--) {
|
2012-05-14 20:14:46 +08:00
|
|
|
/* check if all is ok and we can read out the OOB */
|
2008-10-14 20:23:26 +08:00
|
|
|
size = readl(FLDTCNTR(flctl)) >> 24;
|
2012-05-14 20:14:46 +08:00
|
|
|
if ((size & 0xFF) == 4)
|
|
|
|
return state;
|
|
|
|
|
|
|
|
/* check if a correction code has been calculated */
|
|
|
|
if (!(readl(FL4ECCCR(flctl)) & _4ECCEND)) {
|
|
|
|
/*
|
|
|
|
* either we wait for the fifo to be filled or a
|
|
|
|
* correction pattern is being generated
|
|
|
|
*/
|
|
|
|
udelay(1);
|
|
|
|
continue;
|
|
|
|
}
|
2008-10-14 20:23:26 +08:00
|
|
|
|
2012-05-14 20:14:46 +08:00
|
|
|
/* check for an uncorrectable error */
|
|
|
|
if (readl(FL4ECCCR(flctl)) & _4ECCFA) {
|
|
|
|
/* check if we face a non-empty page */
|
|
|
|
for (i = 0; i < 512; i++) {
|
|
|
|
if (flctl->done_buff[i] != 0xff) {
|
|
|
|
state = FL_ERROR; /* can't correct */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-10-14 20:23:26 +08:00
|
|
|
|
2012-05-14 20:14:46 +08:00
|
|
|
if (state == FL_SUCCESS)
|
|
|
|
dev_dbg(&flctl->pdev->dev,
|
|
|
|
"reading empty sector %d, ecc error ignored\n",
|
|
|
|
sector_number);
|
|
|
|
|
|
|
|
writel(0, FL4ECCCR(flctl));
|
2008-10-14 20:23:26 +08:00
|
|
|
continue;
|
2012-05-14 20:14:46 +08:00
|
|
|
}
|
2008-10-14 20:23:26 +08:00
|
|
|
|
|
|
|
/* start error correction */
|
|
|
|
ecc_reg[0] = FL4ECCRESULT0(flctl);
|
|
|
|
ecc_reg[1] = FL4ECCRESULT1(flctl);
|
|
|
|
ecc_reg[2] = FL4ECCRESULT2(flctl);
|
|
|
|
ecc_reg[3] = FL4ECCRESULT3(flctl);
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
2012-05-14 20:14:46 +08:00
|
|
|
uint8_t org;
|
2012-10-19 18:15:34 +08:00
|
|
|
unsigned int index;
|
2012-05-14 20:14:46 +08:00
|
|
|
|
2008-10-14 20:23:26 +08:00
|
|
|
data = readl(ecc_reg[i]);
|
|
|
|
|
2012-05-14 20:14:46 +08:00
|
|
|
if (flctl->page_size)
|
|
|
|
index = (512 * sector_number) +
|
|
|
|
(data >> 16);
|
|
|
|
else
|
|
|
|
index = data >> 16;
|
|
|
|
|
|
|
|
org = flctl->done_buff[index];
|
|
|
|
flctl->done_buff[index] = org ^ (data & 0xFF);
|
|
|
|
}
|
|
|
|
state = FL_REPAIRABLE;
|
2008-10-14 20:23:26 +08:00
|
|
|
writel(0, FL4ECCCR(flctl));
|
|
|
|
}
|
|
|
|
|
2010-02-02 12:01:25 +08:00
|
|
|
timeout_error(flctl, __func__);
|
2012-05-14 20:14:46 +08:00
|
|
|
return FL_TIMEOUT; /* timeout */
|
2008-10-14 20:23:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wait_wecfifo_ready(struct sh_flctl *flctl)
|
|
|
|
{
|
|
|
|
uint32_t timeout = LOOP_TIMEOUT_MAX;
|
|
|
|
uint32_t len;
|
|
|
|
|
|
|
|
while (timeout--) {
|
|
|
|
/* check FLECFIFO */
|
|
|
|
len = (readl(FLDTCNTR(flctl)) >> 24) & 0xFF;
|
|
|
|
if (len >= 4)
|
|
|
|
return;
|
|
|
|
udelay(1);
|
|
|
|
}
|
2010-02-02 12:01:25 +08:00
|
|
|
timeout_error(flctl, __func__);
|
2008-10-14 20:23:26 +08:00
|
|
|
}
|
|
|
|
|
2012-10-19 18:15:35 +08:00
|
|
|
static int flctl_dma_fifo0_transfer(struct sh_flctl *flctl, unsigned long *buf,
|
|
|
|
int len, enum dma_data_direction dir)
|
|
|
|
{
|
|
|
|
struct dma_async_tx_descriptor *desc = NULL;
|
|
|
|
struct dma_chan *chan;
|
|
|
|
enum dma_transfer_direction tr_dir;
|
|
|
|
dma_addr_t dma_addr;
|
|
|
|
dma_cookie_t cookie = -EINVAL;
|
|
|
|
uint32_t reg;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (dir == DMA_FROM_DEVICE) {
|
|
|
|
chan = flctl->chan_fifo0_rx;
|
|
|
|
tr_dir = DMA_DEV_TO_MEM;
|
|
|
|
} else {
|
|
|
|
chan = flctl->chan_fifo0_tx;
|
|
|
|
tr_dir = DMA_MEM_TO_DEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
dma_addr = dma_map_single(chan->device->dev, buf, len, dir);
|
|
|
|
|
|
|
|
if (dma_addr)
|
|
|
|
desc = dmaengine_prep_slave_single(chan, dma_addr, len,
|
|
|
|
tr_dir, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
|
|
|
|
|
|
|
|
if (desc) {
|
|
|
|
reg = readl(FLINTDMACR(flctl));
|
|
|
|
reg |= DREQ0EN;
|
|
|
|
writel(reg, FLINTDMACR(flctl));
|
|
|
|
|
|
|
|
desc->callback = flctl_dma_complete;
|
|
|
|
desc->callback_param = flctl;
|
|
|
|
cookie = dmaengine_submit(desc);
|
|
|
|
|
|
|
|
dma_async_issue_pending(chan);
|
|
|
|
} else {
|
|
|
|
/* DMA failed, fall back to PIO */
|
|
|
|
flctl_release_dma(flctl);
|
|
|
|
dev_warn(&flctl->pdev->dev,
|
|
|
|
"DMA failed, falling back to PIO\n");
|
|
|
|
ret = -EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret =
|
|
|
|
wait_for_completion_timeout(&flctl->dma_complete,
|
|
|
|
msecs_to_jiffies(3000));
|
|
|
|
|
|
|
|
if (ret <= 0) {
|
2014-10-11 23:40:33 +08:00
|
|
|
dmaengine_terminate_all(chan);
|
2012-10-19 18:15:35 +08:00
|
|
|
dev_err(&flctl->pdev->dev, "wait_for_completion_timeout\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
reg = readl(FLINTDMACR(flctl));
|
|
|
|
reg &= ~DREQ0EN;
|
|
|
|
writel(reg, FLINTDMACR(flctl));
|
|
|
|
|
|
|
|
dma_unmap_single(chan->device->dev, dma_addr, len, dir);
|
|
|
|
|
|
|
|
/* ret > 0 is success */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-10-14 20:23:26 +08:00
|
|
|
static void read_datareg(struct sh_flctl *flctl, int offset)
|
|
|
|
{
|
|
|
|
unsigned long data;
|
|
|
|
unsigned long *buf = (unsigned long *)&flctl->done_buff[offset];
|
|
|
|
|
|
|
|
wait_completion(flctl);
|
|
|
|
|
|
|
|
data = readl(FLDATAR(flctl));
|
|
|
|
*buf = le32_to_cpu(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void read_fiforeg(struct sh_flctl *flctl, int rlen, int offset)
|
|
|
|
{
|
|
|
|
int i, len_4align;
|
|
|
|
unsigned long *buf = (unsigned long *)&flctl->done_buff[offset];
|
|
|
|
|
|
|
|
len_4align = (rlen + 3) / 4;
|
|
|
|
|
2012-10-19 18:15:35 +08:00
|
|
|
/* initiate DMA transfer */
|
|
|
|
if (flctl->chan_fifo0_rx && rlen >= 32 &&
|
|
|
|
flctl_dma_fifo0_transfer(flctl, buf, rlen, DMA_DEV_TO_MEM) > 0)
|
|
|
|
goto convert; /* DMA success */
|
|
|
|
|
|
|
|
/* do polling transfer */
|
2008-10-14 20:23:26 +08:00
|
|
|
for (i = 0; i < len_4align; i++) {
|
|
|
|
wait_rfifo_ready(flctl);
|
2012-05-14 20:14:47 +08:00
|
|
|
buf[i] = readl(FLDTFIFO(flctl));
|
2008-10-14 20:23:26 +08:00
|
|
|
}
|
2012-10-19 18:15:35 +08:00
|
|
|
|
|
|
|
convert:
|
|
|
|
for (i = 0; i < len_4align; i++)
|
|
|
|
buf[i] = be32_to_cpu(buf[i]);
|
2008-10-14 20:23:26 +08:00
|
|
|
}
|
|
|
|
|
2012-05-14 20:14:46 +08:00
|
|
|
static enum flctl_ecc_res_t read_ecfiforeg
|
|
|
|
(struct sh_flctl *flctl, uint8_t *buff, int sector)
|
2008-10-14 20:23:26 +08:00
|
|
|
{
|
|
|
|
int i;
|
2012-05-14 20:14:46 +08:00
|
|
|
enum flctl_ecc_res_t res;
|
2008-10-14 20:23:26 +08:00
|
|
|
unsigned long *ecc_buf = (unsigned long *)buff;
|
|
|
|
|
2012-05-14 20:14:46 +08:00
|
|
|
res = wait_recfifo_ready(flctl , sector);
|
|
|
|
|
|
|
|
if (res != FL_ERROR) {
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
ecc_buf[i] = readl(FLECFIFO(flctl));
|
|
|
|
ecc_buf[i] = be32_to_cpu(ecc_buf[i]);
|
|
|
|
}
|
2008-10-14 20:23:26 +08:00
|
|
|
}
|
|
|
|
|
2012-05-14 20:14:46 +08:00
|
|
|
return res;
|
2008-10-14 20:23:26 +08:00
|
|
|
}
|
|
|
|
|
2012-10-19 18:15:34 +08:00
|
|
|
static void write_fiforeg(struct sh_flctl *flctl, int rlen,
|
|
|
|
unsigned int offset)
|
2008-10-14 20:23:26 +08:00
|
|
|
{
|
|
|
|
int i, len_4align;
|
2012-10-19 18:15:34 +08:00
|
|
|
unsigned long *buf = (unsigned long *)&flctl->done_buff[offset];
|
2008-10-14 20:23:26 +08:00
|
|
|
|
|
|
|
len_4align = (rlen + 3) / 4;
|
|
|
|
for (i = 0; i < len_4align; i++) {
|
|
|
|
wait_wfifo_ready(flctl);
|
2012-10-19 18:15:34 +08:00
|
|
|
writel(cpu_to_be32(buf[i]), FLDTFIFO(flctl));
|
2008-10-14 20:23:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-19 18:15:34 +08:00
|
|
|
static void write_ec_fiforeg(struct sh_flctl *flctl, int rlen,
|
|
|
|
unsigned int offset)
|
2012-05-14 20:14:47 +08:00
|
|
|
{
|
|
|
|
int i, len_4align;
|
2012-10-19 18:15:34 +08:00
|
|
|
unsigned long *buf = (unsigned long *)&flctl->done_buff[offset];
|
2012-05-14 20:14:47 +08:00
|
|
|
|
|
|
|
len_4align = (rlen + 3) / 4;
|
2012-10-19 18:15:35 +08:00
|
|
|
|
|
|
|
for (i = 0; i < len_4align; i++)
|
|
|
|
buf[i] = cpu_to_be32(buf[i]);
|
|
|
|
|
|
|
|
/* initiate DMA transfer */
|
|
|
|
if (flctl->chan_fifo0_tx && rlen >= 32 &&
|
|
|
|
flctl_dma_fifo0_transfer(flctl, buf, rlen, DMA_MEM_TO_DEV) > 0)
|
|
|
|
return; /* DMA success */
|
|
|
|
|
|
|
|
/* do polling transfer */
|
2012-05-14 20:14:47 +08:00
|
|
|
for (i = 0; i < len_4align; i++) {
|
|
|
|
wait_wecfifo_ready(flctl);
|
2012-10-19 18:15:35 +08:00
|
|
|
writel(buf[i], FLECFIFO(flctl));
|
2012-05-14 20:14:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-14 20:23:26 +08:00
|
|
|
static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_val)
|
|
|
|
{
|
|
|
|
struct sh_flctl *flctl = mtd_to_flctl(mtd);
|
2012-03-01 17:48:39 +08:00
|
|
|
uint32_t flcmncr_val = flctl->flcmncr_base & ~SEL_16BIT;
|
2008-10-14 20:23:26 +08:00
|
|
|
uint32_t flcmdcr_val, addr_len_bytes = 0;
|
|
|
|
|
|
|
|
/* Set SNAND bit if page size is 2048byte */
|
|
|
|
if (flctl->page_size)
|
|
|
|
flcmncr_val |= SNAND_E;
|
|
|
|
else
|
|
|
|
flcmncr_val &= ~SNAND_E;
|
|
|
|
|
|
|
|
/* default FLCMDCR val */
|
|
|
|
flcmdcr_val = DOCMD1_E | DOADR_E;
|
|
|
|
|
|
|
|
/* Set for FLCMDCR */
|
|
|
|
switch (cmd) {
|
|
|
|
case NAND_CMD_ERASE1:
|
|
|
|
addr_len_bytes = flctl->erase_ADRCNT;
|
|
|
|
flcmdcr_val |= DOCMD2_E;
|
|
|
|
break;
|
|
|
|
case NAND_CMD_READ0:
|
|
|
|
case NAND_CMD_READOOB:
|
2012-03-01 17:48:38 +08:00
|
|
|
case NAND_CMD_RNDOUT:
|
2008-10-14 20:23:26 +08:00
|
|
|
addr_len_bytes = flctl->rw_ADRCNT;
|
|
|
|
flcmdcr_val |= CDSRC_E;
|
2010-01-27 17:17:21 +08:00
|
|
|
if (flctl->chip.options & NAND_BUSWIDTH_16)
|
|
|
|
flcmncr_val |= SEL_16BIT;
|
2008-10-14 20:23:26 +08:00
|
|
|
break;
|
|
|
|
case NAND_CMD_SEQIN:
|
|
|
|
/* This case is that cmd is READ0 or READ1 or READ00 */
|
|
|
|
flcmdcr_val &= ~DOADR_E; /* ONLY execute 1st cmd */
|
|
|
|
break;
|
|
|
|
case NAND_CMD_PAGEPROG:
|
|
|
|
addr_len_bytes = flctl->rw_ADRCNT;
|
2008-10-20 16:17:44 +08:00
|
|
|
flcmdcr_val |= DOCMD2_E | CDSRC_E | SELRW;
|
2010-01-27 17:17:21 +08:00
|
|
|
if (flctl->chip.options & NAND_BUSWIDTH_16)
|
|
|
|
flcmncr_val |= SEL_16BIT;
|
2008-10-20 16:17:44 +08:00
|
|
|
break;
|
|
|
|
case NAND_CMD_READID:
|
|
|
|
flcmncr_val &= ~SNAND_E;
|
2012-03-01 17:48:37 +08:00
|
|
|
flcmdcr_val |= CDSRC_E;
|
2008-10-20 16:17:44 +08:00
|
|
|
addr_len_bytes = ADRCNT_1;
|
|
|
|
break;
|
|
|
|
case NAND_CMD_STATUS:
|
|
|
|
case NAND_CMD_RESET:
|
|
|
|
flcmncr_val &= ~SNAND_E;
|
|
|
|
flcmdcr_val &= ~(DOADR_E | DOSR_E);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set address bytes parameter */
|
|
|
|
flcmdcr_val |= addr_len_bytes;
|
|
|
|
|
|
|
|
/* Now actually write */
|
|
|
|
writel(flcmncr_val, FLCMNCR(flctl));
|
|
|
|
writel(flcmdcr_val, FLCMDCR(flctl));
|
|
|
|
writel(flcmcdr_val, FLCMCDR(flctl));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int flctl_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
|
2012-05-03 01:14:55 +08:00
|
|
|
uint8_t *buf, int oob_required, int page)
|
2008-10-20 16:17:44 +08:00
|
|
|
{
|
2012-05-14 20:14:44 +08:00
|
|
|
chip->read_buf(mtd, buf, mtd->writesize);
|
2012-07-05 18:41:02 +08:00
|
|
|
if (oob_required)
|
|
|
|
chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
|
2008-10-20 16:17:44 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-25 18:07:45 +08:00
|
|
|
static int flctl_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
|
2015-10-13 17:22:18 +08:00
|
|
|
const uint8_t *buf, int oob_required,
|
|
|
|
int page)
|
2008-10-20 16:17:44 +08:00
|
|
|
{
|
2012-05-14 20:14:44 +08:00
|
|
|
chip->write_buf(mtd, buf, mtd->writesize);
|
2012-05-14 20:14:47 +08:00
|
|
|
chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
|
2012-06-25 18:07:45 +08:00
|
|
|
return 0;
|
2008-10-20 16:17:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void execmd_read_page_sector(struct mtd_info *mtd, int page_addr)
|
|
|
|
{
|
|
|
|
struct sh_flctl *flctl = mtd_to_flctl(mtd);
|
|
|
|
int sector, page_sectors;
|
2012-05-14 20:14:46 +08:00
|
|
|
enum flctl_ecc_res_t ecc_result;
|
2008-10-20 16:17:44 +08:00
|
|
|
|
2012-05-14 20:14:45 +08:00
|
|
|
page_sectors = flctl->page_size ? 4 : 1;
|
|
|
|
|
|
|
|
set_cmd_regs(mtd, NAND_CMD_READ0,
|
|
|
|
(NAND_CMD_READSTART << 8) | NAND_CMD_READ0);
|
2008-10-20 16:17:44 +08:00
|
|
|
|
|
|
|
writel(readl(FLCMNCR(flctl)) | ACM_SACCES_MODE | _4ECCCORRECT,
|
|
|
|
FLCMNCR(flctl));
|
2012-05-14 20:14:45 +08:00
|
|
|
writel(readl(FLCMDCR(flctl)) | page_sectors, FLCMDCR(flctl));
|
|
|
|
writel(page_addr << 2, FLADR(flctl));
|
2008-10-20 16:17:44 +08:00
|
|
|
|
2012-05-14 20:14:45 +08:00
|
|
|
empty_fifo(flctl);
|
|
|
|
start_translation(flctl);
|
2008-10-20 16:17:44 +08:00
|
|
|
|
|
|
|
for (sector = 0; sector < page_sectors; sector++) {
|
|
|
|
read_fiforeg(flctl, 512, 512 * sector);
|
|
|
|
|
2012-05-14 20:14:46 +08:00
|
|
|
ecc_result = read_ecfiforeg(flctl,
|
2009-03-24 17:27:24 +08:00
|
|
|
&flctl->done_buff[mtd->writesize + 16 * sector],
|
|
|
|
sector);
|
2008-10-20 16:17:44 +08:00
|
|
|
|
2012-05-14 20:14:46 +08:00
|
|
|
switch (ecc_result) {
|
|
|
|
case FL_REPAIRABLE:
|
|
|
|
dev_info(&flctl->pdev->dev,
|
|
|
|
"applied ecc on page 0x%x", page_addr);
|
2015-12-10 16:00:23 +08:00
|
|
|
mtd->ecc_stats.corrected++;
|
2012-05-14 20:14:46 +08:00
|
|
|
break;
|
|
|
|
case FL_ERROR:
|
|
|
|
dev_warn(&flctl->pdev->dev,
|
|
|
|
"page 0x%x contains corrupted data\n",
|
|
|
|
page_addr);
|
2015-12-10 16:00:23 +08:00
|
|
|
mtd->ecc_stats.failed++;
|
2012-05-14 20:14:46 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
2008-10-20 16:17:44 +08:00
|
|
|
}
|
2012-05-14 20:14:45 +08:00
|
|
|
|
|
|
|
wait_completion(flctl);
|
|
|
|
|
2008-10-20 16:17:44 +08:00
|
|
|
writel(readl(FLCMNCR(flctl)) & ~(ACM_SACCES_MODE | _4ECCCORRECT),
|
|
|
|
FLCMNCR(flctl));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void execmd_read_oob(struct mtd_info *mtd, int page_addr)
|
|
|
|
{
|
|
|
|
struct sh_flctl *flctl = mtd_to_flctl(mtd);
|
2012-05-14 20:14:43 +08:00
|
|
|
int page_sectors = flctl->page_size ? 4 : 1;
|
|
|
|
int i;
|
2008-10-20 16:17:44 +08:00
|
|
|
|
|
|
|
set_cmd_regs(mtd, NAND_CMD_READ0,
|
|
|
|
(NAND_CMD_READSTART << 8) | NAND_CMD_READ0);
|
|
|
|
|
|
|
|
empty_fifo(flctl);
|
|
|
|
|
2012-05-14 20:14:43 +08:00
|
|
|
for (i = 0; i < page_sectors; i++) {
|
|
|
|
set_addr(mtd, (512 + 16) * i + 512 , page_addr);
|
2008-10-20 16:17:44 +08:00
|
|
|
writel(16, FLDTCNTR(flctl));
|
|
|
|
|
|
|
|
start_translation(flctl);
|
2012-05-14 20:14:43 +08:00
|
|
|
read_fiforeg(flctl, 16, 16 * i);
|
2008-10-20 16:17:44 +08:00
|
|
|
wait_completion(flctl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void execmd_write_page_sector(struct mtd_info *mtd)
|
|
|
|
{
|
|
|
|
struct sh_flctl *flctl = mtd_to_flctl(mtd);
|
2012-05-14 20:14:47 +08:00
|
|
|
int page_addr = flctl->seqin_page_addr;
|
2008-10-20 16:17:44 +08:00
|
|
|
int sector, page_sectors;
|
|
|
|
|
2012-05-14 20:14:45 +08:00
|
|
|
page_sectors = flctl->page_size ? 4 : 1;
|
2008-10-20 16:17:44 +08:00
|
|
|
|
|
|
|
set_cmd_regs(mtd, NAND_CMD_PAGEPROG,
|
|
|
|
(NAND_CMD_PAGEPROG << 8) | NAND_CMD_SEQIN);
|
|
|
|
|
2012-05-14 20:14:45 +08:00
|
|
|
empty_fifo(flctl);
|
|
|
|
writel(readl(FLCMNCR(flctl)) | ACM_SACCES_MODE, FLCMNCR(flctl));
|
|
|
|
writel(readl(FLCMDCR(flctl)) | page_sectors, FLCMDCR(flctl));
|
|
|
|
writel(page_addr << 2, FLADR(flctl));
|
|
|
|
start_translation(flctl);
|
2008-10-20 16:17:44 +08:00
|
|
|
|
2012-05-14 20:14:45 +08:00
|
|
|
for (sector = 0; sector < page_sectors; sector++) {
|
2008-10-20 16:17:44 +08:00
|
|
|
write_fiforeg(flctl, 512, 512 * sector);
|
2012-05-14 20:14:47 +08:00
|
|
|
write_ec_fiforeg(flctl, 16, mtd->writesize + 16 * sector);
|
2008-10-20 16:17:44 +08:00
|
|
|
}
|
|
|
|
|
2012-05-14 20:14:45 +08:00
|
|
|
wait_completion(flctl);
|
2008-10-20 16:17:44 +08:00
|
|
|
writel(readl(FLCMNCR(flctl)) & ~ACM_SACCES_MODE, FLCMNCR(flctl));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void execmd_write_oob(struct mtd_info *mtd)
|
|
|
|
{
|
|
|
|
struct sh_flctl *flctl = mtd_to_flctl(mtd);
|
|
|
|
int page_addr = flctl->seqin_page_addr;
|
|
|
|
int sector, page_sectors;
|
|
|
|
|
2012-05-14 20:14:43 +08:00
|
|
|
page_sectors = flctl->page_size ? 4 : 1;
|
2008-10-20 16:17:44 +08:00
|
|
|
|
|
|
|
set_cmd_regs(mtd, NAND_CMD_PAGEPROG,
|
|
|
|
(NAND_CMD_PAGEPROG << 8) | NAND_CMD_SEQIN);
|
|
|
|
|
2012-05-14 20:14:43 +08:00
|
|
|
for (sector = 0; sector < page_sectors; sector++) {
|
2008-10-20 16:17:44 +08:00
|
|
|
empty_fifo(flctl);
|
|
|
|
set_addr(mtd, sector * 528 + 512, page_addr);
|
|
|
|
writel(16, FLDTCNTR(flctl)); /* set read size */
|
|
|
|
|
|
|
|
start_translation(flctl);
|
|
|
|
write_fiforeg(flctl, 16, 16 * sector);
|
|
|
|
wait_completion(flctl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flctl_cmdfunc(struct mtd_info *mtd, unsigned int command,
|
|
|
|
int column, int page_addr)
|
|
|
|
{
|
|
|
|
struct sh_flctl *flctl = mtd_to_flctl(mtd);
|
|
|
|
uint32_t read_cmd = 0;
|
|
|
|
|
2012-03-18 22:13:20 +08:00
|
|
|
pm_runtime_get_sync(&flctl->pdev->dev);
|
|
|
|
|
2008-10-20 16:17:44 +08:00
|
|
|
flctl->read_bytes = 0;
|
|
|
|
if (command != NAND_CMD_PAGEPROG)
|
|
|
|
flctl->index = 0;
|
|
|
|
|
|
|
|
switch (command) {
|
|
|
|
case NAND_CMD_READ1:
|
|
|
|
case NAND_CMD_READ0:
|
|
|
|
if (flctl->hwecc) {
|
|
|
|
/* read page with hwecc */
|
|
|
|
execmd_read_page_sector(mtd, page_addr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (flctl->page_size)
|
|
|
|
set_cmd_regs(mtd, command, (NAND_CMD_READSTART << 8)
|
|
|
|
| command);
|
|
|
|
else
|
|
|
|
set_cmd_regs(mtd, command, command);
|
|
|
|
|
|
|
|
set_addr(mtd, 0, page_addr);
|
|
|
|
|
|
|
|
flctl->read_bytes = mtd->writesize + mtd->oobsize;
|
2010-01-27 17:17:21 +08:00
|
|
|
if (flctl->chip.options & NAND_BUSWIDTH_16)
|
|
|
|
column >>= 1;
|
2008-10-20 16:17:44 +08:00
|
|
|
flctl->index += column;
|
|
|
|
goto read_normal_exit;
|
|
|
|
|
|
|
|
case NAND_CMD_READOOB:
|
|
|
|
if (flctl->hwecc) {
|
|
|
|
/* read page with hwecc */
|
|
|
|
execmd_read_oob(mtd, page_addr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flctl->page_size) {
|
|
|
|
set_cmd_regs(mtd, command, (NAND_CMD_READSTART << 8)
|
|
|
|
| NAND_CMD_READ0);
|
|
|
|
set_addr(mtd, mtd->writesize, page_addr);
|
|
|
|
} else {
|
|
|
|
set_cmd_regs(mtd, command, command);
|
|
|
|
set_addr(mtd, 0, page_addr);
|
|
|
|
}
|
|
|
|
flctl->read_bytes = mtd->oobsize;
|
|
|
|
goto read_normal_exit;
|
|
|
|
|
2012-03-01 17:48:38 +08:00
|
|
|
case NAND_CMD_RNDOUT:
|
|
|
|
if (flctl->hwecc)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (flctl->page_size)
|
|
|
|
set_cmd_regs(mtd, command, (NAND_CMD_RNDOUTSTART << 8)
|
|
|
|
| command);
|
|
|
|
else
|
|
|
|
set_cmd_regs(mtd, command, command);
|
|
|
|
|
|
|
|
set_addr(mtd, column, 0);
|
|
|
|
|
|
|
|
flctl->read_bytes = mtd->writesize + mtd->oobsize - column;
|
|
|
|
goto read_normal_exit;
|
|
|
|
|
2008-10-20 16:17:44 +08:00
|
|
|
case NAND_CMD_READID:
|
|
|
|
set_cmd_regs(mtd, command, command);
|
|
|
|
|
2012-03-01 17:48:37 +08:00
|
|
|
/* READID is always performed using an 8-bit bus */
|
|
|
|
if (flctl->chip.options & NAND_BUSWIDTH_16)
|
|
|
|
column <<= 1;
|
|
|
|
set_addr(mtd, column, 0);
|
|
|
|
|
|
|
|
flctl->read_bytes = 8;
|
2008-10-20 16:17:44 +08:00
|
|
|
writel(flctl->read_bytes, FLDTCNTR(flctl)); /* set read size */
|
2012-03-01 17:48:36 +08:00
|
|
|
empty_fifo(flctl);
|
2008-10-20 16:17:44 +08:00
|
|
|
start_translation(flctl);
|
2012-03-01 17:48:37 +08:00
|
|
|
read_fiforeg(flctl, flctl->read_bytes, 0);
|
|
|
|
wait_completion(flctl);
|
2008-10-20 16:17:44 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NAND_CMD_ERASE1:
|
|
|
|
flctl->erase1_page_addr = page_addr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NAND_CMD_ERASE2:
|
|
|
|
set_cmd_regs(mtd, NAND_CMD_ERASE1,
|
|
|
|
(command << 8) | NAND_CMD_ERASE1);
|
|
|
|
set_addr(mtd, -1, flctl->erase1_page_addr);
|
|
|
|
start_translation(flctl);
|
|
|
|
wait_completion(flctl);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NAND_CMD_SEQIN:
|
|
|
|
if (!flctl->page_size) {
|
|
|
|
/* output read command */
|
|
|
|
if (column >= mtd->writesize) {
|
|
|
|
column -= mtd->writesize;
|
|
|
|
read_cmd = NAND_CMD_READOOB;
|
|
|
|
} else if (column < 256) {
|
|
|
|
read_cmd = NAND_CMD_READ0;
|
|
|
|
} else {
|
|
|
|
column -= 256;
|
|
|
|
read_cmd = NAND_CMD_READ1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
flctl->seqin_column = column;
|
|
|
|
flctl->seqin_page_addr = page_addr;
|
|
|
|
flctl->seqin_read_cmd = read_cmd;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NAND_CMD_PAGEPROG:
|
|
|
|
empty_fifo(flctl);
|
|
|
|
if (!flctl->page_size) {
|
|
|
|
set_cmd_regs(mtd, NAND_CMD_SEQIN,
|
|
|
|
flctl->seqin_read_cmd);
|
|
|
|
set_addr(mtd, -1, -1);
|
|
|
|
writel(0, FLDTCNTR(flctl)); /* set 0 size */
|
|
|
|
start_translation(flctl);
|
|
|
|
wait_completion(flctl);
|
|
|
|
}
|
|
|
|
if (flctl->hwecc) {
|
|
|
|
/* write page with hwecc */
|
|
|
|
if (flctl->seqin_column == mtd->writesize)
|
|
|
|
execmd_write_oob(mtd);
|
|
|
|
else if (!flctl->seqin_column)
|
|
|
|
execmd_write_page_sector(mtd);
|
|
|
|
else
|
|
|
|
printk(KERN_ERR "Invalid address !?\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
set_cmd_regs(mtd, command, (command << 8) | NAND_CMD_SEQIN);
|
|
|
|
set_addr(mtd, flctl->seqin_column, flctl->seqin_page_addr);
|
|
|
|
writel(flctl->index, FLDTCNTR(flctl)); /* set write size */
|
|
|
|
start_translation(flctl);
|
|
|
|
write_fiforeg(flctl, flctl->index, 0);
|
|
|
|
wait_completion(flctl);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NAND_CMD_STATUS:
|
|
|
|
set_cmd_regs(mtd, command, command);
|
|
|
|
set_addr(mtd, -1, -1);
|
|
|
|
|
|
|
|
flctl->read_bytes = 1;
|
|
|
|
writel(flctl->read_bytes, FLDTCNTR(flctl)); /* set read size */
|
|
|
|
start_translation(flctl);
|
|
|
|
read_datareg(flctl, 0); /* read and end */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NAND_CMD_RESET:
|
|
|
|
set_cmd_regs(mtd, command, command);
|
|
|
|
set_addr(mtd, -1, -1);
|
|
|
|
|
|
|
|
writel(0, FLDTCNTR(flctl)); /* set 0 size */
|
|
|
|
start_translation(flctl);
|
|
|
|
wait_completion(flctl);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-03-18 22:13:20 +08:00
|
|
|
goto runtime_exit;
|
2008-10-20 16:17:44 +08:00
|
|
|
|
|
|
|
read_normal_exit:
|
|
|
|
writel(flctl->read_bytes, FLDTCNTR(flctl)); /* set read size */
|
2012-03-01 17:48:36 +08:00
|
|
|
empty_fifo(flctl);
|
2008-10-20 16:17:44 +08:00
|
|
|
start_translation(flctl);
|
|
|
|
read_fiforeg(flctl, flctl->read_bytes, 0);
|
|
|
|
wait_completion(flctl);
|
2012-03-18 22:13:20 +08:00
|
|
|
runtime_exit:
|
|
|
|
pm_runtime_put_sync(&flctl->pdev->dev);
|
2008-10-20 16:17:44 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flctl_select_chip(struct mtd_info *mtd, int chipnr)
|
|
|
|
{
|
|
|
|
struct sh_flctl *flctl = mtd_to_flctl(mtd);
|
2012-03-18 22:13:20 +08:00
|
|
|
int ret;
|
2008-10-20 16:17:44 +08:00
|
|
|
|
|
|
|
switch (chipnr) {
|
|
|
|
case -1:
|
2012-03-01 17:48:39 +08:00
|
|
|
flctl->flcmncr_base &= ~CE0_ENABLE;
|
2012-03-18 22:13:20 +08:00
|
|
|
|
|
|
|
pm_runtime_get_sync(&flctl->pdev->dev);
|
2012-03-01 17:48:39 +08:00
|
|
|
writel(flctl->flcmncr_base, FLCMNCR(flctl));
|
2012-03-18 22:13:20 +08:00
|
|
|
|
|
|
|
if (flctl->qos_request) {
|
|
|
|
dev_pm_qos_remove_request(&flctl->pm_qos);
|
|
|
|
flctl->qos_request = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pm_runtime_put_sync(&flctl->pdev->dev);
|
2008-10-20 16:17:44 +08:00
|
|
|
break;
|
|
|
|
case 0:
|
2012-03-01 17:48:39 +08:00
|
|
|
flctl->flcmncr_base |= CE0_ENABLE;
|
2012-03-18 22:13:20 +08:00
|
|
|
|
|
|
|
if (!flctl->qos_request) {
|
|
|
|
ret = dev_pm_qos_add_request(&flctl->pdev->dev,
|
2012-10-23 07:09:12 +08:00
|
|
|
&flctl->pm_qos,
|
2014-02-11 07:35:23 +08:00
|
|
|
DEV_PM_QOS_RESUME_LATENCY,
|
2012-10-23 07:09:12 +08:00
|
|
|
100);
|
2012-03-18 22:13:20 +08:00
|
|
|
if (ret < 0)
|
|
|
|
dev_err(&flctl->pdev->dev,
|
|
|
|
"PM QoS request failed: %d\n", ret);
|
|
|
|
flctl->qos_request = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flctl->holden) {
|
|
|
|
pm_runtime_get_sync(&flctl->pdev->dev);
|
2012-03-01 17:48:40 +08:00
|
|
|
writel(HOLDEN, FLHOLDCR(flctl));
|
2012-03-18 22:13:20 +08:00
|
|
|
pm_runtime_put_sync(&flctl->pdev->dev);
|
|
|
|
}
|
2008-10-20 16:17:44 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flctl_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
|
|
|
|
{
|
|
|
|
struct sh_flctl *flctl = mtd_to_flctl(mtd);
|
|
|
|
|
2012-10-19 18:15:34 +08:00
|
|
|
memcpy(&flctl->done_buff[flctl->index], buf, len);
|
2008-10-20 16:17:44 +08:00
|
|
|
flctl->index += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint8_t flctl_read_byte(struct mtd_info *mtd)
|
|
|
|
{
|
|
|
|
struct sh_flctl *flctl = mtd_to_flctl(mtd);
|
|
|
|
uint8_t data;
|
|
|
|
|
2012-10-19 18:15:34 +08:00
|
|
|
data = flctl->done_buff[flctl->index];
|
2008-10-20 16:17:44 +08:00
|
|
|
flctl->index++;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2010-01-27 17:17:21 +08:00
|
|
|
static uint16_t flctl_read_word(struct mtd_info *mtd)
|
|
|
|
{
|
2012-10-19 18:15:34 +08:00
|
|
|
struct sh_flctl *flctl = mtd_to_flctl(mtd);
|
|
|
|
uint16_t *buf = (uint16_t *)&flctl->done_buff[flctl->index];
|
2010-01-27 17:17:21 +08:00
|
|
|
|
2012-10-19 18:15:34 +08:00
|
|
|
flctl->index += 2;
|
|
|
|
return *buf;
|
2010-01-27 17:17:21 +08:00
|
|
|
}
|
|
|
|
|
2008-10-20 16:17:44 +08:00
|
|
|
static void flctl_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
|
|
|
|
{
|
2012-07-05 18:41:01 +08:00
|
|
|
struct sh_flctl *flctl = mtd_to_flctl(mtd);
|
2008-10-20 16:17:44 +08:00
|
|
|
|
2012-10-19 18:15:34 +08:00
|
|
|
memcpy(buf, &flctl->done_buff[flctl->index], len);
|
2012-07-05 18:41:01 +08:00
|
|
|
flctl->index += len;
|
2008-10-20 16:17:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int flctl_chip_init_tail(struct mtd_info *mtd)
|
|
|
|
{
|
|
|
|
struct sh_flctl *flctl = mtd_to_flctl(mtd);
|
|
|
|
struct nand_chip *chip = &flctl->chip;
|
|
|
|
|
|
|
|
if (mtd->writesize == 512) {
|
|
|
|
flctl->page_size = 0;
|
|
|
|
if (chip->chipsize > (32 << 20)) {
|
|
|
|
/* big than 32MB */
|
|
|
|
flctl->rw_ADRCNT = ADRCNT_4;
|
|
|
|
flctl->erase_ADRCNT = ADRCNT_3;
|
|
|
|
} else if (chip->chipsize > (2 << 16)) {
|
|
|
|
/* big than 128KB */
|
|
|
|
flctl->rw_ADRCNT = ADRCNT_3;
|
|
|
|
flctl->erase_ADRCNT = ADRCNT_2;
|
|
|
|
} else {
|
|
|
|
flctl->rw_ADRCNT = ADRCNT_2;
|
|
|
|
flctl->erase_ADRCNT = ADRCNT_1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
flctl->page_size = 1;
|
|
|
|
if (chip->chipsize > (128 << 20)) {
|
|
|
|
/* big than 128MB */
|
|
|
|
flctl->rw_ADRCNT = ADRCNT2_E;
|
|
|
|
flctl->erase_ADRCNT = ADRCNT_3;
|
|
|
|
} else if (chip->chipsize > (8 << 16)) {
|
|
|
|
/* big than 512KB */
|
|
|
|
flctl->rw_ADRCNT = ADRCNT_4;
|
|
|
|
flctl->erase_ADRCNT = ADRCNT_2;
|
|
|
|
} else {
|
|
|
|
flctl->rw_ADRCNT = ADRCNT_3;
|
|
|
|
flctl->erase_ADRCNT = ADRCNT_1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flctl->hwecc) {
|
|
|
|
if (mtd->writesize == 512) {
|
2016-02-04 03:03:47 +08:00
|
|
|
mtd_set_ooblayout(mtd, &flctl_4secc_oob_smallpage_ops);
|
2008-10-20 16:17:44 +08:00
|
|
|
chip->badblock_pattern = &flctl_4secc_smallpage;
|
|
|
|
} else {
|
2016-02-04 03:03:47 +08:00
|
|
|
mtd_set_ooblayout(mtd, &flctl_4secc_oob_largepage_ops);
|
2008-10-20 16:17:44 +08:00
|
|
|
chip->badblock_pattern = &flctl_4secc_largepage;
|
|
|
|
}
|
|
|
|
|
|
|
|
chip->ecc.size = 512;
|
|
|
|
chip->ecc.bytes = 10;
|
2012-03-12 05:21:11 +08:00
|
|
|
chip->ecc.strength = 4;
|
2008-10-20 16:17:44 +08:00
|
|
|
chip->ecc.read_page = flctl_read_page_hwecc;
|
|
|
|
chip->ecc.write_page = flctl_write_page_hwecc;
|
|
|
|
chip->ecc.mode = NAND_ECC_HW;
|
|
|
|
|
|
|
|
/* 4 symbols ECC enabled */
|
2012-05-14 20:14:42 +08:00
|
|
|
flctl->flcmncr_base |= _4ECCEN;
|
2008-10-20 16:17:44 +08:00
|
|
|
} else {
|
|
|
|
chip->ecc.mode = NAND_ECC_SOFT;
|
2016-04-13 20:06:56 +08:00
|
|
|
chip->ecc.algo = NAND_ECC_HAMMING;
|
2008-10-20 16:17:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-14 20:14:41 +08:00
|
|
|
static irqreturn_t flctl_handle_flste(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct sh_flctl *flctl = dev_id;
|
|
|
|
|
|
|
|
dev_err(&flctl->pdev->dev, "flste irq: %x\n", readl(FLINTDMACR(flctl)));
|
|
|
|
writel(flctl->flintdmacr_base, FLINTDMACR(flctl));
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2012-10-19 18:15:36 +08:00
|
|
|
struct flctl_soc_config {
|
|
|
|
unsigned long flcmncr_val;
|
|
|
|
unsigned has_hwecc:1;
|
|
|
|
unsigned use_holden:1;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct flctl_soc_config flctl_sh7372_config = {
|
|
|
|
.flcmncr_val = CLK_16B_12L_4H | TYPESEL_SET | SHBUSSEL,
|
|
|
|
.has_hwecc = 1,
|
|
|
|
.use_holden = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct of_device_id of_flctl_match[] = {
|
|
|
|
{ .compatible = "renesas,shmobile-flctl-sh7372",
|
|
|
|
.data = &flctl_sh7372_config },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, of_flctl_match);
|
|
|
|
|
|
|
|
static struct sh_flctl_platform_data *flctl_parse_dt(struct device *dev)
|
|
|
|
{
|
|
|
|
const struct of_device_id *match;
|
|
|
|
struct flctl_soc_config *config;
|
|
|
|
struct sh_flctl_platform_data *pdata;
|
|
|
|
|
|
|
|
match = of_match_device(of_flctl_match, dev);
|
|
|
|
if (match)
|
|
|
|
config = (struct flctl_soc_config *)match->data;
|
|
|
|
else {
|
|
|
|
dev_err(dev, "%s: no OF configuration attached\n", __func__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdata = devm_kzalloc(dev, sizeof(struct sh_flctl_platform_data),
|
|
|
|
GFP_KERNEL);
|
2013-12-26 11:22:37 +08:00
|
|
|
if (!pdata)
|
2012-10-19 18:15:36 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* set SoC specific options */
|
|
|
|
pdata->flcmncr_val = config->flcmncr_val;
|
|
|
|
pdata->has_hwecc = config->has_hwecc;
|
|
|
|
pdata->use_holden = config->use_holden;
|
|
|
|
|
|
|
|
return pdata;
|
|
|
|
}
|
|
|
|
|
2012-11-20 02:23:07 +08:00
|
|
|
static int flctl_probe(struct platform_device *pdev)
|
2008-10-20 16:17:44 +08:00
|
|
|
{
|
|
|
|
struct resource *res;
|
|
|
|
struct sh_flctl *flctl;
|
|
|
|
struct mtd_info *flctl_mtd;
|
|
|
|
struct nand_chip *nand;
|
|
|
|
struct sh_flctl_platform_data *pdata;
|
2013-11-27 18:27:44 +08:00
|
|
|
int ret;
|
2012-05-14 20:14:41 +08:00
|
|
|
int irq;
|
2008-10-20 16:17:44 +08:00
|
|
|
|
2013-11-27 18:27:44 +08:00
|
|
|
flctl = devm_kzalloc(&pdev->dev, sizeof(struct sh_flctl), GFP_KERNEL);
|
2013-12-26 11:22:37 +08:00
|
|
|
if (!flctl)
|
2008-10-20 16:17:44 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2013-11-27 18:27:44 +08:00
|
|
|
flctl->reg = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(flctl->reg))
|
|
|
|
return PTR_ERR(flctl->reg);
|
2015-12-08 23:38:12 +08:00
|
|
|
flctl->fifo = res->start + 0x24; /* FLDTFIFO */
|
2008-10-20 16:17:44 +08:00
|
|
|
|
2012-05-14 20:14:41 +08:00
|
|
|
irq = platform_get_irq(pdev, 0);
|
|
|
|
if (irq < 0) {
|
|
|
|
dev_err(&pdev->dev, "failed to get flste irq data\n");
|
2013-11-27 18:27:44 +08:00
|
|
|
return -ENXIO;
|
2012-05-14 20:14:41 +08:00
|
|
|
}
|
|
|
|
|
2013-11-27 18:27:44 +08:00
|
|
|
ret = devm_request_irq(&pdev->dev, irq, flctl_handle_flste, IRQF_SHARED,
|
|
|
|
"flste", flctl);
|
2012-05-14 20:14:41 +08:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "request interrupt failed.\n");
|
2013-11-27 18:27:44 +08:00
|
|
|
return ret;
|
2012-05-14 20:14:41 +08:00
|
|
|
}
|
|
|
|
|
2012-10-19 18:15:36 +08:00
|
|
|
if (pdev->dev.of_node)
|
|
|
|
pdata = flctl_parse_dt(&pdev->dev);
|
|
|
|
else
|
2013-07-30 16:18:33 +08:00
|
|
|
pdata = dev_get_platdata(&pdev->dev);
|
2012-10-19 18:15:36 +08:00
|
|
|
|
|
|
|
if (!pdata) {
|
|
|
|
dev_err(&pdev->dev, "no setup data defined\n");
|
2013-11-27 18:27:44 +08:00
|
|
|
return -EINVAL;
|
2012-10-19 18:15:36 +08:00
|
|
|
}
|
|
|
|
|
2008-10-20 16:17:44 +08:00
|
|
|
platform_set_drvdata(pdev, flctl);
|
|
|
|
nand = &flctl->chip;
|
2015-12-10 16:00:23 +08:00
|
|
|
flctl_mtd = nand_to_mtd(nand);
|
2015-10-31 11:33:25 +08:00
|
|
|
nand_set_flash_node(nand, pdev->dev.of_node);
|
2015-06-11 04:39:04 +08:00
|
|
|
flctl_mtd->dev.parent = &pdev->dev;
|
2010-02-02 12:01:25 +08:00
|
|
|
flctl->pdev = pdev;
|
2008-10-20 16:17:44 +08:00
|
|
|
flctl->hwecc = pdata->has_hwecc;
|
2012-03-01 17:48:40 +08:00
|
|
|
flctl->holden = pdata->use_holden;
|
2012-05-14 20:14:41 +08:00
|
|
|
flctl->flcmncr_base = pdata->flcmncr_val;
|
|
|
|
flctl->flintdmacr_base = flctl->hwecc ? (STERINTE | ECERB) : STERINTE;
|
2008-10-20 16:17:44 +08:00
|
|
|
|
|
|
|
/* Set address of hardware control function */
|
|
|
|
/* 20 us command delay time */
|
|
|
|
nand->chip_delay = 20;
|
|
|
|
|
|
|
|
nand->read_byte = flctl_read_byte;
|
2016-04-01 20:54:31 +08:00
|
|
|
nand->read_word = flctl_read_word;
|
2008-10-20 16:17:44 +08:00
|
|
|
nand->write_buf = flctl_write_buf;
|
|
|
|
nand->read_buf = flctl_read_buf;
|
|
|
|
nand->select_chip = flctl_select_chip;
|
|
|
|
nand->cmdfunc = flctl_cmdfunc;
|
|
|
|
|
2016-04-01 20:54:31 +08:00
|
|
|
if (pdata->flcmncr_val & SEL_16BIT)
|
2010-01-27 17:17:21 +08:00
|
|
|
nand->options |= NAND_BUSWIDTH_16;
|
|
|
|
|
2012-03-18 22:13:20 +08:00
|
|
|
pm_runtime_enable(&pdev->dev);
|
|
|
|
pm_runtime_resume(&pdev->dev);
|
|
|
|
|
2012-10-19 18:15:35 +08:00
|
|
|
flctl_setup_dma(flctl);
|
|
|
|
|
2010-02-27 02:32:56 +08:00
|
|
|
ret = nand_scan_ident(flctl_mtd, 1, NULL);
|
2008-10-20 16:17:44 +08:00
|
|
|
if (ret)
|
2012-03-18 22:13:20 +08:00
|
|
|
goto err_chip;
|
2008-10-20 16:17:44 +08:00
|
|
|
|
2016-04-01 20:54:31 +08:00
|
|
|
if (nand->options & NAND_BUSWIDTH_16) {
|
|
|
|
/*
|
|
|
|
* NAND_BUSWIDTH_16 may have been set by nand_scan_ident().
|
|
|
|
* Add the SEL_16BIT flag in pdata->flcmncr_val and re-assign
|
|
|
|
* flctl->flcmncr_base to pdata->flcmncr_val.
|
|
|
|
*/
|
|
|
|
pdata->flcmncr_val |= SEL_16BIT;
|
|
|
|
flctl->flcmncr_base = pdata->flcmncr_val;
|
|
|
|
}
|
|
|
|
|
2008-10-20 16:17:44 +08:00
|
|
|
ret = flctl_chip_init_tail(flctl_mtd);
|
|
|
|
if (ret)
|
2012-03-18 22:13:20 +08:00
|
|
|
goto err_chip;
|
2008-10-20 16:17:44 +08:00
|
|
|
|
|
|
|
ret = nand_scan_tail(flctl_mtd);
|
|
|
|
if (ret)
|
2012-03-18 22:13:20 +08:00
|
|
|
goto err_chip;
|
2008-10-20 16:17:44 +08:00
|
|
|
|
2015-10-31 11:33:25 +08:00
|
|
|
ret = mtd_device_register(flctl_mtd, pdata->parts, pdata->nr_parts);
|
2008-10-20 16:17:44 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2012-03-18 22:13:20 +08:00
|
|
|
err_chip:
|
2012-10-19 18:15:35 +08:00
|
|
|
flctl_release_dma(flctl);
|
2012-03-18 22:13:20 +08:00
|
|
|
pm_runtime_disable(&pdev->dev);
|
2008-10-20 16:17:44 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-20 02:26:04 +08:00
|
|
|
static int flctl_remove(struct platform_device *pdev)
|
2008-10-20 16:17:44 +08:00
|
|
|
{
|
|
|
|
struct sh_flctl *flctl = platform_get_drvdata(pdev);
|
|
|
|
|
2012-10-19 18:15:35 +08:00
|
|
|
flctl_release_dma(flctl);
|
2015-12-10 16:00:23 +08:00
|
|
|
nand_release(nand_to_mtd(&flctl->chip));
|
2012-03-18 22:13:20 +08:00
|
|
|
pm_runtime_disable(&pdev->dev);
|
2008-10-20 16:17:44 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver flctl_driver = {
|
|
|
|
.remove = flctl_remove,
|
|
|
|
.driver = {
|
|
|
|
.name = "sh_flctl",
|
2013-03-14 18:07:04 +08:00
|
|
|
.of_match_table = of_match_ptr(of_flctl_match),
|
2008-10-20 16:17:44 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2013-03-05 12:30:56 +08:00
|
|
|
module_platform_driver_probe(flctl_driver, flctl_probe);
|
2008-10-20 16:17:44 +08:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Yoshihiro Shimoda");
|
|
|
|
MODULE_DESCRIPTION("SuperH FLCTL driver");
|
|
|
|
MODULE_ALIAS("platform:sh_flctl");
|