Release 4.7 drivers/mtd/nand/au1550nd.c
/*
* drivers/mtd/nand/au1550nd.c
*
* Copyright (C) 2004 Embedded Edge, LLC
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#include <linux/slab.h>
#include <linux/gpio.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/nand.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_chip chip;
int cs;
void __iomem *base;
void (*write_byte)(struct mtd_info *, u_char);
};
/**
* au_read_byte - read one byte from the chip
* @mtd: MTD device structure
*
* read function for 8bit buswidth
*/
static u_char au_read_byte(struct mtd_info *mtd)
{
struct nand_chip *this = mtd_to_nand(mtd);
u_char ret = readb(this->IO_ADDR_R);
wmb(); /* drain writebuffer */
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
thomas gleixner | thomas gleixner | 26 | 68.42% | 1 | 25.00% |
david woodhouse | david woodhouse | 7 | 18.42% | 1 | 25.00% |
boris brezillon | boris brezillon | 3 | 7.89% | 1 | 25.00% |
manuel lauss | manuel lauss | 2 | 5.26% | 1 | 25.00% |
| Total | 38 | 100.00% | 4 | 100.00% |
/**
* au_write_byte - write one byte to the chip
* @mtd: MTD device structure
* @byte: pointer to data byte to write
*
* write function for 8it buswidth
*/
static void au_write_byte(struct mtd_info *mtd, u_char byte)
{
struct nand_chip *this = mtd_to_nand(mtd);
writeb(byte, this->IO_ADDR_W);
wmb(); /* drain writebuffer */
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
thomas gleixner | thomas gleixner | 23 | 62.16% | 1 | 25.00% |
david woodhouse | david woodhouse | 9 | 24.32% | 1 | 25.00% |
boris brezillon | boris brezillon | 3 | 8.11% | 1 | 25.00% |
manuel lauss | manuel lauss | 2 | 5.41% | 1 | 25.00% |
| Total | 37 | 100.00% | 4 | 100.00% |
/**
* au_read_byte16 - read one byte endianness aware from the chip
* @mtd: MTD device structure
*
* read function for 16bit buswidth with endianness conversion
*/
static u_char au_read_byte16(struct mtd_info *mtd)
{
struct nand_chip *this = mtd_to_nand(mtd);
u_char ret = (u_char) cpu_to_le16(readw(this->IO_ADDR_R));
wmb(); /* drain writebuffer */
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
thomas gleixner | thomas gleixner | 30 | 68.18% | 1 | 25.00% |
david woodhouse | david woodhouse | 9 | 20.45% | 1 | 25.00% |
boris brezillon | boris brezillon | 3 | 6.82% | 1 | 25.00% |
manuel lauss | manuel lauss | 2 | 4.55% | 1 | 25.00% |
| Total | 44 | 100.00% | 4 | 100.00% |
/**
* au_write_byte16 - write one byte endianness aware to the chip
* @mtd: MTD device structure
* @byte: pointer to data byte to write
*
* write function for 16bit buswidth with endianness conversion
*/
static void au_write_byte16(struct mtd_info *mtd, u_char byte)
{
struct nand_chip *this = mtd_to_nand(mtd);
writew(le16_to_cpu((u16) byte), this->IO_ADDR_W);
wmb(); /* drain writebuffer */
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
thomas gleixner | thomas gleixner | 27 | 62.79% | 1 | 25.00% |
david woodhouse | david woodhouse | 11 | 25.58% | 1 | 25.00% |
boris brezillon | boris brezillon | 3 | 6.98% | 1 | 25.00% |
manuel lauss | manuel lauss | 2 | 4.65% | 1 | 25.00% |
| Total | 43 | 100.00% | 4 | 100.00% |
/**
* au_read_word - read one word from the chip
* @mtd: MTD device structure
*
* read function for 16bit buswidth without endianness conversion
*/
static u16 au_read_word(struct mtd_info *mtd)
{
struct nand_chip *this = mtd_to_nand(mtd);
u16 ret = readw(this->IO_ADDR_R);
wmb(); /* drain writebuffer */
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
david woodhouse | david woodhouse | 19 | 50.00% | 1 | 25.00% |
thomas gleixner | thomas gleixner | 14 | 36.84% | 1 | 25.00% |
boris brezillon | boris brezillon | 3 | 7.89% | 1 | 25.00% |
manuel lauss | manuel lauss | 2 | 5.26% | 1 | 25.00% |
| Total | 38 | 100.00% | 4 | 100.00% |
/**
* au_write_buf - write buffer to chip
* @mtd: MTD device structure
* @buf: data buffer
* @len: number of bytes to write
*
* write function for 8bit buswidth
*/
static void au_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
{
int i;
struct nand_chip *this = mtd_to_nand(mtd);
for (i = 0; i < len; i++) {
writeb(buf[i], this->IO_ADDR_W);
wmb(); /* drain writebuffer */
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
david woodhouse | david woodhouse | 41 | 65.08% | 1 | 25.00% |
thomas gleixner | thomas gleixner | 17 | 26.98% | 1 | 25.00% |
boris brezillon | boris brezillon | 3 | 4.76% | 1 | 25.00% |
manuel lauss | manuel lauss | 2 | 3.17% | 1 | 25.00% |
| Total | 63 | 100.00% | 4 | 100.00% |
/**
* au_read_buf - read chip data into buffer
* @mtd: MTD device structure
* @buf: buffer to store date
* @len: number of bytes to read
*
* read function for 8bit buswidth
*/
static void au_read_buf(struct mtd_info *mtd, u_char *buf, int len)
{
int i;
struct nand_chip *this = mtd_to_nand(mtd);
for (i = 0; i < len; i++) {
buf[i] = readb(this->IO_ADDR_R);
wmb(); /* drain writebuffer */
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
david woodhouse | david woodhouse | 40 | 64.52% | 1 | 25.00% |
thomas gleixner | thomas gleixner | 17 | 27.42% | 1 | 25.00% |
boris brezillon | boris brezillon | 3 | 4.84% | 1 | 25.00% |
manuel lauss | manuel lauss | 2 | 3.23% | 1 | 25.00% |
| Total | 62 | 100.00% | 4 | 100.00% |
/**
* au_write_buf16 - write buffer to chip
* @mtd: MTD device structure
* @buf: data buffer
* @len: number of bytes to write
*
* write function for 16bit buswidth
*/
static void au_write_buf16(struct mtd_info *mtd, const u_char *buf, int len)
{
int i;
struct nand_chip *this = mtd_to_nand(mtd);
u16 *p = (u16 *) buf;
len >>= 1;
for (i = 0; i < len; i++) {
writew(p[i], this->IO_ADDR_W);
wmb(); /* drain writebuffer */
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
thomas gleixner | thomas gleixner | 50 | 64.94% | 1 | 25.00% |
david woodhouse | david woodhouse | 22 | 28.57% | 1 | 25.00% |
boris brezillon | boris brezillon | 3 | 3.90% | 1 | 25.00% |
manuel lauss | manuel lauss | 2 | 2.60% | 1 | 25.00% |
| Total | 77 | 100.00% | 4 | 100.00% |
/**
* au_read_buf16 - read chip data into buffer
* @mtd: MTD device structure
* @buf: buffer to store date
* @len: number of bytes to read
*
* read function for 16bit buswidth
*/
static void au_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
{
int i;
struct nand_chip *this = mtd_to_nand(mtd);
u16 *p = (u16 *) buf;
len >>= 1;
for (i = 0; i < len; i++) {
p[i] = readw(this->IO_ADDR_R);
wmb(); /* drain writebuffer */
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
thomas gleixner | thomas gleixner | 42 | 55.26% | 1 | 25.00% |
david woodhouse | david woodhouse | 29 | 38.16% | 1 | 25.00% |
boris brezillon | boris brezillon | 3 | 3.95% | 1 | 25.00% |
manuel lauss | manuel lauss | 2 | 2.63% | 1 | 25.00% |
| Total | 76 | 100.00% | 4 | 100.00% |
/* Select the chip by setting nCE to low */
#define NAND_CTL_SETNCE 1
/* Deselect the chip by setting nCE to high */
#define NAND_CTL_CLRNCE 2
/* Select the command latch by setting CLE to high */
#define NAND_CTL_SETCLE 3
/* Deselect the command latch by setting CLE to low */
#define NAND_CTL_CLRCLE 4
/* Select the address latch by setting ALE to high */
#define NAND_CTL_SETALE 5
/* Deselect the address latch by setting ALE to low */
#define NAND_CTL_CLRALE 6
static void au1550_hwcontrol(struct mtd_info *mtd, int cmd)
{
struct nand_chip *this = mtd_to_nand(mtd);
struct au1550nd_ctx *ctx = container_of(this, struct au1550nd_ctx,
chip);
switch (cmd) {
case NAND_CTL_SETCLE:
this->IO_ADDR_W = ctx->base + MEM_STNAND_CMD;
break;
case NAND_CTL_CLRCLE:
this->IO_ADDR_W = ctx->base + MEM_STNAND_DATA;
break;
case NAND_CTL_SETALE:
this->IO_ADDR_W = ctx->base + MEM_STNAND_ADDR;
break;
case NAND_CTL_CLRALE:
this->IO_ADDR_W = ctx->base + MEM_STNAND_DATA;
/* FIXME: Nobody knows why this is necessary,
* but it works only that way */
udelay(1);
break;
case NAND_CTL_SETNCE:
/* assert (force assert) chip enable */
alchemy_wrsmem((1 << (4 + ctx->cs)), AU1000_MEM_STNDCTL);
break;
case NAND_CTL_CLRNCE:
/* deassert chip enable */
alchemy_wrsmem(0, AU1000_MEM_STNDCTL);
break;
}
this->IO_ADDR_R = this->IO_ADDR_W;
wmb(); /* Drain the writebuffer */
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
thomas gleixner | thomas gleixner | 81 | 52.94% | 1 | 11.11% |
david woodhouse | david woodhouse | 30 | 19.61% | 3 | 33.33% |
manuel lauss | manuel lauss | 28 | 18.30% | 3 | 33.33% |
boris brezillon | boris brezillon | 14 | 9.15% | 2 | 22.22% |
| Total | 153 | 100.00% | 9 | 100.00% |
int au1550_device_ready(struct mtd_info *mtd)
{
return (alchemy_rdsmem(AU1000_MEM_STSTAT) & 0x1) ? 1 : 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
thomas gleixner | thomas gleixner | 18 | 75.00% | 1 | 33.33% |
manuel lauss | manuel lauss | 3 | 12.50% | 1 | 33.33% |
david woodhouse | david woodhouse | 3 | 12.50% | 1 | 33.33% |
| Total | 24 | 100.00% | 3 | 100.00% |
/**
* au1550_select_chip - control -CE line
* Forbid driving -CE manually permitting the NAND controller to do this.
* Keeping -CE asserted during the whole sector reads interferes with the
* NOR flash and PCMCIA drivers as it causes contention on the static bus.
* We only have to hold -CE low for the NAND read commands since the flash
* chip needs it to be asserted during chip not ready time but the NAND
* controller keeps it released.
*
* @mtd: MTD device structure
* @chip: chipnumber to select, -1 for deselect
*/
static void au1550_select_chip(struct mtd_info *mtd, int chip)
{
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
sergei shtylyov | sergei shtylyov | 13 | 100.00% | 1 | 100.00% |
| Total | 13 | 100.00% | 1 | 100.00% |
/**
* au1550_command - Send command to NAND device
* @mtd: MTD device structure
* @command: the command to be sent
* @column: the column address for this command, -1 if none
* @page_addr: the page address for this command, -1 if none
*/
static void au1550_command(struct mtd_info *mtd, unsigned command, int column, int page_addr)
{
struct nand_chip *this = mtd_to_nand(mtd);
struct au1550nd_ctx *ctx = container_of(this, struct au1550nd_ctx,
chip);
int ce_override = 0, i;
unsigned long flags = 0;
/* Begin command latch cycle */
au1550_hwcontrol(mtd, NAND_CTL_SETCLE);
/*
* Write out the command to the device.
*/
if (command == NAND_CMD_SEQIN) {
int readcmd;
if (column >= mtd->writesize) {
/* OOB area */
column -= mtd->writesize;
readcmd = NAND_CMD_READOOB;
} else if (column < 256) {
/* First 256 bytes --> READ0 */
readcmd = NAND_CMD_READ0;
} else {
column -= 256;
readcmd = NAND_CMD_READ1;
}
ctx->write_byte(mtd, readcmd);
}
ctx->write_byte(mtd, command);
/* Set ALE and clear CLE to start address cycle */
au1550_hwcontrol(mtd, NAND_CTL_CLRCLE);
if (column != -1 || page_addr != -1) {
au1550_hwcontrol(mtd, NAND_CTL_SETALE);
/* Serially input address */
if (column != -1) {
/* Adjust columns for 16 bit buswidth */
if (this->options & NAND_BUSWIDTH_16 &&
!nand_opcode_8bits(command))
column >>= 1;
ctx->write_byte(mtd, column);
}
if (page_addr != -1) {
ctx->write_byte(mtd, (u8)(page_addr & 0xff));
if (command == NAND_CMD_READ0 ||
command == NAND_CMD_READ1 ||
command == NAND_CMD_READOOB) {
/*
* NAND controller will release -CE after
* the last address byte is written, so we'll
* have to forcibly assert it. No interrupts
* are allowed while we do this as we don't
* want the NOR flash or PCMCIA drivers to
* steal our precious bytes of data...
*/
ce_override = 1;
local_irq_save(flags);
au1550_hwcontrol(mtd, NAND_CTL_SETNCE);
}
ctx->write_byte(mtd, (u8)(page_addr >> 8));
/* One more address cycle for devices > 32MiB */
if (this->chipsize > (32 << 20))
ctx->write_byte(mtd,
((page_addr >> 16) & 0x0f));
}
/* Latch in address */
au1550_hwcontrol(mtd, NAND_CTL_CLRALE);
}
/*
* Program and erase have their own busy handlers.
* Status and sequential in need no delay.
*/
switch (command) {
case NAND_CMD_PAGEPROG:
case NAND_CMD_ERASE1:
case NAND_CMD_ERASE2:
case NAND_CMD_SEQIN:
case NAND_CMD_STATUS:
return;
case NAND_CMD_RESET:
break;
case NAND_CMD_READ0:
case NAND_CMD_READ1:
case NAND_CMD_READOOB:
/* Check if we're really driving -CE low (just in case) */
if (unlikely(!ce_override))
break;
/* Apply a short delay always to ensure that we do wait tWB. */
ndelay(100);
/* Wait for a chip to become ready... */
for (i = this->chip_delay; !this->dev_ready(mtd) && i > 0; --i)
udelay(1);
/* Release -CE and re-enable interrupts. */
au1550_hwcontrol(mtd, NAND_CTL_CLRNCE);
local_irq_restore(flags);
return;
}
/* Apply this short delay always to ensure that we do wait tWB. */
ndelay(100);
while(!this->dev_ready(mtd));
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
sergei shtylyov | sergei shtylyov | 374 | 86.37% | 1 | 14.29% |
manuel lauss | manuel lauss | 31 | 7.16% | 1 | 14.29% |
boris brezillon | boris brezillon | 14 | 3.23% | 2 | 28.57% |
brian norris | brian norris | 6 | 1.39% | 1 | 14.29% |
thomas gleixner | thomas gleixner | 6 | 1.39% | 1 | 14.29% |
joern engel | joern engel | 2 | 0.46% | 1 | 14.29% |
| Total | 433 | 100.00% | 7 | 100.00% |
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;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
manuel lauss | manuel lauss | 102 | 73.38% | 1 | 16.67% |
david woodhouse | david woodhouse | 33 | 23.74% | 3 | 50.00% |
pete popov | pete popov | 3 | 2.16% | 1 | 16.67% |
thomas gleixner | thomas gleixner | 1 | 0.72% | 1 | 16.67% |
| Total | 139 | 100.00% | 6 | 100.00% |
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_nocache(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;
this->dev_ready = au1550_device_ready;
this->select_chip = au1550_select_chip;
this->cmdfunc = au1550_command;
/* 30 us command delay time */
this->chip_delay = 30;
this->ecc.mode = NAND_ECC_SOFT;
this->ecc.algo = NAND_ECC_HAMMING;
if (pd->devwidth)
this->options |= NAND_BUSWIDTH_16;
this->read_byte = (pd->devwidth) ? au_read_byte16 : au_read_byte;
ctx->write_byte = (pd->devwidth) ? au_write_byte16 : au_write_byte;
this->read_word = au_read_word;
this->write_buf = (pd->devwidth) ? au_write_buf16 : au_write_buf;
this->read_buf = (pd->devwidth) ? au_read_buf16 : au_read_buf;
ret = nand_scan(mtd, 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;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
manuel lauss | manuel lauss | 235 | 49.58% | 1 | 8.33% |
pete popov | pete popov | 68 | 14.35% | 1 | 8.33% |
david woodhouse | david woodhouse | 65 | 13.71% | 1 | 8.33% |
thomas gleixner | thomas gleixner | 53 | 11.18% | 2 | 16.67% |
boris brezillon | boris brezillon | 14 | 2.95% | 1 | 8.33% |
sergei shtylyov | sergei shtylyov | 12 | 2.53% | 1 | 8.33% |
rafal milecki | rafal milecki | 8 | 1.69% | 1 | 8.33% |
frans klaver | frans klaver | 7 | 1.48% | 1 | 8.33% |
wei yongjun | wei yongjun | 7 | 1.48% | 1 | 8.33% |
jingoo han | jingoo han | 4 | 0.84% | 1 | 8.33% |
jamie iles | jamie iles | 1 | 0.21% | 1 | 8.33% |
| Total | 474 | 100.00% | 12 | 100.00% |
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);
nand_release(nand_to_mtd(&ctx->chip));
iounmap(ctx->base);
release_mem_region(r->start, 0x1000);
kfree(ctx);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
manuel lauss | manuel lauss | 51 | 72.86% | 1 | 25.00% |
david woodhouse | david woodhouse | 14 | 20.00% | 1 | 25.00% |
boris brezillon | boris brezillon | 4 | 5.71% | 1 | 25.00% |
thomas gleixner | thomas gleixner | 1 | 1.43% | 1 | 25.00% |
| Total | 70 | 100.00% | 4 | 100.00% |
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");
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
manuel lauss | manuel lauss | 519 | 26.81% | 6 | 21.43% |
thomas gleixner | thomas gleixner | 453 | 23.40% | 4 | 14.29% |
sergei shtylyov | sergei shtylyov | 404 | 20.87% | 1 | 3.57% |
david woodhouse | david woodhouse | 371 | 19.16% | 5 | 17.86% |
boris brezillon | boris brezillon | 73 | 3.77% | 2 | 7.14% |
pete popov | pete popov | 71 | 3.67% | 1 | 3.57% |
brian norris | brian norris | 15 | 0.77% | 2 | 7.14% |
rafal milecki | rafal milecki | 8 | 0.41% | 1 | 3.57% |
frans klaver | frans klaver | 7 | 0.36% | 1 | 3.57% |
wei yongjun | wei yongjun | 7 | 0.36% | 1 | 3.57% |
jingoo han | jingoo han | 4 | 0.21% | 1 | 3.57% |
joern engel | joern engel | 2 | 0.10% | 1 | 3.57% |
adrian bunk | adrian bunk | 1 | 0.05% | 1 | 3.57% |
jamie iles | jamie iles | 1 | 0.05% | 1 | 3.57% |
| Total | 1936 | 100.00% | 28 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.