Skip to content

Commit 1d09de7

Browse files
mlauss2ralfbaechle
authored andcommitted
MIPS: Alchemy: introduce helpers to access SYS register block.
This patch changes all absolute SYS_XY registers to offsets from the SYS block base, prefixes them with AU1000 to avoid silent failures due to changed addresses, and introduces helper functions to read/write them. No functional changes, comparing assembly of a few select functions shows no differences. Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com> Cc: Linux-MIPS <linux-mips@linux-mips.org> Patchwork: https://patchwork.linux-mips.org/patch/7464/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent 2ef1bb9 commit 1d09de7

17 files changed

Lines changed: 152 additions & 159 deletions

File tree

‎arch/mips/alchemy/board-mtx1.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ void __init board_setup(void)
8585
#endif /* IS_ENABLED(CONFIG_USB_OHCI_HCD) */
8686

8787
/* Initialize sys_pinfunc */
88-
au_writel(SYS_PF_NI2, SYS_PINFUNC);
88+
alchemy_wrsys(SYS_PF_NI2, AU1000_SYS_PINFUNC);
8989

9090
/* Initialize GPIO */
91-
au_writel(~0, KSEG1ADDR(AU1000_SYS_PHYS_ADDR) + SYS_TRIOUTCLR);
91+
alchemy_wrsys(~0, AU1000_SYS_TRIOUTCLR);
9292
alchemy_gpio_direction_output(0, 0); /* Disable M66EN (PCI 66MHz) */
9393
alchemy_gpio_direction_output(3, 1); /* Disable PCI CLKRUN# */
9494
alchemy_gpio_direction_output(1, 1); /* Enable EXT_IO3 */

‎arch/mips/alchemy/board-xxs1500.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ void __init board_setup(void)
8787
alchemy_gpio2_enable();
8888

8989
/* Set multiple use pins (UART3/GPIO) to UART (it's used as UART too) */
90-
pin_func = au_readl(SYS_PINFUNC) & ~SYS_PF_UR3;
90+
pin_func = alchemy_rdsys(AU1000_SYS_PINFUNC) & ~SYS_PF_UR3;
9191
pin_func |= SYS_PF_UR3;
92-
au_writel(pin_func, SYS_PINFUNC);
92+
alchemy_wrsys(pin_func, AU1000_SYS_PINFUNC);
9393

9494
/* Enable UART */
9595
alchemy_uart_enable(AU1000_UART3_PHYS_ADDR);

‎arch/mips/alchemy/common/clocks.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ unsigned long au1xxx_calc_clock(void)
9191
if (au1xxx_cpu_has_pll_wo())
9292
cpu_speed = 396000000;
9393
else
94-
cpu_speed = (au_readl(SYS_CPUPLL) & 0x0000003f) * AU1000_SRC_CLK;
94+
cpu_speed = (alchemy_rdsys(AU1000_SYS_CPUPLL) & 0x3f) * AU1000_SRC_CLK;
9595

9696
/* On Alchemy CPU:counter ratio is 1:1 */
9797
mips_hpt_frequency = cpu_speed;
9898
/* Equation: Baudrate = CPU / (SD * 2 * CLKDIV * 16) */
99-
set_au1x00_uart_baud_base(cpu_speed / (2 * ((int)(au_readl(SYS_POWERCTRL)
100-
& 0x03) + 2) * 16));
99+
set_au1x00_uart_baud_base(cpu_speed / (2 *
100+
((alchemy_rdsys(AU1000_SYS_POWERCTRL) & 0x03) + 2) * 16));
101101

102102
set_au1x00_speed(cpu_speed);
103103

‎arch/mips/alchemy/common/irq.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,12 @@ static int au1x_ic1_setwake(struct irq_data *d, unsigned int on)
389389
return -EINVAL;
390390

391391
local_irq_save(flags);
392-
wakemsk = __raw_readl((void __iomem *)SYS_WAKEMSK);
392+
wakemsk = alchemy_rdsys(AU1000_SYS_WAKEMSK);
393393
if (on)
394394
wakemsk |= 1 << bit;
395395
else
396396
wakemsk &= ~(1 << bit);
397-
__raw_writel(wakemsk, (void __iomem *)SYS_WAKEMSK);
398-
wmb();
397+
alchemy_wrsys(wakemsk, AU1000_SYS_WAKEMSK);
399398
local_irq_restore(flags);
400399

