i.MX pcm043: Add AC97 sound support
[linux-2.6/kvm.git] / arch / arm / mach-pnx4008 / i2c.c
blobf3fea29c00d3b3072008bf52f2c224370f544357
1 /*
2 * I2C initialization for PNX4008.
4 * Author: Vitaly Wool <vitalywool@gmail.com>
6 * 2005-2006 (c) MontaVista Software, Inc. This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
12 #include <linux/clk.h>
13 #include <linux/i2c.h>
14 #include <linux/i2c-pnx.h>
15 #include <linux/platform_device.h>
16 #include <linux/err.h>
17 #include <mach/platform.h>
18 #include <mach/irqs.h>
19 #include <mach/i2c.h>
21 static int set_clock_run(struct platform_device *pdev)
23 struct clk *clk;
24 char name[10];
25 int retval = 0;
27 snprintf(name, 10, "i2c%d_ck", pdev->id);
28 clk = clk_get(&pdev->dev, name);
29 if (!IS_ERR(clk)) {
30 clk_set_rate(clk, 1);
31 clk_put(clk);
32 } else
33 retval = -ENOENT;
35 return retval;
38 static int set_clock_stop(struct platform_device *pdev)
40 struct clk *clk;
41 char name[10];
42 int retval = 0;
44 snprintf(name, 10, "i2c%d_ck", pdev->id);
45 clk = clk_get(&pdev->dev, name);
46 if (!IS_ERR(clk)) {
47 clk_set_rate(clk, 0);
48 clk_put(clk);
49 } else
50 retval = -ENOENT;
52 return retval;
55 static int i2c_pnx_suspend(struct platform_device *pdev, pm_message_t state)
57 int retval = 0;
58 #ifdef CONFIG_PM
59 retval = set_clock_run(pdev);
60 #endif
61 return retval;
64 static int i2c_pnx_resume(struct platform_device *pdev)
66 int retval = 0;
67 #ifdef CONFIG_PM
68 retval = set_clock_run(pdev);
69 #endif
70 return retval;
73 static u32 calculate_input_freq(struct platform_device *pdev)
75 return HCLK_MHZ;
79 static struct i2c_pnx_algo_data pnx_algo_data0 = {
80 .base = PNX4008_I2C1_BASE,
81 .irq = I2C_1_INT,
84 static struct i2c_pnx_algo_data pnx_algo_data1 = {
85 .base = PNX4008_I2C2_BASE,
86 .irq = I2C_2_INT,
89 static struct i2c_pnx_algo_data pnx_algo_data2 = {
90 .base = (PNX4008_USB_CONFIG_BASE + 0x300),
91 .irq = USB_I2C_INT,
94 static struct i2c_adapter pnx_adapter0 = {
95 .name = I2C_CHIP_NAME "0",
96 .algo_data = &pnx_algo_data0,
98 static struct i2c_adapter pnx_adapter1 = {
99 .name = I2C_CHIP_NAME "1",
100 .algo_data = &pnx_algo_data1,
103 static struct i2c_adapter pnx_adapter2 = {
104 .name = "USB-I2C",
105 .algo_data = &pnx_algo_data2,
108 static struct i2c_pnx_data i2c0_data = {
109 .suspend = i2c_pnx_suspend,
110 .resume = i2c_pnx_resume,
111 .calculate_input_freq = calculate_input_freq,
112 .set_clock_run = set_clock_run,
113 .set_clock_stop = set_clock_stop,
114 .adapter = &pnx_adapter0,
117 static struct i2c_pnx_data i2c1_data = {
118 .suspend = i2c_pnx_suspend,
119 .resume = i2c_pnx_resume,
120 .calculate_input_freq = calculate_input_freq,
121 .set_clock_run = set_clock_run,
122 .set_clock_stop = set_clock_stop,
123 .adapter = &pnx_adapter1,
126 static struct i2c_pnx_data i2c2_data = {
127 .suspend = i2c_pnx_suspend,
128 .resume = i2c_pnx_resume,
129 .calculate_input_freq = calculate_input_freq,
130 .set_clock_run = set_clock_run,
131 .set_clock_stop = set_clock_stop,
132 .adapter = &pnx_adapter2,
135 static struct platform_device i2c0_device = {
136 .name = "pnx-i2c",
137 .id = 0,
138 .dev = {
139 .platform_data = &i2c0_data,
143 static struct platform_device i2c1_device = {
144 .name = "pnx-i2c",
145 .id = 1,
146 .dev = {
147 .platform_data = &i2c1_data,
151 static struct platform_device i2c2_device = {
152 .name = "pnx-i2c",
153 .id = 2,
154 .dev = {
155 .platform_data = &i2c2_data,
159 static struct platform_device *devices[] __initdata = {
160 &i2c0_device,
161 &i2c1_device,
162 &i2c2_device,
165 void __init pnx4008_register_i2c_devices(void)
167 platform_add_devices(devices, ARRAY_SIZE(devices));