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>
22 #include <mach/cdce949.h>
26 static struct i2c_client
*cdce_i2c_client
;
27 static DEFINE_MUTEX(cdce_mutex
);
29 /* CDCE register descriptor */
35 /* Per-Output (Y1, Y2 etc.) frequency descriptor */
37 /* Frequency in KHz */
38 unsigned long frequency
;
40 * List of registers to program to obtain a particular frequency.
41 * 0x0 in register address and value is the end of list marker.
43 struct cdce_reg
*reglist
;
46 #define CDCE_FREQ_TABLE_ENTRY(line, out) \
48 .reglist = cdce_y ##line## _ ##out, \
52 /* List of CDCE outputs */
54 /* List of frequencies on this output */
55 struct cdce_freq
*freq_table
;
56 /* Number of possible frequencies */
61 * Finding out the values to program into CDCE949 registers for a particular
62 * frequency output is not a simple calculation. Have a look at the datasheet
63 * for the details. There is desktop software available to help users with
64 * the calculations. Here, we just depend on the output of that software
65 * (or hand calculations) instead trying to runtime calculate the register
66 * values and inflicting misery on ourselves.
68 static struct cdce_reg cdce_y1_148500
[] = {
70 /* program PLL1_0 multiplier */
75 /* program PLL1_11 multiplier */
80 /* output state selection */
83 /* switch MUX to PLL1 output */
86 /* set P2DIV divider, P3DIV and input crystal */
91 /* enable and disable PLL */
97 static struct cdce_reg cdce_y1_74250
[] = {
107 /* output state selection */
110 /* switch MUX to PLL1 output */
113 /* set P2DIV divider, P3DIV and input crystal */
118 /* enable and disable PLL */
124 static struct cdce_reg cdce_y1_27000
[] = {
145 static struct cdce_freq cdce_y1_freqs
[] = {
146 CDCE_FREQ_TABLE_ENTRY(1, 148500),
147 CDCE_FREQ_TABLE_ENTRY(1, 74250),
148 CDCE_FREQ_TABLE_ENTRY(1, 27000),
151 static struct cdce_reg cdce_y5_13500
[] = {
161 static struct cdce_reg cdce_y5_16875
[] = {
171 static struct cdce_reg cdce_y5_27000
[] = {
180 static struct cdce_reg cdce_y5_54000
[] = {
190 static struct cdce_reg cdce_y5_81000
[] = {
200 static struct cdce_freq cdce_y5_freqs
[] = {
201 CDCE_FREQ_TABLE_ENTRY(5, 13500),
202 CDCE_FREQ_TABLE_ENTRY(5, 16875),
203 CDCE_FREQ_TABLE_ENTRY(5, 27000),
204 CDCE_FREQ_TABLE_ENTRY(5, 54000),
205 CDCE_FREQ_TABLE_ENTRY(5, 81000),
209 static struct cdce_output output_list
[] = {
210 [1] = { cdce_y1_freqs
, ARRAY_SIZE(cdce_y1_freqs
) },
211 [5] = { cdce_y5_freqs
, ARRAY_SIZE(cdce_y5_freqs
) },
214 int cdce_set_rate(struct clk
*clk
, unsigned long rate
)
217 struct cdce_freq
*freq_table
= output_list
[clk
->lpsc
].freq_table
;
218 struct cdce_reg
*regs
= NULL
;
220 if (!cdce_i2c_client
)
226 for (i
= 0; i
< output_list
[clk
->lpsc
].size
; i
++) {
227 if (freq_table
[i
].frequency
== rate
/ 1000) {
228 regs
= freq_table
[i
].reglist
;
236 mutex_lock(&cdce_mutex
);
237 for (i
= 0; regs
[i
].addr
; i
++) {
238 ret
= i2c_smbus_write_byte_data(cdce_i2c_client
,
239 regs
[i
].addr
| 0x80, regs
[i
].val
);
243 mutex_unlock(&cdce_mutex
);
251 static int cdce_probe(struct i2c_client
*client
,
252 const struct i2c_device_id
*id
)
254 cdce_i2c_client
= client
;
258 static int __devexit
cdce_remove(struct i2c_client
*client
)
260 cdce_i2c_client
= NULL
;
264 static const struct i2c_device_id cdce_id
[] = {
268 MODULE_DEVICE_TABLE(i2c
, cdce_id
);
270 static struct i2c_driver cdce_driver
= {
272 .owner
= THIS_MODULE
,
276 .remove
= __devexit_p(cdce_remove
),
280 static int __init
cdce_init(void)
282 return i2c_add_driver(&cdce_driver
);
284 subsys_initcall(cdce_init
);
286 static void __exit
cdce_exit(void)
288 i2c_del_driver(&cdce_driver
);
290 module_exit(cdce_exit
);
292 MODULE_AUTHOR("Texas Instruments");
293 MODULE_DESCRIPTION("CDCE949 clock synthesizer driver");
294 MODULE_LICENSE("GPL v2");
This page took 0.036168 seconds and 5 git commands to generate.