]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/PlatformInitPei/LegacySpeaker.c
Upload BSD-licensed Vlv2TbltDevicePkg and Vlv2DeviceRefCodePkg to
[mirror_edk2.git] / Vlv2TbltDevicePkg / PlatformInitPei / 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
17 LegacySpeaker.c
18
19 Abstract:
20
21 This file implements PEIM for Legacy Speaker. This file is valid for platforms both
22 on IA32 and Itanium Product Family
23
24 --*/
25
26 #include "PlatformEarlyInit.h"
27
28 EFI_STATUS
29 OutputBeep (
30 IN CONST EFI_PEI_SERVICES **PeiServices,
31 IN UINTN NumberOfBeep,
32 IN UINTN BeepDuration,
33 IN UINTN TimerInterval
34 );
35
36 /**
37 This function will enable the speaker to generate beep
38
39 @param PeiServices PeiServices to locate PPI
40
41 @retval EFI_STATUS
42
43 **/
44 EFI_STATUS
45 TurnOnSpeaker (
46 IN CONST EFI_PEI_SERVICES **PeiServices
47 )
48 {
49 UINT8 Data;
50 Data = IoRead8 (EFI_SPEAKER_CONTROL_PORT);
51 Data |= 0x03;
52 IoWrite8(EFI_SPEAKER_CONTROL_PORT, Data);
53 return EFI_SUCCESS;
54 }
55
56 /**
57 This function will stop beep from speaker.
58
59 @param PeiServices PeiServices to locate PPI
60
61 @retval Status
62
63 **/
64 EFI_STATUS
65 TurnOffSpeaker (
66 IN CONST EFI_PEI_SERVICES **PeiServices
67 )
68 {
69 UINT8 Data;
70
71 Data = IoRead8 (EFI_SPEAKER_CONTROL_PORT);
72 Data &= 0xFC;
73 IoWrite8(EFI_SPEAKER_CONTROL_PORT, Data);
74 return EFI_SUCCESS;
75 }
76
77
78 EFI_STATUS
79 OutputBeep (
80 IN CONST EFI_PEI_SERVICES **PeiServices,
81 IN UINTN NumberOfBeep,
82 IN UINTN BeepDuration,
83 IN UINTN TimeInterval
84 )
85 {
86 UINTN Num;
87 EFI_PEI_STALL_PPI* StallPpi;
88
89 (**PeiServices).LocatePpi (PeiServices, &gEfiPeiStallPpiGuid, 0, NULL, (void **)&StallPpi);
90
91 for (Num=0; Num < NumberOfBeep; Num++) {
92 TurnOnSpeaker (PeiServices);
93 StallPpi->Stall(PeiServices, StallPpi, BeepDuration);
94 TurnOffSpeaker(PeiServices);
95 StallPpi->Stall(PeiServices, StallPpi, TimeInterval);
96 }
97
98 return EFI_SUCCESS;
99 }
100
101 /**
102 This function will program the speaker tone frequency. The value should be with 64k
103 boundary since it takes only 16 bit value which gets programmed in two step IO opearattion
104
105 Frequency - A value which should be 16 bit only.
106
107 EFI_SUCESS
108
109 **/
110 EFI_STATUS
111 EFIAPI
112 ProgramToneFrequency (
113 IN CONST EFI_PEI_SERVICES **PeiServices,
114 IN UINT16 Frequency
115 )
116 {
117 UINT8 Data;
118
119 Data = 0xB6;
120 IoWrite8(EFI_TIMER_CONTROL_PORT, Data);
121
122 Data = (UINT8)(Frequency & 0x00FF);
123 IoWrite8(EFI_TIMER_2_PORT, Data);
124 Data = (UINT8)((Frequency & 0xFF00) >> 8);
125 IoWrite8(EFI_TIMER_2_PORT, Data);
126 return EFI_SUCCESS;
127 }
128
129 /**
130 This function will generate the beep for specified duration.
131
132 @param PeiServices PeiServices to locate various PPIs
133 @param NumberOfBeeps Number of beeps which user want to produce
134 @param BeepDuration Duration for speaker gate need to be enabled
135 @param TimeInterval Interval between each beep
136
137 @retval EFI_STATUS
138
139 **/
140 EFI_STATUS
141 EFIAPI
142 GenerateBeepTone (
143 IN CONST EFI_PEI_SERVICES **PeiServices,
144 IN UINTN NumberOfBeeps,
145 IN UINTN BeepDuration,
146 IN UINTN TimeInterval
147 )
148 {
149
150 if ((NumberOfBeeps == 1) && (BeepDuration == 0) && (TimeInterval == 0)) {
151 TurnOnSpeaker (PeiServices);
152 return EFI_SUCCESS;
153 }
154
155 if ((NumberOfBeeps == 0) && (BeepDuration == 0) && (TimeInterval == 0)) {
156 TurnOffSpeaker (PeiServices);
157 return EFI_SUCCESS;
158 }
159
160 if (BeepDuration == 0) {
161 BeepDuration = EFI_DEFAULT_SHORT_BEEP_DURATION;
162 }
163
164 if (TimeInterval == 0) {
165 TimeInterval = EFI_DEFAULT_BEEP_TIME_INTERVAL;
166 }
167
168 OutputBeep (PeiServices, NumberOfBeeps, BeepDuration, TimeInterval);
169 return EFI_SUCCESS;
170
171
172 }
173