Hi Daniel, Thomas,
Update h8300 clocksource / clockevents driver
Changes bellow
h8300_timer8.c:
Cleanup set_next_event handler.
Use ioread / iowrite functions.
h8300_timer16.c:
Overflow handling fix.
Use ioread / iowrite functions.
h8300_tpu.c:
Use ioread / iowrite functions.
Thanks.
Yoshinori Sato (5):
clocksource: h8300: Change to overflow interrupt
clocksource: h8300: Fix timer not overflow case
clocksource: h8300: Simplify delta handling
clocksource: h8300: Initializer cleanup.
clocksource: h8300: Use ioread / iowrite
drivers/clocksource/h8300_timer16.c | 48 ++++++++++++-------------
drivers/clocksource/h8300_timer8.c | 70 +++++++++++--------------------------
drivers/clocksource/h8300_tpu.c | 22 ++++++------
3 files changed, 56 insertions(+), 84 deletions(-)
--
2.6.1
Counter overflow detection use for overflow interrupt
Signed-off-by: Yoshinori Sato <[email protected]>
---
drivers/clocksource/h8300_timer16.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/clocksource/h8300_timer16.c b/drivers/clocksource/h8300_timer16.c
index fc14a3f..b14a8da 100644
--- a/drivers/clocksource/h8300_timer16.c
+++ b/drivers/clocksource/h8300_timer16.c
@@ -14,7 +14,6 @@
#include <linux/of_irq.h>
#define TSTR 0
-#define TISRA 4
#define TISRC 6
#define TCR 0
@@ -27,9 +26,8 @@ struct timer16_priv {
void __iomem *mapcommon;
unsigned short cs_enabled;
unsigned char enb;
- unsigned char imfa;
- unsigned char imiea;
unsigned char ovf;
+ unsigned char ovie;
struct clk *clk;
};
@@ -59,8 +57,8 @@ static irqreturn_t timer16_interrupt(int irq, void *dev_id)
{
struct timer16_priv *p = (struct timer16_priv *)dev_id;
- writeb(readb(p->mapcommon + TISRA) & ~p->imfa,
- p->mapcommon + TISRA);
+ writeb(readb(p->mapcommon + TISRC) & ~p->ovf,
+ p->mapcommon + TISRC);
p->total_cycles += 0x10000;
return IRQ_HANDLED;
@@ -93,6 +91,8 @@ static int timer16_enable(struct clocksource *cs)
writeb(0x83, p->mapbase + TCR);
writeb(readb(p->mapcommon + TSTR) | p->enb,
p->mapcommon + TSTR);
+ writeb(readb(p->mapcommon + TISRC) | p->ovie,
+ p->mapcommon + TSTR);
p->cs_enabled = true;
return 0;
@@ -161,8 +161,8 @@ static void __init h8300_16timer_init(struct device_node *node)
timer16_priv.mapbase = base[REG_CH];
timer16_priv.mapcommon = base[REG_COMM];
timer16_priv.enb = 1 << ch;
- timer16_priv.imfa = 1 << ch;
- timer16_priv.imiea = 1 << (4 + ch);
+ timer16_priv.ovf = 1 << ch;
+ timer16_priv.ovie = 1 << (4 + ch);
ret = request_irq(irq, timer16_interrupt,
IRQF_TIMER, timer16_priv.cs.name, &timer16_priv);
--
2.6.1
Signed-off-by: Yoshinori Sato <[email protected]>
---
drivers/clocksource/h8300_timer16.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/clocksource/h8300_timer16.c b/drivers/clocksource/h8300_timer16.c
index b14a8da..934ed0b 100644
--- a/drivers/clocksource/h8300_timer16.c
+++ b/drivers/clocksource/h8300_timer16.c
@@ -48,8 +48,10 @@ static unsigned long timer16_get_counter(struct timer16_priv *p)
} while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3)
|| (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2)));
- v2 |= 0x10000;
- return v2;
+ if (likely(!o1))
+ return v2;
+ else
+ return v2 + 0x10000;
}
--
2.6.1
Signed-off-by: Yoshinori Sato <[email protected]>
---
drivers/clocksource/h8300_timer8.c | 40 ++++++--------------------------------
1 file changed, 6 insertions(+), 34 deletions(-)
diff --git a/drivers/clocksource/h8300_timer8.c b/drivers/clocksource/h8300_timer8.c
index aa4b2a98..1ba453b 100644
--- a/drivers/clocksource/h8300_timer8.c
+++ b/drivers/clocksource/h8300_timer8.c
@@ -36,57 +36,29 @@ struct timer8_priv {
unsigned int tcora;
};
-static unsigned long timer8_get_counter(struct timer8_priv *p)
-{
- unsigned long v1, v2, v3;
- int o1, o2;
-
- o1 = readb(p->mapbase + _8TCSR) & 0x20;
-
- /* Make sure the timer value is stable. Stolen from acpi_pm.c */
- do {
- o2 = o1;
- v1 = readw(p->mapbase + _8TCNT);
- v2 = readw(p->mapbase + _8TCNT);
- v3 = readw(p->mapbase + _8TCNT);
- o1 = readb(p->mapbase + _8TCSR) & 0x20;
- } while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3)
- || (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2)));
-
- v2 |= o1 << 10;
- return v2;
-}
-
static irqreturn_t timer8_interrupt(int irq, void *dev_id)
{
struct timer8_priv *p = dev_id;
- writeb(readb(p->mapbase + _8TCSR) & ~0x40,
- p->mapbase + _8TCSR);
-
- writew(p->tcora, p->mapbase + TCORA);
-
if (clockevent_state_oneshot(&p->ced))
writew(0x0000, p->mapbase + _8TCR);
p->ced.event_handler(&p->ced);
+ writeb(readb(p->mapbase + _8TCSR) & ~0x40,
+ p->mapbase + _8TCSR);
+
return IRQ_HANDLED;
}
static void timer8_set_next(struct timer8_priv *p, unsigned long delta)
{
- unsigned long now;
-
if (delta >= 0x10000)
pr_warn("delta out of range\n");
- now = timer8_get_counter(p);
- p->tcora = delta;
+ writeb(readb(p->mapbase + _8TCR) & ~0x40, p->mapbase + _8TCR);
+ writew(0, p->mapbase + _8TCNT);
+ writew(delta, p->mapbase + TCORA);
writeb(readb(p->mapbase + _8TCR) | 0x40, p->mapbase + _8TCR);
- if (delta > now)
- writew(delta, p->mapbase + TCORA);
- else
- writew(now + 1, p->mapbase + TCORA);
}
static int timer8_enable(struct timer8_priv *p)
--
2.6.1
Signed-off-by: Yoshinori Sato <[email protected]>
---
drivers/clocksource/h8300_timer8.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/clocksource/h8300_timer8.c b/drivers/clocksource/h8300_timer8.c
index 1ba453b..9087dd2 100644
--- a/drivers/clocksource/h8300_timer8.c
+++ b/drivers/clocksource/h8300_timer8.c
@@ -33,7 +33,6 @@ struct timer8_priv {
void __iomem *mapbase;
unsigned long flags;
unsigned int rate;
- unsigned int tcora;
};
static irqreturn_t timer8_interrupt(int irq, void *dev_id)
@@ -163,8 +162,6 @@ static void __init h8300_8timer_init(struct device_node *node)
{
void __iomem *base;
int irq;
- int ret = 0;
- int rate;
struct clk *clk;
clk = of_clk_get(node, 0);
@@ -187,20 +184,20 @@ static void __init h8300_8timer_init(struct device_node *node)
timer8_priv.mapbase = base;
- rate = clk_get_rate(clk) / SCALE;
- if (!rate) {
+ timer8_priv.rate = clk_get_rate(clk) / SCALE;
+ if (!timer8_priv.rate) {
pr_err("Failed to get rate for the clocksource\n");
goto unmap_reg;
}
- ret = request_irq(irq, timer8_interrupt,
- IRQF_TIMER, timer8_priv.ced.name, &timer8_priv);
- if (ret < 0) {
+ if (request_irq(irq, timer8_interrupt, IRQF_TIMER,
+ timer8_priv.ced.name, &timer8_priv) < 0) {
pr_err("failed to request irq %d for clockevent\n", irq);
goto unmap_reg;
}
- clockevents_config_and_register(&timer8_priv.ced, rate, 1, 0x0000ffff);
+ clockevents_config_and_register(&timer8_priv.ced,
+ timer8_priv.rate, 1, 0x0000ffff);
return;
unmap_reg:
--
2.6.1
Signed-off-by: Yoshinori Sato <[email protected]>
---
drivers/clocksource/h8300_timer16.c | 40 +++++++++++++++++--------------------
drivers/clocksource/h8300_timer8.c | 25 +++++++++++++----------
drivers/clocksource/h8300_tpu.c | 22 ++++++++++----------
3 files changed, 44 insertions(+), 43 deletions(-)
diff --git a/drivers/clocksource/h8300_timer16.c b/drivers/clocksource/h8300_timer16.c
index 934ed0b..e8a7d0f 100644
--- a/drivers/clocksource/h8300_timer16.c
+++ b/drivers/clocksource/h8300_timer16.c
@@ -28,23 +28,22 @@ struct timer16_priv {
unsigned char enb;
unsigned char ovf;
unsigned char ovie;
- struct clk *clk;
};
static unsigned long timer16_get_counter(struct timer16_priv *p)
{
- unsigned long v1, v2, v3;
- int o1, o2;
+ unsigned short v1, v2, v3;
+ unsigned char o1, o2;
- o1 = readb(p->mapcommon + TISRC) & p->ovf;
+ o1 = ioread8(p->mapcommon + TISRC) & p->ovf;
/* Make sure the timer value is stable. Stolen from acpi_pm.c */
do {
o2 = o1;
- v1 = readw(p->mapbase + TCNT);
- v2 = readw(p->mapbase + TCNT);
- v3 = readw(p->mapbase + TCNT);
- o1 = readb(p->mapcommon + TISRC) & p->ovf;
+ v1 = ioread16be(p->mapbase + TCNT);
+ v2 = ioread16be(p->mapbase + TCNT);
+ v3 = ioread16be(p->mapbase + TCNT);
+ o1 = ioread8(p->mapcommon + TISRC) & p->ovf;
} while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3)
|| (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2)));
@@ -59,8 +58,7 @@ static irqreturn_t timer16_interrupt(int irq, void *dev_id)
{
struct timer16_priv *p = (struct timer16_priv *)dev_id;
- writeb(readb(p->mapcommon + TISRC) & ~p->ovf,
- p->mapcommon + TISRC);
+ ctrl_bclr(p->ovf, p->mapcommon + TISRC);
p->total_cycles += 0x10000;
return IRQ_HANDLED;
@@ -89,12 +87,10 @@ static int timer16_enable(struct clocksource *cs)
WARN_ON(p->cs_enabled);
p->total_cycles = 0;
- writew(0x0000, p->mapbase + TCNT);
- writeb(0x83, p->mapbase + TCR);
- writeb(readb(p->mapcommon + TSTR) | p->enb,
- p->mapcommon + TSTR);
- writeb(readb(p->mapcommon + TISRC) | p->ovie,
- p->mapcommon + TSTR);
+ iowrite16be(0x0000, p->mapbase + TCNT);
+ iowrite8(0x83, p->mapbase + TCR);
+ ctrl_bset(p->ovie, p->mapcommon + TISRC);
+ ctrl_bset(p->enb, p->mapcommon + TSTR);
p->cs_enabled = true;
return 0;
@@ -106,8 +102,8 @@ static void timer16_disable(struct clocksource *cs)
WARN_ON(!p->cs_enabled);
- writeb(readb(p->mapcommon + TSTR) & ~p->enb,
- p->mapcommon + TSTR);
+ ctrl_bclr(p->ovie, p->mapcommon + TISRC);
+ ctrl_bclr(p->enb, p->mapcommon + TSTR);
p->cs_enabled = false;
}
@@ -162,9 +158,9 @@ static void __init h8300_16timer_init(struct device_node *node)
timer16_priv.mapbase = base[REG_CH];
timer16_priv.mapcommon = base[REG_COMM];
- timer16_priv.enb = 1 << ch;
- timer16_priv.ovf = 1 << ch;
- timer16_priv.ovie = 1 << (4 + ch);
+ timer16_priv.enb = ch;
+ timer16_priv.ovf = ch;
+ timer16_priv.ovie = 4 + ch;
ret = request_irq(irq, timer16_interrupt,
IRQF_TIMER, timer16_priv.cs.name, &timer16_priv);
@@ -174,7 +170,7 @@ static void __init h8300_16timer_init(struct device_node *node)
}
clocksource_register_hz(&timer16_priv.cs,
- clk_get_rate(timer16_priv.clk) / 8);
+ clk_get_rate(clk) / 8);
return;
unmap_comm:
diff --git a/drivers/clocksource/h8300_timer8.c b/drivers/clocksource/h8300_timer8.c
index 9087dd2..2279522 100644
--- a/drivers/clocksource/h8300_timer8.c
+++ b/drivers/clocksource/h8300_timer8.c
@@ -24,6 +24,9 @@
#define TCORB 6
#define _8TCNT 8
+#define CMIEA 6
+#define CMFA 6
+
#define FLAG_STARTED (1 << 3)
#define SCALE 64
@@ -40,12 +43,11 @@ static irqreturn_t timer8_interrupt(int irq, void *dev_id)
struct timer8_priv *p = dev_id;
if (clockevent_state_oneshot(&p->ced))
- writew(0x0000, p->mapbase + _8TCR);
+ iowrite16be(0x0000, p->mapbase + _8TCR);
p->ced.event_handler(&p->ced);
- writeb(readb(p->mapbase + _8TCSR) & ~0x40,
- p->mapbase + _8TCSR);
+ ctrl_bclr(CMFA, p->mapbase + _8TCSR);
return IRQ_HANDLED;
}
@@ -54,17 +56,18 @@ static void timer8_set_next(struct timer8_priv *p, unsigned long delta)
{
if (delta >= 0x10000)
pr_warn("delta out of range\n");
- writeb(readb(p->mapbase + _8TCR) & ~0x40, p->mapbase + _8TCR);
- writew(0, p->mapbase + _8TCNT);
- writew(delta, p->mapbase + TCORA);
- writeb(readb(p->mapbase + _8TCR) | 0x40, p->mapbase + _8TCR);
+ ctrl_bclr(CMIEA, p->mapbase + _8TCR);
+ iowrite16be(delta, p->mapbase + TCORA);
+ iowrite16be(0x0000, p->mapbase + _8TCNT);
+ ctrl_bclr(CMFA, p->mapbase + _8TCSR);
+ ctrl_bset(CMIEA, p->mapbase + _8TCR);
}
static int timer8_enable(struct timer8_priv *p)
{
- writew(0xffff, p->mapbase + TCORA);
- writew(0x0000, p->mapbase + _8TCNT);
- writew(0x0c02, p->mapbase + _8TCR);
+ iowrite16be(0xffff, p->mapbase + TCORA);
+ iowrite16be(0x0000, p->mapbase + _8TCNT);
+ iowrite16be(0x0c02, p->mapbase + _8TCR);
return 0;
}
@@ -85,7 +88,7 @@ static int timer8_start(struct timer8_priv *p)
static void timer8_stop(struct timer8_priv *p)
{
- writew(0x0000, p->mapbase + _8TCR);
+ iowrite16be(0x0000, p->mapbase + _8TCR);
}
static inline struct timer8_priv *ced_to_priv(struct clock_event_device *ced)
diff --git a/drivers/clocksource/h8300_tpu.c b/drivers/clocksource/h8300_tpu.c
index 91bf1992..d4c1a28 100644
--- a/drivers/clocksource/h8300_tpu.c
+++ b/drivers/clocksource/h8300_tpu.c
@@ -19,6 +19,8 @@
#define TSR 0x5
#define TCNT 0x6
+#define TCFV 0x10
+
struct tpu_priv {
struct clocksource cs;
void __iomem *mapbase1;
@@ -31,8 +33,8 @@ static inline unsigned long read_tcnt32(struct tpu_priv *p)
{
unsigned long tcnt;
- tcnt = readw(p->mapbase1 + TCNT) << 16;
- tcnt |= readw(p->mapbase2 + TCNT);
+ tcnt = ioread16be(p->mapbase1 + TCNT) << 16;
+ tcnt |= ioread16be(p->mapbase2 + TCNT);
return tcnt;
}
@@ -41,7 +43,7 @@ static int tpu_get_counter(struct tpu_priv *p, unsigned long long *val)
unsigned long v1, v2, v3;
int o1, o2;
- o1 = readb(p->mapbase1 + TSR) & 0x10;
+ o1 = ioread8(p->mapbase1 + TSR) & TCFV;
/* Make sure the timer value is stable. Stolen from acpi_pm.c */
do {
@@ -49,7 +51,7 @@ static int tpu_get_counter(struct tpu_priv *p, unsigned long long *val)
v1 = read_tcnt32(p);
v2 = read_tcnt32(p);
v3 = read_tcnt32(p);
- o1 = readb(p->mapbase1 + TSR) & 0x10;
+ o1 = ioread8(p->mapbase1 + TSR) & TCFV;
} while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3)
|| (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2)));
@@ -82,10 +84,10 @@ static int tpu_clocksource_enable(struct clocksource *cs)
WARN_ON(p->cs_enabled);
- writew(0, p->mapbase1 + TCNT);
- writew(0, p->mapbase2 + TCNT);
- writeb(0x0f, p->mapbase1 + TCR);
- writeb(0x03, p->mapbase2 + TCR);
+ iowrite16be(0, p->mapbase1 + TCNT);
+ iowrite16be(0, p->mapbase2 + TCNT);
+ iowrite8(0x0f, p->mapbase1 + TCR);
+ iowrite8(0x03, p->mapbase2 + TCR);
p->cs_enabled = true;
return 0;
@@ -97,8 +99,8 @@ static void tpu_clocksource_disable(struct clocksource *cs)
WARN_ON(!p->cs_enabled);
- writeb(0, p->mapbase1 + TCR);
- writeb(0, p->mapbase2 + TCR);
+ iowrite8(0, p->mapbase1 + TCR);
+ iowrite8(0, p->mapbase2 + TCR);
p->cs_enabled = false;
}
--
2.6.1
Hi Yoshinori,
[auto build test ERROR on daniel.lezcano/clockevents/next]
[also build test ERROR on next-20151203]
[cannot apply to uclinux-h8/h8300-next v4.4-rc3]
url: https://github.com/0day-ci/linux/commits/Yoshinori-Sato/clocksource-h8300-driver-update/20151204-201553
base: http://git.linaro.org/people/daniel.lezcano/linux clockevents/next
config: i386-allmodconfig (attached as .config)
reproduce:
# save the attached .config to linux build tree
make ARCH=i386
All errors (new ones prefixed by >>):
drivers/clocksource/h8300_timer8.c: In function 'timer8_interrupt':
>> drivers/clocksource/h8300_timer8.c:50:2: error: implicit declaration of function 'ctrl_bclr' [-Werror=implicit-function-declaration]
ctrl_bclr(CMFA, p->mapbase + _8TCSR);
^
drivers/clocksource/h8300_timer8.c: In function 'timer8_set_next':
>> drivers/clocksource/h8300_timer8.c:63:2: error: implicit declaration of function 'ctrl_bset' [-Werror=implicit-function-declaration]
ctrl_bset(CMIEA, p->mapbase + _8TCR);
^
cc1: some warnings being treated as errors
--
drivers/clocksource/h8300_timer16.c: In function 'timer16_interrupt':
>> drivers/clocksource/h8300_timer16.c:61:2: error: implicit declaration of function 'ctrl_bclr' [-Werror=implicit-function-declaration]
ctrl_bclr(p->ovf, p->mapcommon + TISRC);
^
drivers/clocksource/h8300_timer16.c: In function 'timer16_enable':
>> drivers/clocksource/h8300_timer16.c:92:2: error: implicit declaration of function 'ctrl_bset' [-Werror=implicit-function-declaration]
ctrl_bset(p->ovie, p->mapcommon + TISRC);
^
cc1: some warnings being treated as errors
vim +/ctrl_bclr +50 drivers/clocksource/h8300_timer8.c
44
45 if (clockevent_state_oneshot(&p->ced))
46 iowrite16be(0x0000, p->mapbase + _8TCR);
47
48 p->ced.event_handler(&p->ced);
49
> 50 ctrl_bclr(CMFA, p->mapbase + _8TCSR);
51
52 return IRQ_HANDLED;
53 }
54
55 static void timer8_set_next(struct timer8_priv *p, unsigned long delta)
56 {
57 if (delta >= 0x10000)
58 pr_warn("delta out of range\n");
59 ctrl_bclr(CMIEA, p->mapbase + _8TCR);
60 iowrite16be(delta, p->mapbase + TCORA);
61 iowrite16be(0x0000, p->mapbase + _8TCNT);
62 ctrl_bclr(CMFA, p->mapbase + _8TCSR);
> 63 ctrl_bset(CMIEA, p->mapbase + _8TCR);
64 }
65
66 static int timer8_enable(struct timer8_priv *p)
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Hi Daniel, Thomas,
Update h8300 clocksource / clockevents driver
Changes bellow
h8300_timer8.c:
Cleanup set_next_event handler.
Use ioread / iowrite functions.
h8300_timer16.c:
Overflow handling fix.
Use ioread / iowrite functions.
h8300_tpu.c:
Use ioread / iowrite functions.
Changes v2
Fix build error.
Thanks.
Yoshinori Sato (5):
clocksource: h8300: Change to overflow interrupt
clocksource: h8300: Fix timer not overflow case
clocksource: h8300: Simplify delta handling
clocksource: h8300: Initializer cleanup.
h8300: clocksource: Use ioread / iowrite
drivers/clocksource/h8300_timer16.c | 51 +++++++++++++-------------
drivers/clocksource/h8300_timer8.c | 73 ++++++++++++-------------------------
drivers/clocksource/h8300_tpu.c | 22 ++++++-----
3 files changed, 62 insertions(+), 84 deletions(-)
--
2.6.1
Counter overflow detection use for overflow interrupt
Signed-off-by: Yoshinori Sato <[email protected]>
---
drivers/clocksource/h8300_timer16.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/clocksource/h8300_timer16.c b/drivers/clocksource/h8300_timer16.c
index fc14a3f..b14a8da 100644
--- a/drivers/clocksource/h8300_timer16.c
+++ b/drivers/clocksource/h8300_timer16.c
@@ -14,7 +14,6 @@
#include <linux/of_irq.h>
#define TSTR 0
-#define TISRA 4
#define TISRC 6
#define TCR 0
@@ -27,9 +26,8 @@ struct timer16_priv {
void __iomem *mapcommon;
unsigned short cs_enabled;
unsigned char enb;
- unsigned char imfa;
- unsigned char imiea;
unsigned char ovf;
+ unsigned char ovie;
struct clk *clk;
};
@@ -59,8 +57,8 @@ static irqreturn_t timer16_interrupt(int irq, void *dev_id)
{
struct timer16_priv *p = (struct timer16_priv *)dev_id;
- writeb(readb(p->mapcommon + TISRA) & ~p->imfa,
- p->mapcommon + TISRA);
+ writeb(readb(p->mapcommon + TISRC) & ~p->ovf,
+ p->mapcommon + TISRC);
p->total_cycles += 0x10000;
return IRQ_HANDLED;
@@ -93,6 +91,8 @@ static int timer16_enable(struct clocksource *cs)
writeb(0x83, p->mapbase + TCR);
writeb(readb(p->mapcommon + TSTR) | p->enb,
p->mapcommon + TSTR);
+ writeb(readb(p->mapcommon + TISRC) | p->ovie,
+ p->mapcommon + TSTR);
p->cs_enabled = true;
return 0;
@@ -161,8 +161,8 @@ static void __init h8300_16timer_init(struct device_node *node)
timer16_priv.mapbase = base[REG_CH];
timer16_priv.mapcommon = base[REG_COMM];
timer16_priv.enb = 1 << ch;
- timer16_priv.imfa = 1 << ch;
- timer16_priv.imiea = 1 << (4 + ch);
+ timer16_priv.ovf = 1 << ch;
+ timer16_priv.ovie = 1 << (4 + ch);
ret = request_irq(irq, timer16_interrupt,
IRQF_TIMER, timer16_priv.cs.name, &timer16_priv);
--
2.6.1
Signed-off-by: Yoshinori Sato <[email protected]>
---
drivers/clocksource/h8300_timer16.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/clocksource/h8300_timer16.c b/drivers/clocksource/h8300_timer16.c
index b14a8da..934ed0b 100644
--- a/drivers/clocksource/h8300_timer16.c
+++ b/drivers/clocksource/h8300_timer16.c
@@ -48,8 +48,10 @@ static unsigned long timer16_get_counter(struct timer16_priv *p)
} while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3)
|| (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2)));
- v2 |= 0x10000;
- return v2;
+ if (likely(!o1))
+ return v2;
+ else
+ return v2 + 0x10000;
}
--
2.6.1
Signed-off-by: Yoshinori Sato <[email protected]>
---
drivers/clocksource/h8300_timer8.c | 40 ++++++--------------------------------
1 file changed, 6 insertions(+), 34 deletions(-)
diff --git a/drivers/clocksource/h8300_timer8.c b/drivers/clocksource/h8300_timer8.c
index aa4b2a98..1ba453b 100644
--- a/drivers/clocksource/h8300_timer8.c
+++ b/drivers/clocksource/h8300_timer8.c
@@ -36,57 +36,29 @@ struct timer8_priv {
unsigned int tcora;
};
-static unsigned long timer8_get_counter(struct timer8_priv *p)
-{
- unsigned long v1, v2, v3;
- int o1, o2;
-
- o1 = readb(p->mapbase + _8TCSR) & 0x20;
-
- /* Make sure the timer value is stable. Stolen from acpi_pm.c */
- do {
- o2 = o1;
- v1 = readw(p->mapbase + _8TCNT);
- v2 = readw(p->mapbase + _8TCNT);
- v3 = readw(p->mapbase + _8TCNT);
- o1 = readb(p->mapbase + _8TCSR) & 0x20;
- } while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3)
- || (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2)));
-
- v2 |= o1 << 10;
- return v2;
-}
-
static irqreturn_t timer8_interrupt(int irq, void *dev_id)
{
struct timer8_priv *p = dev_id;
- writeb(readb(p->mapbase + _8TCSR) & ~0x40,
- p->mapbase + _8TCSR);
-
- writew(p->tcora, p->mapbase + TCORA);
-
if (clockevent_state_oneshot(&p->ced))
writew(0x0000, p->mapbase + _8TCR);
p->ced.event_handler(&p->ced);
+ writeb(readb(p->mapbase + _8TCSR) & ~0x40,
+ p->mapbase + _8TCSR);
+
return IRQ_HANDLED;
}
static void timer8_set_next(struct timer8_priv *p, unsigned long delta)
{
- unsigned long now;
-
if (delta >= 0x10000)
pr_warn("delta out of range\n");
- now = timer8_get_counter(p);
- p->tcora = delta;
+ writeb(readb(p->mapbase + _8TCR) & ~0x40, p->mapbase + _8TCR);
+ writew(0, p->mapbase + _8TCNT);
+ writew(delta, p->mapbase + TCORA);
writeb(readb(p->mapbase + _8TCR) | 0x40, p->mapbase + _8TCR);
- if (delta > now)
- writew(delta, p->mapbase + TCORA);
- else
- writew(now + 1, p->mapbase + TCORA);
}
static int timer8_enable(struct timer8_priv *p)
--
2.6.1
Signed-off-by: Yoshinori Sato <[email protected]>
---
drivers/clocksource/h8300_timer8.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/clocksource/h8300_timer8.c b/drivers/clocksource/h8300_timer8.c
index 1ba453b..9087dd2 100644
--- a/drivers/clocksource/h8300_timer8.c
+++ b/drivers/clocksource/h8300_timer8.c
@@ -33,7 +33,6 @@ struct timer8_priv {
void __iomem *mapbase;
unsigned long flags;
unsigned int rate;
- unsigned int tcora;
};
static irqreturn_t timer8_interrupt(int irq, void *dev_id)
@@ -163,8 +162,6 @@ static void __init h8300_8timer_init(struct device_node *node)
{
void __iomem *base;
int irq;
- int ret = 0;
- int rate;
struct clk *clk;
clk = of_clk_get(node, 0);
@@ -187,20 +184,20 @@ static void __init h8300_8timer_init(struct device_node *node)
timer8_priv.mapbase = base;
- rate = clk_get_rate(clk) / SCALE;
- if (!rate) {
+ timer8_priv.rate = clk_get_rate(clk) / SCALE;
+ if (!timer8_priv.rate) {
pr_err("Failed to get rate for the clocksource\n");
goto unmap_reg;
}
- ret = request_irq(irq, timer8_interrupt,
- IRQF_TIMER, timer8_priv.ced.name, &timer8_priv);
- if (ret < 0) {
+ if (request_irq(irq, timer8_interrupt, IRQF_TIMER,
+ timer8_priv.ced.name, &timer8_priv) < 0) {
pr_err("failed to request irq %d for clockevent\n", irq);
goto unmap_reg;
}
- clockevents_config_and_register(&timer8_priv.ced, rate, 1, 0x0000ffff);
+ clockevents_config_and_register(&timer8_priv.ced,
+ timer8_priv.rate, 1, 0x0000ffff);
return;
unmap_reg:
--
2.6.1
Signed-off-by: Yoshinori Sato <[email protected]>
---
drivers/clocksource/h8300_timer16.c | 43 ++++++++++++++++++-------------------
drivers/clocksource/h8300_timer8.c | 28 ++++++++++++++----------
drivers/clocksource/h8300_tpu.c | 22 ++++++++++---------
3 files changed, 50 insertions(+), 43 deletions(-)
diff --git a/drivers/clocksource/h8300_timer16.c b/drivers/clocksource/h8300_timer16.c
index 934ed0b..657d1ce 100644
--- a/drivers/clocksource/h8300_timer16.c
+++ b/drivers/clocksource/h8300_timer16.c
@@ -19,6 +19,9 @@
#define TCR 0
#define TCNT 2
+#define bset(b, a) iowrite8(ioread8(a) | (1 << (b)), (a))
+#define bclr(b, a) iowrite8(ioread8(a) & ~(1 << (b)), (a))
+
struct timer16_priv {
struct clocksource cs;
unsigned long total_cycles;
@@ -28,23 +31,22 @@ struct timer16_priv {
unsigned char enb;
unsigned char ovf;
unsigned char ovie;
- struct clk *clk;
};
static unsigned long timer16_get_counter(struct timer16_priv *p)
{
- unsigned long v1, v2, v3;
- int o1, o2;
+ unsigned short v1, v2, v3;
+ unsigned char o1, o2;
- o1 = readb(p->mapcommon + TISRC) & p->ovf;
+ o1 = ioread8(p->mapcommon + TISRC) & p->ovf;
/* Make sure the timer value is stable. Stolen from acpi_pm.c */
do {
o2 = o1;
- v1 = readw(p->mapbase + TCNT);
- v2 = readw(p->mapbase + TCNT);
- v3 = readw(p->mapbase + TCNT);
- o1 = readb(p->mapcommon + TISRC) & p->ovf;
+ v1 = ioread16be(p->mapbase + TCNT);
+ v2 = ioread16be(p->mapbase + TCNT);
+ v3 = ioread16be(p->mapbase + TCNT);
+ o1 = ioread8(p->mapcommon + TISRC) & p->ovf;
} while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3)
|| (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2)));
@@ -59,8 +61,7 @@ static irqreturn_t timer16_interrupt(int irq, void *dev_id)
{
struct timer16_priv *p = (struct timer16_priv *)dev_id;
- writeb(readb(p->mapcommon + TISRC) & ~p->ovf,
- p->mapcommon + TISRC);
+ ctrl_bclr(p->ovf, p->mapcommon + TISRC);
p->total_cycles += 0x10000;
return IRQ_HANDLED;
@@ -89,12 +90,10 @@ static int timer16_enable(struct clocksource *cs)
WARN_ON(p->cs_enabled);
p->total_cycles = 0;
- writew(0x0000, p->mapbase + TCNT);
- writeb(0x83, p->mapbase + TCR);
- writeb(readb(p->mapcommon + TSTR) | p->enb,
- p->mapcommon + TSTR);
- writeb(readb(p->mapcommon + TISRC) | p->ovie,
- p->mapcommon + TSTR);
+ iowrite16be(0x0000, p->mapbase + TCNT);
+ iowrite8(0x83, p->mapbase + TCR);
+ bset(p->ovie, p->mapcommon + TISRC);
+ bset(p->enb, p->mapcommon + TSTR);
p->cs_enabled = true;
return 0;
@@ -106,8 +105,8 @@ static void timer16_disable(struct clocksource *cs)
WARN_ON(!p->cs_enabled);
- writeb(readb(p->mapcommon + TSTR) & ~p->enb,
- p->mapcommon + TSTR);
+ bclr(p->ovie, p->mapcommon + TISRC);
+ bclr(p->enb, p->mapcommon + TSTR);
p->cs_enabled = false;
}
@@ -162,9 +161,9 @@ static void __init h8300_16timer_init(struct device_node *node)
timer16_priv.mapbase = base[REG_CH];
timer16_priv.mapcommon = base[REG_COMM];
- timer16_priv.enb = 1 << ch;
- timer16_priv.ovf = 1 << ch;
- timer16_priv.ovie = 1 << (4 + ch);
+ timer16_priv.enb = ch;
+ timer16_priv.ovf = ch;
+ timer16_priv.ovie = 4 + ch;
ret = request_irq(irq, timer16_interrupt,
IRQF_TIMER, timer16_priv.cs.name, &timer16_priv);
@@ -174,7 +173,7 @@ static void __init h8300_16timer_init(struct device_node *node)
}
clocksource_register_hz(&timer16_priv.cs,
- clk_get_rate(timer16_priv.clk) / 8);
+ clk_get_rate(clk) / 8);
return;
unmap_comm:
diff --git a/drivers/clocksource/h8300_timer8.c b/drivers/clocksource/h8300_timer8.c
index 9087dd2..c151941 100644
--- a/drivers/clocksource/h8300_timer8.c
+++ b/drivers/clocksource/h8300_timer8.c
@@ -24,10 +24,16 @@
#define TCORB 6
#define _8TCNT 8
+#define CMIEA 6
+#define CMFA 6
+
#define FLAG_STARTED (1 << 3)
#define SCALE 64
+#define bset(b, a) iowrite8(ioread8(a) | (1 << (b)), (a))
+#define bclr(b, a) iowrite8(ioread8(a) & ~(1 << (b)), (a))
+
struct timer8_priv {
struct clock_event_device ced;
void __iomem *mapbase;
@@ -40,12 +46,11 @@ static irqreturn_t timer8_interrupt(int irq, void *dev_id)
struct timer8_priv *p = dev_id;
if (clockevent_state_oneshot(&p->ced))
- writew(0x0000, p->mapbase + _8TCR);
+ iowrite16be(0x0000, p->mapbase + _8TCR);
p->ced.event_handler(&p->ced);
- writeb(readb(p->mapbase + _8TCSR) & ~0x40,
- p->mapbase + _8TCSR);
+ bclr(CMFA, p->mapbase + _8TCSR);
return IRQ_HANDLED;
}
@@ -54,17 +59,18 @@ static void timer8_set_next(struct timer8_priv *p, unsigned long delta)
{
if (delta >= 0x10000)
pr_warn("delta out of range\n");
- writeb(readb(p->mapbase + _8TCR) & ~0x40, p->mapbase + _8TCR);
- writew(0, p->mapbase + _8TCNT);
- writew(delta, p->mapbase + TCORA);
- writeb(readb(p->mapbase + _8TCR) | 0x40, p->mapbase + _8TCR);
+ bclr(CMIEA, p->mapbase + _8TCR);
+ iowrite16be(delta, p->mapbase + TCORA);
+ iowrite16be(0x0000, p->mapbase + _8TCNT);
+ bclr(CMFA, p->mapbase + _8TCSR);
+ bset(CMIEA, p->mapbase + _8TCR);
}
static int timer8_enable(struct timer8_priv *p)
{
- writew(0xffff, p->mapbase + TCORA);
- writew(0x0000, p->mapbase + _8TCNT);
- writew(0x0c02, p->mapbase + _8TCR);
+ iowrite16be(0xffff, p->mapbase + TCORA);
+ iowrite16be(0x0000, p->mapbase + _8TCNT);
+ iowrite16be(0x0c02, p->mapbase + _8TCR);
return 0;
}
@@ -85,7 +91,7 @@ static int timer8_start(struct timer8_priv *p)
static void timer8_stop(struct timer8_priv *p)
{
- writew(0x0000, p->mapbase + _8TCR);
+ iowrite16be(0x0000, p->mapbase + _8TCR);
}
static inline struct timer8_priv *ced_to_priv(struct clock_event_device *ced)
diff --git a/drivers/clocksource/h8300_tpu.c b/drivers/clocksource/h8300_tpu.c
index 91bf1992..d4c1a28 100644
--- a/drivers/clocksource/h8300_tpu.c
+++ b/drivers/clocksource/h8300_tpu.c
@@ -19,6 +19,8 @@
#define TSR 0x5
#define TCNT 0x6
+#define TCFV 0x10
+
struct tpu_priv {
struct clocksource cs;
void __iomem *mapbase1;
@@ -31,8 +33,8 @@ static inline unsigned long read_tcnt32(struct tpu_priv *p)
{
unsigned long tcnt;
- tcnt = readw(p->mapbase1 + TCNT) << 16;
- tcnt |= readw(p->mapbase2 + TCNT);
+ tcnt = ioread16be(p->mapbase1 + TCNT) << 16;
+ tcnt |= ioread16be(p->mapbase2 + TCNT);
return tcnt;
}
@@ -41,7 +43,7 @@ static int tpu_get_counter(struct tpu_priv *p, unsigned long long *val)
unsigned long v1, v2, v3;
int o1, o2;
- o1 = readb(p->mapbase1 + TSR) & 0x10;
+ o1 = ioread8(p->mapbase1 + TSR) & TCFV;
/* Make sure the timer value is stable. Stolen from acpi_pm.c */
do {
@@ -49,7 +51,7 @@ static int tpu_get_counter(struct tpu_priv *p, unsigned long long *val)
v1 = read_tcnt32(p);
v2 = read_tcnt32(p);
v3 = read_tcnt32(p);
- o1 = readb(p->mapbase1 + TSR) & 0x10;
+ o1 = ioread8(p->mapbase1 + TSR) & TCFV;
} while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3)
|| (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2)));
@@ -82,10 +84,10 @@ static int tpu_clocksource_enable(struct clocksource *cs)
WARN_ON(p->cs_enabled);
- writew(0, p->mapbase1 + TCNT);
- writew(0, p->mapbase2 + TCNT);
- writeb(0x0f, p->mapbase1 + TCR);
- writeb(0x03, p->mapbase2 + TCR);
+ iowrite16be(0, p->mapbase1 + TCNT);
+ iowrite16be(0, p->mapbase2 + TCNT);
+ iowrite8(0x0f, p->mapbase1 + TCR);
+ iowrite8(0x03, p->mapbase2 + TCR);
p->cs_enabled = true;
return 0;
@@ -97,8 +99,8 @@ static void tpu_clocksource_disable(struct clocksource *cs)
WARN_ON(!p->cs_enabled);
- writeb(0, p->mapbase1 + TCR);
- writeb(0, p->mapbase2 + TCR);
+ iowrite8(0, p->mapbase1 + TCR);
+ iowrite8(0, p->mapbase2 + TCR);
p->cs_enabled = false;
}
--
2.6.1