Skip to content

Commit e5abf78

Browse files
committed
unicore32 io: redefine __REG(x) and re-use readl/writel funcs
-- by advice of Arnd Bergmann Signed-off-by: Guan Xuetao <gxt@mprc.pku.edu.cn> Reviewed-by: Arnd Bergmann <arnd@arndb.de>
1 parent 4517366 commit e5abf78

13 files changed

Lines changed: 171 additions & 164 deletions

File tree

‎arch/unicore32/include/asm/gpio.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef __UNICORE_GPIO_H__
1414
#define __UNICORE_GPIO_H__
1515

16+
#include <linux/io.h>
1617
#include <asm/irq.h>
1718
#include <mach/hardware.h>
1819
#include <asm-generic/gpio.h>
@@ -66,7 +67,7 @@
6667
static inline int gpio_get_value(unsigned gpio)
6768
{
6869
if (__builtin_constant_p(gpio) && (gpio <= GPIO_MAX))
69-
return GPIO_GPLR & GPIO_GPIO(gpio);
70+
return readl(GPIO_GPLR) & GPIO_GPIO(gpio);
7071
else
7172
return __gpio_get_value(gpio);
7273
}
@@ -75,9 +76,9 @@ static inline void gpio_set_value(unsigned gpio, int value)
7576
{
7677
if (__builtin_constant_p(gpio) && (gpio <= GPIO_MAX))
7778
if (value)
78-
GPIO_GPSR = GPIO_GPIO(gpio);
79+
writel(GPIO_GPIO(gpio), GPIO_GPSR);
7980
else
80-
GPIO_GPCR = GPIO_GPIO(gpio);
81+
writel(GPIO_GPIO(gpio), GPIO_GPCR);
8182
else
8283
__gpio_set_value(gpio, value);
8384
}
@@ -86,7 +87,7 @@ static inline void gpio_set_value(unsigned gpio, int value)
8687

