i2c.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. int retval = 0;
  23. clk = clk_get(&pdev->dev, NULL);
  24. if (!IS_ERR(clk)) {
  25. clk_set_rate(clk, 1);
  26. clk_put(clk);
  27. } else
  28. retval = -ENOENT;
  29. return retval;
  30. }
  31. static int set_clock_stop(struct platform_device *pdev)
  32. {
  33. struct clk *clk;
  34. int retval = 0;
  35. clk = clk_get(&pdev->dev, NULL);
  36. if (!IS_ERR(clk)) {
  37. clk_set_rate(clk, 0);
  38. clk_put(clk);
  39. } else
  40. retval = -ENOENT;
  41. return retval;
  42. }
  43. static u32 calculate_input_freq(struct platform_device *pdev)
  44. {
  45. return HCLK_MHZ;
  46. }
  47. static struct i2c_pnx_algo_data pnx_algo_data0 = {
  48. .base = PNX4008_I2C1_BASE,
  49. .irq = I2C_1_INT,
  50. };
  51. static struct i2c_pnx_algo_data pnx_algo_data1 = {
  52. .base = PNX4008_I2C2_BASE,
  53. .irq = I2C_2_INT,
  54. };
  55. static struct i2c_pnx_algo_data pnx_algo_data2 = {
  56. .base = (PNX4008_USB_CONFIG_BASE + 0x300),
  57. .irq = USB_I2C_INT,
  58. };
  59. static struct i2c_adapter pnx_adapter0 = {
  60. .name = I2C_CHIP_NAME "0",
  61. .algo_data = &pnx_algo_data0,
  62. };
  63. static struct i2c_adapter pnx_adapter1 = {
  64. .name = I2C_CHIP_NAME "1",
  65. .algo_data = &pnx_algo_data1,
  66. };
  67. static struct i2c_adapter pnx_adapter2 = {
  68. .name = "USB-I2C",
  69. .algo_data = &pnx_algo_data2,
  70. };
  71. static struct i2c_pnx_data i2c0_data = {
  72. .calculate_input_freq = calculate_input_freq,
  73. .set_clock_run = set_clock_run,
  74. .set_clock_stop = set_clock_stop,
  75. .adapter = &pnx_adapter0,
  76. };
  77. static struct i2c_pnx_data i2c1_data = {
  78. .calculate_input_freq = calculate_input_freq,
  79. .set_clock_run = set_clock_run,
  80. .set_clock_stop = set_clock_stop,
  81. .adapter = &pnx_adapter1,
  82. };
  83. static struct i2c_pnx_data i2c2_data = {
  84. .calculate_input_freq = calculate_input_freq,
  85. .set_clock_run = set_clock_run,
  86. .set_clock_stop = set_clock_stop,
  87. .adapter = &pnx_adapter2,
  88. };
  89. static struct platform_device i2c0_device = {
  90. .name = "pnx-i2c",
  91. .id = 0,
  92. .dev = {
  93. .platform_data = &i2c0_data,
  94. },
  95. };
  96. static struct platform_device i2c1_device = {
  97. .name = "pnx-i2c",
  98. .id = 1,
  99. .dev = {
  100. .platform_data = &i2c1_data,
  101. },
  102. };
  103. static struct platform_device i2c2_device = {
  104. .name = "pnx-i2c",
  105. .id = 2,
  106. .dev = {
  107. .platform_data = &i2c2_data,
  108. },
  109. };
  110. static struct platform_device *devices[] __initdata = {
  111. &i2c0_device,
  112. &i2c1_device,
  113. &i2c2_device,
  114. };
  115. void __init pnx4008_register_i2c_devices(void)
  116. {
  117. platform_add_devices(devices, ARRAY_SIZE(devices));
  118. }