upstream u-boot with additional patches for our devices/boards:
https://lists.denx.de/pipermail/u-boot/2017-March/282789.html (AXP crashes) ;
Gbit ethernet patch for some LIME2 revisions ;
with SPI flash support
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
185 lines
4.3 KiB
185 lines
4.3 KiB
7 years ago
|
// SPDX-License-Identifier: GPL-2.0+
|
||
17 years ago
|
/*
|
||
|
* FSL UPM NAND driver
|
||
|
*
|
||
|
* Copyright (C) 2007 MontaVista Software, Inc.
|
||
|
* Anton Vorontsov <avorontsov@ru.mvista.com>
|
||
|
*/
|
||
|
|
||
|
#include <config.h>
|
||
|
#include <common.h>
|
||
|
#include <asm/io.h>
|
||
8 years ago
|
#include <linux/errno.h>
|
||
17 years ago
|
#include <linux/mtd/mtd.h>
|
||
|
#include <linux/mtd/fsl_upm.h>
|
||
|
#include <nand.h>
|
||
|
|
||
|
static void fsl_upm_start_pattern(struct fsl_upm *upm, u32 pat_offset)
|
||
|
{
|
||
17 years ago
|
clrsetbits_be32(upm->mxmr, MxMR_MAD_MSK, MxMR_OP_RUNP | pat_offset);
|
||
14 years ago
|
(void)in_be32(upm->mxmr);
|
||
17 years ago
|
}
|
||
|
|
||
|
static void fsl_upm_end_pattern(struct fsl_upm *upm)
|
||
|
{
|
||
17 years ago
|
clrbits_be32(upm->mxmr, MxMR_OP_RUNP);
|
||
|
|
||
|
while (in_be32(upm->mxmr) & MxMR_OP_RUNP)
|
||
17 years ago
|
eieio();
|
||
|
}
|
||
|
|
||
16 years ago
|
static void fsl_upm_run_pattern(struct fsl_upm *upm, int width,
|
||
|
void __iomem *io_addr, u32 mar)
|
||
17 years ago
|
{
|
||
16 years ago
|
out_be32(upm->mar, mar);
|
||
14 years ago
|
(void)in_be32(upm->mar);
|
||
17 years ago
|
switch (width) {
|
||
|
case 8:
|
||
16 years ago
|
out_8(io_addr, 0x0);
|
||
17 years ago
|
break;
|
||
|
case 16:
|
||
16 years ago
|
out_be16(io_addr, 0x0);
|
||
17 years ago
|
break;
|
||
|
case 32:
|
||
16 years ago
|
out_be32(io_addr, 0x0);
|
||
17 years ago
|
break;
|
||
17 years ago
|
}
|
||
|
}
|
||
|
|
||
16 years ago
|
static void fun_wait(struct fsl_upm_nand *fun)
|
||
|
{
|
||
|
if (fun->dev_ready) {
|
||
|
while (!fun->dev_ready(fun->chip_nr))
|
||
|
debug("unexpected busy state\n");
|
||
|
} else {
|
||
|
/*
|
||
12 years ago
|
* If the R/B pin is not connected,
|
||
16 years ago
|
* a short delay is necessary.
|
||
|
*/
|
||
|
udelay(1);
|
||
|
}
|
||
|
}
|
||
|
|
||
16 years ago
|
#if CONFIG_SYS_NAND_MAX_CHIPS > 1
|
||
|
static void fun_select_chip(struct mtd_info *mtd, int chip_nr)
|
||
|
{
|
||
9 years ago
|
struct nand_chip *chip = mtd_to_nand(mtd);
|
||
|
struct fsl_upm_nand *fun = nand_get_controller_data(chip);
|
||
16 years ago
|
|
||
|
if (chip_nr >= 0) {
|
||
|
fun->chip_nr = chip_nr;
|
||
|
chip->IO_ADDR_R = chip->IO_ADDR_W =
|
||
|
fun->upm.io_addr + fun->chip_offset * chip_nr;
|
||
|
} else if (chip_nr == -1) {
|
||
|
chip->cmd_ctrl(mtd, NAND_CMD_NONE, 0 | NAND_CTRL_CHANGE);
|
||
|
}
|
||
|
}
|
||
|
#endif
|
||
|
|
||
17 years ago
|
static void fun_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
|
||
17 years ago
|
{
|
||
9 years ago
|
struct nand_chip *chip = mtd_to_nand(mtd);
|
||
|
struct fsl_upm_nand *fun = nand_get_controller_data(chip);
|
||
16 years ago
|
void __iomem *io_addr;
|
||
|
u32 mar;
|
||
17 years ago
|
|
||
17 years ago
|
if (!(ctrl & fun->last_ctrl)) {
|
||
17 years ago
|
fsl_upm_end_pattern(&fun->upm);
|
||
17 years ago
|
|
||
|
if (cmd == NAND_CMD_NONE)
|
||
|
return;
|
||
|
|
||
|
fun->last_ctrl = ctrl & (NAND_ALE | NAND_CLE);
|
||
17 years ago
|
}
|
||
|
|
||
17 years ago
|
if (ctrl & NAND_CTRL_CHANGE) {
|
||
|
if (ctrl & NAND_ALE)
|
||
|
fsl_upm_start_pattern(&fun->upm, fun->upm_addr_offset);
|
||
|
else if (ctrl & NAND_CLE)
|
||
|
fsl_upm_start_pattern(&fun->upm, fun->upm_cmd_offset);
|
||
|
}
|
||
17 years ago
|
|
||
16 years ago
|
mar = cmd << (32 - fun->width);
|
||
|
io_addr = fun->upm.io_addr;
|
||
|
#if CONFIG_SYS_NAND_MAX_CHIPS > 1
|
||
16 years ago
|
if (fun->chip_nr > 0) {
|
||
16 years ago
|
io_addr += fun->chip_offset * fun->chip_nr;
|
||
16 years ago
|
if (fun->upm_mar_chip_offset)
|
||
|
mar |= fun->upm_mar_chip_offset * fun->chip_nr;
|
||
|
}
|
||
16 years ago
|
#endif
|
||
|
fsl_upm_run_pattern(&fun->upm, fun->width, io_addr, mar);
|
||
17 years ago
|
|
||
|
/*
|
||
11 years ago
|
* Some boards/chips needs this. At least the MPC8360E-RDK
|
||
|
* needs it. Probably weird chip, because I don't see any
|
||
|
* need for this on MPC8555E + Samsung K9F1G08U0A. Usually
|
||
|
* here are 0-2 unexpected busy states per block read.
|
||
17 years ago
|
*/
|
||
16 years ago
|
if (fun->wait_flags & FSL_UPM_WAIT_RUN_PATTERN)
|
||
|
fun_wait(fun);
|
||
17 years ago
|
}
|
||
|
|
||
13 years ago
|
static u8 upm_nand_read_byte(struct mtd_info *mtd)
|
||
17 years ago
|
{
|
||
9 years ago
|
struct nand_chip *chip = mtd_to_nand(mtd);
|
||
17 years ago
|
|
||
|
return in_8(chip->IO_ADDR_R);
|
||
|
}
|
||
|
|
||
13 years ago
|
static void upm_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
|
||
17 years ago
|
{
|
||
|
int i;
|
||
9 years ago
|
struct nand_chip *chip = mtd_to_nand(mtd);
|
||
|
struct fsl_upm_nand *fun = nand_get_controller_data(chip);
|
||
17 years ago
|
|
||
16 years ago
|
for (i = 0; i < len; i++) {
|
||
17 years ago
|
out_8(chip->IO_ADDR_W, buf[i]);
|
||
16 years ago
|
if (fun->wait_flags & FSL_UPM_WAIT_WRITE_BYTE)
|
||
|
fun_wait(fun);
|
||
|
}
|
||
|
|
||
|
if (fun->wait_flags & FSL_UPM_WAIT_WRITE_BUFFER)
|
||
|
fun_wait(fun);
|
||
17 years ago
|
}
|
||
|
|
||
13 years ago
|
static void upm_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
|
||
17 years ago
|
{
|
||
|
int i;
|
||
9 years ago
|
struct nand_chip *chip = mtd_to_nand(mtd);
|
||
17 years ago
|
|
||
|
for (i = 0; i < len; i++)
|
||
|
buf[i] = in_8(chip->IO_ADDR_R);
|
||
|
}
|
||
|
|
||
|
static int nand_dev_ready(struct mtd_info *mtd)
|
||
|
{
|
||
9 years ago
|
struct nand_chip *chip = mtd_to_nand(mtd);
|
||
|
struct fsl_upm_nand *fun = nand_get_controller_data(chip);
|
||
17 years ago
|
|
||
16 years ago
|
return fun->dev_ready(fun->chip_nr);
|
||
17 years ago
|
}
|
||
|
|
||
|
int fsl_upm_nand_init(struct nand_chip *chip, struct fsl_upm_nand *fun)
|
||
|
{
|
||
17 years ago
|
if (fun->width != 8 && fun->width != 16 && fun->width != 32)
|
||
17 years ago
|
return -ENOSYS;
|
||
|
|
||
17 years ago
|
fun->last_ctrl = NAND_CLE;
|
||
|
|
||
9 years ago
|
nand_set_controller_data(chip, fun);
|
||
17 years ago
|
chip->chip_delay = fun->chip_delay;
|
||
17 years ago
|
chip->ecc.mode = NAND_ECC_SOFT;
|
||
|
chip->cmd_ctrl = fun_cmd_ctrl;
|
||
16 years ago
|
#if CONFIG_SYS_NAND_MAX_CHIPS > 1
|
||
|
chip->select_chip = fun_select_chip;
|
||
|
#endif
|
||
13 years ago
|
chip->read_byte = upm_nand_read_byte;
|
||
|
chip->read_buf = upm_nand_read_buf;
|
||
|
chip->write_buf = upm_nand_write_buf;
|
||
17 years ago
|
if (fun->dev_ready)
|
||
|
chip->dev_ready = nand_dev_ready;
|
||
17 years ago
|
|
||
|
return 0;
|
||
|
}
|