2
0

ulpi-viewport.c 2.6 KB

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