aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/nand/pxa3xx_nand.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/nand/pxa3xx_nand.c')
-rw-r--r--drivers/mtd/nand/pxa3xx_nand.c119
1 files changed, 115 insertions, 4 deletions
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index 61b69cc40009..30a8ce6d3e69 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -170,7 +170,13 @@ static int use_dma = 1;
170module_param(use_dma, bool, 0444); 170module_param(use_dma, bool, 0444);
171MODULE_PARM_DESC(use_dma, "enable DMA for data transfering to/from NAND HW"); 171MODULE_PARM_DESC(use_dma, "enable DMA for data transfering to/from NAND HW");
172 172
173#ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN 173/*
174 * Default NAND flash controller configuration setup by the
175 * bootloader. This configuration is used only when pdata->keep_config is set
176 */
177static struct pxa3xx_nand_timing default_timing;
178static struct pxa3xx_nand_flash default_flash;
179
174static struct pxa3xx_nand_cmdset smallpage_cmdset = { 180static struct pxa3xx_nand_cmdset smallpage_cmdset = {
175 .read1 = 0x0000, 181 .read1 = 0x0000,
176 .read2 = 0x0050, 182 .read2 = 0x0050,
@@ -197,6 +203,7 @@ static struct pxa3xx_nand_cmdset largepage_cmdset = {
197 .lock_status = 0x007A, 203 .lock_status = 0x007A,
198}; 204};
199 205
206#ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN
200static struct pxa3xx_nand_timing samsung512MbX16_timing = { 207static struct pxa3xx_nand_timing samsung512MbX16_timing = {
201 .tCH = 10, 208 .tCH = 10,
202 .tCS = 0, 209 .tCS = 0,
@@ -296,9 +303,23 @@ static struct pxa3xx_nand_flash *builtin_flash_types[] = {
296#define NDTR1_tWHR(c) (min((c), 15) << 4) 303#define NDTR1_tWHR(c) (min((c), 15) << 4)
297#define NDTR1_tAR(c) (min((c), 15) << 0) 304#define NDTR1_tAR(c) (min((c), 15) << 0)
298 305
306#define tCH_NDTR0(r) (((r) >> 19) & 0x7)
307#define tCS_NDTR0(r) (((r) >> 16) & 0x7)
308#define tWH_NDTR0(r) (((r) >> 11) & 0x7)
309#define tWP_NDTR0(r) (((r) >> 8) & 0x7)
310#define tRH_NDTR0(r) (((r) >> 3) & 0x7)
311#define tRP_NDTR0(r) (((r) >> 0) & 0x7)
312
313#define tR_NDTR1(r) (((r) >> 16) & 0xffff)
314#define tWHR_NDTR1(r) (((r) >> 4) & 0xf)
315#define tAR_NDTR1(r) (((r) >> 0) & 0xf)
316
299/* convert nano-seconds to nand flash controller clock cycles */ 317/* convert nano-seconds to nand flash controller clock cycles */
300#define ns2cycle(ns, clk) (int)(((ns) * (clk / 1000000) / 1000) - 1) 318#define ns2cycle(ns, clk) (int)(((ns) * (clk / 1000000) / 1000) - 1)
301 319
320/* convert nand flash controller clock cycles to nano-seconds */
321#define cycle2ns(c, clk) ((((c) + 1) * 1000000 + clk / 500) / (clk / 1000))
322
302static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info, 323static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info,
303 const struct pxa3xx_nand_timing *t) 324 const struct pxa3xx_nand_timing *t)
304{ 325{
@@ -920,6 +941,82 @@ static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info,
920 return 0; 941 return 0;
921} 942}
922 943
944static void pxa3xx_nand_detect_timing(struct pxa3xx_nand_info *info,
945 struct pxa3xx_nand_timing *t)
946{
947 unsigned long nand_clk = clk_get_rate(info->clk);
948 uint32_t ndtr0 = nand_readl(info, NDTR0CS0);
949 uint32_t ndtr1 = nand_readl(info, NDTR1CS0);
950
951 t->tCH = cycle2ns(tCH_NDTR0(ndtr0), nand_clk);
952 t->tCS = cycle2ns(tCS_NDTR0(ndtr0), nand_clk);
953 t->tWH = cycle2ns(tWH_NDTR0(ndtr0), nand_clk);
954 t->tWP = cycle2ns(tWP_NDTR0(ndtr0), nand_clk);
955 t->tRH = cycle2ns(tRH_NDTR0(ndtr0), nand_clk);
956 t->tRP = cycle2ns(tRP_NDTR0(ndtr0), nand_clk);
957
958 t->tR = cycle2ns(tR_NDTR1(ndtr1), nand_clk);
959 t->tWHR = cycle2ns(tWHR_NDTR1(ndtr1), nand_clk);
960 t->tAR = cycle2ns(tAR_NDTR1(ndtr1), nand_clk);
961}
962
963static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info)
964{
965 uint32_t ndcr = nand_readl(info, NDCR);
966 struct nand_flash_dev *type = NULL;
967 uint32_t id = -1;
968 int i;
969
970 default_flash.page_per_block = ndcr & NDCR_PG_PER_BLK ? 64 : 32;
971 default_flash.page_size = ndcr & NDCR_PAGE_SZ ? 2048 : 512;
972 default_flash.flash_width = ndcr & NDCR_DWIDTH_M ? 16 : 8;
973 default_flash.dfc_width = ndcr & NDCR_DWIDTH_C ? 16 : 8;
974
975 if (default_flash.page_size == 2048)
976 default_flash.cmdset = &largepage_cmdset;
977 else
978 default_flash.cmdset = &smallpage_cmdset;
979
980 /* set info fields needed to __readid */
981 info->flash_info = &default_flash;
982 info->read_id_bytes = (default_flash.page_size == 2048) ? 4 : 2;
983 info->reg_ndcr = ndcr;
984
985 if (__readid(info, &id))
986 return -ENODEV;
987
988 /* Lookup the flash id */
989 id = (id >> 8) & 0xff; /* device id is byte 2 */
990 for (i = 0; nand_flash_ids[i].name != NULL; i++) {
991 if (id == nand_flash_ids[i].id) {
992 type = &nand_flash_ids[i];
993 break;
994 }
995 }
996
997 if (!type)
998 return -ENODEV;
999
1000 /* fill the missing flash information */
1001 i = __ffs(default_flash.page_per_block * default_flash.page_size);
1002 default_flash.num_blocks = type->chipsize << (20 - i);
1003
1004 info->oob_size = (default_flash.page_size == 2048) ? 64 : 16;
1005
1006 /* calculate addressing information */
1007 info->col_addr_cycles = (default_flash.page_size == 2048) ? 2 : 1;
1008
1009 if (default_flash.num_blocks * default_flash.page_per_block > 65536)
1010 info->row_addr_cycles = 3;
1011 else
1012 info->row_addr_cycles = 2;
1013
1014 pxa3xx_nand_detect_timing(info, &default_timing);
1015 default_flash.timing = &default_timing;
1016
1017 return 0;
1018}
1019
923static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info, 1020static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info,
924 const struct pxa3xx_nand_platform_data *pdata) 1021 const struct pxa3xx_nand_platform_data *pdata)
925{ 1022{
@@ -927,6 +1024,10 @@ static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info,
927 uint32_t id = -1; 1024 uint32_t id = -1;
928 int i; 1025 int i;
929 1026
1027 if (pdata->keep_config)
1028 if (pxa3xx_nand_detect_config(info) == 0)
1029 return 0;
1030
930 for (i = 0; i<pdata->num_flash; ++i) { 1031 for (i = 0; i<pdata->num_flash; ++i) {
931 f = pdata->flash + i; 1032 f = pdata->flash + i;
932 1033
@@ -1078,6 +1179,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
1078 1179
1079 this = &info->nand_chip; 1180 this = &info->nand_chip;
1080 mtd->priv = info; 1181 mtd->priv = info;
1182 mtd->owner = THIS_MODULE;
1081 1183
1082 info->clk = clk_get(&pdev->dev, NULL); 1184 info->clk = clk_get(&pdev->dev, NULL);
1083 if (IS_ERR(info->clk)) { 1185 if (IS_ERR(info->clk)) {
@@ -1117,14 +1219,14 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
1117 goto fail_put_clk; 1219 goto fail_put_clk;
1118 } 1220 }
1119 1221
1120 r = request_mem_region(r->start, r->end - r->start + 1, pdev->name); 1222 r = request_mem_region(r->start, resource_size(r), pdev->name);
1121 if (r == NULL) { 1223 if (r == NULL) {
1122 dev_err(&pdev->dev, "failed to request memory resource\n"); 1224 dev_err(&pdev->dev, "failed to request memory resource\n");
1123 ret = -EBUSY; 1225 ret = -EBUSY;
1124 goto fail_put_clk; 1226 goto fail_put_clk;
1125 } 1227 }
1126 1228
1127 info->mmio_base = ioremap(r->start, r->end - r->start + 1); 1229 info->mmio_base = ioremap(r->start, resource_size(r));
1128 if (info->mmio_base == NULL) { 1230 if (info->mmio_base == NULL) {
1129 dev_err(&pdev->dev, "ioremap() failed\n"); 1231 dev_err(&pdev->dev, "ioremap() failed\n");
1130 ret = -ENODEV; 1232 ret = -ENODEV;
@@ -1173,7 +1275,7 @@ fail_free_buf:
1173fail_free_io: 1275fail_free_io:
1174 iounmap(info->mmio_base); 1276 iounmap(info->mmio_base);
1175fail_free_res: 1277fail_free_res:
1176 release_mem_region(r->start, r->end - r->start + 1); 1278 release_mem_region(r->start, resource_size(r));
1177fail_put_clk: 1279fail_put_clk:
1178 clk_disable(info->clk); 1280 clk_disable(info->clk);
1179 clk_put(info->clk); 1281 clk_put(info->clk);
@@ -1186,6 +1288,7 @@ static int pxa3xx_nand_remove(struct platform_device *pdev)
1186{ 1288{
1187 struct mtd_info *mtd = platform_get_drvdata(pdev); 1289 struct mtd_info *mtd = platform_get_drvdata(pdev);
1188 struct pxa3xx_nand_info *info = mtd->priv; 1290 struct pxa3xx_nand_info *info = mtd->priv;
1291 struct resource *r;
1189 1292
1190 platform_set_drvdata(pdev, NULL); 1293 platform_set_drvdata(pdev, NULL);
1191 1294
@@ -1198,6 +1301,14 @@ static int pxa3xx_nand_remove(struct platform_device *pdev)
1198 info->data_buff, info->data_buff_phys); 1301 info->data_buff, info->data_buff_phys);
1199 } else 1302 } else
1200 kfree(info->data_buff); 1303 kfree(info->data_buff);
1304
1305 iounmap(info->mmio_base);
1306 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1307 release_mem_region(r->start, resource_size(r));
1308
1309 clk_disable(info->clk);
1310 clk_put(info->clk);
1311
1201 kfree(mtd); 1312 kfree(mtd);
1202 return 0; 1313 return 0;
1203} 1314}