* [PATCH 0/4] support for gpio-line-names
@ 2019-11-27 11:16 Sascha Hauer
2019-11-27 11:16 ` [PATCH 1/4] of: Add of_property_read_string_array() Sascha Hauer
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Sascha Hauer @ 2019-11-27 11:16 UTC (permalink / raw)
To: Barebox List
Linux supports the device tree property "gpio-line-names" which allows
it name GPIOs from the device tree. This adds support for this property
to barebox as well. With this the gpio commands not only accept a GPIO
label (which is given by the requester of the GPIO), but also a GPIO
name.
Sascha Hauer (4):
of: Add of_property_read_string_array()
gpio: Introduce GPIO names
of/gpio: Support gpio-line-names property
ARM: Layerscape: TQMLS1046a: Add gpio-line-names
arch/arm/dts/fsl-tqmls1046a-mbls10xxa.dts | 48 +++++++++
commands/gpio.c | 4 +-
drivers/gpio/gpiolib.c | 47 +++++++--
drivers/of/base.c | 122 +++++++---------------
include/gpio.h | 6 ++
include/of.h | 83 ++++++++++++---
6 files changed, 204 insertions(+), 106 deletions(-)
--
2.24.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/4] of: Add of_property_read_string_array()
2019-11-27 11:16 [PATCH 0/4] support for gpio-line-names Sascha Hauer
@ 2019-11-27 11:16 ` Sascha Hauer
2019-11-27 11:16 ` [PATCH 2/4] gpio: Introduce GPIO names Sascha Hauer
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2019-11-27 11:16 UTC (permalink / raw)
To: Barebox List
of_property_read_string_array() is used to read a multistring device
tree property into an array of strings. This is taken from the kernel.
It is implemented around of_property_read_string_helper() which can be
used to implement of_property_count_strings() and
of_property_read_string_index() as well.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/of/base.c | 122 ++++++++++++++--------------------------------
include/of.h | 83 ++++++++++++++++++++++++++-----
2 files changed, 107 insertions(+), 98 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 98ef5fc0d4..80ceeab13b 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -886,54 +886,6 @@ int of_property_read_string(struct device_node *np, const char *propname,
}
EXPORT_SYMBOL_GPL(of_property_read_string);
-/**
- * of_property_read_string_index - Find and read a string from a multiple
- * strings property.
- * @np: device node from which the property value is to be read.
- * @propname: name of the property to be searched.
- * @index: index of the string in the list of strings
- * @out_string: pointer to null terminated return string, modified only if
- * return value is 0.
- *
- * Search for a property in a device tree node and retrieve a null
- * terminated string value (pointer to data, not a copy) in the list of strings
- * contained in that property.
- * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
- * property does not have a value, and -EILSEQ if the string is not
- * null-terminated within the length of the property data.
- *
- * The out_string pointer is modified only if a valid string can be decoded.
- */
-int of_property_read_string_index(struct device_node *np, const char *propname,
- int index, const char **output)
-{
- struct property *prop = of_find_property(np, propname, NULL);
- int i = 0;
- size_t l = 0, total = 0;
- const char *p;
- const void *value;
-
- if (!prop)
- return -EINVAL;
- value = of_property_get_value(prop);
- if (!value)
- return -ENODATA;
- if (strnlen(value, prop->length) >= prop->length)
- return -EILSEQ;
-
- p = value;
-
- for (i = 0; total < prop->length; total += l, p += l) {
- l = strlen(p) + 1;
- if (i++ == index) {
- *output = p;
- return 0;
- }
- }
- return -ENODATA;
-}
-EXPORT_SYMBOL_GPL(of_property_read_string_index);
-
/**
* of_property_match_string() - Find string in a list and return index
* @np: pointer to node containing string list property
@@ -972,43 +924,6 @@ int of_property_match_string(struct device_node *np, const char *propname,
}
EXPORT_SYMBOL_GPL(of_property_match_string);
-/**
- * of_property_count_strings - Find and return the number of strings from a
- * multiple strings property.
- * @np: device node from which the property value is to be read.
- * @propname: name of the property to be searched.
- *
- * Search for a property in a device tree node and retrieve the number of null
- * terminated string contain in it. Returns the number of strings on
- * success, -EINVAL if the property does not exist, -ENODATA if property
- * does not have a value, and -EILSEQ if the string is not null-terminated
- * within the length of the property data.
- */
-int of_property_count_strings(struct device_node *np, const char *propname)
-{
- struct property *prop = of_find_property(np, propname, NULL);
- int i = 0;
- size_t l = 0, total = 0;
- const char *p;
- const void *value;
-
- if (!prop)
- return -EINVAL;
- value = of_property_get_value(prop);
- if (!value)
- return -ENODATA;
- if (strnlen(value, prop->length) >= prop->length)
- return -EILSEQ;
-
- p = value;
-
- for (i = 0; total < prop->length; total += l, p += l, i++)
- l = strlen(p) + 1;
-
- return i;
-}
-EXPORT_SYMBOL_GPL(of_property_count_strings);
-
const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
u32 *pu)
{
@@ -1777,6 +1692,43 @@ struct device_node *of_get_child_by_name(const struct device_node *node,
}
EXPORT_SYMBOL(of_get_child_by_name);
+/**
+ * of_property_read_string_helper() - Utility helper for parsing string properties
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @out_strs: output array of string pointers.
+ * @sz: number of array elements to read.
+ * @skip: Number of strings to skip over at beginning of list.
+ *
+ * Don't call this function directly. It is a utility helper for the
+ * of_property_read_string*() family of functions.
+ */
+int of_property_read_string_helper(const struct device_node *np,
+ const char *propname, const char **out_strs,
+ size_t sz, int skip)
+{
+ const struct property *prop = of_find_property(np, propname, NULL);
+ int l = 0, i = 0;
+ const char *p, *end;
+
+ if (!prop)
+ return -EINVAL;
+ if (!prop->value)
+ return -ENODATA;
+ p = prop->value;
+ end = p + prop->length;
+
+ for (i = 0; p < end && (!out_strs || i < skip + sz); i++, p += l) {
+ l = strnlen(p, end - p) + 1;
+ if (p + l > end)
+ return -EILSEQ;
+ if (out_strs && i >= skip)
+ *out_strs++ = p;
+ }
+ i -= skip;
+ return i <= 0 ? -ENODATA : i;
+}
+
static void __of_print_nodes(struct device_node *node, int indent, const char *prefix)
{
struct device_node *n;
diff --git a/include/of.h b/include/of.h
index 98ddf795cb..f63a3efe13 100644
--- a/include/of.h
+++ b/include/of.h
@@ -197,14 +197,12 @@ extern int of_property_read_u64(const struct device_node *np,
extern int of_property_read_string(struct device_node *np,
const char *propname,
const char **out_string);
-extern int of_property_read_string_index(struct device_node *np,
- const char *propname,
- int index, const char **output);
extern int of_property_match_string(struct device_node *np,
const char *propname,
const char *string);
-extern int of_property_count_strings(struct device_node *np,
- const char *propname);
+extern int of_property_read_string_helper(const struct device_node *np,
+ const char *propname,
+ const char **out_strs, size_t sz, int index);
extern const __be32 *of_prop_next_u32(struct property *prop,
const __be32 *cur, u32 *pu);
@@ -444,20 +442,15 @@ static inline int of_property_read_string(struct device_node *np,
return -ENOSYS;
}
-static inline int of_property_read_string_index(struct device_node *np,
- const char *propname, int index, const char **output)
-{
- return -ENOSYS;
-}
-
static inline int of_property_match_string(struct device_node *np,
const char *propname, const char *string)
{
return -ENOSYS;
}
-static inline int of_property_count_strings(struct device_node *np,
- const char *propname)
+static inline int of_property_read_string_helper(const struct device_node *np,
+ const char *propname,
+ const char **out_strs, size_t sz, int index)
{
return -ENOSYS;
}
@@ -752,6 +745,70 @@ static inline struct device_node *of_find_matching_node(
for (child = of_get_next_available_child(parent, NULL); child != NULL; \
child = of_get_next_available_child(parent, child))
+/**
+ * of_property_read_string_array() - Read an array of strings from a multiple
+ * strings property.
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @out_strs: output array of string pointers.
+ * @sz: number of array elements to read.
+ *
+ * Search for a property in a device tree node and retrieve a list of
+ * terminated string values (pointer to data, not a copy) in that property.
+ *
+ * If @out_strs is NULL, the number of strings in the property is returned.
+ */
+static inline int of_property_read_string_array(const struct device_node *np,
+ const char *propname, const char **out_strs,
+ size_t sz)
+{
+ return of_property_read_string_helper(np, propname, out_strs, sz, 0);
+}
+
+/**
+ * of_property_count_strings() - Find and return the number of strings from a
+ * multiple strings property.
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ *
+ * Search for a property in a device tree node and retrieve the number of null
+ * terminated string contain in it. Returns the number of strings on
+ * success, -EINVAL if the property does not exist, -ENODATA if property
+ * does not have a value, and -EILSEQ if the string is not null-terminated
+ * within the length of the property data.
+ */
+static inline int of_property_count_strings(const struct device_node *np,
+ const char *propname)
+{
+ return of_property_read_string_helper(np, propname, NULL, 0, 0);
+}
+
+/**
+ * of_property_read_string_index() - Find and read a string from a multiple
+ * strings property.
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @index: index of the string in the list of strings
+ * @out_string: pointer to null terminated return string, modified only if
+ * return value is 0.
+ *
+ * Search for a property in a device tree node and retrieve a null
+ * terminated string value (pointer to data, not a copy) in the list of strings
+ * contained in that property.
+ * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
+ * property does not have a value, and -EILSEQ if the string is not
+ * null-terminated within the length of the property data.
+ *
+ * The out_string pointer is modified only if a valid string can be decoded.
+ */
+static inline int of_property_read_string_index(const struct device_node *np,
+ const char *propname,
+ int index, const char **output)
+{
+ int rc = of_property_read_string_helper(np, propname, output, 1, index);
+ return rc < 0 ? rc : 0;
+}
+
/**
* of_property_read_bool - Findfrom a property
* @np: device node from which the property value is to be read.
--
2.24.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/4] gpio: Introduce GPIO names
2019-11-27 11:16 [PATCH 0/4] support for gpio-line-names Sascha Hauer
2019-11-27 11:16 ` [PATCH 1/4] of: Add of_property_read_string_array() Sascha Hauer
@ 2019-11-27 11:16 ` Sascha Hauer
2019-11-27 11:16 ` [PATCH 3/4] of/gpio: Support gpio-line-names property Sascha Hauer
2019-11-27 11:16 ` [PATCH 4/4] ARM: Layerscape: TQMLS1046a: Add gpio-line-names Sascha Hauer
3 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2019-11-27 11:16 UTC (permalink / raw)
To: Barebox List
This introduces GPIO names. So far we only have labels which are given
by the requester. In contrast names are given by the provider and do not
change depending on whoever requests a GPIO. The gpio commands now also
accept to reference a GPIO by name.
The printing of the gpioinfo command is adjusted to nicely print both
the label and the name.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/gpio.c | 4 +++-
drivers/gpio/gpiolib.c | 31 +++++++++++++++++++++++++------
include/gpio.h | 6 ++++++
3 files changed, 34 insertions(+), 7 deletions(-)
diff --git a/commands/gpio.c b/commands/gpio.c
index 951ad2c285..6d88ab6bbe 100644
--- a/commands/gpio.c
+++ b/commands/gpio.c
@@ -25,7 +25,9 @@ static int get_gpio_and_value(int argc, char *argv[],
if (argc < count)
return COMMAND_ERROR_USAGE;
- *gpio = gpio_find_by_label(argv[1]);
+ *gpio = gpio_find_by_name(argv[1]);
+ if (*gpio < 0)
+ *gpio = gpio_find_by_label(argv[1]);
if (*gpio < 0) {
ret = kstrtoint(argv[1], 0, gpio);
if (ret < 0)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index f96009896a..057cea43cc 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -16,6 +16,7 @@ struct gpio_info {
bool requested;
bool active_low;
char *label;
+ char *name;
};
static struct gpio_info *gpio_desc;
@@ -108,6 +109,23 @@ int gpio_find_by_label(const char *label)
return -ENOENT;
}
+int gpio_find_by_name(const char *name)
+{
+ int i;
+
+ for (i = 0; i < ARCH_NR_GPIOS; i++) {
+ struct gpio_info *info = &gpio_desc[i];
+
+ if (!info->chip || !info->name)
+ continue;
+
+ if (!strcmp(info->name, name))
+ return i;
+ }
+
+ return -ENOENT;
+}
+
void gpio_free(unsigned gpio)
{
struct gpio_info *gi = gpio_to_desc(gpio);
@@ -500,7 +518,7 @@ static int do_gpiolib(int argc, char *argv[])
gi->chip->base,
gi->chip->base + gi->chip->ngpio - 1,
gi->chip->dev->name);
- printf("%*cdir val requested label\n", 13, ' ');
+ printf(" %-3s %-3s %-9s %-20s %-20s\n", "dir", "val", "requested", "name", "label");
}
if (gi->chip->ops->get_direction)
@@ -510,11 +528,12 @@ static int do_gpiolib(int argc, char *argv[])
val = gi->chip->ops->get(gi->chip,
i - gi->chip->base);
- printf(" GPIO %*d: %*s %*s %*s %s\n", 4, i,
- 3, (dir < 0) ? "unk" : ((dir == GPIOF_DIR_IN) ? "in" : "out"),
- 3, (val < 0) ? "unk" : ((val == 0) ? "lo" : "hi"),
- 12, gi->requested ? (gi->active_low ? "active low" : "true") : "false",
- (gi->requested && gi->label) ? gi->label : "");
+ printf(" GPIO %4d: %-3s %-3s %-9s %-20s %-20s\n", i,
+ (dir < 0) ? "unk" : ((dir == GPIOF_DIR_IN) ? "in" : "out"),
+ (val < 0) ? "unk" : ((val == 0) ? "lo" : "hi"),
+ gi->requested ? (gi->active_low ? "active low" : "true") : "false",
+ gi->name ? gi->name : "",
+ gi->label ? gi->label : "");
}
return 0;
diff --git a/include/gpio.h b/include/gpio.h
index 4d5f2c25c7..0c0c0337e0 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -114,6 +114,11 @@ static inline int gpio_request(unsigned gpio, const char *label)
return 0;
}
+static inline int gpio_find_by_name(const char *name)
+{
+ return -ENOSYS;
+}
+
static inline int gpio_find_by_label(const char *label)
{
return -ENOSYS;
@@ -141,6 +146,7 @@ static inline void gpio_free_array(const struct gpio *array, size_t num)
}
#else
int gpio_request(unsigned gpio, const char *label);
+int gpio_find_by_name(const char *name);
int gpio_find_by_label(const char *label);
void gpio_free(unsigned gpio);
int gpio_request_one(unsigned gpio, unsigned long flags, const char *label);
--
2.24.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 3/4] of/gpio: Support gpio-line-names property
2019-11-27 11:16 [PATCH 0/4] support for gpio-line-names Sascha Hauer
2019-11-27 11:16 ` [PATCH 1/4] of: Add of_property_read_string_array() Sascha Hauer
2019-11-27 11:16 ` [PATCH 2/4] gpio: Introduce GPIO names Sascha Hauer
@ 2019-11-27 11:16 ` Sascha Hauer
2019-11-27 11:31 ` Ahmad Fatoum
2019-11-27 11:16 ` [PATCH 4/4] ARM: Layerscape: TQMLS1046a: Add gpio-line-names Sascha Hauer
3 siblings, 1 reply; 9+ messages in thread
From: Sascha Hauer @ 2019-11-27 11:16 UTC (permalink / raw)
To: Barebox List
GPIOs can be given names with the gpio-line-names device tree property.
This patch adds support for it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/gpio/gpiolib.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 057cea43cc..9764ddf0f0 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -428,11 +428,25 @@ static int of_hog_gpio(struct device_node *np, struct gpio_chip *chip,
static int of_gpiochip_scan_hogs(struct gpio_chip *chip)
{
struct device_node *np;
- int ret, i;
+ int ret, i, count;
if (!IS_ENABLED(CONFIG_OFDEVICE) || !chip->dev->device_node)
return 0;
+ count = of_property_count_strings(chip->dev->device_node, "gpio-line-names");
+
+ if (count > 0) {
+ const char **arr = xzalloc(count * sizeof(char *));
+
+ of_property_read_string_array(chip->dev->device_node,
+ "gpio-line-names", arr, count);
+
+ for (i = 0; i < chip->ngpio && i < count; i++)
+ gpio_desc[chip->base + i].name = xstrdup(arr[i]);
+
+ free(arr);
+ }
+
for_each_available_child_of_node(chip->dev->device_node, np) {
if (!of_property_read_bool(np, "gpio-hog"))
continue;
--
2.24.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 4/4] ARM: Layerscape: TQMLS1046a: Add gpio-line-names
2019-11-27 11:16 [PATCH 0/4] support for gpio-line-names Sascha Hauer
` (2 preceding siblings ...)
2019-11-27 11:16 ` [PATCH 3/4] of/gpio: Support gpio-line-names property Sascha Hauer
@ 2019-11-27 11:16 ` Sascha Hauer
3 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2019-11-27 11:16 UTC (permalink / raw)
To: Barebox List
The GPIO line names are taken from
https://github.com/tq-systems/u-boot-tqmaxx/blob/warrior.TQMLS1046A.BSP.SW.0003/board/tqc/common/tqc_mbls10xxa.c
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/dts/fsl-tqmls1046a-mbls10xxa.dts | 48 +++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/arch/arm/dts/fsl-tqmls1046a-mbls10xxa.dts b/arch/arm/dts/fsl-tqmls1046a-mbls10xxa.dts
index f0332e3999..a4e3f6b589 100644
--- a/arch/arm/dts/fsl-tqmls1046a-mbls10xxa.dts
+++ b/arch/arm/dts/fsl-tqmls1046a-mbls10xxa.dts
@@ -131,6 +131,22 @@
reg = <0x20>;
gpio-controller;
#gpio-cells = <2>;
+ gpio-line-names = "sd1_3_lane_a_mux",
+ "sd1_2_lane_b_mux",
+ "sd1_0_lane_d_mux",
+ "sd2_1_lane_b_mux",
+ "sd2_3_lane_d_mux1",
+ "sd2_3_lane_d_mux2",
+ "sd_mux_shdn",
+ "sd1_ref_clk2_sel",
+ "mpcie1_disable_n",
+ "mpcie1_wake_n",
+ "mpcie2_disable_n",
+ "mpcie2_wake_n",
+ "prsnt_n",
+ "pcie_pwr_en",
+ "dcdc_pwr_en",
+ "dcdc_pgood_1v8";
};
gpioexp2: pca9555@21 {
@@ -138,6 +154,22 @@
reg = <0x21>;
gpio-controller;
#gpio-cells = <2>;
+ gpio-line-names = "xfi1_tx_dis",
+ "xfi1_tx_fault",
+ "xfi1_moddef_det",
+ "xfi1_rx_loss",
+ "retimer1_loss",
+ "xfi1_ensmb",
+ "qsgmii1_clk_sel0",
+ "qsgmii_phy1_config3",
+ "xfi2_tx_fault",
+ "xfi2_tx_dis",
+ "xfi2_moddef_det",
+ "xfi2_rx_loss",
+ "retimer2_loss",
+ "xfi2_ensmb",
+ "qsgmii2_clk_sel0",
+ "qsgmii_phy2_config3";
};
gpioexp3: pca9555@22 {
@@ -145,6 +177,22 @@
reg = <0x22>;
gpio-controller;
#gpio-cells = <2>;
+ gpio-line-names = "ec1_phy_pwdn",
+ "ec2_phy_pwdn",
+ "usb_c_pwron",
+ "usb_en_oc_3v3_n",
+ "usb_h_grst_n",
+ "gpio_button0",
+ "gpio_button1",
+ "sda_pwr_en",
+ "qsgmii_phy1_int_n",
+ "qsgmii_phy2_int_n",
+ "spi_clko_sof",
+ "spi_int",
+ "can_sel",
+ "led_n",
+ "pcie_rst_3v3_n",
+ "pcie_wake_3v3_n";
};
};
--
2.24.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/4] of/gpio: Support gpio-line-names property
2019-11-27 11:16 ` [PATCH 3/4] of/gpio: Support gpio-line-names property Sascha Hauer
@ 2019-11-27 11:31 ` Ahmad Fatoum
2019-11-27 12:32 ` Sascha Hauer
0 siblings, 1 reply; 9+ messages in thread
From: Ahmad Fatoum @ 2019-11-27 11:31 UTC (permalink / raw)
To: barebox
Hello Sascha,
On 11/27/19 12:16 PM, Sascha Hauer wrote:
> GPIOs can be given names with the gpio-line-names device tree property.
> This patch adds support for it.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> drivers/gpio/gpiolib.c | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 057cea43cc..9764ddf0f0 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -428,11 +428,25 @@ static int of_hog_gpio(struct device_node *np, struct gpio_chip *chip,
> static int of_gpiochip_scan_hogs(struct gpio_chip *chip)
> {
> struct device_node *np;
> - int ret, i;
> + int ret, i, count;
>
> if (!IS_ENABLED(CONFIG_OFDEVICE) || !chip->dev->device_node)
> return 0;
>
> + count = of_property_count_strings(chip->dev->device_node, "gpio-line-names");
> +
> + if (count > 0) {
> + const char **arr = xzalloc(count * sizeof(char *));
> +
> + of_property_read_string_array(chip->dev->device_node,
> + "gpio-line-names", arr, count);
> +
> + for (i = 0; i < chip->ngpio && i < count; i++)
> + gpio_desc[chip->base + i].name = xstrdup(arr[i]);
There's no need to duplicate memory here. You could just directly point into the
unflattened DTB. You could reuse of_gpiochip_set_names from my patch
sent yesterday.
> +
> + free(arr);
> + }
> +
> for_each_available_child_of_node(chip->dev->device_node, np) {
> if (!of_property_read_bool(np, "gpio-hog"))
> continue;
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | https://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/4] of/gpio: Support gpio-line-names property
2019-11-27 11:31 ` Ahmad Fatoum
@ 2019-11-27 12:32 ` Sascha Hauer
2019-11-27 12:35 ` Ahmad Fatoum
0 siblings, 1 reply; 9+ messages in thread
From: Sascha Hauer @ 2019-11-27 12:32 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Wed, Nov 27, 2019 at 12:31:37PM +0100, Ahmad Fatoum wrote:
> Hello Sascha,
>
> On 11/27/19 12:16 PM, Sascha Hauer wrote:
> > GPIOs can be given names with the gpio-line-names device tree property.
> > This patch adds support for it.
> >
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > ---
> > drivers/gpio/gpiolib.c | 16 +++++++++++++++-
> > 1 file changed, 15 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > index 057cea43cc..9764ddf0f0 100644
> > --- a/drivers/gpio/gpiolib.c
> > +++ b/drivers/gpio/gpiolib.c
> > @@ -428,11 +428,25 @@ static int of_hog_gpio(struct device_node *np, struct gpio_chip *chip,
> > static int of_gpiochip_scan_hogs(struct gpio_chip *chip)
> > {
> > struct device_node *np;
> > - int ret, i;
> > + int ret, i, count;
> >
> > if (!IS_ENABLED(CONFIG_OFDEVICE) || !chip->dev->device_node)
> > return 0;
> >
> > + count = of_property_count_strings(chip->dev->device_node, "gpio-line-names");
> > +
> > + if (count > 0) {
> > + const char **arr = xzalloc(count * sizeof(char *));
> > +
> > + of_property_read_string_array(chip->dev->device_node,
> > + "gpio-line-names", arr, count);
> > +
> > + for (i = 0; i < chip->ngpio && i < count; i++)
> > + gpio_desc[chip->base + i].name = xstrdup(arr[i]);
>
> There's no need to duplicate memory here. You could just directly point into the
> unflattened DTB.
barebox contains functions and commands to change and delete properties
and nodes. We shouldn't store pointers into the live tree anywhere.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/4] of/gpio: Support gpio-line-names property
2019-11-27 12:32 ` Sascha Hauer
@ 2019-11-27 12:35 ` Ahmad Fatoum
2019-11-27 13:38 ` Sascha Hauer
0 siblings, 1 reply; 9+ messages in thread
From: Ahmad Fatoum @ 2019-11-27 12:35 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
Hello Sascha,
On 11/27/19 1:32 PM, Sascha Hauer wrote:
> barebox contains functions and commands to change and delete properties
> and nodes. We shouldn't store pointers into the live tree anywhere.
aren't these fixups done just before boot? What users change the live
device tree?
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | https://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/4] of/gpio: Support gpio-line-names property
2019-11-27 12:35 ` Ahmad Fatoum
@ 2019-11-27 13:38 ` Sascha Hauer
0 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2019-11-27 13:38 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Wed, Nov 27, 2019 at 01:35:21PM +0100, Ahmad Fatoum wrote:
> Hello Sascha,
>
> On 11/27/19 1:32 PM, Sascha Hauer wrote:
> > barebox contains functions and commands to change and delete properties
> > and nodes. We shouldn't store pointers into the live tree anywhere.
>
> aren't these fixups done just before boot?
Yes.
> What users change the live device tree?
We already had problems with users deleting nodes that were referenced
at other places. I'm not saying this is wise to do so, but it happened.
It might be a good idea to separate the live tree from the one the user
actually sees, but then again things like of_device_enable_path() and
of_device_enable_and_register_by_name() wouldn't work anymore.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2019-11-27 13:38 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-27 11:16 [PATCH 0/4] support for gpio-line-names Sascha Hauer
2019-11-27 11:16 ` [PATCH 1/4] of: Add of_property_read_string_array() Sascha Hauer
2019-11-27 11:16 ` [PATCH 2/4] gpio: Introduce GPIO names Sascha Hauer
2019-11-27 11:16 ` [PATCH 3/4] of/gpio: Support gpio-line-names property Sascha Hauer
2019-11-27 11:31 ` Ahmad Fatoum
2019-11-27 12:32 ` Sascha Hauer
2019-11-27 12:35 ` Ahmad Fatoum
2019-11-27 13:38 ` Sascha Hauer
2019-11-27 11:16 ` [PATCH 4/4] ARM: Layerscape: TQMLS1046a: Add gpio-line-names Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox