Commit bd7a7ed7 authored by Miquel Raynal's avatar Miquel Raynal Committed by Greg Kroah-Hartman

of: Move of_modalias() to module.c

Create a specific .c file for OF related module handling.
Move of_modalias() inside as a first step.

The helper is exposed through of.h even though it is only used by core
files because the users from device.c will soon be split into an OF-only
helper in module.c as well as a device-oriented inline helper in
of_device.h. Putting this helper in of_private.h would require to
include of_private.h from of_device.h, which is not acceptable.
Suggested-by: default avatarRob Herring <robh+dt@kernel.org>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20230404172148.82422-10-srinivas.kandagatla@linaro.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 673aa1ed
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
obj-y = base.o device.o platform.o property.o obj-y = base.o device.o module.o platform.o property.o
obj-$(CONFIG_OF_KOBJ) += kobj.o obj-$(CONFIG_OF_KOBJ) += kobj.o
obj-$(CONFIG_OF_DYNAMIC) += dynamic.o obj-$(CONFIG_OF_DYNAMIC) += dynamic.o
obj-$(CONFIG_OF_FLATTREE) += fdt.o obj-$(CONFIG_OF_FLATTREE) += fdt.o
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include <linux/string.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_device.h> #include <linux/of_device.h>
...@@ -248,42 +247,6 @@ const void *of_device_get_match_data(const struct device *dev) ...@@ -248,42 +247,6 @@ const void *of_device_get_match_data(const struct device *dev)
} }
EXPORT_SYMBOL(of_device_get_match_data); EXPORT_SYMBOL(of_device_get_match_data);
static ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len)
{
const char *compat;
char *c;
struct property *p;
ssize_t csize;
ssize_t tsize;
/* Name & Type */
/* %p eats all alphanum characters, so %c must be used here */
csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T',
of_node_get_device_type(np));
tsize = csize;
len -= csize;
if (str)
str += csize;
of_property_for_each_string(np, "compatible", p, compat) {
csize = strlen(compat) + 1;
tsize += csize;
if (csize > len)
continue;
csize = snprintf(str, len, "C%s", compat);
for (c = str; c; ) {
c = strchr(c, ' ');
if (c)
*c++ = '_';
}
len -= csize;
str += csize;
}
return tsize;
}
int of_device_request_module(struct device *dev) int of_device_request_module(struct device *dev)
{ {
char *str; char *str;
......
// SPDX-License-Identifier: GPL-2.0
/*
* Linux kernel module helpers.
*/
#include <linux/of.h>
#include <linux/slab.h>
#include <linux/string.h>
ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len)
{
const char *compat;
char *c;
struct property *p;
ssize_t csize;
ssize_t tsize;
/* Name & Type */
/* %p eats all alphanum characters, so %c must be used here */
csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T',
of_node_get_device_type(np));
tsize = csize;
len -= csize;
if (str)
str += csize;
of_property_for_each_string(np, "compatible", p, compat) {
csize = strlen(compat) + 1;
tsize += csize;
if (csize > len)
continue;
csize = snprintf(str, len, "C%s", compat);
for (c = str; c; ) {
c = strchr(c, ' ');
if (c)
*c++ = '_';
}
len -= csize;
str += csize;
}
return tsize;
}
...@@ -385,6 +385,9 @@ extern int of_parse_phandle_with_args_map(const struct device_node *np, ...@@ -385,6 +385,9 @@ extern int of_parse_phandle_with_args_map(const struct device_node *np,
extern int of_count_phandle_with_args(const struct device_node *np, extern int of_count_phandle_with_args(const struct device_node *np,
const char *list_name, const char *cells_name); const char *list_name, const char *cells_name);
/* module functions */
extern ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len);
/* phandle iterator functions */ /* phandle iterator functions */
extern int of_phandle_iterator_init(struct of_phandle_iterator *it, extern int of_phandle_iterator_init(struct of_phandle_iterator *it,
const struct device_node *np, const struct device_node *np,
...@@ -742,6 +745,12 @@ static inline int of_count_phandle_with_args(const struct device_node *np, ...@@ -742,6 +745,12 @@ static inline int of_count_phandle_with_args(const struct device_node *np,
return -ENOSYS; return -ENOSYS;
} }
static inline ssize_t of_modalias(const struct device_node *np, char *str,
ssize_t len)
{
return -ENODEV;
}
static inline int of_phandle_iterator_init(struct of_phandle_iterator *it, static inline int of_phandle_iterator_init(struct of_phandle_iterator *it,
const struct device_node *np, const struct device_node *np,
const char *list_name, const char *list_name,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment