nrhw20,24: board: respect ngpios entry
determine number of gpio entries in ft_set_gpio_name() BugzId: 60387
This commit is contained in:
parent
a583bb6eea
commit
2844abe1c2
|
|
@ -1273,33 +1273,55 @@ static void ft_enable_node(void* blob, const char* name)
|
|||
static void ft_set_gpio_name(void *blob, const char* gpio, int pin, const char* name)
|
||||
{
|
||||
int node_ofs = fdt_path_offset(blob, gpio);
|
||||
if (node_ofs != -1) {
|
||||
const struct fdt_property* prop = fdt_get_property(blob, node_ofs, "gpio-line-names", NULL);
|
||||
if (prop != NULL) {
|
||||
int gpios = -1;
|
||||
const char* text;
|
||||
int pos = 0;
|
||||
int i;
|
||||
char buffer[512];
|
||||
|
||||
/* TODO: Determine number of entries from ngpios field */
|
||||
if (node_ofs == -1) {
|
||||
printf("Can't find node %s\n", gpio);
|
||||
goto end;
|
||||
}
|
||||
|
||||
for (i=0; i<32; i++) {
|
||||
/* get number of IOs in node */
|
||||
gpios = fdt_getprop_u32_default_node(blob, node_ofs, 0, "ngpios", -1);
|
||||
if (gpios == -1 || gpios > 64) {
|
||||
printf("Illegal number of gpios %d\n", gpios);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* get string array with names */
|
||||
const struct fdt_property* prop = fdt_get_property(blob, node_ofs, "gpio-line-names", NULL);
|
||||
if (prop == NULL) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* modify given name */
|
||||
for (i=0; i<gpios; i++) {
|
||||
if (i == pin) {
|
||||
/* Take provided name if GPIO pin is matched */
|
||||
text = name;
|
||||
}
|
||||
else {
|
||||
/* Take existing name from strin list */
|
||||
/* Take existing name from string list */
|
||||
(void)fdt_get_string_index(blob, node_ofs, "gpio-line-names", i, &text);
|
||||
}
|
||||
|
||||
/* Add name to new string list */
|
||||
if ((pos + strlen(text) + 1) < sizeof(buffer)) {
|
||||
strncpy(buffer+pos, text, sizeof(buffer)-pos);
|
||||
pos += strlen(text) + 1;
|
||||
}
|
||||
else {
|
||||
printf("ft_set_gpio_name() Buffer too small\n");
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
(void)fdt_setprop(blob, node_ofs, "gpio-line-names", buffer, pos);
|
||||
}
|
||||
}
|
||||
|
||||
end: ;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -1185,33 +1185,55 @@ static void ft_enable_node(void* blob, const char* name)
|
|||
static void ft_set_gpio_name(void *blob, const char* gpio, int pin, const char* name)
|
||||
{
|
||||
int node_ofs = fdt_path_offset(blob, gpio);
|
||||
if (node_ofs != -1) {
|
||||
const struct fdt_property* prop = fdt_get_property(blob, node_ofs, "gpio-line-names", NULL);
|
||||
if (prop != NULL) {
|
||||
int gpios = -1;
|
||||
const char* text;
|
||||
int pos = 0;
|
||||
int i;
|
||||
char buffer[512];
|
||||
|
||||
/* TODO: Determine number of entries from ngpios field */
|
||||
if (node_ofs == -1) {
|
||||
printf("Can't find node %s\n", gpio);
|
||||
goto end;
|
||||
}
|
||||
|
||||
for (i=0; i<32; i++) {
|
||||
/* get number of IOs in node */
|
||||
gpios = fdt_getprop_u32_default_node(blob, node_ofs, 0, "ngpios", -1);
|
||||
if (gpios == -1 || gpios > 64) {
|
||||
printf("Illegal number of gpios %d\n", gpios);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* get string array with names */
|
||||
const struct fdt_property* prop = fdt_get_property(blob, node_ofs, "gpio-line-names", NULL);
|
||||
if (prop == NULL) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* modify given name */
|
||||
for (i=0; i<gpios; i++) {
|
||||
if (i == pin) {
|
||||
/* Take provided name if GPIO pin is matched */
|
||||
text = name;
|
||||
}
|
||||
else {
|
||||
/* Take existing name from strin list */
|
||||
/* Take existing name from string list */
|
||||
(void)fdt_get_string_index(blob, node_ofs, "gpio-line-names", i, &text);
|
||||
}
|
||||
|
||||
/* Add name to new string list */
|
||||
if ((pos + strlen(text) + 1) < sizeof(buffer)) {
|
||||
strncpy(buffer+pos, text, sizeof(buffer)-pos);
|
||||
pos += strlen(text) + 1;
|
||||
}
|
||||
else {
|
||||
printf("ft_set_gpio_name() Buffer too small\n");
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
(void)fdt_setprop(blob, node_ofs, "gpio-line-names", buffer, pos);
|
||||
}
|
||||
}
|
||||
|
||||
end: ;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in New Issue