omap-ulpi-viewport.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 (2 << 22)
  24. #define OMAP_ULPI_RD_OPSEL (3 << 22)
  25. #define OMAP_ULPI_START (1 << 31)
  26. /*
  27. * Wait for having ulpi in done state
  28. */
  29. static int ulpi_wait(struct ulpi_viewport *ulpi_vp, u32 mask)
  30. {
  31. int timeout = CONFIG_USB_ULPI_TIMEOUT;
  32. while (--timeout) {
  33. if (!(readl(ulpi_vp->viewport_addr) & mask))
  34. return 0;
  35. udelay(1);
  36. }
  37. return ULPI_ERROR;
  38. }
  39. /*
  40. * Issue a ULPI read/write request
  41. */
  42. static int ulpi_request(struct ulpi_viewport *ulpi_vp, u32 value)
  43. {
  44. int err;
  45. writel(value, ulpi_vp->viewport_addr);
  46. err = ulpi_wait(ulpi_vp, OMAP_ULPI_START);
  47. if (err)
  48. debug("ULPI request timed out\n");
  49. return err;
  50. }
  51. int ulpi_write(struct ulpi_viewport *ulpi_vp, u8 *reg, u32 value)
  52. {
  53. u32 val = OMAP_ULPI_START | (((ulpi_vp->port_num + 1) & 0xf) << 24) |
  54. OMAP_ULPI_WR_OPSEL | ((u32)reg << 16) | (value & 0xff);
  55. return ulpi_request(ulpi_vp, val);
  56. }
  57. u32 ulpi_read(struct ulpi_viewport *ulpi_vp, u8 *reg)
  58. {
  59. int err;
  60. u32 val = OMAP_ULPI_START | (((ulpi_vp->port_num + 1) & 0xf) << 24) |
  61. OMAP_ULPI_RD_OPSEL | ((u32)reg << 16);
  62. err = ulpi_request(ulpi_vp, val);
  63. if (err)
  64. return err;
  65. return readl(ulpi_vp->viewport_addr) & 0xff;
  66. }