Add support for pinmux status command on beaglebone
Subsystems (2)
cover Add support for pinmux status command on beaglebone
The series was born from the need to check the pinmux setting of a peripheral on a beaglebone board. I then ran the 'pinmux status -a' command but it failed because some operations (get_pin_muxing, get_pin_name and get_pins_count) were missing in the 'pinctrl-single' driver.
The patch series can be cleanly applied to the HEAD of the master which at the time of release points to e716c9022970dac9be15856a6651a07132463578 commit (Revert "doc: update Kernel documentation build system").
Dario Binacchi (11):
pinctrl: single: fix format of structure documentation
pinctrl: single: fix the loop counter variable type
pinctrl: single: fix debug messages formatting
pinctrl: single: get register area size by device API
pinctrl: single: check "register-width" DT property
pinctrl: single: change function mask default value
pinctrl: single: use function pointer for register access
pinctrl: single: add get_pins_count operation
pinctrl: single: add get_pin_name operation
pinctrl: single: add get_pin_muxing operation
test: pinmux: add test for 'pinctrl-single' driver
arch/sandbox/dts/test.dts | 65 ++++ configs/sandbox_defconfig | 1 + drivers/pinctrl/pinctrl-single.c | 488 +++++++++++++++++++++++++++---- test/dm/pinmux.c | 81 ++++- 4 files changed, 570 insertions(+), 65 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/11 pinctrl: single: fix format of structure documentation
U-Boot adopted the kernel-doc annotation style.
---
drivers/pinctrl/pinctrl-single.c | 45 +++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 9 deletions(-)
drivers/pinctrl/pinctrl-single.c +36 -9
@@ -10,23 +10,50 @@#include <linux/libfdt.h> #include <asm/io.h> +/** +* struct single_pdata - platform data +* @base: first configuration register +* @offset: index of last configuration register +* @mask: configuration-value mask bits +* @width: configuration register bit width +* @bits_per_mux: true if one register controls more than one pin +*/ struct single_pdata { -fdt_addr_t base;/* first configuration register */ -int offset;/* index of last configuration register */ -u32 mask;/* configuration-value mask bits */ -int width;/* configuration register bit width */ +fdt_addr_t base; +int offset; +u32 mask; +int width;bool bits_per_mux; }; +/** +* struct single_fdt_pin_cfg - pin configuration +* +* This structure is used for the pin configuration parameters in case +* the register controls only one pin. +* +* @reg: configuration register offset +* @val: configuration register value +*/ struct single_fdt_pin_cfg { -fdt32_t reg;/* configuration register offset */ -fdt32_t val;/* configuration register value */ +fdt32_t reg; +fdt32_t val; }; +/** +* struct single_fdt_bits_cfg - pin configuration +* +* This structure is used for the pin configuration parameters in case +* the register controls more than one pin. +* +* @reg: configuration register offset +* @val: configuration register value +* @mask: configuration register mask +*/ struct single_fdt_bits_cfg { -fdt32_t reg;/* configuration register offset */ -fdt32_t val;/* configuration register value */ -fdt32_t mask;/* configuration register mask */ +fdt32_t reg; +fdt32_t val; +fdt32_t mask; };/**
Signature · 1 line
2.17.1
PATCH 1/11 pinctrl: single: fix format of structure documentation
Quoted 8 lines · Dario Binacchi
U-Boot adopted the kernel-doc annotation style.
Signed-off-by Dario Binacchi <[email protected]>---
drivers/pinctrl/pinctrl-single.c | 45 +++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 9 deletions(-)
PATCH 2/11 pinctrl: single: fix the loop counter variable type
In reply to Dario BinacchiThe patch changes the variable 'n' type from phys_addr_t to int.
---
drivers/pinctrl/pinctrl-single.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/pinctrl/pinctrl-single.c +4 -4
@@ -75,8 +75,8 @@ static int single_configure_pins(struct udevice *dev, int size) {struct single_pdata *pdata =dev_get_plat (dev); -int count = size /sizeof (struct single_fdt_pin_cfg ); -phys_addr_t n, reg; +int n, count = size /sizeof (struct single_fdt_pin_cfg ); +phys_addr_t reg;u32 val;for (n =0 ; n < count; n++, pins++) {
@@ -109,8 +109,8 @@ static int single_configure_bits(struct udevice *dev, int size) {struct single_pdata *pdata =dev_get_plat (dev); -int count = size /sizeof (struct single_fdt_bits_cfg ); -phys_addr_t n, reg; +int n, count = size /sizeof (struct single_fdt_bits_cfg ); +phys_addr_t reg;u32 val, mask;for (n =0 ; n < count; n++, pins++) {
Signature · 1 line
2.17.1
PATCH 2/11 pinctrl: single: fix the loop counter variable type
Quoted 2 lines · Dario Binacchi
The patch changes the variable 'n' type from
phys_addr_tto int.
s/The patch changes/Change/
Review
Quoted 8 lines
Signed-off-by Dario Binacchi <[email protected]>---
drivers/pinctrl/pinctrl-single.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)(quoted diff) +0
-0
PATCH 2/11 pinctrl: single: fix the loop counter variable type
In reply to Dario BinacchiHi Dario,
Quoted 1 line · Dario Binacchi
The patch changes the variable 'n' type from
phys_addr_tto int.
This information can very easily be obtained by reading the diff. The commit message should also explain _why_ the change is made. For example here it would be a good idea to add something like:
n is used as a loop counter, not as a physical address, and is used in a comparison with an int. So it makes sense to set its type to int.
Other than that,
Quoted 35 lines
Signed-off-by Dario Binacchi <[email protected]>---
drivers/pinctrl/pinctrl-single.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/pinctrl/pinctrl-single.c +4
-4@@ -75,8 +75,8 @@ static int single_configure_pins(struct udevice *dev, int size) {struct single_pdata *pdata =dev_get_plat (dev); -int count = size /sizeof (struct single_fdt_pin_cfg ); -phys_addr_t n, reg; +int n, count = size /sizeof (struct single_fdt_pin_cfg ); +phys_addr_t reg;u32 val;for (n =0 ; n < count; n++, pins++) {@@ -109,8 +109,8 @@ static int single_configure_bits(struct udevice *dev, int size) {struct single_pdata *pdata =dev_get_plat (dev); -int count = size /sizeof (struct single_fdt_bits_cfg ); -phys_addr_t n, reg; +int n, count = size /sizeof (struct single_fdt_bits_cfg ); +phys_addr_t reg;u32 val, mask;for (n =0 ; n < count; n++, pins++) {Signature · 1 line
2.17.1
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments India
PATCH 3/11 pinctrl: single: fix debug messages formatting
In reply to Dario BinacchiThe printf '%pa' format specifier appends the '0x' prefix to the displayed address. Furthermore, the offset variable is displayed with the '%x' format specifier instead of '%pa'.
---
drivers/pinctrl/pinctrl-single.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
drivers/pinctrl/pinctrl-single.c +16 -12
@@ -77,15 +77,17 @@ static int single_configure_pins(struct udevice *dev,struct single_pdata *pdata =dev_get_plat (dev);int n, count = size /sizeof (struct single_fdt_pin_cfg );phys_addr_t reg; -u32 val; +u32 offset, val;for (n =0 ; n < count; n++, pins++) { - reg =fdt32_to_cpu (pins->reg); -if ((reg <0 ) || (reg > pdata->offset)) { -dev_dbg (dev," invalid register offset 0x%pa\n" , ®); + offset =fdt32_to_cpu (pins->reg); +if (offset <0 || offset > pdata->offset) { +dev_dbg (dev," invalid register offset 0x%x\n" , + offset);continue ; } - reg += pdata->base; + + reg = pdata->base + offset; val =fdt32_to_cpu (pins->val) & pdata->mask;switch (pdata->width) {case 16 :
@@ -99,7 +101,7 @@ static int single_configure_pins(struct udevice *dev, pdata->width);continue ; } -dev_dbg (dev," reg/val 0x%pa/0x%08x\n" , ®, val); +dev_dbg (dev," reg/val %pa/0x%08x\n" , ®, val); }return 0 ; }
@@ -111,15 +113,17 @@ static int single_configure_bits(struct udevice *dev,struct single_pdata *pdata =dev_get_plat (dev);int n, count = size /sizeof (struct single_fdt_bits_cfg );phys_addr_t reg; -u32 val, mask; +u32 offset, val, mask;for (n =0 ; n < count; n++, pins++) { - reg =fdt32_to_cpu (pins->reg); -if ((reg <0 ) || (reg > pdata->offset)) { -dev_dbg (dev," invalid register offset 0x%pa\n" , ®); + offset =fdt32_to_cpu (pins->reg); +if (offset <0 || offset > pdata->offset) { +dev_dbg (dev," invalid register offset 0x%x\n" , + offset);continue ; } - reg += pdata->base; + + reg = pdata->base + offset; mask =fdt32_to_cpu (pins->mask); val =fdt32_to_cpu (pins->val) & mask;
@@ -136,7 +140,7 @@ static int single_configure_bits(struct udevice *dev, pdata->width);continue ; } -dev_dbg (dev," reg/val 0x%pa/0x%08x\n" , ®, val); +dev_dbg (dev," reg/val %pa/0x%08x\n" , ®, val); }return 0 ; }
Signature · 1 line
2.17.1
PATCH 3/11 pinctrl: single: fix debug messages formatting
Hi Dario,
Quoted 4 lines · Dario Binacchi
The printf '%pa' format specifier appends the '0x' prefix to the displayed address. Furthermore, the offset variable is displayed with the '%x' format specifier instead of '%pa'.
Please start your commit message with the problem and then describe what your patch does. It is unclear from this commit message why we need this patch :-)
Quoted 6 lines
Signed-off-by Dario Binacchi <[email protected]>---
drivers/pinctrl/pinctrl-single.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
Regards,
Simon
PATCH 3/11 pinctrl: single: fix debug messages formatting
In reply to Dario BinacchiHi Dario,
Quoted 3 lines · Dario Binacchi
The printf '%pa' format specifier appends the '0x' prefix to the displayed address. Furthermore, the offset variable is displayed with the '%x' format specifier instead of '%pa'.
I agree with Simon that the commit message does not explain why this change is needed.
Quoted 15 lines
Signed-off-by Dario Binacchi <[email protected]>---
drivers/pinctrl/pinctrl-single.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)drivers/pinctrl/pinctrl-single.c +0
-1@@ -77,15 +77,17 @@ static int single_configure_pins(struct udevice *dev,struct single_pdata *pdata =dev_get_plat (dev);int n, count = size /sizeof (struct single_fdt_pin_cfg );phys_addr_t reg; -u32 val;
drivers/pinctrl/pinctrl-single.c static int single_configure_pins(struct udevice *dev, · line 86
Quoted 10 lines
drivers/pinctrl/pinctrl-single.c +5
-3+u32 offset, val;for (n =0 ; n < count; n++, pins++) { - reg =fdt32_to_cpu (pins->reg); -if ((reg <0 ) || (reg > pdata->offset)) { -dev_dbg (dev," invalid register offset 0x%pa\n" , ®); + offset =fdt32_to_cpu (pins->reg); +if (offset <0 || offset > pdata->offset) { +dev_dbg (dev," invalid register offset 0x%x\n" , + offset);
You are not just fixing "debug messages formatting" here. You have made other changes to the structure of the code here. While these changes might all be correct, they don't belong in a commit that claims to fix message formatting.
For example, this dev_dbg() statement in the pre-image prints "®" as the offset. This would be the address of the variable reg on the stack. This looks like it is a bug. The offset is stored in "reg", not in "®". The post-image fixes this bug. A person reading this diff might not look so closely at this because you only claim to change formatting. And some important discussion/context on this bug might be skipped over.
Please re-word the commit subject and message to clearly explain why you are making these structural changes and separate them from the formatting changes (which also warrant an explanation on their own).
Quoted 9 lines
drivers/pinctrl/pinctrl-single.c +2
-1continue ; } - reg += pdata->base; + + reg = pdata->base + offset; val =fdt32_to_cpu (pins->val) & pdata->mask;switch (pdata->width) {case 16 :
drivers/pinctrl/pinctrl-single.c static int single_configure_pins(struct udevice *dev, · line 104
Quoted 5 lines
drivers/pinctrl/pinctrl-single.c +1
-1@@ -99,7 +101,7 @@ static int single_configure_pins(struct udevice *dev, pdata->width);continue ; } -dev_dbg (dev," reg/val 0x%pa/0x%08x\n" , ®, val); +dev_dbg (dev," reg/val %pa/0x%08x\n" , ®, val);
In a similar fashion as above, shouldn't "®" be replaced with "reg"? I am not too familiar with the code to say for sure. Same for the changes below.
Quoted 38 lines
drivers/pinctrl/pinctrl-single.c +8
-6}return 0 ; }@@ -111,15 +113,17 @@ static int single_configure_bits(struct udevice *dev,struct single_pdata *pdata =dev_get_plat (dev);int n, count = size /sizeof (struct single_fdt_bits_cfg );phys_addr_t reg; -u32 val, mask; +u32 offset, val, mask;for (n =0 ; n < count; n++, pins++) { - reg =fdt32_to_cpu (pins->reg); -if ((reg <0 ) || (reg > pdata->offset)) { -dev_dbg (dev," invalid register offset 0x%pa\n" , ®); + offset =fdt32_to_cpu (pins->reg); +if (offset <0 || offset > pdata->offset) { +dev_dbg (dev," invalid register offset 0x%x\n" , + offset);continue ; } - reg += pdata->base; + + reg = pdata->base + offset; mask =fdt32_to_cpu (pins->mask); val =fdt32_to_cpu (pins->val) & mask;@@ -136,7 +140,7 @@ static int single_configure_bits(struct udevice *dev, pdata->width);continue ; } -dev_dbg (dev," reg/val 0x%pa/0x%08x\n" , ®, val); +dev_dbg (dev," reg/val %pa/0x%08x\n" , ®, val); }return 0 ; }Signature · 1 line
2.17.1
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments India
PATCH 3/11 pinctrl: single: fix debug messages formatting
Hi Pratyush,
Quoted 65 lines
Il 25/01/2021 18:09 Pratyush Yadav <[email protected]> ha scritto:
Hi Dario,
Quoted 3 lines · Dario Binacchi
The printf '%pa' format specifier appends the '0x' prefix to the displayed address. Furthermore, the offset variable is displayed with the '%x' format specifier instead of '%pa'.
I agree with Simon that the commit message does not explain why this change is needed.
Quoted 15 lines
Signed-off-by Dario Binacchi <[email protected]>---
drivers/pinctrl/pinctrl-single.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)drivers/pinctrl/pinctrl-single.c +0
-1@@ -77,15 +77,17 @@ static int single_configure_pins(struct udevice *dev,struct single_pdata *pdata =dev_get_plat (dev);int n, count = size /sizeof (struct single_fdt_pin_cfg );phys_addr_t reg; -u32 val;drivers/pinctrl/pinctrl-single.c static int single_configure_pins(struct udevice *dev, · line 86
Quoted 10 lines
drivers/pinctrl/pinctrl-single.c +5
-3+u32 offset, val;for (n =0 ; n < count; n++, pins++) { - reg =fdt32_to_cpu (pins->reg); -if ((reg <0 ) || (reg > pdata->offset)) { -dev_dbg (dev," invalid register offset 0x%pa\n" , ®); + offset =fdt32_to_cpu (pins->reg); +if (offset <0 || offset > pdata->offset) { +dev_dbg (dev," invalid register offset 0x%x\n" , + offset);You are not just fixing "debug messages formatting" here. You have made other changes to the structure of the code here. While these changes might all be correct, they don't belong in a commit that claims to fix message formatting.
For example, this
dev_dbg()statement in the pre-image prints "®" as the offset. This would be the address of the variable reg on the stack. This looks like it is a bug. The offset is stored in "reg", not in "®". The post-image fixes this bug. A person reading this diff might not look so closely at this because you only claim to change formatting. And some important discussion/context on this bug might be skipped over.Please re-word the commit subject and message to clearly explain why you are making these structural changes and separate them from the formatting changes (which also warrant an explanation on their own).
Quoted 10 lines
drivers/pinctrl/pinctrl-single.c +2
-1continue ; } - reg += pdata->base; + + reg = pdata->base + offset; val =fdt32_to_cpu (pins->val) & pdata->mask;switch (pdata->width) {case 16 :@@ -99,7 +101,7 @@ static int single_configure_pins(struct udevice *dev, pdata->width);
Quoted 9 lines
drivers/pinctrl/pinctrl-single.c static int single_configure_pins(struct udevice *dev, · line 104
Quoted 4 lines
drivers/pinctrl/pinctrl-single.c +1
-1continue ; } -dev_dbg (dev," reg/val 0x%pa/0x%08x\n" , ®, val); +dev_dbg (dev," reg/val %pa/0x%08x\n" , ®, val);In a similar fashion as above, shouldn't "®" be replaced with "reg"? I am not too familiar with the code to say for sure. Same for the changes below.
Also I would have expected reg instead of ® but at the link
https://www.kernel.org/doc/html/latest/core-api/printk-formats.html is explained:
...
"Phys_addr_t Physical Address Types"
%pa [p] 0x01234567 or 0x0123456789abcdef
For printing a phys_addr_t type (and its derivatives, such as resource_size_t) which can vary based on build options, regardless of the width of the CPU data path.
Passed by reference.
...
I also did some tests on the board:dev_dbg(dev, " reg/val %pa/0x%08x\n", ®, val); --> reg/val 0x44e10940/0x00000030dev_dbg(dev, " reg/val %p/0x%08x\n", reg, val); --> reg/val 44e10940/0x00000030
I'll continue to use the first one, which is documented.
Quoted 24 lines
Quoted 24 lines
drivers/pinctrl/pinctrl-single.c +7
-5}return 0 ; }@@ -111,15 +113,17 @@ static int single_configure_bits(struct udevice *dev,struct single_pdata *pdata =dev_get_plat (dev);int n, count = size /sizeof (struct single_fdt_bits_cfg );phys_addr_t reg; -u32 val, mask; +u32 offset, val, mask;for (n =0 ; n < count; n++, pins++) { - reg =fdt32_to_cpu (pins->reg); -if ((reg <0 ) || (reg > pdata->offset)) { -dev_dbg (dev," invalid register offset 0x%pa\n" , ®); + offset =fdt32_to_cpu (pins->reg); +if (offset <0 || offset > pdata->offset) { +dev_dbg (dev," invalid register offset 0x%x\n" , + offset);continue ; } - reg += pdata->base; + + reg = pdata->base + offset;
Quoted 19 lines
Quoted 14 lines
drivers/pinctrl/pinctrl-single.c +1
-1mask =fdt32_to_cpu (pins->mask); val =fdt32_to_cpu (pins->val) & mask;@@ -136,7 +140,7 @@ static int single_configure_bits(struct udevice *dev, pdata->width);continue ; } -dev_dbg (dev," reg/val 0x%pa/0x%08x\n" , ®, val); +dev_dbg (dev," reg/val %pa/0x%08x\n" , ®, val); }return 0 ; }Signature · 1 line
2.17.1Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments India
Regards,
Dario
PATCH 3/11 pinctrl: single: fix debug messages formatting
Quoted 87 lines · Dario Binacchi
Hi Pratyush,
Quoted 65 lines
Il 25/01/2021 18:09 Pratyush Yadav <[email protected]> ha scritto:
Hi Dario,
Quoted 3 lines · Dario Binacchi
The printf '%pa' format specifier appends the '0x' prefix to the displayed address. Furthermore, the offset variable is displayed with the '%x' format specifier instead of '%pa'.
I agree with Simon that the commit message does not explain why this change is needed.
Quoted 15 lines
Signed-off-by Dario Binacchi <[email protected]>---
drivers/pinctrl/pinctrl-single.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)drivers/pinctrl/pinctrl-single.c +0
-1@@ -77,15 +77,17 @@ static int single_configure_pins(struct udevice *dev,struct single_pdata *pdata =dev_get_plat (dev);int n, count = size /sizeof (struct single_fdt_pin_cfg );phys_addr_t reg; -u32 val;drivers/pinctrl/pinctrl-single.c static int single_configure_pins(struct udevice *dev, · line 86
Quoted 10 lines
drivers/pinctrl/pinctrl-single.c +5
-3+u32 offset, val;for (n =0 ; n < count; n++, pins++) { - reg =fdt32_to_cpu (pins->reg); -if ((reg <0 ) || (reg > pdata->offset)) { -dev_dbg (dev," invalid register offset 0x%pa\n" , ®); + offset =fdt32_to_cpu (pins->reg); +if (offset <0 || offset > pdata->offset) { +dev_dbg (dev," invalid register offset 0x%x\n" , + offset);You are not just fixing "debug messages formatting" here. You have made other changes to the structure of the code here. While these changes might all be correct, they don't belong in a commit that claims to fix message formatting.
For example, this
dev_dbg()statement in the pre-image prints "®" as the offset. This would be the address of the variable reg on the stack. This looks like it is a bug. The offset is stored in "reg", not in "®". The post-image fixes this bug. A person reading this diff might not look so closely at this because you only claim to change formatting. And some important discussion/context on this bug might be skipped over.Please re-word the commit subject and message to clearly explain why you are making these structural changes and separate them from the formatting changes (which also warrant an explanation on their own).
Quoted 10 lines
drivers/pinctrl/pinctrl-single.c +2
-1continue ; } - reg += pdata->base; + + reg = pdata->base + offset; val =fdt32_to_cpu (pins->val) & pdata->mask;switch (pdata->width) {case 16 :@@ -99,7 +101,7 @@ static int single_configure_pins(struct udevice *dev, pdata->width);Quoted 9 lines
drivers/pinctrl/pinctrl-single.c static int single_configure_pins(struct udevice *dev, · line 104
Quoted 4 lines
drivers/pinctrl/pinctrl-single.c +1
-1continue ; } -dev_dbg (dev," reg/val 0x%pa/0x%08x\n" , ®, val); +dev_dbg (dev," reg/val %pa/0x%08x\n" , ®, val);In a similar fashion as above, shouldn't "®" be replaced with "reg"? I am not too familiar with the code to say for sure. Same for the changes below.
Also I would have expected reg instead of ® but at the link
https://www.kernel.org/doc/html/latest/core-api/printk-formats.html is explained:
...
"Phys_addr_tPhysical Address Types"%pa [p]
0x01234567or0x0123456789abcdef
For printing aphys_addr_ttype (and its derivatives, such asresource_size_t) which can vary based on build options, regardless of the width of the CPU data path.
Quoted 8 lines
Passed by reference.
...I also did some tests on the board:
dev_dbg(dev, " reg/val %pa/0x%08x\n", ®, val); --> reg/val 0x44e10940/0x00000030dev_dbg(dev, " reg/val %p/0x%08x\n", reg, val); --> reg/val 44e10940/0x00000030I'll continue to use the first one, which is documented.
Makes sense. Thanks for the explanation.
My comments about commit message and splitting out changes still hold. If you think these changes should be in the same commit then please explain why in the commit message.
Quoted 46 lines
Quoted 24 lines
Quoted 24 lines
drivers/pinctrl/pinctrl-single.c +7
-5}return 0 ; }@@ -111,15 +113,17 @@ static int single_configure_bits(struct udevice *dev,struct single_pdata *pdata =dev_get_plat (dev);int n, count = size /sizeof (struct single_fdt_bits_cfg );phys_addr_t reg; -u32 val, mask; +u32 offset, val, mask;for (n =0 ; n < count; n++, pins++) { - reg =fdt32_to_cpu (pins->reg); -if ((reg <0 ) || (reg > pdata->offset)) { -dev_dbg (dev," invalid register offset 0x%pa\n" , ®); + offset =fdt32_to_cpu (pins->reg); +if (offset <0 || offset > pdata->offset) { +dev_dbg (dev," invalid register offset 0x%x\n" , + offset);continue ; } - reg += pdata->base; + + reg = pdata->base + offset;Quoted 19 lines
Quoted 14 lines
drivers/pinctrl/pinctrl-single.c +1
-1mask =fdt32_to_cpu (pins->mask); val =fdt32_to_cpu (pins->val) & mask;@@ -136,7 +140,7 @@ static int single_configure_bits(struct udevice *dev, pdata->width);continue ; } -dev_dbg (dev," reg/val 0x%pa/0x%08x\n" , ®, val); +dev_dbg (dev," reg/val %pa/0x%08x\n" , ®, val); }return 0 ; }Signature · 1 line
2.17.1Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments IndiaRegards,
Dario
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments India
PATCH 4/11 pinctrl: single: get register area size by device API
In reply to Dario BinacchiUse dev_read_addr_size to get size of the controller's register area.
---
drivers/pinctrl/pinctrl-single.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/pinctrl/pinctrl-single.c +3 -6
@@ -182,17 +182,14 @@ static int single_set_state(struct udevice *dev,static int single_of_to_plat (struct udevice *dev) {fdt_addr_t addr; -u32 of_reg[2 ]; -int res; +fdt_size_t size;struct single_pdata *pdata =dev_get_plat (dev); pdata->width =dev_read_u32_default (dev,"pinctrl-single,register-width" ,0 ); - res =dev_read_u32_array (dev,"reg" , of_reg,2 ); -if (res) -return res; - pdata->offset = of_reg[1 ] - pdata->width /8 ; +dev_read_addr_size (dev,"reg" , &size); + pdata->offset = size - pdata->width /BITS_PER_BYTE ; addr =dev_read_addr (dev);if (addr ==FDT_ADDR_T_NONE ) {
Signature · 1 line
2.17.1
PATCH 4/11 pinctrl: single: get register area size by device API
Hi Dario,
Quoted 20 lines · Dario Binacchi
Use
dev_read_addr_sizeto get size of the controller's register area.Signed-off-by Dario Binacchi <[email protected]>---
drivers/pinctrl/pinctrl-single.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)drivers/pinctrl/pinctrl-single.c +1
-2@@ -182,17 +182,14 @@ static int single_set_state(struct udevice *dev,static int single_of_to_plat (struct udevice *dev) {fdt_addr_t addr; -u32 of_reg[2 ]; -int res; +fdt_size_t size;
drivers/pinctrl/pinctrl-single.c static int single_set_state(struct udevice *dev, · line 191
Quoted 10 lines
drivers/pinctrl/pinctrl-single.c +1
-4struct single_pdata *pdata =dev_get_plat (dev); pdata->width =dev_read_u32_default (dev,"pinctrl-single,register-width" ,0 ); - res =dev_read_u32_array (dev,"reg" , of_reg,2 ); -if (res) -return res; - pdata->offset = of_reg[1 ] - pdata->width /8 ; +dev_read_addr_size (dev,"reg" , &size);
Please check return value.
Quoted 7 lines
drivers/pinctrl/pinctrl-single.c +1
-1+ pdata->offset = size - pdata->width /BITS_PER_BYTE ; addr =dev_read_addr (dev);if (addr ==FDT_ADDR_T_NONE ) { --2.17.1
Regards,
Simon
PATCH 5/11 pinctrl: single: check "register-width" DT property
In reply to Dario BinacchiIn more recent versions of the Linux kernel the driver's probe function returns an error if the "pinctrl-single,register-width" DT property is missing. The lack of this information, in fact, does not allow to know whether to access the registers of the controller at 8, 16 or 32 bits.
---
drivers/pinctrl/pinctrl-single.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/pinctrl/pinctrl-single.c +7 -3
@@ -22,7 +22,7 @@ struct single_pdata {fdt_addr_t base;int offset;u32 mask; -int width; +u32 width;bool bits_per_mux; };
@@ -184,9 +184,13 @@ static int single_of_to_plat(struct udevice *dev)fdt_addr_t addr;fdt_size_t size;struct single_pdata *pdata =dev_get_plat (dev); +int ret; - pdata->width = -dev_read_u32_default (dev,"pinctrl-single,register-width" ,0 ); + ret =dev_read_u32 (dev,"pinctrl-single,register-width" , &pdata->width); +if (ret) { +dev_err (dev,"missing register width\n" ); +return ret; + }dev_read_addr_size (dev,"reg" , &size); pdata->offset = size - pdata->width /BITS_PER_BYTE ;
Signature · 1 line
2.17.1
PATCH 5/11 pinctrl: single: check "register-width" DT property
Hi Dario,
Quoted 5 lines · Dario Binacchi
In more recent versions of the Linux kernel the driver's probe function returns an error if the "pinctrl-single,register-width" DT property is missing. The lack of this information, in fact, does not allow to know whether to access the registers of the controller at 8, 16 or 32 bits.
"Update it to ..."
Quoted 7 lines
Signed-off-by Dario Binacchi <[email protected]>---
drivers/pinctrl/pinctrl-single.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
Consider updating the pinctrl tests for this.
PATCH 6/11 pinctrl: single: change function mask default value
In reply to Dario BinacchiThe patch is inspired by more recent versions of the Linux driver. Replacing the default value 0xffffffff of the function mask with 0 is certainly more conservative in case the "pinctrl-single,function-mask" DT property is missing.
---
drivers/pinctrl/pinctrl-single.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/pinctrl/pinctrl-single.c +10 -2
@@ -79,6 +79,10 @@ static int single_configure_pins(struct udevice *dev,phys_addr_t reg;u32 offset, val; +/* If function mask is null, needn't enable it. */ +if (!pdata->mask) +return 0 ; +for (n =0 ; n < count; n++, pins++) { offset =fdt32_to_cpu (pins->reg);if (offset <0 || offset > pdata->offset) {
@@ -202,8 +206,12 @@ static int single_of_to_plat(struct udevice *dev) } pdata->base = addr; - pdata->mask =dev_read_u32_default (dev,"pinctrl-single,function-mask" , -0xffffffff ); + ret =dev_read_u32 (dev,"pinctrl-single,function-mask" , &pdata->mask); +if (ret) { + pdata->mask =0 ; +dev_warn (dev,"missing function register mask\n" ); + } + pdata->bits_per_mux =dev_read_bool (dev,"pinctrl-single,bit-per-mux" );return 0 ;
Signature · 1 line
2.17.1
PATCH 7/11 pinctrl: single: use function pointer for register access
In reply to Dario BinacchiThe patch allows you to call the read/write functions set during probing without having to check the type of access at runtime. It also adds functions for 8-bit registers access.
---
drivers/pinctrl/pinctrl-single.c | 98 ++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 25 deletions(-)
drivers/pinctrl/pinctrl-single.c +73 -25
@@ -26,6 +26,16 @@ struct single_pdata {bool bits_per_mux; }; +/** +* struct single_priv - private data +* @read: function to read from a configuration register +* @write: function to write to a configuration register +*/ +struct single_priv { +unsigned int (*read)(fdt_addr_t reg); +void (*write)(unsigned int val,fdt_addr_t reg); +}; +/** * struct single_fdt_pin_cfg - pin configuration *
@@ -56,6 +66,36 @@ struct single_fdt_bits_cfg {fdt32_t mask; }; +static unsigned int single_readb (fdt_addr_t reg) +{ +return readb (reg); +} + +static unsigned int single_readw (fdt_addr_t reg) +{ +return readw (reg); +} + +static unsigned int single_readl (fdt_addr_t reg) +{ +return readl (reg); +} + +static void single_writeb (unsigned int val,fdt_addr_t reg) +{ +writeb (val, reg); +} + +static void single_writew (unsigned int val,fdt_addr_t reg) +{ +writew (val, reg); +} + +static void single_writel (unsigned int val,fdt_addr_t reg) +{ +writel (val, reg); +} +/** * single_configure_pins() - Configure pins based on FDT data *
@@ -75,6 +115,7 @@ static int single_configure_pins(struct udevice *dev, int size) {struct single_pdata *pdata =dev_get_plat (dev); +struct single_priv *priv =dev_get_priv (dev);int n, count = size /sizeof (struct single_fdt_pin_cfg );phys_addr_t reg;u32 offset, val;
@@ -93,19 +134,9 @@ static int single_configure_pins(struct udevice *dev, reg = pdata->base + offset; val =fdt32_to_cpu (pins->val) & pdata->mask; -switch (pdata->width) { -case 16 : -writew ((readw (reg) & ~pdata->mask) | val, reg); -break ; -case 32 : -writel ((readl (reg) & ~pdata->mask) | val, reg); -break ; -default : -dev_warn (dev,"unsupported register width %i\n" , - pdata->width); -continue ; - } + priv->write ((priv->read (reg) & ~pdata->mask) | val, reg);dev_dbg (dev," reg/val %pa/0x%08x\n" , ®, val); + }return 0 ; }
@@ -115,6 +146,7 @@ static int single_configure_bits(struct udevice *dev, int size) {struct single_pdata *pdata =dev_get_plat (dev); +struct single_priv *priv =dev_get_priv (dev);int n, count = size /sizeof (struct single_fdt_bits_cfg );phys_addr_t reg;u32 offset, val, mask;
@@ -131,19 +163,7 @@ static int single_configure_bits(struct udevice *dev, mask =fdt32_to_cpu (pins->mask); val =fdt32_to_cpu (pins->val) & mask; - -switch (pdata->width) { -case 16 : -writew ((readw (reg) & ~mask) | val, reg); -break ; -case 32 : -writel ((readl (reg) & ~mask) | val, reg); -break ; -default : -dev_warn (dev,"unsupported register width %i\n" , - pdata->width); -continue ; - } + priv->write ((priv->read (reg) & ~mask) | val, reg);dev_dbg (dev," reg/val %pa/0x%08x\n" , ®, val); }return 0 ;
@@ -183,6 +203,32 @@ static int single_set_state(struct udevice *dev,return len; } +static int single_probe (struct udevice *dev) +{ +struct single_pdata *pdata =dev_get_plat (dev); +struct single_priv *priv =dev_get_priv (dev); + +switch (pdata->width) { +case 8 : + priv->read = single_readb; + priv->write = single_writeb; +break ; +case 16 : + priv->read = single_readw; + priv->write = single_writew; +break ; +case 32 : + priv->read = single_readl; + priv->write = single_writel; +break ; +default : +dev_err (dev,"wrong register width\n" ); +return -EINVAL ; + } + +return 0 ; +} +static int single_of_to_plat (struct udevice *dev) {fdt_addr_t addr;
@@ -232,5 +278,7 @@ U_BOOT_DRIVER(single_pinctrl) = { .of_match = single_pinctrl_match, .ops = &single_pinctrl_ops, .plat_auto = sizeof(struct single_pdata), + .priv_auto = sizeof(struct single_priv), .of_to_plat = single_of_to_plat, + .probe = single_probe, };
Signature · 1 line
2.17.1
PATCH 7/11 pinctrl: single: use function pointer for register access
Hi Dario,
Quoted 10 lines · Dario Binacchi
The patch allows you to call the read/write functions set during probing without having to check the type of access at runtime. It also adds functions for 8-bit registers access.
Signed-off-by Dario Binacchi <[email protected]>---
drivers/pinctrl/pinctrl-single.c | 98 ++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 25 deletions(-)
I'm not really keen on this. A switch() statement is not expensive and function pointers add indirection/confusion and use more space.
Regards,
Simon
PATCH 7/11 pinctrl: single: use function pointer for register access
Hi Simon,
Quoted 11 lines
Il 24/01/2021 03:03 Simon Glass <[email protected]> ha scritto:
Hi Dario,
Quoted 5 lines · Dario Binacchi
The patch allows you to call the read/write functions set during probing without having to check the type of access at runtime. It also adds functions for 8-bit registers access.
Quoted 8 lines
Quoted 5 lines
Signed-off-by Dario Binacchi <[email protected]>---
drivers/pinctrl/pinctrl-single.c | 98 ++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 25 deletions(-)I'm not really keen on this. A
switch()statement is not expensive and function pointers add indirection/confusion and use more space.
I think however it is better to create two static functions for reading/writing operations (with a switch() statement inside). So as not to replicate the code. Do you agree?
Regards,
Dario
Quoted 3 lines
Regards,
Simon
PATCH 7/11 pinctrl: single: use function pointer for register access
Hi Dario,
Quoted 21 lines · Dario Binacchi
Hi Simon,
Quoted 17 lines
Il 24/01/2021 03:03 Simon Glass <[email protected]> ha scritto:
Hi Dario,
Quoted 10 lines · Dario Binacchi
The patch allows you to call the read/write functions set during probing without having to check the type of access at runtime. It also adds functions for 8-bit registers access.
Signed-off-by Dario Binacchi <[email protected]>---
drivers/pinctrl/pinctrl-single.c | 98 ++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 25 deletions(-)
Quoted 6 lines
Quoted 2 lines
I'm not really keen on this. A
switch()statement is not expensive and function pointers add indirection/confusion and use more space.I think however it is better to create two static functions for reading/writing operations (with a
switch()statement inside). So as not to replicate the code. Do you agree?
Yes that sounds good to me.
Regards,
Simon
PATCH 8/11 pinctrl: single: add get_pins_count operation
In reply to Dario BinacchiIt returns the number of selectable pins.
---
drivers/pinctrl/pinctrl-single.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/pinctrl/pinctrl-single.c +22 -0
@@ -28,10 +28,14 @@ struct single_pdata {/** * struct single_priv - private data +* @bits_per_pin: number of bits per pin +* @npins: number of selectable pins * @read: function to read from a configuration register * @write: function to write to a configuration register */ struct single_priv { +unsigned int bits_per_pin; +unsigned int npins;unsigned int (*read)(fdt_addr_t reg);void (*write)(unsigned int val,fdt_addr_t reg); };
@@ -203,10 +207,27 @@ static int single_set_state(struct udevice *dev,return len; } +static int single_get_pins_count (struct udevice *dev) +{ +struct single_priv *priv =dev_get_priv (dev); + +return priv->npins; +} +static int single_probe (struct udevice *dev) {struct single_pdata *pdata =dev_get_plat (dev);struct single_priv *priv =dev_get_priv (dev); +u32 size; + + size = pdata->offset + pdata->width /BITS_PER_BYTE ; + priv->npins = size / (pdata->width /BITS_PER_BYTE ); +if (pdata->bits_per_mux) { + priv->bits_per_pin =fls (pdata->mask); + priv->npins *= (pdata->width / priv->bits_per_pin); + } + +dev_dbg (dev,"%d pins\n" , priv->npins);switch (pdata->width) {case 8 :
@@ -264,6 +285,7 @@ static int single_of_to_plat(struct udevice *dev) }const struct pinctrl_ops single_pinctrl_ops = { + .get_pins_count = single_get_pins_count, .set_state = single_set_state, };
Signature · 1 line
2.17.1
PATCH 8/11 pinctrl: single: add get_pins_count operation
Quoted 9 lines · Dario Binacchi
It returns the number of selectable pins.
Signed-off-by Dario Binacchi <[email protected]>---
drivers/pinctrl/pinctrl-single.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
PATCH 9/11 pinctrl: single: add get_pin_name operation
In reply to Dario BinacchiIt returns the name of the requested pin.
---
drivers/pinctrl/pinctrl-single.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/pinctrl/pinctrl-single.c +16 -0
@@ -30,12 +30,14 @@ struct single_pdata {* struct single_priv - private data * @bits_per_pin: number of bits per pin * @npins: number of selectable pins +* @pin_name: temporary buffer to store the pin name * @read: function to read from a configuration register * @write: function to write to a configuration register */ struct single_priv {unsigned int bits_per_pin;unsigned int npins; +char pin_name[PINNAME_SIZE ];unsigned int (*read)(fdt_addr_t reg);void (*write)(unsigned int val,fdt_addr_t reg); };
@@ -207,6 +209,19 @@ static int single_set_state(struct udevice *dev,return len; } +static const char *single_get_pin_name (struct udevice *dev, +unsigned int selector) +{ +struct single_priv *priv =dev_get_priv (dev); + +if (selector >= priv->npins) +snprintf (priv->pin_name,PINNAME_SIZE ,"Error" ); +else +snprintf (priv->pin_name,PINNAME_SIZE ,"PIN%u" , selector); + +return priv->pin_name; +} +static int single_get_pins_count (struct udevice *dev) {struct single_priv *priv =dev_get_priv (dev);
@@ -286,6 +301,7 @@ static int single_of_to_plat(struct udevice *dev)const struct pinctrl_ops single_pinctrl_ops = { .get_pins_count = single_get_pins_count, + .get_pin_name = single_get_pin_name, .set_state = single_set_state, };
Signature · 1 line
2.17.1
PATCH 9/11 pinctrl: single: add get_pin_name operation
Quoted 9 lines · Dario Binacchi
It returns the name of the requested pin.
Signed-off-by Dario Binacchi <[email protected]>---
drivers/pinctrl/pinctrl-single.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
PATCH 10/11 pinctrl: single: add get_pin_muxing operation
In reply to Dario BinacchiIt allows to display the muxing of a given pin. Inspired by more recent versions of the Linux driver, in addition to the address and the value of the configuration register I added the pin function retrieved from the DT. In doing so, the information displayed does not depend on the platform, being a generic type driver, and it can be useful for debug purposes.
---
drivers/pinctrl/pinctrl-single.c | 220 +++++++++++++++++++++++++++++-- 1 file changed, 211 insertions(+), 9 deletions(-)
drivers/pinctrl/pinctrl-single.c +211 -9
@@ -1,14 +1,18 @@// SPDX-License-Identifier: GPL-2.0+ /* * Copyright (C) EETS GmbH, 2017, Felix Brack <[email protected]> +* Copyright (C) 2021 Dario Binacchi <[email protected]> */ #include <common.h> #include <dm.h> #include <dm/device_compat.h> +#include <dm/devres.h> #include <dm/pinctrl.h> #include <linux/libfdt.h> +#include <linux/list.h> #include <asm/io.h> +#include <sort.h> /** * struct single_pdata - platform data
@@ -26,6 +30,20 @@ struct single_pdata {bool bits_per_mux; }; +/** +* struct single_func - pinctrl function +* @node: list node +* @name: pinctrl function name +* @npins: number of entries in pins array +* @pins: pins array +*/ +struct single_func { +struct list_head node; +const char *name; +unsigned int npins; +unsigned int *pins; +}; +/** * struct single_priv - private data * @bits_per_pin: number of bits per pin
@@ -38,6 +56,7 @@ struct single_priv {unsigned int bits_per_pin;unsigned int npins;char pin_name[PINNAME_SIZE ]; +struct list_head functions;unsigned int (*read)(fdt_addr_t reg);void (*write)(unsigned int val,fdt_addr_t reg); };
@@ -102,6 +121,121 @@ static void single_writel(unsigned int val, fdt_addr_t reg)writel (val, reg); } +/** +* single_get_pin_by_offset() - get a pin based on the register offset +* @dev: single driver instance +* @offset: register offset from the base +*/ +static int single_get_pin_by_offset (struct udevice *dev,unsigned int offset) +{ +struct single_pdata *pdata =dev_get_plat (dev); +struct single_priv *priv =dev_get_priv (dev); + +if (offset > pdata->offset) { +dev_err (dev,"mux offset out of range: 0x%x (0x%x)\n" , + offset, pdata->offset); +return -EINVAL ; + } + +if (pdata->bits_per_mux) +return (offset *BITS_PER_BYTE ) / priv->bits_per_pin; + +return offset / (pdata->width /BITS_PER_BYTE ); +} + +static int single_get_offset_by_pin (struct udevice *dev,unsigned int pin) +{ +struct single_pdata *pdata =dev_get_plat (dev); +struct single_priv *priv =dev_get_priv (dev); +unsigned int mux_bytes; + +if (pin >= priv->npins) +return -EINVAL ; + + mux_bytes = pdata->width /BITS_PER_BYTE ; +if (pdata->bits_per_mux) { +int byte_num; + + byte_num = (priv->bits_per_pin * pin) /BITS_PER_BYTE ; +return (byte_num / mux_bytes) * mux_bytes; + } + +return pin * mux_bytes; +} + +static const char *single_get_pin_function (struct udevice *dev, +unsigned int pin) +{ +struct single_priv *priv =dev_get_priv (dev); +struct single_func *func; +int i; + +list_for_each_entry (func, &priv->functions, node) { +for (i =0 ; i < func->npins; i++) { +if (pin == func->pins[i]) +return func->name; + +if (pin < func->pins[i]) +break ; + } + } + +return NULL ; +} + +static int single_get_pin_muxing (struct udevice *dev,unsigned int pin, +char *buf,int size) +{ +struct single_pdata *pdata =dev_get_plat (dev); +struct single_priv *priv =dev_get_priv (dev); +fdt_addr_t reg; +const char *fname; +unsigned int val; +int offset, pin_shift =0 ; + + offset =single_get_offset_by_pin (dev, pin); +if (offset <0 ) +return offset; + + reg = pdata->base + offset; + val = priv->read (reg); + +if (pdata->bits_per_mux) + pin_shift = pin % (pdata->width / priv->bits_per_pin) * + priv->bits_per_pin; + + val &= (pdata->mask << pin_shift); + fname =single_get_pin_function (dev, pin); +snprintf (buf, size,"%pa 0x%08x %s" , ®, val, + fname ? fname :"UNCLAIMED" ); +return 0 ; +} + +static struct single_func *single_allocate_function (struct udevice *dev, +unsigned int group_pins) +{ +struct single_func *func; + + func =devm_kmalloc (dev,sizeof (*func),GFP_KERNEL ); +if (!func) +return ERR_PTR (-ENOMEM ); + + func->pins =devm_kmalloc (dev,sizeof (unsigned int ) * group_pins, +GFP_KERNEL ); +if (!func->pins) +return ERR_PTR (-ENOMEM ); + +return func; +} + +static int single_pin_compare (const void *s1,const void *s2) +{ +int pin1 = *(const unsigned int *)s1; +int pin2 = *(const unsigned int *)s2; + +return pin1 - pin2; +} +/** * single_configure_pins() - Configure pins based on FDT data *
@@ -115,14 +249,16 @@ static void single_writel(unsigned int val, fdt_addr_t reg)* @size: Size of the 'pins' array in bytes. * The number of register/value pairs in the 'pins' array therefore * equals to 'size / sizeof(struct single_fdt_pin_cfg)'. +* @fname: Function name. */ static int single_configure_pins (struct udevice *dev,const struct single_fdt_pin_cfg *pins, -int size) +int size,const char *fname) {struct single_pdata *pdata =dev_get_plat (dev);struct single_priv *priv =dev_get_priv (dev); -int n, count = size /sizeof (struct single_fdt_pin_cfg ); +int n, pin, count = size /sizeof (struct single_fdt_pin_cfg ); +struct single_func *func;phys_addr_t reg;u32 offset, val;
@@ -130,33 +266,60 @@ static int single_configure_pins(struct udevice *dev,if (!pdata->mask)return 0 ; + func =single_allocate_function (dev, count); +if (IS_ERR (func)) +return PTR_ERR (func); + + func->name = fname; + func->npins =0 ;for (n =0 ; n < count; n++, pins++) { offset =fdt32_to_cpu (pins->reg);if (offset <0 || offset > pdata->offset) { -dev_dbg (dev," invalid register offset 0x%x\n" , +dev_err (dev," invalid register offset 0x%x\n" , offset);continue ; } reg = pdata->base + offset; val =fdt32_to_cpu (pins->val) & pdata->mask; + pin =single_get_pin_by_offset (dev, offset); +if (pin <0 ) { +dev_err (dev," failed to get pin by offset %x\n" , + offset); +continue ; + } + priv->write ((priv->read (reg) & ~pdata->mask) | val, reg);dev_dbg (dev," reg/val %pa/0x%08x\n" , ®, val); - + func->pins[func->npins] = pin; + func->npins++; } + +qsort (func->pins, func->npins,sizeof (func->pins[0 ]), + single_pin_compare); +list_add (&func->node, &priv->functions);return 0 ; }static int single_configure_bits (struct udevice *dev,const struct single_fdt_bits_cfg *pins, -int size) +int size,const char *fname) {struct single_pdata *pdata =dev_get_plat (dev);struct single_priv *priv =dev_get_priv (dev); -int n, count = size /sizeof (struct single_fdt_bits_cfg ); +int n, pin, count = size /sizeof (struct single_fdt_bits_cfg ); +int npins_in_reg, pin_num_from_lsb; +struct single_func *func;phys_addr_t reg; -u32 offset, val, mask; +u32 offset, val, mask, bit_pos, val_pos, mask_pos, submask; + npins_in_reg = pdata->width / priv->bits_per_pin; + func =single_allocate_function (dev, count * npins_in_reg); +if (IS_ERR (func)) +return PTR_ERR (func); + + func->name = fname; + func->npins =0 ;for (n =0 ; n < count; n++, pins++) { offset =fdt32_to_cpu (pins->reg);if (offset <0 || offset > pdata->offset) {
@@ -167,11 +330,47 @@ static int single_configure_bits(struct udevice *dev, reg = pdata->base + offset; + pin =single_get_pin_by_offset (dev, offset); +if (pin <0 ) { +dev_err (dev," failed to get pin by offset 0x%pa\n" , + ®); +continue ; + } + mask =fdt32_to_cpu (pins->mask); val =fdt32_to_cpu (pins->val) & mask; priv->write ((priv->read (reg) & ~mask) | val, reg);dev_dbg (dev," reg/val %pa/0x%08x\n" , ®, val); + +while (mask) { + bit_pos =__ffs (mask); + pin_num_from_lsb = bit_pos / priv->bits_per_pin; + mask_pos = pdata->mask << bit_pos; + val_pos = val & mask_pos; + submask = mask & mask_pos; + +if ((mask & mask_pos) ==0 ) { +dev_err (dev,"Invalid mask at 0x%x\n" , offset); +break ; + } + + mask &= ~mask_pos; + +if (submask != mask_pos) { +dev_warn (dev, +"Invalid submask 0x%x@0x%x\n" , + submask, offset); +continue ; + } + + func->pins[func->npins] = pin + pin_num_from_lsb; + func->npins++; + } } + +qsort (func->pins, func->npins,sizeof (func->pins[0 ]), + single_pin_compare); +list_add (&func->node, &priv->functions);return 0 ; } static int single_set_state(struct udevice *dev,
@@ -189,7 +388,7 @@ static int single_set_state(struct udevice *dev,dev_dbg (dev," invalid pin configuration in fdt\n" );return -FDT_ERR_BADSTRUCTURE ; } -single_configure_pins (dev, prop, len); +single_configure_pins (dev, prop, len, config->name);return 0 ; }
@@ -201,7 +400,7 @@ static int single_set_state(struct udevice *dev,dev_dbg (dev," invalid bits configuration in fdt\n" );return -FDT_ERR_BADSTRUCTURE ; } -single_configure_bits (dev, prop_bits, len); +single_configure_bits (dev, prop_bits, len, config->name);return 0 ; }
@@ -235,6 +434,8 @@ static int single_probe(struct udevice *dev)struct single_priv *priv =dev_get_priv (dev);u32 size; +INIT_LIST_HEAD (&priv->functions); + size = pdata->offset + pdata->width /BITS_PER_BYTE ; priv->npins = size / (pdata->width /BITS_PER_BYTE );if (pdata->bits_per_mux) {
@@ -303,6 +504,7 @@ const struct pinctrl_ops single_pinctrl_ops = { .get_pins_count = single_get_pins_count, .get_pin_name = single_get_pin_name, .set_state = single_set_state, + .get_pin_muxing = single_get_pin_muxing, };static const struct udevice_id single_pinctrl_match[] = {
Signature · 1 line
2.17.1
PATCH 10/11 pinctrl: single: add get_pin_muxing operation
Hi Dario,
Quoted 8 lines · Dario Binacchi
It allows to display the muxing of a given pin. Inspired by more recent versions of the Linux driver, in addition to the address and the value of the configuration register I added the pin function retrieved from the DT. In doing so, the information displayed does not depend on the platform, being a generic type driver, and it can be useful for debug purposes.
Quoted 5 lines
Signed-off-by Dario Binacchi <[email protected]>---
drivers/pinctrl/pinctrl-single.c | 220 +++++++++++++++++++++++++++++-- 1 file changed, 211 insertions(+), 9 deletions(-)
Do we need an updated DT binding file?
Regards,
Simon
PATCH 10/11 pinctrl: single: add get_pin_muxing operation
Hi Simon,
Quoted 14 lines
Il 24/01/2021 03:03 Simon Glass <[email protected]> ha scritto:
Hi Dario,
Quoted 8 lines · Dario Binacchi
It allows to display the muxing of a given pin. Inspired by more recent versions of the Linux driver, in addition to the address and the value of the configuration register I added the pin function retrieved from the DT. In doing so, the information displayed does not depend on the platform, being a generic type driver, and it can be useful for debug purposes.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Dario Binacchi <[email protected]>---
drivers/pinctrl/pinctrl-single.c | 220 +++++++++++++++++++++++++++++-- 1 file changed, 211 insertions(+), 9 deletions(-)Do we need an updated DT binding file?
I would say no, the am335x DT has recently been resynced with one of the latest versions of the Linux kernel.
Quoted 3 lines
Regards,
Simon
Regards
Dario
PATCH 10/11 pinctrl: single: add get_pin_muxing operation
Quoted 20 lines · Dario Binacchi
Hi Simon,
Quoted 17 lines
Il 24/01/2021 03:03 Simon Glass <[email protected]> ha scritto:
Hi Dario,
Quoted 11 lines · Dario Binacchi
It allows to display the muxing of a given pin. Inspired by more recent versions of the Linux driver, in addition to the address and the value of the configuration register I added the pin function retrieved from the DT. In doing so, the information displayed does not depend on the platform, being a generic type driver, and it can be useful for debug purposes.
Signed-off-by Dario Binacchi <[email protected]>---
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
drivers/pinctrl/pinctrl-single.c | 220 +++++++++++++++++++++++++++++-- 1 file changed, 211 insertions(+), 9 deletions(-)Do we need an updated DT binding file?
I would say no, the am335x DT has recently been resynced with one of the latest versions of the Linux kernel.
PATCH 11/11 test: pinmux: add test for 'pinctrl-single' driver
In reply to Dario BinacchiThe test adds two pinmux nodes to the device tree, one to test when a register changes only one pin's mux (pinctrl-single,pins), and the other to test when more than one pin's mux is changed (pinctrl-single,bits). This required replacing the controller's register access functions when the driver is used on sandbox.
---
arch/sandbox/dts/test.dts | 65 +++++++++++++++++++++++++ configs/sandbox_defconfig | 1 + drivers/pinctrl/pinctrl-single.c | 62 +++++++++++++++++++----- test/dm/pinmux.c | 81 ++++++++++++++++++++++++++++++-- 4 files changed, 193 insertions(+), 16 deletions(-)
arch/sandbox/dts/test.dts +65 -0
@@ -513,6 +513,9 @@ reg = <0 1>; compatible = "sandbox,i2c"; clock-frequency = <100000>; + pinctrl-names = "default"; + pinctrl-0 = <&pinmux_i2c0_pins>; + eeprom at 2c { reg = <0x2c>; compatible = "i2c-eeprom";
@@ -592,6 +595,8 @@ lcd { u-boot,dm-pre-reloc; compatible = "sandbox,lcd-sdl"; + pinctrl-names = "default"; + pinctrl-0 = <&pinmux_lcd_pins>; xres = <1366>; yres = <768>; };
@@ -842,6 +847,8 @@ pwm: pwm { compatible = "sandbox,pwm"; #pwm-cells = <2>; + pinctrl-names = "default"; + pinctrl-0 = <&pinmux_pwm_pins>; }; pwm2 {
@@ -913,6 +920,9 @@ reg = <0 1>; compatible = "sandbox,spi"; cs-gpios = <0>, <0>, <&gpio_a 0>; + pinctrl-names = "default"; + pinctrl-0 = <&pinmux_spi0_pins>; + spi.bin at 0 { reg = <0>; compatible = "spansion,m25p16", "jedec,spi-nor";
@@ -1002,6 +1012,8 @@ uart0: serial { compatible = "sandbox,serial"; u-boot,dm-pre-reloc; + pinctrl-names = "default"; + pinctrl-0 = <&pinmux_uart0_pins>; }; usb_0: usb at 0 {
@@ -1268,6 +1280,59 @@ }; }; + pinctrl-single-pins { + compatible = "pinctrl-single"; + reg = <0x0000 0x238>; + #pinctrl-cells = <1>; + pinctrl-single,register-width = <32>; + pinctrl-single,function-mask = <0x7f>; + + pinmux_pwm_pins: pinmux_pwm_pins { + pinctrl-single,pins = < 0x48 0x06 >; + }; + + pinmux_spi0_pins: pinmux_spi0_pins { + pinctrl-single,pins = < + 0x190 0x0c + 0x194 0x0c + 0x198 0x23 + 0x19c 0x0c + >; + }; + + pinmux_uart0_pins: pinmux_uart0_pins { + pinctrl-single,pins = < + 0x70 0x30 + 0x74 0x00 + >; + }; + }; + + pinctrl-single-bits { + compatible = "pinctrl-single"; + reg = <0x0000 0x50>; + #pinctrl-cells = <2>; + pinctrl-single,bit-per-mux; + pinctrl-single,register-width = <32>; + pinctrl-single,function-mask = <0xf>; + + pinmux_i2c0_pins: pinmux_i2c0_pins { + pinctrl-single,bits = < + 0x10 0x00002200 0x0000ff00 + >; + }; + + pinmux_lcd_pins: pinmux_lcd_pins { + pinctrl-single,bits = < + 0x40 0x22222200 0xffffff00 + 0x44 0x22222222 0xffffffff + 0x48 0x00000022 0x000000ff + 0x48 0x02000000 0x0f000000 + 0x4c 0x02000022 0x0f0000ff + >; + }; + }; + hwspinlock at 0 { compatible = "sandbox,hwspinlock"; };
configs/sandbox_defconfig +1 -0
@@ -193,6 +193,7 @@ CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=y CONFIG_PINCONF=y CONFIG_PINCTRL_SANDBOX=y +CONFIG_PINCTRL_SINGLE=y CONFIG_POWER_DOMAIN=y CONFIG_SANDBOX_POWER_DOMAIN=y CONFIG_DM_PMIC=y
drivers/pinctrl/pinctrl-single.c +51 -11
126 lines not on this page · raw message
test/dm/pinmux.c +76 -5
95 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 11/11 test: pinmux: add test for 'pinctrl-single' driver
Quoted 9 lines · Dario Binacchi
The test adds two pinmux nodes to the device tree, one to test when a register changes only one pin's mux (pinctrl-single,pins), and the other to test when more than one pin's mux is changed (pinctrl-single,bits). This required replacing the controller's register access functions when the driver is used on sandbox.
Signed-off-by Dario Binacchi <[email protected]>
Quoted 7 lines
---
arch/sandbox/dts/test.dts | 65 +++++++++++++++++++++++++ configs/sandbox_defconfig | 1 + drivers/pinctrl/pinctrl-single.c | 62 +++++++++++++++++++----- test/dm/pinmux.c | 81 ++++++++++++++++++++++++++++++-- 4 files changed, 193 insertions(+), 16 deletions(-)