i2c.c 3.4 KB

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