diff options
Diffstat (limited to 'arch/arm/mach-zynq')
-rw-r--r-- | arch/arm/mach-zynq/common.c | 54 | ||||
-rw-r--r-- | arch/arm/mach-zynq/common.h | 4 | ||||
-rw-r--r-- | arch/arm/mach-zynq/include/mach/clkdev.h | 32 | ||||
-rw-r--r-- | arch/arm/mach-zynq/include/mach/zynq_soc.h | 45 | ||||
-rw-r--r-- | arch/arm/mach-zynq/timer.c | 297 |
5 files changed, 230 insertions, 202 deletions
diff --git a/arch/arm/mach-zynq/common.c b/arch/arm/mach-zynq/common.c index ab5cfddc0d7b..79bf5fb4dad3 100644 --- a/arch/arm/mach-zynq/common.c +++ b/arch/arm/mach-zynq/common.c | |||
@@ -19,19 +19,21 @@ | |||
19 | #include <linux/cpumask.h> | 19 | #include <linux/cpumask.h> |
20 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
21 | #include <linux/clk.h> | 21 | #include <linux/clk.h> |
22 | #include <linux/clk/zynq.h> | ||
23 | #include <linux/of_address.h> | ||
22 | #include <linux/of_irq.h> | 24 | #include <linux/of_irq.h> |
23 | #include <linux/of_platform.h> | 25 | #include <linux/of_platform.h> |
24 | #include <linux/of.h> | 26 | #include <linux/of.h> |
25 | 27 | ||
26 | #include <asm/mach/arch.h> | 28 | #include <asm/mach/arch.h> |
27 | #include <asm/mach/map.h> | 29 | #include <asm/mach/map.h> |
30 | #include <asm/mach/time.h> | ||
28 | #include <asm/mach-types.h> | 31 | #include <asm/mach-types.h> |
29 | #include <asm/page.h> | 32 | #include <asm/page.h> |
30 | #include <asm/hardware/gic.h> | 33 | #include <asm/hardware/gic.h> |
31 | #include <asm/hardware/cache-l2x0.h> | 34 | #include <asm/hardware/cache-l2x0.h> |
32 | 35 | ||
33 | #include <mach/zynq_soc.h> | 36 | #include <mach/zynq_soc.h> |
34 | #include <mach/clkdev.h> | ||
35 | #include "common.h" | 37 | #include "common.h" |
36 | 38 | ||
37 | static struct of_device_id zynq_of_bus_ids[] __initdata = { | 39 | static struct of_device_id zynq_of_bus_ids[] __initdata = { |
@@ -45,22 +47,25 @@ static struct of_device_id zynq_of_bus_ids[] __initdata = { | |||
45 | */ | 47 | */ |
46 | static void __init xilinx_init_machine(void) | 48 | static void __init xilinx_init_machine(void) |
47 | { | 49 | { |
48 | #ifdef CONFIG_CACHE_L2X0 | ||
49 | /* | 50 | /* |
50 | * 64KB way size, 8-way associativity, parity disabled | 51 | * 64KB way size, 8-way associativity, parity disabled |
51 | */ | 52 | */ |
52 | l2x0_init(PL310_L2CC_BASE, 0x02060000, 0xF0F0FFFF); | 53 | l2x0_of_init(0x02060000, 0xF0F0FFFF); |
53 | #endif | ||
54 | 54 | ||
55 | of_platform_bus_probe(NULL, zynq_of_bus_ids, NULL); | 55 | of_platform_bus_probe(NULL, zynq_of_bus_ids, NULL); |
56 | } | 56 | } |
57 | 57 | ||
58 | static struct of_device_id irq_match[] __initdata = { | ||
59 | { .compatible = "arm,cortex-a9-gic", .data = gic_of_init, }, | ||
60 | { } | ||
61 | }; | ||
62 | |||
58 | /** | 63 | /** |
59 | * xilinx_irq_init() - Interrupt controller initialization for the GIC. | 64 | * xilinx_irq_init() - Interrupt controller initialization for the GIC. |
60 | */ | 65 | */ |
61 | static void __init xilinx_irq_init(void) | 66 | static void __init xilinx_irq_init(void) |
62 | { | 67 | { |
63 | gic_init(0, 29, SCU_GIC_DIST_BASE, SCU_GIC_CPU_BASE); | 68 | of_irq_init(irq_match); |
64 | } | 69 | } |
65 | 70 | ||
66 | /* The minimum devices needed to be mapped before the VM system is up and | 71 | /* The minimum devices needed to be mapped before the VM system is up and |
@@ -71,31 +76,47 @@ static struct map_desc io_desc[] __initdata = { | |||
71 | { | 76 | { |
72 | .virtual = TTC0_VIRT, | 77 | .virtual = TTC0_VIRT, |
73 | .pfn = __phys_to_pfn(TTC0_PHYS), | 78 | .pfn = __phys_to_pfn(TTC0_PHYS), |
74 | .length = SZ_4K, | 79 | .length = TTC0_SIZE, |
75 | .type = MT_DEVICE, | 80 | .type = MT_DEVICE, |
76 | }, { | 81 | }, { |
77 | .virtual = SCU_PERIPH_VIRT, | 82 | .virtual = SCU_PERIPH_VIRT, |
78 | .pfn = __phys_to_pfn(SCU_PERIPH_PHYS), | 83 | .pfn = __phys_to_pfn(SCU_PERIPH_PHYS), |
79 | .length = SZ_8K, | 84 | .length = SCU_PERIPH_SIZE, |
80 | .type = MT_DEVICE, | ||
81 | }, { | ||
82 | .virtual = PL310_L2CC_VIRT, | ||
83 | .pfn = __phys_to_pfn(PL310_L2CC_PHYS), | ||
84 | .length = SZ_4K, | ||
85 | .type = MT_DEVICE, | 85 | .type = MT_DEVICE, |
86 | }, | 86 | }, |
87 | 87 | ||
88 | #ifdef CONFIG_DEBUG_LL | 88 | #ifdef CONFIG_DEBUG_LL |
89 | { | 89 | { |
90 | .virtual = UART0_VIRT, | 90 | .virtual = LL_UART_VADDR, |
91 | .pfn = __phys_to_pfn(UART0_PHYS), | 91 | .pfn = __phys_to_pfn(LL_UART_PADDR), |
92 | .length = SZ_4K, | 92 | .length = UART_SIZE, |
93 | .type = MT_DEVICE, | 93 | .type = MT_DEVICE, |
94 | }, | 94 | }, |
95 | #endif | 95 | #endif |
96 | 96 | ||
97 | }; | 97 | }; |
98 | 98 | ||
99 | static void __init xilinx_zynq_timer_init(void) | ||
100 | { | ||
101 | struct device_node *np; | ||
102 | void __iomem *slcr; | ||
103 | |||
104 | np = of_find_compatible_node(NULL, NULL, "xlnx,zynq-slcr"); | ||
105 | slcr = of_iomap(np, 0); | ||
106 | WARN_ON(!slcr); | ||
107 | |||
108 | xilinx_zynq_clocks_init(slcr); | ||
109 | |||
110 | xttcpss_timer_init(); | ||
111 | } | ||
112 | |||
113 | /* | ||
114 | * Instantiate and initialize the system timer structure | ||
115 | */ | ||
116 | static struct sys_timer xttcpss_sys_timer = { | ||
117 | .init = xilinx_zynq_timer_init, | ||
118 | }; | ||
119 | |||
99 | /** | 120 | /** |
100 | * xilinx_map_io() - Create memory mappings needed for early I/O. | 121 | * xilinx_map_io() - Create memory mappings needed for early I/O. |
101 | */ | 122 | */ |
@@ -105,7 +126,8 @@ static void __init xilinx_map_io(void) | |||
105 | } | 126 | } |
106 | 127 | ||
107 | static const char *xilinx_dt_match[] = { | 128 | static const char *xilinx_dt_match[] = { |
108 | "xlnx,zynq-ep107", | 129 | "xlnx,zynq-zc702", |
130 | "xlnx,zynq-7000", | ||
109 | NULL | 131 | NULL |
110 | }; | 132 | }; |
111 | 133 | ||
diff --git a/arch/arm/mach-zynq/common.h b/arch/arm/mach-zynq/common.h index a009644a1555..954b91c13c91 100644 --- a/arch/arm/mach-zynq/common.h +++ b/arch/arm/mach-zynq/common.h | |||
@@ -17,8 +17,6 @@ | |||
17 | #ifndef __MACH_ZYNQ_COMMON_H__ | 17 | #ifndef __MACH_ZYNQ_COMMON_H__ |
18 | #define __MACH_ZYNQ_COMMON_H__ | 18 | #define __MACH_ZYNQ_COMMON_H__ |
19 | 19 | ||
20 | #include <asm/mach/time.h> | 20 | void __init xttcpss_timer_init(void); |
21 | |||
22 | extern struct sys_timer xttcpss_sys_timer; | ||
23 | 21 | ||
24 | #endif | 22 | #endif |
diff --git a/arch/arm/mach-zynq/include/mach/clkdev.h b/arch/arm/mach-zynq/include/mach/clkdev.h deleted file mode 100644 index c6e73d81a459..000000000000 --- a/arch/arm/mach-zynq/include/mach/clkdev.h +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | /* | ||
2 | * arch/arm/mach-zynq/include/mach/clkdev.h | ||
3 | * | ||
4 | * Copyright (C) 2011 Xilinx, Inc. | ||
5 | * | ||
6 | * This software is licensed under the terms of the GNU General Public | ||
7 | * License version 2, as published by the Free Software Foundation, and | ||
8 | * may be copied, distributed, and modified under those terms. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | */ | ||
16 | |||
17 | #ifndef __MACH_CLKDEV_H__ | ||
18 | #define __MACH_CLKDEV_H__ | ||
19 | |||
20 | #include <plat/clock.h> | ||
21 | |||
22 | struct clk { | ||
23 | unsigned long rate; | ||
24 | const struct clk_ops *ops; | ||
25 | const struct icst_params *params; | ||
26 | void __iomem *vcoreg; | ||
27 | }; | ||
28 | |||
29 | #define __clk_get(clk) ({ 1; }) | ||
30 | #define __clk_put(clk) do { } while (0) | ||
31 | |||
32 | #endif | ||
diff --git a/arch/arm/mach-zynq/include/mach/zynq_soc.h b/arch/arm/mach-zynq/include/mach/zynq_soc.h index d0d3f8fb06dd..5ebbd8e6eeee 100644 --- a/arch/arm/mach-zynq/include/mach/zynq_soc.h +++ b/arch/arm/mach-zynq/include/mach/zynq_soc.h | |||
@@ -15,34 +15,39 @@ | |||
15 | #ifndef __MACH_XILINX_SOC_H__ | 15 | #ifndef __MACH_XILINX_SOC_H__ |
16 | #define __MACH_XILINX_SOC_H__ | 16 | #define __MACH_XILINX_SOC_H__ |
17 | 17 | ||
18 | #include <asm/pgtable.h> | ||
19 | |||
18 | #define PERIPHERAL_CLOCK_RATE 2500000 | 20 | #define PERIPHERAL_CLOCK_RATE 2500000 |
19 | 21 | ||
20 | /* For now, all mappings are flat (physical = virtual) | 22 | /* Static peripheral mappings are mapped at the top of the vmalloc region. The |
23 | * early uart mapping causes intermediate problems/failure at certain | ||
24 | * addresses, including the very top of the vmalloc region. Map it at an | ||
25 | * address that is known to work. | ||
21 | */ | 26 | */ |
22 | #define UART0_PHYS 0xE0000000 | 27 | #define UART0_PHYS 0xE0000000 |
23 | #define UART0_VIRT UART0_PHYS | 28 | #define UART1_PHYS 0xE0001000 |
24 | 29 | #define UART_SIZE SZ_4K | |
25 | #define TTC0_PHYS 0xF8001000 | 30 | #define UART_VIRT 0xF0001000 |
26 | #define TTC0_VIRT TTC0_PHYS | 31 | |
27 | 32 | #define TTC0_PHYS 0xF8001000 | |
28 | #define PL310_L2CC_PHYS 0xF8F02000 | 33 | #define TTC0_SIZE SZ_4K |
29 | #define PL310_L2CC_VIRT PL310_L2CC_PHYS | 34 | #define TTC0_VIRT (VMALLOC_END - TTC0_SIZE) |
35 | |||
36 | #define SCU_PERIPH_PHYS 0xF8F00000 | ||
37 | #define SCU_PERIPH_SIZE SZ_8K | ||
38 | #define SCU_PERIPH_VIRT (TTC0_VIRT - SCU_PERIPH_SIZE) | ||
39 | |||
40 | #if IS_ENABLED(CONFIG_DEBUG_ZYNQ_UART1) | ||
41 | # define LL_UART_PADDR UART1_PHYS | ||
42 | #else | ||
43 | # define LL_UART_PADDR UART0_PHYS | ||
44 | #endif | ||
30 | 45 | ||
31 | #define SCU_PERIPH_PHYS 0xF8F00000 | 46 | #define LL_UART_VADDR UART_VIRT |
32 | #define SCU_PERIPH_VIRT SCU_PERIPH_PHYS | ||
33 | 47 | ||
34 | /* The following are intended for the devices that are mapped early */ | 48 | /* The following are intended for the devices that are mapped early */ |
35 | 49 | ||
36 | #define TTC0_BASE IOMEM(TTC0_VIRT) | 50 | #define TTC0_BASE IOMEM(TTC0_VIRT) |
37 | #define SCU_PERIPH_BASE IOMEM(SCU_PERIPH_VIRT) | 51 | #define SCU_PERIPH_BASE IOMEM(SCU_PERIPH_VIRT) |
38 | #define SCU_GIC_CPU_BASE (SCU_PERIPH_BASE + 0x100) | ||
39 | #define SCU_GIC_DIST_BASE (SCU_PERIPH_BASE + 0x1000) | ||
40 | #define PL310_L2CC_BASE IOMEM(PL310_L2CC_VIRT) | ||
41 | |||
42 | /* | ||
43 | * Mandatory for CONFIG_LL_DEBUG, UART is mapped virtual = physical | ||
44 | */ | ||
45 | #define LL_UART_PADDR UART0_PHYS | ||
46 | #define LL_UART_VADDR UART0_VIRT | ||
47 | 52 | ||
48 | #endif | 53 | #endif |
diff --git a/arch/arm/mach-zynq/timer.c b/arch/arm/mach-zynq/timer.c index c2c96cc7d6e7..9662306aa12f 100644 --- a/arch/arm/mach-zynq/timer.c +++ b/arch/arm/mach-zynq/timer.c | |||
@@ -23,32 +23,15 @@ | |||
23 | #include <linux/clocksource.h> | 23 | #include <linux/clocksource.h> |
24 | #include <linux/clockchips.h> | 24 | #include <linux/clockchips.h> |
25 | #include <linux/io.h> | 25 | #include <linux/io.h> |
26 | #include <linux/of.h> | ||
27 | #include <linux/of_address.h> | ||
28 | #include <linux/of_irq.h> | ||
29 | #include <linux/slab.h> | ||
30 | #include <linux/clk-provider.h> | ||
26 | 31 | ||
27 | #include <asm/mach/time.h> | ||
28 | #include <mach/zynq_soc.h> | 32 | #include <mach/zynq_soc.h> |
29 | #include "common.h" | 33 | #include "common.h" |
30 | 34 | ||
31 | #define IRQ_TIMERCOUNTER0 42 | ||
32 | |||
33 | /* | ||
34 | * This driver configures the 2 16-bit count-up timers as follows: | ||
35 | * | ||
36 | * T1: Timer 1, clocksource for generic timekeeping | ||
37 | * T2: Timer 2, clockevent source for hrtimers | ||
38 | * T3: Timer 3, <unused> | ||
39 | * | ||
40 | * The input frequency to the timer module for emulation is 2.5MHz which is | ||
41 | * common to all the timer channels (T1, T2, and T3). With a pre-scaler of 32, | ||
42 | * the timers are clocked at 78.125KHz (12.8 us resolution). | ||
43 | * | ||
44 | * The input frequency to the timer module in silicon will be 200MHz. With the | ||
45 | * pre-scaler of 32, the timers are clocked at 6.25MHz (160ns resolution). | ||
46 | */ | ||
47 | #define XTTCPSS_CLOCKSOURCE 0 /* Timer 1 as a generic timekeeping */ | ||
48 | #define XTTCPSS_CLOCKEVENT 1 /* Timer 2 as a clock event */ | ||
49 | |||
50 | #define XTTCPSS_TIMER_BASE TTC0_BASE | ||
51 | #define XTTCPCC_EVENT_TIMER_IRQ (IRQ_TIMERCOUNTER0 + 1) | ||
52 | /* | 35 | /* |
53 | * Timer Register Offset Definitions of Timer 1, Increment base address by 4 | 36 | * Timer Register Offset Definitions of Timer 1, Increment base address by 4 |
54 | * and use same offsets for Timer 2 | 37 | * and use same offsets for Timer 2 |
@@ -65,9 +48,14 @@ | |||
65 | 48 | ||
66 | #define XTTCPSS_CNT_CNTRL_DISABLE_MASK 0x1 | 49 | #define XTTCPSS_CNT_CNTRL_DISABLE_MASK 0x1 |
67 | 50 | ||
68 | /* Setup the timers to use pre-scaling */ | 51 | /* Setup the timers to use pre-scaling, using a fixed value for now that will |
69 | 52 | * work across most input frequency, but it may need to be more dynamic | |
70 | #define TIMER_RATE (PERIPHERAL_CLOCK_RATE / 32) | 53 | */ |
54 | #define PRESCALE_EXPONENT 11 /* 2 ^ PRESCALE_EXPONENT = PRESCALE */ | ||
55 | #define PRESCALE 2048 /* The exponent must match this */ | ||
56 | #define CLK_CNTRL_PRESCALE ((PRESCALE_EXPONENT - 1) << 1) | ||
57 | #define CLK_CNTRL_PRESCALE_EN 1 | ||
58 | #define CNT_CNTRL_RESET (1<<4) | ||
71 | 59 | ||
72 | /** | 60 | /** |
73 | * struct xttcpss_timer - This definition defines local timer structure | 61 | * struct xttcpss_timer - This definition defines local timer structure |
@@ -75,11 +63,25 @@ | |||
75 | * @base_addr: Base address of timer | 63 | * @base_addr: Base address of timer |
76 | **/ | 64 | **/ |
77 | struct xttcpss_timer { | 65 | struct xttcpss_timer { |
78 | void __iomem *base_addr; | 66 | void __iomem *base_addr; |
79 | }; | 67 | }; |
80 | 68 | ||
81 | static struct xttcpss_timer timers[2]; | 69 | struct xttcpss_timer_clocksource { |
82 | static struct clock_event_device xttcpss_clockevent; | 70 | struct xttcpss_timer xttc; |
71 | struct clocksource cs; | ||
72 | }; | ||
73 | |||
74 | #define to_xttcpss_timer_clksrc(x) \ | ||
75 | container_of(x, struct xttcpss_timer_clocksource, cs) | ||
76 | |||
77 | struct xttcpss_timer_clockevent { | ||
78 | struct xttcpss_timer xttc; | ||
79 | struct clock_event_device ce; | ||
80 | struct clk *clk; | ||
81 | }; | ||
82 | |||
83 | #define to_xttcpss_timer_clkevent(x) \ | ||
84 | container_of(x, struct xttcpss_timer_clockevent, ce) | ||
83 | 85 | ||
84 | /** | 86 | /** |
85 | * xttcpss_set_interval - Set the timer interval value | 87 | * xttcpss_set_interval - Set the timer interval value |
@@ -101,7 +103,7 @@ static void xttcpss_set_interval(struct xttcpss_timer *timer, | |||
101 | 103 | ||
102 | /* Reset the counter (0x10) so that it starts from 0, one-shot | 104 | /* Reset the counter (0x10) so that it starts from 0, one-shot |
103 | mode makes this needed for timing to be right. */ | 105 | mode makes this needed for timing to be right. */ |
104 | ctrl_reg |= 0x10; | 106 | ctrl_reg |= CNT_CNTRL_RESET; |
105 | ctrl_reg &= ~XTTCPSS_CNT_CNTRL_DISABLE_MASK; | 107 | ctrl_reg &= ~XTTCPSS_CNT_CNTRL_DISABLE_MASK; |
106 | __raw_writel(ctrl_reg, timer->base_addr + XTTCPSS_CNT_CNTRL_OFFSET); | 108 | __raw_writel(ctrl_reg, timer->base_addr + XTTCPSS_CNT_CNTRL_OFFSET); |
107 | } | 109 | } |
@@ -116,90 +118,31 @@ static void xttcpss_set_interval(struct xttcpss_timer *timer, | |||
116 | **/ | 118 | **/ |
117 | static irqreturn_t xttcpss_clock_event_interrupt(int irq, void *dev_id) | 119 | static irqreturn_t xttcpss_clock_event_interrupt(int irq, void *dev_id) |
118 | { | 120 | { |
119 | struct clock_event_device *evt = &xttcpss_clockevent; | 121 | struct xttcpss_timer_clockevent *xttce = dev_id; |
120 | struct xttcpss_timer *timer = dev_id; | 122 | struct xttcpss_timer *timer = &xttce->xttc; |
121 | 123 | ||
122 | /* Acknowledge the interrupt and call event handler */ | 124 | /* Acknowledge the interrupt and call event handler */ |
123 | __raw_writel(__raw_readl(timer->base_addr + XTTCPSS_ISR_OFFSET), | 125 | __raw_writel(__raw_readl(timer->base_addr + XTTCPSS_ISR_OFFSET), |
124 | timer->base_addr + XTTCPSS_ISR_OFFSET); | 126 | timer->base_addr + XTTCPSS_ISR_OFFSET); |
125 | 127 | ||
126 | evt->event_handler(evt); | 128 | xttce->ce.event_handler(&xttce->ce); |
127 | 129 | ||
128 | return IRQ_HANDLED; | 130 | return IRQ_HANDLED; |
129 | } | 131 | } |
130 | 132 | ||
131 | static struct irqaction event_timer_irq = { | ||
132 | .name = "xttcpss clockevent", | ||
133 | .flags = IRQF_DISABLED | IRQF_TIMER, | ||
134 | .handler = xttcpss_clock_event_interrupt, | ||
135 | }; | ||
136 | |||
137 | /** | 133 | /** |
138 | * xttcpss_timer_hardware_init - Initialize the timer hardware | 134 | * __xttc_clocksource_read - Reads the timer counter register |
139 | * | ||
140 | * Initialize the hardware to start the clock source, get the clock | ||
141 | * event timer ready to use, and hook up the interrupt. | ||
142 | **/ | ||
143 | static void __init xttcpss_timer_hardware_init(void) | ||
144 | { | ||
145 | /* Setup the clock source counter to be an incrementing counter | ||
146 | * with no interrupt and it rolls over at 0xFFFF. Pre-scale | ||
147 | it by 32 also. Let it start running now. | ||
148 | */ | ||
149 | timers[XTTCPSS_CLOCKSOURCE].base_addr = XTTCPSS_TIMER_BASE; | ||
150 | |||
151 | __raw_writel(0x0, timers[XTTCPSS_CLOCKSOURCE].base_addr + | ||
152 | XTTCPSS_IER_OFFSET); | ||
153 | __raw_writel(0x9, timers[XTTCPSS_CLOCKSOURCE].base_addr + | ||
154 | XTTCPSS_CLK_CNTRL_OFFSET); | ||
155 | __raw_writel(0x10, timers[XTTCPSS_CLOCKSOURCE].base_addr + | ||
156 | XTTCPSS_CNT_CNTRL_OFFSET); | ||
157 | |||
158 | /* Setup the clock event timer to be an interval timer which | ||
159 | * is prescaled by 32 using the interval interrupt. Leave it | ||
160 | * disabled for now. | ||
161 | */ | ||
162 | |||
163 | timers[XTTCPSS_CLOCKEVENT].base_addr = XTTCPSS_TIMER_BASE + 4; | ||
164 | |||
165 | __raw_writel(0x23, timers[XTTCPSS_CLOCKEVENT].base_addr + | ||
166 | XTTCPSS_CNT_CNTRL_OFFSET); | ||
167 | __raw_writel(0x9, timers[XTTCPSS_CLOCKEVENT].base_addr + | ||
168 | XTTCPSS_CLK_CNTRL_OFFSET); | ||
169 | __raw_writel(0x1, timers[XTTCPSS_CLOCKEVENT].base_addr + | ||
170 | XTTCPSS_IER_OFFSET); | ||
171 | |||
172 | /* Setup IRQ the clock event timer */ | ||
173 | event_timer_irq.dev_id = &timers[XTTCPSS_CLOCKEVENT]; | ||
174 | setup_irq(XTTCPCC_EVENT_TIMER_IRQ, &event_timer_irq); | ||
175 | } | ||
176 | |||
177 | /** | ||
178 | * __raw_readl_cycles - Reads the timer counter register | ||
179 | * | 135 | * |
180 | * returns: Current timer counter register value | 136 | * returns: Current timer counter register value |
181 | **/ | 137 | **/ |
182 | static cycle_t __raw_readl_cycles(struct clocksource *cs) | 138 | static cycle_t __xttc_clocksource_read(struct clocksource *cs) |
183 | { | 139 | { |
184 | struct xttcpss_timer *timer = &timers[XTTCPSS_CLOCKSOURCE]; | 140 | struct xttcpss_timer *timer = &to_xttcpss_timer_clksrc(cs)->xttc; |
185 | 141 | ||
186 | return (cycle_t)__raw_readl(timer->base_addr + | 142 | return (cycle_t)__raw_readl(timer->base_addr + |
187 | XTTCPSS_COUNT_VAL_OFFSET); | 143 | XTTCPSS_COUNT_VAL_OFFSET); |
188 | } | 144 | } |
189 | 145 | ||
190 | |||
191 | /* | ||
192 | * Instantiate and initialize the clock source structure | ||
193 | */ | ||
194 | static struct clocksource clocksource_xttcpss = { | ||
195 | .name = "xttcpss_timer1", | ||
196 | .rating = 200, /* Reasonable clock source */ | ||
197 | .read = __raw_readl_cycles, | ||
198 | .mask = CLOCKSOURCE_MASK(16), | ||
199 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, | ||
200 | }; | ||
201 | |||
202 | |||
203 | /** | 146 | /** |
204 | * xttcpss_set_next_event - Sets the time interval for next event | 147 | * xttcpss_set_next_event - Sets the time interval for next event |
205 | * | 148 | * |
@@ -211,7 +154,8 @@ static struct clocksource clocksource_xttcpss = { | |||
211 | static int xttcpss_set_next_event(unsigned long cycles, | 154 | static int xttcpss_set_next_event(unsigned long cycles, |
212 | struct clock_event_device *evt) | 155 | struct clock_event_device *evt) |
213 | { | 156 | { |
214 | struct xttcpss_timer *timer = &timers[XTTCPSS_CLOCKEVENT]; | 157 | struct xttcpss_timer_clockevent *xttce = to_xttcpss_timer_clkevent(evt); |
158 | struct xttcpss_timer *timer = &xttce->xttc; | ||
215 | 159 | ||
216 | xttcpss_set_interval(timer, cycles); | 160 | xttcpss_set_interval(timer, cycles); |
217 | return 0; | 161 | return 0; |
@@ -226,12 +170,15 @@ static int xttcpss_set_next_event(unsigned long cycles, | |||
226 | static void xttcpss_set_mode(enum clock_event_mode mode, | 170 | static void xttcpss_set_mode(enum clock_event_mode mode, |
227 | struct clock_event_device *evt) | 171 | struct clock_event_device *evt) |
228 | { | 172 | { |
229 | struct xttcpss_timer *timer = &timers[XTTCPSS_CLOCKEVENT]; | 173 | struct xttcpss_timer_clockevent *xttce = to_xttcpss_timer_clkevent(evt); |
174 | struct xttcpss_timer *timer = &xttce->xttc; | ||
230 | u32 ctrl_reg; | 175 | u32 ctrl_reg; |
231 | 176 | ||
232 | switch (mode) { | 177 | switch (mode) { |
233 | case CLOCK_EVT_MODE_PERIODIC: | 178 | case CLOCK_EVT_MODE_PERIODIC: |
234 | xttcpss_set_interval(timer, TIMER_RATE / HZ); | 179 | xttcpss_set_interval(timer, |
180 | DIV_ROUND_CLOSEST(clk_get_rate(xttce->clk), | ||
181 | PRESCALE * HZ)); | ||
235 | break; | 182 | break; |
236 | case CLOCK_EVT_MODE_ONESHOT: | 183 | case CLOCK_EVT_MODE_ONESHOT: |
237 | case CLOCK_EVT_MODE_UNUSED: | 184 | case CLOCK_EVT_MODE_UNUSED: |
@@ -252,15 +199,106 @@ static void xttcpss_set_mode(enum clock_event_mode mode, | |||
252 | } | 199 | } |
253 | } | 200 | } |
254 | 201 | ||
255 | /* | 202 | static void __init zynq_ttc_setup_clocksource(struct device_node *np, |
256 | * Instantiate and initialize the clock event structure | 203 | void __iomem *base) |
257 | */ | 204 | { |
258 | static struct clock_event_device xttcpss_clockevent = { | 205 | struct xttcpss_timer_clocksource *ttccs; |
259 | .name = "xttcpss_timer2", | 206 | struct clk *clk; |
260 | .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, | 207 | int err; |
261 | .set_next_event = xttcpss_set_next_event, | 208 | u32 reg; |
262 | .set_mode = xttcpss_set_mode, | 209 | |
263 | .rating = 200, | 210 | ttccs = kzalloc(sizeof(*ttccs), GFP_KERNEL); |
211 | if (WARN_ON(!ttccs)) | ||
212 | return; | ||
213 | |||
214 | err = of_property_read_u32(np, "reg", ®); | ||
215 | if (WARN_ON(err)) | ||
216 | return; | ||
217 | |||
218 | clk = of_clk_get_by_name(np, "cpu_1x"); | ||
219 | if (WARN_ON(IS_ERR(clk))) | ||
220 | return; | ||
221 | |||
222 | err = clk_prepare_enable(clk); | ||
223 | if (WARN_ON(err)) | ||
224 | return; | ||
225 | |||
226 | ttccs->xttc.base_addr = base + reg * 4; | ||
227 | |||
228 | ttccs->cs.name = np->name; | ||
229 | ttccs->cs.rating = 200; | ||
230 | ttccs->cs.read = __xttc_clocksource_read; | ||
231 | ttccs->cs.mask = CLOCKSOURCE_MASK(16); | ||
232 | ttccs->cs.flags = CLOCK_SOURCE_IS_CONTINUOUS; | ||
233 | |||
234 | __raw_writel(0x0, ttccs->xttc.base_addr + XTTCPSS_IER_OFFSET); | ||
235 | __raw_writel(CLK_CNTRL_PRESCALE | CLK_CNTRL_PRESCALE_EN, | ||
236 | ttccs->xttc.base_addr + XTTCPSS_CLK_CNTRL_OFFSET); | ||
237 | __raw_writel(CNT_CNTRL_RESET, | ||
238 | ttccs->xttc.base_addr + XTTCPSS_CNT_CNTRL_OFFSET); | ||
239 | |||
240 | err = clocksource_register_hz(&ttccs->cs, clk_get_rate(clk) / PRESCALE); | ||
241 | if (WARN_ON(err)) | ||
242 | return; | ||
243 | } | ||
244 | |||
245 | static void __init zynq_ttc_setup_clockevent(struct device_node *np, | ||
246 | void __iomem *base) | ||
247 | { | ||
248 | struct xttcpss_timer_clockevent *ttcce; | ||
249 | int err, irq; | ||
250 | u32 reg; | ||
251 | |||
252 | ttcce = kzalloc(sizeof(*ttcce), GFP_KERNEL); | ||
253 | if (WARN_ON(!ttcce)) | ||
254 | return; | ||
255 | |||
256 | err = of_property_read_u32(np, "reg", ®); | ||
257 | if (WARN_ON(err)) | ||
258 | return; | ||
259 | |||
260 | ttcce->xttc.base_addr = base + reg * 4; | ||
261 | |||
262 | ttcce->clk = of_clk_get_by_name(np, "cpu_1x"); | ||
263 | if (WARN_ON(IS_ERR(ttcce->clk))) | ||
264 | return; | ||
265 | |||
266 | err = clk_prepare_enable(ttcce->clk); | ||
267 | if (WARN_ON(err)) | ||
268 | return; | ||
269 | |||
270 | irq = irq_of_parse_and_map(np, 0); | ||
271 | if (WARN_ON(!irq)) | ||
272 | return; | ||
273 | |||
274 | ttcce->ce.name = np->name; | ||
275 | ttcce->ce.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT; | ||
276 | ttcce->ce.set_next_event = xttcpss_set_next_event; | ||
277 | ttcce->ce.set_mode = xttcpss_set_mode; | ||
278 | ttcce->ce.rating = 200; | ||
279 | ttcce->ce.irq = irq; | ||
280 | |||
281 | __raw_writel(0x23, ttcce->xttc.base_addr + XTTCPSS_CNT_CNTRL_OFFSET); | ||
282 | __raw_writel(CLK_CNTRL_PRESCALE | CLK_CNTRL_PRESCALE_EN, | ||
283 | ttcce->xttc.base_addr + XTTCPSS_CLK_CNTRL_OFFSET); | ||
284 | __raw_writel(0x1, ttcce->xttc.base_addr + XTTCPSS_IER_OFFSET); | ||
285 | |||
286 | err = request_irq(irq, xttcpss_clock_event_interrupt, IRQF_TIMER, | ||
287 | np->name, ttcce); | ||
288 | if (WARN_ON(err)) | ||
289 | return; | ||
290 | |||
291 | clockevents_config_and_register(&ttcce->ce, | ||
292 | clk_get_rate(ttcce->clk) / PRESCALE, | ||
293 | 1, 0xfffe); | ||
294 | } | ||
295 | |||
296 | static const __initconst struct of_device_id zynq_ttc_match[] = { | ||
297 | { .compatible = "xlnx,ttc-counter-clocksource", | ||
298 | .data = zynq_ttc_setup_clocksource, }, | ||
299 | { .compatible = "xlnx,ttc-counter-clockevent", | ||
300 | .data = zynq_ttc_setup_clockevent, }, | ||
301 | {} | ||
264 | }; | 302 | }; |
265 | 303 | ||
266 | /** | 304 | /** |
@@ -269,30 +307,27 @@ static struct clock_event_device xttcpss_clockevent = { | |||
269 | * Initializes the timer hardware and register the clock source and clock event | 307 | * Initializes the timer hardware and register the clock source and clock event |
270 | * timers with Linux kernal timer framework | 308 | * timers with Linux kernal timer framework |
271 | **/ | 309 | **/ |
272 | static void __init xttcpss_timer_init(void) | 310 | void __init xttcpss_timer_init(void) |
273 | { | 311 | { |
274 | xttcpss_timer_hardware_init(); | 312 | struct device_node *np; |
275 | clocksource_register_hz(&clocksource_xttcpss, TIMER_RATE); | 313 | |
276 | 314 | for_each_compatible_node(np, NULL, "xlnx,ttc") { | |
277 | /* Calculate the parameters to allow the clockevent to operate using | 315 | struct device_node *np_chld; |
278 | integer math | 316 | void __iomem *base; |
279 | */ | 317 | |
280 | clockevents_calc_mult_shift(&xttcpss_clockevent, TIMER_RATE, 4); | 318 | base = of_iomap(np, 0); |
281 | 319 | if (WARN_ON(!base)) | |
282 | xttcpss_clockevent.max_delta_ns = | 320 | return; |
283 | clockevent_delta2ns(0xfffe, &xttcpss_clockevent); | 321 | |
284 | xttcpss_clockevent.min_delta_ns = | 322 | for_each_available_child_of_node(np, np_chld) { |
285 | clockevent_delta2ns(1, &xttcpss_clockevent); | 323 | int (*cb)(struct device_node *np, void __iomem *base); |
286 | 324 | const struct of_device_id *match; | |
287 | /* Indicate that clock event is on 1st CPU as SMP boot needs it */ | 325 | |
288 | 326 | match = of_match_node(zynq_ttc_match, np_chld); | |
289 | xttcpss_clockevent.cpumask = cpumask_of(0); | 327 | if (match) { |
290 | clockevents_register_device(&xttcpss_clockevent); | 328 | cb = match->data; |
329 | cb(np_chld, base); | ||
330 | } | ||
331 | } | ||
332 | } | ||
291 | } | 333 | } |
292 | |||
293 | /* | ||
294 | * Instantiate and initialize the system timer structure | ||
295 | */ | ||
296 | struct sys_timer xttcpss_sys_timer = { | ||
297 | .init = xttcpss_timer_init, | ||
298 | }; | ||