401400
return 0;

‎arch/mips/alchemy/common/platform.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ static void __init alchemy_setup_macs(int ctype)
420420
memcpy(au1xxx_eth1_platform_data.mac, ethaddr, 6);
421421

422422
/* Register second MAC if enabled in pinfunc */
423-
if (!(au_readl(SYS_PINFUNC) & (u32)SYS_PF_NI2)) {
423+
if (!(alchemy_rdsys(AU1000_SYS_PINFUNC) & SYS_PF_NI2)) {
424424
ret = platform_device_register(&au1xxx_eth1_device);
425425
if (ret)
426426
printk(KERN_INFO "Alchemy: failed to register MAC1\n");

‎arch/mips/alchemy/common/power.c‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ static unsigned int sleep_static_memctlr[4][3];
5454
static void save_core_regs(void)
5555
{
5656
/* Clocks and PLLs. */
57-
sleep_sys_clocks[0] = au_readl(SYS_FREQCTRL0);
58-
sleep_sys_clocks[1] = au_readl(SYS_FREQCTRL1);
59-
sleep_sys_clocks[2] = au_readl(SYS_CLKSRC);
60-
sleep_sys_clocks[3] = au_readl(SYS_CPUPLL);
61-
sleep_sys_clocks[4] = au_readl(SYS_AUXPLL);
57+
sleep_sys_clocks[0] = alchemy_rdsys(AU1000_SYS_FREQCTRL0);
58+
sleep_sys_clocks[1] = alchemy_rdsys(AU1000_SYS_FREQCTRL1);
59+
sleep_sys_clocks[2] = alchemy_rdsys(AU1000_SYS_CLKSRC);
60+
sleep_sys_clocks[3] = alchemy_rdsys(AU1000_SYS_CPUPLL);
61+
sleep_sys_clocks[4] = alchemy_rdsys(AU1000_SYS_AUXPLL);
6262

6363
/* pin mux config */
64-
sleep_sys_pinfunc = au_readl(SYS_PINFUNC);
64+
sleep_sys_pinfunc = alchemy_rdsys(AU1000_SYS_PINFUNC);
6565

6666
/* Save the static memory controller configuration. */
6767
sleep_static_memctlr[0][0] = au_readl(MEM_STCFG0);
@@ -85,16 +85,14 @@ static void restore_core_regs(void)
8585
* one of those Au1000 with a write-only PLL, where we dont
8686
* have a valid value)
8787
*/
88-
au_writel(sleep_sys_clocks[0], SYS_FREQCTRL0);
89-
au_writel(sleep_sys_clocks[1], SYS_FREQCTRL1);
90-
au_writel(sleep_sys_clocks[2], SYS_CLKSRC);
91-
au_writel(sleep_sys_clocks[4], SYS_AUXPLL);
88+
alchemy_wrsys(sleep_sys_clocks[0], AU1000_SYS_FREQCTRL0);
89+
alchemy_wrsys(sleep_sys_clocks[1], AU1000_SYS_FREQCTRL1);
90+
alchemy_wrsys(sleep_sys_clocks[2], AU1000_SYS_CLKSRC);
91+
alchemy_wrsys(sleep_sys_clocks[4], AU1000_SYS_AUXPLL);
9292
if (!au1xxx_cpu_has_pll_wo())
93-
au_writel(sleep_sys_clocks[3], SYS_CPUPLL);
94-
au_sync();
93+
alchemy_wrsys(sleep_sys_clocks[3], AU1000_SYS_CPUPLL);
9594

96-
au_writel(sleep_sys_pinfunc, SYS_PINFUNC);
97-
au_sync();
95+
alchemy_wrsys(sleep_sys_pinfunc, AU1000_SYS_PINFUNC);
9896

9997
/* Restore the static memory controller configuration. */
10098
au_writel(sleep_static_memctlr[0][0], MEM_STCFG0);

‎arch/mips/alchemy/common/time.c‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
static cycle_t au1x_counter1_read(struct clocksource *cs)
4848
{
49-
return au_readl(SYS_RTCREAD);
49+
return alchemy_rdsys(AU1000_SYS_RTCREAD);
5050
}
5151

5252
static struct clocksource au1x_counter1_clocksource = {
@@ -60,12 +60,11 @@ static struct clocksource au1x_counter1_clocksource = {
6060
static int au1x_rtcmatch2_set_next_event(unsigned long delta,
6161
struct clock_event_device *cd)
6262
{
63-
delta += au_readl(SYS_RTCREAD);
63+
delta += alchemy_rdsys(AU1000_SYS_RTCREAD);
6464
/* wait for register access */
65-
while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_M21)
65+
while (alchemy_rdsys(AU1000_SYS_CNTRCTRL) & SYS_CNTRL_M21)
6666
;
67-
au_writel(delta, SYS_RTCMATCH2);
68-
au_sync();
67+
alchemy_wrsys(delta, AU1000_SYS_RTCMATCH2);
6968

7069
return 0;
7170
}
@@ -112,31 +111,29 @@ static int __init alchemy_time_init(unsigned int m2int)
112111
* (the 32S bit seems to be stuck set to 1 once a single clock-
113112
* edge is detected, hence the timeouts).
114113
*/
115-
if (CNTR_OK != (au_readl(SYS_COUNTER_CNTRL) & CNTR_OK))
114+
if (CNTR_OK != (alchemy_rdsys(AU1000_SYS_CNTRCTRL) & CNTR_OK))
116115
goto cntr_err;
117116

118117
/*
119118
* setup counter 1 (RTC) to tick at full speed
120119
*/
121120
t = 0xffffff;
122-
while ((au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_T1S) && --t)
121+
while ((alchemy_rdsys(AU1000_SYS_CNTRCTRL) & SYS_CNTRL_T1S) && --t)
123122
asm volatile ("nop");
124123
if (!t)
125124
goto cntr_err;
126125

127-
au_writel(0, SYS_RTCTRIM); /* 32.768 kHz */
128-
au_sync();
126+
alchemy_wrsys(0, AU1000_SYS_RTCTRIM); /* 32.768 kHz */
129127

130128
t = 0xffffff;
131-
while ((au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_C1S) && --t)
129+
while ((alchemy_rdsys(AU1000_SYS_CNTRCTRL) & SYS_CNTRL_C1S) && --t)
132130
asm volatile ("nop");
133131
if (!t)
134132
goto cntr_err;
135-
au_writel(0, SYS_RTCWRITE);
136-
au_sync();
133+
alchemy_wrsys(0, AU1000_SYS_RTCWRITE);
137134

138135
t = 0xffffff;
139-
while ((au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_C1S) && --t)
136+
while ((alchemy_rdsys(AU1000_SYS_CNTRCTRL) & SYS_CNTRL_C1S) && --t)
140137
asm volatile ("nop");
141138
if (!t)
142139
goto cntr_err;

‎arch/mips/alchemy/devboards/db1000.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,9 @@ int __init db1000_dev_setup(void)
518518
gpio_direction_input(20); /* sd1 cd# */
519519

520520
/* spi_gpio on SSI0 pins */
521-
pfc = __raw_readl((void __iomem *)SYS_PINFUNC);
521+
pfc = alchemy_rdsys(AU1000_SYS_PINFUNC);
522522
pfc |= (1 << 0); /* SSI0 pins as GPIOs */
523-
__raw_writel(pfc, (void __iomem *)SYS_PINFUNC);
524-
wmb();
523+
alchemy_wrsys(pfc, AU1000_SYS_PINFUNC);
525524

526525
spi_register_board_info(db1100_spi_info,
527526
ARRAY_SIZE(db1100_spi_info));

‎arch/mips/alchemy/devboards/db1200.c‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,11 @@ int __init db1200_board_setup(void)
150150
(whoami >> 4) & 0xf, (whoami >> 8) & 0xf, whoami & 0xf);
151151

152152
/* SMBus/SPI on PSC0, Audio on PSC1 */
153-
pfc = __raw_readl((void __iomem *)SYS_PINFUNC);
153+
pfc = alchemy_rdsys(AU1000_SYS_PINFUNC);
154154
pfc &= ~(SYS_PINFUNC_P0A | SYS_PINFUNC_P0B);
155155
pfc &= ~(SYS_PINFUNC_P1A | SYS_PINFUNC_P1B | SYS_PINFUNC_FS3);
156156
pfc |= SYS_PINFUNC_P1C; /* SPI is configured later */
157-
__raw_writel(pfc, (void __iomem *)SYS_PINFUNC);
158-
wmb();
157+
alchemy_wrsys(pfc, AU1000_SYS_PINFUNC);
159158

160159
/* Clock configurations: PSC0: ~50MHz via Clkgen0, derived from
161160
* CPU clock; all other clock generators off/unused.
@@ -166,16 +165,13 @@ int __init db1200_board_setup(void)
166165
div = ((div >> 1) - 1) & 0xff;
167166

168167
freq0 = div << SYS_FC_FRDIV0_BIT;
169-
__raw_writel(freq0, (void __iomem *)SYS_FREQCTRL0);
170-
wmb();
168+
alchemy_wrsys(freq0, AU1000_SYS_FREQCTRL0);
171169
freq0 |= SYS_FC_FE0; /* enable F0 */
172-
__raw_writel(freq0, (void __iomem *)SYS_FREQCTRL0);
173-
wmb();
170+
alchemy_wrsys(freq0, AU1000_SYS_FREQCTRL0);
174171

175172
/* psc0_intclk comes 1:1 from F0 */
176173
clksrc = SYS_CS_MUX_FQ0 << SYS_CS_ME0_BIT;
177-
__raw_writel(clksrc, (void __iomem *)SYS_CLKSRC);
178-
wmb();
174+
alchemy_wrsys(clksrc, AU1000_SYS_CLKSRC);
179175

180176
return 0;
181177
}
@@ -886,7 +882,7 @@ int __init db1200_dev_setup(void)
886882
* As a result, in SPI mode, OTG simply won't work (PSC0 uses
887883
* it as an input pin which is pulled high on the boards).
888884
*/
889-
pfc = __raw_readl((void __iomem *)SYS_PINFUNC) & ~SYS_PINFUNC_P0A;
885+
pfc = alchemy_rdsys(AU1000_SYS_PINFUNC) & ~SYS_PINFUNC_P0A;
890886

