Lines Matching +full:nvmem +full:- +full:layout

1 // SPDX-License-Identifier: GPL-2.0
3 * NVMEM layout bus handling
10 #include <linux/dma-mapping.h>
11 #include <linux/nvmem-consumer.h>
12 #include <linux/nvmem-provider.h>
31 struct nvmem_layout_driver *drv = to_nvmem_layout_driver(dev->driver); in nvmem_layout_bus_probe()
32 struct nvmem_layout *layout = to_nvmem_layout_device(dev); in nvmem_layout_bus_probe() local
34 if (!drv->probe || !drv->remove) in nvmem_layout_bus_probe()
35 return -EINVAL; in nvmem_layout_bus_probe()
37 return drv->probe(layout); in nvmem_layout_bus_probe()
42 struct nvmem_layout_driver *drv = to_nvmem_layout_driver(dev->driver); in nvmem_layout_bus_remove()
43 struct nvmem_layout *layout = to_nvmem_layout_device(dev); in nvmem_layout_bus_remove() local
45 return drv->remove(layout); in nvmem_layout_bus_remove()
49 .name = "nvmem-layout",
58 drv->driver.bus = &nvmem_layout_bus_type; in __nvmem_layout_driver_register()
59 drv->driver.owner = owner; in __nvmem_layout_driver_register()
61 return driver_register(&drv->driver); in __nvmem_layout_driver_register()
67 driver_unregister(&drv->driver); in nvmem_layout_driver_unregister()
73 struct nvmem_layout *layout = to_nvmem_layout_device(dev); in nvmem_layout_release_device() local
75 of_node_put(layout->dev.of_node); in nvmem_layout_release_device()
76 kfree(layout); in nvmem_layout_release_device()
79 static int nvmem_layout_create_device(struct nvmem_device *nvmem, in nvmem_layout_create_device() argument
82 struct nvmem_layout *layout; in nvmem_layout_create_device() local
86 layout = kzalloc(sizeof(*layout), GFP_KERNEL); in nvmem_layout_create_device()
87 if (!layout) in nvmem_layout_create_device()
88 return -ENOMEM; in nvmem_layout_create_device()
91 layout->nvmem = nvmem; in nvmem_layout_create_device()
92 nvmem->layout = layout; in nvmem_layout_create_device()
95 dev = &layout->dev; in nvmem_layout_create_device()
97 dev->parent = &nvmem->dev; in nvmem_layout_create_device()
98 dev->bus = &nvmem_layout_bus_type; in nvmem_layout_create_device()
99 dev->release = nvmem_layout_release_device; in nvmem_layout_create_device()
100 dev->coherent_dma_mask = DMA_BIT_MASK(32); in nvmem_layout_create_device()
101 dev->dma_mask = &dev->coherent_dma_mask; in nvmem_layout_create_device()
104 of_msi_configure(dev, dev->of_node); in nvmem_layout_create_device()
116 { .compatible = "fixed-layout", },
120 static int nvmem_layout_bus_populate(struct nvmem_device *nvmem, in nvmem_layout_bus_populate() argument
127 pr_debug("%s() - skipping %pOF, no compatible prop\n", in nvmem_layout_bus_populate()
134 pr_debug("%s() - skipping %pOF node\n", __func__, layout_dn); in nvmem_layout_bus_populate()
139 pr_debug("%s() - skipping %pOF, already populated\n", in nvmem_layout_bus_populate()
145 /* NVMEM layout buses expect only a single device representing the layout */ in nvmem_layout_bus_populate()
146 ret = nvmem_layout_create_device(nvmem, layout_dn); in nvmem_layout_bus_populate()
155 struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvmem) in of_nvmem_layout_get_container() argument
157 return of_get_child_by_name(nvmem->dev.of_node, "nvmem-layout"); in of_nvmem_layout_get_container()
163 * for this nvmem device, an error code otherwise.
165 int nvmem_populate_layout(struct nvmem_device *nvmem) in nvmem_populate_layout() argument
170 layout_dn = of_nvmem_layout_get_container(nvmem); in nvmem_populate_layout()
174 /* Populate the layout device */ in nvmem_populate_layout()
176 ret = nvmem_layout_bus_populate(nvmem, layout_dn); in nvmem_populate_layout()
183 void nvmem_destroy_layout(struct nvmem_device *nvmem) in nvmem_destroy_layout() argument
187 if (!nvmem->layout) in nvmem_destroy_layout()
190 dev = &nvmem->layout->dev; in nvmem_destroy_layout()
191 of_node_clear_flag(dev->of_node, OF_POPULATED_BUS); in nvmem_destroy_layout()