summaryrefslogtreecommitdiffstats
path: root/drivers/clk/imx/clk-imx1.c
blob: 5f600a9da3e13aec196ae8a228c44c9bb410af03 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 *  Copyright (C) 2008 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <common.h>
#include <init.h>
#include <driver.h>
#include <linux/clk.h>
#include <io.h>
#include <linux/clkdev.h>
#include <linux/err.h>
#include <mach/imx1-regs.h>

#include "clk.h"

#define CCM_CSCR	0x0
#define CCM_MPCTL0	0x4
#define CCM_SPCTL0	0xc
#define CCM_PCDR	0x20

enum imx1_clks {
	dummy, clk32, clk16m, clk32_premult, prem, mpll, spll, mcu,
	fclk, hclk, clk48m, per1, per2, per3, clko, dma_gate, csi_gate,
	mma_gate, usbd_gate, clk_max
};

static struct clk *clks[clk_max];

static const char *prem_sel_clks[] = {
	"clk32_premult",
	"clk16m",
};

static const char *clko_sel_clks[] = {
	"per1",
	"hclk",
	"clk48m",
	"clk16m",
	"prem",
	"fclk",
};

int __init mx1_clocks_init(void __iomem *regs, unsigned long fref)
{
	clks[dummy] = clk_fixed("dummy", 0);
	clks[clk32] = clk_fixed("clk32", fref);
	clks[clk16m] = clk_fixed("clk16m", 16000000);
	clks[clk32_premult] = imx_clk_fixed_factor("clk32_premult", "clk32", 512, 1);
	clks[prem] = imx_clk_mux("prem", regs + CCM_CSCR, 16, 1, prem_sel_clks,
			ARRAY_SIZE(prem_sel_clks));
	clks[mpll] = imx_clk_pllv1("mpll", "clk32_premult", regs + CCM_MPCTL0);
	clks[spll] = imx_clk_pllv1("spll", "prem", regs + CCM_SPCTL0);
	clks[mcu] = imx_clk_divider("mcu", "clk32_premult", regs + CCM_CSCR, 15, 1);
	clks[fclk] = imx_clk_divider("fclk", "mpll", regs + CCM_CSCR, 15, 1);
	clks[hclk] = imx_clk_divider("hclk", "spll", regs + CCM_CSCR, 10, 4);
	clks[clk48m] = imx_clk_divider("clk48m", "spll", regs + CCM_CSCR, 26, 3);
	clks[per1] = imx_clk_divider("per1", "spll", regs + CCM_PCDR, 0, 4);
	clks[per2] = imx_clk_divider("per2", "spll", regs + CCM_PCDR, 4, 4);
	clks[per3] = imx_clk_divider("per3", "spll", regs + CCM_PCDR, 16, 7);
	clks[clko] = imx_clk_mux("clko", regs + CCM_CSCR, 29, 3, clko_sel_clks,
			ARRAY_SIZE(clko_sel_clks));

	clkdev_add_physbase(clks[per1], MX1_TIM1_BASE_ADDR, NULL);
	clkdev_add_physbase(clks[per1], MX1_TIM2_BASE_ADDR, NULL);
	clkdev_add_physbase(clks[per2], MX1_LCDC_BASE_ADDR, NULL);
	clkdev_add_physbase(clks[per1], MX1_UART1_BASE_ADDR, NULL);
	clkdev_add_physbase(clks[per1], MX1_UART2_BASE_ADDR, NULL);
	clkdev_add_physbase(clks[per2], MX1_CSPI1_BASE_ADDR, NULL);
	clkdev_add_physbase(clks[per2], MX1_CSPI2_BASE_ADDR, NULL);
	clkdev_add_physbase(clks[hclk], MX1_I2C_BASE_ADDR, NULL);

	return 0;
}

static int imx1_ccm_probe(struct device_d *dev)
{
	struct resource *iores;
	void __iomem *regs;

	iores = dev_request_mem_resource(dev, 0);
	if (IS_ERR(iores))
		return PTR_ERR(iores);
	regs = IOMEM(iores->start);

	mx1_clocks_init(regs, 32000);

	return 0;
}

static __maybe_unused struct of_device_id imx1_ccm_dt_ids[] = {
	{
		.compatible = "fsl,imx1-ccm",
	}, {
		/* sentinel */
	}
};

static struct driver_d imx1_ccm_driver = {
	.probe	= imx1_ccm_probe,
	.name	= "imx1-ccm",
	.of_compatible = DRV_OF_COMPAT(imx1_ccm_dt_ids),
};

static int imx1_ccm_init(void)
{
	return platform_driver_register(&imx1_ccm_driver);
}
core_initcall(imx1_ccm_init);