dm: add support of new binding in gpio and pincontrol
Subsystems (5)
v2 cover dm: add support of new binding in gpio and pincontrol
Hi,
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.
=> ut dm power_domain
Test: dm_test_power_domain: power-domain.c../test/dm/test-main.c:73, dm_test_destroy(): 0 == uclass_destroy(uc): Expected 0, got -22 ../test/dm/test-main.c:108, dm_do_test(): 0 == dm_test_destroy(uts): Expected 0, got 1 ../test/dm/test-main.c:170, dm_test_main(): 0 == dm_do_test(uts, test, 1): Expected 0, got 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,
it should be investigated by power domain users.
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
CI-Travis build:
https://travis-ci.org/patrickdelaunay/u-boot/builds/616716294
Issue for tbs2910 board not reproduced locally with buildman +u-boot.imx exceeds file size limit:
1405+ limit: 0x5fc00 bytes 1406+ actual: 0x60c00 bytes 1407+ excess: 0x1000 bytes
Regards
Patrick Delaunay
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
- 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 (14):
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 ops for configuration with 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 | 192 ++++++++++---- 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 | 104 ++++---- 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/gpio.c | 69 ++++- test/dm/test-fdt.c | 2 +- test/py/tests/test_pinmux.py | 38 ++- 22 files changed, 1216 insertions(+), 398 deletions(-) create mode 100644 doc/README.gpio create mode 100644 include/dt-bindings/gpio/sandbox-gpio.h
Signature · 1 line
2.17.1
PATCH v2 1/14 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 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
@@ -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
PATCH v2 1/14 dm: pinctrl: convert pinctrl-single to livetree
Quoted 9 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 ofDECLARE_GLOBAL_DATA_PTR.
Quoted 8 lines
Signed-off-by Patrick Delaunay <[email protected]>---
Changes in v2:
- use thedev_API instead ofofnode_function.drivers/pinctrl/pinctrl-single.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-)
PATCH v2 2/14 dm: core: add ofnode and dev function to iterate on node property
In reply to Patrick DelaunayAdd 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
For example:
struct ofprop property;
dev_for_each_property(property, config) {
value = dev_read_prop_by_prop(&property, &propname, &len);or:
for (prop = ofnode_get_first_property(dev_ofnode(dev));
prop;
prop = ofnode_get_next_property(dev_ofnode(dev),prop))
{
value = ofnode_get_property_by_prop(dev_ofnode(dev), prop,
&propname, &len);
....
}
---
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 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 265 insertions(+), 1 deletion(-)
drivers/core/of_access.c +32 -0
@@ -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
@@ -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
@@ -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
Signature · 1 line
2.17.1
PATCH v2 2/14 dm: core: add ofnode and dev function to iterate on node property
Quoted 34 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_propFor example:
struct ofprop property;dev_for_each_property(property, config) { value = dev_read_prop_by_prop(&property, &propname, &len);or:
for (prop = ofnode_get_first_property(dev_ofnode(dev));
prop;
prop = ofnode_get_next_property(dev_ofnode(dev),prop))
{
value = ofnode_get_property_by_prop(dev_ofnode(dev), prop,
&propname, &len);
....
}Signed-off-by Patrick Delaunay <[email protected]>---
Changes in v2:
- Identify property with a new struct ofprop as proposed by Simon Glass
- Adddev_iterate functions
Quoted 7 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 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 265 insertions(+), 1 deletion(-)
These look good, but please add a few simple tests like in your commit message.
See test/dm/ofnode.c, or you could add test/dm/read.c and just use the read interface which would be good enough It think, since tests run with and without livetree.
Regards,
Simon
PATCH v2 2/14 dm: core: add ofnode and dev function to iterate on node property
Hi,
Quoted 44 lines
From: Simon Glass <[email protected]>
Sent: lundi 30 décembre 2019 02:21Quoted 33 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_propFor example:
struct ofprop property;dev_for_each_property(property, config) { value = dev_read_prop_by_prop(&property, &propname, &len);or:
for (prop = ofnode_get_first_property(dev_ofnode(dev));
prop;
prop = ofnode_get_next_property(dev_ofnode(dev),prop))
{
value = ofnode_get_property_by_prop(dev_ofnode(dev), prop,
&propname, &len); ....
}Signed-off-by Patrick Delaunay <[email protected]>---
Changes in v2:
- Identify property with a new struct ofprop as proposed by Simon Glass
- Adddev_iterate functionsQuoted 6 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
Quoted 8 lines
++++++++++++++++++++++++++++++++++++++++
Quoted 1 line
6 files changed, 265 insertions(+), 1 deletion(-)These look good, but please add a few simple tests like in your commit message.
See
test/dm/ofnode.c, or you could addtest/dm/read.cand just use the read interface which would be good enough It think, since tests run with and without livetree.
Ok I will add it.
Regards
Patrick
PATCH v2 3/14 dm: pinctrl: migrate pinctrl-generic to livetree
In reply to Patrick DelaunayMigrate 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 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
@@ -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
PATCH v2 3/14 dm: pinctrl: migrate pinctrl-generic to livetree
Quoted 13 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 ofDECLARE_GLOBAL_DATA_PTR.This patch solves the parsing issue during sandbox tests for pin configuration (
OF_LIVEis activated insandbox_defconfigand sub node are not correctly parsed inpinctrl_generic_set_state_subnodewith fdt lib API).
Quoted 8 lines
Signed-off-by Patrick Delaunay <[email protected]>---
Changes in v2:
- Changedev_functions in pinctrl-genericdrivers/pinctrl/pinctrl-generic.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-)
PATCH v2 4/14 dt-bindings: gpio: document the new pull-up/pull-down flags
In reply to Patrick DelaunayThis 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 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
@@ -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
@@ -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
PATCH v2 5/14 gpio: remove GPIOD_REQUESTED
In reply to Patrick DelaunayRemove the define GPIOD_REQUESTED as it is never used and use BIT() macro for other defines.
---
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
@@ -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
PATCH v2 6/14 gpio: remove the open_drain API and ops
In reply to Patrick DelaunayThis 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 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 6/14 gpio: remove the open_drain API and ops
Quoted 16 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.
Signed-off-by Patrick Delaunay <[email protected]>---
Changes in v2:
- remove theopen_drainAPI and ops
Quoted 7 lines
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(-)
PATCH v2 7/14 gpio: add gpio descriptor initialization helper
In reply to Patrick DelaunayAdd 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 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
@@ -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
PATCH v2 7/14 gpio: add gpio descriptor initialization helper
Quoted 6 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.
Quoted 8 lines
Signed-off-by Patrick Delaunay <[email protected]>---
Changes in v2:
- add gpio descriptor initialization helperdrivers/gpio/gpio-uclass.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
PATCH v2 8/14 gpio: add ops for configuration with dir flags
In reply to Patrick DelaunayThis commit manages the dir flags that can be used in gpio specifiers to indicate if a pull-up resistor or pull-down resistor should be enabled for output gpio (GPIO_PULL_UP, GPIO_PULL_DOWN) and the Open Drain/Open Source configuration for input gpio (GPIO_OPEN_DRAIN, GPIO_OPEN_SOURCE).
These flags are already supported in Linux kernel in gpiolib; this patch provides the same support in U-Boot.
The dir flags are managed in gpio drivers with two optional ops in gpio
uclass: set_dir_flags and get_dir_flags.
- ops set_dir_flags() set the direction and configuration of each GPIO with a only call to dm_gpio_set_dir_flags() / dm_gpio_set_dir() and respecting the configuration provided by device tree (saved in desc->flags).
- ops get_dir_flags() return dynamically the current gpio configuration, it is used by the new API dm_gpio_get_dir_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
---
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 | 157 +++++++++++++++++++++++++++++++------ include/asm-generic/gpio.h | 65 +++++++++++++-- 2 files changed, 192 insertions(+), 30 deletions(-)
drivers/gpio/gpio-uclass.c +133 -24
@@ -140,8 +140,27 @@ 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 ; + +/* +* 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 ; }
@@ -476,18 +495,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)
@@ -504,39 +529,119 @@ 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) +/* check dir flags invalid configuration */ +static int check_dir_flags (ulong flags) +{ +if ((flags &GPIOD_IS_OUT ) && (flags &GPIOD_IS_IN )) +return -EINVAL ; + +if ((flags &GPIOD_PULL_UP ) && (flags &GPIOD_PULL_DOWN )) +return -EINVAL ; + +if ((flags &GPIOD_OPEN_DRAIN ) && (flags &GPIOD_OPEN_SOURCE )) +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; - ret =check_reserved (desc,"set_dir" ); -if (ret) -return ret; + ret =check_dir_flags (flags); +if (ret) { +dev_err (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); -if (flags &GPIOD_IS_OUT ) { -int value = flags &GPIOD_IS_OUT_ACTIVE ?1 :0 ; +return ret; + } -if (flags &GPIOD_ACTIVE_LOW ) - value = !value; - ret = ops->direction_output (dev, desc->offset, value); - }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; +} + +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 ; +/* 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 */ +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); +} + +int dm_gpio_get_dir_flags (struct gpio_desc *desc,ulong *flags) +{ +struct udevice *dev = desc->dev; +struct dm_gpio_ops *ops =gpio_get_ops (dev); +int ret, value; +ulong dir_flags; + + ret =check_reserved (desc,"get_dir_flags" ); +if (ret) +return ret; + +/* 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 ; }/**
@@ -809,7 +914,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;
@@ -1036,6 +1141,10 @@ 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; reloc_done++; }
include/asm-generic/gpio.h +59 -6
112 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 8/14 gpio: add ops for configuration with dir flags
Hi Patrick,
Quoted 32 lines · Patrick Delaunay
This commit manages the dir flags that can be used in gpio specifiers to indicate if a pull-up resistor or pull-down resistor should be enabled for output gpio (
GPIO_PULL_UP,GPIO_PULL_DOWN) and the Open Drain/Open Source configuration for input gpio (GPIO_OPEN_DRAIN,GPIO_OPEN_SOURCE).These flags are already supported in Linux kernel in gpiolib; this patch provides the same support in U-Boot.
The dir flags are managed in gpio drivers with two optional ops in gpio
uclass:set_dir_flagsandget_dir_flags.- ops
set_dir_flags()set the direction and configuration of each GPIO with a only call todm_gpio_set_dir_flags()/dm_gpio_set_dir()and respecting the configuration provided by device tree (saved indesc->flags).- ops
get_dir_flags()return dynamically the current gpio configuration, it is used by the new APIdm_gpio_get_dir_flags().When these optional ops are absent, the gpio uclass use the mandatory ops (
direction_output,direction_input,get_value) anddesc->flagsto manage only the main dir flags:
-GPIOD_IS_IN
-GPIOD_IS_OUT
-GPIOD_IS_OUT_ACTIVE
-GPIOD_ACTIVE_LOWSigned-off-by Patrick Delaunay <[email protected]>---
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 APIdm_gpio_get_dir_flagsdrivers/gpio/gpio-uclass.c | 157 +++++++++++++++++++++++++++++++------ include/asm-generic/gpio.h | 65 +++++++++++++-- 2 files changed, 192 insertions(+), 30 deletions(-)
Quoted 69 lines
drivers/gpio/gpio-uclass.c +31
-6@@ -140,8 +140,27 @@ 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 ; + +/* +* 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 ; }@@ -476,18 +495,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)@@ -504,39 +529,119 @@ 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) +/* check dir flags invalid configuration */
drivers/gpio/gpio-uclass.c int dm_gpio_set_value(const struct gpio_desc *desc, int value) · line 542
Quoted 10 lines
drivers/gpio/gpio-uclass.c +10
-0+static int check_dir_flags (ulong flags) +{ +if ((flags &GPIOD_IS_OUT ) && (flags &GPIOD_IS_IN )) +return -EINVAL ; + +if ((flags &GPIOD_PULL_UP ) && (flags &GPIOD_PULL_DOWN )) +return -EINVAL ; + +if ((flags &GPIOD_OPEN_DRAIN ) && (flags &GPIOD_OPEN_SOURCE )) +return -EINVAL ;
Can we use different error numbers here, so that people can figure out what is going on?
Quoted 11 lines
drivers/gpio/gpio-uclass.c +6
-0+ +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;
drivers/gpio/gpio-uclass.c int dm_gpio_set_value(const struct gpio_desc *desc, int value) · line 560
Quoted 10 lines
drivers/gpio/gpio-uclass.c +7
-3- ret =check_reserved (desc,"set_dir" ); -if (ret) -return ret; + ret =check_dir_flags (flags); +if (ret) { +dev_err (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);
log_debug()
Also should return error
Quoted 65 lines
drivers/gpio/gpio-uclass.c +41
-14-if (flags &GPIOD_IS_OUT ) { -int value = flags &GPIOD_IS_OUT_ACTIVE ?1 :0 ; +return ret; + } -if (flags &GPIOD_ACTIVE_LOW ) - value = !value; - ret = ops->direction_output (dev, desc->offset, value); - }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; +} + +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 ; +/* 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 */ +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); +} + +int dm_gpio_get_dir_flags (struct gpio_desc *desc,ulong *flags) +{
drivers/gpio/gpio-uclass.c int dm_gpio_set_value(const struct gpio_desc *desc, int value) · line 621
Quoted 10 lines
drivers/gpio/gpio-uclass.c +10
-0+struct udevice *dev = desc->dev; +struct dm_gpio_ops *ops =gpio_get_ops (dev); +int ret, value; +ulong dir_flags; + + ret =check_reserved (desc,"get_dir_flags" ); +if (ret) +return ret; + +/* GPIOD_ are directly provided by driver except GPIOD_ACTIVE_LOW*/
Space before *
Quoted 51 lines
drivers/gpio/gpio-uclass.c +28
-1+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 ; }/** @@ -809,7 +914,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;@@ -1036,6 +1141,10 @@ 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; reloc_done++; }include/asm-generic/gpio.h +0
-0
include/asm-generic/gpio.h struct udevice; · line 123
Quoted 7 lines
include/asm-generic/gpio.h +1
-0@@ -117,10 +117,15 @@ struct udevice;struct gpio_desc {struct udevice *dev;/* Device, NULL for invalid GPIO */ 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 */
s/has/is/ ?
include/asm-generic/gpio.h struct udevice; · line 128
Quoted 5 lines
include/asm-generic/gpio.h +4
-0#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 */
pull-down or pulldown
include/asm-generic/gpio.h struct gpio_desc { · line 142
Quoted 13 lines
include/asm-generic/gpio.h +6
-0uint offset;/* GPIO offset within the device */ /* @@ -129,6 +134,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)) ? 1 : 0) +
You can drop the ? 1 : 0 since boolean expressions do that anyway.
Quoted 94 lines
include/asm-generic/gpio.h +48
-7/** * dm_gpio_is_valid() - Check if a GPIO is valid * @@ -253,6 +264,7 @@ struct dm_gpio_ops { int value);int (*get_value)(struct udevice *dev,unsigned offset);int (*set_value)(struct udevice *dev,unsigned offset,int value); +/** * get_function() Get the GPIO function * @@ -287,6 +299,37 @@ 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 +* +* 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); };/** @@ -586,8 +629,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() @@ -596,11 +638,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 add 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 tot 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, @@ -610,6 +651,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 * --
Quoted 2 lines
2.17.1
There's a lot going on in this patch.
Regards,
Simon
PATCH v2 8/14 gpio: add ops for configuration with dir flags
Hi Simon
Quoted 134 lines
From: Simon Glass <[email protected]>
Sent: lundi 30 décembre 2019 02:21Hi Patrick,
Quoted 39 lines · Patrick Delaunay
This commit manages the dir flags that can be used in gpio specifiers to indicate if a pull-up resistor or pull-down resistor should be enabled for output gpio (
GPIO_PULL_UP,GPIO_PULL_DOWN) and the Open Drain/Open Source configuration for input gpio (GPIO_OPEN_DRAIN,GPIO_OPEN_SOURCE).These flags are already supported in Linux kernel in gpiolib; this patch provides the same support in U-Boot.
The dir flags are managed in gpio drivers with two optional ops in gpio
uclass:set_dir_flagsandget_dir_flags.- ops
set_dir_flags()set the direction and configuration of each GPIO with a only call todm_gpio_set_dir_flags()/dm_gpio_set_dir()and respecting the configuration provided by device tree (saved indesc->flags).- ops
get_dir_flags()return dynamically the current gpio configuration, it is used by the new APIdm_gpio_get_dir_flags().When these optional ops are absent, the gpio uclass use the mandatory ops (
direction_output,direction_input,get_value) anddesc->flagsto manage only the main dir flags:
-GPIOD_IS_IN
-GPIOD_IS_OUT
-GPIOD_IS_OUT_ACTIVE
-GPIOD_ACTIVE_LOWSigned-off-by Patrick Delaunay <[email protected]>---
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 APIdm_gpio_get_dir_flagsQuoted 4 lines
drivers/gpio/gpio-uclass.c | 157 +++++++++++++++++++++++++++++++------ include/asm-generic/gpio.h | 65 +++++++++++++-- 2 files changed, 192 insertions(+), 30 deletions(-)Reviewed-by Simon Glass <[email protected]>drivers/gpio/gpio-uclass.c int gpio_xlate_offs_flags(struct udevice *dev, struct
Quoted 6 lines
drivers/gpio/gpio-uclass.c +0
-0@@ -140,8 +140,27 @@ int gpio_xlate_offs_flags(struct udevice *dev, struct
gpio_desc*desc,drivers/gpio/gpio-uclass.c int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,
Quoted 11 lines
drivers/gpio/gpio-uclass.c +6
-1if (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 ; + +/* +* need to test 2 bits for gpio output binding: +* OPEN_DRAIN (0x6) = SINGLE_ENDED (0x2) | LINE_OPEN_DRAIN (
0x4)drivers/gpio/gpio-uclass.c int gpio_xlate_offs_flags(struct udevice *dev, struct · line 150
Quoted 1 line
drivers/gpio/gpio-uclass.c +1
-0+* OPEN_SOURCE (0x2) = SINGLE_ENDED (0x2) |
LINE_OPEN_SOURCE(0x0)Quoted 35 lines
drivers/gpio/gpio-uclass.c +21
-1+*/ +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 ; }@@ -476,18 +495,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)drivers/gpio/gpio-uclass.c int gpio_direction_output(unsigned gpio, int value)
Quoted 10 lines
drivers/gpio/gpio-uclass.c +1
-4return 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) @@ -504,39 +529,119 @@ int dm_gpio_set_value(const struct gpio_desc *desc, intvalue)
drivers/gpio/gpio-uclass.c int dm_gpio_set_value(const struct gpio_desc *desc, int value)
Quoted 13 lines
return 0;}
drivers/gpio/gpio-uclass.c +9
-1-int dm_gpio_set_dir_flags (struct gpio_desc *desc,ulong flags) +/* check dir flags invalid configuration */ static int +check_dir_flags (ulong flags) { +if ((flags &GPIOD_IS_OUT ) && (flags &GPIOD_IS_IN )) +return -EINVAL ; + +if ((flags &GPIOD_PULL_UP ) && (flags &GPIOD_PULL_DOWN )) +return -EINVAL ; + + if ((flags & GPIOD_OPEN_DRAIN) && (flags &
GPIOD_OPEN_SOURCE))
Quoted 4 lines
Quoted 1 line
+ return
-EINVAL;Can we use different error numbers here, so that people can figure out what is going on?
It is really a basic error that should be never occur,
I think that EINVAL is the correct return value here (it is difficult to have 3 different errno)
But I will add a debug trace before each return...
Quoted 20 lines
Quoted 9 lines
drivers/gpio/gpio-uclass.c +6
-0+ +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);drivers/gpio/gpio-uclass.c int dm_gpio_set_value(const struct gpio_desc *desc, int value)
Quoted 10 lines
drivers/gpio/gpio-uclass.c +5
-3+struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev);int ret; - ret =check_reserved (desc,"set_dir" ); -if (ret) -return ret; + ret =check_dir_flags (flags); +if (ret) { + dev_err(dev, + "%s error: set_dir_flags for gpio %s%d has invalid dir flags0x%lx\n",
Quoted 5 lines
drivers/gpio/gpio-uclass.c int dm_gpio_set_value(const struct gpio_desc *desc, int value) · line 560
Quoted 3 lines
drivers/gpio/gpio-uclass.c +3
-0+ desc->dev->name, + uc_priv->bank_name ? uc_priv->bank_name :"" , + desc->offset, flags);
log_debug()
Ok change to dev_dbglog_debug is preferered to dev_dbg ?
for me dev_.... functions are preferred when 'dev' is available.
Quoted 7 lines
Also should return error
Quoted 5 lines
drivers/gpio/gpio-uclass.c +2
-2-if (flags &GPIOD_IS_OUT ) { -int value = flags &GPIOD_IS_OUT_ACTIVE ?1 :0 ; +return ret; + }
In fact return is inserted here (test moved in check_dir_flags)
The final code become :
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;
}
/* GPIOD_ are directly managed by driver in set_dir_flags*/Quoted 61 lines
Quoted 61 lines
drivers/gpio/gpio-uclass.c +41
-12-if (flags &GPIOD_ACTIVE_LOW ) - value = !value; - ret = ops->direction_output (dev, desc->offset, value); - }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; +} + +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 ; +/* 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 */ +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); } + +int dm_gpio_get_dir_flags (struct gpio_desc *desc,ulong *flags) { +struct udevice *dev = desc->dev; +struct dm_gpio_ops *ops =gpio_get_ops (dev); +int ret, value; +ulong dir_flags; +
Quoted 8 lines
drivers/gpio/gpio-uclass.c int dm_gpio_set_value(const struct gpio_desc *desc, int value)
Quoted 6 lines
drivers/gpio/gpio-uclass.c +6
-0+ ret =check_reserved (desc,"get_dir_flags" ); +if (ret) +return ret; + +/* GPIOD_ are directly provided by driver except +GPIOD_ACTIVE_LOW*/ Space before *
ok
Quoted 45 lines
drivers/gpio/gpio-uclass.c static int gpio_request_tail(int ret, const char
Quoted 27 lines
drivers/gpio/gpio-uclass.c +23
-0+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 ; }/** @@ -809,7 +914,7 @@ static int gpio_request_tail(int ret, const char*nodename,
Quoted 17 lines
drivers/gpio/gpio-uclass.c +5
-1debug ("%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;@@ -1036,6 +1141,10 @@ 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;
Quoted 16 lines
Quoted 7 lines
drivers/gpio/gpio-uclass.c +0
-0reloc_done++; }include/asm-generic/gpio.h +0
-0include/asm-generic/gpio.h struct udevice; · line 123
Quoted 7 lines
include/asm-generic/gpio.h +1
-0@@ -117,10 +117,15 @@ struct udevice;struct gpio_desc {struct udevice *dev;/* Device, NULL for invalid GPIO */ 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 */ s/has/is/ ?
GPIO is active when value is low
Quoted 9 lines
include/asm-generic/gpio.h struct udevice;
Quoted 6 lines
include/asm-generic/gpio.h +4
-0#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 */
pull-down or pulldown
Ok => pull-down
Quoted 12 lines
include/asm-generic/gpio.h struct gpio_desc { · line 138
Quoted 9 lines
include/asm-generic/gpio.h +2
-0uint offset;/* GPIO offset within the device */ /* @@ -129,6 +134,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)include/asm-generic/gpio.h struct gpio_desc { · line 140
Quoted 2 lines
include/asm-generic/gpio.h +2
-0+#define GPIOD_FLAGS_OUTPUT (flags) \ + (((((flags) & GPIOD_FLAGS_OUTPUT_MASK) ==
Quoted 7 lines
GPIOD_IS_OUT_ACTIVE) || \include/asm-generic/gpio.h struct gpio_desc { · line 141
Quoted 1 line
include/asm-generic/gpio.h +1
-0+ (((flags) & GPIOD_FLAGS_OUTPUT_MASK) ==
GPIOD_ACTIVE_LOW)) ?include/asm-generic/gpio.h struct gpio_desc { · line 143
Quoted 2 lines
include/asm-generic/gpio.h +2
-0+1 : 0) +You can drop the ? 1 : 0 since boolean expressions do that anyway.
Yes I drop it ....
Quoted 96 lines
Quoted 96 lines
include/asm-generic/gpio.h +1
-0/** * dm_gpio_is_valid() - Check if a GPIO is valid * @@ -253,6 +264,7 @@ struct dm_gpio_ops { int value);int (*get_value)(struct udevice *dev,unsigned offset);int (*set_value)(struct udevice *dev,unsigned offset,int value); +/** * get_function() Get the GPIO function *include/asm-generic/gpio.h +31
-1@@ -287,6 +299,37 @@ 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 +* +* 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); };/** @@ -586,8 +629,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 bygpio_request_by_name()include/asm-generic/gpio.h +1
-2@@ -596,11 +638,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 add flags * -* This is like dm_gpio_set_dir() except that the flags value is provided
- * instead of being used fromdesc->flags. This is needed because in many
- * cases the GPIO description does not include direction information.
+ * This sets up the direction according tot the provided flags and
+ the GPIO
+ * description (desc->flags) which include direction information.
* Note thatdesc->flagsis updated by this function.
*
* @desc: GPIO description containing device, offset and flags,include/asm-generic/gpio.h +12
-0@@ -610,6 +651,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); +
Quoted 8 lines
Quoted 6 lines
include/asm-generic/gpio.h +0
-1/** * gpio_get_number() - Get the global GPIO number of a GPIO * -- 2.17.1
There's a lot going on in this patch.
Yes, I can split the work to help the review
1/ prepare
2/ add get_dir_flags
3/ add set_dir_flags
Quoted 2 lines
Regards,
Simon
Regards
Patrick
PATCH v2 9/14 dt-bindings: gpio: alignment with kernel v5.3
In reply to Patrick DelaunayUpdate 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 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
@@ -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
PATCH v2 10/14 pinctrl: sandbox: Add mux information in get_pin_muxing
In reply to Patrick DelaunayAdd param information in pin information output. This update prepare unitary test for pin configuration in pinctrl node.
---
Changes in v2: None
drivers/pinctrl/pinctrl-sandbox.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/pinctrl/pinctrl-sandbox.c +30 -0
@@ -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
PATCH v2 11/14 test: dm: update test for pins configuration in pinctrl node
In reply to Patrick DelaunayAdd 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 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
@@ -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
@@ -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
@@ -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
PATCH v2 12/14 gpio: sandbox: cleanup binding support
In reply to Patrick DelaunayCleanup 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 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
@@ -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
@@ -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
@@ -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
PATCH v2 13/14 test: dm: update test for pins configuration in gpio
In reply to Patrick DelaunayAdd 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 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
@@ -16,6 +16,7 @@ eth5 = ð_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
@@ -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
@@ -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
PATCH v2 13/14 test: dm: update test for pins configuration in gpio
Quoted 18 lines · Patrick Delaunay
Add tests for new API
set_dir_flagsandset_dir_flagsand associated code in gpio uclass.Test support for new flags
GPIO_OPEN_DRAIN,GPIO_OPEN_SOURCEGPIO_PULL_UPandGPIO_PULL_DOWN.Signed-off-by Patrick Delaunay <[email protected]>---
Changes in v2:
- simplify sandbox GPIO driver: savedir_flags(GPIOD_...) and remove internal flags (GPIOF_...); the previous path "gpio: sandbox: cleanup flag support" is no more needed
- add unitary test indm_test_gpioforset_dir_flags
- add some function check indm_test_gpio_phandles
-dm_test_gpio_pin_configchange todm_test_gpio_get_dir_flags
Quoted 6 lines
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(-)
PATCH v2 14/14 test: pinmux: add pincontrol-gpio for pin configuration
In reply to Patrick DelaunayAdd a simple pincontrol associated to the sandbox gpio driver, that allows to check pin configuration with the command pinmux.
The pmux 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 .
...
Serie-cc: Heiko Schocher <[email protected]>
Serie-cc: Simon Glass <[email protected]>
---
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
@@ -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
@@ -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
PATCH v2 14/14 test: pinmux: add pincontrol-gpio for pin configuration
Quoted 26 lines · Patrick Delaunay
Add a simple pincontrol associated to the sandbox gpio driver, that allows to check pin configuration with the command pinmux.
The pmux 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
Serie-cc: Heiko Schocher <[email protected]>
Serie-cc: Simon Glass <[email protected]>
Series-cc :-)
Quoted 10 lines
Signed-off-by Patrick Delaunay <[email protected]>---
Changes in v2:
- Adaptsandbox_pinctrl_gpiodriver with the saveddir_flagsin sandbox gpio driver
- rebase on v2020.01-rc3
Quoted 4 lines
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(-)
PATCH v2 14/14 test: pinmux: add pincontrol-gpio for pin configuration
Hi Simon,
Quoted 31 lines
From: Simon Glass <[email protected]>
Sent: lundi 30 décembre 2019 02:21Quoted 26 lines · Patrick Delaunay
Add a simple pincontrol associated to the sandbox gpio driver, that allows to check pin configuration with the command pinmux.
The pmux 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 4 lines
Quoted 2 lines
Serie-cc: Heiko Schocher <[email protected]>
Serie-cc: Simon Glass <[email protected]>Series-cc :-)
Oups :-)
Quoted 10 lines
Quoted 10 lines
Signed-off-by Patrick Delaunay <[email protected]>---
Changes in v2:
- Adaptsandbox_pinctrl_gpiodriver with the saveddir_flagsin sandbox gpio driver
- rebase on v2020.01-rc3
Quoted 6 lines
Quoted 4 lines
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(-)Reviewed-by Simon Glass <[email protected]>
Thanks for the review
I am preparing a v3.
Do you think I need to split the patch
[PATCH v2 08/14] gpio: add ops for configuration with dir flags
Regards.
Patrick
PATCH v2 14/14 test: pinmux: add pincontrol-gpio for pin configuration
Hi Patrick,
Quoted 57 lines · Patrick DELAUNAY
Hi Simon,
Quoted 31 lines
From: Simon Glass <[email protected]>
Sent: lundi 30 décembre 2019 02:21Quoted 26 lines · Patrick Delaunay
Add a simple pincontrol associated to the sandbox gpio driver, that allows to check pin configuration with the command pinmux.
The pmux 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 4 lines
Quoted 2 lines
Serie-cc: Heiko Schocher <[email protected]>
Serie-cc: Simon Glass <[email protected]>Series-cc :-)
Oups :-)
Quoted 15 lines
Quoted 14 lines
Signed-off-by Patrick Delaunay <[email protected]>---
Changes in v2:
- Adaptsandbox_pinctrl_gpiodriver with the saveddir_flagsin sandbox gpio driver
- rebase on v2020.01-rc3arch/sandbox/dts/test.dts | 48 +++++---- drivers/gpio/sandbox.c | 195 +++++++++++++++++++++++++++++++++++ test/py/tests/test_pinmux.py | 10 ++ 3 files changed, 231 insertions(+), 22 deletions(-)
Quoted 9 lines
Quoted 1 line
Reviewed-by Simon Glass <[email protected]>Thanks for the review
I am preparing a v3.
Do you think I need to split the patch
[PATCH v2 08/14] gpio: add ops for configuration with dir flags
I am in favour of that.
Regards,
Simon