aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/nand/pxa3xx_nand.c
diff options
context:
space:
mode:
authorLei Wen <leiwen@marvell.com>2010-08-17 05:25:57 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2010-10-24 18:39:28 -0400
commit18c81b1828f8c4bdd01dd24f4015604a17ca0bb8 (patch)
treecfd6f016a49ba016fb40bb8313b37d2b1b534ac6 /drivers/mtd/nand/pxa3xx_nand.c
parent227a886c7ead6420465abfd1242f449895b2c332 (diff)
mtd: pxa3xx_nand: remove the flash info in driver structure
After probe, all info already transfer to driver structure. There is no need to keep the original flash info. So that we could safely free the flash info in memory, which may grows larger when more flash is suported. Signed-off-by: Lei Wen <leiwen@marvell.com> Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com> Acked-by: Eric Miao <eric.y.miao@gmail.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd/nand/pxa3xx_nand.c')
-rw-r--r--drivers/mtd/nand/pxa3xx_nand.c115
1 files changed, 43 insertions, 72 deletions
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index 621fa68189fd..cafd8e4946bc 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -117,7 +117,7 @@ struct pxa3xx_nand_info {
117 struct nand_chip nand_chip; 117 struct nand_chip nand_chip;
118 118
119 struct platform_device *pdev; 119 struct platform_device *pdev;
120 const struct pxa3xx_nand_flash *flash_info; 120 struct pxa3xx_nand_cmdset *cmdset;
121 121
122 struct clk *clk; 122 struct clk *clk;
123 void __iomem *mmio_base; 123 void __iomem *mmio_base;
@@ -131,6 +131,7 @@ struct pxa3xx_nand_info {
131 int drcmr_cmd; 131 int drcmr_cmd;
132 132
133 unsigned char *data_buff; 133 unsigned char *data_buff;
134 unsigned char *oob_buff;
134 dma_addr_t data_buff_phys; 135 dma_addr_t data_buff_phys;
135 size_t data_buff_size; 136 size_t data_buff_size;
136 int data_dma_ch; 137 int data_dma_ch;
@@ -149,7 +150,8 @@ struct pxa3xx_nand_info {
149 int use_ecc; /* use HW ECC ? */ 150 int use_ecc; /* use HW ECC ? */
150 int use_dma; /* use DMA ? */ 151 int use_dma; /* use DMA ? */
151 152
152 size_t data_size; /* data size in FIFO */ 153 unsigned int page_size; /* page size of attached chip */
154 unsigned int data_size; /* data size in FIFO */
153 int retcode; 155 int retcode;
154 struct completion cmd_complete; 156 struct completion cmd_complete;
155 157
@@ -158,6 +160,10 @@ struct pxa3xx_nand_info {
158 uint32_t ndcb1; 160 uint32_t ndcb1;
159 uint32_t ndcb2; 161 uint32_t ndcb2;
160 162
163 /* timing calcuted from setting */
164 uint32_t ndtr0cs0;
165 uint32_t ndtr1cs0;
166
161 /* calculated from pxa3xx_nand_flash data */ 167 /* calculated from pxa3xx_nand_flash data */
162 size_t oob_size; 168 size_t oob_size;
163 size_t read_id_bytes; 169 size_t read_id_bytes;
@@ -174,8 +180,6 @@ MODULE_PARM_DESC(use_dma, "enable DMA for data transfering to/from NAND HW");
174 * Default NAND flash controller configuration setup by the 180 * Default NAND flash controller configuration setup by the
175 * bootloader. This configuration is used only when pdata->keep_config is set 181 * bootloader. This configuration is used only when pdata->keep_config is set
176 */ 182 */
177static struct pxa3xx_nand_timing default_timing;
178static struct pxa3xx_nand_flash default_flash;
179static struct pxa3xx_nand_cmdset default_cmdset = { 183static struct pxa3xx_nand_cmdset default_cmdset = {
180 .read1 = 0x3000, 184 .read1 = 0x3000,
181 .read2 = 0x0050, 185 .read2 = 0x0050,
@@ -222,23 +226,9 @@ static struct pxa3xx_nand_flash builtin_flash_types[] = {
222#define NDTR1_tWHR(c) (min((c), 15) << 4) 226#define NDTR1_tWHR(c) (min((c), 15) << 4)
223#define NDTR1_tAR(c) (min((c), 15) << 0) 227#define NDTR1_tAR(c) (min((c), 15) << 0)
224 228
225#define tCH_NDTR0(r) (((r) >> 19) & 0x7)
226#define tCS_NDTR0(r) (((r) >> 16) & 0x7)
227#define tWH_NDTR0(r) (((r) >> 11) & 0x7)
228#define tWP_NDTR0(r) (((r) >> 8) & 0x7)
229#define tRH_NDTR0(r) (((r) >> 3) & 0x7)
230#define tRP_NDTR0(r) (((r) >> 0) & 0x7)
231
232#define tR_NDTR1(r) (((r) >> 16) & 0xffff)
233#define tWHR_NDTR1(r) (((r) >> 4) & 0xf)
234#define tAR_NDTR1(r) (((r) >> 0) & 0xf)
235
236/* convert nano-seconds to nand flash controller clock cycles */ 229/* convert nano-seconds to nand flash controller clock cycles */
237#define ns2cycle(ns, clk) (int)((ns) * (clk / 1000000) / 1000) 230#define ns2cycle(ns, clk) (int)((ns) * (clk / 1000000) / 1000)
238 231
239/* convert nand flash controller clock cycles to nano-seconds */
240#define cycle2ns(c, clk) ((((c) + 1) * 1000000 + clk / 500) / (clk / 1000))
241
242static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info, 232static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info,
243 const struct pxa3xx_nand_timing *t) 233 const struct pxa3xx_nand_timing *t)
244{ 234{
@@ -256,6 +246,8 @@ static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info,
256 NDTR1_tWHR(ns2cycle(t->tWHR, nand_clk)) | 246 NDTR1_tWHR(ns2cycle(t->tWHR, nand_clk)) |
257 NDTR1_tAR(ns2cycle(t->tAR, nand_clk)); 247 NDTR1_tAR(ns2cycle(t->tAR, nand_clk));
258 248
249 info->ndtr0cs0 = ndtr0;
250 info->ndtr1cs0 = ndtr1;
259 nand_writel(info, NDTR0CS0, ndtr0); 251 nand_writel(info, NDTR0CS0, ndtr0);
260 nand_writel(info, NDTR1CS0, ndtr1); 252 nand_writel(info, NDTR1CS0, ndtr1);
261} 253}
@@ -279,23 +271,24 @@ static int wait_for_event(struct pxa3xx_nand_info *info, uint32_t event)
279 return -ETIMEDOUT; 271 return -ETIMEDOUT;
280} 272}
281 273
282static int prepare_read_prog_cmd(struct pxa3xx_nand_info *info, 274static void pxa3xx_set_datasize(struct pxa3xx_nand_info *info)
283 uint16_t cmd, int column, int page_addr)
284{ 275{
285 const struct pxa3xx_nand_flash *f = info->flash_info;
286 const struct pxa3xx_nand_cmdset *cmdset = f->cmdset;
287
288 /* calculate data size */ 276 /* calculate data size */
289 switch (f->page_size) { 277 switch (info->page_size) {
290 case 2048: 278 case 2048:
291 info->data_size = (info->use_ecc) ? 2088 : 2112; 279 info->data_size = (info->use_ecc) ? 2088 : 2112;
292 break; 280 break;
293 case 512: 281 case 512:
294 info->data_size = (info->use_ecc) ? 520 : 528; 282 info->data_size = (info->use_ecc) ? 520 : 528;
295 break; 283 break;
296 default:
297 return -EINVAL;
298 } 284 }
285}
286
287static int prepare_read_prog_cmd(struct pxa3xx_nand_info *info,
288 uint16_t cmd, int column, int page_addr)
289{
290 const struct pxa3xx_nand_cmdset *cmdset = info->cmdset;
291 pxa3xx_set_datasize(info);
299 292
300 /* generate values for NDCBx registers */ 293 /* generate values for NDCBx registers */
301 info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0); 294 info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0);
@@ -334,7 +327,7 @@ static int prepare_erase_cmd(struct pxa3xx_nand_info *info,
334 327
335static int prepare_other_cmd(struct pxa3xx_nand_info *info, uint16_t cmd) 328static int prepare_other_cmd(struct pxa3xx_nand_info *info, uint16_t cmd)
336{ 329{
337 const struct pxa3xx_nand_cmdset *cmdset = info->flash_info->cmdset; 330 const struct pxa3xx_nand_cmdset *cmdset = info->cmdset;
338 331
339 info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0); 332 info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0);
340 info->ndcb1 = 0; 333 info->ndcb1 = 0;
@@ -571,8 +564,7 @@ static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
571 int column, int page_addr) 564 int column, int page_addr)
572{ 565{
573 struct pxa3xx_nand_info *info = mtd->priv; 566 struct pxa3xx_nand_info *info = mtd->priv;
574 const struct pxa3xx_nand_flash *flash_info = info->flash_info; 567 const struct pxa3xx_nand_cmdset *cmdset = info->cmdset;
575 const struct pxa3xx_nand_cmdset *cmdset = flash_info->cmdset;
576 int ret; 568 int ret;
577 569
578 info->use_dma = (use_dma) ? 1 : 0; 570 info->use_dma = (use_dma) ? 1 : 0;
@@ -796,8 +788,7 @@ static int pxa3xx_nand_ecc_correct(struct mtd_info *mtd,
796 788
797static int __readid(struct pxa3xx_nand_info *info, uint32_t *id) 789static int __readid(struct pxa3xx_nand_info *info, uint32_t *id)
798{ 790{
799 const struct pxa3xx_nand_flash *f = info->flash_info; 791 const struct pxa3xx_nand_cmdset *cmdset = info->cmdset;
800 const struct pxa3xx_nand_cmdset *cmdset = f->cmdset;
801 uint32_t ndcr; 792 uint32_t ndcr;
802 uint8_t id_buff[8]; 793 uint8_t id_buff[8];
803 794
@@ -839,6 +830,9 @@ static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info,
839 return -EINVAL; 830 return -EINVAL;
840 831
841 /* calculate flash information */ 832 /* calculate flash information */
833 info->cmdset = f->cmdset;
834 info->page_size = f->page_size;
835 info->oob_buff = info->data_buff + f->page_size;
842 info->oob_size = (f->page_size == 2048) ? 64 : 16; 836 info->oob_size = (f->page_size == 2048) ? 64 : 16;
843 info->read_id_bytes = (f->page_size == 2048) ? 4 : 2; 837 info->read_id_bytes = (f->page_size == 2048) ? 4 : 2;
844 838
@@ -863,44 +857,20 @@ static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info,
863 info->reg_ndcr = ndcr; 857 info->reg_ndcr = ndcr;
864 858
865 pxa3xx_nand_set_timing(info, f->timing); 859 pxa3xx_nand_set_timing(info, f->timing);
866 info->flash_info = f;
867 return 0; 860 return 0;
868} 861}
869 862
870static void pxa3xx_nand_detect_timing(struct pxa3xx_nand_info *info,
871 struct pxa3xx_nand_timing *t)
872{
873 unsigned long nand_clk = clk_get_rate(info->clk);
874 uint32_t ndtr0 = nand_readl(info, NDTR0CS0);
875 uint32_t ndtr1 = nand_readl(info, NDTR1CS0);
876
877 t->tCH = cycle2ns(tCH_NDTR0(ndtr0), nand_clk);
878 t->tCS = cycle2ns(tCS_NDTR0(ndtr0), nand_clk);
879 t->tWH = cycle2ns(tWH_NDTR0(ndtr0), nand_clk);
880 t->tWP = cycle2ns(tWP_NDTR0(ndtr0), nand_clk);
881 t->tRH = cycle2ns(tRH_NDTR0(ndtr0), nand_clk);
882 t->tRP = cycle2ns(tRP_NDTR0(ndtr0), nand_clk);
883
884 t->tR = cycle2ns(tR_NDTR1(ndtr1), nand_clk);
885 t->tWHR = cycle2ns(tWHR_NDTR1(ndtr1), nand_clk);
886 t->tAR = cycle2ns(tAR_NDTR1(ndtr1), nand_clk);
887}
888
889static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info) 863static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info)
890{ 864{
891 uint32_t ndcr = nand_readl(info, NDCR); 865 uint32_t ndcr = nand_readl(info, NDCR);
892 struct nand_flash_dev *type = NULL; 866 struct nand_flash_dev *type = NULL;
893 uint32_t id = -1; 867 uint32_t id = -1, page_per_block, num_blocks;
894 int i; 868 int i;
895 869
896 default_flash.page_per_block = ndcr & NDCR_PG_PER_BLK ? 64 : 32; 870 page_per_block = ndcr & NDCR_PG_PER_BLK ? 64 : 32;
897 default_flash.page_size = ndcr & NDCR_PAGE_SZ ? 2048 : 512; 871 info->page_size = ndcr & NDCR_PAGE_SZ ? 2048 : 512;
898 default_flash.flash_width = ndcr & NDCR_DWIDTH_M ? 16 : 8;
899 default_flash.dfc_width = ndcr & NDCR_DWIDTH_C ? 16 : 8;
900
901 /* set info fields needed to __readid */ 872 /* set info fields needed to __readid */
902 info->flash_info = &default_flash; 873 info->read_id_bytes = (info->page_size == 2048) ? 4 : 2;
903 info->read_id_bytes = (default_flash.page_size == 2048) ? 4 : 2;
904 info->reg_ndcr = ndcr; 874 info->reg_ndcr = ndcr;
905 875
906 if (__readid(info, &id)) 876 if (__readid(info, &id))
@@ -919,22 +889,22 @@ static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info)
919 return -ENODEV; 889 return -ENODEV;
920 890
921 /* fill the missing flash information */ 891 /* fill the missing flash information */
922 i = __ffs(default_flash.page_per_block * default_flash.page_size); 892 i = __ffs(page_per_block * info->page_size);
923 default_flash.num_blocks = type->chipsize << (20 - i); 893 num_blocks = type->chipsize << (20 - i);
924 894
925 info->oob_size = (default_flash.page_size == 2048) ? 64 : 16; 895 info->oob_size = (info->page_size == 2048) ? 64 : 16;
926 896
927 /* calculate addressing information */ 897 /* calculate addressing information */
928 info->col_addr_cycles = (default_flash.page_size == 2048) ? 2 : 1; 898 info->col_addr_cycles = (info->page_size == 2048) ? 2 : 1;
929 899
930 if (default_flash.num_blocks * default_flash.page_per_block > 65536) 900 if (num_blocks * page_per_block > 65536)
931 info->row_addr_cycles = 3; 901 info->row_addr_cycles = 3;
932 else 902 else
933 info->row_addr_cycles = 2; 903 info->row_addr_cycles = 2;
934 904
935 pxa3xx_nand_detect_timing(info, &default_timing); 905 info->ndtr0cs0 = nand_readl(info, NDTR0CS0);
936 default_flash.timing = &default_timing; 906 info->ndtr1cs0 = nand_readl(info, NDTR1CS0);
937 default_flash.cmdset = &default_cmdset; 907 info->cmdset = &default_cmdset;
938 908
939 return 0; 909 return 0;
940} 910}
@@ -1035,10 +1005,9 @@ static struct nand_ecclayout hw_largepage_ecclayout = {
1035static void pxa3xx_nand_init_mtd(struct mtd_info *mtd, 1005static void pxa3xx_nand_init_mtd(struct mtd_info *mtd,
1036 struct pxa3xx_nand_info *info) 1006 struct pxa3xx_nand_info *info)
1037{ 1007{
1038 const struct pxa3xx_nand_flash *f = info->flash_info;
1039 struct nand_chip *this = &info->nand_chip; 1008 struct nand_chip *this = &info->nand_chip;
1040 1009
1041 this->options = (f->flash_width == 16) ? NAND_BUSWIDTH_16: 0; 1010 this->options = (info->reg_ndcr & NDCR_DWIDTH_C) ? NAND_BUSWIDTH_16: 0;
1042 1011
1043 this->waitfunc = pxa3xx_nand_waitfunc; 1012 this->waitfunc = pxa3xx_nand_waitfunc;
1044 this->select_chip = pxa3xx_nand_select_chip; 1013 this->select_chip = pxa3xx_nand_select_chip;
@@ -1054,9 +1023,9 @@ static void pxa3xx_nand_init_mtd(struct mtd_info *mtd,
1054 this->ecc.hwctl = pxa3xx_nand_ecc_hwctl; 1023 this->ecc.hwctl = pxa3xx_nand_ecc_hwctl;
1055 this->ecc.calculate = pxa3xx_nand_ecc_calculate; 1024 this->ecc.calculate = pxa3xx_nand_ecc_calculate;
1056 this->ecc.correct = pxa3xx_nand_ecc_correct; 1025 this->ecc.correct = pxa3xx_nand_ecc_correct;
1057 this->ecc.size = f->page_size; 1026 this->ecc.size = info->page_size;
1058 1027
1059 if (f->page_size == 2048) 1028 if (info->page_size == 2048)
1060 this->ecc.layout = &hw_largepage_ecclayout; 1029 this->ecc.layout = &hw_largepage_ecclayout;
1061 else 1030 else
1062 this->ecc.layout = &hw_smallpage_ecclayout; 1031 this->ecc.layout = &hw_smallpage_ecclayout;
@@ -1269,9 +1238,11 @@ static int pxa3xx_nand_resume(struct platform_device *pdev)
1269 struct mtd_info *mtd = (struct mtd_info *)platform_get_drvdata(pdev); 1238 struct mtd_info *mtd = (struct mtd_info *)platform_get_drvdata(pdev);
1270 struct pxa3xx_nand_info *info = mtd->priv; 1239 struct pxa3xx_nand_info *info = mtd->priv;
1271 1240
1241 nand_writel(info, NDTR0CS0, info->ndtr0cs0);
1242 nand_writel(info, NDTR1CS0, info->ndtr1cs0);
1272 clk_enable(info->clk); 1243 clk_enable(info->clk);
1273 1244
1274 return pxa3xx_nand_config_flash(info, info->flash_info); 1245 return 0;
1275} 1246}
1276#else 1247#else
1277#define pxa3xx_nand_suspend NULL 1248#define pxa3xx_nand_suspend NULL