diff options
author | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
---|---|---|
committer | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
commit | ada47b5fe13d89735805b566185f4885f5a3f750 (patch) | |
tree | 644b88f8a71896307d71438e9b3af49126ffb22b /drivers/mtd/nand/sh_flctl.c | |
parent | 43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff) | |
parent | 3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff) |
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'drivers/mtd/nand/sh_flctl.c')
-rw-r--r-- | drivers/mtd/nand/sh_flctl.c | 70 |
1 files changed, 50 insertions, 20 deletions
diff --git a/drivers/mtd/nand/sh_flctl.c b/drivers/mtd/nand/sh_flctl.c index 02bef21f2e4b..34752fce0793 100644 --- a/drivers/mtd/nand/sh_flctl.c +++ b/drivers/mtd/nand/sh_flctl.c | |||
@@ -1,10 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | * SuperH FLCTL nand controller | 2 | * SuperH FLCTL nand controller |
3 | * | 3 | * |
4 | * Copyright © 2008 Renesas Solutions Corp. | 4 | * Copyright (c) 2008 Renesas Solutions Corp. |
5 | * Copyright © 2008 Atom Create Engineering Co., Ltd. | 5 | * Copyright (c) 2008 Atom Create Engineering Co., Ltd. |
6 | * | 6 | * |
7 | * Based on fsl_elbc_nand.c, Copyright © 2006-2007 Freescale Semiconductor | 7 | * Based on fsl_elbc_nand.c, Copyright (c) 2006-2007 Freescale Semiconductor |
8 | * | 8 | * |
9 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by | 10 | * it under the terms of the GNU General Public License as published by |
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/delay.h> | 26 | #include <linux/delay.h> |
27 | #include <linux/io.h> | 27 | #include <linux/io.h> |
28 | #include <linux/platform_device.h> | 28 | #include <linux/platform_device.h> |
29 | #include <linux/slab.h> | ||
29 | 30 | ||
30 | #include <linux/mtd/mtd.h> | 31 | #include <linux/mtd/mtd.h> |
31 | #include <linux/mtd/nand.h> | 32 | #include <linux/mtd/nand.h> |
@@ -75,6 +76,11 @@ static void start_translation(struct sh_flctl *flctl) | |||
75 | writeb(TRSTRT, FLTRCR(flctl)); | 76 | writeb(TRSTRT, FLTRCR(flctl)); |
76 | } | 77 | } |
77 | 78 | ||
79 | static void timeout_error(struct sh_flctl *flctl, const char *str) | ||
80 | { | ||
81 | dev_err(&flctl->pdev->dev, "Timeout occured in %s\n", str); | ||
82 | } | ||
83 | |||
78 | static void wait_completion(struct sh_flctl *flctl) | 84 | static void wait_completion(struct sh_flctl *flctl) |
79 | { | 85 | { |
80 | uint32_t timeout = LOOP_TIMEOUT_MAX; | 86 | uint32_t timeout = LOOP_TIMEOUT_MAX; |
@@ -87,7 +93,7 @@ static void wait_completion(struct sh_flctl *flctl) | |||
87 | udelay(1); | 93 | udelay(1); |
88 | } | 94 | } |
89 | 95 | ||
90 | printk(KERN_ERR "wait_completion(): Timeout occured \n"); | 96 | timeout_error(flctl, __func__); |
91 | writeb(0x0, FLTRCR(flctl)); | 97 | writeb(0x0, FLTRCR(flctl)); |
92 | } | 98 | } |
93 | 99 | ||
@@ -100,6 +106,8 @@ static void set_addr(struct mtd_info *mtd, int column, int page_addr) | |||
100 | addr = page_addr; /* ERASE1 */ | 106 | addr = page_addr; /* ERASE1 */ |
101 | } else if (page_addr != -1) { | 107 | } else if (page_addr != -1) { |
102 | /* SEQIN, READ0, etc.. */ | 108 | /* SEQIN, READ0, etc.. */ |
109 | if (flctl->chip.options & NAND_BUSWIDTH_16) | ||
110 | column >>= 1; | ||
103 | if (flctl->page_size) { | 111 | if (flctl->page_size) { |
104 | addr = column & 0x0FFF; | 112 | addr = column & 0x0FFF; |
105 | addr |= (page_addr & 0xff) << 16; | 113 | addr |= (page_addr & 0xff) << 16; |
@@ -132,7 +140,7 @@ static void wait_rfifo_ready(struct sh_flctl *flctl) | |||
132 | return; | 140 | return; |
133 | udelay(1); | 141 | udelay(1); |
134 | } | 142 | } |
135 | printk(KERN_ERR "wait_rfifo_ready(): Timeout occured \n"); | 143 | timeout_error(flctl, __func__); |
136 | } | 144 | } |
137 | 145 | ||
138 | static void wait_wfifo_ready(struct sh_flctl *flctl) | 146 | static void wait_wfifo_ready(struct sh_flctl *flctl) |
@@ -146,7 +154,7 @@ static void wait_wfifo_ready(struct sh_flctl *flctl) | |||
146 | return; | 154 | return; |
147 | udelay(1); | 155 | udelay(1); |
148 | } | 156 | } |
149 | printk(KERN_ERR "wait_wfifo_ready(): Timeout occured \n"); | 157 | timeout_error(flctl, __func__); |
150 | } | 158 | } |
151 | 159 | ||
152 | static int wait_recfifo_ready(struct sh_flctl *flctl, int sector_number) | 160 | static int wait_recfifo_ready(struct sh_flctl *flctl, int sector_number) |
@@ -198,7 +206,7 @@ static int wait_recfifo_ready(struct sh_flctl *flctl, int sector_number) | |||
198 | writel(0, FL4ECCCR(flctl)); | 206 | writel(0, FL4ECCCR(flctl)); |
199 | } | 207 | } |
200 | 208 | ||
201 | printk(KERN_ERR "wait_recfifo_ready(): Timeout occured \n"); | 209 | timeout_error(flctl, __func__); |
202 | return 1; /* timeout */ | 210 | return 1; /* timeout */ |
203 | } | 211 | } |
204 | 212 | ||
@@ -214,7 +222,7 @@ static void wait_wecfifo_ready(struct sh_flctl *flctl) | |||
214 | return; | 222 | return; |
215 | udelay(1); | 223 | udelay(1); |
216 | } | 224 | } |
217 | printk(KERN_ERR "wait_wecfifo_ready(): Timeout occured \n"); | 225 | timeout_error(flctl, __func__); |
218 | } | 226 | } |
219 | 227 | ||
220 | static void read_datareg(struct sh_flctl *flctl, int offset) | 228 | static void read_datareg(struct sh_flctl *flctl, int offset) |
@@ -275,7 +283,7 @@ static void write_fiforeg(struct sh_flctl *flctl, int rlen, int offset) | |||
275 | static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_val) | 283 | static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_val) |
276 | { | 284 | { |
277 | struct sh_flctl *flctl = mtd_to_flctl(mtd); | 285 | struct sh_flctl *flctl = mtd_to_flctl(mtd); |
278 | uint32_t flcmncr_val = readl(FLCMNCR(flctl)); | 286 | uint32_t flcmncr_val = readl(FLCMNCR(flctl)) & ~SEL_16BIT; |
279 | uint32_t flcmdcr_val, addr_len_bytes = 0; | 287 | uint32_t flcmdcr_val, addr_len_bytes = 0; |
280 | 288 | ||
281 | /* Set SNAND bit if page size is 2048byte */ | 289 | /* Set SNAND bit if page size is 2048byte */ |
@@ -297,6 +305,8 @@ static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_va | |||
297 | case NAND_CMD_READOOB: | 305 | case NAND_CMD_READOOB: |
298 | addr_len_bytes = flctl->rw_ADRCNT; | 306 | addr_len_bytes = flctl->rw_ADRCNT; |
299 | flcmdcr_val |= CDSRC_E; | 307 | flcmdcr_val |= CDSRC_E; |
308 | if (flctl->chip.options & NAND_BUSWIDTH_16) | ||
309 | flcmncr_val |= SEL_16BIT; | ||
300 | break; | 310 | break; |
301 | case NAND_CMD_SEQIN: | 311 | case NAND_CMD_SEQIN: |
302 | /* This case is that cmd is READ0 or READ1 or READ00 */ | 312 | /* This case is that cmd is READ0 or READ1 or READ00 */ |
@@ -305,6 +315,8 @@ static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_va | |||
305 | case NAND_CMD_PAGEPROG: | 315 | case NAND_CMD_PAGEPROG: |
306 | addr_len_bytes = flctl->rw_ADRCNT; | 316 | addr_len_bytes = flctl->rw_ADRCNT; |
307 | flcmdcr_val |= DOCMD2_E | CDSRC_E | SELRW; | 317 | flcmdcr_val |= DOCMD2_E | CDSRC_E | SELRW; |
318 | if (flctl->chip.options & NAND_BUSWIDTH_16) | ||
319 | flcmncr_val |= SEL_16BIT; | ||
308 | break; | 320 | break; |
309 | case NAND_CMD_READID: | 321 | case NAND_CMD_READID: |
310 | flcmncr_val &= ~SNAND_E; | 322 | flcmncr_val &= ~SNAND_E; |
@@ -523,6 +535,8 @@ static void flctl_cmdfunc(struct mtd_info *mtd, unsigned int command, | |||
523 | set_addr(mtd, 0, page_addr); | 535 | set_addr(mtd, 0, page_addr); |
524 | 536 | ||
525 | flctl->read_bytes = mtd->writesize + mtd->oobsize; | 537 | flctl->read_bytes = mtd->writesize + mtd->oobsize; |
538 | if (flctl->chip.options & NAND_BUSWIDTH_16) | ||
539 | column >>= 1; | ||
526 | flctl->index += column; | 540 | flctl->index += column; |
527 | goto read_normal_exit; | 541 | goto read_normal_exit; |
528 | 542 | ||
@@ -686,6 +700,18 @@ static uint8_t flctl_read_byte(struct mtd_info *mtd) | |||
686 | return data; | 700 | return data; |
687 | } | 701 | } |
688 | 702 | ||
703 | static uint16_t flctl_read_word(struct mtd_info *mtd) | ||
704 | { | ||
705 | struct sh_flctl *flctl = mtd_to_flctl(mtd); | ||
706 | int index = flctl->index; | ||
707 | uint16_t data; | ||
708 | uint16_t *buf = (uint16_t *)&flctl->done_buff[index]; | ||
709 | |||
710 | data = *buf; | ||
711 | flctl->index += 2; | ||
712 | return data; | ||
713 | } | ||
714 | |||
689 | static void flctl_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) | 715 | static void flctl_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) |
690 | { | 716 | { |
691 | int i; | 717 | int i; |
@@ -769,38 +795,36 @@ static int flctl_chip_init_tail(struct mtd_info *mtd) | |||
769 | return 0; | 795 | return 0; |
770 | } | 796 | } |
771 | 797 | ||
772 | static int __init flctl_probe(struct platform_device *pdev) | 798 | static int __devinit flctl_probe(struct platform_device *pdev) |
773 | { | 799 | { |
774 | struct resource *res; | 800 | struct resource *res; |
775 | struct sh_flctl *flctl; | 801 | struct sh_flctl *flctl; |
776 | struct mtd_info *flctl_mtd; | 802 | struct mtd_info *flctl_mtd; |
777 | struct nand_chip *nand; | 803 | struct nand_chip *nand; |
778 | struct sh_flctl_platform_data *pdata; | 804 | struct sh_flctl_platform_data *pdata; |
779 | int ret; | 805 | int ret = -ENXIO; |
780 | 806 | ||
781 | pdata = pdev->dev.platform_data; | 807 | pdata = pdev->dev.platform_data; |
782 | if (pdata == NULL) { | 808 | if (pdata == NULL) { |
783 | printk(KERN_ERR "sh_flctl platform_data not found.\n"); | 809 | dev_err(&pdev->dev, "no platform data defined\n"); |
784 | return -ENODEV; | 810 | return -EINVAL; |
785 | } | 811 | } |
786 | 812 | ||
787 | flctl = kzalloc(sizeof(struct sh_flctl), GFP_KERNEL); | 813 | flctl = kzalloc(sizeof(struct sh_flctl), GFP_KERNEL); |
788 | if (!flctl) { | 814 | if (!flctl) { |
789 | printk(KERN_ERR "Unable to allocate NAND MTD dev structure.\n"); | 815 | dev_err(&pdev->dev, "failed to allocate driver data\n"); |
790 | return -ENOMEM; | 816 | return -ENOMEM; |
791 | } | 817 | } |
792 | 818 | ||
793 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 819 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
794 | if (!res) { | 820 | if (!res) { |
795 | printk(KERN_ERR "%s: resource not found.\n", __func__); | 821 | dev_err(&pdev->dev, "failed to get I/O memory\n"); |
796 | ret = -ENODEV; | ||
797 | goto err; | 822 | goto err; |
798 | } | 823 | } |
799 | 824 | ||
800 | flctl->reg = ioremap(res->start, res->end - res->start + 1); | 825 | flctl->reg = ioremap(res->start, resource_size(res)); |
801 | if (flctl->reg == NULL) { | 826 | if (flctl->reg == NULL) { |
802 | printk(KERN_ERR "%s: ioremap error.\n", __func__); | 827 | dev_err(&pdev->dev, "failed to remap I/O memory\n"); |
803 | ret = -ENOMEM; | ||
804 | goto err; | 828 | goto err; |
805 | } | 829 | } |
806 | 830 | ||
@@ -808,6 +832,7 @@ static int __init flctl_probe(struct platform_device *pdev) | |||
808 | flctl_mtd = &flctl->mtd; | 832 | flctl_mtd = &flctl->mtd; |
809 | nand = &flctl->chip; | 833 | nand = &flctl->chip; |
810 | flctl_mtd->priv = nand; | 834 | flctl_mtd->priv = nand; |
835 | flctl->pdev = pdev; | ||
811 | flctl->hwecc = pdata->has_hwecc; | 836 | flctl->hwecc = pdata->has_hwecc; |
812 | 837 | ||
813 | flctl_register_init(flctl, pdata->flcmncr_val); | 838 | flctl_register_init(flctl, pdata->flcmncr_val); |
@@ -825,6 +850,11 @@ static int __init flctl_probe(struct platform_device *pdev) | |||
825 | nand->select_chip = flctl_select_chip; | 850 | nand->select_chip = flctl_select_chip; |
826 | nand->cmdfunc = flctl_cmdfunc; | 851 | nand->cmdfunc = flctl_cmdfunc; |
827 | 852 | ||
853 | if (pdata->flcmncr_val & SEL_16BIT) { | ||
854 | nand->options |= NAND_BUSWIDTH_16; | ||
855 | nand->read_word = flctl_read_word; | ||
856 | } | ||
857 | |||
828 | ret = nand_scan_ident(flctl_mtd, 1); | 858 | ret = nand_scan_ident(flctl_mtd, 1); |
829 | if (ret) | 859 | if (ret) |
830 | goto err; | 860 | goto err; |
@@ -846,7 +876,7 @@ err: | |||
846 | return ret; | 876 | return ret; |
847 | } | 877 | } |
848 | 878 | ||
849 | static int __exit flctl_remove(struct platform_device *pdev) | 879 | static int __devexit flctl_remove(struct platform_device *pdev) |
850 | { | 880 | { |
851 | struct sh_flctl *flctl = platform_get_drvdata(pdev); | 881 | struct sh_flctl *flctl = platform_get_drvdata(pdev); |
852 | 882 | ||