Skip to content

Commit da40d5f

Browse files
Hanna Hawagregkh
authored andcommitted
pinctrl: pinctrl-single: fix pcs_pin_dbg_show() when bits_per_mux is not zero
[ Upstream commit bd85125 ] A System Error (SError, followed by kernel panic) 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 is not zero. In addition move offset calculation and pin offset in register to common function. Fixes: 4e7e801 ("pinctrl: pinctrl-single: enhance to configure multiple pins of different modules") Signed-off-by: Hanna Hawa <hhhawa@amazon.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Tony Lindgren <tony@atomide.com> Reviewed-by: Drew Fustini <drew@beagleboard.org> Link: https://lore.kernel.org/r/20210319152133.28705-4-hhhawa@amazon.com Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 353fceb commit da40d5f

1 file changed

Lines changed: 35 additions & 20 deletions

File tree

‎drivers/pinctrl/pinctrl-single.c‎

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -270,20 +270,44 @@ static void __maybe_unused pcs_writel(unsigned val, void __iomem *reg)
270270
writel(val, reg);
271271
}
272272

273+
static unsigned int pcs_pin_reg_offset_get(struct pcs_device *pcs,
274+
unsigned int pin)
275+
{
276+
unsigned int mux_bytes = pcs->width / BITS_PER_BYTE;
277+
278+
if (pcs->bits_per_mux) {
279+
unsigned int pin_offset_bytes;
280+
281+
pin_offset_bytes = (pcs->bits_per_pin * pin) / BITS_PER_BYTE;
282+
return (pin_offset_bytes / mux_bytes) * mux_bytes;
283+
}
284+
285+
return pin * mux_bytes;
286+
}
287+
288+
static unsigned int pcs_pin_shift_reg_get(struct pcs_device *pcs,
289+
unsigned int pin)
290+
{
291+
return (pin % (pcs->width / pcs->bits_per_pin)) * pcs->bits_per_pin;
292+
}
293+
273294
static void pcs_pin_dbg_show(struct pinctrl_dev *pctldev,
274295
struct seq_file *s,
275296
unsigned pin)
276297
{
277298
struct pcs_device *pcs;
278-
unsigned val, mux_bytes;
299+
unsigned int val;
279300
unsigned long offset;
280301
size_t pa;
281302

282303
pcs = pinctrl_dev_get_drvdata(pctldev);
283304

284-
mux_bytes = pcs->width / BITS_PER_BYTE;
285-
offset = pin * mux_bytes;
305+
offset = pcs_pin_reg_offset_get(pcs, pin);
286306
val = pcs->read(pcs->base + offset);
307+
308+
if (pcs->bits_per_mux)
309+
val &= pcs->fmask << pcs_pin_shift_reg_get(pcs, pin);
310+
287311
pa = pcs->res->start + offset;
288312

289313
seq_printf(s, "%zx %08x %s ", pa, val, DRIVER_NAME);
@@ -384,37 +408,34 @@ static int pcs_request_gpio(struct pinctrl_dev *pctldev,
384408
struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev);
385409
struct pcs_gpiofunc_range *frange = NULL;
386410
struct list_head *pos, *tmp;
387-
int mux_bytes = 0;
388411
unsigned data;
389412

390413
/* If function mask is null, return directly. */
391414
if (!pcs->fmask)
392415
return -ENOTSUPP;
393416

394417
list_for_each_safe(pos, tmp, &pcs->gpiofuncs) {
418+
u32 offset;
419+
395420
frange = list_entry(pos, struct pcs_gpiofunc_range, node);
396421
if (pin >= frange->offset + frange->npins
397422
|| pin < frange->offset)
398423
continue;
399-
mux_bytes = pcs->width / BITS_PER_BYTE;
400424

401-
if (pcs->bits_per_mux) {
402-
int byte_num, offset, pin_shift;
425+
offset = pcs_pin_reg_offset_get(pcs, pin);
403426

404-
byte_num = (pcs->bits_per_pin * pin) / BITS_PER_BYTE;
405-
offset = (byte_num / mux_bytes) * mux_bytes;
406-
pin_shift = pin % (pcs->width / pcs->bits_per_pin) *
407-
pcs->bits_per_pin;
427+
if (pcs->bits_per_mux) {
428+
int pin_shift = pcs_pin_shift_reg_get(pcs, pin);
408429

409430
data = pcs->read(pcs->base + offset);
410431
data &= ~(pcs->fmask << pin_shift);
411432
data |= frange->gpiofunc << pin_shift;
412433
pcs->write(data, pcs->base + offset);
413434
} else {
414-
data = pcs->read(pcs->base + pin * mux_bytes);
435+
data = pcs->read(pcs->base + offset);
415436
data &= ~pcs->fmask;
416437
data |= frange->gpiofunc;
417-
pcs->write(data, pcs->base + pin * mux_bytes);
438+
pcs->write(data, pcs->base + offset);
418439
}
419440
break;
420441
}
@@ -726,14 +747,8 @@ static int pcs_allocate_pin_table(struct pcs_device *pcs)
726747
for (i = 0; i < pcs->desc.npins; i++) {
727748
unsigned offset;
728749
int res;
729-
int byte_num;
730750

731-
if (pcs->bits_per_mux) {
732-
byte_num = (pcs->bits_per_pin * i) / BITS_PER_BYTE;
733-
offset = (byte_num / mux_bytes) * mux_bytes;
734-
} else {
735-
offset = i * mux_bytes;
736-
}
751+
offset = pcs_pin_reg_offset_get(pcs, i);
737752
res = pcs_add_pin(pcs, offset);
738753
if (res < 0) {
739754
dev_err(pcs->dev, "error adding pins: %i\n", res);

0 commit comments

Comments
 (0)