Root/target/linux/ramips/files/arch/mips/ralink/rt305x/clock.c

1/*
2 * Ralink RT305X clock API
3 *
4 * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/err.h>
15#include <linux/clk.h>
16
17#include <asm/mach-ralink/common.h>
18#include <asm/mach-ralink/rt305x.h>
19#include <asm/mach-ralink/rt305x_regs.h>
20#include "common.h"
21
22struct clk {
23    unsigned long rate;
24};
25
26static struct clk rt305x_cpu_clk;
27static struct clk rt305x_sys_clk;
28static struct clk rt305x_wdt_clk;
29static struct clk rt305x_uart_clk;
30
31void __init rt305x_clocks_init(void)
32{
33    u32 t;
34
35    t = rt305x_sysc_rr(SYSC_REG_SYSTEM_CONFIG);
36    t = ((t >> SYSTEM_CONFIG_CPUCLK_SHIFT) & SYSTEM_CONFIG_CPUCLK_MASK);
37
38    switch (t) {
39    case SYSTEM_CONFIG_CPUCLK_320:
40        rt305x_cpu_clk.rate = 320000000;
41        break;
42    case SYSTEM_CONFIG_CPUCLK_384:
43        rt305x_cpu_clk.rate = 384000000;
44        break;
45    }
46
47    rt305x_sys_clk.rate = rt305x_cpu_clk.rate / 3;
48    rt305x_uart_clk.rate = rt305x_sys_clk.rate;
49    rt305x_wdt_clk.rate = rt305x_sys_clk.rate;
50}
51
52/*
53 * Linux clock API
54 */
55struct clk *clk_get(struct device *dev, const char *id)
56{
57    if (!strcmp(id, "sys"))
58        return &rt305x_sys_clk;
59
60    if (!strcmp(id, "cpu"))
61        return &rt305x_cpu_clk;
62
63    if (!strcmp(id, "wdt"))
64        return &rt305x_wdt_clk;
65
66    if (!strcmp(id, "uart"))
67        return &rt305x_uart_clk;
68
69    return ERR_PTR(-ENOENT);
70}
71EXPORT_SYMBOL(clk_get);
72
73int clk_enable(struct clk *clk)
74{
75    return 0;
76}
77EXPORT_SYMBOL(clk_enable);
78
79void clk_disable(struct clk *clk)
80{
81}
82EXPORT_SYMBOL(clk_disable);
83
84unsigned long clk_get_rate(struct clk *clk)
85{
86    return clk->rate;
87}
88EXPORT_SYMBOL(clk_get_rate);
89
90void clk_put(struct clk *clk)
91{
92}
93EXPORT_SYMBOL(clk_put);
94

Archive Download this file



interactive