Skip to contentSkip to conversation

pinctrl: pinctrl-single: Fix pcs_request_gpio() when bits_per_mux != 0

PATCH Superseded David Lechner 3 participants 5 messages Jan 21, 2018 – Jan 23, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: pinctrl-single: Fix pcs_request_gpio() when bits_per_mux != 0

This fixes pcs_request_gpio() in the pinctrl-single driver when bits_per_mux != 0. It appears this was overlooked when the multiple pins per register feature was added.

Fixes 4e7e8017a80e ("pinctrl: pinctrl-single: enhance to configure

multiple pins of different modules")

Cc Tony Lindgren <[email protected]>
Cc Haojian Zhuang <[email protected]>
Cc Linus Walleij <[email protected]>
---
 drivers/pinctrl/pinctrl-single.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
drivers/pinctrl/pinctrl-single.c +19 -3
index 3501491..7a5e2f1 100644
@@ -391,9 +391,25 @@ static int pcs_request_gpio(struct pinctrl_dev *pctldev,
 			|| pin < frange->offset)
 			continue;
 		mux_bytes = pcs->width / BITS_PER_BYTE;
-		data = pcs->read(pcs->base + pin * mux_bytes) & ~pcs->fmask;
-		data |= frange->gpiofunc;
-		pcs->write(data, pcs->base + pin * mux_bytes);
+
+		if (pcs->bits_per_mux) {
+			int byte_num, offset, pin_shift;
+
+			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;
+
+			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->fmask;
+			data |= frange->gpiofunc;
+			pcs->write(data, pcs->base + pin * mux_bytes);
+		}
 		break;
 	}
 	return 0;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 6 lines · David Lechner

This fixes pcs_request_gpio() in the pinctrl-single driver when bits_per_mux != 0. It appears this was overlooked when the multiple pins per register feature was added.

Fixes 4e7e8017a80e ("pinctrl: pinctrl-single: enhance to configure

multiple pins of different modules")

One line?

drivers/pinctrl/pinctrl-single.c static int pcs_request_gpio(struct pinctrl_dev *pctldev, · line 401

Quoted 4 lines
drivers/pinctrl/pinctrl-single.c +4 -0
+                       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;

Sounds like playing around pretty well defined macro and functions, e.g. DIV_ROUND_UP(), round_up().

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 6 lines · David Lechner

This fixes pcs_request_gpio() in the pinctrl-single driver when bits_per_mux != 0. It appears this was overlooked when the multiple pins per register feature was added.

Fixes 4e7e8017a80e ("pinctrl: pinctrl-single: enhance to configure

multiple pins of different modules")

One line?

One line is more important that wrapping to 75 chars?

Quoted 9 lines

drivers/pinctrl/pinctrl-single.c static int pcs_request_gpio(struct pinctrl_dev *pctldev, · line 401

Quoted 5 lines
drivers/pinctrl/pinctrl-single.c +4 -0
+                       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;

Sounds like playing around pretty well defined macro and functions, e.g. DIV_ROUND_UP(), round_up().

I admit, I just copied existing code (which may be a reason to leave this the way it is). But, I only see once place to do this:

	offset = round_down(byte_num, mux_bytes);

Did I miss another?

#3 lore raw
Quoted 10 lines · David Lechner
Quoted 7 lines · Andy Shevchenko
Quoted 2 lines · David Lechner
Fixes 4e7e8017a80e ("pinctrl: pinctrl-single: enhance to configure

multiple pins of different modules")

One line?

One line is more important that wrapping to 75 chars?

It's *special* line, i.e. tag. Tag per line is a rule I know, did I miss any new change to that?

Quoted 7 lines
Quoted 6 lines
Quoted 6 lines

+ byte_num = (pcs->bits_per_pin * pin) /
BITS_PER_BYTE;

(quoted diff) +2 -0
+                       offset = (byte_num / mux_bytes) * mux_bytes;
+                       pin_shift = pin % (pcs->width /

pcs->bits_per_pin) *
+ pcs->bits_per_pin;

Quoted 6 lines
Quoted 2 lines

Sounds like playing around pretty well defined macro and functions, e.g. DIV_ROUND_UP(), round_up().

I admit, I just copied existing code (which may be a reason to leave this the
way it is).

Ah, fair enough.

Quoted 5 lines

But, I only see once place to do this:

        offset = round_down(byte_num, mux_bytes);

Did I miss another?

I meant that you may use macros to make code cleaner. Though, taking above into consideration, it would be done as a separate patch later.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#4 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · David Lechner
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · David Lechner
Fixes 4e7e8017a80e ("pinctrl: pinctrl-single: enhance to configure

multiple pins of different modules")

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

One line?

One line is more important that wrapping to 75 chars?

It's *special* line, i.e. tag. Tag per line is a rule I know, did I miss any new change to that?

I think the rule for merge commits is to try to limit them to 75 characters for git log.

Quoted 16 lines
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines

+ byte_num = (pcs->bits_per_pin * pin) /
BITS_PER_BYTE;

(quoted diff) +2 -0
+                       offset = (byte_num / mux_bytes) * mux_bytes;
+                       pin_shift = pin % (pcs->width /

pcs->bits_per_pin) *
+ pcs->bits_per_pin;

Quoted 6 lines
Quoted 2 lines

Sounds like playing around pretty well defined macro and functions, e.g. DIV_ROUND_UP(), round_up().

I admit, I just copied existing code (which may be a reason to leave this the
way it is).

Ah, fair enough.

Quoted 8 lines
Quoted 5 lines

But, I only see once place to do this:

        offset = round_down(byte_num, mux_bytes);

Did I miss another?

I meant that you may use macros to make code cleaner. Though, taking above into consideration, it would be done as a separate patch later.

Yeah makes sense to me to do them separately. It would be good to get Haojian's ack or tested-by on this one, I don't think I have hardware where I can test the GPIO features with this driver.

Regards,

Tony