diff options
Diffstat (limited to 'drivers/mtd/lpddr/lpddr_cmds.c')
-rw-r--r-- | drivers/mtd/lpddr/lpddr_cmds.c | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/drivers/mtd/lpddr/lpddr_cmds.c b/drivers/mtd/lpddr/lpddr_cmds.c index 536bbceaeaad..d3cfe26beeaa 100644 --- a/drivers/mtd/lpddr/lpddr_cmds.c +++ b/drivers/mtd/lpddr/lpddr_cmds.c | |||
@@ -40,7 +40,7 @@ static int lpddr_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len); | |||
40 | static int lpddr_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len); | 40 | static int lpddr_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len); |
41 | static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len, | 41 | static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len, |
42 | size_t *retlen, void **mtdbuf, resource_size_t *phys); | 42 | size_t *retlen, void **mtdbuf, resource_size_t *phys); |
43 | static void lpddr_unpoint(struct mtd_info *mtd, loff_t adr, size_t len); | 43 | static int lpddr_unpoint(struct mtd_info *mtd, loff_t adr, size_t len); |
44 | static int get_chip(struct map_info *map, struct flchip *chip, int mode); | 44 | static int get_chip(struct map_info *map, struct flchip *chip, int mode); |
45 | static int chip_ready(struct map_info *map, struct flchip *chip, int mode); | 45 | static int chip_ready(struct map_info *map, struct flchip *chip, int mode); |
46 | static void put_chip(struct map_info *map, struct flchip *chip); | 46 | static void put_chip(struct map_info *map, struct flchip *chip); |
@@ -63,18 +63,18 @@ struct mtd_info *lpddr_cmdset(struct map_info *map) | |||
63 | mtd->type = MTD_NORFLASH; | 63 | mtd->type = MTD_NORFLASH; |
64 | 64 | ||
65 | /* Fill in the default mtd operations */ | 65 | /* Fill in the default mtd operations */ |
66 | mtd->read = lpddr_read; | 66 | mtd->_read = lpddr_read; |
67 | mtd->type = MTD_NORFLASH; | 67 | mtd->type = MTD_NORFLASH; |
68 | mtd->flags = MTD_CAP_NORFLASH; | 68 | mtd->flags = MTD_CAP_NORFLASH; |
69 | mtd->flags &= ~MTD_BIT_WRITEABLE; | 69 | mtd->flags &= ~MTD_BIT_WRITEABLE; |
70 | mtd->erase = lpddr_erase; | 70 | mtd->_erase = lpddr_erase; |
71 | mtd->write = lpddr_write_buffers; | 71 | mtd->_write = lpddr_write_buffers; |
72 | mtd->writev = lpddr_writev; | 72 | mtd->_writev = lpddr_writev; |
73 | mtd->lock = lpddr_lock; | 73 | mtd->_lock = lpddr_lock; |
74 | mtd->unlock = lpddr_unlock; | 74 | mtd->_unlock = lpddr_unlock; |
75 | if (map_is_linear(map)) { | 75 | if (map_is_linear(map)) { |
76 | mtd->point = lpddr_point; | 76 | mtd->_point = lpddr_point; |
77 | mtd->unpoint = lpddr_unpoint; | 77 | mtd->_unpoint = lpddr_unpoint; |
78 | } | 78 | } |
79 | mtd->size = 1 << lpddr->qinfo->DevSizeShift; | 79 | mtd->size = 1 << lpddr->qinfo->DevSizeShift; |
80 | mtd->erasesize = 1 << lpddr->qinfo->UniformBlockSizeShift; | 80 | mtd->erasesize = 1 << lpddr->qinfo->UniformBlockSizeShift; |
@@ -530,14 +530,12 @@ static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len, | |||
530 | struct flchip *chip = &lpddr->chips[chipnum]; | 530 | struct flchip *chip = &lpddr->chips[chipnum]; |
531 | int ret = 0; | 531 | int ret = 0; |
532 | 532 | ||
533 | if (!map->virt || (adr + len > mtd->size)) | 533 | if (!map->virt) |
534 | return -EINVAL; | 534 | return -EINVAL; |
535 | 535 | ||
536 | /* ofs: offset within the first chip that the first read should start */ | 536 | /* ofs: offset within the first chip that the first read should start */ |
537 | ofs = adr - (chipnum << lpddr->chipshift); | 537 | ofs = adr - (chipnum << lpddr->chipshift); |
538 | |||
539 | *mtdbuf = (void *)map->virt + chip->start + ofs; | 538 | *mtdbuf = (void *)map->virt + chip->start + ofs; |
540 | *retlen = 0; | ||
541 | 539 | ||
542 | while (len) { | 540 | while (len) { |
543 | unsigned long thislen; | 541 | unsigned long thislen; |
@@ -575,11 +573,11 @@ static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len, | |||
575 | return 0; | 573 | return 0; |
576 | } | 574 | } |
577 | 575 | ||
578 | static void lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len) | 576 | static int lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len) |
579 | { | 577 | { |
580 | struct map_info *map = mtd->priv; | 578 | struct map_info *map = mtd->priv; |
581 | struct lpddr_private *lpddr = map->fldrv_priv; | 579 | struct lpddr_private *lpddr = map->fldrv_priv; |
582 | int chipnum = adr >> lpddr->chipshift; | 580 | int chipnum = adr >> lpddr->chipshift, err = 0; |
583 | unsigned long ofs; | 581 | unsigned long ofs; |
584 | 582 | ||
585 | /* ofs: offset within the first chip that the first read should start */ | 583 | /* ofs: offset within the first chip that the first read should start */ |
@@ -603,9 +601,11 @@ static void lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len) | |||
603 | chip->ref_point_counter--; | 601 | chip->ref_point_counter--; |
604 | if (chip->ref_point_counter == 0) | 602 | if (chip->ref_point_counter == 0) |
605 | chip->state = FL_READY; | 603 | chip->state = FL_READY; |
606 | } else | 604 | } else { |
607 | printk(KERN_WARNING "%s: Warning: unpoint called on non" | 605 | printk(KERN_WARNING "%s: Warning: unpoint called on non" |
608 | "pointed region\n", map->name); | 606 | "pointed region\n", map->name); |
607 | err = -EINVAL; | ||
608 | } | ||
609 | 609 | ||
610 | put_chip(map, chip); | 610 | put_chip(map, chip); |
611 | mutex_unlock(&chip->mutex); | 611 | mutex_unlock(&chip->mutex); |
@@ -614,6 +614,8 @@ static void lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len) | |||
614 | ofs = 0; | 614 | ofs = 0; |
615 | chipnum++; | 615 | chipnum++; |
616 | } | 616 | } |
617 | |||
618 | return err; | ||
617 | } | 619 | } |
618 | 620 | ||
619 | static int lpddr_write_buffers(struct mtd_info *mtd, loff_t to, size_t len, | 621 | static int lpddr_write_buffers(struct mtd_info *mtd, loff_t to, size_t len, |
@@ -637,13 +639,11 @@ static int lpddr_writev(struct mtd_info *mtd, const struct kvec *vecs, | |||
637 | int chipnum; | 639 | int chipnum; |
638 | unsigned long ofs, vec_seek, i; | 640 | unsigned long ofs, vec_seek, i; |
639 | int wbufsize = 1 << lpddr->qinfo->BufSizeShift; | 641 | int wbufsize = 1 << lpddr->qinfo->BufSizeShift; |
640 | |||
641 | size_t len = 0; | 642 | size_t len = 0; |
642 | 643 | ||
643 | for (i = 0; i < count; i++) | 644 | for (i = 0; i < count; i++) |
644 | len += vecs[i].iov_len; | 645 | len += vecs[i].iov_len; |
645 | 646 | ||
646 | *retlen = 0; | ||
647 | if (!len) | 647 | if (!len) |
648 | return 0; | 648 | return 0; |
649 | 649 | ||
@@ -688,9 +688,6 @@ static int lpddr_erase(struct mtd_info *mtd, struct erase_info *instr) | |||
688 | ofs = instr->addr; | 688 | ofs = instr->addr; |
689 | len = instr->len; | 689 | len = instr->len; |
690 | 690 | ||
691 | if (ofs > mtd->size || (len + ofs) > mtd->size) | ||
692 | return -EINVAL; | ||
693 | |||
694 | while (len > 0) { | 691 | while (len > 0) { |
695 | ret = do_erase_oneblock(mtd, ofs); | 692 | ret = do_erase_oneblock(mtd, ofs); |
696 | if (ret) | 693 | if (ret) |