aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/adm8668/files-3.18/arch/mips/adm8668/clock.c
blob: 1e010fcc8f05d094c6ebeed1b883b174c7cf3c1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * ADM8668 minimal clock support
 *
 * Copyright (C) 2012, Florian Fainelli <florian@openwrt.org>
 *
 * Licensed under the terms of the GPLv2
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/clk.h>

#include <adm8668.h>

struct clk {
	unsigned long rate;
};

static struct clk uart_clk = {
	.rate	= 62500000,
};

static struct clk sys_clk;

struct clk *clk_get(struct device *dev, const char *id)
{
	const char *lookup = id;

	if (dev)
		lookup = dev_name(dev);

	if (!strcmp(lookup, "apb:uart0"))
		return &uart_clk;
	if (!strcmp(lookup, "sys"))
		return &sys_clk;

	return ERR_PTR(-ENOENT);
}
EXPORT_SYMBOL(clk_get);

int clk_enable(struct clk *clk)
{
	return 0;
}
EXPORT_SYMBOL(clk_enable);

void clk_disable(struct clk *clk)
{
}
EXPORT_SYMBOL(clk_disable);

unsigned long clk_get_rate(struct clk *clk)
{
	return clk->rate;
}
EXPORT_SYMBOL(clk_get_rate);

void clk_put(struct clk *clk)
{
}
EXPORT_SYMBOL(clk_put);

void __init adm8668_init_clocks(void)
{
	u32 adj;

	/* adjustable clock selection
	 * CR3 bit 14~11, 0000 -> 175MHz, 0001 -> 180MHz, etc...
	 */
	adj = (ADM8668_CONFIG_REG(ADM8668_CR3) >> 11) & 0xf;
	sys_clk.rate = 175000000 + (adj * 5000000);

	pr_info("ADM8668 CPU clock: %lu MHz\n", sys_clk.rate / 1000000);
}