Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nvmem: core: Rework layouts to become regular devices

Current layout support was initially written without modules support in
mind. When the requirement for module support rose, the existing base
was improved to adopt modularization support, but kind of a design flaw
was introduced. With the existing implementation, when a storage device
registers into NVMEM, the core tries to hook a layout (if any) and
populates its cells immediately. This means, if the hardware description
expects a layout to be hooked up, but no driver was provided for that,
the storage medium will fail to probe and try later from
scratch. Even if we consider that the hardware description shall be
correct, we could still probe the storage device (especially if it
contains the rootfs).

One way to overcome this situation is to consider the layouts as
devices, and leverage the native notifier mechanism. When a new NVMEM
device is registered, we can populate its nvmem-layout child, if any,
and wait for the matching to be done in order to get the cells (the
waiting can be easily done with the NVMEM notifiers). If the layout
driver is compiled as a module, it should automatically be loaded. This
way, there is no strong order to enforce, any NVMEM device creation
or NVMEM layout driver insertion will be observed as a new event which
may lead to the creation of additional cells, without disturbing the
probes with costly (and sometimes endless) deferrals.

In order to achieve that goal we create a new bus for the nvmem-layouts
with minimal logic to match nvmem-layout devices with nvmem-layout
drivers. All this infrastructure code is created in the layouts.c file.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Tested-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20231215111536.316972-7-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Miquel Raynal and committed by
Greg Kroah-Hartman
fc29fd82 1172460e

