Skip to content

Commit 9cf1216

Browse files
mlauss2ralfbaechle
authored andcommitted
MIPS: Alchemy: add helpers to access static memory ctrl registers.
This patch changes the static memory controller registers to offsets from base, prefixes them with AU1000_ to avoid silent failures due to changed addresses and introduces helpers to access 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/7463/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent 1d09de7 commit 9cf1216

6 files changed

Lines changed: 62 additions & 52 deletions

File tree

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,18 @@ static void save_core_regs(void)
6464
sleep_sys_pinfunc = alchemy_rdsys(AU1000_SYS_PINFUNC);
6565

6666
/* Save the static memory controller configuration. */
67-
sleep_static_memctlr[0][0] = au_readl(MEM_STCFG0);
68-
sleep_static_memctlr[0][1] = au_readl(MEM_STTIME0);
69-
sleep_static_memctlr[0][2] = au_readl(MEM_STADDR0);
70-
sleep_static_memctlr[1][0] = au_readl(MEM_STCFG1);
71-
sleep_static_memctlr[1][1] = au_readl(MEM_STTIME1);
72-
sleep_static_memctlr[1][2] = au_readl(MEM_STADDR1);
73-
sleep_static_memctlr[2][0] = au_readl(MEM_STCFG2);
74-
sleep_static_memctlr[2][1] = au_readl(MEM_STTIME2);
75-
sleep_static_memctlr[2][2] = au_readl(MEM_STADDR2);
76-
sleep_static_memctlr[3][0] = au_readl(MEM_STCFG3);
77-
sleep_static_memctlr[3][1] = au_readl(MEM_STTIME3);
78-
sleep_static_memctlr[3][2] = au_readl(MEM_STADDR3);
67+
sleep_static_memctlr[0][0] = alchemy_rdsmem(AU1000_MEM_STCFG0);
68+
sleep_static_memctlr[0][1] = alchemy_rdsmem(AU1000_MEM_STTIME0);
69+
sleep_static_memctlr[0][2] = alchemy_rdsmem(AU1000_MEM_STADDR0);
70+
sleep_static_memctlr[1][0] = alchemy_rdsmem(AU1000_MEM_STCFG1);
71+
sleep_static_memctlr[1][1] = alchemy_rdsmem(AU1000_MEM_STTIME1);
72+
sleep_static_memctlr[1][2] = alchemy_rdsmem(AU1000_MEM_STADDR1);
73+
sleep_static_memctlr[2][0] = alchemy_rdsmem(AU1000_MEM_STCFG2);
74+
sleep_static_memctlr[2][1] = alchemy_rdsmem(AU1000_MEM_STTIME2);
75+
sleep_static_memctlr[2][2] = alchemy_rdsmem(AU1000_MEM_STADDR2);
76+
sleep_static_memctlr[3][0] = alchemy_rdsmem(AU1000_MEM_STCFG3);
77+
sleep_static_memctlr[3][1] = alchemy_rdsmem(AU1000_MEM_STTIME3);
78+
sleep_static_memctlr[3][2] = alchemy_rdsmem(AU1000_MEM_STADDR3);
7979
}
8080

8181
static void restore_core_regs(void)
@@ -95,18 +95,18 @@ static void restore_core_regs(void)
9595
alchemy_wrsys(sleep_sys_pinfunc, AU1000_SYS_PINFUNC);
9696

