2 * TI CDCE949 clock synthesizer driver
4 * Note: This implementation assumes an input of 27MHz to the CDCE.
5 * This is by no means constrained by CDCE hardware although the datasheet
6 * does use this as an example for all illustrations and more importantly:
7 * that is the crystal input on boards it is currently used on.
9 * Copyright (C) 2009 Texas Instruments Incorporated. http://www.ti.com/
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/kernel.h>
17 #include <linux/clk.h>
18 #include <linux/platform_device.h>
19 #include <linux/i2c.h>
21 #include <mach/clock.h>
25 static struct i2c_client
*cdce_i2c_client
;
26 static DEFINE_MUTEX(cdce_mutex
);
28 /* CDCE register descriptor */
34 /* Per-Output (Y1, Y2 etc.) frequency descriptor */
36 /* Frequency in KHz */
37 unsigned long frequency
;
39 * List of registers to program to obtain a particular frequency.
40 * 0x0 in register address and value is the end of list marker.
42 struct cdce_reg
*reglist
;
45 #define CDCE_FREQ_TABLE_ENTRY(line, out) \
47 .reglist = cdce_y ##line## _ ##out, \
51 /* List of CDCE outputs */
53 /* List of frequencies on this output */
54 struct cdce_freq
*freq_table
;
55 /* Number of possible frequencies */
60 * Finding out the values to program into CDCE949 registers for a particular
61 * frequency output is not a simple calculation. Have a look at the datasheet
62 * for the details. There is desktop software available to help users with
63 * the calculations. Here, we just depend on the output of that software
64 * (or hand calculations) instead trying to runtime calculate the register
65 * values and inflicting misery on ourselves.
67 static struct cdce_reg cdce_y1_148500
[] = {
69 /* program PLL1_0 multiplier */
74 /* program PLL1_11 multiplier */
79 /* output state selection */
82 /* switch MUX to PLL1 output */
85 /* set P2DIV divider, P3DIV and input crystal */
90 /* enable and disable PLL */
96 static struct cdce_reg cdce_y1_74250
[] = {
106 /* output state selection */
109 /* switch MUX to PLL1 output */
112 /* set P2DIV divider, P3DIV and input crystal */
117 /* enable and disable PLL */
123 static struct cdce_reg cdce_y1_27000
[] = {
144 static struct cdce_freq cdce_y1_freqs
[] = {
145 CDCE_FREQ_TABLE_ENTRY(1, 148500),
146 CDCE_FREQ_TABLE_ENTRY(1, 74250),
147 CDCE_FREQ_TABLE_ENTRY(1, 27000),
150 static struct cdce_reg cdce_y5_13500
[] = {
160 static struct cdce_reg cdce_y5_16875
[] = {
170 static struct cdce_reg cdce_y5_27000
[] = {
179 static struct cdce_reg cdce_y5_54000
[] = {
189 static struct cdce_reg cdce_y5_81000
[] = {
199 static struct cdce_freq cdce_y5_freqs
[] = {
200 CDCE_FREQ_TABLE_ENTRY(5, 13500),
201 CDCE_FREQ_TABLE_ENTRY(5, 16875),
202 CDCE_FREQ_TABLE_ENTRY(5, 27000),
203 CDCE_FREQ_TABLE_ENTRY(5, 54000),
204 CDCE_FREQ_TABLE_ENTRY(5, 81000),
208 static struct cdce_output output_list
[] = {
209 [1] = { cdce_y1_freqs
, ARRAY_SIZE(cdce_y1_freqs
) },
210 [5] = { cdce_y5_freqs
, ARRAY_SIZE(cdce_y5_freqs
) },
213 int cdce_set_rate(struct clk
*clk
, unsigned long rate
)
216 struct cdce_freq
*freq_table
= output_list
[clk
->lpsc
].freq_table
;
217 struct cdce_reg
*regs
= NULL
;
219 if (!cdce_i2c_client
)
225 for (i
= 0; i
< output_list
[clk
->lpsc
].size
; i
++) {
226 if (freq_table
[i
].frequency
== rate
/ 1000) {
227 regs
= freq_table
[i
].reglist
;
235 mutex_lock(&cdce_mutex
);
236 for (i
= 0; regs
[i
].addr
; i
++) {
237 ret
= i2c_smbus_write_byte_data(cdce_i2c_client
,
238 regs
[i
].addr
| 0x80, regs
[i
].val
);
242 mutex_unlock(&cdce_mutex
);
250 static int cdce_probe(struct i2c_client
*client
,
251 const struct i2c_device_id
*id
)
253 cdce_i2c_client
= client
;
257 static int __devexit
cdce_remove(struct i2c_client
*client
)
259 cdce_i2c_client
= NULL
;
263 static const struct i2c_device_id cdce_id
[] = {
267 MODULE_DEVICE_TABLE(i2c
, cdce_id
);
269 static struct i2c_driver cdce_driver
= {
271 .owner
= THIS_MODULE
,
275 .remove
= __devexit_p(cdce_remove
),
279 static int __init
cdce_init(void)
281 return i2c_add_driver(&cdce_driver
);
283 subsys_initcall(cdce_init
);
285 static void __exit
cdce_exit(void)
287 i2c_del_driver(&cdce_driver
);
289 module_exit(cdce_exit
);
291 MODULE_AUTHOR("Texas Instruments");
292 MODULE_DESCRIPTION("CDCE949 clock synthesizer driver");
293 MODULE_LICENSE("GPL v2");