hdq1w.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * IP block integration code for the HDQ1W/1-wire IP block
  4. *
  5. * Copyright (C) 2012 Texas Instruments, Inc.
  6. * Paul Walmsley
  7. *
  8. * Based on the I2C reset code in arch/arm/mach-omap2/i2c.c by
  9. * Avinash.H.M <[email protected]>
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/err.h>
  14. #include <linux/platform_device.h>
  15. #include "soc.h"
  16. #include "omap_hwmod.h"
  17. #include "omap_device.h"
  18. #include "hdq1w.h"
  19. #include "prm.h"
  20. #include "common.h"
  21. /**
  22. * omap_hdq1w_reset - reset the OMAP HDQ1W module
  23. * @oh: struct omap_hwmod *
  24. *
  25. * OCP soft reset the HDQ1W IP block. Section 20.6.1.4 "HDQ1W/1-Wire
  26. * Software Reset" of the OMAP34xx Technical Reference Manual Revision
  27. * ZR (SWPU223R) does not include the rather important fact that, for
  28. * the reset to succeed, the HDQ1W module's internal clock gate must be
  29. * programmed to allow the clock to propagate to the rest of the
  30. * module. In this sense, it's rather similar to the I2C custom reset
  31. * function. Returns 0.
  32. */
  33. int omap_hdq1w_reset(struct omap_hwmod *oh)
  34. {
  35. u32 v;
  36. int c = 0;
  37. /* Write to the SOFTRESET bit */
  38. omap_hwmod_softreset(oh);
  39. /* Enable the module's internal clocks */
  40. v = omap_hwmod_read(oh, HDQ_CTRL_STATUS_OFFSET);
  41. v |= 1 << HDQ_CTRL_STATUS_CLOCKENABLE_SHIFT;
  42. omap_hwmod_write(v, oh, HDQ_CTRL_STATUS_OFFSET);
  43. /* Poll on RESETDONE bit */
  44. omap_test_timeout((omap_hwmod_read(oh,
  45. oh->class->sysc->syss_offs)
  46. & SYSS_RESETDONE_MASK),
  47. MAX_MODULE_SOFTRESET_WAIT, c);
  48. if (c == MAX_MODULE_SOFTRESET_WAIT)
  49. pr_warn("%s: %s: softreset failed (waited %d usec)\n",
  50. __func__, oh->name, MAX_MODULE_SOFTRESET_WAIT);
  51. else
  52. pr_debug("%s: %s: softreset in %d usec\n", __func__,
  53. oh->name, c);
  54. return 0;
  55. }