i2c.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Helper module for board specific I2C bus registration
  3. *
  4. * Copyright (C) 2009 Nokia Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA
  19. *
  20. */
  21. #include <plat/cpu.h>
  22. #include <plat/i2c.h>
  23. #include <plat/common.h>
  24. #include <plat/omap_hwmod.h>
  25. #include "mux.h"
  26. /* In register I2C_CON, Bit 15 is the I2C enable bit */
  27. #define I2C_EN BIT(15)
  28. #define OMAP2_I2C_CON_OFFSET 0x24
  29. #define OMAP4_I2C_CON_OFFSET 0xA4
  30. /* Maximum microseconds to wait for OMAP module to softreset */
  31. #define MAX_MODULE_SOFTRESET_WAIT 10000
  32. void __init omap2_i2c_mux_pins(int bus_id)
  33. {
  34. char mux_name[sizeof("i2c2_scl.i2c2_scl")];
  35. /* First I2C bus is not muxable */
  36. if (bus_id == 1)
  37. return;
  38. sprintf(mux_name, "i2c%i_scl.i2c%i_scl", bus_id, bus_id);
  39. omap_mux_init_signal(mux_name, OMAP_PIN_INPUT);
  40. sprintf(mux_name, "i2c%i_sda.i2c%i_sda", bus_id, bus_id);
  41. omap_mux_init_signal(mux_name, OMAP_PIN_INPUT);
  42. }
  43. /**
  44. * omap_i2c_reset - reset the omap i2c module.
  45. * @oh: struct omap_hwmod *
  46. *
  47. * The i2c moudle in omap2, omap3 had a special sequence to reset. The
  48. * sequence is:
  49. * - Disable the I2C.
  50. * - Write to SOFTRESET bit.
  51. * - Enable the I2C.
  52. * - Poll on the RESETDONE bit.
  53. * The sequence is implemented in below function. This is called for 2420,
  54. * 2430 and omap3.
  55. */
  56. int omap_i2c_reset(struct omap_hwmod *oh)
  57. {
  58. u32 v;
  59. u16 i2c_con;
  60. int c = 0;
  61. if (oh->class->rev == OMAP_I2C_IP_VERSION_2) {
  62. i2c_con = OMAP4_I2C_CON_OFFSET;
  63. } else if (oh->class->rev == OMAP_I2C_IP_VERSION_1) {
  64. i2c_con = OMAP2_I2C_CON_OFFSET;
  65. } else {
  66. WARN(1, "Cannot reset I2C block %s: unsupported revision\n",
  67. oh->name);
  68. return -EINVAL;
  69. }
  70. /* Disable I2C */
  71. v = omap_hwmod_read(oh, i2c_con);
  72. v &= ~I2C_EN;
  73. omap_hwmod_write(v, oh, i2c_con);
  74. /* Write to the SOFTRESET bit */
  75. omap_hwmod_softreset(oh);
  76. /* Enable I2C */
  77. v = omap_hwmod_read(oh, i2c_con);
  78. v |= I2C_EN;
  79. omap_hwmod_write(v, oh, i2c_con);
  80. /* Poll on RESETDONE bit */
  81. omap_test_timeout((omap_hwmod_read(oh,
  82. oh->class->sysc->syss_offs)
  83. & SYSS_RESETDONE_MASK),
  84. MAX_MODULE_SOFTRESET_WAIT, c);
  85. if (c == MAX_MODULE_SOFTRESET_WAIT)
  86. pr_warning("%s: %s: softreset failed (waited %d usec)\n",
  87. __func__, oh->name, MAX_MODULE_SOFTRESET_WAIT);
  88. else
  89. pr_debug("%s: %s: softreset in %d usec\n", __func__,
  90. oh->name, c);
  91. return 0;
  92. }