LegacySpeaker.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 DXE for Legacy Speaker.
  8. --*/
  9. #include "LegacySpeaker.h"
  10. /**
  11. This function will enable the speaker to generate beep
  12. @retval EFI_STATUS
  13. **/
  14. EFI_STATUS
  15. TurnOnSpeaker (
  16. )
  17. {
  18. UINT8 Data;
  19. Data = IoRead8 (EFI_SPEAKER_CONTROL_PORT);
  20. Data |= 0x03;
  21. IoWrite8(EFI_SPEAKER_CONTROL_PORT, Data);
  22. return EFI_SUCCESS;
  23. }
  24. /**
  25. This function will stop beep from speaker.
  26. @retval Status
  27. **/
  28. EFI_STATUS
  29. TurnOffSpeaker (
  30. )
  31. {
  32. UINT8 Data;
  33. Data = IoRead8 (EFI_SPEAKER_CONTROL_PORT);
  34. Data &= 0xFC;
  35. IoWrite8(EFI_SPEAKER_CONTROL_PORT, Data);
  36. return EFI_SUCCESS;
  37. }
  38. /**
  39. Generate beep sound based upon number of beeps and duration of the beep
  40. @param NumberOfBeeps Number of beeps which user want to produce
  41. @param BeepDuration Duration for speaker gate need to be enabled
  42. @param TimeInterval Interval between each beep
  43. @retval Does not return if the reset takes place.
  44. EFI_INVALID_PARAMETER If ResetType is invalid.
  45. **/
  46. EFI_STATUS
  47. OutputBeep (
  48. IN UINTN NumberOfBeep,
  49. IN UINTN BeepDuration,
  50. IN UINTN TimeInterval
  51. )
  52. {
  53. UINTN Num;
  54. for (Num=0; Num < NumberOfBeep; Num++) {
  55. TurnOnSpeaker ();
  56. //
  57. // wait some time,at least 120us
  58. //
  59. gBS->Stall (BeepDuration);
  60. TurnOffSpeaker();
  61. gBS->Stall (TimeInterval);
  62. }
  63. return EFI_SUCCESS;
  64. }
  65. /**
  66. This function will program the speaker tone frequency. The value should be with 64k
  67. boundary since it takes only 16 bit value which gets programmed in two step IO opearattion
  68. @param Frequency A value which should be 16 bit only.
  69. @retval EFI_SUCESS
  70. **/
  71. EFI_STATUS
  72. EFIAPI
  73. ProgramToneFrequency (
  74. IN EFI_SPEAKER_IF_PROTOCOL * This,
  75. IN UINT16 Frequency
  76. )
  77. {
  78. UINT8 Data;
  79. Data = 0xB6;
  80. IoWrite8(EFI_TIMER_CONTROL_PORT, Data);
  81. Data = (UINT8)(Frequency & 0x00FF);
  82. IoWrite8(EFI_TIMER_2_PORT, Data);
  83. Data = (UINT8)((Frequency & 0xFF00) >> 8);
  84. IoWrite8(EFI_TIMER_2_PORT, Data);
  85. return EFI_SUCCESS;
  86. }
  87. /**
  88. This function will generate the beep for specified duration.
  89. @param NumberOfBeeps Number of beeps which user want to produce
  90. @param BeepDuration Duration for speaker gate need to be enabled
  91. @param TimeInterval Interval between each beep
  92. @retval EFI_STATUS
  93. **/
  94. EFI_STATUS
  95. EFIAPI
  96. GenerateBeepTone (
  97. IN EFI_SPEAKER_IF_PROTOCOL * This,
  98. IN UINTN NumberOfBeeps,
  99. IN UINTN BeepDuration,
  100. IN UINTN TimeInterval
  101. )
  102. {
  103. if ((NumberOfBeeps == 1) && (BeepDuration == 0) && (TimeInterval == 0)) {
  104. TurnOnSpeaker ();
  105. return EFI_SUCCESS;
  106. }
  107. if ((NumberOfBeeps == 0) && (BeepDuration == 0) && (TimeInterval == 0)) {
  108. TurnOffSpeaker ();
  109. return EFI_SUCCESS;
  110. }
  111. if (BeepDuration == 0) {
  112. BeepDuration = EFI_DEFAULT_SHORT_BEEP_DURATION;
  113. }
  114. if (TimeInterval == 0) {
  115. TimeInterval = EFI_DEFAULT_BEEP_TIME_INTERVAL;
  116. }
  117. OutputBeep (NumberOfBeeps, BeepDuration, TimeInterval);
  118. return EFI_SUCCESS;
  119. }