LegacySpeaker.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /** @file
  2. Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. Module Name:
  5. LegacySpeaker.c
  6. Abstract:
  7. This file implements PEIM for Legacy Speaker. This file is valid for platforms both
  8. on IA32 and Itanium Product Family
  9. --*/
  10. #include "PlatformEarlyInit.h"
  11. EFI_STATUS
  12. OutputBeep (
  13. IN CONST EFI_PEI_SERVICES **PeiServices,
  14. IN UINTN NumberOfBeep,
  15. IN UINTN BeepDuration,
  16. IN UINTN TimerInterval
  17. );
  18. /**
  19. This function will enable the speaker to generate beep
  20. @param PeiServices PeiServices to locate PPI
  21. @retval EFI_STATUS
  22. **/
  23. EFI_STATUS
  24. TurnOnSpeaker (
  25. IN CONST EFI_PEI_SERVICES **PeiServices
  26. )
  27. {
  28. UINT8 Data;
  29. Data = IoRead8 (EFI_SPEAKER_CONTROL_PORT);
  30. Data |= 0x03;
  31. IoWrite8(EFI_SPEAKER_CONTROL_PORT, Data);
  32. return EFI_SUCCESS;
  33. }
  34. /**
  35. This function will stop beep from speaker.
  36. @param PeiServices PeiServices to locate PPI
  37. @retval Status
  38. **/
  39. EFI_STATUS
  40. TurnOffSpeaker (
  41. IN CONST EFI_PEI_SERVICES **PeiServices
  42. )
  43. {
  44. UINT8 Data;
  45. Data = IoRead8 (EFI_SPEAKER_CONTROL_PORT);
  46. Data &= 0xFC;
  47. IoWrite8(EFI_SPEAKER_CONTROL_PORT, Data);
  48. return EFI_SUCCESS;
  49. }
  50. EFI_STATUS
  51. OutputBeep (
  52. IN CONST EFI_PEI_SERVICES **PeiServices,
  53. IN UINTN NumberOfBeep,
  54. IN UINTN BeepDuration,
  55. IN UINTN TimeInterval
  56. )
  57. {
  58. UINTN Num;
  59. EFI_PEI_STALL_PPI* StallPpi;
  60. (**PeiServices).LocatePpi (PeiServices, &gEfiPeiStallPpiGuid, 0, NULL, (void **)&StallPpi);
  61. for (Num=0; Num < NumberOfBeep; Num++) {
  62. TurnOnSpeaker (PeiServices);
  63. StallPpi->Stall(PeiServices, StallPpi, BeepDuration);
  64. TurnOffSpeaker(PeiServices);
  65. StallPpi->Stall(PeiServices, StallPpi, TimeInterval);
  66. }
  67. return EFI_SUCCESS;
  68. }
  69. /**
  70. This function will program the speaker tone frequency. The value should be with 64k
  71. boundary since it takes only 16 bit value which gets programmed in two step IO opearattion
  72. Frequency - A value which should be 16 bit only.
  73. EFI_SUCESS
  74. **/
  75. EFI_STATUS
  76. EFIAPI
  77. ProgramToneFrequency (
  78. IN CONST EFI_PEI_SERVICES **PeiServices,
  79. IN UINT16 Frequency
  80. )
  81. {
  82. UINT8 Data;
  83. Data = 0xB6;
  84. IoWrite8(EFI_TIMER_CONTROL_PORT, Data);
  85. Data = (UINT8)(Frequency & 0x00FF);
  86. IoWrite8(EFI_TIMER_2_PORT, Data);
  87. Data = (UINT8)((Frequency & 0xFF00) >> 8);
  88. IoWrite8(EFI_TIMER_2_PORT, Data);
  89. return EFI_SUCCESS;
  90. }
  91. /**
  92. This function will generate the beep for specified duration.
  93. @param PeiServices PeiServices to locate various PPIs
  94. @param NumberOfBeeps Number of beeps which user want to produce
  95. @param BeepDuration Duration for speaker gate need to be enabled
  96. @param TimeInterval Interval between each beep
  97. @retval EFI_STATUS
  98. **/
  99. EFI_STATUS
  100. EFIAPI
  101. GenerateBeepTone (
  102. IN CONST EFI_PEI_SERVICES **PeiServices,
  103. IN UINTN NumberOfBeeps,
  104. IN UINTN BeepDuration,
  105. IN UINTN TimeInterval
  106. )
  107. {
  108. if ((NumberOfBeeps == 1) && (BeepDuration == 0) && (TimeInterval == 0)) {
  109. TurnOnSpeaker (PeiServices);
  110. return EFI_SUCCESS;
  111. }
  112. if ((NumberOfBeeps == 0) && (BeepDuration == 0) && (TimeInterval == 0)) {
  113. TurnOffSpeaker (PeiServices);
  114. return EFI_SUCCESS;
  115. }
  116. if (BeepDuration == 0) {
  117. BeepDuration = EFI_DEFAULT_SHORT_BEEP_DURATION;
  118. }
  119. if (TimeInterval == 0) {
  120. TimeInterval = EFI_DEFAULT_BEEP_TIME_INTERVAL;
  121. }
  122. OutputBeep (PeiServices, NumberOfBeeps, BeepDuration, TimeInterval);
  123. return EFI_SUCCESS;
  124. }