Skip to content

Commit 6c73698

Browse files
anderssonLinus Walleij
authored andcommitted
pinctrl: qcom: Introduce readl/writel accessors
In preparation for the support for dispersed tiles move all readl and writel calls to helper functions. This will allow us to isolate the added complexity of another indirection. Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent ed80f6e commit 6c73698

1 file changed

Lines changed: 54 additions & 36 deletions

File tree

‎drivers/pinctrl/qcom/pinctrl-msm.c‎

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ struct msm_pinctrl {
7373
void __iomem *regs;
7474
};
7575

76+
#define MSM_ACCESSOR(name) \
77+
static u32 msm_readl_##name(struct msm_pinctrl *pctrl, \
78+
const struct msm_pingroup *g) \
79+
{ \
80+
return readl(pctrl->regs + g->name##_reg); \
81+
} \
82+
static void msm_writel_##name(u32 val, struct msm_pinctrl *pctrl, \
83+
const struct msm_pingroup *g) \
84+
{ \
85+
writel(val, pctrl->regs + g->name##_reg); \
86+
}
87+
88+
MSM_ACCESSOR(ctl)
89+
MSM_ACCESSOR(io)
90+
MSM_ACCESSOR(intr_cfg)
91+
MSM_ACCESSOR(intr_status)
92+
MSM_ACCESSOR(intr_target)
93+
7694
static int msm_get_groups_count(struct pinctrl_dev *pctldev)
7795
{
7896
struct msm_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
@@ -166,10 +184,10 @@ static int msm_pinmux_set_mux(struct pinctrl_dev *pctldev,
166184

167185
raw_spin_lock_irqsave(&pctrl->lock, flags);
168186

169-
val = readl(pctrl->regs + g->ctl_reg);
187+
val = msm_readl_ctl(pctrl, g);
170188
val &= ~mask;
171189
val |= i << g->mux_bit;
172-
writel(val, pctrl->regs + g->ctl_reg);
190+
msm_writel_ctl(val, pctrl, g);
173191

174192
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
175193

@@ -260,7 +278,7 @@ static int msm_config_group_get(struct pinctrl_dev *pctldev,
260278
if (ret < 0)
261279
return ret;
262280

263-
val = readl(pctrl->regs + g->ctl_reg);
281+
val = msm_readl_ctl(pctrl, g);
264282
arg = (val >> bit) & mask;
265283

266284
/* Convert register value to pinconf value */
@@ -299,7 +317,7 @@ static int msm_config_group_get(struct pinctrl_dev *pctldev,
299317
if (!arg)
300318
return -EINVAL;
301319

302-
val = readl(pctrl->regs + g->io_reg);
320+
val = msm_readl_io(pctrl, g);
303321
arg = !!(val & BIT(g->in_bit));
304322
break;
305323
case PIN_CONFIG_INPUT_ENABLE:
@@ -373,12 +391,12 @@ static int msm_config_group_set(struct pinctrl_dev *pctldev,
373391
case PIN_CONFIG_OUTPUT:
374392
/* set output value */
375393
raw_spin_lock_irqsave(&pctrl->lock, flags);
376-
val = readl(pctrl->regs + g->io_reg);
394+
val = msm_readl_io(pctrl, g);
377395
if (arg)
378396
val |= BIT(g->out_bit);
379397
else
380398
val &= ~BIT(g->out_bit);
381-
writel(val, pctrl->regs + g->io_reg);
399+
msm_writel_io(val, pctrl, g);
382400
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
383401

384402
/* enable output */
@@ -401,10 +419,10 @@ static int msm_config_group_set(struct pinctrl_dev *pctldev,
401419
}
402420

403421
raw_spin_lock_irqsave(&pctrl->lock, flags);
404-
val = readl(pctrl->regs + g->ctl_reg);
422+
val = msm_readl_ctl(pctrl, g);
405423
val &= ~(mask << bit);
406424
val |= arg << bit;
407-
writel(val, pctrl->regs + g->ctl_reg);
425+
msm_writel_ctl(val, pctrl, g);
408426
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
409427
}
410428

@@ -428,9 +446,9 @@ static int msm_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
428446

429447
raw_spin_lock_irqsave(&pctrl->lock, flags);
430448

431-
val = readl(pctrl->regs + g->ctl_reg);
449+
val = msm_readl_ctl(pctrl, g);
432450
val &= ~BIT(g->oe_bit);
433-
writel(val, pctrl->regs + g->ctl_reg);
451+
msm_writel_ctl(val, pctrl, g);
434452

435453
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
436454

@@ -448,16 +466,16 @@ static int msm_gpio_direction_output(struct gpio_chip *chip, unsigned offset, in
448466

449467
raw_spin_lock_irqsave(&pctrl->lock, flags);
450468

451-
val = readl(pctrl->regs + g->io_reg);
469+
val = msm_readl_io(pctrl, g);
452470
if (value)
453471
val |= BIT(g->out_bit);
454472
else
455473
val &= ~BIT(g->out_bit);
456-
writel(val, pctrl->regs + g->io_reg);
474+
msm_writel_io(val, pctrl, g);
457475

458-
val = readl(pctrl->regs + g->ctl_reg);
476+
val = msm_readl_ctl(pctrl, g);
459477
val |= BIT(g->oe_bit);
460-
writel(val, pctrl->regs + g->ctl_reg);
478+
msm_writel_ctl(val, pctrl, g);
461479

462480
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
463481

@@ -472,7 +490,7 @@ static int msm_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
472490

473491
g = &pctrl->soc->groups[offset];
474492

475-
val = readl(pctrl->regs + g->ctl_reg);
493+
val = msm_readl_ctl(pctrl, g);
476494

477495
/* 0 = output, 1 = input */
478496
return val & BIT(g->oe_bit) ? 0 : 1;
@@ -486,7 +504,7 @@ static int msm_gpio_get(struct gpio_chip *chip, unsigned offset)
486504

487505
g = &pctrl->soc->groups[offset];
488506

489-
val = readl(pctrl->regs + g->io_reg);
507+
val = msm_readl_io(pctrl, g);
490508
return !!(val & BIT(g->in_bit));
491509
}
492510

@@ -501,12 +519,12 @@ static void msm_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
501519

502520
raw_spin_lock_irqsave(&pctrl->lock, flags);
503521

504-
val = readl(pctrl->regs + g->io_reg);
522+
val = msm_readl_io(pctrl, g);
505523
if (value)
506524
val |= BIT(g->out_bit);
507525
else
508526
val &= ~BIT(g->out_bit);
509-
writel(val, pctrl->regs + g->io_reg);
527+
msm_writel_io(val, pctrl, g);
510528

511529
raw_spin_unlock_irqrestore(&pctrl->lock, flags);
512530
}
@@ -546,8 +564,8 @@ static void msm_gpio_dbg_show_one(struct seq_file *s,
546564
return;
547565

548566
g = &pctrl->soc->groups[offset];
549-
ctl_reg = readl(pctrl->regs + g->ctl_reg);
550-
io_reg = readl(pctrl->regs + g->io_reg);
567+
ctl_reg = msm_readl_ctl(pctrl, g);
568+
io_reg = msm_readl_io(pctrl, g);
551569

552570
is_out = !!(ctl_reg & BIT(g->oe_bit));
553571
func = (ctl_reg >> g->mux_bit) & 7;
@@ -622,14 +640,14 @@ static void msm_gpio_update_dual_edge_pos(struct msm_pinctrl *pctrl,
622640
unsigned pol;
623641

624642
do {
625-
val = readl(pctrl->regs + g->io_reg) & BIT(g->in_bit);
643+
val = msm_readl_io(pctrl, g) & BIT(g->in_bit);
626644

627-
pol = readl(pctrl->regs + g->intr_cfg_reg);
645+
pol = msm_readl_intr_cfg(pctrl, g);
628646
pol ^= BIT(g->intr_polarity_bit);
629-
writel(pol, pctrl->regs + g->intr_cfg_reg);
647+
msm_writel_intr_cfg(val, pctrl, g);
630648

631-
val2 = readl(pctrl->regs + g->io_reg) & BIT(g->in_bit);
632-
intstat = readl(pctrl->regs + g->intr_status_reg);
649+
val2 = msm_readl_io(pctrl, g) & BIT(g->in_bit);
650+
intstat = msm_readl_intr_status(pctrl, g);
633651
if (intstat || (val == val2))
634652
return;
635653
} while (loop_limit-- > 0);
@@ -649,9 +667,9 @@ static void msm_gpio_irq_mask(struct irq_data *d)
649667

650668
raw_spin_lock_irqsave(&pctrl->lock, flags);
651669

652-
val = readl(pctrl->regs + g->intr_cfg_reg);
670+
val = msm_readl_intr_cfg(pctrl, g);
653671
val &= ~BIT(g->intr_enable_bit);
654-
writel(val, pctrl->regs + g->intr_cfg_reg);
672+
msm_writel_intr_cfg(val, pctrl, g);
655673

656674
clear_bit(d->hwirq, pctrl->enabled_irqs);
657675

@@ -670,9 +688,9 @@ static void msm_gpio_irq_unmask(struct irq_data *d)
670688

671689
raw_spin_lock_irqsave(&pctrl->lock, flags);
672690

673-
val = readl(pctrl->regs + g->intr_cfg_reg);
691+
val = msm_readl_intr_cfg(pctrl, g);
674692
val |= BIT(g->intr_enable_bit);
675-
writel(val, pctrl->regs + g->intr_cfg_reg);
693+
msm_writel_intr_cfg(val, pctrl, g);
676694

677695
set_bit(d->hwirq, pctrl->enabled_irqs);
678696

@@ -691,12 +709,12 @@ static void msm_gpio_irq_ack(struct irq_data *d)
691709

692710
raw_spin_lock_irqsave(&pctrl->lock, flags);
693711

694-
val = readl(pctrl->regs + g->intr_status_reg);
712+
val = msm_readl_intr_status(pctrl, g);
695713
if (g->intr_ack_high)
696714
val |= BIT(g->intr_status_bit);
697715
else
698716
val &= ~BIT(g->intr_status_bit);
699-
writel(val, pctrl->regs + g->intr_status_reg);
717+
msm_writel_intr_status(val, pctrl, g);
700718

701719
if (test_bit(d->hwirq, pctrl->dual_edge_irqs))
702720
msm_gpio_update_dual_edge_pos(pctrl, g, d);
@@ -725,17 +743,17 @@ static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type)
725743
clear_bit(d->hwirq, pctrl->dual_edge_irqs);
726744

727745
/* Route interrupts to application cpu */
728-
val = readl(pctrl->regs + g->intr_target_reg);
746+
val = msm_readl_intr_target(pctrl, g);
729747
val &= ~(7 << g->intr_target_bit);
730748
val |= g->intr_target_kpss_val << g->intr_target_bit;
731-
writel(val, pctrl->regs + g->intr_target_reg);
749+
msm_writel_intr_target(val, pctrl, g);
732750

733751
/* Update configuration for gpio.
734752
* RAW_STATUS_EN is left on for all gpio irqs. Due to the
735753
* internal circuitry of TLMM, toggling the RAW_STATUS
736754
* could cause the INTR_STATUS to be set for EDGE interrupts.
737755
*/
738-
val = readl(pctrl->regs + g->intr_cfg_reg);
756+
val = msm_readl_intr_cfg(pctrl, g);
739757
val |= BIT(g->intr_raw_status_bit);
740758
if (g->intr_detection_width == 2) {
741759
val &= ~(3 << g->intr_detection_bit);
@@ -783,7 +801,7 @@ static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type)
783801
} else {
784802
BUG();
785803
}
786-
writel(val, pctrl->regs + g->intr_cfg_reg);
804+
msm_writel_intr_cfg(val, pctrl, g);
787805

788806
if (test_bit(d->hwirq, pctrl->dual_edge_irqs))
789807
msm_gpio_update_dual_edge_pos(pctrl, g, d);
@@ -867,7 +885,7 @@ static void msm_gpio_irq_handler(struct irq_desc *desc)
867885
*/
868886
for_each_set_bit(i, pctrl->enabled_irqs, pctrl->chip.ngpio) {
869887
g = &pctrl->soc->groups[i];
870-
val = readl(pctrl->regs + g->intr_status_reg);
888+
val = msm_readl_intr_status(pctrl, g);
871889
if (val & BIT(g->intr_status_bit)) {
872890
irq_pin = irq_find_mapping(gc->irq.domain, i);
873891
generic_handle_irq(irq_pin);

0 commit comments

Comments
 (0)