Skip to contentSkip to conversation

dm: add support of new binding in gpio and pincontrol

PATCH New Patrick Delaunay 4 participants 60 messages Jan 13, 2020 – Apr 22, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v3 cover dm: add support of new binding in gpio and pincontrol

Hi,

it is the V3 of "dm: add support of new binding in gpio and pincontrol"
http://patchwork.ozlabs.org/project/uboot/list/?series=145044

I rebase on v2020.01 and made some minor update after Simon Glass review. And I also split the previous patch was part of v2 08/14 to help review

	http://patchwork.ozlabs.org/patch/1200865/
	"gpio: add ops for configuration with dir flags"

I create this patchset to prepare alignment of stm32mp157c-ev1 device-tree with the linux kernel v5.4.

One node for touch screen support use the IRQ line configuration using the new kernel binding introduced by the linux kernel commit ede033e1e863c from v5.1 ('dt-bindings:
gpio: document the new pull-up/pull-down flags')
https://github.com/torvalds/linux/commit/ede033e1e863c

gt9147: goodix_ts at 5d {
	compatible = "goodix,gt9147";
	reg = <0x5d>;
	status = "okay";
	irq-gpios = <&stmfx_pinctrl 14
			(GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
	irq-flags = <IRQ_TYPE_EDGE_RISING>;
};

In Linux Kernel, the GPIO configuration (pull down/up) are now managed by GPIO lib but they are not yet supported by U-boot in uclass GPIO or pincontrol (when used by gpio-hog).

This serie adds the support of theses new defines (with ops get_config/set_config) added in kernel GPIO binding and adds the test in sandbox.

NB: In a second phase, the removed set_open_drain/get_open_drain
API could be replaced by the new ops get_config/set_config.

I also align the gpio binding file with the version from the latest kernel v5.3 (I don't think I remove any U-Boot specific part with this patch)
I move the added information on gpio hog code in a new file doc/README.gpio.

To have functional test, I convert pinctrl-generic to livetree otherwise the pins are not correctly configured in sandbox, when CONFIG_OF_LIVE is activated.

For the test on gpio I add information for pin configuration in output of the command "pinmux status" with a simple pincontrol driver associated to GPIO driver.

NB: after rebase on master branch, the sandbox test "ut dm power_domain"
is failing; it was not the case for v2019.10.

------------------------------------------------------ Captured stdout call ------------------------------------------------------- => ut dm power_domain
Test: dm_test_power_domain: power-domain.c
../test/dm/test-main.c:72, dm_test_destroy(): 0 == uclass_destroy(uc): Expected 0x0 (0), got 0xffffffea (-22) ../test/dm/test-main.c:107, dm_do_test(): 0 == dm_test_destroy(uts): Expected 0x0 (0), got 0x1 (1) ../test/dm/test-main.c:169, dm_test_main(): 0 == dm_do_test(uts, test, 1): Expected 0x0 (0), got 0x1 (1)
=>

I think it is linked to commit 52edfed65de9 ("dm: core:
device: switch off power domain after device removal")

After some investigation :

1/ pincontrol is remove in uclass_destroy(0)

2/ power domain is removed in uclass_destroy(0)

3/ device_chld_unbind()
dev_power_domain_off
-> probe power domain (again)
--> pinctrl_select_state() in device_probe()
---> pincontrol is probed (again)

4/ at the end of dev_power_domain_off() function the power domain
is unbind in dev_power_domain_off device_remove(pd.dev, DM_REMOVE_NORMAL);

So power domain driver is correctly removed but it is not the case for the pincontrol driver and that cause the issue.

The problem occurs after my serie only because I introduce a second pincontrol driver for sandbox, so the dynamic changes but my serie is not the root cause of the issue.

Workaround to allow test execution:
"dm: core: device: don't probe pinctrl for power domain"

My working branch:
https://github.com/patrickdelaunay/u-boot/tree/dm

Regards

Patrick Delaunay

Changes in v3:
- add test dm_test_ofnode_get_property_by_prop
- udpate ofnode example in commit message
- solve comment for ofnode_get_property_by_prop (and not by of_ofprop)
- Split the previous patch [PATCH v2 08/14] to help review
- Split the previous patch [PATCH v2 08/14] to help review
- Split the previous patch [PATCH v2 08/14] to help review
- Split the previous patch [PATCH v2 08/14] to help review
- Split the previous patch [PATCH v2 08/14] to help review
- Split the previous patch [PATCH v2 08/14] to help review
- Split the previous patch [PATCH v2 08/14] to help review
- Split the previous patch [PATCH v2 08/14] to help review

Changes in v2:
- use the dev_ API instead of ofnode_ function.
- Identify property with a new struct ofprop as proposed
by Simon Glass
- Add dev_ iterate functions
- Change dev_ functions in pinctrl-generic
- remove the unused GPIOD_REQUESTED
- remove the open_drain API and ops
- add gpio descriptor initialization helper
- change the proposed ops for pin config to set_dir_flags/get_dir_flags
- reused the existing API dm_gpio_set_dir_flags/dm_gpio_set_dir
- add a new API dm_gpio_get_dir_flags
- change the proposed ops for pin config to set_dir_flags/get_dir_flags
- reused the existing API dm_gpio_set_dir_flags/dm_gpio_set_dir
- add a new API dm_gpio_get_dir_flags
- simplify sandbox GPIO driver: save dir_flags (GPIOD_...) and remove internal flags (GPIOF_...); the previous path "gpio: sandbox: cleanup flag support" is no more needed
- add unitary test in dm_test_gpio for set_dir_flags
- add some function check in dm_test_gpio_phandles
- dm_test_gpio_pin_config change to dm_test_gpio_get_dir_flags
- Adapt sandbox_pinctrl_gpio driver with the saved dir_flags in sandbox gpio driver
- rebase on v2020.01-rc3

Patrick Delaunay (21):
dm: pinctrl: convert pinctrl-single to livetree
dm: core: add ofnode and dev function to iterate on node property
dm: pinctrl: migrate pinctrl-generic to livetree
dt-bindings: gpio: document the new pull-up/pull-down flags
gpio: remove GPIOD_REQUESTED
gpio: remove the open_drain API and ops
gpio: add gpio descriptor initialization helper
gpio: add function _gpio_get_value
gpio: add function _dm_gpio_set_dir_flags
gpio: add function check_dir_flags
gpio: add helper GPIOD_FLAGS_OUTPUT
gpio: update dir_flags management
gpio: add support of new GPIO direction flag
gpio: add ops to get dir flags
gpio: add ops to set dir flags
dt-bindings: gpio: alignment with kernel v5.3
pinctrl: sandbox: Add mux information in get_pin_muxing
test: dm: update test for pins configuration in pinctrl node
gpio: sandbox: cleanup binding support
test: dm: update test for pins configuration in gpio
test: pinmux: add pincontrol-gpio for pin configuration

 arch/sandbox/dts/test.dts               |  85 +++++--
 arch/sandbox/include/asm/gpio.h         |  38 +--
 doc/README.gpio                         |  42 ++++
 doc/device-tree-bindings/gpio/gpio.txt  | 304 ++++++++++++----------
 drivers/core/of_access.c                |  32 +++
 drivers/core/ofnode.c                   |  48 ++++
 drivers/core/read.c                     |  16 ++
 drivers/gpio/gpio-uclass.c              | 203 +++++++++++----
 drivers/gpio/mpc8xxx_gpio.c             |  22 --
 drivers/gpio/sandbox.c                  | 321 +++++++++++++++++++-----
 drivers/pinctrl/pinctrl-generic.c       |  30 +--
 drivers/pinctrl/pinctrl-sandbox.c       |  44 +++-
 drivers/pinctrl/pinctrl-single.c        |  27 +-
 include/asm-generic/gpio.h              | 102 ++++----
 include/dm/of_access.h                  |  40 +++
 include/dm/ofnode.h                     |  63 ++++-
 include/dm/read.h                       |  67 +++++
 include/dt-bindings/gpio/gpio.h         |   6 +
 include/dt-bindings/gpio/sandbox-gpio.h |  24 ++
 test/dm/Makefile                        |   1 +
 test/dm/gpio.c                          |  69 ++++-
 test/dm/ofread.c                        |  50 ++++
 test/dm/test-fdt.c                      |   2 +-
 test/py/tests/test_pinmux.py            |  38 ++-
 24 files changed, 1275 insertions(+), 399 deletions(-)
 create mode 100644 doc/README.gpio
 create mode 100644 include/dt-bindings/gpio/sandbox-gpio.h
 create mode 100644 test/dm/ofread.c
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 1/21 dm: pinctrl: convert pinctrl-single to livetree

Convert 'pinctrl-single' using livetree functions
- dev_read_prop
- dev_read_u32_default
- dev_read_u32_array
- dev_read_bool
- dev_read_addr
and get rid of DECLARE_GLOBAL_DATA_PTR.

---

Changes in v3: None
Changes in v2:
- use the dev_ API instead of ofnode_ function.

 drivers/pinctrl/pinctrl-single.c | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)
drivers/pinctrl/pinctrl-single.c +9 -18
index 1dfc97dcea..6d8f989ebd 100644
@@ -9,8 +9,6 @@
 #include <linux/libfdt.h>
 #include <asm/io.h>
 
-DECLARE_GLOBAL_DATA_PTR;
-
 struct single_pdata {
 	fdt_addr_t base;	/* first configuration register */
 	int offset;		/* index of last configuration register */
@@ -117,13 +115,11 @@ static int single_configure_bits(struct udevice *dev,
 static int single_set_state(struct udevice *dev,
 			    struct udevice *config)
 {
-	const void *fdt = gd->fdt_blob;
 	const struct single_fdt_pin_cfg *prop;
 	const struct single_fdt_bits_cfg *prop_bits;
 	int len;
 
-	prop = fdt_getprop(fdt, dev_of_offset(config), "pinctrl-single,pins",
-			   &len);
+	prop = dev_read_prop(dev, "pinctrl-single,pins", &len);
 
 	if (prop) {
 		dev_dbg(dev, "configuring pins for %s\n", config->name);
@@ -136,9 +132,7 @@ static int single_set_state(struct udevice *dev,
 	}
 
 	/* pinctrl-single,pins not found so check for pinctrl-single,bits */
-	prop_bits = fdt_getprop(fdt, dev_of_offset(config),
-				"pinctrl-single,bits",
-				    &len);
+	prop_bits = dev_read_prop(dev, "pinctrl-single,bits", &len);
 	if (prop_bits) {
 		dev_dbg(dev, "configuring pins for %s\n", config->name);
 		if (len % sizeof(struct single_fdt_bits_cfg)) {
@@ -160,27 +154,24 @@ static int single_ofdata_to_platdata(struct udevice *dev)
 	int res;
 	struct single_pdata *pdata = dev->platdata;
 
-	pdata->width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
-				      "pinctrl-single,register-width", 0);
+	pdata->width =
+		dev_read_u32_default(dev, "pinctrl-single,register-width", 0);
 
-	res = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev),
-				   "reg", of_reg, 2);
+	res = dev_read_u32_array(dev, "reg", of_reg, 2);
 	if (res)
 		return res;
 	pdata->offset = of_reg[1] - pdata->width / 8;
 
-	addr = devfdt_get_addr(dev);
+	addr = dev_read_addr(dev);
 	if (addr == FDT_ADDR_T_NONE) {
 		dev_dbg(dev, "no valid base register address\n");
 		return -EINVAL;
 	}
 	pdata->base = addr;
 
-	pdata->mask = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
-				     "pinctrl-single,function-mask",
-				     0xffffffff);
-	pdata->bits_per_mux = fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev),
-					      "pinctrl-single,bit-per-mux");
+	pdata->mask = dev_read_u32_default(dev, "pinctrl-single,function-mask",
+					   0xffffffff);
+	pdata->bits_per_mux = dev_read_bool(dev, "pinctrl-single,bit-per-mux");
 
 	return 0;
 }
Signature · 1 line
2.17.1
#2 lore raw

PATCH v3 1/21 dm: pinctrl: convert pinctrl-single to livetree

Quoted 10 lines · Patrick Delaunay

Convert 'pinctrl-single' using livetree functions
- dev_read_prop
- dev_read_u32_default
- dev_read_u32_array
- dev_read_bool
- dev_read_addr
and get rid of DECLARE_GLOBAL_DATA_PTR.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/08d378b0/attachment.sig>
#3 lore raw

PATCH v3 1/21 dm: pinctrl: convert pinctrl-single to livetree

Quoted 10 lines · Tom Rini
Quoted 8 lines · Patrick Delaunay

Convert 'pinctrl-single' using livetree functions
- dev_read_prop
- dev_read_u32_default
- dev_read_u32_array
- dev_read_bool
- dev_read_addr
and get rid of DECLARE_GLOBAL_DATA_PTR.

Quoted 4 lines
Quoted 2 lines

Applied to u-boot/master, thanks!

Now that I've setup my AM65x board, this commit is breaking boot there and I don't have any idea why. I don't get any sort of output on either core (this platform takes am65x_evm_r5 for the SPL and am65x_evm_a53 for the main core).

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200422/cfde4d85/attachment.sig>
#4 lore raw

PATCH v3 1/21 dm: pinctrl: convert pinctrl-single to livetree

Quoted 14 lines · Tom Rini
Quoted 13 lines · Tom Rini
Quoted 10 lines · Patrick Delaunay

Convert 'pinctrl-single' using livetree functions
- dev_read_prop
- dev_read_u32_default
- dev_read_u32_array
- dev_read_bool
- dev_read_addr
and get rid of DECLARE_GLOBAL_DATA_PTR.

Quoted 7 lines
Quoted 1 line

Applied to u-boot/master, thanks!

Now that I've setup my AM65x board, this commit is breaking boot there and I don't have any idea why. I don't get any sort of output on either core (this platform takes am65x_evm_r5 for the SPL and am65x_evm_a53 for the main core).

Ahh thanks for the pointer Tom. I have been struggling since yesterday as why my board is not booting with latest master. Looks like this patch is passing the wrong device pointer for searching pinctrl-single-pins. Just posted a patch fixing it[0]. Please have a look and merge it asap.

[0]
https://patchwork.ozlabs.org/project/uboot/patch/20200422172531.29649-1-lokeshvutla at ti.com/

Thanks and regards,
Lokesh

#5 lore raw

PATCH v3 2/21 dm: core: add ofnode and dev function to iterate on node property

In reply to Patrick Delaunay

Add functions to iterate on all property with livetree
- dev_read_first_prop
- dev_read_next_prop
- dev_read_prop_by_prop
and
- ofnode_get_first_property
- ofnode_get_next_property
- ofnode_get_property_by_prop

And helper: dev_for_each_property

For example:
struct ofprop property;

dev_for_each_property(property, config) {
	value = dev_read_prop_by_prop(&property, &propname, &len);

or:

for (res = ofnode_get_first_property(node, &property);
!res;
res = ofnode_get_next_property(&property))

{
     value = ofnode_get_property_by_prop(&property, &propname, &len);

....
}

---

Changes in v3:
- add test dm_test_ofnode_get_property_by_prop
- udpate ofnode example in commit message
- solve comment for ofnode_get_property_by_prop (and not by of_ofprop)

Changes in v2:
- Identify property with a new struct ofprop as proposed by Simon Glass
- Add dev_ iterate functions

 drivers/core/of_access.c | 32 +++++++++++++++++++
 drivers/core/ofnode.c    | 48 ++++++++++++++++++++++++++++
 drivers/core/read.c      | 16 ++++++++++
 include/dm/of_access.h   | 40 ++++++++++++++++++++++++
 include/dm/ofnode.h      | 63 ++++++++++++++++++++++++++++++++++++-
 include/dm/read.h        | 67 ++++++++++++++++++++++++++++++++++++++++
 test/dm/Makefile         |  1 +
 test/dm/ofread.c         | 50 ++++++++++++++++++++++++++++++
 8 files changed, 316 insertions(+), 1 deletion(-)
 create mode 100644 test/dm/ofread.c
drivers/core/of_access.c +32 -0
index 945b81448c..86fe42ad14 100644
@@ -170,6 +170,38 @@ const void *of_get_property(const struct device_node *np, const char *name,
 	return pp ? pp->value : NULL;
 }
 
+const struct property *of_get_first_property(const struct device_node *np)
+{
+	if (!np)
+		return NULL;
+
+	return  np->properties;
+}
+
+const struct property *of_get_next_property(const struct device_node *np,
+					    const struct property *property)
+{
+	if (!np)
+		return NULL;
+
+	return property->next;
+}
+
+const void *of_get_property_by_prop(const struct device_node *np,
+				    const struct property *property,
+				    const char **name,
+				    int *lenp)
+{
+	if (!np || !property)
+		return NULL;
+	if (name)
+		*name = property->name;
+	if (lenp)
+		*lenp = property->length;
+
+	return property->value;
+}
+
 static const char *of_prop_next_string(struct property *prop, const char *cur)
 {
 	const void *curv = cur;
drivers/core/ofnode.c +48 -0

54 lines not on this page · raw message

drivers/core/read.c +16 -0
index 9602e52d1b..a9f5d147b2 100644
@@ -238,6 +238,22 @@ const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp)
 	return ofnode_get_property(dev_ofnode(dev), propname, lenp);
 }
 
+int dev_read_first_prop(struct udevice *dev, struct ofprop *prop)
+{
+	return ofnode_get_first_property(dev_ofnode(dev), prop);
+}
+
+int dev_read_next_prop(struct ofprop *prop)
+{
+	return ofnode_get_next_property(prop);
+}
+
+const void *dev_read_prop_by_prop(struct ofprop *prop,
+				  const char **propname, int *lenp)
+{
+	return ofnode_get_property_by_prop(prop, propname, lenp);
+}
+
 int dev_read_alias_seq(struct udevice *dev, int *devnump)
 {
 	ofnode node = dev_ofnode(dev);
include/dm/of_access.h +40 -0
index 13fedb7cf5..1eb1ce13d0 100644
@@ -103,6 +103,46 @@ struct property *of_find_property(const struct device_node *np,
 const void *of_get_property(const struct device_node *np, const char *name,
 			    int *lenp);
 
+/**
+ * of_get_first_property()- get to the pointer of the first property
+ *
+ * Get pointer to the first property of the node, it is used to iterate
+ * and read all the property with of_get_next_property_by_prop().
+ *
+ * @np: Pointer to device node
+ * @return pointer to property or NULL if not found
+ */
+const struct property *of_get_first_property(const struct device_node *np);
+
+/**
+ * of_get_next_property() - get to the pointer of the next property
+ *
+ * Get pointer to the next property of the node, it is used to iterate
+ * and read all the property with of_get_property_by_prop().
+ *
+ * @np: Pointer to device node
+ * @property: pointer of the current property
+ * @return pointer to next property or NULL if not found
+ */
+const struct property *of_get_next_property(const struct device_node *np,
+					    const struct property *property);
+
+/**
+ * of_get_property_by_prop() - get a property value of a node property
+ *
+ * Get value for the property identified by node and property pointer.
+ *
+ * @node: node to read
+ * @property: pointer of the property to read
+ * @propname: place to property name on success
+ * @lenp: place to put length on success
+ * @return pointer to property value or NULL if error
+ */
+const void *of_get_property_by_prop(const struct device_node *np,
+				    const struct property *property,
+				    const char **name,
+				    int *lenp);
+
 /**
  * of_device_is_compatible() - Check if the node matches given constraints
  * @device: pointer to node
include/dm/ofnode.h +62 -1

81 lines not on this page · raw message

include/dm/read.h +67 -0

83 lines not on this page · raw message

test/dm/Makefile +1 -0
index 0c2fd5cb5e..6a1af1511a 100644
@@ -29,6 +29,7 @@ obj-$(CONFIG_LED) += led.o
 obj-$(CONFIG_DM_MAILBOX) += mailbox.o
 obj-$(CONFIG_DM_MMC) += mmc.o
 obj-y += ofnode.o
+obj-y += ofread.o
 obj-$(CONFIG_OSD) += osd.o
 obj-$(CONFIG_DM_VIDEO) += panel.o
 obj-$(CONFIG_DM_PCI) += pci.o
test/dm/ofread.c new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
2.17.1
#6 lore raw

PATCH v3 2/21 dm: core: add ofnode and dev function to iterate on node property

Quoted 41 lines · Patrick Delaunay

Add functions to iterate on all property with livetree
- dev_read_first_prop
- dev_read_next_prop
- dev_read_prop_by_prop
and
- ofnode_get_first_property
- ofnode_get_next_property
- ofnode_get_property_by_prop

And helper: dev_for_each_property

For example:
struct ofprop property;

dev_for_each_property(property, config) {
        value = dev_read_prop_by_prop(&property, &propname, &len);

or:

for (res = ofnode_get_first_property(node, &property);
!res;
res = ofnode_get_next_property(&property))

{
     value = ofnode_get_property_by_prop(&property, &propname, &len);

....
}

---

Changes in v3:
- add test dm_test_ofnode_get_property_by_prop
- udpate ofnode example in commit message
- solve comment for ofnode_get_property_by_prop (and not by of_ofprop)

Changes in v2:
- Identify property with a new struct ofprop as proposed by Simon Glass
- Add dev_ iterate functions

Quoted 11 lines
 drivers/core/of_access.c | 32 +++++++++++++++++++
 drivers/core/ofnode.c    | 48 ++++++++++++++++++++++++++++
 drivers/core/read.c      | 16 ++++++++++
 include/dm/of_access.h   | 40 ++++++++++++++++++++++++
 include/dm/ofnode.h      | 63 ++++++++++++++++++++++++++++++++++++-
 include/dm/read.h        | 67 ++++++++++++++++++++++++++++++++++++++++
 test/dm/Makefile         |  1 +
 test/dm/ofread.c         | 50 ++++++++++++++++++++++++++++++
 8 files changed, 316 insertions(+), 1 deletion(-)
 create mode 100644 test/dm/ofread.c
#7 lore raw

PATCH v3 2/21 dm: core: add ofnode and dev function to iterate on node property

In reply to Patrick Delaunay
Quoted 22 lines · Patrick Delaunay

Add functions to iterate on all property with livetree
- dev_read_first_prop
- dev_read_next_prop
- dev_read_prop_by_prop
and
- ofnode_get_first_property
- ofnode_get_next_property
- ofnode_get_property_by_prop

And helper: dev_for_each_property

For example:
struct ofprop property;

dev_for_each_property(property, config) {
	value = dev_read_prop_by_prop(&property, &propname, &len);

or:

for (res = ofnode_get_first_property(node, &property);
!res;
res = ofnode_get_next_property(&property))

Quoted 7 lines
{
     value = ofnode_get_property_by_prop(&property, &propname, &len);

....
}

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/39726192/attachment.sig>
#8 lore raw

PATCH v3 3/21 dm: pinctrl: migrate pinctrl-generic to livetree

In reply to Patrick Delaunay

Migrate pinctrl-generic to livetree:
- dev_for_each_property
- dev_read_prop_by_prop
- dev_read_string_count
- dev_read_string_index
and get rid of DECLARE_GLOBAL_DATA_PTR.

This patch solves the parsing issue during sandbox tests for pin configuration (OF_LIVE is activated in sandbox_defconfig and sub node are not correctly parsed in pinctrl_generic_set_state_subnode with fdt lib API).

---

Changes in v3: None
Changes in v2:
- Change dev_ functions in pinctrl-generic

 drivers/pinctrl/pinctrl-generic.c | 30 +++++++++++-------------------
 1 file changed, 11 insertions(+), 19 deletions(-)
drivers/pinctrl/pinctrl-generic.c +11 -19
index eecf0f5dc1..9c4f73b1be 100644
@@ -8,8 +8,6 @@
 #include <linux/compat.h>
 #include <dm/pinctrl.h>
 
-DECLARE_GLOBAL_DATA_PTR;
-
 /**
  * pinctrl_pin_name_to_selector() - return the pin selector for a pin
  *
@@ -243,18 +241,14 @@ static int pinctrl_generic_set_state_one(struct udevice *dev,
 					 struct udevice *config,
 					 bool is_group, unsigned selector)
 {
-	const void *fdt = gd->fdt_blob;
-	int node_offset = dev_of_offset(config);
 	const char *propname;
 	const void *value;
-	int prop_offset, len, func_selector, param, ret;
+	struct ofprop property;
+	int len, func_selector, param, ret;
 	u32 arg, default_val;
 
-	for (prop_offset = fdt_first_property_offset(fdt, node_offset);
-	     prop_offset > 0;
-	     prop_offset = fdt_next_property_offset(fdt, prop_offset)) {
-		value = fdt_getprop_by_offset(fdt, prop_offset,
-					      &propname, &len);
+	dev_for_each_property(property, config) {
+		value = dev_read_prop_by_prop(&property, &propname, &len);
 		if (!value)
 			return -EINVAL;
 
@@ -298,19 +292,17 @@ static int pinctrl_generic_set_state_one(struct udevice *dev,
 static int pinctrl_generic_set_state_subnode(struct udevice *dev,
 					     struct udevice *config)
 {
-	const void *fdt = gd->fdt_blob;
-	int node = dev_of_offset(config);
 	const char *subnode_target_type = "pins";
 	bool is_group = false;
 	const char *name;
 	int strings_count, selector, i, ret;
 
-	strings_count = fdt_stringlist_count(fdt, node, subnode_target_type);
+	strings_count = dev_read_string_count(config, subnode_target_type);
 	if (strings_count < 0) {
 		subnode_target_type = "groups";
 		is_group = true;
-		strings_count = fdt_stringlist_count(fdt, node,
-						     subnode_target_type);
+		strings_count = dev_read_string_count(config,
+						      subnode_target_type);
 		if (strings_count < 0) {
 			/* skip this node; may contain config child nodes */
 			return 0;
@@ -318,10 +310,10 @@ static int pinctrl_generic_set_state_subnode(struct udevice *dev,
 	}
 
 	for (i = 0; i < strings_count; i++) {
-		name = fdt_stringlist_get(fdt, node, subnode_target_type, i,
-					  NULL);
-		if (!name)
-			return -EINVAL;
+		ret = dev_read_string_index(config, subnode_target_type, i,
+					    &name);
+		if (ret)
+			return ret;
 
 		if (is_group)
 			selector = pinctrl_group_name_to_selector(dev, name);
Signature · 1 line
2.17.1
#9 lore raw

PATCH v3 3/21 dm: pinctrl: migrate pinctrl-generic to livetree

Quoted 7 lines · Patrick Delaunay

Migrate pinctrl-generic to livetree:
- dev_for_each_property
- dev_read_prop_by_prop
- dev_read_string_count
- dev_read_string_index
and get rid of DECLARE_GLOBAL_DATA_PTR.

Quoted 7 lines

This patch solves the parsing issue during sandbox tests for pin configuration (OF_LIVE is activated in sandbox_defconfig and sub node are not correctly parsed in pinctrl_generic_set_state_subnode with fdt lib API).

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/c9e2f38d/attachment.sig>
#10 lore raw

PATCH v3 4/21 dt-bindings: gpio: document the new pull-up/pull-down flags

In reply to Patrick Delaunay

This commit extends the flags that can be used in GPIO specifiers to indicate if a pull-up resistor or pull-down resistor should be enabled.

It is the backport of linux commit ede033e1e863c ('dt-bindings:
gpio: document the new pull-up/pull-down flags')
from Thomas Petazzoni <[email protected]> and integrated in v5.1-rc1
https://github.com/torvalds/linux/commit/ede033e1e863c

---

Changes in v3: None
Changes in v2: None

 doc/device-tree-bindings/gpio/gpio.txt | 24 ++++++++++++++++++++++++
 include/dt-bindings/gpio/gpio.h        |  6 ++++++
 2 files changed, 30 insertions(+)
doc/device-tree-bindings/gpio/gpio.txt +24 -0
index e146917ff3..e9ef0212af 100644
@@ -65,6 +65,30 @@ Example of a node using GPIOs:
 GPIO_ACTIVE_HIGH is 0, so in this example gpio-specifier is "18 0" and encodes
 GPIO pin number, and GPIO flags as accepted by the "qe_pio_e" gpio-controller.
 
+Optional standard bitfield specifiers for the last cell:
+
+- Bit 0: 0 means active high, 1 means active low
+- Bit 1: 0 mean push-pull wiring, see:
+           https://en.wikipedia.org/wiki/Push-pull_output
+         1 means single-ended wiring, see:
+           https://en.wikipedia.org/wiki/Single-ended_triode
+- Bit 2: 0 means open-source, 1 means open drain, see:
+           https://en.wikipedia.org/wiki/Open_collector
+- Bit 3: 0 means the output should be maintained during sleep/low-power mode
+         1 means the output state can be lost during sleep/low-power mode
+- Bit 4: 0 means no pull-up resistor should be enabled
+         1 means a pull-up resistor should be enabled
+         This setting only applies to hardware with a simple on/off
+         control for pull-up configuration. If the hardware has more
+         elaborate pull-up configuration, it should be represented
+         using a pin control binding.
+- Bit 5: 0 means no pull-down resistor should be enabled
+         1 means a pull-down resistor should be enabled
+         This setting only applies to hardware with a simple on/off
+         control for pull-down configuration. If the hardware has more
+         elaborate pull-down configuration, it should be represented
+         using a pin control binding.
+
 1.1) GPIO specifier best practices
 ----------------------------------
 
include/dt-bindings/gpio/gpio.h +6 -0
index 2cc10ae4bb..c029467e82 100644
@@ -33,4 +33,10 @@
 #define GPIO_PERSISTENT 0
 #define GPIO_TRANSITORY 8
 
+/* Bit 4 express pull up */
+#define GPIO_PULL_UP 16
+
+/* Bit 5 express pull down */
+#define GPIO_PULL_DOWN 32
+
 #endif
Signature · 1 line
2.17.1
#11 lore raw

PATCH v3 4/21 dt-bindings: gpio: document the new pull-up/pull-down flags

Quoted 6 lines · Patrick Delaunay

This commit extends the flags that can be used in GPIO specifiers to indicate if a pull-up resistor or pull-down resistor should be enabled.

It is the backport of linux commit ede033e1e863c ('dt-bindings:

Strictly speaking I don't think this is a backport, since this is a different project.

Quoted 6 lines

gpio: document the new pull-up/pull-down flags') from Thomas Petazzoni <[email protected]> and integrated in v5.1-rc1
https://github.com/torvalds/linux/commit/ede033e1e863c

Quoted 8 lines

---

Changes in v3: None
Changes in v2: None

 doc/device-tree-bindings/gpio/gpio.txt | 24 ++++++++++++++++++++++++
 include/dt-bindings/gpio/gpio.h        |  6 ++++++
 2 files changed, 30 insertions(+)
#12 lore raw

PATCH v3 4/21 dt-bindings: gpio: document the new pull-up/pull-down flags

In reply to Patrick Delaunay
Quoted 4 lines · Patrick Delaunay

This commit extends the flags that can be used in GPIO specifiers to indicate if a pull-up resistor or pull-down resistor should be enabled.

Quoted 8 lines

It is the backport of linux commit ede033e1e863c ('dt-bindings:
gpio: document the new pull-up/pull-down flags')
from Thomas Petazzoni <[email protected]> and integrated in v5.1-rc1
https://github.com/torvalds/linux/commit/ede033e1e863c

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/c0598c03/attachment.sig>
#13 lore raw

PATCH v3 5/21 gpio: remove GPIOD_REQUESTED

In reply to Patrick Delaunay

Remove the define GPIOD_REQUESTED as it is never used and use BIT() macro for other defines.

---

Changes in v3: None
Changes in v2:
- remove the unused GPIOD_REQUESTED

 include/asm-generic/gpio.h | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
include/asm-generic/gpio.h +4 -5
index d6cf18744f..7da2015805 100644
@@ -117,11 +117,10 @@ struct udevice;
 struct gpio_desc {
 	struct udevice *dev;	/* Device, NULL for invalid GPIO */
 	unsigned long flags;
-#define GPIOD_REQUESTED		(1 << 0)	/* Requested/claimed */
-#define GPIOD_IS_OUT		(1 << 1)	/* GPIO is an output */
-#define GPIOD_IS_IN		(1 << 2)	/* GPIO is an input */
-#define GPIOD_ACTIVE_LOW	(1 << 3)	/* value has active low */
-#define GPIOD_IS_OUT_ACTIVE	(1 << 4)	/* set output active */
+#define GPIOD_IS_OUT		BIT(1)	/* GPIO is an output */
+#define GPIOD_IS_IN		BIT(2)	/* GPIO is an input */
+#define GPIOD_ACTIVE_LOW	BIT(3)	/* value has active low */
+#define GPIOD_IS_OUT_ACTIVE	BIT(4)	/* set output active */
 
 	uint offset;		/* GPIO offset within the device */
 	/*
Signature · 1 line
2.17.1
#14 lore raw

PATCH v3 5/21 gpio: remove GPIOD_REQUESTED

Quoted 5 lines · Patrick Delaunay

Remove the define GPIOD_REQUESTED as it is never used and use BIT() macro for other defines.

Quoted 8 lines

---

Changes in v3: None
Changes in v2:
- remove the unused GPIOD_REQUESTED

 include/asm-generic/gpio.h | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
#15 lore raw

PATCH v3 5/21 gpio: remove GPIOD_REQUESTED

In reply to Patrick Delaunay
Quoted 5 lines · Patrick Delaunay

Remove the define GPIOD_REQUESTED as it is never used and use BIT() macro for other defines.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/198334fb/attachment.sig>
#16 lore raw

PATCH v3 6/21 gpio: remove the open_drain API and ops

In reply to Patrick Delaunay

This patch removes the ops get_open_drain/set_open_drain and the API dm_gpio_get_open_drain/dm_gpio_set_open_drain.

The ops only provided in one driver (mpc8xxx gpio) and the associated API is never called in boards.

This patch prepare a more generic set/get_dir_flags ops, including the open drain property.

---

Changes in v3: None
Changes in v2:
- remove the open_drain API and ops

 arch/sandbox/include/asm/gpio.h | 20 ------------------
 drivers/gpio/gpio-uclass.c      | 36 ---------------------------------
 drivers/gpio/mpc8xxx_gpio.c     | 22 --------------------
 drivers/gpio/sandbox.c          | 35 --------------------------------
 include/asm-generic/gpio.h      | 34 -------------------------------
 test/dm/gpio.c                  |  7 -------
 6 files changed, 154 deletions(-)
arch/sandbox/include/asm/gpio.h +0 -20
index de8ac37f42..cfb803bb3b 100644
@@ -42,26 +42,6 @@ int sandbox_gpio_get_value(struct udevice *dev, unsigned int offset);
  */
 int sandbox_gpio_set_value(struct udevice *dev, unsigned int offset, int value);
 
-/**
- * Set or reset the simulated open drain mode of a GPIO (used only in sandbox
- * test code)
- *
- * @param gp	GPIO number
- * @param value	value to set (0 for enabled open drain mode, non-zero for
- * 		disabled)
- * @return -1 on error, 0 if ok
- */
-int sandbox_gpio_set_open_drain(struct udevice *dev, unsigned offset, int value);
-
-/**
- * Return the state of the simulated open drain mode of a GPIO (used only in
- * sandbox test code)
- *
- * @param gp	GPIO number
- * @return -1 on error, 0 if GPIO is input, >0 if output
- */
-int sandbox_gpio_get_open_drain(struct udevice *dev, unsigned offset);
-
 /**
  * Return the simulated direction of a GPIO (used only in sandbox test code)
  *
drivers/gpio/gpio-uclass.c +0 -36
index 90fbed455b..eb599cbcfd 100644
@@ -491,38 +491,6 @@ int dm_gpio_set_value(const struct gpio_desc *desc, int value)
 	return 0;
 }
 
-int dm_gpio_get_open_drain(struct gpio_desc *desc)
-{
-	struct dm_gpio_ops *ops = gpio_get_ops(desc->dev);
-	int ret;
-
-	ret = check_reserved(desc, "get_open_drain");
-	if (ret)
-		return ret;
-
-	if (ops->set_open_drain)
-		return ops->get_open_drain(desc->dev, desc->offset);
-	else
-		return -ENOSYS;
-}
-
-int dm_gpio_set_open_drain(struct gpio_desc *desc, int value)
-{
-	struct dm_gpio_ops *ops = gpio_get_ops(desc->dev);
-	int ret;
-
-	ret = check_reserved(desc, "set_open_drain");
-	if (ret)
-		return ret;
-
-	if (ops->set_open_drain)
-		ret = ops->set_open_drain(desc->dev, desc->offset, value);
-	else
-		return 0; /* feature not supported -> ignore setting */
-
-	return ret;
-}
-
 int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
 {
 	struct udevice *dev = desc->dev;
@@ -1053,10 +1021,6 @@ static int gpio_post_bind(struct udevice *dev)
 			ops->get_value += gd->reloc_off;
 		if (ops->set_value)
 			ops->set_value += gd->reloc_off;
-		if (ops->get_open_drain)
-			ops->get_open_drain += gd->reloc_off;
-		if (ops->set_open_drain)
-			ops->set_open_drain += gd->reloc_off;
 		if (ops->get_function)
 			ops->get_function += gd->reloc_off;
 		if (ops->xlate)
drivers/gpio/mpc8xxx_gpio.c +0 -22
index c273c2c8a4..c23f5b5227 100644
@@ -144,26 +144,6 @@ static int mpc8xxx_gpio_get_value(struct udevice *dev, uint gpio)
 	return !!mpc8xxx_gpio_get_val(data->base, gpio_mask(gpio));
 }
 
-static int mpc8xxx_gpio_get_open_drain(struct udevice *dev, uint gpio)
-{
-	struct mpc8xxx_gpio_data *data = dev_get_priv(dev);
-
-	return !!mpc8xxx_gpio_open_drain_val(data->base, gpio_mask(gpio));
-}
-
-static int mpc8xxx_gpio_set_open_drain(struct udevice *dev, uint gpio,
-				       int value)
-{
-	struct mpc8xxx_gpio_data *data = dev_get_priv(dev);
-
-	if (value)
-		mpc8xxx_gpio_open_drain_on(data->base, gpio_mask(gpio));
-	else
-		mpc8xxx_gpio_open_drain_off(data->base, gpio_mask(gpio));
-
-	return 0;
-}
-
 static int mpc8xxx_gpio_get_function(struct udevice *dev, uint gpio)
 {
 	struct mpc8xxx_gpio_data *data = dev_get_priv(dev);
@@ -240,8 +220,6 @@ static const struct dm_gpio_ops gpio_mpc8xxx_ops = {
 	.direction_output	= mpc8xxx_gpio_direction_output,
 	.get_value		= mpc8xxx_gpio_get_value,
 	.set_value		= mpc8xxx_gpio_set_value,
-	.get_open_drain		= mpc8xxx_gpio_get_open_drain,
-	.set_open_drain		= mpc8xxx_gpio_set_open_drain,
 	.get_function		= mpc8xxx_gpio_get_function,
 };
 
drivers/gpio/sandbox.c +0 -35
index 2ef5c67ad5..91e8e0677e 100644
@@ -14,7 +14,6 @@
 /* Flags for each GPIO */
 #define GPIOF_OUTPUT	(1 << 0)	/* Currently set as an output */
 #define GPIOF_HIGH	(1 << 1)	/* Currently set high */
-#define GPIOF_ODR	(1 << 2)	/* Currently set to open drain mode */
 
 struct gpio_state {
 	const char *label;	/* label given by requester */
@@ -70,16 +69,6 @@ int sandbox_gpio_set_value(struct udevice *dev, unsigned offset, int value)
 	return set_gpio_flag(dev, offset, GPIOF_HIGH, value);
 }
 
-int sandbox_gpio_get_open_drain(struct udevice *dev, unsigned offset)
-{
-	return get_gpio_flag(dev, offset, GPIOF_ODR);
-}
-
-int sandbox_gpio_set_open_drain(struct udevice *dev, unsigned offset, int value)
-{
-	return set_gpio_flag(dev, offset, GPIOF_ODR, value);
-}
-
 int sandbox_gpio_get_direction(struct udevice *dev, unsigned offset)
 {
 	return get_gpio_flag(dev, offset, GPIOF_OUTPUT);
@@ -134,28 +123,6 @@ static int sb_gpio_set_value(struct udevice *dev, unsigned offset, int value)
 	return sandbox_gpio_set_value(dev, offset, value);
 }
 
-/* read GPIO ODR value of port 'offset' */
-static int sb_gpio_get_open_drain(struct udevice *dev, unsigned offset)
-{
-	debug("%s: offset:%u\n", __func__, offset);
-
-	return sandbox_gpio_get_open_drain(dev, offset);
-}
-
-/* write GPIO ODR value to port 'offset' */
-static int sb_gpio_set_open_drain(struct udevice *dev, unsigned offset, int value)
-{
-	debug("%s: offset:%u, value = %d\n", __func__, offset, value);
-
-	if (!sandbox_gpio_get_direction(dev, offset)) {
-		printf("sandbox_gpio: error: set_open_drain on input gpio %u\n",
-		       offset);
-		return -1;
-	}
-
-	return sandbox_gpio_set_open_drain(dev, offset, value);
-}
-
 static int sb_gpio_get_function(struct udevice *dev, unsigned offset)
 {
 	if (get_gpio_flag(dev, offset, GPIOF_OUTPUT))
@@ -186,8 +153,6 @@ static const struct dm_gpio_ops gpio_sandbox_ops = {
 	.direction_output	= sb_gpio_direction_output,
 	.get_value		= sb_gpio_get_value,
 	.set_value		= sb_gpio_set_value,
-	.get_open_drain		= sb_gpio_get_open_drain,
-	.set_open_drain		= sb_gpio_set_open_drain,
 	.get_function		= sb_gpio_get_function,
 	.xlate			= sb_gpio_xlate,
 };
include/asm-generic/gpio.h +0 -34
index 7da2015805..454578c8d2 100644
@@ -253,8 +253,6 @@ struct dm_gpio_ops {
 				int value);
 	int (*get_value)(struct udevice *dev, unsigned offset);
 	int (*set_value)(struct udevice *dev, unsigned offset, int value);
-	int (*get_open_drain)(struct udevice *dev, unsigned offset);
-	int (*set_open_drain)(struct udevice *dev, unsigned offset, int value);
 	/**
 	 * get_function() Get the GPIO function
 	 *
@@ -585,38 +583,6 @@ int dm_gpio_get_value(const struct gpio_desc *desc);
 
 int dm_gpio_set_value(const struct gpio_desc *desc, int value);
 
-/**
- * dm_gpio_get_open_drain() - Check if open-drain-mode of a GPIO is active
- *
- * This checks if open-drain-mode for a GPIO is enabled or not. This method is
- * optional.
- *
- * @desc:	GPIO description containing device, offset and flags,
- *		previously returned by gpio_request_by_name()
- * @return Value of open drain mode for GPIO (0 for inactive, 1 for active) or
- *	   -ve on error
- */
-int dm_gpio_get_open_drain(struct gpio_desc *desc);
-
-/**
- * dm_gpio_set_open_drain() - Switch open-drain-mode of a GPIO on or off
- *
- * This enables or disables open-drain mode for a GPIO. This method is
- * optional; if the driver does not support it, nothing happens when the method
- * is called.
- *
- * In open-drain mode, instead of actively driving the output (Push-pull
- * output), the GPIO's pin is connected to the collector (for a NPN transistor)
- * or the drain (for a MOSFET) of a transistor, respectively. The pin then
- * either forms an open circuit or a connection to ground, depending on the
- * state of the transistor.
- *
- * @desc:	GPIO description containing device, offset and flags,
- *		previously returned by gpio_request_by_name()
- * @return 0 if OK, -ve on error
- */
-int dm_gpio_set_open_drain(struct gpio_desc *desc, int value);
-
 /**
  * dm_gpio_set_dir() - Set the direction for a GPIO
  *
test/dm/gpio.c +0 -7
index bb4b20cea9..8abf0cd8c8 100644
@@ -72,13 +72,6 @@ static int dm_test_gpio(struct unit_test_state *uts)
 	ut_assertok(ops->set_value(dev, offset, 1));
 	ut_asserteq(1, ops->get_value(dev, offset));
 
-	/* Make it an open drain output, and reset it */
-	ut_asserteq(0, sandbox_gpio_get_open_drain(dev, offset));
-	ut_assertok(ops->set_open_drain(dev, offset, 1));
-	ut_asserteq(1, sandbox_gpio_get_open_drain(dev, offset));
-	ut_assertok(ops->set_open_drain(dev, offset, 0));
-	ut_asserteq(0, sandbox_gpio_get_open_drain(dev, offset));
-
 	/* Make it an input */
 	ut_assertok(ops->direction_input(dev, offset));
 	ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
Signature · 1 line
2.17.1
#17 lore raw

PATCH v3 6/21 gpio: remove the open_drain API and ops

Quoted 11 lines · Patrick Delaunay

This patch removes the ops get_open_drain/set_open_drain and the API dm_gpio_get_open_drain/dm_gpio_set_open_drain.

The ops only provided in one driver (mpc8xxx gpio) and the associated API is never called in boards.

This patch prepare a more generic set/get_dir_flags ops, including the open drain property.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/12618391/attachment.sig>
#18 lore raw

PATCH v3 7/21 gpio: add gpio descriptor initialization helper

In reply to Patrick Delaunay

Add a helper function gpio_desc_init() to initialize the gpio descriptor; with this function the flags will be always set to 0.

It wasn't the case before this patch in dm_gpio_lookup_name.

---

Changes in v3: None
Changes in v2:
- add gpio descriptor initialization helper

 drivers/gpio/gpio-uclass.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)
drivers/gpio/gpio-uclass.c +19 -8
index eb599cbcfd..0870458e96 100644
@@ -18,6 +18,22 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+/**
+ * gpio_desc_init() - Initialize the GPIO descriptor
+ *
+ * @desc:	GPIO descriptor to initialize
+ * @dev:	GPIO device
+ * @offset:	Offset of device GPIO
+ */
+static void gpio_desc_init(struct gpio_desc *desc,
+			   struct udevice *dev,
+			   uint offset)
+{
+	desc->dev = dev;
+	desc->offset = offset;
+	desc->flags = 0;
+}
+
 /**
  * gpio_to_device() - Convert global GPIO number to device, number
  *
@@ -41,9 +57,7 @@ static int gpio_to_device(unsigned int gpio, struct gpio_desc *desc)
 		uc_priv = dev_get_uclass_priv(dev);
 		if (gpio >= uc_priv->gpio_base &&
 		    gpio < uc_priv->gpio_base + uc_priv->gpio_count) {
-			desc->dev = dev;
-			desc->offset = gpio - uc_priv->gpio_base;
-			desc->flags = 0;
+			gpio_desc_init(desc, dev, gpio - uc_priv->gpio_base);
 			return 0;
 		}
 	}
@@ -85,8 +99,7 @@ int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc)
 	if (!dev)
 		return ret ? ret : -EINVAL;
 
-	desc->dev = dev;
-	desc->offset = offset;
+	gpio_desc_init(desc, dev, offset);
 
 	return 0;
 }
@@ -772,9 +785,7 @@ static int gpio_request_tail(int ret, const char *nodename,
 			     struct gpio_desc *desc, int flags,
 			     bool add_index, struct udevice *gpio_dev)
 {
-	desc->dev = gpio_dev;
-	desc->offset = 0;
-	desc->flags = 0;
+	gpio_desc_init(desc, gpio_dev, 0);
 	if (ret)
 		goto err;
 
Signature · 1 line
2.17.1
#19 lore raw

PATCH v3 7/21 gpio: add gpio descriptor initialization helper

Quoted 7 lines · Patrick Delaunay

Add a helper function gpio_desc_init() to initialize the gpio descriptor; with this function the flags will be always set to 0.

It wasn't the case before this patch in dm_gpio_lookup_name.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/63caa7e5/attachment.sig>
#20 lore raw

PATCH v3 8/21 gpio: add function _gpio_get_value

In reply to Patrick Delaunay

Introduce the function _gpio_get_value to get the GPIO value without check if it is reserved.
This patch prepare new ops introduction.

---

This patch was part of v2 08/14
= gpio: add ops for configuration with dir flags

Changes in v3:
- Split the previous patch [PATCH v2 08/14] to help review

Changes in v2: None

 drivers/gpio/gpio-uclass.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/gpio/gpio-uclass.c +10 -4
index 0870458e96..bdf7f5bb4e 100644
@@ -476,18 +476,24 @@ int gpio_direction_output(unsigned gpio, int value)
 							desc.offset, value);
 }
 
-int dm_gpio_get_value(const struct gpio_desc *desc)
+static int _gpio_get_value(const struct gpio_desc *desc)
 {
 	int value;
+
+	value = gpio_get_ops(desc->dev)->get_value(desc->dev, desc->offset);
+
+	return desc->flags & GPIOD_ACTIVE_LOW ? !value : value;
+}
+
+int dm_gpio_get_value(const struct gpio_desc *desc)
+{
 	int ret;
 
 	ret = check_reserved(desc, "get_value");
 	if (ret)
 		return ret;
 
-	value = gpio_get_ops(desc->dev)->get_value(desc->dev, desc->offset);
-
-	return desc->flags & GPIOD_ACTIVE_LOW ? !value : value;
+	return _gpio_get_value(desc);
 }
 
 int dm_gpio_set_value(const struct gpio_desc *desc, int value)
Signature · 1 line
2.17.1
#21 lore raw

PATCH v3 8/21 gpio: add function _gpio_get_value

Quoted 12 lines · Patrick Delaunay

Introduce the function _gpio_get_value to get the GPIO value without check if it is reserved.
This patch prepare new ops introduction.

---

This patch was part of v2 08/14
= gpio: add ops for configuration with dir flags

Quoted 7 lines

Changes in v3:
- Split the previous patch [PATCH v2 08/14] to help review

Changes in v2: None

 drivers/gpio/gpio-uclass.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
#22 lore raw

PATCH v3 8/21 gpio: add function _gpio_get_value

In reply to Patrick Delaunay
Quoted 6 lines · Patrick Delaunay

Introduce the function _gpio_get_value to get the GPIO value without check if it is reserved.
This patch prepare new ops introduction.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/ac888971/attachment.sig>
#23 lore raw

PATCH v3 9/21 gpio: add function _dm_gpio_set_dir_flags

In reply to Patrick Delaunay

Introduce the function _dm_gpio_set_dir_flags to set dir flags without check if the GPIO is reserved.

Separate the reserved check for "set_dir" and "set_dir_flags".

This patch is a preliminary step to add new ops.

---

This patch was part of v2 08/14
= gpio: add ops for configuration with dir flags

Changes in v3:
- Split the previous patch [PATCH v2 08/14] to help review

Changes in v2: None

 drivers/gpio/gpio-uclass.c | 38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)
drivers/gpio/gpio-uclass.c +25 -13
index bdf7f5bb4e..94e90cb8ac 100644
@@ -510,15 +510,11 @@ int dm_gpio_set_value(const struct gpio_desc *desc, int value)
 	return 0;
 }
 
-int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
+static int _dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
 {
 	struct udevice *dev = desc->dev;
 	struct dm_gpio_ops *ops = gpio_get_ops(dev);
-	int ret;
-
-	ret = check_reserved(desc, "set_dir");
-	if (ret)
-		return ret;
+	int ret = 0;
 
 	if (flags & GPIOD_IS_OUT) {
 		int value = flags & GPIOD_IS_OUT_ACTIVE ? 1 : 0;
@@ -529,20 +525,36 @@ int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
 	} else  if (flags & GPIOD_IS_IN) {
 		ret = ops->direction_input(dev, desc->offset);
 	}
+
+	return ret;
+}
+
+int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
+{
+	int ret;
+
+	ret = check_reserved(desc, "set_dir_flags");
 	if (ret)
 		return ret;
-	/*
-	 * Update desc->flags here, so that GPIO_ACTIVE_LOW is honoured in
-	 * futures
-	 */
-	desc->flags = flags;
 
-	return 0;
+	ret = _dm_gpio_set_dir_flags(desc, flags);
+
+	/* update the descriptor flags */
+	if (ret)
+		desc->flags = flags;
+
+	return ret;
 }
 
 int dm_gpio_set_dir(struct gpio_desc *desc)
 {
-	return dm_gpio_set_dir_flags(desc, desc->flags);
+	int ret;
+
+	ret = check_reserved(desc, "set_dir");
+	if (ret)
+		return ret;
+
+	return _dm_gpio_set_dir_flags(desc, desc->flags);
 }
 
 /**
Signature · 1 line
2.17.1
#24 lore raw

PATCH v3 9/21 gpio: add function _dm_gpio_set_dir_flags

Quoted 15 lines · Patrick Delaunay

Introduce the function _dm_gpio_set_dir_flags to set dir flags without check if the GPIO is reserved.

Separate the reserved check for "set_dir" and "set_dir_flags".

This patch is a preliminary step to add new ops.

---

This patch was part of v2 08/14
= gpio: add ops for configuration with dir flags

Quoted 7 lines

Changes in v3:
- Split the previous patch [PATCH v2 08/14] to help review

Changes in v2: None

 drivers/gpio/gpio-uclass.c | 38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)
#25 lore raw

PATCH v3 9/21 gpio: add function _dm_gpio_set_dir_flags

In reply to Patrick Delaunay
Quoted 9 lines · Patrick Delaunay

Introduce the function _dm_gpio_set_dir_flags to set dir flags without check if the GPIO is reserved.

Separate the reserved check for "set_dir" and "set_dir_flags".

This patch is a preliminary step to add new ops.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/82efa04c/attachment.sig>
#26 lore raw

PATCH v3 10/21 gpio: add function check_dir_flags

In reply to Patrick Delaunay

Add a dir flags validity check with a new function check_dir_flags.

---

This patch was part of v2 08/14
= gpio: add ops for configuration with dir flags

Changes in v3:
- Split the previous patch [PATCH v2 08/14] to help review

Changes in v2: None

 drivers/gpio/gpio-uclass.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/gpio/gpio-uclass.c +24 -0
index 94e90cb8ac..62462dffa5 100644
@@ -510,12 +510,36 @@ int dm_gpio_set_value(const struct gpio_desc *desc, int value)
 	return 0;
 }
 
+/* check dir flags invalid configuration */
+static int check_dir_flags(ulong flags)
+{
+	if ((flags & GPIOD_IS_OUT) && (flags & GPIOD_IS_IN)) {
+		log_debug("%s: flags 0x%lx has GPIOD_IS_OUT and GPIOD_IS_IN\n",
+			  __func__, flags);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int _dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
 {
 	struct udevice *dev = desc->dev;
 	struct dm_gpio_ops *ops = gpio_get_ops(dev);
+	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
 	int ret = 0;
 
+	ret = check_dir_flags(flags);
+	if (ret) {
+		dev_dbg(dev,
+			"%s error: set_dir_flags for gpio %s%d has invalid dir flags 0x%lx\n",
+			desc->dev->name,
+			uc_priv->bank_name ? uc_priv->bank_name : "",
+			desc->offset, flags);
+
+		return ret;
+	}
+
 	if (flags & GPIOD_IS_OUT) {
 		int value = flags & GPIOD_IS_OUT_ACTIVE ? 1 : 0;
 
Signature · 1 line
2.17.1
#27 lore raw

PATCH v3 10/21 gpio: add function check_dir_flags

Quoted 11 lines · Patrick Delaunay

Add a dir flags validity check with a new function check_dir_flags.

---

This patch was part of v2 08/14
= gpio: add ops for configuration with dir flags

Quoted 7 lines

Changes in v3:
- Split the previous patch [PATCH v2 08/14] to help review

Changes in v2: None

 drivers/gpio/gpio-uclass.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
#28 lore raw

PATCH v3 10/21 gpio: add function check_dir_flags

In reply to Patrick Delaunay
Quoted 5 lines · Patrick Delaunay

Add a dir flags validity check with a new function check_dir_flags.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/e5df5d82/attachment.sig>
#29 lore raw

PATCH v3 11/21 gpio: add helper GPIOD_FLAGS_OUTPUT

In reply to Patrick Delaunay

Add a macro to provide the GPIO output value according the dir flags content.

---

This patch was part of v2 08/14
= gpio: add ops for configuration with dir flags

Changes in v3:
- Split the previous patch [PATCH v2 08/14] to help review

Changes in v2: None

 drivers/gpio/gpio-uclass.c | 9 +++------
 include/asm-generic/gpio.h | 6 ++++++
 2 files changed, 9 insertions(+), 6 deletions(-)
drivers/gpio/gpio-uclass.c +3 -6
index 62462dffa5..1d16d4acf9 100644
@@ -541,12 +541,9 @@ static int _dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
 	}
 
 	if (flags & GPIOD_IS_OUT) {
-		int value = flags & GPIOD_IS_OUT_ACTIVE ? 1 : 0;
-
-		if (flags & GPIOD_ACTIVE_LOW)
-			value = !value;
-		ret = ops->direction_output(dev, desc->offset, value);
-	} else  if (flags & GPIOD_IS_IN) {
+		ret = ops->direction_output(dev, desc->offset,
+					    GPIOD_FLAGS_OUTPUT(flags));
+	} else if (flags & GPIOD_IS_IN) {
 		ret = ops->direction_input(dev, desc->offset);
 	}
 
include/asm-generic/gpio.h +6 -0
index 454578c8d2..111319f41f 100644
@@ -129,6 +129,12 @@ struct gpio_desc {
 	 */
 };
 
+/* helper to compute the value of the gpio output */
+#define GPIOD_FLAGS_OUTPUT_MASK (GPIOD_ACTIVE_LOW | GPIOD_IS_OUT_ACTIVE)
+#define GPIOD_FLAGS_OUTPUT(flags) \
+	(((((flags) & GPIOD_FLAGS_OUTPUT_MASK) == GPIOD_IS_OUT_ACTIVE) || \
+	  (((flags) & GPIOD_FLAGS_OUTPUT_MASK) == GPIOD_ACTIVE_LOW)))
+
 /**
  * dm_gpio_is_valid() - Check if a GPIO is valid
  *
Signature · 1 line
2.17.1
#30 lore raw

PATCH v3 11/21 gpio: add helper GPIOD_FLAGS_OUTPUT

Quoted 11 lines · Patrick Delaunay

Add a macro to provide the GPIO output value according the dir flags content.

---

This patch was part of v2 08/14
= gpio: add ops for configuration with dir flags

Quoted 9 lines

Changes in v3:
- Split the previous patch [PATCH v2 08/14] to help review

Changes in v2: None

 drivers/gpio/gpio-uclass.c | 9 +++------
 include/asm-generic/gpio.h | 6 ++++++
 2 files changed, 9 insertions(+), 6 deletions(-)
Quoted 25 lines
drivers/gpio/gpio-uclass.c +3 -6
index 62462dffa5..1d16d4acf9 100644
@@ -541,12 +541,9 @@ static int _dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
        }
 
        if (flags & GPIOD_IS_OUT) {
-               int value = flags & GPIOD_IS_OUT_ACTIVE ? 1 : 0;
-
-               if (flags & GPIOD_ACTIVE_LOW)
-                       value = !value;
-               ret = ops->direction_output(dev, desc->offset, value);
-       } else  if (flags & GPIOD_IS_IN) {
+               ret = ops->direction_output(dev, desc->offset,
+                                           GPIOD_FLAGS_OUTPUT(flags));
+       } else if (flags & GPIOD_IS_IN) {
                ret = ops->direction_input(dev, desc->offset);
        }
 
include/asm-generic/gpio.h +0 -0
index 454578c8d2..111319f41f 100644

include/asm-generic/gpio.h struct gpio_desc { · line 136

Quoted 8 lines
include/asm-generic/gpio.h +5 -0
@@ -129,6 +129,12 @@ struct gpio_desc {
         */
 };
 
+/* helper to compute the value of the gpio output */
+#define GPIOD_FLAGS_OUTPUT_MASK (GPIOD_ACTIVE_LOW | GPIOD_IS_OUT_ACTIVE)
+#define GPIOD_FLAGS_OUTPUT(flags) \
+       (((((flags) & GPIOD_FLAGS_OUTPUT_MASK) == GPIOD_IS_OUT_ACTIVE) || \
+         (((flags) & GPIOD_FLAGS_OUTPUT_MASK) == GPIOD_ACTIVE_LOW)))

nit: you don't need brackets around the == operands, I think.

Quoted 7 lines
include/asm-generic/gpio.h +1 -1
+
 /**
  * dm_gpio_is_valid() - Check if a GPIO is valid
  *
--

2.17.1

#31 lore raw

PATCH v3 11/21 gpio: add helper GPIOD_FLAGS_OUTPUT

In reply to Patrick Delaunay
Quoted 5 lines · Patrick Delaunay

Add a macro to provide the GPIO output value according the dir flags content.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/64f90587/attachment.sig>
#32 lore raw

PATCH v3 12/21 gpio: update dir_flags management

In reply to Patrick Delaunay

Update the flag management in GPIO uclass: the desc->flags is always combined with the requested flags and the GPIO descriptor is updated for further call.

Add a function dm_gpio_get_dir_flags to get dynamically the current dir_flags (configuration and value).

This patch prepare introduction of the dir flags support with new ops.

---

This patch was part of v2 08/14
= gpio: add ops for configuration with dir flags

Changes in v3:
- Split the previous patch [PATCH v2 08/14] to help review

Changes in v2: None

 drivers/gpio/gpio-uclass.c | 27 +++++++++++++++++++++++++--
 include/asm-generic/gpio.h | 22 ++++++++++++++++------
 2 files changed, 41 insertions(+), 8 deletions(-)
drivers/gpio/gpio-uclass.c +25 -2
index 1d16d4acf9..85f0b03f81 100644
@@ -140,8 +140,9 @@ int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,
 	if (args->args_count < 2)
 		return 0;
 
+	desc->flags = 0;
 	if (args->args[1] & GPIO_ACTIVE_LOW)
-		desc->flags = GPIOD_ACTIVE_LOW;
+		desc->flags |= GPIOD_ACTIVE_LOW;
 
 	return 0;
 }
@@ -558,6 +559,8 @@ int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
 	if (ret)
 		return ret;
 
+	/* combine the requested flags (for IN/OUT) and the descriptor flags */
+	flags |= desc->flags;
 	ret = _dm_gpio_set_dir_flags(desc, flags);
 
 	/* update the descriptor flags */
@@ -578,6 +581,26 @@ int dm_gpio_set_dir(struct gpio_desc *desc)
 	return _dm_gpio_set_dir_flags(desc, desc->flags);
 }
 
+int dm_gpio_get_dir_flags(struct gpio_desc *desc, ulong *flags)
+{
+	int ret;
+	ulong dir_flags;
+
+	ret = check_reserved(desc, "get_dir_flags");
+	if (ret)
+		return ret;
+
+	dir_flags = desc->flags;
+	/* only GPIOD_IS_OUT_ACTIVE is provided by uclass */
+	dir_flags &= ~GPIOD_IS_OUT_ACTIVE;
+	if ((desc->flags & GPIOD_IS_OUT) && _gpio_get_value(desc))
+		dir_flags |= GPIOD_IS_OUT_ACTIVE;
+
+	*flags = dir_flags;
+
+	return 0;
+}
+
 /**
  * gpio_get_value() - [COMPAT] Sample GPIO pin and return it's value
  * gpio:	GPIO number
@@ -848,7 +871,7 @@ static int gpio_request_tail(int ret, const char *nodename,
 		debug("%s: dm_gpio_requestf failed\n", __func__);
 		goto err;
 	}
-	ret = dm_gpio_set_dir_flags(desc, flags | desc->flags);
+	ret = dm_gpio_set_dir_flags(desc, flags);
 	if (ret) {
 		debug("%s: dm_gpio_set_dir failed\n", __func__);
 		goto err;
include/asm-generic/gpio.h +16 -6
index 111319f41f..3dd0002b0b 100644
@@ -592,8 +592,7 @@ int dm_gpio_set_value(const struct gpio_desc *desc, int value);
 /**
  * dm_gpio_set_dir() - Set the direction for a GPIO
  *
- * This sets up the direction according tot the provided flags. It will do
- * nothing unless the direction is actually specified.
+ * This sets up the direction according to the GPIO flags: desc->flags.
  *
  * @desc:	GPIO description containing device, offset and flags,
  *		previously returned by gpio_request_by_name()
@@ -602,11 +601,10 @@ int dm_gpio_set_value(const struct gpio_desc *desc, int value);
 int dm_gpio_set_dir(struct gpio_desc *desc);
 
 /**
- * dm_gpio_set_dir_flags() - Set direction using specific flags
+ * dm_gpio_set_dir_flags() - Set direction using description and added flags
  *
- * This is like dm_gpio_set_dir() except that the flags value is provided
- * instead of being used from desc->flags. This is needed because in many
- * cases the GPIO description does not include direction information.
+ * This sets up the direction according to the provided flags and the GPIO
+ * description (desc->flags) which include direction information.
  * Note that desc->flags is updated by this function.
  *
  * @desc:	GPIO description containing device, offset and flags,
@@ -616,6 +614,18 @@ int dm_gpio_set_dir(struct gpio_desc *desc);
  */
 int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags);
 
+/**
+ * dm_gpio_get_dir_flags() - Get direction flags
+ *
+ * read the current direction flags
+ *
+ * @desc:	GPIO description containing device, offset and flags,
+ *		previously returned by gpio_request_by_name()
+ * @flags:	place to put the used flags
+ * @return 0 if OK, -ve on error, in which case desc->flags is not updated
+ */
+int dm_gpio_get_dir_flags(struct gpio_desc *desc, ulong *flags);
+
 /**
  * gpio_get_number() - Get the global GPIO number of a GPIO
  *
Signature · 1 line
2.17.1
#33 lore raw

PATCH v3 12/21 gpio: update dir_flags management

Quoted 17 lines · Patrick Delaunay

Update the flag management in GPIO uclass: the desc->flags is always combined with the requested flags and the GPIO descriptor is updated for further call.

Add a function dm_gpio_get_dir_flags to get dynamically the current dir_flags (configuration and value).

This patch prepare introduction of the dir flags support with new ops.

---

This patch was part of v2 08/14
= gpio: add ops for configuration with dir flags

Quoted 8 lines

Changes in v3:
- Split the previous patch [PATCH v2 08/14] to help review

Changes in v2: None

 drivers/gpio/gpio-uclass.c | 27 +++++++++++++++++++++++++--
 include/asm-generic/gpio.h | 22 ++++++++++++++++------
 2 files changed, 41 insertions(+), 8 deletions(-)
#34 lore raw

PATCH v3 12/21 gpio: update dir_flags management

In reply to Patrick Delaunay
Quoted 11 lines · Patrick Delaunay

Update the flag management in GPIO uclass: the desc->flags is always combined with the requested flags and the GPIO descriptor is updated for further call.

Add a function dm_gpio_get_dir_flags to get dynamically the current dir_flags (configuration and value).

This patch prepare introduction of the dir flags support with new ops.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/fe58755f/attachment.sig>
#35 lore raw

PATCH v3 13/21 gpio: add support of new GPIO direction flag

In reply to Patrick Delaunay

This commit manages the new dir flags that can be used in gpio specifiers to indicate the pull-up or pull-down resistor configuration for output gpio (GPIO_PULL_UP, GPIO_PULL_DOWN) or the Open Drain/Open Source configuration for input gpio (GPIO_OPEN_DRAIN, GPIO_OPEN_SOURCE).

These flags are already supported in Linux kernel in gpio lib.

This patch only parse and save the direction flags in GPIO descriptor (desc->flags), it prepares the introduction of new ops to manage them.
The GPIO uclass supports new GPIO flags from device-tree (GPIO_XXX define in include/dt-bindings/gpio/gpio.h) and translate them in the dir flags (GPIOD_XXX):

- GPIO_PULL_UP     => GPIOD_PULL_UP
- GPIO_PULL_DOWN   => GPIOD_PULL_DOWN
- GPIO_OPEN_DRAIN  => GPIOD_OPEN_DRAIN

- GPIO_OPEN_SOURCE => GPIOD_OPEN_SOURCE

This patch also adds protection in the check_dir_flags function for new invalid configuration of the dir flags.

---

This patch was part of v2 08/14
= gpio: add ops for configuration with dir flags

Changes in v3:
- Split the previous patch [PATCH v2 08/14] to help review

Changes in v2: None

 drivers/gpio/gpio-uclass.c | 30 ++++++++++++++++++++++++++++++
 include/asm-generic/gpio.h |  6 +++++-
 2 files changed, 35 insertions(+), 1 deletion(-)
drivers/gpio/gpio-uclass.c +30 -0
index 85f0b03f81..e02ef29fed 100644
@@ -144,6 +144,24 @@ int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,
 	if (args->args[1] & GPIO_ACTIVE_LOW)
 		desc->flags |= GPIOD_ACTIVE_LOW;
 
+	/*
+	 * need to test 2 bits for gpio output binding:
+	 * OPEN_DRAIN (0x6) = SINGLE_ENDED (0x2) | LINE_OPEN_DRAIN (0x4)
+	 * OPEN_SOURCE (0x2) = SINGLE_ENDED (0x2) | LINE_OPEN_SOURCE (0x0)
+	 */
+	if (args->args[1] & GPIO_SINGLE_ENDED) {
+		if (args->args[1] & GPIO_LINE_OPEN_DRAIN)
+			desc->flags |= GPIOD_OPEN_DRAIN;
+		else
+			desc->flags |= GPIOD_OPEN_SOURCE;
+	}
+
+	if (args->args[1] & GPIO_PULL_UP)
+		desc->flags |= GPIOD_PULL_UP;
+
+	if (args->args[1] & GPIO_PULL_DOWN)
+		desc->flags |= GPIOD_PULL_DOWN;
+
 	return 0;
 }
 
@@ -520,6 +538,18 @@ static int check_dir_flags(ulong flags)
 		return -EINVAL;
 	}
 
+	if ((flags & GPIOD_PULL_UP) && (flags & GPIOD_PULL_DOWN)) {
+		log_debug("%s: flags 0x%lx has GPIOD_PULL_UP and GPIOD_PULL_DOWN\n",
+			  __func__, flags);
+		return -EINVAL;
+	}
+
+	if ((flags & GPIOD_OPEN_DRAIN) && (flags & GPIOD_OPEN_SOURCE)) {
+		log_debug("%s: flags 0x%lx has GPIOD_OPEN_DRAIN and GPIOD_OPEN_SOURCE\n",
+			  __func__, flags);
+		return -EINVAL;
+	}
+
 	return 0;
 }
 
include/asm-generic/gpio.h +5 -1
index 3dd0002b0b..4f7b43f163 100644
@@ -119,8 +119,12 @@ struct gpio_desc {
 	unsigned long flags;
 #define GPIOD_IS_OUT		BIT(1)	/* GPIO is an output */
 #define GPIOD_IS_IN		BIT(2)	/* GPIO is an input */
-#define GPIOD_ACTIVE_LOW	BIT(3)	/* value has active low */
+#define GPIOD_ACTIVE_LOW	BIT(3)	/* GPIO is active when value is low */
 #define GPIOD_IS_OUT_ACTIVE	BIT(4)	/* set output active */
+#define GPIOD_OPEN_DRAIN	BIT(5)	/* GPIO is open drain type */
+#define GPIOD_OPEN_SOURCE	BIT(6)	/* GPIO is open source type */
+#define GPIOD_PULL_UP		BIT(7)	/* GPIO has pull-up enabled */
+#define GPIOD_PULL_DOWN		BIT(8)	/* GPIO has pull-down enabled */
 
 	uint offset;		/* GPIO offset within the device */
 	/*
Signature · 1 line
2.17.1
#36 lore raw

PATCH v3 13/21 gpio: add support of new GPIO direction flag

Quoted 30 lines · Patrick Delaunay

This commit manages the new dir flags that can be used in gpio specifiers to indicate the pull-up or pull-down resistor configuration for output gpio (GPIO_PULL_UP, GPIO_PULL_DOWN) or the Open Drain/Open Source configuration for input gpio (GPIO_OPEN_DRAIN, GPIO_OPEN_SOURCE).

These flags are already supported in Linux kernel in gpio lib.

This patch only parse and save the direction flags in GPIO descriptor (desc->flags), it prepares the introduction of new ops to manage them.
The GPIO uclass supports new GPIO flags from device-tree (GPIO_XXX define in include/dt-bindings/gpio/gpio.h) and translate them in the dir flags (GPIOD_XXX):

- GPIO_PULL_UP     => GPIOD_PULL_UP
- GPIO_PULL_DOWN   => GPIOD_PULL_DOWN
- GPIO_OPEN_DRAIN  => GPIOD_OPEN_DRAIN

- GPIO_OPEN_SOURCE => GPIOD_OPEN_SOURCE

This patch also adds protection in the check_dir_flags function for new invalid configuration of the dir flags.

---

This patch was part of v2 08/14
= gpio: add ops for configuration with dir flags

Quoted 8 lines

Changes in v3:
- Split the previous patch [PATCH v2 08/14] to help review

Changes in v2: None

 drivers/gpio/gpio-uclass.c | 30 ++++++++++++++++++++++++++++++
 include/asm-generic/gpio.h |  6 +++++-
 2 files changed, 35 insertions(+), 1 deletion(-)
#37 lore raw

PATCH v3 13/21 gpio: add support of new GPIO direction flag

In reply to Patrick Delaunay
Quoted 17 lines · Patrick Delaunay

This commit manages the new dir flags that can be used in gpio specifiers to indicate the pull-up or pull-down resistor configuration for output gpio (GPIO_PULL_UP, GPIO_PULL_DOWN) or the Open Drain/Open Source configuration for input gpio (GPIO_OPEN_DRAIN, GPIO_OPEN_SOURCE).

These flags are already supported in Linux kernel in gpio lib.

This patch only parse and save the direction flags in GPIO descriptor (desc->flags), it prepares the introduction of new ops to manage them.
The GPIO uclass supports new GPIO flags from device-tree (GPIO_XXX define in include/dt-bindings/gpio/gpio.h) and translate them in the dir flags (GPIOD_XXX):

- GPIO_PULL_UP     => GPIOD_PULL_UP
- GPIO_PULL_DOWN   => GPIOD_PULL_DOWN
- GPIO_OPEN_DRAIN  => GPIOD_OPEN_DRAIN
Quoted 7 lines

- GPIO_OPEN_SOURCE => GPIOD_OPEN_SOURCE

This patch also adds protection in the check_dir_flags function for new invalid configuration of the dir flags.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/5c18f39d/attachment.sig>
#38 lore raw

PATCH v3 14/21 gpio: add ops to get dir flags

In reply to Patrick Delaunay

Add the ops for GPIO driver get_dir_flags(), allows to get dynamically the current gpio configuration; it is used by the API function dm_gpio_get_dir_flags().

When these optional ops are absent, the gpio uclass continues to use the mandatory ops (direction_output, direction_input, get_value) and value of desc->flags to manage only the main dir flags:
- GPIOD_IS_IN
- GPIOD_IS_OUT
- GPIOD_IS_OUT_ACTIVE
- GPIOD_ACTIVE_LOW

---

This patch was part of v2 08/14
= gpio: add ops for configuration with dir flags

Changes in v3:
- Split the previous patch [PATCH v2 08/14] to help review

Changes in v2:
- change the proposed ops for pin config to set_dir_flags/get_dir_flags
- reused the existing API dm_gpio_set_dir_flags/dm_gpio_set_dir
- add a new API dm_gpio_get_dir_flags

 drivers/gpio/gpio-uclass.c | 31 +++++++++++++++++++++++++------
 include/asm-generic/gpio.h | 15 +++++++++++++++
 2 files changed, 40 insertions(+), 6 deletions(-)
drivers/gpio/gpio-uclass.c +25 -6
index e02ef29fed..89af37a4ea 100644
@@ -613,19 +613,36 @@ int dm_gpio_set_dir(struct gpio_desc *desc)
 
 int dm_gpio_get_dir_flags(struct gpio_desc *desc, ulong *flags)
 {
-	int ret;
+	struct udevice *dev = desc->dev;
+	int ret, value;
+	struct dm_gpio_ops *ops = gpio_get_ops(dev);
 	ulong dir_flags;
 
 	ret = check_reserved(desc, "get_dir_flags");
 	if (ret)
 		return ret;
 
-	dir_flags = desc->flags;
-	/* only GPIOD_IS_OUT_ACTIVE is provided by uclass */
-	dir_flags &= ~GPIOD_IS_OUT_ACTIVE;
-	if ((desc->flags & GPIOD_IS_OUT) && _gpio_get_value(desc))
-		dir_flags |= GPIOD_IS_OUT_ACTIVE;
+	/* GPIOD_ are directly provided by driver except GPIOD_ACTIVE_LOW */
+	if (ops->get_dir_flags) {
+		ret = ops->get_dir_flags(dev, desc->offset, &dir_flags);
+		if (ret)
+			return ret;
 
+		/* GPIOD_ACTIVE_LOW is saved in desc->flags */
+		value = dir_flags & GPIOD_IS_OUT_ACTIVE ? 1 : 0;
+		if (desc->flags & GPIOD_ACTIVE_LOW)
+			value = !value;
+		dir_flags &= ~(GPIOD_ACTIVE_LOW | GPIOD_IS_OUT_ACTIVE);
+		dir_flags |= (desc->flags & GPIOD_ACTIVE_LOW);
+		if (value)
+			dir_flags |= GPIOD_IS_OUT_ACTIVE;
+	} else {
+		dir_flags = desc->flags;
+		/* only GPIOD_IS_OUT_ACTIVE is provided by uclass */
+		dir_flags &= ~GPIOD_IS_OUT_ACTIVE;
+		if ((desc->flags & GPIOD_IS_OUT) && _gpio_get_value(desc))
+			dir_flags |= GPIOD_IS_OUT_ACTIVE;
+	}
 	*flags = dir_flags;
 
 	return 0;
@@ -1128,6 +1145,8 @@ static int gpio_post_bind(struct udevice *dev)
 			ops->get_function += gd->reloc_off;
 		if (ops->xlate)
 			ops->xlate += gd->reloc_off;
+		if (ops->get_dir_flags)
+			ops->get_dir_flags += gd->reloc_off;
 
 		reloc_done++;
 	}
include/asm-generic/gpio.h +15 -0
index 4f7b43f163..ac30c3ee4e 100644
@@ -297,6 +297,21 @@ struct dm_gpio_ops {
 	 */
 	int (*xlate)(struct udevice *dev, struct gpio_desc *desc,
 		     struct ofnode_phandle_args *args);
+
+	/**
+	 * get_dir_flags() - Get GPIO dir flags
+	 *
+	 * This function return the GPIO direction flags used.
+	 *
+	 * This method is optional.
+	 *
+	 * @dev:	GPIO device
+	 * @offset:	GPIO offset within that device
+	 * @flags:	place to put the used direction flags by GPIO
+	 * @return 0 if OK, -ve on error
+	 */
+	int (*get_dir_flags)(struct udevice *dev, unsigned int offset,
+			     ulong *flags);
 };
 
 /**
Signature · 1 line
2.17.1
#39 lore raw

PATCH v3 14/21 gpio: add ops to get dir flags

Quoted 23 lines · Patrick Delaunay

Add the ops for GPIO driver get_dir_flags(), allows to get dynamically the current gpio configuration; it is used by the API function dm_gpio_get_dir_flags().

When these optional ops are absent, the gpio uclass continues to use the mandatory ops (direction_output, direction_input, get_value) and value of desc->flags to manage only the main dir flags:
- GPIOD_IS_IN
- GPIOD_IS_OUT
- GPIOD_IS_OUT_ACTIVE
- GPIOD_ACTIVE_LOW

---

This patch was part of v2 08/14
= gpio: add ops for configuration with dir flags

Changes in v3:
- Split the previous patch [PATCH v2 08/14] to help review

Quoted 8 lines

Changes in v2:
- change the proposed ops for pin config to set_dir_flags/get_dir_flags
- reused the existing API dm_gpio_set_dir_flags/dm_gpio_set_dir
- add a new API dm_gpio_get_dir_flags

 drivers/gpio/gpio-uclass.c | 31 +++++++++++++++++++++++++------
 include/asm-generic/gpio.h | 15 +++++++++++++++
 2 files changed, 40 insertions(+), 6 deletions(-)

But please see below

include/asm-generic/gpio.h struct dm_gpio_ops { · line 304

Quoted 13 lines
include/asm-generic/gpio.h +5 -0
index 4f7b43f163..ac30c3ee4e 100644
@@ -297,6 +297,21 @@ struct dm_gpio_ops {
         */
        int (*xlate)(struct udevice *dev, struct gpio_desc *desc,
                     struct ofnode_phandle_args *args);
+
+       /**
+        * get_dir_flags() - Get GPIO dir flags
+        *
+        * This function return the GPIO direction flags used.

returns

used by what? This is too vague.

include/asm-generic/gpio.h struct dm_gpio_ops { · line 306

Quoted 2 lines
include/asm-generic/gpio.h +2 -0
+        *
+        * This method is optional.

Please expand this (perhaps in a follow-up patch) to explain what happens when not implemented.

Quoted 14 lines
include/asm-generic/gpio.h +8 -1
+        *
+        * @dev:        GPIO device
+        * @offset:     GPIO offset within that device
+        * @flags:      place to put the used direction flags by GPIO
+        * @return 0 if OK, -ve on error
+        */
+       int (*get_dir_flags)(struct udevice *dev, unsigned int offset,
+                            ulong *flags);
 };
 
 /**
--

2.17.1

#40 lore raw

PATCH v3 14/21 gpio: add ops to get dir flags

In reply to Patrick Delaunay
Quoted 12 lines · Patrick Delaunay

Add the ops for GPIO driver get_dir_flags(), allows to get dynamically the current gpio configuration; it is used by the API function dm_gpio_get_dir_flags().

When these optional ops are absent, the gpio uclass continues to use the mandatory ops (direction_output, direction_input, get_value) and value of desc->flags to manage only the main dir flags:
- GPIOD_IS_IN
- GPIOD_IS_OUT
- GPIOD_IS_OUT_ACTIVE
- GPIOD_ACTIVE_LOW

Quoted 2 lines

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/6757c878/attachment.sig>
#41 lore raw

PATCH v3 15/21 gpio: add ops to set dir flags

In reply to Patrick Delaunay

Add the ops for GPIO driver set_dir_flags() to set the dir flags. The user can update the direction and configuration
of each GPIO with a only call to dm_gpio_set_dir_flags() or dm_gpio_set_dir() and respecting the configuration provided by device tree (saved in desc->flags).

When these optional ops are absent, the gpio uclass use the mandatory ops (direction_output, direction_input, get_value) and desc->flags to manage only the main dir flags:
- GPIOD_IS_IN
- GPIOD_IS_OUT
- GPIOD_IS_OUT_ACTIVE
- GPIOD_ACTIVE_LOW

---

This patch was part of v2 08/14
= gpio: add ops for configuration with dir flags

Changes in v3:
- Split the previous patch [PATCH v2 08/14] to help review

Changes in v2:
- change the proposed ops for pin config to set_dir_flags/get_dir_flags
- reused the existing API dm_gpio_set_dir_flags/dm_gpio_set_dir
- add a new API dm_gpio_get_dir_flags

 drivers/gpio/gpio-uclass.c | 17 ++++++++++++-----
 include/asm-generic/gpio.h | 16 ++++++++++++++++
 2 files changed, 28 insertions(+), 5 deletions(-)
drivers/gpio/gpio-uclass.c +12 -5
index 89af37a4ea..5da28e6ed9 100644
@@ -571,11 +571,16 @@ static int _dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
 		return ret;
 	}
 
-	if (flags & GPIOD_IS_OUT) {
-		ret = ops->direction_output(dev, desc->offset,
-					    GPIOD_FLAGS_OUTPUT(flags));
-	} else if (flags & GPIOD_IS_IN) {
-		ret = ops->direction_input(dev, desc->offset);
+	/* GPIOD_ are directly managed by driver in set_dir_flags*/
+	if (ops->set_dir_flags) {
+		ret = ops->set_dir_flags(dev, desc->offset, flags);
+	} else {
+		if (flags & GPIOD_IS_OUT) {
+			ret = ops->direction_output(dev, desc->offset,
+						    GPIOD_FLAGS_OUTPUT(flags));
+		} else if (flags & GPIOD_IS_IN) {
+			ret = ops->direction_input(dev, desc->offset);
+		}
 	}
 
 	return ret;
@@ -1145,6 +1150,8 @@ static int gpio_post_bind(struct udevice *dev)
 			ops->get_function += gd->reloc_off;
 		if (ops->xlate)
 			ops->xlate += gd->reloc_off;
+		if (ops->set_dir_flags)
+			ops->set_dir_flags += gd->reloc_off;
 		if (ops->get_dir_flags)
 			ops->get_dir_flags += gd->reloc_off;
 
include/asm-generic/gpio.h +16 -0
index ac30c3ee4e..ec4877037a 100644
@@ -298,6 +298,22 @@ struct dm_gpio_ops {
 	int (*xlate)(struct udevice *dev, struct gpio_desc *desc,
 		     struct ofnode_phandle_args *args);
 
+	/**
+	 * set_dir_flags() - Set GPIO dir flags
+	 *
+	 * This function should set up the GPIO configuration according to the
+	 * information provide by the direction flags bitfield.
+	 *
+	 * This method is optional.
+	 *
+	 * @dev:	GPIO device
+	 * @offset:	GPIO offset within that device
+	 * @flags:	GPIO configuration to use
+	 * @return 0 if OK, -ve on error
+	 */
+	int (*set_dir_flags)(struct udevice *dev, unsigned int offset,
+			     ulong flags);
+
 	/**
 	 * get_dir_flags() - Get GPIO dir flags
 	 *
Signature · 1 line
2.17.1
#42 lore raw

PATCH v3 15/21 gpio: add ops to set dir flags

Quoted 25 lines · Patrick Delaunay

Add the ops for GPIO driver set_dir_flags() to set the dir flags. The user can update the direction and configuration
of each GPIO with a only call to dm_gpio_set_dir_flags() or dm_gpio_set_dir() and respecting the configuration provided by device tree (saved in desc->flags).

When these optional ops are absent, the gpio uclass use the mandatory ops (direction_output, direction_input, get_value) and desc->flags to manage only the main dir flags:
- GPIOD_IS_IN
- GPIOD_IS_OUT
- GPIOD_IS_OUT_ACTIVE
- GPIOD_ACTIVE_LOW

---

This patch was part of v2 08/14
= gpio: add ops for configuration with dir flags

Changes in v3:
- Split the previous patch [PATCH v2 08/14] to help review

Quoted 8 lines

Changes in v2:
- change the proposed ops for pin config to set_dir_flags/get_dir_flags
- reused the existing API dm_gpio_set_dir_flags/dm_gpio_set_dir
- add a new API dm_gpio_get_dir_flags

 drivers/gpio/gpio-uclass.c | 17 ++++++++++++-----
 include/asm-generic/gpio.h | 16 ++++++++++++++++
 2 files changed, 28 insertions(+), 5 deletions(-)
#43 lore raw

PATCH v3 15/21 gpio: add ops to set dir flags

In reply to Patrick Delaunay
Quoted 14 lines · Patrick Delaunay

Add the ops for GPIO driver set_dir_flags() to set the dir flags. The user can update the direction and configuration
of each GPIO with a only call to dm_gpio_set_dir_flags() or dm_gpio_set_dir() and respecting the configuration provided by device tree (saved in desc->flags).

When these optional ops are absent, the gpio uclass use the mandatory ops (direction_output, direction_input, get_value) and desc->flags to manage only the main dir flags:
- GPIOD_IS_IN
- GPIOD_IS_OUT
- GPIOD_IS_OUT_ACTIVE
- GPIOD_ACTIVE_LOW

Quoted 2 lines

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/324746a8/attachment.sig>
#44 lore raw

PATCH v3 16/21 dt-bindings: gpio: alignment with kernel v5.3

In reply to Patrick Delaunay

Update the binding file for gpio, it is just an alignment with kernel v5.3.
The U-Boot code example for gpio-hog (not directly linked to binding) is moved in a new file doc/README.gpio. [commit 21676b706e99 ("gpio: fixes for gpio-hog support") & 'commit 4762a9988ede ("gpio: add gpio-hog support")']

---

Changes in v3: None
Changes in v2: None

 doc/README.gpio                        |  42 ++++
 doc/device-tree-bindings/gpio/gpio.txt | 280 ++++++++++++++-----------
 2 files changed, 196 insertions(+), 126 deletions(-)
 create mode 100644 doc/README.gpio
doc/README.gpio new file +42 -0
new file mode 100644
index 0000000000..548ff37b8c
@@ -0,0 +1,42 @@
+
+GPIO hog (CONFIG_GPIO_HOG)
+--------
+
+All the GPIO hog are initialized in gpio_hog_probe_all() function called in
+board_r.c just before board_late_init() but you can also acces directly to
+the gpio with gpio_hog_lookup_name().
+
+
+Example, for the device tree:
+
+        tca6416 at 20 {
+                compatible = "ti,tca6416";
+                reg = <0x20>;
+                #gpio-cells = <2>;
+                gpio-controller;
+
+                env_reset {
+                        gpio-hog;
+                        input;
+                        gpios = <6 GPIO_ACTIVE_LOW>;
+                };
+                boot_rescue {
+                        gpio-hog;
+                        input;
+                        line-name = "foo-bar-gpio";
+                        gpios = <7 GPIO_ACTIVE_LOW>;
+                };
+        };
+
+You can than access the gpio in your board code with:
+
+	struct gpio_desc *desc;
+	int ret;
+
+	ret = gpio_hog_lookup_name("boot_rescue", &desc);
+	if (ret)
+		return;
+	if (dm_gpio_get_value(desc) == 1)
+		printf("\nBooting into Rescue System\n");
+	else if (dm_gpio_get_value(desc) == 0)
+		printf("\nBoot normal\n");
doc/device-tree-bindings/gpio/gpio.txt +154 -126

333 lines not on this page · raw message

Signature · 1 line
2.17.1
#45 lore raw

PATCH v3 16/21 dt-bindings: gpio: alignment with kernel v5.3

Quoted 11 lines · Patrick Delaunay

Update the binding file for gpio, it is just an alignment with kernel v5.3.
The U-Boot code example for gpio-hog (not directly linked to binding) is moved in a new file doc/README.gpio. [commit 21676b706e99 ("gpio: fixes for gpio-hog support") & 'commit 4762a9988ede ("gpio: add gpio-hog support")']

---

Quoted 7 lines

Changes in v3: None
Changes in v2: None

 doc/README.gpio                        |  42 ++++
 doc/device-tree-bindings/gpio/gpio.txt | 280 ++++++++++++++-----------
 2 files changed, 196 insertions(+), 126 deletions(-)
 create mode 100644 doc/README.gpio
#46 lore raw

PATCH v3 16/21 dt-bindings: gpio: alignment with kernel v5.3

In reply to Patrick Delaunay
Quoted 9 lines · Patrick Delaunay

Update the binding file for gpio, it is just an alignment with kernel v5.3.
The U-Boot code example for gpio-hog (not directly linked to binding) is moved in a new file doc/README.gpio. [commit 21676b706e99 ("gpio: fixes for gpio-hog support") & 'commit 4762a9988ede ("gpio: add gpio-hog support")']

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/700ffee0/attachment.sig>
#47 lore raw

PATCH v3 17/21 pinctrl: sandbox: Add mux information in get_pin_muxing

In reply to Patrick Delaunay

Add param information in pin information output. This update prepare unitary test for pin configuration in pinctrl node.

---

Changes in v3: None
Changes in v2: None

 drivers/pinctrl/pinctrl-sandbox.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
drivers/pinctrl/pinctrl-sandbox.c +30 -0
index 0786afe747..d1a21f0f19 100644
@@ -54,6 +54,10 @@ static const struct pinconf_param sandbox_conf_params[] = {
 	{ "input-disable", PIN_CONFIG_INPUT_ENABLE, 0 },
 };
 
+/* bitfield used to save param and value of each pin/selector */
+static unsigned int sandbox_pins_param[ARRAY_SIZE(sandbox_pins)];
+static unsigned int sandbox_pins_value[ARRAY_SIZE(sandbox_pins)];
+
 static int sandbox_get_pins_count(struct udevice *dev)
 {
 	return ARRAY_SIZE(sandbox_pins);
@@ -68,8 +72,25 @@ static int sandbox_get_pin_muxing(struct udevice *dev,
 				  unsigned int selector,
 				  char *buf, int size)
 {
+	const struct pinconf_param *p;
+	int i;
+
 	snprintf(buf, size, "%s", sandbox_pins_muxing[selector]);
 
+	if (sandbox_pins_param[selector]) {
+		for (i = 0, p = sandbox_conf_params;
+		     i < ARRAY_SIZE(sandbox_conf_params);
+		     i++, p++) {
+			if ((sandbox_pins_param[selector] & BIT(p->param)) &&
+			    (!!(sandbox_pins_value[selector] & BIT(p->param)) ==
+			     p->default_value)) {
+				strncat(buf, " ", size);
+				strncat(buf, p->property, size);
+			}
+		}
+	}
+	strncat(buf, ".", size);
+
 	return 0;
 }
 
@@ -102,6 +123,9 @@ static int sandbox_pinmux_set(struct udevice *dev, unsigned pin_selector,
 	      pin_selector, sandbox_get_pin_name(dev, pin_selector),
 	      func_selector, sandbox_get_function_name(dev, func_selector));
 
+	sandbox_pins_param[pin_selector] = 0;
+	sandbox_pins_value[pin_selector] = 0;
+
 	return 0;
 }
 
@@ -123,6 +147,12 @@ static int sandbox_pinconf_set(struct udevice *dev, unsigned pin_selector,
 	      pin_selector, sandbox_get_pin_name(dev, pin_selector),
 	      param, argument);
 
+	sandbox_pins_param[pin_selector] |= BIT(param);
+	if (argument)
+		sandbox_pins_value[pin_selector] |= BIT(param);
+	else
+		sandbox_pins_value[pin_selector] &= ~BIT(param);
+
 	return 0;
 }
 
Signature · 1 line
2.17.1
#48 lore raw

PATCH v3 17/21 pinctrl: sandbox: Add mux information in get_pin_muxing

Quoted 6 lines · Patrick Delaunay

Add param information in pin information output. This update prepare unitary test for pin configuration in pinctrl node.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/879ac23c/attachment.sig>
#49 lore raw

PATCH v3 18/21 test: dm: update test for pins configuration in pinctrl node

In reply to Patrick Delaunay

Add test for "pins" configuration in gpio uclass with set_state() ops and test for generic parsing of pinconf_param array).

set_state() is called by:
- pinctrl_generic_set_state
|- pinctrl_generic_set_state_subnode

---

Changes in v3: None
Changes in v2: None

 arch/sandbox/dts/test.dts         | 25 +++++++++++++++++++++++++
 drivers/pinctrl/pinctrl-sandbox.c | 14 +++++++++++++-
 test/py/tests/test_pinmux.py      | 28 ++++++++++++++++++----------
 3 files changed, 56 insertions(+), 11 deletions(-)
arch/sandbox/dts/test.dts +25 -0
index fdb08f2111..b57f152fa3 100644
@@ -851,6 +851,31 @@
 
 	pinctrl {
 		compatible = "sandbox,pinctrl";
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&gpios>;
+
+		gpios: gpios {
+			gpio0 {
+				pins = "GPIO0";
+				bias-pull-up;
+				input-disable;
+			};
+			gpio1 {
+				pins = "GPIO1";
+				output-high;
+				drive-open-drain;
+			};
+			gpio2 {
+				pins = "GPIO2";
+				bias-pull-down;
+				input-enable;
+			};
+			gpio3 {
+				pins = "GPIO3";
+				bias-disable;
+			};
+		};
 	};
 
 	hwspinlock at 0 {
drivers/pinctrl/pinctrl-sandbox.c +13 -1
index d1a21f0f19..3ee75fbbee 100644
@@ -14,7 +14,11 @@ static const char * const sandbox_pins[] = {
 	"SDA",
 	"TX",
 	"RX",
-	"W1"
+	"W1",
+	"GPIO0",
+	"GPIO1",
+	"GPIO2",
+	"GPIO3",
 };
 
 static const char * const sandbox_pins_muxing[] = {
@@ -23,6 +27,10 @@ static const char * const sandbox_pins_muxing[] = {
 	"Uart TX",
 	"Uart RX",
 	"1-wire gpio",
+	"gpio",
+	"gpio",
+	"gpio",
+	"gpio",
 };
 
 static const char * const sandbox_groups[] = {
@@ -38,6 +46,10 @@ static const char * const sandbox_functions[] = {
 	"serial",
 	"spi",
 	"w1",
+	"gpio",
+	"gpio",
+	"gpio",
+	"gpio",
 };
 
 static const struct pinconf_param sandbox_conf_params[] = {
test/py/tests/test_pinmux.py +18 -10
index 25394f1faf..5ca0b4b630 100644
@@ -22,11 +22,15 @@ def test_pinmux_usage_2(u_boot_console):
 def test_pinmux_status_all(u_boot_console):
     """Test that 'pinmux status -a' displays pin's muxing."""
     output = u_boot_console.run_command('pinmux status -a')
-    assert ('SCL       : I2C SCL' in output)
-    assert ('SDA       : I2C SDA' in output)
-    assert ('TX        : Uart TX' in output)
-    assert ('RX        : Uart RX' in output)
-    assert ('W1        : 1-wire gpio' in output)
+    assert ('SCL       : I2C SCL.' in output)
+    assert ('SDA       : I2C SDA.' in output)
+    assert ('TX        : Uart TX.' in output)
+    assert ('RX        : Uart RX.' in output)
+    assert ('W1        : 1-wire gpio.' in output)
+    assert ('GPIO0     : gpio bias-pull-up input-disable.' in output)
+    assert ('GPIO1     : gpio drive-open-drain.' in output)
+    assert ('GPIO2     : gpio bias-pull-down input-enable.' in output)
+    assert ('GPIO3     : gpio bias-disable.' in output)
 
 @pytest.mark.buildconfigspec('cmd_pinmux')
 @pytest.mark.boardspec('sandbox')
@@ -59,8 +63,12 @@ def test_pinmux_status(u_boot_console):
     """Test that 'pinmux status' displays selected pincontroller's pin
     muxing descriptions."""
     output = u_boot_console.run_command('pinmux status')
-    assert ('SCL       : I2C SCL' in output)
-    assert ('SDA       : I2C SDA' in output)
-    assert ('TX        : Uart TX' in output)
-    assert ('RX        : Uart RX' in output)
-    assert ('W1        : 1-wire gpio' in output)
+    assert ('SCL       : I2C SCL.' in output)
+    assert ('SDA       : I2C SDA.' in output)
+    assert ('TX        : Uart TX.' in output)
+    assert ('RX        : Uart RX.' in output)
+    assert ('W1        : 1-wire gpio.' in output)
+    assert ('GPIO0     : gpio bias-pull-up input-disable.' in output)
+    assert ('GPIO1     : gpio drive-open-drain.' in output)
+    assert ('GPIO2     : gpio bias-pull-down input-enable.' in output)
+    assert ('GPIO3     : gpio bias-disable.' in output)
Signature · 1 line
2.17.1
#50 lore raw

PATCH v3 18/21 test: dm: update test for pins configuration in pinctrl node

Quoted 9 lines · Patrick Delaunay

Add test for "pins" configuration in gpio uclass with set_state() ops and test for generic parsing of pinconf_param array).

set_state() is called by:
- pinctrl_generic_set_state
|- pinctrl_generic_set_state_subnode

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/06f4f1d4/attachment.sig>
#51 lore raw

PATCH v3 19/21 gpio: sandbox: cleanup binding support

In reply to Patrick Delaunay

Cleanup binding support, use the generic binding by default (test u-class gpio_xlate_offs_flags function) and add specific binding for added value.

---

Changes in v3: None
Changes in v2: None

 arch/sandbox/dts/test.dts               | 14 ++++++++++----
 drivers/gpio/sandbox.c                  | 13 ++++++++-----
 include/dt-bindings/gpio/sandbox-gpio.h | 24 ++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 9 deletions(-)
 create mode 100644 include/dt-bindings/gpio/sandbox-gpio.h
arch/sandbox/dts/test.dts +10 -4
index b57f152fa3..df58a0b488 100644
@@ -1,5 +1,8 @@
 /dts-v1/;
 
+#include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/gpio/sandbox-gpio.h>
+
 / {
 	model = "sandbox";
 	compatible = "sandbox";
@@ -86,11 +89,14 @@
 		ping-expect = <0>;
 		ping-add = <0>;
 		u-boot,dm-pre-reloc;
-		test-gpios = <&gpio_a 1>, <&gpio_a 4>, <&gpio_b 5 0 3 2 1>,
+		test-gpios = <&gpio_a 1>, <&gpio_a 4>,
+			<&gpio_b 5 GPIO_ACTIVE_HIGH 3 2 1>,
 			<0>, <&gpio_a 12>;
-		test2-gpios = <&gpio_a 1>, <&gpio_a 4>, <&gpio_b 6 1 3 2 1>,
-			<&gpio_b 7 2 3 2 1>, <&gpio_b 8 4 3 2 1>,
-			<&gpio_b 9 0xc 3 2 1>;
+		test2-gpios = <&gpio_a 1>, <&gpio_a 4>,
+			<&gpio_b 6 GPIO_ACTIVE_LOW 3 2 1>,
+			<&gpio_b 7 GPIO_IN 3 2 1>,
+			<&gpio_b 8 GPIO_OUT 3 2 1>,
+			<&gpio_b 9 (GPIO_OUT|GPIO_OUT_ACTIVE) 3 2 1>;
 		int-value = <1234>;
 		uint-value = <(-1234)>;
 	};
drivers/gpio/sandbox.c +8 -5
index 91e8e0677e..c2a8adc647 100644
@@ -10,6 +10,7 @@
 #include <asm/gpio.h>
 #include <dm/of.h>
 #include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/gpio/sandbox-gpio.h>
 
 /* Flags for each GPIO */
 #define GPIOF_OUTPUT	(1 << 0)	/* Currently set as an output */
@@ -136,13 +137,15 @@ static int sb_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
 	desc->offset = args->args[0];
 	if (args->args_count < 2)
 		return 0;
-	if (args->args[1] & GPIO_ACTIVE_LOW)
-		desc->flags |= GPIOD_ACTIVE_LOW;
-	if (args->args[1] & 2)
+	/* treat generic binding with gpio uclass */
+	gpio_xlate_offs_flags(dev, desc, args);
+
+	/* sandbox test specific, not defined in gpio.h */
+	if (args->args[1] & GPIO_IN)
 		desc->flags |= GPIOD_IS_IN;
-	if (args->args[1] & 4)
+	if (args->args[1] & GPIO_OUT)
 		desc->flags |= GPIOD_IS_OUT;
-	if (args->args[1] & 8)
+	if (args->args[1] & GPIO_OUT_ACTIVE)
 		desc->flags |= GPIOD_IS_OUT_ACTIVE;
 
 	return 0;
include/dt-bindings/gpio/sandbox-gpio.h new file +24 -0
new file mode 100644
index 0000000000..e4bfdb3ce1
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * This header provides constants for binding sandbox,gpio
+ *
+ */
+#ifndef _DT_BINDINGS_GPIO_SANDBOX_GPIO_H
+#define _DT_BINDINGS_GPIO_SANDBOX_GPIO_H
+
+/*
+ * Add a specific binding for sandbox gpio.
+ * The value need to be after the generic defines of
+ * dt-bindings/gpio/gpio.h
+ */
+
+/* Bit 16 express GPIO input mode */
+#define GPIO_IN			0x10000
+
+/* Bit 17 express GPIO output mode */
+#define GPIO_OUT		0x20000
+
+/* Bit 18 express GPIO output is active */
+#define GPIO_OUT_ACTIVE		0x40000
+
+#endif
Signature · 1 line
2.17.1
#52 lore raw

PATCH v3 19/21 gpio: sandbox: cleanup binding support

Quoted 6 lines · Patrick Delaunay

Cleanup binding support, use the generic binding by default (test u-class gpio_xlate_offs_flags function) and add specific binding for added value.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/133f3ab9/attachment.sig>
#53 lore raw

PATCH v3 20/21 test: dm: update test for pins configuration in gpio

In reply to Patrick Delaunay

Add tests for new API set_dir_flags and set_dir_flags and associated code in gpio uclass.

Test support for new flags GPIO_OPEN_DRAIN, GPIO_OPEN_SOURCE GPIO_PULL_UP and GPIO_PULL_DOWN.

---

Changes in v3: None
Changes in v2:
- simplify sandbox GPIO driver: save dir_flags (GPIOD_...) and remove internal flags (GPIOF_...); the previous path "gpio: sandbox: cleanup flag support" is no more needed
- add unitary test in dm_test_gpio for set_dir_flags
- add some function check in dm_test_gpio_phandles
- dm_test_gpio_pin_config change to dm_test_gpio_get_dir_flags

 arch/sandbox/dts/test.dts       | 16 ++++++
 arch/sandbox/include/asm/gpio.h | 20 ++++++++
 drivers/gpio/sandbox.c          | 86 +++++++++++++++++++++++++--------
 test/dm/gpio.c                  | 66 ++++++++++++++++++++++---
 test/dm/test-fdt.c              |  2 +-
 5 files changed, 163 insertions(+), 27 deletions(-)
arch/sandbox/dts/test.dts +16 -0
index df58a0b488..8ab22c0c81 100644
@@ -16,6 +16,7 @@
 		eth5 = &eth_5;
 		gpio1 = &gpio_a;
 		gpio2 = &gpio_b;
+		gpio3 = &gpio_c;
 		i2c0 = "/i2c at 0";
 		mmc0 = "/mmc0";
 		mmc1 = "/mmc1";
@@ -97,6 +98,13 @@
 			<&gpio_b 7 GPIO_IN 3 2 1>,
 			<&gpio_b 8 GPIO_OUT 3 2 1>,
 			<&gpio_b 9 (GPIO_OUT|GPIO_OUT_ACTIVE) 3 2 1>;
+		test3-gpios =
+			<&gpio_c 0 (GPIO_OUT|GPIO_OPEN_DRAIN)>,
+			<&gpio_c 1 (GPIO_OUT|GPIO_OPEN_SOURCE)>,
+			<&gpio_c 2 GPIO_OUT>,
+			<&gpio_c 3 (GPIO_IN|GPIO_PULL_UP)>,
+			<&gpio_c 4 (GPIO_IN|GPIO_PULL_DOWN)>,
+			<&gpio_c 5 GPIO_IN>;
 		int-value = <1234>;
 		uint-value = <(-1234)>;
 	};
@@ -296,6 +304,14 @@
 		sandbox,gpio-count = <10>;
 	};
 
+	gpio_c: extra2-gpios {
+		compatible = "sandbox,gpio";
+		gpio-controller;
+		#gpio-cells = <2>;
+		gpio-bank-name = "c";
+		sandbox,gpio-count = <10>;
+	};
+
 	i2c at 0 {
 		#address-cells = <1>;
 		#size-cells = <0>;
arch/sandbox/include/asm/gpio.h +20 -0
index cfb803bb3b..df4ba4fb5f 100644
@@ -62,4 +62,24 @@ int sandbox_gpio_get_direction(struct udevice *dev, unsigned int offset);
 int sandbox_gpio_set_direction(struct udevice *dev, unsigned int offset,
 			       int output);
 
+/**
+ * Return the simulated flags of a GPIO (used only in sandbox test code)
+ *
+ * @param dev		device to use
+ * @param offset	GPIO offset within bank
+ * @return dir_flags: bitfield accesses by GPIOD_ defines
+ */
+ulong sandbox_gpio_get_dir_flags(struct udevice *dev, unsigned int offset);
+
+/**
+ * Set the simulated flags of a GPIO (used only in sandbox test code)
+ *
+ * @param dev		device to use
+ * @param offset	GPIO offset within bank
+ * @param flags		dir_flags: bitfield accesses by GPIOD_ defines
+ * @return -1 on error, 0 if ok
+ */
+int sandbox_gpio_set_dir_flags(struct udevice *dev, unsigned int offset,
+			       ulong flags);
+
 #endif
drivers/gpio/sandbox.c +66 -20

162 lines not on this page · raw message

test/dm/gpio.c +60 -6

103 lines not on this page · raw message

test/dm/test-fdt.c +1 -1
index 1fb8b5c248..3451146d04 100644
@@ -227,7 +227,7 @@ static int dm_test_alias_highest_id(struct unit_test_state *uts)
 	ut_asserteq(5, ret);
 
 	ret = dev_read_alias_highest_id("gpio");
-	ut_asserteq(2, ret);
+	ut_asserteq(3, ret);
 
 	ret = dev_read_alias_highest_id("pci");
 	ut_asserteq(2, ret);
Signature · 1 line
2.17.1
#54 lore raw

PATCH v3 20/21 test: dm: update test for pins configuration in gpio

Quoted 8 lines · Patrick Delaunay

Add tests for new API set_dir_flags and set_dir_flags and associated code in gpio uclass.

Test support for new flags GPIO_OPEN_DRAIN, GPIO_OPEN_SOURCE GPIO_PULL_UP and GPIO_PULL_DOWN.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/56abf85d/attachment.sig>
#55 lore raw

PATCH v3 21/21 test: pinmux: add pincontrol-gpio for pin configuration

In reply to Patrick Delaunay

Add a simple pincontrol associated to the sandbox gpio driver, that allows to check pin configuration with the command pinmux.

The pinmux test is also updated to test behavior with 2 pincontrols.

Example to check LED pin configuration:

=> pinmux list

| Device                        | Driver                        | Parent
| pinctrl-gpio                  | sandbox_pinctrl_gpio          | root_driver
| pinctrl                       | sandbox_pinctrl               | root_driver

=> pinmux dev pinctrl-gpio

=> pinmux status

a0 : gpio input .
a1 : gpio input .
a2 : gpio input .
a3 : gpio input .
a4 : gpio input .
a5 : gpio output .
a6 : gpio output .
...

---

Changes in v3: None
Changes in v2:
- Adapt sandbox_pinctrl_gpio driver with the saved dir_flags in sandbox gpio driver
- rebase on v2020.01-rc3

 arch/sandbox/dts/test.dts    |  48 +++++----
 drivers/gpio/sandbox.c       | 195 +++++++++++++++++++++++++++++++++++
 test/py/tests/test_pinmux.py |  10 ++
 3 files changed, 231 insertions(+), 22 deletions(-)
arch/sandbox/dts/test.dts +26 -22
index 8ab22c0c81..b69f0da871 100644
@@ -288,28 +288,32 @@
 		};
 	};
 
-	gpio_a: base-gpios {
-		compatible = "sandbox,gpio";
-		gpio-controller;
-		#gpio-cells = <1>;
-		gpio-bank-name = "a";
-		sandbox,gpio-count = <20>;
-	};
-
-	gpio_b: extra-gpios {
-		compatible = "sandbox,gpio";
-		gpio-controller;
-		#gpio-cells = <5>;
-		gpio-bank-name = "b";
-		sandbox,gpio-count = <10>;
-	};
-
-	gpio_c: extra2-gpios {
-		compatible = "sandbox,gpio";
-		gpio-controller;
-		#gpio-cells = <2>;
-		gpio-bank-name = "c";
-		sandbox,gpio-count = <10>;
+	pinctrl-gpio {
+		compatible = "sandbox,pinctrl-gpio";
+
+		gpio_a: base-gpios {
+			compatible = "sandbox,gpio";
+			gpio-controller;
+			#gpio-cells = <1>;
+			gpio-bank-name = "a";
+			sandbox,gpio-count = <20>;
+		};
+
+		gpio_b: extra-gpios {
+			compatible = "sandbox,gpio";
+			gpio-controller;
+			#gpio-cells = <5>;
+			gpio-bank-name = "b";
+			sandbox,gpio-count = <10>;
+		};
+
+		gpio_c: pinmux-gpios {
+			compatible = "sandbox,gpio";
+			gpio-controller;
+			#gpio-cells = <2>;
+			gpio-bank-name = "c";
+			sandbox,gpio-count = <10>;
+		};
 	};
 
 	i2c at 0 {
drivers/gpio/sandbox.c +195 -0

198 lines not on this page · raw message

test/py/tests/test_pinmux.py +10 -0
index 5ca0b4b630..4e6df992a4 100644
@@ -22,6 +22,12 @@ def test_pinmux_usage_2(u_boot_console):
 def test_pinmux_status_all(u_boot_console):
     """Test that 'pinmux status -a' displays pin's muxing."""
     output = u_boot_console.run_command('pinmux status -a')
+
+    assert ('pinctrl-gpio:' in output)
+    assert ('a5        : gpio output .' in output)
+    assert ('a6        : gpio output .' in output)
+
+    assert ('pinctrl:' in output)
     assert ('SCL       : I2C SCL.' in output)
     assert ('SDA       : I2C SDA.' in output)
     assert ('TX        : Uart TX.' in output)
@@ -63,6 +69,10 @@ def test_pinmux_status(u_boot_console):
     """Test that 'pinmux status' displays selected pincontroller's pin
     muxing descriptions."""
     output = u_boot_console.run_command('pinmux status')
+
+    assert (not 'pinctrl-gpio:' in output)
+    assert (not 'pinctrl:' in output)
+
     assert ('SCL       : I2C SCL.' in output)
     assert ('SDA       : I2C SDA.' in output)
     assert ('TX        : Uart TX.' in output)
Signature · 1 line
2.17.1
#56 lore raw

PATCH v3 21/21 test: pinmux: add pincontrol-gpio for pin configuration

Quoted 25 lines · Patrick Delaunay

Add a simple pincontrol associated to the sandbox gpio driver, that allows to check pin configuration with the command pinmux.

The pinmux test is also updated to test behavior with 2 pincontrols.

Example to check LED pin configuration:

=> pinmux list

| Device                        | Driver                        | Parent
| pinctrl-gpio                  | sandbox_pinctrl_gpio          | root_driver
| pinctrl                       | sandbox_pinctrl               | root_driver

=> pinmux dev pinctrl-gpio

=> pinmux status

a0 : gpio input .
a1 : gpio input .
a2 : gpio input .
a3 : gpio input .
a4 : gpio input .
a5 : gpio output .
a6 : gpio output .
...

Quoted 2 lines

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200417/bccd40b0/attachment.sig>
#57 lore raw

v3 cover dm: add support of new binding in gpio and pincontrol

In reply to Patrick Delaunay
Quoted 86 lines · Patrick Delaunay

Hi,

it is the V3 of "dm: add support of new binding in gpio and pincontrol"
http://patchwork.ozlabs.org/project/uboot/list/?series=145044

I rebase on v2020.01 and made some minor update after Simon Glass review. And I also split the previous patch was part of v2 08/14 to help review

	http://patchwork.ozlabs.org/patch/1200865/
	"gpio: add ops for configuration with dir flags"

I create this patchset to prepare alignment of stm32mp157c-ev1 device-tree with the linux kernel v5.4.

One node for touch screen support use the IRQ line configuration using the new kernel binding introduced by the linux kernel commit ede033e1e863c from v5.1 ('dt-bindings:
gpio: document the new pull-up/pull-down flags')
https://github.com/torvalds/linux/commit/ede033e1e863c

gt9147: goodix_ts at 5d {
	compatible = "goodix,gt9147";
	reg = <0x5d>;
	status = "okay";
	irq-gpios = <&stmfx_pinctrl 14
			(GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
	irq-flags = <IRQ_TYPE_EDGE_RISING>;
};

In Linux Kernel, the GPIO configuration (pull down/up) are now managed by GPIO lib but they are not yet supported by U-boot in uclass GPIO or pincontrol (when used by gpio-hog).

This serie adds the support of theses new defines (with ops get_config/set_config) added in kernel GPIO binding and adds the test in sandbox.

NB: In a second phase, the removed set_open_drain/get_open_drain
API could be replaced by the new ops get_config/set_config.

I also align the gpio binding file with the version from the latest kernel v5.3 (I don't think I remove any U-Boot specific part with this patch)
I move the added information on gpio hog code in a new file doc/README.gpio.

To have functional test, I convert pinctrl-generic to livetree otherwise the pins are not correctly configured in sandbox, when CONFIG_OF_LIVE is activated.

For the test on gpio I add information for pin configuration in output of the command "pinmux status" with a simple pincontrol driver associated to GPIO driver.

NB: after rebase on master branch, the sandbox test "ut dm power_domain"
is failing; it was not the case for v2019.10.

------------------------------------------------------ Captured stdout call ------------------------------------------------------- => ut dm power_domain
Test: dm_test_power_domain: power-domain.c
../test/dm/test-main.c:72, dm_test_destroy(): 0 == uclass_destroy(uc): Expected 0x0 (0), got 0xffffffea (-22) ../test/dm/test-main.c:107, dm_do_test(): 0 == dm_test_destroy(uts): Expected 0x0 (0), got 0x1 (1) ../test/dm/test-main.c:169, dm_test_main(): 0 == dm_do_test(uts, test, 1): Expected 0x0 (0), got 0x1 (1)
=>

I think it is linked to commit 52edfed65de9 ("dm: core:
device: switch off power domain after device removal")

After some investigation :

1/ pincontrol is remove in uclass_destroy(0)

2/ power domain is removed in uclass_destroy(0)

3/ device_chld_unbind()
dev_power_domain_off
-> probe power domain (again)
--> pinctrl_select_state() in device_probe()
---> pincontrol is probed (again)

4/ at the end of dev_power_domain_off() function the power domain
is unbind in dev_power_domain_off device_remove(pd.dev, DM_REMOVE_NORMAL);

So power domain driver is correctly removed but it is not the case for the pincontrol driver and that cause the issue.

Quoted 6 lines

The problem occurs after my serie only because I introduce a second pincontrol driver for sandbox, so the dynamic changes but my serie is not the root cause of the issue.

Workaround to allow test execution:
"dm: core: device: don't probe pinctrl for power domain"

Simon, any idea on how to fix the test failure above? I don't think excluding the test is the right path forward. Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200327/68d3e0c9/attachment.sig>
#58 lore raw

v3 cover dm: add support of new binding in gpio and pincontrol

Hi Tom,

Quoted 93 lines · Tom Rini
Quoted 90 lines · Patrick Delaunay

Hi,

it is the V3 of "dm: add support of new binding in gpio and pincontrol"
http://patchwork.ozlabs.org/project/uboot/list/?series=145044

I rebase on v2020.01 and made some minor update after Simon Glass review. And I also split the previous patch was part of v2 08/14 to help review
http://patchwork.ozlabs.org/patch/1200865/
"gpio: add ops for configuration with dir flags"

I create this patchset to prepare alignment of stm32mp157c-ev1 device-tree with the linux kernel v5.4.

One node for touch screen support use the IRQ line configuration using the new kernel binding introduced by the linux kernel commit ede033e1e863c from v5.1 ('dt-bindings:
gpio: document the new pull-up/pull-down flags')
https://github.com/torvalds/linux/commit/ede033e1e863c

gt9147: goodix_ts at 5d {
      compatible = "goodix,gt9147";
      reg = <0x5d>;
      status = "okay";
      irq-gpios = <&stmfx_pinctrl 14
                      (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
      irq-flags = <IRQ_TYPE_EDGE_RISING>;
};

In Linux Kernel, the GPIO configuration (pull down/up) are now managed by GPIO lib but they are not yet supported by U-boot in uclass GPIO or pincontrol (when used by gpio-hog).

This serie adds the support of theses new defines (with ops get_config/set_config) added in kernel GPIO binding and adds the test in sandbox.

NB: In a second phase, the removed set_open_drain/get_open_drain
API could be replaced by the new ops get_config/set_config.

I also align the gpio binding file with the version from the latest kernel v5.3 (I don't think I remove any U-Boot specific part with this patch)
I move the added information on gpio hog code in a new file doc/README.gpio.

To have functional test, I convert pinctrl-generic to livetree otherwise the pins are not correctly configured in sandbox, when CONFIG_OF_LIVE is activated.

For the test on gpio I add information for pin configuration in output of the command "pinmux status" with a simple pincontrol driver associated to GPIO driver.

NB: after rebase on master branch, the sandbox test "ut dm power_domain"
is failing; it was not the case for v2019.10.

------------------------------------------------------ Captured stdout call ------------------------------------------------------- => ut dm power_domain
Test: dm_test_power_domain: power-domain.c
../test/dm/test-main.c:72, dm_test_destroy(): 0 == uclass_destroy(uc): Expected 0x0 (0), got 0xffffffea (-22) ../test/dm/test-main.c:107, dm_do_test(): 0 == dm_test_destroy(uts): Expected 0x0 (0), got 0x1 (1) ../test/dm/test-main.c:169, dm_test_main(): 0 == dm_do_test(uts, test, 1): Expected 0x0 (0), got 0x1 (1)
=>

I think it is linked to commit 52edfed65de9 ("dm: core:
device: switch off power domain after device removal")

After some investigation :

1/ pincontrol is remove in uclass_destroy(0)

2/ power domain is removed in uclass_destroy(0)

3/ device_chld_unbind()
dev_power_domain_off
-> probe power domain (again)
--> pinctrl_select_state() in device_probe()
---> pincontrol is probed (again)

4/ at the end of dev_power_domain_off() function the power domain
is unbind in dev_power_domain_off device_remove(pd.dev, DM_REMOVE_NORMAL);

So power domain driver is correctly removed but it is not the case for the pincontrol driver and that cause the issue.

The problem occurs after my serie only because I introduce a second pincontrol driver for sandbox, so the dynamic changes but my serie is not the root cause of the issue.

Quoted 5 lines
Quoted 2 lines

Workaround to allow test execution:
"dm: core: device: don't probe pinctrl for power domain"

Simon, any idea on how to fix the test failure above? I don't think excluding the test is the right path forward. Thanks!

Not really. I will see if I can figure it out when I get back to things.

Regards,
Simon

#59 lore raw

v3 cover dm: add support of new binding in gpio and pincontrol

Hi Tom and Patrick,

Quoted 97 lines · Simon Glass

Hi Tom,

Quoted 93 lines · Tom Rini
Quoted 90 lines · Patrick Delaunay

Hi,

it is the V3 of "dm: add support of new binding in gpio and pincontrol"
http://patchwork.ozlabs.org/project/uboot/list/?series=145044

I rebase on v2020.01 and made some minor update after Simon Glass review. And I also split the previous patch was part of v2 08/14 to help review
http://patchwork.ozlabs.org/patch/1200865/
"gpio: add ops for configuration with dir flags"

I create this patchset to prepare alignment of stm32mp157c-ev1 device-tree with the linux kernel v5.4.

One node for touch screen support use the IRQ line configuration using the new kernel binding introduced by the linux kernel commit ede033e1e863c from v5.1 ('dt-bindings:
gpio: document the new pull-up/pull-down flags')
https://github.com/torvalds/linux/commit/ede033e1e863c

gt9147: goodix_ts at 5d {
      compatible = "goodix,gt9147";
      reg = <0x5d>;
      status = "okay";
      irq-gpios = <&stmfx_pinctrl 14
                      (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>;
      irq-flags = <IRQ_TYPE_EDGE_RISING>;
};

In Linux Kernel, the GPIO configuration (pull down/up) are now managed by GPIO lib but they are not yet supported by U-boot in uclass GPIO or pincontrol (when used by gpio-hog).

This serie adds the support of theses new defines (with ops get_config/set_config) added in kernel GPIO binding and adds the test in sandbox.

NB: In a second phase, the removed set_open_drain/get_open_drain
API could be replaced by the new ops get_config/set_config.

I also align the gpio binding file with the version from the latest kernel v5.3 (I don't think I remove any U-Boot specific part with this patch)
I move the added information on gpio hog code in a new file doc/README.gpio.

To have functional test, I convert pinctrl-generic to livetree otherwise the pins are not correctly configured in sandbox, when CONFIG_OF_LIVE is activated.

For the test on gpio I add information for pin configuration in output of the command "pinmux status" with a simple pincontrol driver associated to GPIO driver.

NB: after rebase on master branch, the sandbox test "ut dm power_domain"
is failing; it was not the case for v2019.10.

------------------------------------------------------ Captured stdout call ------------------------------------------------------- => ut dm power_domain
Test: dm_test_power_domain: power-domain.c
../test/dm/test-main.c:72, dm_test_destroy(): 0 == uclass_destroy(uc): Expected 0x0 (0), got 0xffffffea (-22) ../test/dm/test-main.c:107, dm_do_test(): 0 == dm_test_destroy(uts): Expected 0x0 (0), got 0x1 (1) ../test/dm/test-main.c:169, dm_test_main(): 0 == dm_do_test(uts, test, 1): Expected 0x0 (0), got 0x1 (1)
=>

I think it is linked to commit 52edfed65de9 ("dm: core:
device: switch off power domain after device removal")

After some investigation :

1/ pincontrol is remove in uclass_destroy(0)

2/ power domain is removed in uclass_destroy(0)

3/ device_chld_unbind()
dev_power_domain_off
-> probe power domain (again)
--> pinctrl_select_state() in device_probe()
---> pincontrol is probed (again)

4/ at the end of dev_power_domain_off() function the power domain
is unbind in dev_power_domain_off device_remove(pd.dev, DM_REMOVE_NORMAL);

So power domain driver is correctly removed but it is not the case for the pincontrol driver and that cause the issue.

The problem occurs after my serie only because I introduce a second pincontrol driver for sandbox, so the dynamic changes but my serie is not the root cause of the issue.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Workaround to allow test execution:
"dm: core: device: don't probe pinctrl for power domain"

Simon, any idea on how to fix the test failure above? I don't think excluding the test is the right path forward. Thanks!

Not really. I will see if I can figure it out when I get back to things.

I found a solution and send out two patches.

Regards,
Simon