26 #include <linux/device.h>
27 #include <linux/module.h>
37 #include <linux/slab.h>
48 #define DRIVER_NAME "omap2-onenand"
50 #define ONENAND_BUFRAM_SIZE (1024 * 5)
68 static void omap2_onenand_dma_cb(
int lch,
u16 ch_status,
void *
data)
95 static void wait_err(
char *
msg,
int state,
unsigned int ctrl,
unsigned int intr)
97 printk(
KERN_ERR "onenand_wait: %s! state %d ctrl 0x%04x intr 0x%04x\n",
98 msg, state, ctrl, intr);
101 static void wait_warn(
char *
msg,
int state,
unsigned int ctrl,
105 "intr 0x%04x\n", msg, state, ctrl, intr);
112 unsigned int intr = 0;
113 unsigned int ctrl, ctrl_mask;
142 wait_err(
"controller error", state, ctrl, intr);
145 if ((intr & intr_flags) == intr_flags)
169 wait_err(
"gpio error", state, ctrl, intr);
193 wait_err(
"timeout", state, ctrl, intr);
198 wait_warn(
"timeout", state, ctrl, intr);
206 syscfg &= ~ONENAND_SYS_CFG1_IOBE;
242 unsigned int addr1, addr8;
248 "0x%04x, addr1 %#x, addr8 %#x\n",
254 "ECC error = 0x%04x, addr1 %#x, "
255 "addr8 %#x\n", ecc, addr1, addr8);
260 wait_err(
"timeout", state, ctrl, intr);
264 if (ctrl & ONENAND_CTRL_ERROR) {
265 wait_err(
"controller error", state, ctrl, intr);
268 "Device is write protected!!!\n");
274 ctrl_mask &= ~0x8000;
276 if (ctrl & ctrl_mask)
277 wait_warn(
"unexpected controller status", state, ctrl, intr);
282 static inline int omap2_onenand_bufferram_offset(
struct mtd_info *mtd,
int area)
296 #if defined(CONFIG_ARCH_OMAP3) || defined(MULTI_OMAP2)
306 unsigned long timeout;
307 void *
buf = (
void *)buffer;
309 volatile unsigned *
done;
311 bram_offset = omap2_onenand_bufferram_offset(mtd, area) + area +
offset;
312 if (bram_offset & 3 || (
size_t)buf & 3 || count < 384)
319 if (buf >= high_memory) {
323 ((
size_t)(buf + count - 1) & PAGE_MASK))
334 memcpy(buf + count, this->base + bram_offset + count, xtra);
341 "Couldn't DMA map a %d byte buffer\n",
347 count >> 2, 1, 0, 0, 0);
365 dev_err(&c->
pdev->dev,
"timeout waiting for DMA\n");
372 memcpy(buf, this->base + bram_offset, count);
377 const unsigned char *buffer,
378 int offset,
size_t count)
384 unsigned long timeout;
385 void *buf = (
void *)buffer;
386 volatile unsigned *
done;
388 bram_offset = omap2_onenand_bufferram_offset(mtd, area) + area +
offset;
389 if (bram_offset & 3 || (
size_t)buf & 3 || count < 384)
396 if (buf >= high_memory) {
399 if (((
size_t)buf & PAGE_MASK) !=
400 ((
size_t)(buf + count - 1) & PAGE_MASK))
412 "Couldn't DMA map a %d byte buffer\n",
418 count >> 2, 1, 0, 0, 0);
436 dev_err(&c->
pdev->dev,
"timeout waiting for DMA\n");
443 memcpy(this->base + bram_offset, buf, count);
450 unsigned char *buffer,
int offset,
454 const unsigned char *buffer,
455 int offset,
size_t count);
459 #if defined(CONFIG_ARCH_OMAP2) || defined(MULTI_OMAP2)
462 unsigned char *buffer,
int offset,
470 bram_offset = omap2_onenand_bufferram_offset(mtd, area) + area +
offset;
473 ((
void *) buffer >= (
void *) high_memory) || (bram_offset & 3) ||
474 (((
unsigned int) buffer) & 3) || (count < 1024) || (count & 3)) {
485 "Couldn't DMA map a %d byte buffer\n",
491 count / 4, 1, 0, 0, 0);
507 const unsigned char *buffer,
508 int offset,
size_t count)
515 bram_offset = omap2_onenand_bufferram_offset(mtd, area) + area +
offset;
518 ((
void *) buffer >= (
void *) high_memory) || (bram_offset & 3) ||
519 (((
unsigned int) buffer) & 3) || (count < 1024) || (count & 3)) {
530 "Couldn't DMA map a %d byte buffer\n",
536 count / 2, 1, 0, 0, 0);
554 unsigned char *buffer,
int offset,
558 const unsigned char *buffer,
559 int offset,
size_t count);
584 NULL, __adjust_timing);
598 static int omap2_onenand_enable(
struct mtd_info *mtd)
605 dev_err(&c->
pdev->dev,
"can't enable regulator\n");
610 static int omap2_onenand_disable(
struct mtd_info *mtd)
617 dev_err(&c->
pdev->dev,
"can't disable regulator\n");
630 pdata = pdev->
dev.platform_data;
632 dev_err(&pdev->
dev,
"platform data missing\n");
653 dev_err(&pdev->
dev,
"error getting memory resource\n");
661 pdev->
dev.driver->name) ==
NULL) {
662 dev_err(&pdev->
dev,
"Cannot reserve memory region at 0x%08lx, size: 0x%x\n",
670 goto err_release_mem_region;
676 dev_err(&pdev->
dev,
"Onenand platform setup failed: "
685 dev_err(&pdev->
dev,
"Failed to request GPIO%d for "
693 pdev->
dev.driver->name, c)) < 0)
694 goto err_release_gpio;
699 omap2_onenand_dma_cb, (
void *) c,
712 "failed to allocate DMA for OneNAND, "
713 "using PIO instead\n");
718 dev_info(&pdev->
dev,
"initializing on CS%d, phys base 0x%08lx, virtual "
723 c->
mtd.name = dev_name(&pdev->
dev);
727 c->
mtd.dev.parent = &pdev->
dev;
731 this->
wait = omap2_onenand_wait;
744 dev_err(&pdev->
dev,
"Failed to get regulator\n");
746 goto err_release_dma;
748 c->
onenand.enable = omap2_onenand_enable;
749 c->
onenand.disable = omap2_onenand_disable;
756 goto err_release_regulator;
762 goto err_release_onenand;
764 platform_set_drvdata(pdev, c);
770 err_release_regulator:
782 err_release_mem_region:
798 omap2_onenand_shutdown(pdev);
799 platform_set_drvdata(pdev,
NULL);
813 .probe = omap2_onenand_probe,
815 .shutdown = omap2_onenand_shutdown,
822 static int __init omap2_onenand_init(
void)
828 static void __exit omap2_onenand_exit(
void)