Lines Matching full:mtd

3  * Core registration and callback routines for MTD
34 #include <linux/mtd/mtd.h>
35 #include <linux/mtd/partitions.h>
73 .name = "mtd",
178 /* REVISIT once MTD uses the driver model better, whoever allocates
183 struct mtd_info __maybe_unused *mtd = dev_get_drvdata(dev); in mtd_release() local
184 dev_t index = MTD_DEVT(mtd->index); in mtd_release()
193 struct mtd_info *mtd = dev_get_drvdata(dev); in mtd_cls_suspend() local
195 return mtd ? mtd_suspend(mtd) : 0; in mtd_cls_suspend()
200 struct mtd_info *mtd = dev_get_drvdata(dev); in mtd_cls_resume() local
202 if (mtd) in mtd_cls_resume()
203 mtd_resume(mtd); in mtd_cls_resume()
210 struct mtd_info *mtd = dev_get_drvdata(dev); in mtd_type_show() local
213 switch (mtd->type) { in mtd_type_show()
249 struct mtd_info *mtd = dev_get_drvdata(dev); in mtd_flags_show() local
251 return snprintf(buf, PAGE_SIZE, "0x%lx\n", (unsigned long)mtd->flags); in mtd_flags_show()
259 struct mtd_info *mtd = dev_get_drvdata(dev); in mtd_size_show() local
262 (unsigned long long)mtd->size); in mtd_size_show()
270 struct mtd_info *mtd = dev_get_drvdata(dev); in mtd_erasesize_show() local
272 return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->erasesize); in mtd_erasesize_show()
280 struct mtd_info *mtd = dev_get_drvdata(dev); in mtd_writesize_show() local
282 return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->writesize); in mtd_writesize_show()
290 struct mtd_info *mtd = dev_get_drvdata(dev); in mtd_subpagesize_show() local
291 unsigned int subpagesize = mtd->writesize >> mtd->subpage_sft; in mtd_subpagesize_show()
301 struct mtd_info *mtd = dev_get_drvdata(dev); in mtd_oobsize_show() local
303 return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->oobsize); in mtd_oobsize_show()
311 struct mtd_info *mtd = dev_get_drvdata(dev); in mtd_numeraseregions_show() local
313 return snprintf(buf, PAGE_SIZE, "%u\n", mtd->numeraseregions); in mtd_numeraseregions_show()
322 struct mtd_info *mtd = dev_get_drvdata(dev); in mtd_name_show() local
324 return snprintf(buf, PAGE_SIZE, "%s\n", mtd->name); in mtd_name_show()
332 struct mtd_info *mtd = dev_get_drvdata(dev); in mtd_ecc_strength_show() local
334 return snprintf(buf, PAGE_SIZE, "%u\n", mtd->ecc_strength); in mtd_ecc_strength_show()
342 struct mtd_info *mtd = dev_get_drvdata(dev); in mtd_bitflip_threshold_show() local
344 return snprintf(buf, PAGE_SIZE, "%u\n", mtd->bitflip_threshold); in mtd_bitflip_threshold_show()
351 struct mtd_info *mtd = dev_get_drvdata(dev); in mtd_bitflip_threshold_store() local
359 mtd->bitflip_threshold = bitflip_threshold; in mtd_bitflip_threshold_store()
369 struct mtd_info *mtd = dev_get_drvdata(dev); in mtd_ecc_step_size_show() local
371 return snprintf(buf, PAGE_SIZE, "%u\n", mtd->ecc_step_size); in mtd_ecc_step_size_show()
391 ATTRIBUTE_GROUPS(mtd);
394 .name = "mtd",
401 * add_mtd_device - register an MTD device
402 * @mtd: pointer to new MTD device info structure
404 * Add a device to the list of MTD devices present in the system, and
405 * notify each currently active MTD 'user' of its arrival. Returns
410 int add_mtd_device(struct mtd_info *mtd) in add_mtd_device() argument
418 if (!mtd->backing_dev_info) { in add_mtd_device()
419 switch (mtd->type) { in add_mtd_device()
421 mtd->backing_dev_info = &mtd_bdi_rw_mappable; in add_mtd_device()
424 mtd->backing_dev_info = &mtd_bdi_ro_mappable; in add_mtd_device()
427 mtd->backing_dev_info = &mtd_bdi_unmappable; in add_mtd_device()
433 BUG_ON(mtd->writesize == 0); in add_mtd_device()
436 i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL); in add_mtd_device()
440 mtd->index = i; in add_mtd_device()
441 mtd->usecount = 0; in add_mtd_device()
443 INIT_LIST_HEAD(&mtd->partitions); in add_mtd_device()
446 if (mtd->bitflip_threshold == 0) in add_mtd_device()
447 mtd->bitflip_threshold = mtd->ecc_strength; in add_mtd_device()
449 if (is_power_of_2(mtd->erasesize)) in add_mtd_device()
450 mtd->erasesize_shift = ffs(mtd->erasesize) - 1; in add_mtd_device()
452 mtd->erasesize_shift = 0; in add_mtd_device()
454 if (is_power_of_2(mtd->writesize)) in add_mtd_device()
455 mtd->writesize_shift = ffs(mtd->writesize) - 1; in add_mtd_device()
457 mtd->writesize_shift = 0; in add_mtd_device()
459 mtd->erasesize_mask = (1 << mtd->erasesize_shift) - 1; in add_mtd_device()
460 mtd->writesize_mask = (1 << mtd->writesize_shift) - 1; in add_mtd_device()
463 if ((mtd->flags & MTD_WRITEABLE) && (mtd->flags & MTD_POWERUP_LOCK)) { in add_mtd_device()
464 error = mtd_unlock(mtd, 0, mtd->size); in add_mtd_device()
468 mtd->name); in add_mtd_device()
475 mtd->dev.type = &mtd_devtype; in add_mtd_device()
476 mtd->dev.class = &mtd_class; in add_mtd_device()
477 mtd->dev.devt = MTD_DEVT(i); in add_mtd_device()
478 dev_set_name(&mtd->dev, "mtd%d", i); in add_mtd_device()
479 dev_set_drvdata(&mtd->dev, mtd); in add_mtd_device()
480 if (device_register(&mtd->dev) != 0) in add_mtd_device()
484 device_create(&mtd_class, mtd->dev.parent, in add_mtd_device()
486 NULL, "mtd%dro", i); in add_mtd_device()
488 pr_debug("mtd: Giving out device %d to %s\n", i, mtd->name); in add_mtd_device()
492 not->add(mtd); in add_mtd_device()
494 pr_debug("mtd: Giving out device %d to %s\n", i, mtd->name); in add_mtd_device()
515 * del_mtd_device - unregister an MTD device
516 * @mtd: pointer to MTD device info structure
518 * Remove a device from the list of MTD devices present in the system,
519 * and notify each currently active MTD 'user' of its departure.
524 int del_mtd_device(struct mtd_info *mtd) in del_mtd_device() argument
531 ret = del_mtd_partitions(mtd); in del_mtd_device()
533 debug("Failed to delete MTD partitions attached to %s (err %d)\n", in del_mtd_device()
534 mtd->name, ret); in del_mtd_device()
540 if (idr_find(&mtd_idr, mtd->index) != mtd) { in del_mtd_device()
549 not->remove(mtd); in del_mtd_device()
552 if (mtd->usecount) { in del_mtd_device()
553 printk(KERN_NOTICE "Removing MTD device #%d (%s) with use count %d\n", in del_mtd_device()
554 mtd->index, mtd->name, mtd->usecount); in del_mtd_device()
558 device_unregister(&mtd->dev); in del_mtd_device()
561 idr_remove(&mtd_idr, mtd->index); in del_mtd_device()
574 * mtd_device_parse_register - parse partitions and register an MTD device.
576 * @mtd: the MTD device to register
577 * @types: the list of MTD partition probes to try, see
579 * @parser_data: MTD partition parser-specific data
583 * MTD device is registered if no partition info is found
585 * This function aggregates MTD partitions parsing (done by
586 * 'parse_mtd_partitions()') and MTD device and partitions registering. It
587 * basically follows the most common pattern found in many MTD drivers:
589 * * It first tries to probe partitions on MTD device @mtd using parsers
596 * * If no partitions were found this function just registers the MTD device
597 * @mtd and exits.
601 int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, in mtd_device_parse_register() argument
609 err = parse_mtd_partitions(mtd, types, &real_parts, parser_data); in mtd_device_parse_register()
620 err = add_mtd_partitions(mtd, real_parts, err); in mtd_device_parse_register()
623 err = add_mtd_device(mtd); in mtd_device_parse_register()
633 * mtd_device_unregister - unregister an existing MTD device.
635 * @master: the MTD device to unregister. This will unregister both the master
654 * register_mtd_user - register a 'user' of MTD devices.
658 * or removal of MTD devices. Causes the 'add' callback to be immediately
659 * invoked for each MTD device currently present in the system.
663 struct mtd_info *mtd; in register_mtd_user() local
671 mtd_for_each_device(mtd) in register_mtd_user()
672 new->add(mtd); in register_mtd_user()
679 * unregister_mtd_user - unregister a 'user' of MTD devices.
683 * notified upon addition or removal of MTD devices. Causes the
684 * 'remove' callback to be immediately invoked for each MTD device
689 struct mtd_info *mtd; in unregister_mtd_user() local
695 mtd_for_each_device(mtd) in unregister_mtd_user()
696 old->remove(mtd); in unregister_mtd_user()
706 * get_mtd_device - obtain a validated handle for an MTD device
707 * @mtd: last known address of the required MTD device
708 * @num: internal device number of the required MTD device
716 struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) in get_mtd_device() argument
725 if (other == mtd) { in get_mtd_device()
726 ret = mtd; in get_mtd_device()
732 if (mtd && mtd != ret) in get_mtd_device()
751 int __get_mtd_device(struct mtd_info *mtd) in __get_mtd_device() argument
755 if (!try_module_get(mtd->owner)) in __get_mtd_device()
758 if (mtd->_get_device) { in __get_mtd_device()
759 err = mtd->_get_device(mtd); in __get_mtd_device()
762 module_put(mtd->owner); in __get_mtd_device()
766 mtd->usecount++; in __get_mtd_device()
772 * get_mtd_device_nm - obtain a validated handle for an MTD device by
774 * @name: MTD device name to open
776 * This function returns MTD device description structure in case of
782 struct mtd_info *mtd = NULL, *other; in get_mtd_device_nm() local
788 mtd = other; in get_mtd_device_nm()
793 if (!mtd) in get_mtd_device_nm()
796 err = __get_mtd_device(mtd); in get_mtd_device_nm()
801 return mtd; in get_mtd_device_nm()
815 * @param mtd an MTD device
821 void mtd_get_len_incl_bad(struct mtd_info *mtd, uint64_t offset, in mtd_get_len_incl_bad() argument
828 if (!mtd->_block_isbad) { in mtd_get_len_incl_bad()
837 if (offset >= mtd->size) { in mtd_get_len_incl_bad()
842 block_len = mtd->erasesize - (offset & (mtd->erasesize - 1)); in mtd_get_len_incl_bad()
844 if (!mtd->_block_isbad(mtd, offset & ~(mtd->erasesize - 1))) in mtd_get_len_incl_bad()
853 void put_mtd_device(struct mtd_info *mtd) in put_mtd_device() argument
856 __put_mtd_device(mtd); in put_mtd_device()
862 void __put_mtd_device(struct mtd_info *mtd) in __put_mtd_device() argument
864 --mtd->usecount; in __put_mtd_device()
865 BUG_ON(mtd->usecount < 0); in __put_mtd_device()
867 if (mtd->_put_device) in __put_mtd_device()
868 mtd->_put_device(mtd); in __put_mtd_device()
870 module_put(mtd->owner); in __put_mtd_device()
881 int mtd_erase(struct mtd_info *mtd, struct erase_info *instr) in mtd_erase() argument
883 if (instr->addr > mtd->size || instr->len > mtd->size - instr->addr) in mtd_erase()
885 if (!(mtd->flags & MTD_WRITEABLE)) in mtd_erase()
893 return mtd->_erase(mtd, instr); in mtd_erase()
901 int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, in mtd_point() argument
908 if (!mtd->_point) in mtd_point()
910 if (from < 0 || from > mtd->size || len > mtd->size - from) in mtd_point()
914 return mtd->_point(mtd, from, len, retlen, virt, phys); in mtd_point()
919 int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len) in mtd_unpoint() argument
921 if (!mtd->_point) in mtd_unpoint()
923 if (from < 0 || from > mtd->size || len > mtd->size - from) in mtd_unpoint()
927 return mtd->_unpoint(mtd, from, len); in mtd_unpoint()
937 unsigned long mtd_get_unmapped_area(struct mtd_info *mtd, unsigned long len, in mtd_get_unmapped_area() argument
940 if (!mtd->_get_unmapped_area) in mtd_get_unmapped_area()
942 if (offset > mtd->size || len > mtd->size - offset) in mtd_get_unmapped_area()
944 return mtd->_get_unmapped_area(mtd, len, offset, flags); in mtd_get_unmapped_area()
948 int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, in mtd_read() argument
953 if (from < 0 || from > mtd->size || len > mtd->size - from) in mtd_read()
963 if (mtd->_read) { in mtd_read()
964 ret_code = mtd->_read(mtd, from, len, retlen, buf); in mtd_read()
965 } else if (mtd->_read_oob) { in mtd_read()
971 ret_code = mtd->_read_oob(mtd, from, &ops); in mtd_read()
979 if (mtd->ecc_strength == 0) in mtd_read()
981 return ret_code >= mtd->bitflip_threshold ? -EUCLEAN : 0; in mtd_read()
985 int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, in mtd_write() argument
989 if (to < 0 || to > mtd->size || len > mtd->size - to) in mtd_write()
991 if ((!mtd->_write && !mtd->_write_oob) || in mtd_write()
992 !(mtd->flags & MTD_WRITEABLE)) in mtd_write()
997 if (!mtd->_write) { in mtd_write()
1004 ret = mtd->_write_oob(mtd, to, &ops); in mtd_write()
1009 return mtd->_write(mtd, to, len, retlen, buf); in mtd_write()
1020 int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, in mtd_panic_write() argument
1024 if (!mtd->_panic_write) in mtd_panic_write()
1026 if (to < 0 || to > mtd->size || len > mtd->size - to) in mtd_panic_write()
1028 if (!(mtd->flags & MTD_WRITEABLE)) in mtd_panic_write()
1032 return mtd->_panic_write(mtd, to, len, retlen, buf); in mtd_panic_write()
1036 static int mtd_check_oob_ops(struct mtd_info *mtd, loff_t offs, in mtd_check_oob_ops() argument
1050 if (offs < 0 || offs + ops->len > mtd->size) in mtd_check_oob_ops()
1056 if (ops->ooboffs >= mtd_oobavail(mtd, ops)) in mtd_check_oob_ops()
1059 maxooblen = ((mtd_div_by_ws(mtd->size, mtd) - in mtd_check_oob_ops()
1060 mtd_div_by_ws(offs, mtd)) * in mtd_check_oob_ops()
1061 mtd_oobavail(mtd, ops)) - ops->ooboffs; in mtd_check_oob_ops()
1069 int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops) in mtd_read_oob() argument
1074 ret_code = mtd_check_oob_ops(mtd, from, ops); in mtd_read_oob()
1078 /* Check the validity of a potential fallback on mtd->_read */ in mtd_read_oob()
1079 if (!mtd->_read_oob && (!mtd->_read || ops->oobbuf)) in mtd_read_oob()
1082 if (mtd->_read_oob) in mtd_read_oob()
1083 ret_code = mtd->_read_oob(mtd, from, ops); in mtd_read_oob()
1085 ret_code = mtd->_read(mtd, from, ops->len, &ops->retlen, in mtd_read_oob()
1089 * In cases where ops->datbuf != NULL, mtd->_read_oob() has semantics in mtd_read_oob()
1090 * similar to mtd->_read(), returning a non-negative integer in mtd_read_oob()
1091 * representing max bitflips. In other cases, mtd->_read_oob() may in mtd_read_oob()
1096 if (mtd->ecc_strength == 0) in mtd_read_oob()
1098 return ret_code >= mtd->bitflip_threshold ? -EUCLEAN : 0; in mtd_read_oob()
1102 int mtd_write_oob(struct mtd_info *mtd, loff_t to, in mtd_write_oob() argument
1109 if (!(mtd->flags & MTD_WRITEABLE)) in mtd_write_oob()
1112 ret = mtd_check_oob_ops(mtd, to, ops); in mtd_write_oob()
1116 /* Check the validity of a potential fallback on mtd->_write */ in mtd_write_oob()
1117 if (!mtd->_write_oob && (!mtd->_write || ops->oobbuf)) in mtd_write_oob()
1120 if (mtd->_write_oob) in mtd_write_oob()
1121 return mtd->_write_oob(mtd, to, ops); in mtd_write_oob()
1123 return mtd->_write(mtd, to, ops->len, &ops->retlen, in mtd_write_oob()
1130 * @mtd: MTD device structure
1140 * mtd_ooblayout_ecc(mtd, section++, oobecc) until it returns -ERANGE.
1144 int mtd_ooblayout_ecc(struct mtd_info *mtd, int section, in mtd_ooblayout_ecc() argument
1149 if (!mtd || section < 0) in mtd_ooblayout_ecc()
1152 if (!mtd->ooblayout || !mtd->ooblayout->ecc) in mtd_ooblayout_ecc()
1155 return mtd->ooblayout->ecc(mtd, section, oobecc); in mtd_ooblayout_ecc()
1162 * @mtd: MTD device structure
1172 * mtd_ooblayout_free(mtd, section++, oobfree) until it returns -ERANGE.
1176 int mtd_ooblayout_free(struct mtd_info *mtd, int section, in mtd_ooblayout_free() argument
1181 if (!mtd || section < 0) in mtd_ooblayout_free()
1184 if (!mtd->ooblayout || !mtd->ooblayout->free) in mtd_ooblayout_free()
1187 return mtd->ooblayout->free(mtd, section, oobfree); in mtd_ooblayout_free()
1193 * @mtd: mtd info structure
1204 * mtd_ooblayout_find_region(mtd, 3, &section, &oobregion, mtd_ooblayout_ecc);
1208 static int mtd_ooblayout_find_region(struct mtd_info *mtd, int byte, in mtd_ooblayout_find_region() argument
1219 ret = iter(mtd, section, oobregion); in mtd_ooblayout_find_region()
1244 * @mtd: mtd info structure
1254 int mtd_ooblayout_find_eccregion(struct mtd_info *mtd, int eccbyte, in mtd_ooblayout_find_eccregion() argument
1258 return mtd_ooblayout_find_region(mtd, eccbyte, section, oobregion, in mtd_ooblayout_find_eccregion()
1265 * @mtd: mtd info structure
1277 static int mtd_ooblayout_get_bytes(struct mtd_info *mtd, u8 *buf, in mtd_ooblayout_get_bytes() argument
1286 ret = mtd_ooblayout_find_region(mtd, start, &section, in mtd_ooblayout_get_bytes()
1300 ret = iter(mtd, ++section, &oobregion); in mtd_ooblayout_get_bytes()
1308 * @mtd: mtd info structure
1320 static int mtd_ooblayout_set_bytes(struct mtd_info *mtd, const u8 *buf, in mtd_ooblayout_set_bytes() argument
1329 ret = mtd_ooblayout_find_region(mtd, start, &section, in mtd_ooblayout_set_bytes()
1343 ret = iter(mtd, ++section, &oobregion); in mtd_ooblayout_set_bytes()
1351 * @mtd: mtd info structure
1358 static int mtd_ooblayout_count_bytes(struct mtd_info *mtd, in mtd_ooblayout_count_bytes() argument
1367 ret = iter(mtd, section++, &oobregion); in mtd_ooblayout_count_bytes()
1382 * @mtd: mtd info structure
1392 int mtd_ooblayout_get_eccbytes(struct mtd_info *mtd, u8 *eccbuf, in mtd_ooblayout_get_eccbytes() argument
1395 return mtd_ooblayout_get_bytes(mtd, eccbuf, oobbuf, start, nbytes, in mtd_ooblayout_get_eccbytes()
1402 * @mtd: mtd info structure
1412 int mtd_ooblayout_set_eccbytes(struct mtd_info *mtd, const u8 *eccbuf, in mtd_ooblayout_set_eccbytes() argument
1415 return mtd_ooblayout_set_bytes(mtd, eccbuf, oobbuf, start, nbytes, in mtd_ooblayout_set_eccbytes()
1422 * @mtd: mtd info structure
1432 int mtd_ooblayout_get_databytes(struct mtd_info *mtd, u8 *databuf, in mtd_ooblayout_get_databytes() argument
1435 return mtd_ooblayout_get_bytes(mtd, databuf, oobbuf, start, nbytes, in mtd_ooblayout_get_databytes()
1442 * @mtd: mtd info structure
1452 int mtd_ooblayout_set_databytes(struct mtd_info *mtd, const u8 *databuf, in mtd_ooblayout_set_databytes() argument
1455 return mtd_ooblayout_set_bytes(mtd, databuf, oobbuf, start, nbytes, in mtd_ooblayout_set_databytes()
1462 * @mtd: mtd info structure
1468 int mtd_ooblayout_count_freebytes(struct mtd_info *mtd) in mtd_ooblayout_count_freebytes() argument
1470 return mtd_ooblayout_count_bytes(mtd, mtd_ooblayout_free); in mtd_ooblayout_count_freebytes()
1476 * @mtd: mtd info structure
1482 int mtd_ooblayout_count_eccbytes(struct mtd_info *mtd) in mtd_ooblayout_count_eccbytes() argument
1484 return mtd_ooblayout_count_bytes(mtd, mtd_ooblayout_ecc); in mtd_ooblayout_count_eccbytes()
1493 int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen, in mtd_get_fact_prot_info() argument
1496 if (!mtd->_get_fact_prot_info) in mtd_get_fact_prot_info()
1500 return mtd->_get_fact_prot_info(mtd, len, retlen, buf); in mtd_get_fact_prot_info()
1504 int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len, in mtd_read_fact_prot_reg() argument
1508 if (!mtd->_read_fact_prot_reg) in mtd_read_fact_prot_reg()
1512 return mtd->_read_fact_prot_reg(mtd, from, len, retlen, buf); in mtd_read_fact_prot_reg()
1516 int mtd_get_user_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen, in mtd_get_user_prot_info() argument
1519 if (!mtd->_get_user_prot_info) in mtd_get_user_prot_info()
1523 return mtd->_get_user_prot_info(mtd, len, retlen, buf); in mtd_get_user_prot_info()
1527 int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len, in mtd_read_user_prot_reg() argument
1531 if (!mtd->_read_user_prot_reg) in mtd_read_user_prot_reg()
1535 return mtd->_read_user_prot_reg(mtd, from, len, retlen, buf); in mtd_read_user_prot_reg()
1539 int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len, in mtd_write_user_prot_reg() argument
1545 if (!mtd->_write_user_prot_reg) in mtd_write_user_prot_reg()
1549 ret = mtd->_write_user_prot_reg(mtd, to, len, retlen, buf); in mtd_write_user_prot_reg()
1561 int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len) in mtd_lock_user_prot_reg() argument
1563 if (!mtd->_lock_user_prot_reg) in mtd_lock_user_prot_reg()
1567 return mtd->_lock_user_prot_reg(mtd, from, len); in mtd_lock_user_prot_reg()
1572 int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) in mtd_lock() argument
1574 if (!mtd->_lock) in mtd_lock()
1576 if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs) in mtd_lock()
1580 return mtd->_lock(mtd, ofs, len); in mtd_lock()
1584 int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) in mtd_unlock() argument
1586 if (!mtd->_unlock) in mtd_unlock()
1588 if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs) in mtd_unlock()
1592 return mtd->_unlock(mtd, ofs, len); in mtd_unlock()
1596 int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) in mtd_is_locked() argument
1598 if (!mtd->_is_locked) in mtd_is_locked()
1600 if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs) in mtd_is_locked()
1604 return mtd->_is_locked(mtd, ofs, len); in mtd_is_locked()
1608 int mtd_block_isreserved(struct mtd_info *mtd, loff_t ofs) in mtd_block_isreserved() argument
1610 if (ofs < 0 || ofs > mtd->size) in mtd_block_isreserved()
1612 if (!mtd->_block_isreserved) in mtd_block_isreserved()
1614 return mtd->_block_isreserved(mtd, ofs); in mtd_block_isreserved()
1618 int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs) in mtd_block_isbad() argument
1620 if (ofs < 0 || ofs > mtd->size) in mtd_block_isbad()
1622 if (!mtd->_block_isbad) in mtd_block_isbad()
1624 return mtd->_block_isbad(mtd, ofs); in mtd_block_isbad()
1628 int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs) in mtd_block_markbad() argument
1630 if (!mtd->_block_markbad) in mtd_block_markbad()
1632 if (ofs < 0 || ofs > mtd->size) in mtd_block_markbad()
1634 if (!(mtd->flags & MTD_WRITEABLE)) in mtd_block_markbad()
1636 return mtd->_block_markbad(mtd, ofs); in mtd_block_markbad()
1643 * @mtd: mtd device description object pointer
1646 * @to: the MTD device offset to write to
1647 * @retlen: on exit contains the count of bytes written to the MTD device.
1652 static int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, in default_mtd_writev() argument
1662 ret = mtd_write(mtd, to, vecs[i].iov_len, &thislen, in default_mtd_writev()
1674 * mtd_writev - the vector-based MTD write method
1675 * @mtd: mtd device description object pointer
1678 * @to: the MTD device offset to write to
1679 * @retlen: on exit contains the count of bytes written to the MTD device.
1684 int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, in mtd_writev() argument
1688 if (!(mtd->flags & MTD_WRITEABLE)) in mtd_writev()
1690 if (!mtd->_writev) in mtd_writev()
1691 return default_mtd_writev(mtd, vecs, count, to, retlen); in mtd_writev()
1692 return mtd->_writev(mtd, vecs, count, to, retlen); in mtd_writev()
1698 * @mtd: mtd device description object pointer
1711 * the MTD device's min. I/O unit, i.e. the "mtd->writesize" value.
1720 void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size) in mtd_kmalloc_up_to() argument
1724 size_t min_alloc = max_t(size_t, mtd->writesize, PAGE_SIZE); in mtd_kmalloc_up_to()
1735 *size = ALIGN(*size, mtd->writesize); in mtd_kmalloc_up_to()
1750 /* Support for /proc/mtd */
1754 struct mtd_info *mtd; in mtd_proc_show() local
1758 mtd_for_each_device(mtd) { in mtd_proc_show()
1759 seq_printf(m, "mtd%d: %8.8llx %8.8x \"%s\"\n", in mtd_proc_show()
1760 mtd->index, (unsigned long long)mtd->size, in mtd_proc_show()
1761 mtd->erasesize, mtd->name); in mtd_proc_show()
1808 ret = mtd_bdi_init(&mtd_bdi_unmappable, "mtd-unmap"); in init_mtd()
1812 ret = mtd_bdi_init(&mtd_bdi_ro_mappable, "mtd-romap"); in init_mtd()
1816 ret = mtd_bdi_init(&mtd_bdi_rw_mappable, "mtd-rwmap"); in init_mtd()
1820 proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops); in init_mtd()
1830 remove_proc_entry("mtd", NULL); in init_mtd()
1838 pr_err("Error registering mtd class or bdi: %d\n", ret); in init_mtd()
1846 remove_proc_entry("mtd", NULL); in cleanup_mtd()
1859 MODULE_DESCRIPTION("Core MTD registration and access routines");