diff options
| author | Arnd Bergmann <arnd@arndb.de> | 2013-06-21 05:46:56 -0400 |
|---|---|---|
| committer | Arnd Bergmann <arnd@arndb.de> | 2013-06-21 05:46:56 -0400 |
| commit | c20e459fcc7d5d86a359b19f54362fb6fb77c6aa (patch) | |
| tree | 67874c7e922932af6f25793775d0ca781b2697c2 /drivers/clocksource | |
| parent | e43995ad58264f5113a27d4c6c75edadcf126840 (diff) | |
| parent | d63dc0514d56e108cc96e334ca26b538263e52a2 (diff) | |
Merge tag 'v3.11-rockchip-basics' of git://git.kernel.org/pub/scm/linux/kernel/git/mmind/linux-rockchip into next/soc
From Heiko Stuebner:
Adds basic support for Rockchip Cortex-A9 SoCs.
* tag 'v3.11-rockchip-basics' of git://git.kernel.org/pub/scm/linux/kernel/git/mmind/linux-rockchip:
arm: add basic support for Rockchip RK3066a boards
arm: add debug uarts for rockchip rk29xx and rk3xxx series
arm: Add basic clocks for Rockchip rk3066a SoCs
clocksource: dw_apb_timer_of: use clocksource_of_init
clocksource: dw_apb_timer_of: select DW_APB_TIMER
clocksource: dw_apb_timer_of: add clock-handling
clocksource: dw_apb_timer_of: enable the use the clocksource as sched clock
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Diffstat (limited to 'drivers/clocksource')
| -rw-r--r-- | drivers/clocksource/Kconfig | 2 | ||||
| -rw-r--r-- | drivers/clocksource/dw_apb_timer_of.c | 95 |
2 files changed, 65 insertions, 32 deletions
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index f151c6cf27c3..5871933c4e51 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig | |||
| @@ -21,6 +21,8 @@ config DW_APB_TIMER | |||
| 21 | 21 | ||
| 22 | config DW_APB_TIMER_OF | 22 | config DW_APB_TIMER_OF |
| 23 | bool | 23 | bool |
| 24 | select DW_APB_TIMER | ||
| 25 | select CLKSRC_OF | ||
| 24 | 26 | ||
| 25 | config ARMADA_370_XP_TIMER | 27 | config ARMADA_370_XP_TIMER |
| 26 | bool | 28 | bool |
diff --git a/drivers/clocksource/dw_apb_timer_of.c b/drivers/clocksource/dw_apb_timer_of.c index ab09ed3742ee..cef554432a33 100644 --- a/drivers/clocksource/dw_apb_timer_of.c +++ b/drivers/clocksource/dw_apb_timer_of.c | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | #include <linux/of.h> | 20 | #include <linux/of.h> |
| 21 | #include <linux/of_address.h> | 21 | #include <linux/of_address.h> |
| 22 | #include <linux/of_irq.h> | 22 | #include <linux/of_irq.h> |
| 23 | #include <linux/clk.h> | ||
| 23 | 24 | ||
| 24 | #include <asm/mach/time.h> | 25 | #include <asm/mach/time.h> |
| 25 | #include <asm/sched_clock.h> | 26 | #include <asm/sched_clock.h> |
| @@ -27,14 +28,37 @@ | |||
| 27 | static void timer_get_base_and_rate(struct device_node *np, | 28 | static void timer_get_base_and_rate(struct device_node *np, |
| 28 | void __iomem **base, u32 *rate) | 29 | void __iomem **base, u32 *rate) |
| 29 | { | 30 | { |
| 31 | struct clk *timer_clk; | ||
| 32 | struct clk *pclk; | ||
| 33 | |||
| 30 | *base = of_iomap(np, 0); | 34 | *base = of_iomap(np, 0); |
| 31 | 35 | ||
| 32 | if (!*base) | 36 | if (!*base) |
| 33 | panic("Unable to map regs for %s", np->name); | 37 | panic("Unable to map regs for %s", np->name); |
| 34 | 38 | ||
| 39 | /* | ||
| 40 | * Not all implementations use a periphal clock, so don't panic | ||
| 41 | * if it's not present | ||
| 42 | */ | ||
| 43 | pclk = of_clk_get_by_name(np, "pclk"); | ||
| 44 | if (!IS_ERR(pclk)) | ||
| 45 | if (clk_prepare_enable(pclk)) | ||
| 46 | pr_warn("pclk for %s is present, but could not be activated\n", | ||
| 47 | np->name); | ||
| 48 | |||
| 49 | timer_clk = of_clk_get_by_name(np, "timer"); | ||
| 50 | if (IS_ERR(timer_clk)) | ||
| 51 | goto try_clock_freq; | ||
| 52 | |||
| 53 | if (!clk_prepare_enable(timer_clk)) { | ||
| 54 | *rate = clk_get_rate(timer_clk); | ||
| 55 | return; | ||
| 56 | } | ||
| 57 | |||
| 58 | try_clock_freq: | ||
| 35 | if (of_property_read_u32(np, "clock-freq", rate) && | 59 | if (of_property_read_u32(np, "clock-freq", rate) && |
| 36 | of_property_read_u32(np, "clock-frequency", rate)) | 60 | of_property_read_u32(np, "clock-frequency", rate)) |
| 37 | panic("No clock-frequency property for %s", np->name); | 61 | panic("No clock nor clock-frequency property for %s", np->name); |
| 38 | } | 62 | } |
| 39 | 63 | ||
| 40 | static void add_clockevent(struct device_node *event_timer) | 64 | static void add_clockevent(struct device_node *event_timer) |
| @@ -57,6 +81,9 @@ static void add_clockevent(struct device_node *event_timer) | |||
| 57 | dw_apb_clockevent_register(ced); | 81 | dw_apb_clockevent_register(ced); |
| 58 | } | 82 | } |
| 59 | 83 | ||
| 84 | static void __iomem *sched_io_base; | ||
| 85 | static u32 sched_rate; | ||
| 86 | |||
| 60 | static void add_clocksource(struct device_node *source_timer) | 87 | static void add_clocksource(struct device_node *source_timer) |
| 61 | { | 88 | { |
| 62 | void __iomem *iobase; | 89 | void __iomem *iobase; |
| @@ -71,9 +98,15 @@ static void add_clocksource(struct device_node *source_timer) | |||
| 71 | 98 | ||
| 72 | dw_apb_clocksource_start(cs); | 99 | dw_apb_clocksource_start(cs); |
| 73 | dw_apb_clocksource_register(cs); | 100 | dw_apb_clocksource_register(cs); |
| 74 | } | ||
| 75 | 101 | ||
| 76 | static void __iomem *sched_io_base; | 102 | /* |
| 103 | * Fallback to use the clocksource as sched_clock if no separate | ||
| 104 | * timer is found. sched_io_base then points to the current_value | ||
| 105 | * register of the clocksource timer. | ||
| 106 | */ | ||
| 107 | sched_io_base = iobase + 0x04; | ||
| 108 | sched_rate = rate; | ||
| 109 | } | ||
| 77 | 110 | ||
| 78 | static u32 read_sched_clock(void) | 111 | static u32 read_sched_clock(void) |
| 79 | { | 112 | { |
| @@ -89,39 +122,37 @@ static const struct of_device_id sptimer_ids[] __initconst = { | |||
| 89 | static void init_sched_clock(void) | 122 | static void init_sched_clock(void) |
| 90 | { | 123 | { |
| 91 | struct device_node *sched_timer; | 124 | struct device_node *sched_timer; |
| 92 | u32 rate; | ||
| 93 | 125 | ||
| 94 | sched_timer = of_find_matching_node(NULL, sptimer_ids); | 126 | sched_timer = of_find_matching_node(NULL, sptimer_ids); |
| 95 | if (!sched_timer) | 127 | if (sched_timer) { |
| 96 | panic("No RTC for sched clock to use"); | 128 | timer_get_base_and_rate(sched_timer, &sched_io_base, |
| 129 | &sched_rate); | ||
| 130 | of_node_put(sched_timer); | ||
| 131 | } | ||
| 97 | 132 | ||
| 98 | timer_get_base_and_rate(sched_timer, &sched_io_base, &rate); | 133 | setup_sched_clock(read_sched_clock, 32, sched_rate); |
| 99 | of_node_put(sched_timer); | ||
| 100 | |||
| 101 | setup_sched_clock(read_sched_clock, 32, rate); | ||
| 102 | } | 134 | } |
| 103 | 135 | ||
| 104 | static const struct of_device_id osctimer_ids[] __initconst = { | 136 | static int num_called; |
| 105 | { .compatible = "picochip,pc3x2-timer" }, | 137 | static void __init dw_apb_timer_init(struct device_node *timer) |
| 106 | { .compatible = "snps,dw-apb-timer-osc" }, | ||
| 107 | {}, | ||
| 108 | }; | ||
| 109 | |||
| 110 | void __init dw_apb_timer_init(void) | ||
| 111 | { | 138 | { |
| 112 | struct device_node *event_timer, *source_timer; | 139 | switch (num_called) { |
| 113 | 140 | case 0: | |
| 114 | event_timer = of_find_matching_node(NULL, osctimer_ids); | 141 | pr_debug("%s: found clockevent timer\n", __func__); |
| 115 | if (!event_timer) | 142 | add_clockevent(timer); |
| 116 | panic("No timer for clockevent"); | 143 | of_node_put(timer); |
| 117 | add_clockevent(event_timer); | 144 | break; |
| 118 | 145 | case 1: | |
| 119 | source_timer = of_find_matching_node(event_timer, osctimer_ids); | 146 | pr_debug("%s: found clocksource timer\n", __func__); |
| 120 | if (!source_timer) | 147 | add_clocksource(timer); |
| 121 | panic("No timer for clocksource"); | 148 | of_node_put(timer); |
| 122 | add_clocksource(source_timer); | 149 | init_sched_clock(); |
| 123 | 150 | break; | |
| 124 | of_node_put(source_timer); | 151 | default: |
| 125 | 152 | break; | |
| 126 | init_sched_clock(); | 153 | } |
| 154 | |||
| 155 | num_called++; | ||
| 127 | } | 156 | } |
| 157 | CLOCKSOURCE_OF_DECLARE(pc3x2_timer, "picochip,pc3x2-timer", dw_apb_timer_init); | ||
| 158 | CLOCKSOURCE_OF_DECLARE(apb_timer, "snps,dw-apb-timer-osc", dw_apb_timer_init); | ||
