Firmware for MNT ZZ9000 graphics and ARM coprocessor card for Amiga computers.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ulpi-viewport.c 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2011 Jana Rapava <fermata7@gmail.com>
  4. * Copyright (C) 2011 CompuLab, Ltd. <www.compulab.co.il>
  5. *
  6. * Authors: Jana Rapava <fermata7@gmail.com>
  7. * Igor Grinberg <grinberg@compulab.co.il>
  8. *
  9. * Based on:
  10. * linux/drivers/usb/otg/ulpi_viewport.c
  11. *
  12. * Original Copyright follow:
  13. * Copyright (C) 2011 Google, Inc.
  14. */
  15. #include <xil_types.h>
  16. #include "io.h"
  17. #include "ulpi.h"
  18. #include <stdio.h>
  19. #include <xenv_standalone.h>
  20. /* ULPI viewport control bits */
  21. #define ULPI_SS (1 << 27)
  22. #define ULPI_RWCTRL (1 << 29)
  23. #define ULPI_RWRUN (1 << 30)
  24. #define ULPI_WU (1 << 31)
  25. /*
  26. * Wait for the ULPI request to complete
  27. *
  28. * @ulpi_viewport - the address of the viewport
  29. * @mask - expected value to wait for
  30. *
  31. * returns 0 on mask match, ULPI_ERROR on time out.
  32. */
  33. static int ulpi_wait(struct ulpi_viewport *ulpi_vp, u32 mask)
  34. {
  35. int timeout = CONFIG_USB_ULPI_TIMEOUT;
  36. /* Wait for the bits in mask to become zero. */
  37. while (--timeout) {
  38. if ((readl(ulpi_vp->viewport_addr) & mask) == 0)
  39. return 0;
  40. udelay(1);
  41. }
  42. return ULPI_ERROR;
  43. }
  44. /*
  45. * Wake the ULPI PHY up for communication
  46. *
  47. * returns 0 on success.
  48. */
  49. static int ulpi_wakeup(struct ulpi_viewport *ulpi_vp)
  50. {
  51. int err;
  52. if (readl(ulpi_vp->viewport_addr) & ULPI_SS)
  53. return 0; /* already awake */
  54. writel(ULPI_WU, ulpi_vp->viewport_addr);
  55. err = ulpi_wait(ulpi_vp, ULPI_WU);
  56. if (err)
  57. printf("ULPI wakeup timed out\n");
  58. return err;
  59. }
  60. /*
  61. * Issue a ULPI read/write request
  62. *
  63. * @value - the ULPI request
  64. */
  65. static int ulpi_request(struct ulpi_viewport *ulpi_vp, u32 value)
  66. {
  67. int err;
  68. err = ulpi_wakeup(ulpi_vp);
  69. if (err)
  70. return err;
  71. writel(value, ulpi_vp->viewport_addr);
  72. err = ulpi_wait(ulpi_vp, ULPI_RWRUN);
  73. if (err)
  74. printf("ULPI request timed out\n");
  75. return err;
  76. }
  77. int ulpi_write(struct ulpi_viewport *ulpi_vp, u8 *reg, u32 value)
  78. {
  79. u32 addr = (uintptr_t)reg & 0xFF;
  80. u32 val = ULPI_RWRUN | ULPI_RWCTRL | addr << 16 | (value & 0xff);
  81. val |= (ulpi_vp->port_num & 0x7) << 24;
  82. return ulpi_request(ulpi_vp, val);
  83. }
  84. u32 ulpi_read(struct ulpi_viewport *ulpi_vp, u8 *reg)
  85. {
  86. int err;
  87. u32 val = ULPI_RWRUN | ((uintptr_t)reg & 0xFF) << 16;
  88. val |= (ulpi_vp->port_num & 0x7) << 24;
  89. err = ulpi_request(ulpi_vp, val);
  90. if (err)
  91. return err;
  92. return (readl(ulpi_vp->viewport_addr) >> 8) & 0xff;
  93. }