8788
static inline unsigned gpio_to_irq(unsigned gpio)
8889
{
89-
if ((gpio < IRQ_GPIOHIGH) && (FIELD(1, 1, gpio) & GPIO_GPIR))
90+
if ((gpio < IRQ_GPIOHIGH) && (FIELD(1, 1, gpio) & readl(GPIO_GPIR)))
9091
return IRQ_GPIOLOW0 + gpio;
9192
else
9293
return IRQ_GPIO0 + gpio;

‎arch/unicore32/include/mach/dma.h‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ extern int puv3_request_dma(char *name,
3535

3636
extern void puv3_free_dma(int dma_ch);
3737

38-
#define puv3_stop_dma(ch) (DMAC_CONFIG(ch) &= ~DMAC_CONFIG_EN)
39-
#define puv3_resume_dma(ch) (DMAC_CONFIG(ch) |= DMAC_CONFIG_EN)
38+
static inline void puv3_stop_dma(int ch)
39+
{
40+
writel(readl(DMAC_CONFIG(ch)) & ~DMAC_CONFIG_EN, DMAC_CONFIG(ch));
41+
}
42+
43+
static inline void puv3_resume_dma(int ch)
44+
{
45+
writel(readl(DMAC_CONFIG(ch)) | DMAC_CONFIG_EN, DMAC_CONFIG(ch));
46+
}
4047

4148
#endif /* __MACH_PUV3_DMA_H__ */

‎arch/unicore32/include/mach/hardware.h‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,7 @@
2222

2323
#ifndef __ASSEMBLY__
2424

25-
# define __REG(x) (*((volatile unsigned long *)io_p2v(x)))
26-
# define __PREG(x) (io_v2p((unsigned long)&(x)))
27-
28-
#else
29-
30-
# define __REG(x) io_p2v(x)
31-
# define __PREG(x) io_v2p(x)
25+
# define __REG(x) (void __iomem *)io_p2v(x)
3226

3327
#endif
3428

‎arch/unicore32/kernel/clock.c‎

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/clk.h>
2121
#include <linux/mutex.h>
2222
#include <linux/delay.h>
23+
#include <linux/io.h>
2324

2425
#include <mach/hardware.h>
2526

@@ -152,28 +153,29 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
152153
if (ret)
153154
return ret;
154155

155-
if (PM_PLLVGACFG == pll_vgacfg)
156+
if (readl(PM_PLLVGACFG) == pll_vgacfg)
156157
return 0;
157158

158159
/* set pll vga cfg reg. */
159-
PM_PLLVGACFG = pll_vgacfg;
160+
writel(pll_vgacfg, PM_PLLVGACFG);
160161

161-
PM_PMCR = PM_PMCR_CFBVGA;
162-
while ((PM_PLLDFCDONE & PM_PLLDFCDONE_VGADFC)
162+
writel(PM_PMCR_CFBVGA, PM_PMCR);
163+
while ((readl(PM_PLLDFCDONE) & PM_PLLDFCDONE_VGADFC)
163164
!= PM_PLLDFCDONE_VGADFC)
164165
udelay(100); /* about 1ms */
165166

166167
/* set div cfg reg. */
167-
PM_PCGR |= PM_PCGR_VGACLK;
168+
writel(readl(PM_PCGR) | PM_PCGR_VGACLK, PM_PCGR);
168169

169-
PM_DIVCFG = (PM_DIVCFG & ~PM_DIVCFG_VGACLK_MASK)
170-
| PM_DIVCFG_VGACLK(pll_vgadiv);
170+
writel((readl(PM_DIVCFG) & ~PM_DIVCFG_VGACLK_MASK)
171+
| PM_DIVCFG_VGACLK(pll_vgadiv), PM_DIVCFG);
171172

172-
PM_SWRESET |= PM_SWRESET_VGADIV;
173-
while ((PM_SWRESET & PM_SWRESET_VGADIV) == PM_SWRESET_VGADIV)
173+
writel(readl(PM_SWRESET) | PM_SWRESET_VGADIV, PM_SWRESET);
174+
while ((readl(PM_SWRESET) & PM_SWRESET_VGADIV)
175+
== PM_SWRESET_VGADIV)
174176
udelay(100); /* 65536 bclk32, about 320us */
175177

176-
PM_PCGR &= ~PM_PCGR_VGACLK;
178+
writel(readl(PM_PCGR) & ~PM_PCGR_VGACLK, PM_PCGR);
177179
}
178180
#ifdef CONFIG_CPU_FREQ
179181
if (clk == &clk_mclk_clk) {
@@ -323,15 +325,15 @@ struct {
323325
static int __init clk_init(void)
324326
{
325327
#ifdef CONFIG_PUV3_PM
326-
u32 pllrate, divstatus = PM_DIVSTATUS;
327-
u32 pcgr_val = PM_PCGR;
328+
u32 pllrate, divstatus = readl(PM_DIVSTATUS);
329+
u32 pcgr_val = readl(PM_PCGR);
328330
int i;
329331

330332
pcgr_val |= PM_PCGR_BCLKMME | PM_PCGR_BCLKH264E | PM_PCGR_BCLKH264D
331333
| PM_PCGR_HECLK | PM_PCGR_HDCLK;
332-
PM_PCGR = pcgr_val;
334+
writel(pcgr_val, PM_PCGR);
333335

334-
pllrate = PM_PLLSYSSTATUS;
336+
pllrate = readl(PM_PLLSYSSTATUS);
335337

336338
/* lookup pmclk_table */
337339
clk_mclk_clk.rate = 0;
@@ -346,7 +348,7 @@ static int __init clk_init(void)
346348
clk_bclk32_clk.rate = clk_mclk_clk.rate /
347349
(((divstatus & 0x0000f000) >> 12) + 1);
348350

349-
pllrate = PM_PLLDDRSTATUS;
351+
pllrate = readl(PM_PLLDDRSTATUS);
350352

351353
/* lookup pddr_table */
352354
clk_ddr_clk.rate = 0;
@@ -357,7 +359,7 @@ static int __init clk_init(void)
357359
}
358360
}
359361

360-
pllrate = PM_PLLVGASTATUS;
362+
pllrate = readl(PM_PLLVGASTATUS);
361363

362364
/* lookup pvga_table */
363365
clk_vga_clk.rate = 0;

‎arch/unicore32/kernel/dma.c‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/kernel.h>
1717
#include <linux/interrupt.h>
1818
#include <linux/errno.h>
19+
#include <linux/io.h>
1920

2021
#include <asm/system.h>
2122
#include <asm/irq.h>
@@ -94,15 +95,16 @@ EXPORT_SYMBOL(puv3_free_dma);
9495

9596
static irqreturn_t dma_irq_handler(int irq, void *dev_id)
9697
{
97-
int i, dint = DMAC_ITCSR;
98+
int i, dint;
9899

100+
dint = readl(DMAC_ITCSR);
99101
for (i = 0; i < MAX_DMA_CHANNELS; i++) {
100102
if (dint & DMAC_CHANNEL(i)) {
101103
struct dma_channel *channel = &dma_channels[i];
102104

103105
/* Clear TC interrupt of channel i */
104-
DMAC_ITCCR = DMAC_CHANNEL(i);
105-
DMAC_ITCCR = 0;
106+
writel(DMAC_CHANNEL(i), DMAC_ITCCR);
107+
writel(0, DMAC_ITCCR);
106108

107109
if (channel->name && channel->irq_handler) {
108110
channel->irq_handler(i, channel->data);
@@ -121,15 +123,16 @@ static irqreturn_t dma_irq_handler(int irq, void *dev_id)
121123

122124
static irqreturn_t dma_err_handler(int irq, void *dev_id)
123125
{
124-
int i, dint = DMAC_IESR;
126+
int i, dint;
125127

128+
dint = readl(DMAC_IESR);
126129
for (i = 0; i < MAX_DMA_CHANNELS; i++) {
127130
if (dint & DMAC_CHANNEL(i)) {
128131
struct dma_channel *channel = &dma_channels[i];
129132

130133
/* Clear Err interrupt of channel i */
131-
DMAC_IECR = DMAC_CHANNEL(i);
132-
DMAC_IECR = 0;
134+
writel(DMAC_CHANNEL(i), DMAC_IECR);
135+
writel(0, DMAC_IECR);
133136

134137
if (channel->name && channel->err_handler) {
135138
channel->err_handler(i, channel->data);

‎arch/unicore32/kernel/gpio.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,23 @@ device_initcall(puv3_gpio_leds_init);
5252

5353
static int puv3_gpio_get(struct gpio_chip *chip, unsigned offset)
5454
{
55-
return GPIO_GPLR & GPIO_GPIO(offset);
55+
return readl(GPIO_GPLR) & GPIO_GPIO(offset);
5656
}
5757

5858
static void puv3_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
5959
{
6060
if (value)
61-
GPIO_GPSR = GPIO_GPIO(offset);
61+
writel(GPIO_GPIO(offset), GPIO_GPSR);
6262
else
63-
GPIO_GPCR = GPIO_GPIO(offset);
63+
writel(GPIO_GPIO(offset), GPIO_GPCR);
6464
}
6565

6666
static int puv3_direction_input(struct gpio_chip *chip, unsigned offset)
6767
{
6868
unsigned long flags;
6969

7070
local_irq_save(flags);
71-
GPIO_GPDR &= ~GPIO_GPIO(offset);
71+
writel(readl(GPIO_GPDR) & ~GPIO_GPIO(offset), GPIO_GPDR);
7272
local_irq_restore(flags);
7373
return 0;
7474
}
@@ -80,7 +80,7 @@ static int puv3_direction_output(struct gpio_chip *chip, unsigned offset,
8080

8181
local_irq_save(flags);
8282
puv3_gpio_set(chip, offset, value);
83-
GPIO_GPDR |= GPIO_GPIO(offset);
83+
writel(readl(GPIO_GPDR) | GPIO_GPIO(offset), GPIO_GPDR);
8484
local_irq_restore(flags);
8585
return 0;
8686
}
@@ -97,7 +97,7 @@ static struct gpio_chip puv3_gpio_chip = {
9797

9898
void __init puv3_init_gpio(void)
9999
{
100-
GPIO_GPDR = GPIO_DIR;
100+
writel(GPIO_DIR, GPIO_GPDR);
101101
#if defined(CONFIG_PUV3_NB0916) || defined(CONFIG_PUV3_SMW0919) \
102102
|| defined(CONFIG_PUV3_DB0913)
103103
gpio_set_value(GPO_WIFI_EN, 1);

0 commit comments

Comments
 (0)