403-v6.1-mtd-allow-getting-MTD-device-associated-with-a-speci.patch 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. From b0321721be50b80c03a51866a94fde4f94690e18 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <[email protected]>
  3. Date: Wed, 15 Jun 2022 21:42:59 +0200
  4. Subject: [PATCH] mtd: allow getting MTD device associated with a specific DT
  5. node
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. MTD subsystem API allows interacting with MTD devices (e.g. reading,
  10. writing, handling bad blocks). So far a random driver could get MTD
  11. device only by its name (get_mtd_device_nm()). This change allows
  12. getting them also by a DT node.
  13. This API is required for drivers handling DT defined MTD partitions in a
  14. specific way (e.g. U-Boot (sub)partition with environment variables).
  15. Signed-off-by: Rafał Miłecki <[email protected]>
  16. Acked-by: Miquel Raynal <[email protected]>
  17. Signed-off-by: Srinivas Kandagatla <[email protected]>
  18. ---
  19. drivers/mtd/mtdcore.c | 28 ++++++++++++++++++++++++++++
  20. include/linux/mtd/mtd.h | 1 +
  21. 2 files changed, 29 insertions(+)
  22. --- a/drivers/mtd/mtdcore.c
  23. +++ b/drivers/mtd/mtdcore.c
  24. @@ -1236,6 +1236,34 @@ int __get_mtd_device(struct mtd_info *mt
  25. EXPORT_SYMBOL_GPL(__get_mtd_device);
  26. /**
  27. + * of_get_mtd_device_by_node - obtain an MTD device associated with a given node
  28. + *
  29. + * @np: device tree node
  30. + */
  31. +struct mtd_info *of_get_mtd_device_by_node(struct device_node *np)
  32. +{
  33. + struct mtd_info *mtd = NULL;
  34. + struct mtd_info *tmp;
  35. + int err;
  36. +
  37. + mutex_lock(&mtd_table_mutex);
  38. +
  39. + err = -EPROBE_DEFER;
  40. + mtd_for_each_device(tmp) {
  41. + if (mtd_get_of_node(tmp) == np) {
  42. + mtd = tmp;
  43. + err = __get_mtd_device(mtd);
  44. + break;
  45. + }
  46. + }
  47. +
  48. + mutex_unlock(&mtd_table_mutex);
  49. +
  50. + return err ? ERR_PTR(err) : mtd;
  51. +}
  52. +EXPORT_SYMBOL_GPL(of_get_mtd_device_by_node);
  53. +
  54. +/**
  55. * get_mtd_device_nm - obtain a validated handle for an MTD device by
  56. * device name
  57. * @name: MTD device name to open
  58. --- a/include/linux/mtd/mtd.h
  59. +++ b/include/linux/mtd/mtd.h
  60. @@ -682,6 +682,7 @@ extern int mtd_device_unregister(struct
  61. extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
  62. extern int __get_mtd_device(struct mtd_info *mtd);
  63. extern void __put_mtd_device(struct mtd_info *mtd);
  64. +extern struct mtd_info *of_get_mtd_device_by_node(struct device_node *np);
  65. extern struct mtd_info *get_mtd_device_nm(const char *name);
  66. extern void put_mtd_device(struct mtd_info *mtd);