i2c.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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/i2c.h>
  22. #include "common.h"
  23. #include <plat/omap_hwmod.h>
  24. #include "mux.h"
  25. /* In register I2C_CON, Bit 15 is the I2C enable bit */
  26. #define I2C_EN BIT(15)
  27. #define OMAP2_I2C_CON_OFFSET 0x24
  28. #define OMAP4_I2C_CON_OFFSET 0xA4
  29. /* Maximum microseconds to wait for OMAP module to softreset */
  30. #define MAX_MODULE_SOFTRESET_WAIT 10000
  31. void __init omap2_i2c_mux_pins(int bus_id)
  32. {
  33. char mux_name[sizeof("i2c2_scl.i2c2_scl")];
  34. /* First I2C bus is not muxable */
  35. if (bus_id == 1)
  36. return;
  37. sprintf(mux_name, "i2c%i_scl.i2c%i_scl", bus_id, bus_id);
  38. omap_mux_init_signal(mux_name, OMAP_PIN_INPUT);
  39. sprintf(mux_name, "i2c%i_sda.i2c%i_sda", bus_id, bus_id);
  40. omap_mux_init_signal(mux_name, OMAP_PIN_INPUT);
  41. }
  42. /**
  43. * omap_i2c_reset - reset the omap i2c module.
  44. * @oh: struct omap_hwmod *
  45. *
  46. * The i2c moudle in omap2, omap3 had a special sequence to reset. The
  47. * sequence is:
  48. * - Disable the I2C.
  49. * - Write to SOFTRESET bit.
  50. * - Enable the I2C.
  51. * - Poll on the RESETDONE bit.
  52. * The sequence is implemented in below function. This is called for 2420,
  53. * 2430 and omap3.
  54. */
  55. int omap_i2c_reset(struct omap_hwmod *oh)
  56. {
  57. u32 v;
  58. u16 i2c_con;
  59. int c = 0;
  60. if (oh->class->rev == OMAP_I2C_IP_VERSION_2) {
  61. i2c_con = OMAP4_I2C_CON_OFFSET;
  62. } else if (oh->class->rev == OMAP_I2C_IP_VERSION_1) {
  63. i2c_con = OMAP2_I2C_CON_OFFSET;
  64. } else {
  65. WARN(1, "Cannot reset I2C block %s: unsupported revision\n",
  66. oh->name);
  67. return -EINVAL;
  68. }
  69. /* Disable I2C */
  70. v = omap_hwmod_read(oh, i2c_con);
  71. v &= ~I2C_EN;
  72. omap_hwmod_write(v, oh, i2c_con);
  73. /* Write to the SOFTRESET bit */
  74. omap_hwmod_softreset(oh);
  75. /* Enable I2C */
  76. v = omap_hwmod_read(oh, i2c_con);
  77. v |= I2C_EN;
  78. omap_hwmod_write(v, oh, i2c_con);
  79. /* Poll on RESETDONE bit */
  80. omap_test_timeout((omap_hwmod_read(oh,
  81. oh->class->sysc->syss_offs)
  82. & SYSS_RESETDONE_MASK),
  83. MAX_MODULE_SOFTRESET_WAIT, c);
  84. if (c == MAX_MODULE_SOFTRESET_WAIT)
  85. pr_warning("%s: %s: softreset failed (waited %d usec)\n",
  86. __func__, oh->name, MAX_MODULE_SOFTRESET_WAIT);
  87. else
  88. pr_debug("%s: %s: softreset in %d usec\n", __func__,
  89. oh->name, c);
  90. return 0;
  91. }