9797
/* Restore the static memory controller configuration. */
98-
au_writel(sleep_static_memctlr[0][0], MEM_STCFG0);
99-
au_writel(sleep_static_memctlr[0][1], MEM_STTIME0);
100-
au_writel(sleep_static_memctlr[0][2], MEM_STADDR0);
101-
au_writel(sleep_static_memctlr[1][0], MEM_STCFG1);
102-
au_writel(sleep_static_memctlr[1][1], MEM_STTIME1);
103-
au_writel(sleep_static_memctlr[1][2], MEM_STADDR1);
104-
au_writel(sleep_static_memctlr[2][0], MEM_STCFG2);
105-
au_writel(sleep_static_memctlr[2][1], MEM_STTIME2);
106-
au_writel(sleep_static_memctlr[2][2], MEM_STADDR2);
107-
au_writel(sleep_static_memctlr[3][0], MEM_STCFG3);
108-
au_writel(sleep_static_memctlr[3][1], MEM_STTIME3);
109-
au_writel(sleep_static_memctlr[3][2], MEM_STADDR3);
98+
alchemy_wrsmem(sleep_static_memctlr[0][0], AU1000_MEM_STCFG0);
99+
alchemy_wrsmem(sleep_static_memctlr[0][1], AU1000_MEM_STTIME0);
100+
alchemy_wrsmem(sleep_static_memctlr[0][2], AU1000_MEM_STADDR0);
101+
alchemy_wrsmem(sleep_static_memctlr[1][0], AU1000_MEM_STCFG1);
102+
alchemy_wrsmem(sleep_static_memctlr[1][1], AU1000_MEM_STTIME1);
103+
alchemy_wrsmem(sleep_static_memctlr[1][2], AU1000_MEM_STADDR1);
104+
alchemy_wrsmem(sleep_static_memctlr[2][0], AU1000_MEM_STCFG2);
105+
alchemy_wrsmem(sleep_static_memctlr[2][1], AU1000_MEM_STTIME2);
106+
alchemy_wrsmem(sleep_static_memctlr[2][2], AU1000_MEM_STADDR2);
107+
alchemy_wrsmem(sleep_static_memctlr[3][0], AU1000_MEM_STCFG3);
108+
alchemy_wrsmem(sleep_static_memctlr[3][1], AU1000_MEM_STTIME3);
109+
alchemy_wrsmem(sleep_static_memctlr[3][2], AU1000_MEM_STADDR3);
110110
}
111111

112112
void au_sleep(void)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ static void au1200_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
246246

247247
static int au1200_nand_device_ready(struct mtd_info *mtd)
248248
{
249-
return __raw_readl((void __iomem *)MEM_STSTAT) & 1;
249+
return alchemy_rdsmem(AU1000_MEM_STSTAT) & 1;
250250
}
251251

