core.c (ca712e47054678c5ce93a0e0f686353ad5561195) | core.c (266570f496b90dea8fda893c2cf7c28d63ae2bd9) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * nvmem framework core. 4 * 5 * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org> 6 * Copyright (C) 2013 Maxime Ripard <maxime.ripard@free-electrons.com> 7 */ 8 --- 26 unchanged lines hidden (view full) --- 35 struct device *base_dev; 36 struct list_head cells; 37 const struct nvmem_keepout *keepout; 38 unsigned int nkeepout; 39 nvmem_reg_read_t reg_read; 40 nvmem_reg_write_t reg_write; 41 nvmem_cell_post_process_t cell_post_process; 42 struct gpio_desc *wp_gpio; | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * nvmem framework core. 4 * 5 * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org> 6 * Copyright (C) 2013 Maxime Ripard <maxime.ripard@free-electrons.com> 7 */ 8 --- 26 unchanged lines hidden (view full) --- 35 struct device *base_dev; 36 struct list_head cells; 37 const struct nvmem_keepout *keepout; 38 unsigned int nkeepout; 39 nvmem_reg_read_t reg_read; 40 nvmem_reg_write_t reg_write; 41 nvmem_cell_post_process_t cell_post_process; 42 struct gpio_desc *wp_gpio; |
43 struct nvmem_layout *layout; |
|
43 void *priv; 44}; 45 46#define to_nvmem_device(d) container_of(d, struct nvmem_device, dev) 47 48#define FLAG_COMPAT BIT(0) 49struct nvmem_cell_entry { 50 const char *name; --- 18 unchanged lines hidden (view full) --- 69static DEFINE_MUTEX(nvmem_cell_mutex); 70static LIST_HEAD(nvmem_cell_tables); 71 72static DEFINE_MUTEX(nvmem_lookup_mutex); 73static LIST_HEAD(nvmem_lookup_list); 74 75static BLOCKING_NOTIFIER_HEAD(nvmem_notifier); 76 | 44 void *priv; 45}; 46 47#define to_nvmem_device(d) container_of(d, struct nvmem_device, dev) 48 49#define FLAG_COMPAT BIT(0) 50struct nvmem_cell_entry { 51 const char *name; --- 18 unchanged lines hidden (view full) --- 70static DEFINE_MUTEX(nvmem_cell_mutex); 71static LIST_HEAD(nvmem_cell_tables); 72 73static DEFINE_MUTEX(nvmem_lookup_mutex); 74static LIST_HEAD(nvmem_lookup_list); 75 76static BLOCKING_NOTIFIER_HEAD(nvmem_notifier); 77 |
78static DEFINE_SPINLOCK(nvmem_layout_lock); 79static LIST_HEAD(nvmem_layouts); 80 |
|
77static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset, 78 void *val, size_t bytes) 79{ 80 if (nvmem->reg_read) 81 return nvmem->reg_read(nvmem->priv, offset, val, bytes); 82 83 return -EINVAL; 84} --- 638 unchanged lines hidden (view full) --- 723 of_node_put(child); 724 return ret; 725 } 726 } 727 728 return 0; 729} 730 | 81static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset, 82 void *val, size_t bytes) 83{ 84 if (nvmem->reg_read) 85 return nvmem->reg_read(nvmem->priv, offset, val, bytes); 86 87 return -EINVAL; 88} --- 638 unchanged lines hidden (view full) --- 727 of_node_put(child); 728 return ret; 729 } 730 } 731 732 return 0; 733} 734 |
735int __nvmem_layout_register(struct nvmem_layout *layout, struct module *owner) 736{ 737 layout->owner = owner; 738 739 spin_lock(&nvmem_layout_lock); 740 list_add(&layout->node, &nvmem_layouts); 741 spin_unlock(&nvmem_layout_lock); 742 743 return 0; 744} 745EXPORT_SYMBOL_GPL(__nvmem_layout_register); 746 747void nvmem_layout_unregister(struct nvmem_layout *layout) 748{ 749 spin_lock(&nvmem_layout_lock); 750 list_del(&layout->node); 751 spin_unlock(&nvmem_layout_lock); 752} 753EXPORT_SYMBOL_GPL(nvmem_layout_unregister); 754 755static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem) 756{ 757 struct device_node *layout_np, *np = nvmem->dev.of_node; 758 struct nvmem_layout *l, *layout = NULL; 759 760 layout_np = of_get_child_by_name(np, "nvmem-layout"); 761 if (!layout_np) 762 return NULL; 763 764 spin_lock(&nvmem_layout_lock); 765 766 list_for_each_entry(l, &nvmem_layouts, node) { 767 if (of_match_node(l->of_match_table, layout_np)) { 768 if (try_module_get(l->owner)) 769 layout = l; 770 771 break; 772 } 773 } 774 775 spin_unlock(&nvmem_layout_lock); 776 of_node_put(layout_np); 777 778 return layout; 779} 780 781static void nvmem_layout_put(struct nvmem_layout *layout) 782{ 783 if (layout) 784 module_put(layout->owner); 785} 786 787static int nvmem_add_cells_from_layout(struct nvmem_device *nvmem) 788{ 789 struct nvmem_layout *layout = nvmem->layout; 790 int ret; 791 792 if (layout && layout->add_cells) { 793 ret = layout->add_cells(&nvmem->dev, nvmem, layout); 794 if (ret) 795 return ret; 796 } 797 798 return 0; 799} 800 801#if IS_ENABLED(CONFIG_OF) |
|
731/** | 802/** |
803 * of_nvmem_layout_get_container() - Get OF node to layout container. 804 * 805 * @nvmem: nvmem device. 806 * 807 * Return: a node pointer with refcount incremented or NULL if no 808 * container exists. Use of_node_put() on it when done. 809 */ 810struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvmem) 811{ 812 return of_get_child_by_name(nvmem->dev.of_node, "nvmem-layout"); 813} 814EXPORT_SYMBOL_GPL(of_nvmem_layout_get_container); 815#endif 816 817const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem, 818 struct nvmem_layout *layout) 819{ 820 struct device_node __maybe_unused *layout_np; 821 const struct of_device_id *match; 822 823 layout_np = of_nvmem_layout_get_container(nvmem); 824 match = of_match_node(layout->of_match_table, layout_np); 825 826 return match ? match->data : NULL; 827} 828EXPORT_SYMBOL_GPL(nvmem_layout_get_match_data); 829 830/** |
|
732 * nvmem_register() - Register a nvmem device for given nvmem_config. 733 * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem 734 * 735 * @config: nvmem device configuration with which nvmem device is created. 736 * 737 * Return: Will be an ERR_PTR() on error or a valid pointer to nvmem_device 738 * on success. 739 */ --- 89 unchanged lines hidden (view full) --- 829 } 830 831 if (config->compat) { 832 rval = nvmem_sysfs_setup_compat(nvmem, config); 833 if (rval) 834 goto err_put_device; 835 } 836 | 831 * nvmem_register() - Register a nvmem device for given nvmem_config. 832 * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem 833 * 834 * @config: nvmem device configuration with which nvmem device is created. 835 * 836 * Return: Will be an ERR_PTR() on error or a valid pointer to nvmem_device 837 * on success. 838 */ --- 89 unchanged lines hidden (view full) --- 928 } 929 930 if (config->compat) { 931 rval = nvmem_sysfs_setup_compat(nvmem, config); 932 if (rval) 933 goto err_put_device; 934 } 935 |
936 /* 937 * If the driver supplied a layout by config->layout, the module 938 * pointer will be NULL and nvmem_layout_put() will be a noop. 939 */ 940 nvmem->layout = config->layout ?: nvmem_layout_get(nvmem); 941 |
|
837 if (config->cells) { 838 rval = nvmem_add_cells(nvmem, config->cells, config->ncells); 839 if (rval) 840 goto err_remove_cells; 841 } 842 843 rval = nvmem_add_cells_from_table(nvmem); 844 if (rval) --- 4 unchanged lines hidden (view full) --- 849 goto err_remove_cells; 850 851 dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); 852 853 rval = device_add(&nvmem->dev); 854 if (rval) 855 goto err_remove_cells; 856 | 942 if (config->cells) { 943 rval = nvmem_add_cells(nvmem, config->cells, config->ncells); 944 if (rval) 945 goto err_remove_cells; 946 } 947 948 rval = nvmem_add_cells_from_table(nvmem); 949 if (rval) --- 4 unchanged lines hidden (view full) --- 954 goto err_remove_cells; 955 956 dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); 957 958 rval = device_add(&nvmem->dev); 959 if (rval) 960 goto err_remove_cells; 961 |
962 rval = nvmem_add_cells_from_layout(nvmem); 963 if (rval) 964 goto err_remove_cells; 965 |
|
857 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); 858 859 return nvmem; 860 861err_remove_cells: 862 nvmem_device_remove_all_cells(nvmem); | 966 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); 967 968 return nvmem; 969 970err_remove_cells: 971 nvmem_device_remove_all_cells(nvmem); |
972 nvmem_layout_put(nvmem->layout); |
|
863 if (config->compat) 864 nvmem_sysfs_remove_compat(nvmem, config); 865err_put_device: 866 put_device(&nvmem->dev); 867 868 return ERR_PTR(rval); 869} 870EXPORT_SYMBOL_GPL(nvmem_register); --- 5 unchanged lines hidden (view full) --- 876 nvmem = container_of(kref, struct nvmem_device, refcnt); 877 878 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_REMOVE, nvmem); 879 880 if (nvmem->flags & FLAG_COMPAT) 881 device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); 882 883 nvmem_device_remove_all_cells(nvmem); | 973 if (config->compat) 974 nvmem_sysfs_remove_compat(nvmem, config); 975err_put_device: 976 put_device(&nvmem->dev); 977 978 return ERR_PTR(rval); 979} 980EXPORT_SYMBOL_GPL(nvmem_register); --- 5 unchanged lines hidden (view full) --- 986 nvmem = container_of(kref, struct nvmem_device, refcnt); 987 988 blocking_notifier_call_chain(&nvmem_notifier, NVMEM_REMOVE, nvmem); 989 990 if (nvmem->flags & FLAG_COMPAT) 991 device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); 992 993 nvmem_device_remove_all_cells(nvmem); |
994 nvmem_layout_put(nvmem->layout); |
|
884 device_unregister(&nvmem->dev); 885} 886 887/** 888 * nvmem_unregister() - Unregister previously registered nvmem device 889 * 890 * @nvmem: Pointer to previously registered nvmem device. 891 */ --- 349 unchanged lines hidden (view full) --- 1241 cell_index = cell_spec.args[0]; 1242 1243 nvmem_np = of_get_parent(cell_np); 1244 if (!nvmem_np) { 1245 of_node_put(cell_np); 1246 return ERR_PTR(-EINVAL); 1247 } 1248 | 995 device_unregister(&nvmem->dev); 996} 997 998/** 999 * nvmem_unregister() - Unregister previously registered nvmem device 1000 * 1001 * @nvmem: Pointer to previously registered nvmem device. 1002 */ --- 349 unchanged lines hidden (view full) --- 1352 cell_index = cell_spec.args[0]; 1353 1354 nvmem_np = of_get_parent(cell_np); 1355 if (!nvmem_np) { 1356 of_node_put(cell_np); 1357 return ERR_PTR(-EINVAL); 1358 } 1359 |
1360 /* nvmem layouts produce cells within the nvmem-layout container */ 1361 if (of_node_name_eq(nvmem_np, "nvmem-layout")) { 1362 nvmem_np = of_get_next_parent(nvmem_np); 1363 if (!nvmem_np) { 1364 of_node_put(cell_np); 1365 return ERR_PTR(-EINVAL); 1366 } 1367 } 1368 |
|
1249 nvmem = __nvmem_device_get(nvmem_np, device_match_of_node); 1250 of_node_put(nvmem_np); 1251 if (IS_ERR(nvmem)) { 1252 of_node_put(cell_np); 1253 return ERR_CAST(nvmem); 1254 } 1255 1256 cell_entry = nvmem_find_cell_entry_by_node(nvmem, cell_np); --- 705 unchanged lines hidden --- | 1369 nvmem = __nvmem_device_get(nvmem_np, device_match_of_node); 1370 of_node_put(nvmem_np); 1371 if (IS_ERR(nvmem)) { 1372 of_node_put(cell_np); 1373 return ERR_CAST(nvmem); 1374 } 1375 1376 cell_entry = nvmem_find_cell_entry_by_node(nvmem, cell_np); --- 705 unchanged lines hidden --- |