+354 -135
+1
drivers/nvmem/Kconfig
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 menuconfig NVMEM 3 3 bool "NVMEM Support" 4 + imply NVMEM_LAYOUTS 4 5 help 5 6 Support for NVMEM(Non Volatile Memory) devices like EEPROM, EFUSES... 6 7
+2
drivers/nvmem/Makefile
··· 5 5 6 6 obj-$(CONFIG_NVMEM) += nvmem_core.o 7 7 nvmem_core-y := core.o 8 + obj-$(CONFIG_NVMEM_LAYOUTS) += nvmem_layouts.o 9 + nvmem_layouts-y := layouts.o 8 10 obj-y += layouts/ 9 11 10 12 # Devices
+61 -109
drivers/nvmem/core.c
··· 55 55 56 56 static BLOCKING_NOTIFIER_HEAD(nvmem_notifier); 57 57 58 - static DEFINE_SPINLOCK(nvmem_layout_lock); 59 - static LIST_HEAD(nvmem_layouts); 60 - 61 58 static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset, 62 59 void *val, size_t bytes) 63 60 { ··· 737 740 return err; 738 741 } 739 742 740 - int __nvmem_layout_register(struct nvmem_layout *layout, struct module *owner) 743 + int nvmem_layout_register(struct nvmem_layout *layout) 741 744 { 742 - layout->owner = owner; 745 + if (!layout->add_cells) 746 + return -EINVAL; 743 747 744 - spin_lock(&nvmem_layout_lock); 745 - list_add(&layout->node, &nvmem_layouts); 746 - spin_unlock(&nvmem_layout_lock); 747 - 748 - blocking_notifier_call_chain(&nvmem_notifier, NVMEM_LAYOUT_ADD, layout); 749 - 750 - return 0; 748 + /* Populate the cells */ 749 + return layout->add_cells(&layout->nvmem->dev, layout->nvmem); 751 750 } 752 - EXPORT_SYMBOL_GPL(__nvmem_layout_register); 751 + EXPORT_SYMBOL_GPL(nvmem_layout_register); 753 752 754 753 void nvmem_layout_unregister(struct nvmem_layout *layout) 755 754 { 756 - blocking_notifier_call_chain(&nvmem_notifier, NVMEM_LAYOUT_REMOVE, layout); 757 - 758 - spin_lock(&nvmem_layout_lock); 759 - list_del(&layout->node); 760 - spin_unlock(&nvmem_layout_lock); 755 + /* Keep the API even with an empty stub in case we need it later */ 761 756 } 762 757 EXPORT_SYMBOL_GPL(nvmem_layout_unregister); 763 - 764 - static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem) 765 - { 766 - struct device_node *layout_np; 767 - struct nvmem_layout *l, *layout = ERR_PTR(-EPROBE_DEFER); 768 - 769 - layout_np = of_nvmem_layout_get_container(nvmem); 770 - if (!layout_np) 771 - return NULL; 772 - 773 - /* Fixed layouts don't have a matching driver */ 774 - if (of_device_is_compatible(layout_np, "fixed-layout")) { 775 - of_node_put(layout_np); 776 - return NULL; 777 - } 778 - 779 - /* 780 - * In case the nvmem device was built-in while the layout was built as a 781 - * module, we shall manually request the layout driver loading otherwise 782 - * we'll never have any match. 783 - */ 784 - of_request_module(layout_np); 785 - 786 - spin_lock(&nvmem_layout_lock); 787 - 788 - list_for_each_entry(l, &nvmem_layouts, node) { 789 - if (of_match_node(l->of_match_table, layout_np)) { 790 - if (try_module_get(l->owner)) 791 - layout = l; 792 - 793 - break; 794 - } 795 - } 796 - 797 - spin_unlock(&nvmem_layout_lock); 798 - of_node_put(layout_np); 799 - 800 - return layout; 801 - } 802 - 803 - static void nvmem_layout_put(struct nvmem_layout *layout) 804 - { 805 - if (layout) 806 - module_put(layout->owner); 807 - } 808 - 809 - static int nvmem_add_cells_from_layout(struct nvmem_device *nvmem) 810 - { 811 - struct nvmem_layout *layout = nvmem->layout; 812 - int ret; 813 - 814 - if (layout && layout->add_cells) { 815 - ret = layout->add_cells(&nvmem->dev, nvmem); 816 - if (ret) 817 - return ret; 818 - } 819 - 820 - return 0; 821 - } 822 - 823 - #if IS_ENABLED(CONFIG_OF) 824 - struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvmem) 825 - { 826 - return of_get_child_by_name(nvmem->dev.of_node, "nvmem-layout"); 827 - } 828 - EXPORT_SYMBOL_GPL(of_nvmem_layout_get_container); 829 - #endif 830 758 831 759 const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem, 832 760 struct nvmem_layout *layout) ··· 760 838 const struct of_device_id *match; 761 839 762 840 layout_np = of_nvmem_layout_get_container(nvmem); 763 - match = of_match_node(layout->of_match_table, layout_np); 841 + match = of_match_node(layout->dev.driver->of_match_table, layout_np); 764 842 765 843 return match ? match->data : NULL; 766 844 } ··· 872 950 goto err_put_device; 873 951 } 874 952 875 - /* 876 - * If the driver supplied a layout by config->layout, the module 877 - * pointer will be NULL and nvmem_layout_put() will be a noop. 878 - */ 879 - nvmem->layout = config->layout ?: nvmem_layout_get(nvmem); 880 - if (IS_ERR(nvmem->layout)) { 881 - rval = PTR_ERR(nvmem->layout); 882 - nvmem->layout = NULL; 883 - 884 - if (rval == -EPROBE_DEFER) 885 - goto err_teardown_compat; 886 - } 887 - 888 953 if (config->cells) { 889 954 rval = nvmem_add_cells(nvmem, config->cells, config->ncells); 890 955 if (rval) ··· 892 983 if (rval) 893 984 goto err_remove_cells; 894 985 895 - rval = nvmem_add_cells_from_layout(nvmem); 896 - if (rval) 897 - goto err_remove_cells; 898 - 899 986 dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); 900 987 901 988 rval = device_add(&nvmem->dev); 902 989 if (rval) 903 990 goto err_remove_cells; 904 991 992 + rval = nvmem_populate_layout(nvmem); 993 + if (rval) 994 + goto err_remove_dev; 995 + 905 996 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); 906 997 907 998 return nvmem; 908 999 1000 + err_remove_dev: 1001 + device_del(&nvmem->dev); 909 1002 err_remove_cells: 910 1003 nvmem_device_remove_all_cells(nvmem); 911 - nvmem_layout_put(nvmem->layout); 912 - err_teardown_compat: 913 1004 if (config->compat) 914 1005 nvmem_sysfs_remove_compat(nvmem, config); 915 1006 err_put_device: ··· 931 1022 device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); 932 1023 933 1024 nvmem_device_remove_all_cells(nvmem); 934 - nvmem_layout_put(nvmem->layout); 1025 + nvmem_destroy_layout(nvmem); 935 1026 device_unregister(&nvmem->dev); 936 1027 } 937 1028 ··· 1233 1324 return cell; 1234 1325 } 1235 1326 1327 + static void nvmem_layout_module_put(struct nvmem_device *nvmem) 1328 + { 1329 + if (nvmem->layout && nvmem->layout->dev.driver) 1330 + module_put(nvmem->layout->dev.driver->owner); 1331 + } 1332 + 1236 1333 #if IS_ENABLED(CONFIG_OF) 1237 1334 static struct nvmem_cell_entry * 1238 1335 nvmem_find_cell_entry_by_node(struct nvmem_device *nvmem, struct device_node *np) ··· 1255 1340 mutex_unlock(&nvmem_mutex); 1256 1341 1257 1342 return cell; 1343 + } 1344 + 1345 + static int nvmem_layout_module_get_optional(struct nvmem_device *nvmem) 1346 + { 1347 + if (!nvmem->layout) 1348 + return 0; 1349 + 1350 + if (!nvmem->layout->dev.driver || 1351 + !try_module_get(nvmem->layout->dev.driver->owner)) 1352 + return -EPROBE_DEFER; 1353 + 1354 + return 0; 1258 1355 } 1259 1356 1260 1357 /** ··· 1331 1404 return ERR_CAST(nvmem); 1332 1405 } 1333 1406 1407 + ret = nvmem_layout_module_get_optional(nvmem); 1408 + if (ret) { 1409 + of_node_put(cell_np); 1410 + __nvmem_device_put(nvmem); 1411 + return ERR_PTR(ret); 1412 + } 1413 + 1334 1414 cell_entry = nvmem_find_cell_entry_by_node(nvmem, cell_np); 1335 1415 of_node_put(cell_np); 1336 1416 if (!cell_entry) { 1337 1417 __nvmem_device_put(nvmem); 1338 - return ERR_PTR(-ENOENT); 1418 + nvmem_layout_module_put(nvmem); 1419 + if (nvmem->layout) 1420 + return ERR_PTR(-EPROBE_DEFER); 1421 + else 1422 + return ERR_PTR(-ENOENT); 1339 1423 } 1340 1424 1341 1425 cell = nvmem_create_cell(cell_entry, id, cell_index); 1342 - if (IS_ERR(cell)) 1426 + if (IS_ERR(cell)) { 1343 1427 __nvmem_device_put(nvmem); 1428 + nvmem_layout_module_put(nvmem); 1429 + } 1344 1430 1345 1431 return cell; 1346 1432 } ··· 1467 1527 1468 1528 kfree(cell); 1469 1529 __nvmem_device_put(nvmem); 1530 + nvmem_layout_module_put(nvmem); 1470 1531 } 1471 1532 EXPORT_SYMBOL_GPL(nvmem_cell_put); 1472 1533 ··· 2045 2104 2046 2105 static int __init nvmem_init(void) 2047 2106 { 2048 - return bus_register(&nvmem_bus_type); 2107 + int ret; 2108 + 2109 + ret = bus_register(&nvmem_bus_type); 2110 + if (ret) 2111 + return ret; 2112 + 2113 + ret = nvmem_layout_bus_register(); 2114 + if (ret) 2115 + bus_unregister(&nvmem_bus_type); 2116 + 2117 + return ret; 2049 2118 } 2050 2119 2051 2120 static void __exit nvmem_exit(void) 2052 2121 { 2122 + nvmem_layout_bus_unregister(); 2053 2123 bus_unregister(&nvmem_bus_type); 2054 2124 } 2055 2125
+21
drivers/nvmem/internals.h
··· 34 34 void *priv; 35 35 }; 36 36 37 + #if IS_ENABLED(CONFIG_OF) 38 + int nvmem_layout_bus_register(void); 39 + void nvmem_layout_bus_unregister(void); 40 + int nvmem_populate_layout(struct nvmem_device *nvmem); 41 + void nvmem_destroy_layout(struct nvmem_device *nvmem); 42 + #else /* CONFIG_OF */ 43 + static inline int nvmem_layout_bus_register(void) 44 + { 45 + return 0; 46 + } 47 + 48 + static inline void nvmem_layout_bus_unregister(void) {} 49 + 50 + static inline int nvmem_populate_layout(struct nvmem_device *nvmem) 51 + { 52 + return 0; 53 + } 54 + 55 + static inline void nvmem_destroy_layout(struct nvmem_device *nvmem) { } 56 + #endif /* CONFIG_OF */ 57 + 37 58 #endif /* ifndef _LINUX_NVMEM_INTERNALS_H */
+201
drivers/nvmem/layouts.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * NVMEM layout bus handling 4 + * 5 + * Copyright (C) 2023 Bootlin 6 + * Author: Miquel Raynal <miquel.raynal@bootlin.com 7 + */ 8 + 9 + #include <linux/device.h> 10 + #include <linux/dma-mapping.h> 11 + #include <linux/nvmem-consumer.h> 12 + #include <linux/nvmem-provider.h> 13 + #include <linux/of.h> 14 + #include <linux/of_device.h> 15 + #include <linux/of_irq.h> 16 + 17 + #include "internals.h" 18 + 19 + #define to_nvmem_layout_driver(drv) \ 20 + (container_of((drv), struct nvmem_layout_driver, driver)) 21 + #define to_nvmem_layout_device(_dev) \ 22 + container_of((_dev), struct nvmem_layout, dev) 23 + 24 + static int nvmem_layout_bus_match(struct device *dev, struct device_driver *drv) 25 + { 26 + return of_driver_match_device(dev, drv); 27 + } 28 + 29 + static int nvmem_layout_bus_probe(struct device *dev) 30 + { 31 + struct nvmem_layout_driver *drv = to_nvmem_layout_driver(dev->driver); 32 + struct nvmem_layout *layout = to_nvmem_layout_device(dev); 33 + 34 + if (!drv->probe || !drv->remove) 35 + return -EINVAL; 36 + 37 + return drv->probe(layout); 38 + } 39 + 40 + static void nvmem_layout_bus_remove(struct device *dev) 41 + { 42 + struct nvmem_layout_driver *drv = to_nvmem_layout_driver(dev->driver); 43 + struct nvmem_layout *layout = to_nvmem_layout_device(dev); 44 + 45 + return drv->remove(layout); 46 + } 47 + 48 + static struct bus_type nvmem_layout_bus_type = { 49 + .name = "nvmem-layout", 50 + .match = nvmem_layout_bus_match, 51 + .probe = nvmem_layout_bus_probe, 52 + .remove = nvmem_layout_bus_remove, 53 + }; 54 + 55 + int nvmem_layout_driver_register(struct nvmem_layout_driver *drv) 56 + { 57 + drv->driver.bus = &nvmem_layout_bus_type; 58 + 59 + return driver_register(&drv->driver); 60 + } 61 + EXPORT_SYMBOL_GPL(nvmem_layout_driver_register); 62 + 63 + void nvmem_layout_driver_unregister(struct nvmem_layout_driver *drv) 64 + { 65 + driver_unregister(&drv->driver); 66 + } 67 + EXPORT_SYMBOL_GPL(nvmem_layout_driver_unregister); 68 + 69 + static void nvmem_layout_release_device(struct device *dev) 70 + { 71 + struct nvmem_layout *layout = to_nvmem_layout_device(dev); 72 + 73 + of_node_put(layout->dev.of_node); 74 + kfree(layout); 75 + } 76 + 77 + static int nvmem_layout_create_device(struct nvmem_device *nvmem, 78 + struct device_node *np) 79 + { 80 + struct nvmem_layout *layout; 81 + struct device *dev; 82 + int ret; 83 + 84 + layout = kzalloc(sizeof(*layout), GFP_KERNEL); 85 + if (!layout) 86 + return -ENOMEM; 87 + 88 + /* Create a bidirectional link */ 89 + layout->nvmem = nvmem; 90 + nvmem->layout = layout; 91 + 92 + /* Device model registration */ 93 + dev = &layout->dev; 94 + device_initialize(dev); 95 + dev->parent = &nvmem->dev; 96 + dev->bus = &nvmem_layout_bus_type; 97 + dev->release = nvmem_layout_release_device; 98 + dev->coherent_dma_mask = DMA_BIT_MASK(32); 99 + dev->dma_mask = &dev->coherent_dma_mask; 100 + device_set_node(dev, of_fwnode_handle(of_node_get(np))); 101 + of_device_make_bus_id(dev); 102 + of_msi_configure(dev, dev->of_node); 103 + 104 + ret = device_add(dev); 105 + if (ret) { 106 + put_device(dev); 107 + return ret; 108 + } 109 + 110 + return 0; 111 + } 112 + 113 + static const struct of_device_id of_nvmem_layout_skip_table[] = { 114 + { .compatible = "fixed-layout", }, 115 + {} 116 + }; 117 + 118 + static int nvmem_layout_bus_populate(struct nvmem_device *nvmem, 119 + struct device_node *layout_dn) 120 + { 121 + int ret; 122 + 123 + /* Make sure it has a compatible property */ 124 + if (!of_get_property(layout_dn, "compatible", NULL)) { 125 + pr_debug("%s() - skipping %pOF, no compatible prop\n", 126 + __func__, layout_dn); 127 + return 0; 128 + } 129 + 130 + /* Fixed layouts are parsed manually somewhere else for now */ 131 + if (of_match_node(of_nvmem_layout_skip_table, layout_dn)) { 132 + pr_debug("%s() - skipping %pOF node\n", __func__, layout_dn); 133 + return 0; 134 + } 135 + 136 + if (of_node_check_flag(layout_dn, OF_POPULATED_BUS)) { 137 + pr_debug("%s() - skipping %pOF, already populated\n", 138 + __func__, layout_dn); 139 + 140 + return 0; 141 + } 142 + 143 + /* NVMEM layout buses expect only a single device representing the layout */ 144 + ret = nvmem_layout_create_device(nvmem, layout_dn); 145 + if (ret) 146 + return ret; 147 + 148 + of_node_set_flag(layout_dn, OF_POPULATED_BUS); 149 + 150 + return 0; 151 + } 152 + 153 + struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvmem) 154 + { 155 + return of_get_child_by_name(nvmem->dev.of_node, "nvmem-layout"); 156 + } 157 + EXPORT_SYMBOL_GPL(of_nvmem_layout_get_container); 158 + 159 + /* 160 + * Returns the number of devices populated, 0 if the operation was not relevant 161 + * for this nvmem device, an error code otherwise. 162 + */ 163 + int nvmem_populate_layout(struct nvmem_device *nvmem) 164 + { 165 + struct device_node *layout_dn; 166 + int ret; 167 + 168 + layout_dn = of_nvmem_layout_get_container(nvmem); 169 + if (!layout_dn) 170 + return 0; 171 + 172 + /* Populate the layout device */ 173 + device_links_supplier_sync_state_pause(); 174 + ret = nvmem_layout_bus_populate(nvmem, layout_dn); 175 + device_links_supplier_sync_state_resume(); 176 + 177 + of_node_put(layout_dn); 178 + return ret; 179 + } 180 + 181 + void nvmem_destroy_layout(struct nvmem_device *nvmem) 182 + { 183 + struct device *dev; 184 + 185 + if (!nvmem->layout) 186 + return; 187 + 188 + dev = &nvmem->layout->dev; 189 + of_node_clear_flag(dev->of_node, OF_POPULATED_BUS); 190 + device_unregister(dev); 191 + } 192 + 193 + int nvmem_layout_bus_register(void) 194 + { 195 + return bus_register(&nvmem_layout_bus_type); 196 + } 197 + 198 + void nvmem_layout_bus_unregister(void) 199 + { 200 + bus_unregister(&nvmem_layout_bus_type); 201 + }
+8
drivers/nvmem/layouts/Kconfig
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 + config NVMEM_LAYOUTS 4 + bool 5 + depends on OF 6 + 7 + if NVMEM_LAYOUTS 8 + 3 9 menu "Layout Types" 4 10 5 11 config NVMEM_LAYOUT_SL28_VPD ··· 27 21 If unsure, say N. 28 22 29 23 endmenu 24 + 25 + endif
+20 -4
drivers/nvmem/layouts/onie-tlv.c
··· 225 225 return 0; 226 226 } 227 227 228 + static int onie_tlv_probe(struct nvmem_layout *layout) 229 + { 230 + layout->add_cells = onie_tlv_parse_table; 231 + 232 + return nvmem_layout_register(layout); 233 + } 234 + 235 + static void onie_tlv_remove(struct nvmem_layout *layout) 236 + { 237 + nvmem_layout_unregister(layout); 238 + } 239 + 228 240 static const struct of_device_id onie_tlv_of_match_table[] = { 229 241 { .compatible = "onie,tlv-layout", }, 230 242 {}, 231 243 }; 232 244 MODULE_DEVICE_TABLE(of, onie_tlv_of_match_table); 233 245 234 - static struct nvmem_layout onie_tlv_layout = { 235 - .name = "ONIE tlv layout", 236 - .of_match_table = onie_tlv_of_match_table, 237 - .add_cells = onie_tlv_parse_table, 246 + static struct nvmem_layout_driver onie_tlv_layout = { 247 + .driver = { 248 + .owner = THIS_MODULE, 249 + .name = "onie-tlv-layout", 250 + .of_match_table = onie_tlv_of_match_table, 251 + }, 252 + .probe = onie_tlv_probe, 253 + .remove = onie_tlv_remove, 238 254 }; 239 255 module_nvmem_layout_driver(onie_tlv_layout); 240 256
+20 -4
drivers/nvmem/layouts/sl28vpd.c
··· 134 134 return 0; 135 135 } 136 136 137 + static int sl28vpd_probe(struct nvmem_layout *layout) 138 + { 139 + layout->add_cells = sl28vpd_add_cells; 140 + 141 + return nvmem_layout_register(layout); 142 + } 143 + 144 + static void sl28vpd_remove(struct nvmem_layout *layout) 145 + { 146 + nvmem_layout_unregister(layout); 147 + } 148 + 137 149 static const struct of_device_id sl28vpd_of_match_table[] = { 138 150 { .compatible = "kontron,sl28-vpd" }, 139 151 {}, 140 152 }; 141 153 MODULE_DEVICE_TABLE(of, sl28vpd_of_match_table); 142 154 143 - static struct nvmem_layout sl28vpd_layout = { 144 - .name = "sl28-vpd", 145 - .of_match_table = sl28vpd_of_match_table, 146 - .add_cells = sl28vpd_add_cells, 155 + static struct nvmem_layout_driver sl28vpd_layout = { 156 + .driver = { 157 + .owner = THIS_MODULE, 158 + .name = "kontron-sl28vpd-layout", 159 + .of_match_table = sl28vpd_of_match_table, 160 + }, 161 + .probe = sl28vpd_probe, 162 + .remove = sl28vpd_remove, 147 163 }; 148 164 module_nvmem_layout_driver(sl28vpd_layout); 149 165
+20 -18
include/linux/nvmem-provider.h
··· 9 9 #ifndef _LINUX_NVMEM_PROVIDER_H 10 10 #define _LINUX_NVMEM_PROVIDER_H 11 11 12 + #include <linux/device.h> 12 13 #include <linux/device/driver.h> 13 14 #include <linux/err.h> 14 15 #include <linux/errno.h> ··· 159 158 /** 160 159 * struct nvmem_layout - NVMEM layout definitions 161 160 * 162 - * @name: Layout name. 163 - * @of_match_table: Open firmware match table. 164 - * @add_cells: Called to populate the layout using 165 - * nvmem_add_one_cell(). 166 - * @owner: Pointer to struct module. 167 - * @node: List node. 161 + * @dev: Device-model layout device. 162 + * @nvmem: The underlying NVMEM device 163 + * @add_cells: Will be called if a nvmem device is found which 164 + * has this layout. The function will add layout 165 + * specific cells with nvmem_add_one_cell(). 168 166 * 169 167 * A nvmem device can hold a well defined structure which can just be 170 168 * evaluated during runtime. For example a TLV list, or a list of "name=val" ··· 171 171 * cells. 172 172 */ 173 173 struct nvmem_layout { 174 - const char *name; 175 - const struct of_device_id *of_match_table; 174 + struct device dev; 175 + struct nvmem_device *nvmem; 176 176 int (*add_cells)(struct device *dev, struct nvmem_device *nvmem); 177 + }; 177 178 178 - /* private */ 179 - struct module *owner; 180 - struct list_head node; 179 + struct nvmem_layout_driver { 180 + struct device_driver driver; 181 + int (*probe)(struct nvmem_layout *layout); 182 + void (*remove)(struct nvmem_layout *layout); 181 183 }; 182 184 183 185 #if IS_ENABLED(CONFIG_NVMEM) ··· 196 194 int nvmem_add_one_cell(struct nvmem_device *nvmem, 197 195 const struct nvmem_cell_info *info); 198 196 199 - int __nvmem_layout_register(struct nvmem_layout *layout, struct module *owner); 200 - #define nvmem_layout_register(layout) \ 201 - __nvmem_layout_register(layout, THIS_MODULE) 197 + int nvmem_layout_register(struct nvmem_layout *layout); 202 198 void nvmem_layout_unregister(struct nvmem_layout *layout); 199 + 200 + int nvmem_layout_driver_register(struct nvmem_layout_driver *drv); 201 + void nvmem_layout_driver_unregister(struct nvmem_layout_driver *drv); 202 + #define module_nvmem_layout_driver(__nvmem_layout_driver) \ 203 + module_driver(__nvmem_layout_driver, nvmem_layout_driver_register, \ 204 + nvmem_layout_driver_unregister) 203 205 204 206 const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem, 205 207 struct nvmem_layout *layout); ··· 267 261 } 268 262 269 263 #endif /* CONFIG_NVMEM && CONFIG_OF */ 270 - 271 - #define module_nvmem_layout_driver(__layout_driver) \ 272 - module_driver(__layout_driver, nvmem_layout_register, \ 273 - nvmem_layout_unregister) 274 264 275 265 #endif /* ifndef _LINUX_NVMEM_PROVIDER_H */