|
16 | 16 |
|
17 | 17 | #define pr_fmt(fmt) "OF: " fmt
|
18 | 18 |
|
| 19 | +#include <linux/bitmap.h> |
19 | 20 | #include <linux/console.h>
|
20 | 21 | #include <linux/ctype.h>
|
21 | 22 | #include <linux/cpu.h>
|
@@ -1942,6 +1943,57 @@ int of_alias_get_id(struct device_node *np, const char *stem)
|
1942 | 1943 | }
|
1943 | 1944 | EXPORT_SYMBOL_GPL(of_alias_get_id);
|
1944 | 1945 |
|
| 1946 | +/** |
| 1947 | + * of_alias_get_alias_list - Get alias list for the given device driver |
| 1948 | + * @matches: Array of OF device match structures to search in |
| 1949 | + * @stem: Alias stem of the given device_node |
| 1950 | + * @bitmap: Bitmap field pointer |
| 1951 | + * @nbits: Maximum number of alias ID which can be recorded it bitmap |
| 1952 | + * |
| 1953 | + * The function travels the lookup table to record alias ids for the given |
| 1954 | + * device match structures and alias stem. |
| 1955 | + * |
| 1956 | + * Return: 0 or -ENOSYS when !CONFIG_OF |
| 1957 | + */ |
| 1958 | +int of_alias_get_alias_list(const struct of_device_id *matches, |
| 1959 | + const char *stem, unsigned long *bitmap, |
| 1960 | + unsigned int nbits) |
| 1961 | +{ |
| 1962 | + struct alias_prop *app; |
| 1963 | + |
| 1964 | + /* Zero bitmap field to make sure that all the time it is clean */ |
| 1965 | + bitmap_zero(bitmap, nbits); |
| 1966 | + |
| 1967 | + mutex_lock(&of_mutex); |
| 1968 | + pr_debug("%s: Looking for stem: %s\n", __func__, stem); |
| 1969 | + list_for_each_entry(app, &aliases_lookup, link) { |
| 1970 | + pr_debug("%s: stem: %s, id: %d\n", |
| 1971 | + __func__, app->stem, app->id); |
| 1972 | + |
| 1973 | + if (strcmp(app->stem, stem) != 0) { |
| 1974 | + pr_debug("%s: stem comparison doesn't passed %s\n", |
| 1975 | + __func__, app->stem); |
| 1976 | + continue; |
| 1977 | + } |
| 1978 | + |
| 1979 | + if (app->id >= nbits) { |
| 1980 | + pr_debug("%s: ID %d greater then bitmap field %d\n", |
| 1981 | + __func__, app->id, nbits); |
| 1982 | + continue; |
| 1983 | + } |
| 1984 | + |
| 1985 | + if (of_match_node(matches, app->np)) { |
| 1986 | + pr_debug("%s: Allocated ID %d\n", __func__, app->id); |
| 1987 | + set_bit(app->id, bitmap); |
| 1988 | + } |
| 1989 | + /* Alias exist but it not compatible with matches */ |
| 1990 | + } |
| 1991 | + mutex_unlock(&of_mutex); |
| 1992 | + |
| 1993 | + return 0; |
| 1994 | +} |
| 1995 | +EXPORT_SYMBOL_GPL(of_alias_get_alias_list); |
| 1996 | + |
1945 | 1997 | /**
|
1946 | 1998 | * of_alias_get_highest_id - Get highest alias id for the given stem
|
1947 | 1999 | * @stem: Alias stem to be examined
|
|
0 commit comments