diff options
Diffstat (limited to 'include/linux/mtd/mtd.h')
-rw-r--r-- | include/linux/mtd/mtd.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index cd55bf14ad51..205ededccc60 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h | |||
@@ -489,6 +489,34 @@ static inline uint32_t mtd_mod_by_eb(uint64_t sz, struct mtd_info *mtd) | |||
489 | return do_div(sz, mtd->erasesize); | 489 | return do_div(sz, mtd->erasesize); |
490 | } | 490 | } |
491 | 491 | ||
492 | /** | ||
493 | * mtd_align_erase_req - Adjust an erase request to align things on eraseblock | ||
494 | * boundaries. | ||
495 | * @mtd: the MTD device this erase request applies on | ||
496 | * @req: the erase request to adjust | ||
497 | * | ||
498 | * This function will adjust @req->addr and @req->len to align them on | ||
499 | * @mtd->erasesize. Of course we expect @mtd->erasesize to be != 0. | ||
500 | */ | ||
501 | static inline void mtd_align_erase_req(struct mtd_info *mtd, | ||
502 | struct erase_info *req) | ||
503 | { | ||
504 | u32 mod; | ||
505 | |||
506 | if (WARN_ON(!mtd->erasesize)) | ||
507 | return; | ||
508 | |||
509 | mod = mtd_mod_by_eb(req->addr, mtd); | ||
510 | if (mod) { | ||
511 | req->addr -= mod; | ||
512 | req->len += mod; | ||
513 | } | ||
514 | |||
515 | mod = mtd_mod_by_eb(req->addr + req->len, mtd); | ||
516 | if (mod) | ||
517 | req->len += mtd->erasesize - mod; | ||
518 | } | ||
519 | |||
492 | static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd) | 520 | static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd) |
493 | { | 521 | { |
494 | if (mtd->writesize_shift) | 522 | if (mtd->writesize_shift) |