]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/PlatformDxe/LegacySpeaker.c
09e7fe31132851a326607649d15c90a80723db14
[mirror_edk2.git] / Vlv2TbltDevicePkg / PlatformDxe / LegacySpeaker.c
1 /** @file
2
3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
4
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7
8
9 Module Name:
10
11 LegacySpeaker.c
12
13 Abstract:
14
15 This file implements DXE for Legacy Speaker.
16
17 --*/
18
19 #include "LegacySpeaker.h"
20
21 /**
22
23 This function will enable the speaker to generate beep
24
25 @retval EFI_STATUS
26
27 **/
28 EFI_STATUS
29 TurnOnSpeaker (
30 )
31 {
32 UINT8 Data;
33 Data = IoRead8 (EFI_SPEAKER_CONTROL_PORT);
34 Data |= 0x03;
35 IoWrite8(EFI_SPEAKER_CONTROL_PORT, Data);
36 return EFI_SUCCESS;
37 }
38
39 /**
40
41 This function will stop beep from speaker.
42
43 @retval Status
44
45 **/
46 EFI_STATUS
47 TurnOffSpeaker (
48 )
49 {
50 UINT8 Data;
51
52 Data = IoRead8 (EFI_SPEAKER_CONTROL_PORT);
53 Data &= 0xFC;
54 IoWrite8(EFI_SPEAKER_CONTROL_PORT, Data);
55 return EFI_SUCCESS;
56 }
57
58 /**
59 Generate beep sound based upon number of beeps and duration of the beep
60
61 @param NumberOfBeeps Number of beeps which user want to produce
62 @param BeepDuration Duration for speaker gate need to be enabled
63 @param TimeInterval Interval between each beep
64
65 @retval Does not return if the reset takes place.
66 EFI_INVALID_PARAMETER If ResetType is invalid.
67
68 **/
69 EFI_STATUS
70 OutputBeep (
71 IN UINTN NumberOfBeep,
72 IN UINTN BeepDuration,
73 IN UINTN TimeInterval
74 )
75 {
76 UINTN Num;
77
78 for (Num=0; Num < NumberOfBeep; Num++) {
79 TurnOnSpeaker ();
80 //
81 // wait some time,at least 120us
82 //
83 gBS->Stall (BeepDuration);
84 TurnOffSpeaker();
85 gBS->Stall (TimeInterval);
86 }
87
88 return EFI_SUCCESS;
89 }
90
91 /**
92 This function will program the speaker tone frequency. The value should be with 64k
93 boundary since it takes only 16 bit value which gets programmed in two step IO opearattion
94
95 @param Frequency A value which should be 16 bit only.
96
97 @retval EFI_SUCESS
98
99 **/
100 EFI_STATUS
101 EFIAPI
102 ProgramToneFrequency (
103 IN EFI_SPEAKER_IF_PROTOCOL * This,
104 IN UINT16 Frequency
105 )
106 {
107 UINT8 Data;
108
109 Data = 0xB6;
110 IoWrite8(EFI_TIMER_CONTROL_PORT, Data);
111
112 Data = (UINT8)(Frequency & 0x00FF);
113 IoWrite8(EFI_TIMER_2_PORT, Data);
114 Data = (UINT8)((Frequency & 0xFF00) >> 8);
115 IoWrite8(EFI_TIMER_2_PORT, Data);
116 return EFI_SUCCESS;
117 }
118
119 /**
120 This function will generate the beep for specified duration.
121
122 @param NumberOfBeeps Number of beeps which user want to produce
123 @param BeepDuration Duration for speaker gate need to be enabled
124 @param TimeInterval Interval between each beep
125
126 @retval EFI_STATUS
127
128 **/
129 EFI_STATUS
130 EFIAPI
131 GenerateBeepTone (
132 IN EFI_SPEAKER_IF_PROTOCOL * This,
133 IN UINTN NumberOfBeeps,
134 IN UINTN BeepDuration,
135 IN UINTN TimeInterval
136 )
137 {
138
139 if ((NumberOfBeeps == 1) && (BeepDuration == 0) && (TimeInterval == 0)) {
140 TurnOnSpeaker ();
141 return EFI_SUCCESS;
142 }
143
144 if ((NumberOfBeeps == 0) && (BeepDuration == 0) && (TimeInterval == 0)) {
145 TurnOffSpeaker ();
146 return EFI_SUCCESS;
147 }
148
149 if (BeepDuration == 0) {
150 BeepDuration = EFI_DEFAULT_SHORT_BEEP_DURATION;
151 }
152
153 if (TimeInterval == 0) {
154 TimeInterval = EFI_DEFAULT_BEEP_TIME_INTERVAL;
155 }
156
157 OutputBeep (NumberOfBeeps, BeepDuration, TimeInterval);
158 return EFI_SUCCESS;
159
160
161 }