hdq1w.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * IP block integration code for the HDQ1W/1-wire IP block
  3. *
  4. * Copyright (C) 2012 Texas Instruments, Inc.
  5. * Paul Walmsley
  6. *
  7. * Based on the I2C reset code in arch/arm/mach-omap2/i2c.c by
  8. * Avinash.H.M <avinashhm@ti.com>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * version 2 as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  22. * 02110-1301 USA
  23. */
  24. #include <linux/kernel.h>
  25. #include <linux/init.h>
  26. #include <linux/err.h>
  27. #include <linux/platform_device.h>
  28. #include "soc.h"
  29. #include "omap_hwmod.h"
  30. #include "omap_device.h"
  31. #include "hdq1w.h"
  32. #include "prm.h"
  33. #include "common.h"
  34. /**
  35. * omap_hdq1w_reset - reset the OMAP HDQ1W module
  36. * @oh: struct omap_hwmod *
  37. *
  38. * OCP soft reset the HDQ1W IP block. Section 20.6.1.4 "HDQ1W/1-Wire
  39. * Software Reset" of the OMAP34xx Technical Reference Manual Revision
  40. * ZR (SWPU223R) does not include the rather important fact that, for
  41. * the reset to succeed, the HDQ1W module's internal clock gate must be
  42. * programmed to allow the clock to propagate to the rest of the
  43. * module. In this sense, it's rather similar to the I2C custom reset
  44. * function. Returns 0.
  45. */
  46. int omap_hdq1w_reset(struct omap_hwmod *oh)
  47. {
  48. u32 v;
  49. int c = 0;
  50. /* Write to the SOFTRESET bit */
  51. omap_hwmod_softreset(oh);
  52. /* Enable the module's internal clocks */
  53. v = omap_hwmod_read(oh, HDQ_CTRL_STATUS_OFFSET);
  54. v |= 1 << HDQ_CTRL_STATUS_CLOCKENABLE_SHIFT;
  55. omap_hwmod_write(v, oh, HDQ_CTRL_STATUS_OFFSET);
  56. /* Poll on RESETDONE bit */
  57. omap_test_timeout((omap_hwmod_read(oh,
  58. oh->class->sysc->syss_offs)
  59. & SYSS_RESETDONE_MASK),
  60. MAX_MODULE_SOFTRESET_WAIT, c);
  61. if (c == MAX_MODULE_SOFTRESET_WAIT)
  62. pr_warn("%s: %s: softreset failed (waited %d usec)\n",
  63. __func__, oh->name, MAX_MODULE_SOFTRESET_WAIT);
  64. else
  65. pr_debug("%s: %s: softreset in %d usec\n", __func__,
  66. oh->name, c);
  67. return 0;
  68. }
  69. #ifndef CONFIG_OF
  70. static int __init omap_init_hdq(void)
  71. {
  72. int id = -1;
  73. struct platform_device *pdev;
  74. struct omap_hwmod *oh;
  75. char *oh_name = "hdq1w";
  76. char *devname = "omap_hdq";
  77. oh = omap_hwmod_lookup(oh_name);
  78. if (!oh)
  79. return 0;
  80. pdev = omap_device_build(devname, id, oh, NULL, 0);
  81. WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
  82. devname, oh->name);
  83. return 0;
  84. }
  85. omap_arch_initcall(omap_init_hdq);
  86. #endif