1 /** @file 2 3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR> 4 5 This program and the accompanying materials are licensed and made available under 7 the terms and conditions of the BSD License that accompanies this distribution. 9 The full text of the license may be found at 11 http://opensource.org/licenses/bsd-license.php. 13 15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 17 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 19 21 23 Module Name: 24 25 LegacySpeaker.c 26 27 Abstract: 28 29 This file implements DXE for Legacy Speaker. 30 31 --*/ 32 33 #include "LegacySpeaker.h" 34 35 /** 36 37 This function will enable the speaker to generate beep 38 39 @retval EFI_STATUS 40 41 **/ 42 EFI_STATUS 43 TurnOnSpeaker ( 44 ) 45 { 46 UINT8 Data; 47 Data = IoRead8 (EFI_SPEAKER_CONTROL_PORT); 48 Data |= 0x03; 49 IoWrite8(EFI_SPEAKER_CONTROL_PORT, Data); 50 return EFI_SUCCESS; 51 } 52 53 /** 54 55 This function will stop beep from speaker. 56 57 @retval Status 58 59 **/ 60 EFI_STATUS 61 TurnOffSpeaker ( 62 ) 63 { 64 UINT8 Data; 65 66 Data = IoRead8 (EFI_SPEAKER_CONTROL_PORT); 67 Data &= 0xFC; 68 IoWrite8(EFI_SPEAKER_CONTROL_PORT, Data); 69 return EFI_SUCCESS; 70 } 71 72 /** 73 Generate beep sound based upon number of beeps and duration of the beep 74 75 @param NumberOfBeeps Number of beeps which user want to produce 76 @param BeepDuration Duration for speaker gate need to be enabled 77 @param TimeInterval Interval between each beep 78 79 @retval Does not return if the reset takes place. 80 EFI_INVALID_PARAMETER If ResetType is invalid. 81 82 **/ 83 EFI_STATUS 84 OutputBeep ( 85 IN UINTN NumberOfBeep, 86 IN UINTN BeepDuration, 87 IN UINTN TimeInterval 88 ) 89 { 90 UINTN Num; 91 92 for (Num=0; Num < NumberOfBeep; Num++) { 93 TurnOnSpeaker (); 94 // 95 // wait some time,at least 120us 96 // 97 gBS->Stall (BeepDuration); 98 TurnOffSpeaker(); 99 gBS->Stall (TimeInterval); 100 } 101 102 return EFI_SUCCESS; 103 } 104 105 /** 106 This function will program the speaker tone frequency. The value should be with 64k 107 boundary since it takes only 16 bit value which gets programmed in two step IO opearattion 108 109 @param Frequency A value which should be 16 bit only. 110 111 @retval EFI_SUCESS 112 113 **/ 114 EFI_STATUS 115 EFIAPI 116 ProgramToneFrequency ( 117 IN EFI_SPEAKER_IF_PROTOCOL * This, 118 IN UINT16 Frequency 119 ) 120 { 121 UINT8 Data; 122 123 Data = 0xB6; 124 IoWrite8(EFI_TIMER_CONTROL_PORT, Data); 125 126 Data = (UINT8)(Frequency & 0x00FF); 127 IoWrite8(EFI_TIMER_2_PORT, Data); 128 Data = (UINT8)((Frequency & 0xFF00) >> 8); 129 IoWrite8(EFI_TIMER_2_PORT, Data); 130 return EFI_SUCCESS; 131 } 132 133 /** 134 This function will generate the beep for specified duration. 135 136 @param NumberOfBeeps Number of beeps which user want to produce 137 @param BeepDuration Duration for speaker gate need to be enabled 138 @param TimeInterval Interval between each beep 139 140 @retval EFI_STATUS 141 142 **/ 143 EFI_STATUS 144 EFIAPI 145 GenerateBeepTone ( 146 IN EFI_SPEAKER_IF_PROTOCOL * This, 147 IN UINTN NumberOfBeeps, 148 IN UINTN BeepDuration, 149 IN UINTN TimeInterval 150 ) 151 { 152 153 if ((NumberOfBeeps == 1) && (BeepDuration == 0) && (TimeInterval == 0)) { 154 TurnOnSpeaker (); 155 return EFI_SUCCESS; 156 } 157 158 if ((NumberOfBeeps == 0) && (BeepDuration == 0) && (TimeInterval == 0)) { 159 TurnOffSpeaker (); 160 return EFI_SUCCESS; 161 } 162 163 if (BeepDuration == 0) { 164 BeepDuration = EFI_DEFAULT_SHORT_BEEP_DURATION; 165 } 166 167 if (TimeInterval == 0) { 168 TimeInterval = EFI_DEFAULT_BEEP_TIME_INTERVAL; 169 } 170 171 OutputBeep (NumberOfBeeps, BeepDuration, TimeInterval); 172 return EFI_SUCCESS; 173 174 175 } 176