891887
/* switch off OTG VBUS supply */
892888
gpio_request(215, "otg-vbus");
@@ -912,8 +908,7 @@ int __init db1200_dev_setup(void)
912908
printk(KERN_INFO " S6.8 ON : PSC0 mode SPI\n");
913909
printk(KERN_INFO " OTG port VBUS supply disabled\n");
914910
}
915-
__raw_writel(pfc, (void __iomem *)SYS_PINFUNC);
916-
wmb();
911+
alchemy_wrsys(pfc, AU1000_SYS_PINFUNC);
917912

918913
/* Audio: DIP7 selects I2S(0)/AC97(1), but need I2C for I2S!
919914
* so: DIP7=1 || DIP8=0 => AC97, DIP7=0 && DIP8=1 => I2S

‎arch/mips/alchemy/devboards/db1550.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@
3131
static void __init db1550_hw_setup(void)
3232
{
3333
void __iomem *base;
34+
unsigned long v;
3435

3536
/* complete SPI setup: link psc0_intclk to a 48MHz source,
3637
* and assign GPIO16 to PSC0_SYNC1 (SPI cs# line) as well as PSC1_SYNC
3738
* for AC97 on PB1550.
3839
*/
39-
base = (void __iomem *)SYS_CLKSRC;
40-
__raw_writel(__raw_readl(base) | 0x000001e0, base);
41-
base = (void __iomem *)SYS_PINFUNC;
42-
__raw_writel(__raw_readl(base) | 1 | SYS_PF_PSC1_S1, base);
43-
wmb();
40+
v = alchemy_rdsys(AU1000_SYS_CLKSRC);
41+
alchemy_wrsys(v | 0x000001e0, AU1000_SYS_CLKSRC);
42+
v = alchemy_rdsys(AU1000_SYS_PINFUNC);
43+
alchemy_wrsys(v | 1 | SYS_PF_PSC1_S1, AU1000_SYS_PINFUNC);
4444

4545
/* reset the AC97 codec now, the reset time in the psc-ac97 driver
4646
* is apparently too short although it's ridiculous as it is.

0 commit comments

Comments
 (0)