omap-ulpi-viewport.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * OMAP ulpi viewport support
  4. * Based on drivers/usb/ulpi/ulpi-viewport.c
  5. *
  6. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com
  7. * Author: Govindraj R <govindraj.raja@ti.com>
  8. */
  9. #include <common.h>
  10. #include <log.h>
  11. #include <asm/io.h>
  12. #include <linux/delay.h>
  13. #include <usb/ulpi.h>
  14. #define OMAP_ULPI_WR_OPSEL (2 << 22)
  15. #define OMAP_ULPI_RD_OPSEL (3 << 22)
  16. #define OMAP_ULPI_START (1 << 31)
  17. /*
  18. * Wait for having ulpi in done state
  19. */
  20. static int ulpi_wait(struct ulpi_viewport *ulpi_vp, u32 mask)
  21. {
  22. int timeout = CONFIG_USB_ULPI_TIMEOUT;
  23. while (--timeout) {
  24. if (!(readl(ulpi_vp->viewport_addr) & mask))
  25. return 0;
  26. udelay(1);
  27. }
  28. return ULPI_ERROR;
  29. }
  30. /*
  31. * Issue a ULPI read/write request
  32. */
  33. static int ulpi_request(struct ulpi_viewport *ulpi_vp, u32 value)
  34. {
  35. int err;
  36. writel(value, ulpi_vp->viewport_addr);
  37. err = ulpi_wait(ulpi_vp, OMAP_ULPI_START);
  38. if (err)
  39. debug("ULPI request timed out\n");
  40. return err;
  41. }
  42. int ulpi_write(struct ulpi_viewport *ulpi_vp, u8 *reg, u32 value)
  43. {
  44. u32 val = OMAP_ULPI_START | (((ulpi_vp->port_num + 1) & 0xf) << 24) |
  45. OMAP_ULPI_WR_OPSEL | ((u32)reg << 16) | (value & 0xff);
  46. return ulpi_request(ulpi_vp, val);
  47. }
  48. u32 ulpi_read(struct ulpi_viewport *ulpi_vp, u8 *reg)
  49. {
  50. int err;
  51. u32 val = OMAP_ULPI_START | (((ulpi_vp->port_num + 1) & 0xf) << 24) |
  52. OMAP_ULPI_RD_OPSEL | ((u32)reg << 16);
  53. err = ulpi_request(ulpi_vp, val);
  54. if (err)
  55. return err;
  56. return readl(ulpi_vp->viewport_addr) & 0xff;
  57. }