Date:2011-03-04 13:09:39 (9 years 3 months ago)
Author:Lars C.
Commit:87c1d85060f383267e56764f05f6f69900d3895b
Message:Split time.c into timer-cevt.c and timer-csrc.c

Make clocksource/clockevent timer channels and irq configurable and move
initalization to the sub-archs.
Files: arch/mips/jz47xx/Kconfig (2 diffs)
arch/mips/jz47xx/Makefile (1 diff)
arch/mips/jz47xx/jz4740/Makefile (1 diff)
arch/mips/jz47xx/jz4740/time.c (1 diff)
arch/mips/jz47xx/time.c (1 diff)
arch/mips/jz47xx/timer-cevt.c (1 diff)
arch/mips/jz47xx/timer-cevt.h (1 diff)
arch/mips/jz47xx/timer-csrc.c (1 diff)
arch/mips/jz47xx/timer-csrc.h (1 diff)

Change Details

arch/mips/jz47xx/Kconfig
77config MACH_JZ4740
88    bool "JZ4740"
99    select JZ47XX_TIMER_CSRC
10    select JZ47XX_TIMER_CEVT
1011    select JZ47XX_GPIOV2
1112
1213
...... 
2021config JZ47XX_TIMER_CSRC
2122    bool
2223
24config JZ47XX_TIMER_CEVT
25    bool
26
2327config JZ47XX_GPIOV2
2428    bool
arch/mips/jz47xx/Makefile
77obj-y += prom.o irq.o reset.o setup.o dma.o \
88    timer.o pwm.o serial.o
99
10obj-$(CONFIG_JZ47XX_TIMER_CSRC) += time.o
10obj-$(CONFIG_JZ47XX_TIMER_CSRC) += timer-csrc.o
11obj-$(CONFIG_JZ47XX_TIMER_CEVT) += timer-cevt.o
1112obj-$(CONFIG_JZ47XX_GPIOV2) += gpiov2.o
1213obj-$(CONFIG_DEBUG_FS) += clock-debugfs.o
1314
arch/mips/jz47xx/jz4740/Makefile
11
2obj-y += clock.o platform.o
2obj-y += clock.o platform.o time.o
33
44obj-$(CONFIG_JZ4740_QI_LB60) += board-qi_lb60.o
55obj-$(CONFIG_JZ4740_N516) += board-n516.o board-n516-display.o
arch/mips/jz47xx/jz4740/time.c
1
2
3#include <asm/time.h>
4#include <asm/mach-jz47xx/jz4740/irq.h>
5
6#include "../timer.h"
7#include "../timer-csrc.h"
8#include "../timer-cevt.h"
9
10void __init plat_time_init(void)
11{
12    jz4740_timer_init();
13    jz47xx_timer_csrc_init(1);
14    jz47xx_timer_cevt_init(JZ4740_IRQ_TCU0, 0);
15}
arch/mips/jz47xx/time.c
1/*
2 * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
3 * JZ4740 platform time support
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * You should have received a copy of the GNU General Public License along
11 * with this program; if not, write to the Free Software Foundation, Inc.,
12 * 675 Mass Ave, Cambridge, MA 02139, USA.
13 *
14 */
15
16#include <linux/interrupt.h>
17#include <linux/kernel.h>
18#include <linux/time.h>
19
20#include <linux/clockchips.h>
21
22#include <jz4740/irq.h>
23#include <asm/time.h>
24
25#include "clock.h"
26#include "timer.h"
27
28
29static unsigned int jz4740_jz4740_timer_clockevent;
30static unsigned int jz4740_jz4740_timer_clocksource;
31
32static uint16_t jz4740_jiffies_per_tick;
33
34static cycle_t jz4740_clocksource_read(struct clocksource *cs)
35{
36    return jz4740_timer_get_count(jz4740_timer_clocksource);
37}
38
39static struct clocksource jz4740_clocksource = {
40    .name = "jz4740-timer",
41    .rating = 200,
42    .read = jz4740_clocksource_read,
43    .mask = CLOCKSOURCE_MASK(16),
44    .flags = CLOCK_SOURCE_IS_CONTINUOUS,
45};
46
47static irqreturn_t jz4740_clockevent_irq(int irq, void *devid)
48{
49    struct clock_event_device *cd = devid;
50
51    jz4740_timer_ack_full(jz4740_timer_clockevent);
52
53    if (cd->mode != CLOCK_EVT_MODE_PERIODIC)
54        jz4740_timer_disable(jz4740_timer_clockevent);
55
56    cd->event_handler(cd);
57
58    return IRQ_HANDLED;
59}
60
61static void jz4740_clockevent_set_mode(enum clock_event_mode mode,
62    struct clock_event_device *cd)
63{
64    switch (mode) {
65    case CLOCK_EVT_MODE_PERIODIC:
66        jz4740_timer_set_count(jz4740_timer_clockevent, 0);
67        jz4740_timer_set_period(jz4740_timer_clockevent, jz4740_jiffies_per_tick);
68    case CLOCK_EVT_MODE_RESUME:
69        jz4740_timer_irq_full_enable(jz4740_timer_clockevent);
70        jz4740_timer_enable(jz4740_timer_clockevent);
71        break;
72    case CLOCK_EVT_MODE_ONESHOT:
73    case CLOCK_EVT_MODE_SHUTDOWN:
74        jz4740_timer_disable(jz4740_timer_clockevent);
75        break;
76    default:
77        break;
78    }
79}
80
81static int jz4740_clockevent_set_next(unsigned long evt,
82    struct clock_event_device *cd)
83{
84    jz4740_timer_set_count(jz4740_timer_clockevent, 0);
85    jz4740_timer_set_period(jz4740_timer_clockevent, evt);
86    jz4740_timer_enable(jz4740_timer_clockevent);
87
88    return 0;
89}
90
91static struct clock_event_device jz4740_clockevent = {
92    .name = "jz4740-timer",
93    .features = CLOCK_EVT_FEAT_PERIODIC,
94    .set_next_event = jz4740_clockevent_set_next,
95    .set_mode = jz4740_clockevent_set_mode,
96    .rating = 200,
97    .irq = JZ4740_IRQ_TCU0,
98};
99
100static struct irqaction timer_irqaction = {
101    .handler = jz4740_clockevent_irq,
102    .flags = IRQF_PERCPU | IRQF_TIMER,
103    .name = "jz4740-timerirq",
104    .dev_id = &jz4740_clockevent,
105};
106
107void __init jz4740_timer_csrc_init(int irq, unsigned int csrc, unsigned int cevt)
108{
109    int ret;
110    uint32_t clk_rate;
111    uint16_t ctrl;
112
113    jz4740_timer_init();
114
115    jz4740_timer_clocksource = csrc;
116    jz4740_timer_clockevent = cevt;
117
118    jz4740_clockevent.irq = irq;
119
120    clk_rate = jz4740_clock_bdata.ext_rate >> 4;
121    jz4740_jiffies_per_tick = DIV_ROUND_CLOSEST(clk_rate, HZ);
122
123    clockevent_set_clock(&jz4740_clockevent, clk_rate);
124    jz4740_clockevent.min_delta_ns = clockevent_delta2ns(100, &jz4740_clockevent);
125    jz4740_clockevent.max_delta_ns = clockevent_delta2ns(0xffff, &jz4740_clockevent);
126    jz4740_clockevent.cpumask = cpumask_of(0);
127
128    clockevents_register_device(&jz4740_clockevent);
129
130    clocksource_set_clock(&jz4740_clocksource, clk_rate);
131    ret = clocksource_register(&jz4740_clocksource);
132
133    if (ret)
134        printk(KERN_ERR "Failed to register clocksource: %d\n", ret);
135
136    setup_irq(irq, &timer_irqaction);
137
138    ctrl = JZ_TIMER_CTRL_PRESCALE_16 | JZ_TIMER_CTRL_SRC_EXT;
139
140    jz4740_timer_set_ctrl(jz4740_timer_clockevent, ctrl);
141    jz4740_timer_set_ctrl(jz4740_timer_clocksource, ctrl);
142
143    jz4740_timer_set_period(jz4740_timer_clockevent, jz4740_jiffies_per_tick);
144    jz4740_timer_irq_full_enable(jz4740_timer_clockevent);
145
146    jz4740_timer_set_period(jz4740_timer_clocksource, 0xffff);
147
148    jz4740_timer_enable(jz4740_timer_clockevent);
149    jz4740_timer_enable(jz4740_timer_clocksource);
150}
arch/mips/jz47xx/timer-cevt.c
1/*
2 * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
3 * jz47xx platform time support
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * You should have received a copy of the GNU General Public License along
11 * with this program; if not, write to the Free Software Foundation, Inc.,
12 * 675 Mass Ave, Cambridge, MA 02139, USA.
13 *
14 */
15
16#include <linux/interrupt.h>
17#include <linux/kernel.h>
18#include <linux/time.h>
19
20#include <linux/clockchips.h>
21
22#include <asm/time.h>
23
24#include "clock.h"
25#include "timer.h"
26#include "timer-cevt.h"
27
28static unsigned int jz47xx_timer_clockevent;
29
30static uint16_t jz47xx_ticks_per_jiffy;
31
32static irqreturn_t jz47xx_clockevent_irq(int irq, void *devid)
33{
34    struct clock_event_device *cd = devid;
35
36    jz4740_timer_ack_full(jz47xx_timer_clockevent);
37
38    if (cd->mode != CLOCK_EVT_MODE_PERIODIC)
39        jz4740_timer_disable(jz47xx_timer_clockevent);
40
41    cd->event_handler(cd);
42
43    return IRQ_HANDLED;
44}
45
46static void jz47xx_clockevent_set_mode(enum clock_event_mode mode,
47    struct clock_event_device *cd)
48{
49    switch (mode) {
50    case CLOCK_EVT_MODE_PERIODIC:
51        jz4740_timer_set_count(jz47xx_timer_clockevent, 0);
52        jz4740_timer_set_period(jz47xx_timer_clockevent, jz47xx_ticks_per_jiffy);
53    case CLOCK_EVT_MODE_RESUME:
54        jz4740_timer_irq_full_enable(jz47xx_timer_clockevent);
55        jz4740_timer_enable(jz47xx_timer_clockevent);
56        break;
57    case CLOCK_EVT_MODE_ONESHOT:
58    case CLOCK_EVT_MODE_SHUTDOWN:
59        jz4740_timer_disable(jz47xx_timer_clockevent);
60        break;
61    default:
62        break;
63    }
64}
65
66static int jz47xx_clockevent_set_next(unsigned long evt,
67    struct clock_event_device *cd)
68{
69    jz4740_timer_set_count(jz47xx_timer_clockevent, 0);
70    jz4740_timer_set_period(jz47xx_timer_clockevent, evt);
71    jz4740_timer_enable(jz47xx_timer_clockevent);
72
73    return 0;
74}
75
76static struct clock_event_device jz47xx_clockevent = {
77    .name = "jz47xx-timer",
78    .features = CLOCK_EVT_FEAT_PERIODIC,
79    .set_next_event = jz47xx_clockevent_set_next,
80    .set_mode = jz47xx_clockevent_set_mode,
81    .rating = 200,
82};
83
84static struct irqaction timer_irqaction = {
85    .handler = jz47xx_clockevent_irq,
86    .flags = IRQF_PERCPU | IRQF_TIMER,
87    .name = "jz47xx-cevt",
88    .dev_id = &jz47xx_clockevent,
89};
90
91void __init jz47xx_timer_cevt_init(unsigned int irq, unsigned int timer_id)
92{
93    uint32_t clk_rate;
94
95    jz47xx_timer_clockevent = timer_id;
96
97    jz47xx_clockevent.irq = irq;
98
99    clk_rate = jz4740_clock_bdata.ext_rate >> 4;
100    jz47xx_ticks_per_jiffy = DIV_ROUND_CLOSEST(clk_rate, HZ);
101
102    clockevent_set_clock(&jz47xx_clockevent, clk_rate);
103    jz47xx_clockevent.min_delta_ns = clockevent_delta2ns(100, &jz47xx_clockevent);
104    jz47xx_clockevent.max_delta_ns = clockevent_delta2ns(0xffff, &jz47xx_clockevent);
105    jz47xx_clockevent.cpumask = cpumask_of(0);
106
107    clockevents_register_device(&jz47xx_clockevent);
108
109    setup_irq(irq, &timer_irqaction);
110
111    jz4740_timer_set_ctrl(jz47xx_timer_clockevent,
112        JZ_TIMER_CTRL_PRESCALE_16 | JZ_TIMER_CTRL_SRC_EXT);
113
114    jz4740_timer_set_period(jz47xx_timer_clockevent, jz47xx_ticks_per_jiffy);
115    jz4740_timer_irq_full_enable(jz47xx_timer_clockevent);
116    jz4740_timer_enable(jz47xx_timer_clockevent);
117}
arch/mips/jz47xx/timer-cevt.h
1#ifndef __MIPS_JZ47XX_TIMER_CEVT_H__
2#define __MIPS_JZ47XX_TIMER_CEVT_H__
3
4void __init jz47xx_timer_cevt_init(unsigned int irq, unsigned int timer_id);
5
6#endif
arch/mips/jz47xx/timer-csrc.c
1/*
2 * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
3 * JZ4740 platform time support
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * You should have received a copy of the GNU General Public License along
11 * with this program; if not, write to the Free Software Foundation, Inc.,
12 * 675 Mass Ave, Cambridge, MA 02139, USA.
13 *
14 */
15
16#include <linux/init.h>
17
18#include <linux/clocksource.h>
19
20#include <asm/time.h>
21
22#include "clock.h"
23#include "timer.h"
24#include "timer-csrc.h"
25
26static unsigned int jz47xx_timer_clocksource;
27
28static cycle_t jz47xx_clocksource_read(struct clocksource *cs)
29{
30    return jz4740_timer_get_count(jz47xx_timer_clocksource);
31}
32
33static struct clocksource jz47xx_clocksource = {
34    .name = "jz47xx-timer",
35    .rating = 200,
36    .read = jz47xx_clocksource_read,
37    .mask = CLOCKSOURCE_MASK(16),
38    .flags = CLOCK_SOURCE_IS_CONTINUOUS,
39};
40
41int __init jz47xx_timer_csrc_init(unsigned int timer_id)
42{
43    int ret;
44    unsigned int clk_rate;
45
46    jz47xx_timer_clocksource = timer_id;
47
48    clk_rate = jz4740_clock_bdata.ext_rate >> 4;
49
50    clocksource_set_clock(&jz47xx_clocksource, clk_rate);
51    ret = clocksource_register(&jz47xx_clocksource);
52
53    if (ret) {
54        printk(KERN_ERR "Failed to register clocksource: %d\n", ret);
55        return ret;
56    }
57
58    jz4740_timer_set_ctrl(jz47xx_timer_clocksource,
59        JZ_TIMER_CTRL_PRESCALE_16 | JZ_TIMER_CTRL_SRC_EXT);
60
61    jz4740_timer_set_period(jz47xx_timer_clocksource, 0xffff);
62    jz4740_timer_enable(jz47xx_timer_clocksource);
63
64    return 0;
65}
arch/mips/jz47xx/timer-csrc.h
1#ifndef __MIPS_JZ47XX_TIMER_CSRC_H__
2#define __MIPS_JZ47XX_TIMER_CSRC_H__
3
4int __init jz47xx_timer_csrc_init(unsigned int timer_id);
5
6#endif

Archive Download the corresponding diff file



interactive