252252
static struct mtd_partition db1200_nand_parts[] = {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static void au1300_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
169169

170170
static int au1300_nand_device_ready(struct mtd_info *mtd)
171171
{
172-
return __raw_readl((void __iomem *)MEM_STSTAT) & 1;
172+
return alchemy_rdsmem(AU1000_MEM_STSTAT) & 1;
173173
}
174174

175175
static struct mtd_partition db1300_nand_parts[] = {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static void au1550_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
151151

152152
static int au1550_nand_device_ready(struct mtd_info *mtd)
153153
{
154-
return __raw_readl((void __iomem *)MEM_STSTAT) & 1;
154+
return alchemy_rdsmem(AU1000_MEM_STSTAT) & 1;
155155
}
156156

157157
static struct mtd_partition db1550_nand_parts[] = {
@@ -217,7 +217,7 @@ static struct platform_device pb1550_nand_dev = {
217217

218218
static void __init pb1550_nand_setup(void)
219219
{
220-
int boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) |
220+
int boot_swapboot = (alchemy_rdsmem(AU1000_MEM_STSTAT) & (0x7 << 1)) |
221221
((bcsr_read(BCSR_STATUS) >> 6) & 0x1);
222222

223223
gpio_direction_input(206); /* de-assert NAND CS# */

‎arch/mips/include/asm/mach-au1x00/au1000.h‎

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -309,25 +309,21 @@
309309
#define AU1550_MEM_SDSREF 0x08D0
310310
#define AU1550_MEM_SDSLEEP MEM_SDSREF
311311

312-
/* Static Bus Controller */
313-
#define MEM_STCFG0 0xB4001000
314-
#define MEM_STTIME0 0xB4001004
315-
#define MEM_STADDR0 0xB4001008
316-
317-
#define MEM_STCFG1 0xB4001010
318-
#define MEM_STTIME1 0xB4001014
319-
#define MEM_STADDR1 0xB4001018
320-
321-
#define MEM_STCFG2 0xB4001020
322-
#define MEM_STTIME2 0xB4001024
323-
#define MEM_STADDR2 0xB4001028
324-
325-
#define MEM_STCFG3 0xB4001030
326-
#define MEM_STTIME3 0xB4001034
327-
#define MEM_STADDR3 0xB4001038
328-
329-
#define MEM_STNDCTL 0xB4001100
330-
#define MEM_STSTAT 0xB4001104
312+
/* Static Bus Controller register offsets */
313+
#define AU1000_MEM_STCFG0 0x000
314+
#define AU1000_MEM_STTIME0 0x004
315+
#define AU1000_MEM_STADDR0 0x008
316+
#define AU1000_MEM_STCFG1 0x010
317+
#define AU1000_MEM_STTIME1 0x014
318+
#define AU1000_MEM_STADDR1 0x018
319+
#define AU1000_MEM_STCFG2 0x020
320+
#define AU1000_MEM_STTIME2 0x024
321+
#define AU1000_MEM_STADDR2 0x028
322+
#define AU1000_MEM_STCFG3 0x030
323+
#define AU1000_MEM_STTIME3 0x034
324+
#define AU1000_MEM_STADDR3 0x038
325+
#define AU1000_MEM_STNDCTL 0x100
326+
#define AU1000_MEM_STSTAT 0x104
331327

332328
#define MEM_STNAND_CMD 0x0
333329
#define MEM_STNAND_ADDR 0x4
@@ -713,6 +709,22 @@ static inline void alchemy_wrsys(unsigned long v, int regofs)
713709
wmb(); /* drain writebuffer */
714710
}
715711

712+
/* helpers to access static memctrl registers */
713+
static inline unsigned long alchemy_rdsmem(int regofs)
714+
{
715+
void __iomem *b = (void __iomem *)KSEG1ADDR(AU1000_STATIC_MEM_PHYS_ADDR);
716+
717+
return __raw_readl(b + regofs);
718+
}
719+
720+
static inline void alchemy_wrsmem(unsigned long v, int regofs)
721+
{
722+
void __iomem *b = (void __iomem *)KSEG1ADDR(AU1000_STATIC_MEM_PHYS_ADDR);
723+
724+
__raw_writel(v, b + regofs);
725+
wmb(); /* drain writebuffer */
726+
}
727+
716728
/* Early Au1000 have a write-only SYS_CPUPLL register. */
717729
static inline int au1xxx_cpu_has_pll_wo(void)
718730
{

‎drivers/mtd/nand/au1550nd.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,12 @@ static void au1550_hwcontrol(struct mtd_info *mtd, int cmd)
223223

224224
case NAND_CTL_SETNCE:
225225
/* assert (force assert) chip enable */
226-
au_writel((1 << (4 + ctx->cs)), MEM_STNDCTL);
226+
alchemy_wrsmem((1 << (4 + ctx->cs)), AU1000_MEM_STNDCTL);
227227
break;
228228

229229
case NAND_CTL_CLRNCE:
230230
/* deassert chip enable */
231-
au_writel(0, MEM_STNDCTL);
231+
alchemy_wrsmem(0, AU1000_MEM_STNDCTL);
232232
break;
233233
}
234234

@@ -240,9 +240,7 @@ static void au1550_hwcontrol(struct mtd_info *mtd, int cmd)
240240

241241
int au1550_device_ready(struct mtd_info *mtd)
242242
{
243-
int ret = (au_readl(MEM_STSTAT) & 0x1) ? 1 : 0;
244-
au_sync();
245-
return ret;
243+
return (alchemy_rdsmem(AU1000_MEM_STSTAT) & 0x1) ? 1 : 0;
246244
}
247245

248246
/**

0 commit comments

Comments
 (0)