i2c.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * I2C initialization for PNX4008.
  3. *
  4. * Author: Vitaly Wool <vitalywool@gmail.com>
  5. *
  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.
  10. */
  11. #include <linux/clk.h>
  12. #include <linux/i2c.h>
  13. #include <linux/i2c-pnx.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/err.h>
  16. #include <mach/platform.h>
  17. #include <mach/irqs.h>
  18. #include <mach/i2c.h>
  19. static int set_clock_run(struct platform_device *pdev)
  20. {
  21. struct clk *clk;
  22. char name[10];
  23. int retval = 0;
  24. snprintf(name, 10, "i2c%d_ck", pdev->id);
  25. clk = clk_get(&pdev->dev, name);
  26. if (!IS_ERR(clk)) {
  27. clk_set_rate(clk, 1);
  28. clk_put(clk);
  29. } else
  30. retval = -ENOENT;
  31. return retval;
  32. }
  33. static int set_clock_stop(struct platform_device *pdev)
  34. {
  35. struct clk *clk;
  36. char name[10];
  37. int retval = 0;
  38. snprintf(name, 10, "i2c%d_ck", pdev->id);
  39. clk = clk_get(&pdev->dev, name);
  40. if (!IS_ERR(clk)) {
  41. clk_set_rate(clk, 0);
  42. clk_put(clk);
  43. } else
  44. retval = -ENOENT;
  45. return retval;
  46. }
  47. static int i2c_pnx_suspend(struct platform_device *pdev, pm_message_t state)
  48. {
  49. int retval = 0;
  50. #ifdef CONFIG_PM
  51. retval = set_clock_run(pdev);
  52. #endif
  53. return retval;
  54. }
  55. static int i2c_pnx_resume(struct platform_device *pdev)
  56. {
  57. int retval = 0;
  58. #ifdef CONFIG_PM
  59. retval = set_clock_run(pdev);
  60. #endif
  61. return retval;
  62. }
  63. static u32 calculate_input_freq(struct platform_device *pdev)
  64. {
  65. return HCLK_MHZ;
  66. }
  67. static struct i2c_pnx_algo_data pnx_algo_data0 = {
  68. .base = PNX4008_I2C1_BASE,
  69. .irq = I2C_1_INT,
  70. };
  71. static struct i2c_pnx_algo_data pnx_algo_data1 = {
  72. .base = PNX4008_I2C2_BASE,
  73. .irq = I2C_2_INT,
  74. };
  75. static struct i2c_pnx_algo_data pnx_algo_data2 = {
  76. .base = (PNX4008_USB_CONFIG_BASE + 0x300),
  77. .irq = USB_I2C_INT,
  78. };
  79. static struct i2c_adapter pnx_adapter0 = {
  80. .name = I2C_CHIP_NAME "0",
  81. .algo_data = &pnx_algo_data0,
  82. };
  83. static struct i2c_adapter pnx_adapter1 = {
  84. .name = I2C_CHIP_NAME "1",
  85. .algo_data = &pnx_algo_data1,
  86. };
  87. static struct i2c_adapter pnx_adapter2 = {
  88. .name = "USB-I2C",
  89. .algo_data = &pnx_algo_data2,
  90. };
  91. static struct i2c_pnx_data i2c0_data = {
  92. .suspend = i2c_pnx_suspend,
  93. .resume = i2c_pnx_resume,
  94. .calculate_input_freq = calculate_input_freq,
  95. .set_clock_run = set_clock_run,
  96. .set_clock_stop = set_clock_stop,
  97. .adapter = &pnx_adapter0,
  98. };
  99. static struct i2c_pnx_data i2c1_data = {
  100. .suspend = i2c_pnx_suspend,
  101. .resume = i2c_pnx_resume,
  102. .calculate_input_freq = calculate_input_freq,
  103. .set_clock_run = set_clock_run,
  104. .set_clock_stop = set_clock_stop,
  105. .adapter = &pnx_adapter1,
  106. };
  107. static struct i2c_pnx_data i2c2_data = {
  108. .suspend = i2c_pnx_suspend,
  109. .resume = i2c_pnx_resume,
  110. .calculate_input_freq = calculate_input_freq,
  111. .set_clock_run = set_clock_run,
  112. .set_clock_stop = set_clock_stop,
  113. .adapter = &pnx_adapter2,
  114. };
  115. static struct platform_device i2c0_device = {
  116. .name = "pnx-i2c",
  117. .id = 0,
  118. .dev = {
  119. .platform_data = &i2c0_data,
  120. },
  121. };
  122. static struct platform_device i2c1_device = {
  123. .name = "pnx-i2c",
  124. .id = 1,
  125. .dev = {
  126. .platform_data = &i2c1_data,
  127. },
  128. };
  129. static struct platform_device i2c2_device = {
  130. .name = "pnx-i2c",
  131. .id = 2,
  132. .dev = {
  133. .platform_data = &i2c2_data,
  134. },
  135. };
  136. static struct platform_device *devices[] __initdata = {
  137. &i2c0_device,
  138. &i2c1_device,
  139. &i2c2_device,
  140. };
  141. void __init pnx4008_register_i2c_devices(void)
  142. {
  143. platform_add_devices(devices, ARRAY_SIZE(devices));
  144. }