i2c.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Helper module for board specific I2C bus registration
  4. *
  5. * Copyright (C) 2009 Nokia Corporation.
  6. */
  7. #include "soc.h"
  8. #include "omap_hwmod.h"
  9. #include "omap_device.h"
  10. #include "prm.h"
  11. #include "common.h"
  12. #include "i2c.h"
  13. /* In register I2C_CON, Bit 15 is the I2C enable bit */
  14. #define I2C_EN BIT(15)
  15. #define OMAP2_I2C_CON_OFFSET 0x24
  16. #define OMAP4_I2C_CON_OFFSET 0xA4
  17. #define MAX_OMAP_I2C_HWMOD_NAME_LEN 16
  18. /**
  19. * omap_i2c_reset - reset the omap i2c module.
  20. * @oh: struct omap_hwmod *
  21. *
  22. * The i2c moudle in omap2, omap3 had a special sequence to reset. The
  23. * sequence is:
  24. * - Disable the I2C.
  25. * - Write to SOFTRESET bit.
  26. * - Enable the I2C.
  27. * - Poll on the RESETDONE bit.
  28. * The sequence is implemented in below function. This is called for 2420,
  29. * 2430 and omap3.
  30. */
  31. int omap_i2c_reset(struct omap_hwmod *oh)
  32. {
  33. u32 v;
  34. u16 i2c_con;
  35. int c = 0;
  36. if (soc_is_omap24xx() || soc_is_omap34xx() || soc_is_am35xx())
  37. i2c_con = OMAP2_I2C_CON_OFFSET;
  38. else
  39. i2c_con = OMAP4_I2C_CON_OFFSET;
  40. /* Disable I2C */
  41. v = omap_hwmod_read(oh, i2c_con);
  42. v &= ~I2C_EN;
  43. omap_hwmod_write(v, oh, i2c_con);
  44. /* Write to the SOFTRESET bit */
  45. omap_hwmod_softreset(oh);
  46. /* Enable I2C */
  47. v = omap_hwmod_read(oh, i2c_con);
  48. v |= I2C_EN;
  49. omap_hwmod_write(v, oh, i2c_con);
  50. /* Poll on RESETDONE bit */
  51. omap_test_timeout((omap_hwmod_read(oh,
  52. oh->class->sysc->syss_offs)
  53. & SYSS_RESETDONE_MASK),
  54. MAX_MODULE_SOFTRESET_WAIT, c);
  55. if (c == MAX_MODULE_SOFTRESET_WAIT)
  56. pr_warn("%s: %s: softreset failed (waited %d usec)\n",
  57. __func__, oh->name, MAX_MODULE_SOFTRESET_WAIT);
  58. else
  59. pr_debug("%s: %s: softreset in %d usec\n", __func__,
  60. oh->name, c);
  61. return 0;
  62. }