Fix pinctrl-single pcs_pin_dbg_show()
Subsystems (3)
v2 cover Fix pinctrl-single pcs_pin_dbg_show()
These patches fix the pcs_pin_dbg_show() function for the scenario where a single register controls multiple pins (i.e. bits_per_mux != 0). Additionally, the common formula is moved to a separate function to allow reuse.
Changes since v1:
-----------------
- remove unused variable in In function 'pcs_allocate_pin_table' (Reported-by: kernel test robot <[email protected]>)
Hanna Hawa (3):
pinctrl: pinctrl-single: remove unused variable
pinctrl: pinctrl-single: remove unused parameter
pinctrl: pinctrl-single: fix pcs_pin_dbg_show() when bits_per_mux != 0
drivers/pinctrl/pinctrl-single.c | 76 ++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 29 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/3 pinctrl: pinctrl-single: remove unused variable
Remove unused parameter 'num_pins_in_register' from pcs_allocate_pin_table().
--- drivers/pinctrl/pinctrl-single.c | 2 -- 1 file changed, 2 deletions(-)
drivers/pinctrl/pinctrl-single.c +0 -2
@@ -703,14 +703,12 @@ static int pcs_add_pin(struct pcs_device *pcs, unsigned offset,static int pcs_allocate_pin_table (struct pcs_device *pcs) {int mux_bytes, nr_pins, i; -int num_pins_in_register =0 ; mux_bytes = pcs->width /BITS_PER_BYTE ;if (pcs->bits_per_mux) { pcs->bits_per_pin =fls (pcs->fmask); nr_pins = (pcs->size *BITS_PER_BYTE ) / pcs->bits_per_pin; - num_pins_in_register = pcs->width / pcs->bits_per_pin; }else { nr_pins = pcs->size / mux_bytes; }
Signature · 1 line
2.17.1
PATCH v2 2/3 pinctrl: pinctrl-single: remove unused parameter
In reply to Hanna HawaRemove unused parameter 'pin_pos' from pcs_add_pin().
--- drivers/pinctrl/pinctrl-single.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/pinctrl/pinctrl-single.c +2 -6
@@ -656,10 +656,8 @@ static const struct pinconf_ops pcs_pinconf_ops = {* pcs_add_pin() - add a pin to the static per controller pin array * @pcs: pcs driver instance * @offset: register offset from base -* @pin_pos: unused */ -static int pcs_add_pin (struct pcs_device *pcs,unsigned offset, -unsigned pin_pos) +static int pcs_add_pin (struct pcs_device *pcs,unsigned int offset) {struct pcs_soc_data *pcs_soc = &pcs->socdata;struct pinctrl_pin_desc *pin;
@@ -727,16 +725,14 @@ static int pcs_allocate_pin_table(struct pcs_device *pcs)unsigned offset;int res;int byte_num; -int pin_pos =0 ;if (pcs->bits_per_mux) { byte_num = (pcs->bits_per_pin * i) /BITS_PER_BYTE ; offset = (byte_num / mux_bytes) * mux_bytes; - pin_pos = i % num_pins_in_register; }else { offset = i * mux_bytes; } - res =pcs_add_pin (pcs, offset, pin_pos); + res =pcs_add_pin (pcs, offset);if (res <0 ) {dev_err (pcs->dev,"error adding pins: %i\n" , res);return res;
Signature · 1 line
2.17.1
PATCH v2 3/3 pinctrl: pinctrl-single: fix pcs_pin_dbg_show() when bits_per_mux != 0
In reply to Hanna HawaAn SError was detected when trying to print the supported pins in a pinctrl device which supports multiple pins per register. This change fixes the pcs_pin_dbg_show() in pinctrl-single driver when bits_per_mux != 0. In addition move offset calculation and pin offset in register to common function.
--- drivers/pinctrl/pinctrl-single.c | 66 ++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 21 deletions(-)
drivers/pinctrl/pinctrl-single.c +45 -21
@@ -270,20 +270,53 @@ static void __maybe_unused pcs_writel(unsigned val, void __iomem *reg)writel (val, reg); } +static unsigned int pcs_pin_reg_offset_get (struct pcs_device *pcs, +unsigned int pin) +{ +unsigned int offset, mux_bytes; + + mux_bytes = pcs->width /BITS_PER_BYTE ; + +if (pcs->bits_per_mux) { +unsigned int pin_offset_bytes; + + pin_offset_bytes = (pcs->bits_per_pin * pin) /BITS_PER_BYTE ; + offset = (pin_offset_bytes / mux_bytes) * mux_bytes; + }else { + offset = pin * mux_bytes; + } + +return offset; +} + +static unsigned int pcs_pin_shift_reg_get (struct pcs_device *pcs, +unsigned int pin) +{ +return ((pin % (pcs->width / pcs->bits_per_pin)) * pcs->bits_per_pin); +} +static void pcs_pin_dbg_show (struct pinctrl_dev *pctldev,struct seq_file *s,unsigned pin) {struct pcs_device *pcs; -unsigned val, mux_bytes; +unsigned int val;unsigned long offset;size_t pa; pcs =pinctrl_dev_get_drvdata (pctldev); - mux_bytes = pcs->width /BITS_PER_BYTE ; - offset = pin * mux_bytes; - val = pcs->read (pcs->base + offset); + offset =pcs_pin_reg_offset_get (pcs, pin); + +if (pcs->bits_per_mux) { +unsigned int pin_shift_in_reg =pcs_pin_shift_reg_get (pcs, pin); + + val = pcs->read (pcs->base + offset) + & (pcs->fmask << pin_shift_in_reg); + }else { + val = pcs->read (pcs->base + offset); + } + pa = pcs->res->start + offset;seq_printf (s,"%zx %08x %s " , pa, val,DRIVER_NAME );
@@ -384,7 +417,6 @@ static int pcs_request_gpio(struct pinctrl_dev *pctldev,struct pcs_device *pcs =pinctrl_dev_get_drvdata (pctldev);struct pcs_gpiofunc_range *frange =NULL ;struct list_head *pos, *tmp; -int mux_bytes =0 ;unsigned data;/* If function mask is null, return directly. */
@@ -392,29 +424,27 @@ static int pcs_request_gpio(struct pinctrl_dev *pctldev,return -ENOTSUPP ;list_for_each_safe (pos, tmp, &pcs->gpiofuncs) { +u32 offset; + frange = list_entry(pos, struct pcs_gpiofunc_range, node);if (pin >= frange->offset + frange->npins || pin < frange->offset)continue ; - mux_bytes = pcs->width /BITS_PER_BYTE ; -if (pcs->bits_per_mux) { -int byte_num, offset, pin_shift; + offset =pcs_pin_reg_offset_get (pcs, pin); - byte_num = (pcs->bits_per_pin * pin) /BITS_PER_BYTE ; - offset = (byte_num / mux_bytes) * mux_bytes; - pin_shift = pin % (pcs->width / pcs->bits_per_pin) * - pcs->bits_per_pin; +if (pcs->bits_per_mux) { +int pin_shift =pcs_pin_shift_reg_get (pcs, pin); data = pcs->read (pcs->base + offset); data &= ~(pcs->fmask << pin_shift); data |= frange->gpiofunc << pin_shift; pcs->write (data, pcs->base + offset); }else { - data = pcs->read (pcs->base + pin * mux_bytes); + data = pcs->read (pcs->base + offset); data &= ~pcs->fmask; data |= frange->gpiofunc; - pcs->write (data, pcs->base + pin * mux_bytes); + pcs->write (data, pcs->base + offset); }break ; }
@@ -724,14 +754,8 @@ static int pcs_allocate_pin_table(struct pcs_device *pcs)for (i =0 ; i < pcs->desc.npins; i++) {unsigned offset;int res; -int byte_num; -if (pcs->bits_per_mux) { - byte_num = (pcs->bits_per_pin * i) /BITS_PER_BYTE ; - offset = (byte_num / mux_bytes) * mux_bytes; - }else { - offset = i * mux_bytes; - } + offset =pcs_pin_reg_offset_get (pcs, i); res =pcs_add_pin (pcs, offset);if (res <0 ) {dev_err (pcs->dev,"error adding pins: %i\n" , res);
Signature · 1 line
2.17.1
Re: [PATCH v2 3/3] pinctrl: pinctrl-single: fix pcs_pin_dbg_show() when bits_per_mux != 0
Quoted 2 lines · Hanna Hawa
An SError was detected when trying to print the supported pins in a
What SError is?
Quoted 3 lines
pinctrl device which supports multiple pins per register. This change fixes the
pcs_pin_dbg_show()in pinctrl-single driver whenbits_per_mux!= 0. In addition move offset calculation and pin offset in
'!= 0' -> 'is not zero'
Quoted 1 line
register to common function.
Fixes tag?
Quoted 10 lines
Signed-off-by Hanna Hawa <[email protected]>--- drivers/pinctrl/pinctrl-single.c | 66 ++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 21 deletions(-)drivers/pinctrl/pinctrl-single.c +0
-0
drivers/pinctrl/pinctrl-single.c static void __maybe_unused pcs_writel(unsigned val, void __iomem *reg) · line 276
Quoted 7 lines
drivers/pinctrl/pinctrl-single.c +4
-0@@ -270,20 +270,53 @@ static void __maybe_unused pcs_writel(unsigned val, void __iomem *reg)writel (val, reg); } +static unsigned int pcs_pin_reg_offset_get (struct pcs_device *pcs, +unsigned int pin) +{ +unsigned int offset, mux_bytes;
Offset can be replaced by direct return statements.
Quoted 8 lines
drivers/pinctrl/pinctrl-single.c +8
-0+ mux_bytes = pcs->width /BITS_PER_BYTE ; + +if (pcs->bits_per_mux) { +unsigned int pin_offset_bytes; + + pin_offset_bytes = (pcs->bits_per_pin * pin) /BITS_PER_BYTE ; + offset = (pin_offset_bytes / mux_bytes) * mux_bytes; + }else {
drivers/pinctrl/pinctrl-single.c static void __maybe_unused pcs_writel(unsigned val, void __iomem *reg) · line 295
Quoted 10 lines
drivers/pinctrl/pinctrl-single.c +10
-0+ offset = pin * mux_bytes; + } + +return offset; +} + +static unsigned int pcs_pin_shift_reg_get (struct pcs_device *pcs, +unsigned int pin) +{ +return ((pin % (pcs->width / pcs->bits_per_pin)) * pcs->bits_per_pin);
Too many parentheses.
Quoted 14 lines
drivers/pinctrl/pinctrl-single.c +3
-1+} +static void pcs_pin_dbg_show (struct pinctrl_dev *pctldev,struct seq_file *s,unsigned pin) {struct pcs_device *pcs; -unsigned val, mux_bytes; +unsigned int val;unsigned long offset;size_t pa; pcs =pinctrl_dev_get_drvdata (pctldev);
drivers/pinctrl/pinctrl-single.c static void __maybe_unused pcs_writel(unsigned val, void __iomem *reg)
Quoted 10 lines
drivers/pinctrl/pinctrl-single.c +6
-3- mux_bytes = pcs->width /BITS_PER_BYTE ; - offset = pin * mux_bytes; - val = pcs->read (pcs->base + offset); + offset =pcs_pin_reg_offset_get (pcs, pin); + +if (pcs->bits_per_mux) { +unsigned int pin_shift_in_reg =pcs_pin_shift_reg_get (pcs, pin); + val = pcs->read (pcs->base + offset) + & (pcs->fmask << pin_shift_in_reg);
One line?
At least move & to the upper line.
drivers/pinctrl/pinctrl-single.c static void __maybe_unused pcs_writel(unsigned val, void __iomem *reg) · line 316
Quoted 2 lines
drivers/pinctrl/pinctrl-single.c +2
-0+ }else { + val = pcs->read (pcs->base + offset);
It's the same as in above branch, why not
val = read();
if ()
val &= fmask << _reg_get(...);
?
Quoted 69 lines
drivers/pinctrl/pinctrl-single.c +10
-18+ } + pa = pcs->res->start + offset;seq_printf (s,"%zx %08x %s " , pa, val,DRIVER_NAME );@@ -384,7 +417,6 @@ static int pcs_request_gpio(struct pinctrl_dev *pctldev,struct pcs_device *pcs =pinctrl_dev_get_drvdata (pctldev);struct pcs_gpiofunc_range *frange =NULL ;struct list_head *pos, *tmp; -int mux_bytes =0 ;unsigned data;/* If function mask is null, return directly. */ @@ -392,29 +424,27 @@ static int pcs_request_gpio(struct pinctrl_dev *pctldev,return -ENOTSUPP ;list_for_each_safe (pos, tmp, &pcs->gpiofuncs) { +u32 offset; + frange = list_entry(pos, struct pcs_gpiofunc_range, node);if (pin >= frange->offset + frange->npins || pin < frange->offset)continue ; - mux_bytes = pcs->width /BITS_PER_BYTE ; -if (pcs->bits_per_mux) { -int byte_num, offset, pin_shift; + offset =pcs_pin_reg_offset_get (pcs, pin); - byte_num = (pcs->bits_per_pin * pin) /BITS_PER_BYTE ; - offset = (byte_num / mux_bytes) * mux_bytes; - pin_shift = pin % (pcs->width / pcs->bits_per_pin) * - pcs->bits_per_pin; +if (pcs->bits_per_mux) { +int pin_shift =pcs_pin_shift_reg_get (pcs, pin); data = pcs->read (pcs->base + offset); data &= ~(pcs->fmask << pin_shift); data |= frange->gpiofunc << pin_shift; pcs->write (data, pcs->base + offset); }else { - data = pcs->read (pcs->base + pin * mux_bytes); + data = pcs->read (pcs->base + offset); data &= ~pcs->fmask; data |= frange->gpiofunc; - pcs->write (data, pcs->base + pin * mux_bytes); + pcs->write (data, pcs->base + offset); }break ; }@@ -724,14 +754,8 @@ static int pcs_allocate_pin_table(struct pcs_device *pcs)for (i =0 ; i < pcs->desc.npins; i++) {unsigned offset;int res; -int byte_num; -if (pcs->bits_per_mux) { - byte_num = (pcs->bits_per_pin * i) /BITS_PER_BYTE ; - offset = (byte_num / mux_bytes) * mux_bytes; - }else { - offset = i * mux_bytes; - } + offset =pcs_pin_reg_offset_get (pcs, i); res =pcs_add_pin (pcs, offset);if (res <0 ) {dev_err (pcs->dev,"error adding pins: %i\n" , res); --2.17.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 3/3] pinctrl: pinctrl-single: fix pcs_pin_dbg_show() when bits_per_mux != 0
Quoted 6 lines · Andy Shevchenko
Quoted 2 lines · Hanna Hawa
An SError was detected when trying to print the supported pins in a
What SError is?
System error:
[ 24.257831] SError Interrupt on CPU0, code 0xbf000002 -- SError ... [ 24.257855] Kernel panic - not syncing: Asynchronous SError Interrupt
Quoted 6 lines
Quoted 4 lines
pinctrl device which supports multiple pins per register. This change fixes the
pcs_pin_dbg_show()in pinctrl-single driver whenbits_per_mux!= 0. In addition move offset calculation and pin offset in'!= 0' -> 'is not zero'
Will be fixed.
Quoted 4 lines
Quoted 2 lines
register to common function.
Fixes tag?
Sure, will be added.
Quoted 14 lines
Quoted 14 lines
Signed-off-by Hanna Hawa <[email protected]>--- drivers/pinctrl/pinctrl-single.c | 66 ++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 21 deletions(-)drivers/pinctrl/pinctrl-single.c +0
-0@@ -270,20 +270,53 @@ static void __maybe_unused pcs_writel(unsigned val, void __iomem *reg)writel (val, reg); }
Quoted 6 lines
drivers/pinctrl/pinctrl-single.c static void __maybe_unused pcs_writel(unsigned val, void __iomem *reg) · line 276
Quoted 4 lines
drivers/pinctrl/pinctrl-single.c +4
-0+static unsigned int pcs_pin_reg_offset_get (struct pcs_device *pcs, +unsigned int pin) +{ +unsigned int offset, mux_bytes;Offset can be replaced by direct return statements.
Ack.
Quoted 13 lines
Quoted 13 lines
drivers/pinctrl/pinctrl-single.c +12
-0+ mux_bytes = pcs->width /BITS_PER_BYTE ; + +if (pcs->bits_per_mux) { +unsigned int pin_offset_bytes; + + pin_offset_bytes = (pcs->bits_per_pin * pin) /BITS_PER_BYTE ; + offset = (pin_offset_bytes / mux_bytes) * mux_bytes; + }else { + offset = pin * mux_bytes; + } + +return offset;
Quoted 8 lines
drivers/pinctrl/pinctrl-single.c static void __maybe_unused pcs_writel(unsigned val, void __iomem *reg) · line 295
Quoted 6 lines
drivers/pinctrl/pinctrl-single.c +6
-0+} + +static unsigned int pcs_pin_shift_reg_get (struct pcs_device *pcs, +unsigned int pin) +{ +return ((pin % (pcs->width / pcs->bits_per_pin)) * pcs->bits_per_pin);Too many parentheses.
Will remove the extra parentheses.
Quoted 32 lines
Quoted 15 lines
drivers/pinctrl/pinctrl-single.c +3
-1+} +static void pcs_pin_dbg_show (struct pinctrl_dev *pctldev,struct seq_file *s,unsigned pin) {struct pcs_device *pcs; -unsigned val, mux_bytes; +unsigned int val;unsigned long offset;size_t pa; pcs =pinctrl_dev_get_drvdata (pctldev);drivers/pinctrl/pinctrl-single.c static void __maybe_unused pcs_writel(unsigned val, void __iomem *reg)
Quoted 10 lines
drivers/pinctrl/pinctrl-single.c +6
-3- mux_bytes = pcs->width /BITS_PER_BYTE ; - offset = pin * mux_bytes; - val = pcs->read (pcs->base + offset); + offset =pcs_pin_reg_offset_get (pcs, pin); + +if (pcs->bits_per_mux) { +unsigned int pin_shift_in_reg =pcs_pin_shift_reg_get (pcs, pin); + val = pcs->read (pcs->base + offset) + & (pcs->fmask << pin_shift_in_reg);One line?
At least move & to the upper line.drivers/pinctrl/pinctrl-single.c static void __maybe_unused pcs_writel(unsigned val, void __iomem *reg) · line 316
Quoted 2 lines
drivers/pinctrl/pinctrl-single.c +2
-0+ }else { + val = pcs->read (pcs->base + offset);
Quoted 7 lines
It's the same as in above branch, why not
val =
read();
if ()
val &= fmask <<_reg_get(...);?
Agree, looks better
Thanks Andy, will send new patchset soon.
Thanks,
Hanna
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel