omap-ulpi-viewport.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * OMAP ulpi viewport support
  3. * Based on drivers/usb/ulpi/ulpi-viewport.c
  4. *
  5. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com
  6. * Author: Govindraj R <govindraj.raja@ti.com>
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 of
  10. * the License as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <common.h>
  21. #include <asm/io.h>
  22. #include <usb/ulpi.h>
  23. #define OMAP_ULPI_WR_OPSEL (3 << 21)
  24. #define OMAP_ULPI_ACCESS (1 << 31)
  25. /*
  26. * Wait for the ULPI Access to complete
  27. */
  28. static int ulpi_wait(struct ulpi_viewport *ulpi_vp, u32 mask)
  29. {
  30. int timeout = CONFIG_USB_ULPI_TIMEOUT;
  31. while (--timeout) {
  32. if ((readl(ulpi_vp->viewport_addr) & mask))
  33. return 0;
  34. udelay(1);
  35. }
  36. return ULPI_ERROR;
  37. }
  38. /*
  39. * Wake the ULPI PHY up for communication
  40. *
  41. * returns 0 on success.
  42. */
  43. static int ulpi_wakeup(struct ulpi_viewport *ulpi_vp)
  44. {
  45. int err;
  46. if (readl(ulpi_vp->viewport_addr) & OMAP_ULPI_ACCESS)
  47. return 0; /* already awake */
  48. writel(OMAP_ULPI_ACCESS, ulpi_vp->viewport_addr);
  49. err = ulpi_wait(ulpi_vp, OMAP_ULPI_ACCESS);
  50. if (err)
  51. debug("ULPI wakeup timed out\n");
  52. return err;
  53. }
  54. /*
  55. * Issue a ULPI read/write request
  56. */
  57. static int ulpi_request(struct ulpi_viewport *ulpi_vp, u32 value)
  58. {
  59. int err;
  60. err = ulpi_wakeup(ulpi_vp);
  61. if (err)
  62. return err;
  63. writel(value, ulpi_vp->viewport_addr);
  64. err = ulpi_wait(ulpi_vp, OMAP_ULPI_ACCESS);
  65. if (err)
  66. debug("ULPI request timed out\n");
  67. return err;
  68. }
  69. int ulpi_write(struct ulpi_viewport *ulpi_vp, u8 *reg, u32 value)
  70. {
  71. u32 val = ((ulpi_vp->port_num & 0xf) << 24) |
  72. OMAP_ULPI_WR_OPSEL | ((u32)reg << 16) | (value & 0xff);
  73. return ulpi_request(ulpi_vp, val);
  74. }
  75. u32 ulpi_read(struct ulpi_viewport *ulpi_vp, u8 *reg)
  76. {
  77. int err;
  78. u32 val = ((ulpi_vp->port_num & 0xf) << 24) |
  79. OMAP_ULPI_WR_OPSEL | ((u32)reg << 16);
  80. err = ulpi_request(ulpi_vp, val);
  81. if (err)
  82. return err;
  83. return readl(ulpi_vp->viewport_addr) & 0xff;
  84. }