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