--- zzzz-none-000/linux-5.4.213/include/linux/mtd/mtd.h 2022-09-15 10:04:56.000000000 +0000 +++ miami-7690-761/linux-5.4.213/include/linux/mtd/mtd.h 2024-05-29 11:20:02.000000000 +0000 @@ -504,6 +504,24 @@ req->len += mtd->erasesize - mod; } +static inline uint64_t mtd_roundup_to_eb(uint64_t sz, struct mtd_info *mtd) +{ + if (mtd_mod_by_eb(sz, mtd) == 0) + return sz; + + /* Round up to next erase block */ + return (mtd_div_by_eb(sz, mtd) + 1) * mtd->erasesize; +} + +static inline uint64_t mtd_rounddown_to_eb(uint64_t sz, struct mtd_info *mtd) +{ + if (mtd_mod_by_eb(sz, mtd) == 0) + return sz; + + /* Round down to the start of the current erase block */ + return (mtd_div_by_eb(sz, mtd)) * mtd->erasesize; +} + static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd) { if (mtd->writesize_shift) @@ -568,6 +586,8 @@ extern int __get_mtd_device(struct mtd_info *mtd); extern void __put_mtd_device(struct mtd_info *mtd); extern struct mtd_info *get_mtd_device_nm(const char *name); +extern struct mtd_info *get_mtd_device_by_node( + const struct device_node *of_node); extern void put_mtd_device(struct mtd_info *mtd);