NonDiscoverableInitLib.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. *
  3. * Copyright (c) 2017, Linaro Ltd. All rights reserved.
  4. * Copyright (c) 2018, Marvell International Ltd. All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause-Patent
  7. *
  8. **/
  9. #include <Uefi.h>
  10. #include <Library/DebugLib.h>
  11. #include <Library/DevicePathLib.h>
  12. #include <Library/IoLib.h>
  13. #include <Library/MemoryAllocationLib.h>
  14. #include <Library/MvGpioLib.h>
  15. #include <Library/NonDiscoverableDeviceRegistrationLib.h>
  16. #include <Library/UefiBootServicesTableLib.h>
  17. #include <Protocol/NonDiscoverableDevice.h>
  18. #include "NonDiscoverableInitLib.h"
  19. STATIC CONST MV_GPIO_PIN mXhciVbusPins[] = {
  20. {
  21. ARMADA_70x0_DB_IO_EXPANDER0,
  22. ARMADA_70x0_DB_VBUS0_PIN,
  23. TRUE,
  24. },
  25. {
  26. ARMADA_70x0_DB_IO_EXPANDER0,
  27. ARMADA_70x0_DB_VBUS0_LIMIT_PIN,
  28. TRUE,
  29. },
  30. {
  31. ARMADA_70x0_DB_IO_EXPANDER0,
  32. ARMADA_70x0_DB_VBUS1_PIN,
  33. TRUE,
  34. },
  35. {
  36. ARMADA_70x0_DB_IO_EXPANDER0,
  37. ARMADA_70x0_DB_VBUS1_LIMIT_PIN,
  38. TRUE,
  39. },
  40. };
  41. STATIC
  42. EFI_STATUS
  43. EFIAPI
  44. XhciInit (
  45. IN NON_DISCOVERABLE_DEVICE *This
  46. )
  47. {
  48. CONST MV_GPIO_PIN *VbusPin;
  49. EMBEDDED_GPIO_MODE Mode;
  50. EMBEDDED_GPIO_PIN Gpio;
  51. EMBEDDED_GPIO *GpioProtocol;
  52. EFI_STATUS Status;
  53. UINTN Index;
  54. Status = MvGpioGetProtocol (MV_GPIO_DRIVER_TYPE_PCA95XX, &GpioProtocol);
  55. if (EFI_ERROR (Status)) {
  56. DEBUG ((DEBUG_ERROR, "%a: Unable to find GPIO protocol\n", __FUNCTION__));
  57. return Status;
  58. }
  59. VbusPin = mXhciVbusPins;
  60. for (Index = 0; Index < ARRAY_SIZE (mXhciVbusPins); Index++) {
  61. Mode = VbusPin->ActiveHigh ? GPIO_MODE_OUTPUT_1 : GPIO_MODE_OUTPUT_0;
  62. Gpio = GPIO (VbusPin->ControllerId, VbusPin->PinNumber);
  63. GpioProtocol->Set (GpioProtocol, Gpio, Mode);
  64. VbusPin++;
  65. }
  66. return EFI_SUCCESS;
  67. }
  68. NON_DISCOVERABLE_DEVICE_INIT
  69. EFIAPI
  70. NonDiscoverableDeviceInitializerGet (
  71. IN NON_DISCOVERABLE_DEVICE_TYPE Type,
  72. IN UINTN Index
  73. )
  74. {
  75. if (Type == NonDiscoverableDeviceTypeXhci) {
  76. return XhciInit;
  77. }
  78. return NULL;
  79. }