2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU General Public License version 2 as published
4 * by the Free Software Foundation.
6 * Copyright (C) 2010 Thomas Langer <thomas.langer@lantiq.com>
7 * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
10 #include <linux/export.h>
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/types.h>
14 #include <linux/clk.h>
15 #include <linux/err.h>
16 #include <linux/list.h>
20 #include <asm/div64.h>
22 #include <lantiq_soc.h>
29 unsigned long (*get_rate
) (void);
32 static struct clk
*cpu_clk
;
33 static int cpu_clk_cnt
;
35 /* lantiq socs have 3 static clocks */
36 static struct clk cpu_clk_generic
[] = {
39 .get_rate
= ltq_get_cpu_hz
,
42 .get_rate
= ltq_get_fpi_hz
,
45 .get_rate
= ltq_get_io_region_clock
,
49 static struct resource ltq_cgu_resource
= {
51 .start
= LTQ_CGU_BASE_ADDR
,
52 .end
= LTQ_CGU_BASE_ADDR
+ LTQ_CGU_SIZE
- 1,
53 .flags
= IORESOURCE_MEM
,
56 /* remapped clock register range */
57 void __iomem
*ltq_cgu_membase
;
61 cpu_clk
= cpu_clk_generic
;
62 cpu_clk_cnt
= ARRAY_SIZE(cpu_clk_generic
);
65 static inline int clk_good(struct clk
*clk
)
67 return clk
&& !IS_ERR(clk
);
70 unsigned long clk_get_rate(struct clk
*clk
)
72 if (unlikely(!clk_good(clk
)))
78 if (clk
->get_rate
!= NULL
)
79 return clk
->get_rate();
83 EXPORT_SYMBOL(clk_get_rate
);
85 struct clk
*clk_get(struct device
*dev
, const char *id
)
89 for (i
= 0; i
< cpu_clk_cnt
; i
++)
90 if (!strcmp(id
, cpu_clk
[i
].name
))
93 return ERR_PTR(-ENOENT
);
95 EXPORT_SYMBOL(clk_get
);
97 void clk_put(struct clk
*clk
)
101 EXPORT_SYMBOL(clk_put
);
103 int clk_enable(struct clk
*clk
)
108 EXPORT_SYMBOL(clk_enable
);
110 void clk_disable(struct clk
*clk
)
114 EXPORT_SYMBOL(clk_disable
);
116 static inline u32
ltq_get_counter_resolution(void)
120 __asm__
__volatile__(
132 void __init
plat_time_init(void)
136 if (insert_resource(&iomem_resource
, <q_cgu_resource
) < 0)
137 panic("Failed to insert cgu memory");
139 if (request_mem_region(ltq_cgu_resource
.start
,
140 resource_size(<q_cgu_resource
), "cgu") < 0)
141 panic("Failed to request cgu memory");
143 ltq_cgu_membase
= ioremap_nocache(ltq_cgu_resource
.start
,
144 resource_size(<q_cgu_resource
));
145 if (!ltq_cgu_membase
) {
146 pr_err("Failed to remap cgu memory\n");
149 clk
= clk_get(0, "cpu");
150 mips_hpt_frequency
= clk_get_rate(clk
) / ltq_get_counter_resolution();
151 write_c0_compare(read_c0_count());