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>
20 #include <linux/module.h>
22 #include <mach/clock.h>
23 #include <mach/cdce949.h>
27 static struct i2c_client
*cdce_i2c_client
;
28 static DEFINE_MUTEX(cdce_mutex
);
30 /* CDCE register descriptor */
36 /* Per-Output (Y1, Y2 etc.) frequency descriptor */
38 /* Frequency in KHz */
39 unsigned long frequency
;
41 * List of registers to program to obtain a particular frequency.
42 * 0x0 in register address and value is the end of list marker.
44 struct cdce_reg
*reglist
;
47 #define CDCE_FREQ_TABLE_ENTRY(line, out) \
49 .reglist = cdce_y ##line## _ ##out, \
53 /* List of CDCE outputs */
55 /* List of frequencies on this output */
56 struct cdce_freq
*freq_table
;
57 /* Number of possible frequencies */
62 * Finding out the values to program into CDCE949 registers for a particular
63 * frequency output is not a simple calculation. Have a look at the datasheet
64 * for the details. There is desktop software available to help users with
65 * the calculations. Here, we just depend on the output of that software
66 * (or hand calculations) instead trying to runtime calculate the register
67 * values and inflicting misery on ourselves.
69 static struct cdce_reg cdce_y1_148500
[] = {
71 /* program PLL1_0 multiplier */
76 /* program PLL1_11 multiplier */
81 /* output state selection */
84 /* switch MUX to PLL1 output */
87 /* set P2DIV divider, P3DIV and input crystal */
92 /* enable and disable PLL */
98 static struct cdce_reg cdce_y1_74250
[] = {
108 /* output state selection */
111 /* switch MUX to PLL1 output */
114 /* set P2DIV divider, P3DIV and input crystal */
119 /* enable and disable PLL */
125 static struct cdce_reg cdce_y1_27000
[] = {
146 static struct cdce_freq cdce_y1_freqs
[] = {
147 CDCE_FREQ_TABLE_ENTRY(1, 148500),
148 CDCE_FREQ_TABLE_ENTRY(1, 74250),
149 CDCE_FREQ_TABLE_ENTRY(1, 27000),
152 static struct cdce_reg cdce_y5_13500
[] = {
162 static struct cdce_reg cdce_y5_16875
[] = {
172 static struct cdce_reg cdce_y5_27000
[] = {
181 static struct cdce_reg cdce_y5_54000
[] = {
191 static struct cdce_reg cdce_y5_81000
[] = {
201 static struct cdce_freq cdce_y5_freqs
[] = {
202 CDCE_FREQ_TABLE_ENTRY(5, 13500),
203 CDCE_FREQ_TABLE_ENTRY(5, 16875),
204 CDCE_FREQ_TABLE_ENTRY(5, 27000),
205 CDCE_FREQ_TABLE_ENTRY(5, 54000),
206 CDCE_FREQ_TABLE_ENTRY(5, 81000),
210 static struct cdce_output output_list
[] = {
211 [1] = { cdce_y1_freqs
, ARRAY_SIZE(cdce_y1_freqs
) },
212 [5] = { cdce_y5_freqs
, ARRAY_SIZE(cdce_y5_freqs
) },
215 int cdce_set_rate(struct clk
*clk
, unsigned long rate
)
218 struct cdce_freq
*freq_table
= output_list
[clk
->lpsc
].freq_table
;
219 struct cdce_reg
*regs
= NULL
;
221 if (!cdce_i2c_client
)
227 for (i
= 0; i
< output_list
[clk
->lpsc
].size
; i
++) {
228 if (freq_table
[i
].frequency
== rate
/ 1000) {
229 regs
= freq_table
[i
].reglist
;
237 mutex_lock(&cdce_mutex
);
238 for (i
= 0; regs
[i
].addr
; i
++) {
239 ret
= i2c_smbus_write_byte_data(cdce_i2c_client
,
240 regs
[i
].addr
| 0x80, regs
[i
].val
);
244 mutex_unlock(&cdce_mutex
);
252 static int cdce_probe(struct i2c_client
*client
,
253 const struct i2c_device_id
*id
)
255 cdce_i2c_client
= client
;
259 static int cdce_remove(struct i2c_client
*client
)
261 cdce_i2c_client
= NULL
;
265 static const struct i2c_device_id cdce_id
[] = {
269 MODULE_DEVICE_TABLE(i2c
, cdce_id
);
271 static struct i2c_driver cdce_driver
= {
273 .owner
= THIS_MODULE
,
277 .remove
= cdce_remove
,
281 static int __init
cdce_init(void)
283 return i2c_add_driver(&cdce_driver
);
285 subsys_initcall(cdce_init
);
287 static void __exit
cdce_exit(void)
289 i2c_del_driver(&cdce_driver
);
291 module_exit(cdce_exit
);
293 MODULE_AUTHOR("Texas Instruments");
294 MODULE_DESCRIPTION("CDCE949 clock synthesizer driver");
295 MODULE_LICENSE("GPL v2");