projects
/
openwrt
/
svn-archive
/
archive.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ar71xx: ar934x_nfc: return error code from some low-level functions
[openwrt/svn-archive/archive.git]
/
target
/
linux
/
ar71xx
/
files
/
drivers
/
mtd
/
nand
/
ar934x_nfc.c
diff --git
a/target/linux/ar71xx/files/drivers/mtd/nand/ar934x_nfc.c
b/target/linux/ar71xx/files/drivers/mtd/nand/ar934x_nfc.c
index d889c70b027ae3e0e047d66b3faea5752addda91..1e387e875f6df066f0f79c8226cfcb3a7434f206 100644
(file)
--- a/
target/linux/ar71xx/files/drivers/mtd/nand/ar934x_nfc.c
+++ b/
target/linux/ar71xx/files/drivers/mtd/nand/ar934x_nfc.c
@@
-131,6
+131,7
@@
#define AR934X_NFC_DEV_READY_TIMEOUT 25 /* msecs */
#define AR934X_NFC_DMA_READY_TIMEOUT 25 /* msecs */
#define AR934X_NFC_DONE_TIMEOUT 1000
#define AR934X_NFC_DEV_READY_TIMEOUT 25 /* msecs */
#define AR934X_NFC_DMA_READY_TIMEOUT 25 /* msecs */
#define AR934X_NFC_DONE_TIMEOUT 1000
+#define AR934X_NFC_DMA_RETRIES 20
#define AR934X_NFC_USE_IRQ true
#define AR934X_NFC_IRQ_MASK AR934X_NFC_INT_DEV_RDY(0)
#define AR934X_NFC_USE_IRQ true
#define AR934X_NFC_IRQ_MASK AR934X_NFC_INT_DEV_RDY(0)
@@
-173,6
+174,7
@@
struct ar934x_nfc {
struct device *parent;
void __iomem *base;
void (*select_chip)(int chip_no);
struct device *parent;
void __iomem *base;
void (*select_chip)(int chip_no);
+ bool swap_dma;
int irq;
wait_queue_head_t irq_waitq;
int irq;
wait_queue_head_t irq_waitq;
@@
-189,6
+191,8
@@
struct ar934x_nfc {
unsigned int buf_size;
int buf_index;
unsigned int buf_size;
int buf_index;
+ bool read_id;
+
int erase1_page_addr;
int rndout_page_addr;
int erase1_page_addr;
int rndout_page_addr;
@@
-406,7
+410,7
@@
ar934x_nfc_send_cmd(struct ar934x_nfc *nfc, unsigned command)
ar934x_nfc_wait_dev_ready(nfc);
}
ar934x_nfc_wait_dev_ready(nfc);
}
-static
void
+static
int
ar934x_nfc_do_rw_command(struct ar934x_nfc *nfc, int column, int page_addr,
int len, u32 cmd_reg, u32 ctrl_reg, bool write)
{
ar934x_nfc_do_rw_command(struct ar934x_nfc *nfc, int column, int page_addr,
int len, u32 cmd_reg, u32 ctrl_reg, bool write)
{
@@
-465,38
+469,44
@@
retry:
(write) ? "write" : "read", page_addr);
ar934x_nfc_restart(nfc);
(write) ? "write" : "read", page_addr);
ar934x_nfc_restart(nfc);
- if (retries++ <
5
)
+ if (retries++ <
AR934X_NFC_DMA_RETRIES
)
goto retry;
dev_err(nfc->parent, "%s operation failed on page %d\n",
(write) ? "write" : "read", page_addr);
}
goto retry;
dev_err(nfc->parent, "%s operation failed on page %d\n",
(write) ? "write" : "read", page_addr);
}
+
+ return err;
}
}
-static
void
+static
int
ar934x_nfc_send_readid(struct ar934x_nfc *nfc, unsigned command)
{
u32 cmd_reg;
ar934x_nfc_send_readid(struct ar934x_nfc *nfc, unsigned command)
{
u32 cmd_reg;
+ int err;
nfc_dbg(nfc, "readid, cmd:%02x\n", command);
cmd_reg = AR934X_NFC_CMD_SEQ_1C1AXR;
cmd_reg |= (command & AR934X_NFC_CMD_CMD0_M) << AR934X_NFC_CMD_CMD0_S;
nfc_dbg(nfc, "readid, cmd:%02x\n", command);
cmd_reg = AR934X_NFC_CMD_SEQ_1C1AXR;
cmd_reg |= (command & AR934X_NFC_CMD_CMD0_M) << AR934X_NFC_CMD_CMD0_S;
-
ar934x_nfc_do_rw_command(nfc, -1, -1, AR934X_NFC_ID_BUF_SIZE, cmd_reg
,
- nfc->ctrl_reg, false);
+
err = ar934x_nfc_do_rw_command(nfc, -1, -1, AR934X_NFC_ID_BUF_SIZE
,
+
cmd_reg,
nfc->ctrl_reg, false);
nfc_debug_data("[id] ", nfc->buf, AR934X_NFC_ID_BUF_SIZE);
nfc_debug_data("[id] ", nfc->buf, AR934X_NFC_ID_BUF_SIZE);
+
+ return err;
}
}
-static
void
+static
int
ar934x_nfc_send_read(struct ar934x_nfc *nfc, unsigned command, int column,
ar934x_nfc_send_read(struct ar934x_nfc *nfc, unsigned command, int column,
- int page_addr, int len
, bool oob
)
+ int page_addr, int len)
{
u32 cmd_reg;
{
u32 cmd_reg;
+ int err;
- nfc_dbg(nfc, "read, column=%d page=%d len=%d
oob:%d
\n",
- column, page_addr, len
, oob
);
+ nfc_dbg(nfc, "read, column=%d page=%d len=%d\n",
+ column, page_addr, len);
cmd_reg = (command & AR934X_NFC_CMD_CMD0_M) << AR934X_NFC_CMD_CMD0_S;
cmd_reg = (command & AR934X_NFC_CMD_CMD0_M) << AR934X_NFC_CMD_CMD0_S;
@@
-507,10
+517,12
@@
ar934x_nfc_send_read(struct ar934x_nfc *nfc, unsigned command, int column,
cmd_reg |= AR934X_NFC_CMD_SEQ_1C5A1CXR;
}
cmd_reg |= AR934X_NFC_CMD_SEQ_1C5A1CXR;
}
- ar934x_nfc_do_rw_command(nfc, column, page_addr, len,
- cmd_reg, nfc->ctrl_reg, false);
+
err =
ar934x_nfc_do_rw_command(nfc, column, page_addr, len,
+
cmd_reg, nfc->ctrl_reg, false);
nfc_debug_data("[data] ", nfc->buf, len);
nfc_debug_data("[data] ", nfc->buf, len);
+
+ return err;
}
static void
}
static void
@@
-551,7
+563,7
@@
ar934x_nfc_send_erase(struct ar934x_nfc *nfc, unsigned command, int column,
ar934x_nfc_wait_dev_ready(nfc);
}
ar934x_nfc_wait_dev_ready(nfc);
}
-static
void
+static
int
ar934x_nfc_send_write(struct ar934x_nfc *nfc, unsigned command, int column,
int page_addr, int len)
{
ar934x_nfc_send_write(struct ar934x_nfc *nfc, unsigned command, int column,
int page_addr, int len)
{
@@
-566,8
+578,8
@@
ar934x_nfc_send_write(struct ar934x_nfc *nfc, unsigned command, int column,
cmd_reg |= command << AR934X_NFC_CMD_CMD1_S;
cmd_reg |= AR934X_NFC_CMD_SEQ_12;
cmd_reg |= command << AR934X_NFC_CMD_CMD1_S;
cmd_reg |= AR934X_NFC_CMD_SEQ_12;
- ar934x_nfc_do_rw_command(nfc, column, page_addr, len,
- cmd_reg, nfc->ctrl_reg, true);
+
return
ar934x_nfc_do_rw_command(nfc, column, page_addr, len,
+
cmd_reg, nfc->ctrl_reg, true);
}
static void
}
static void
@@
-590,7
+602,10
@@
ar934x_nfc_read_status(struct ar934x_nfc *nfc)
nfc_dbg(nfc, "read status, cmd:%08x status:%02x\n",
cmd_reg, (status & 0xff));
nfc_dbg(nfc, "read status, cmd:%08x status:%02x\n",
cmd_reg, (status & 0xff));
- nfc->buf[0 ^ 3] = status;
+ if (nfc->swap_dma)
+ nfc->buf[0 ^ 3] = status;
+ else
+ nfc->buf[0] = status;
}
static void
}
static void
@@
-599,6
+614,7
@@
ar934x_nfc_cmdfunc(struct mtd_info *mtd, unsigned int command, int column,
{
struct ar934x_nfc *nfc = mtd_to_ar934x_nfc(mtd);
{
struct ar934x_nfc *nfc = mtd_to_ar934x_nfc(mtd);
+ nfc->read_id = false;
if (command != NAND_CMD_PAGEPROG)
nfc->buf_index = 0;
if (command != NAND_CMD_PAGEPROG)
nfc->buf_index = 0;
@@
-608,6
+624,7
@@
ar934x_nfc_cmdfunc(struct mtd_info *mtd, unsigned int command, int column,
break;
case NAND_CMD_READID:
break;
case NAND_CMD_READID:
+ nfc->read_id = true;
ar934x_nfc_send_readid(nfc, command);
break;
ar934x_nfc_send_readid(nfc, command);
break;
@@
-615,12
+632,10
@@
ar934x_nfc_cmdfunc(struct mtd_info *mtd, unsigned int command, int column,
case NAND_CMD_READ1:
if (nfc->small_page) {
ar934x_nfc_send_read(nfc, command, column, page_addr,
case NAND_CMD_READ1:
if (nfc->small_page) {
ar934x_nfc_send_read(nfc, command, column, page_addr,
- mtd->writesize + mtd->oobsize,
- false);
+ mtd->writesize + mtd->oobsize);
} else {
ar934x_nfc_send_read(nfc, command, 0, page_addr,
} else {
ar934x_nfc_send_read(nfc, command, 0, page_addr,
- mtd->writesize + mtd->oobsize,
- false);
+ mtd->writesize + mtd->oobsize);
nfc->buf_index = column;
nfc->rndout_page_addr = page_addr;
nfc->rndout_read_cmd = command;
nfc->buf_index = column;
nfc->rndout_page_addr = page_addr;
nfc->rndout_read_cmd = command;
@@
-628,18
+643,14
@@
ar934x_nfc_cmdfunc(struct mtd_info *mtd, unsigned int command, int column,
break;
case NAND_CMD_READOOB:
break;
case NAND_CMD_READOOB:
- if (nfc->small_page)
{
+ if (nfc->small_page)
ar934x_nfc_send_read(nfc, NAND_CMD_READOOB,
column, page_addr,
ar934x_nfc_send_read(nfc, NAND_CMD_READOOB,
column, page_addr,
- mtd->oobsize,
- true);
- } else {
+ mtd->oobsize);
+ else
ar934x_nfc_send_read(nfc, NAND_CMD_READ0,
ar934x_nfc_send_read(nfc, NAND_CMD_READ0,
- column, page_addr,
- mtd->writesize + mtd->oobsize,
- true);
- nfc->buf_index = mtd->writesize;
- }
+ mtd->writesize, page_addr,
+ mtd->oobsize);
break;
case NAND_CMD_RNDOUT:
break;
case NAND_CMD_RNDOUT:
@@
-649,7
+660,7
@@
ar934x_nfc_cmdfunc(struct mtd_info *mtd, unsigned int command, int column,
/* emulate subpage read */
ar934x_nfc_send_read(nfc, nfc->rndout_read_cmd, 0,
nfc->rndout_page_addr,
/* emulate subpage read */
ar934x_nfc_send_read(nfc, nfc->rndout_read_cmd, 0,
nfc->rndout_page_addr,
- mtd->writesize + mtd->oobsize
, false
);
+ mtd->writesize + mtd->oobsize);
nfc->buf_index = column;
break;
nfc->buf_index = column;
break;
@@
-722,13
+733,15
@@
static u8
ar934x_nfc_read_byte(struct mtd_info *mtd)
{
struct ar934x_nfc *nfc = mtd_to_ar934x_nfc(mtd);
ar934x_nfc_read_byte(struct mtd_info *mtd)
{
struct ar934x_nfc *nfc = mtd_to_ar934x_nfc(mtd);
- unsigned int buf_index;
u8 data;
WARN_ON(nfc->buf_index >= nfc->buf_size);
u8 data;
WARN_ON(nfc->buf_index >= nfc->buf_size);
- buf_index = nfc->buf_index ^ 3;
- data = nfc->buf[buf_index];
+ if (nfc->swap_dma || nfc->read_id)
+ data = nfc->buf[nfc->buf_index ^ 3];
+ else
+ data = nfc->buf[nfc->buf_index];
+
nfc->buf_index++;
return data;
nfc->buf_index++;
return data;
@@
-742,9
+755,16
@@
ar934x_nfc_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
WARN_ON(nfc->buf_index + len > nfc->buf_size);
WARN_ON(nfc->buf_index + len > nfc->buf_size);
- for (i = 0; i < len; i++) {
- nfc->buf[nfc->buf_index ^ 3] = buf[i];
- nfc->buf_index++;
+ if (nfc->swap_dma) {
+ for (i = 0; i < len; i++) {
+ nfc->buf[nfc->buf_index ^ 3] = buf[i];
+ nfc->buf_index++;
+ }
+ } else {
+ for (i = 0; i < len; i++) {
+ nfc->buf[nfc->buf_index] = buf[i];
+ nfc->buf_index++;
+ }
}
}
}
}
@@
-759,26
+779,21
@@
ar934x_nfc_read_buf(struct mtd_info *mtd, u8 *buf, int len)
buf_index = nfc->buf_index;
buf_index = nfc->buf_index;
- for (i = 0; i < len; i++) {
- buf[i] = nfc->buf[buf_index ^ 3];
- buf_index++;
+ if (nfc->swap_dma || nfc->read_id) {
+ for (i = 0; i < len; i++) {
+ buf[i] = nfc->buf[buf_index ^ 3];
+ buf_index++;
+ }
+ } else {
+ for (i = 0; i < len; i++) {
+ buf[i] = nfc->buf[buf_index];
+ buf_index++;
+ }
}
nfc->buf_index = buf_index;
}
}
nfc->buf_index = buf_index;
}
-static int
-ar934x_nfc_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
-{
- int i;
-
- for (i = 0; i < len; i++)
- if (buf[i] != ar934x_nfc_read_byte(mtd))
- return -EFAULT;
-
- return 0;
-}
-
static void
ar934x_nfc_hw_init(struct ar934x_nfc *nfc)
{
static void
ar934x_nfc_hw_init(struct ar934x_nfc *nfc)
{
@@
-865,7
+880,7
@@
ar934x_nfc_irq_handler(int irq, void *data)
return IRQ_HANDLED;
}
return IRQ_HANDLED;
}
-static int
__devinit
+static int
ar934x_nfc_init_tail(struct mtd_info *mtd)
{
struct ar934x_nfc *nfc = mtd_to_ar934x_nfc(mtd);
ar934x_nfc_init_tail(struct mtd_info *mtd)
{
struct ar934x_nfc *nfc = mtd_to_ar934x_nfc(mtd);
@@
-991,7
+1006,7
@@
ar934x_nfc_init_tail(struct mtd_info *mtd)
return err;
}
return err;
}
-static int
__devinit
+static int
ar934x_nfc_probe(struct platform_device *pdev)
{
static const char *part_probes[] = { "cmdlinepart", NULL, };
ar934x_nfc_probe(struct platform_device *pdev)
{
static const char *part_probes[] = { "cmdlinepart", NULL, };
@@
-1015,24
+1030,22
@@
ar934x_nfc_probe(struct platform_device *pdev)
return -EINVAL;
}
return -EINVAL;
}
- nfc =
kzalloc(
sizeof(struct ar934x_nfc), GFP_KERNEL);
+ nfc =
devm_kzalloc(&pdev->dev,
sizeof(struct ar934x_nfc), GFP_KERNEL);
if (!nfc) {
dev_err(&pdev->dev, "failed to allocate driver data\n");
return -ENOMEM;
}
if (!nfc) {
dev_err(&pdev->dev, "failed to allocate driver data\n");
return -ENOMEM;
}
- nfc->base =
ioremap(res->start, resource_size(res)
);
- if (
nfc->base == NULL
) {
+ nfc->base =
devm_ioremap_resource(&pdev->dev, res
);
+ if (
IS_ERR(nfc->base)
) {
dev_err(&pdev->dev, "failed to remap I/O memory\n");
dev_err(&pdev->dev, "failed to remap I/O memory\n");
- ret = -ENXIO;
- goto err_free_nand;
+ return PTR_ERR(nfc->base);
}
nfc->irq = platform_get_irq(pdev, 0);
if (nfc->irq < 0) {
dev_err(&pdev->dev, "no IRQ resource specified\n");
}
nfc->irq = platform_get_irq(pdev, 0);
if (nfc->irq < 0) {
dev_err(&pdev->dev, "no IRQ resource specified\n");
- ret = -EINVAL;
- goto err_unmap;
+ return -EINVAL;
}
init_waitqueue_head(&nfc->irq_waitq);
}
init_waitqueue_head(&nfc->irq_waitq);
@@
-1040,11
+1053,12
@@
ar934x_nfc_probe(struct platform_device *pdev)
dev_name(&pdev->dev), nfc);
if (ret) {
dev_err(&pdev->dev, "requast_irq failed, err:%d\n", ret);
dev_name(&pdev->dev), nfc);
if (ret) {
dev_err(&pdev->dev, "requast_irq failed, err:%d\n", ret);
-
goto err_unmap
;
+
return ret
;
}
nfc->parent = &pdev->dev;
nfc->select_chip = pdata->select_chip;
}
nfc->parent = &pdev->dev;
nfc->select_chip = pdata->select_chip;
+ nfc->swap_dma = pdata->swap_dma;
nand = &nfc->nand_chip;
mtd = &nfc->mtd;
nand = &nfc->nand_chip;
mtd = &nfc->mtd;
@@
-1056,7
+1070,6
@@
ar934x_nfc_probe(struct platform_device *pdev)
else
mtd->name = dev_name(&pdev->dev);
else
mtd->name = dev_name(&pdev->dev);
- nand->options = NAND_NO_AUTOINCR;
nand->chip_delay = 25;
nand->ecc.mode = NAND_ECC_SOFT;
nand->chip_delay = 25;
nand->ecc.mode = NAND_ECC_SOFT;
@@
-1065,7
+1078,6
@@
ar934x_nfc_probe(struct platform_device *pdev)
nand->read_byte = ar934x_nfc_read_byte;
nand->write_buf = ar934x_nfc_write_buf;
nand->read_buf = ar934x_nfc_read_buf;
nand->read_byte = ar934x_nfc_read_byte;
nand->write_buf = ar934x_nfc_write_buf;
nand->read_buf = ar934x_nfc_read_buf;
- nand->verify_buf = ar934x_nfc_verify_buf;
nand->select_chip = ar934x_nfc_select_chip;
ret = ar934x_nfc_alloc_buf(nfc, AR934X_NFC_ID_BUF_SIZE);
nand->select_chip = ar934x_nfc_select_chip;
ret = ar934x_nfc_alloc_buf(nfc, AR934X_NFC_ID_BUF_SIZE);
@@
-1114,15
+1126,10
@@
err_free_buf:
ar934x_nfc_free_buf(nfc);
err_free_irq:
free_irq(nfc->irq, nfc);
ar934x_nfc_free_buf(nfc);
err_free_irq:
free_irq(nfc->irq, nfc);
-err_unmap:
- iounmap(nfc->base);
-err_free_nand:
- kfree(nfc);
- platform_set_drvdata(pdev, NULL);
return ret;
}
return ret;
}
-static int
__devexit
+static int
ar934x_nfc_remove(struct platform_device *pdev)
{
struct ar934x_nfc *nfc;
ar934x_nfc_remove(struct platform_device *pdev)
{
struct ar934x_nfc *nfc;
@@
-1132,8
+1139,6
@@
ar934x_nfc_remove(struct platform_device *pdev)
nand_release(&nfc->mtd);
ar934x_nfc_free_buf(nfc);
free_irq(nfc->irq, nfc);
nand_release(&nfc->mtd);
ar934x_nfc_free_buf(nfc);
free_irq(nfc->irq, nfc);
- iounmap(nfc->base);
- kfree(nfc);
}
return 0;
}
return 0;
@@
-1141,7
+1146,7
@@
ar934x_nfc_remove(struct platform_device *pdev)
static struct platform_driver ar934x_nfc_driver = {
.probe = ar934x_nfc_probe,
static struct platform_driver ar934x_nfc_driver = {
.probe = ar934x_nfc_probe,
- .remove =
__devexit_p(ar934x_nfc_remove)
,
+ .remove =
ar934x_nfc_remove
,
.driver = {
.name = AR934X_NFC_DRIVER_NAME,
.owner = THIS_MODULE,
.driver = {
.name = AR934X_NFC_DRIVER_NAME,
.owner = THIS_MODULE,