]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/PlatformInitPei/LegacySpeaker.c
MdeModulePkg: Change the SMM debug lib instance
[mirror_edk2.git] / Vlv2TbltDevicePkg / PlatformInitPei / 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
12 LegacySpeaker.c
13
14 Abstract:
15
16 This file implements PEIM for Legacy Speaker. This file is valid for platforms both
17 on IA32 and Itanium Product Family
18
19 --*/
20
21 #include "PlatformEarlyInit.h"
22
23 EFI_STATUS
24 OutputBeep (
25 IN CONST EFI_PEI_SERVICES **PeiServices,
26 IN UINTN NumberOfBeep,
27 IN UINTN BeepDuration,
28 IN UINTN TimerInterval
29 );
30
31 /**
32 This function will enable the speaker to generate beep
33
34 @param PeiServices PeiServices to locate PPI
35
36 @retval EFI_STATUS
37
38 **/
39 EFI_STATUS
40 TurnOnSpeaker (
41 IN CONST EFI_PEI_SERVICES **PeiServices
42 )
43 {
44 UINT8 Data;
45 Data = IoRead8 (EFI_SPEAKER_CONTROL_PORT);
46 Data |= 0x03;
47 IoWrite8(EFI_SPEAKER_CONTROL_PORT, Data);
48 return EFI_SUCCESS;
49 }
50
51 /**
52 This function will stop beep from speaker.
53
54 @param PeiServices PeiServices to locate PPI
55
56 @retval Status
57
58 **/
59 EFI_STATUS
60 TurnOffSpeaker (
61 IN CONST EFI_PEI_SERVICES **PeiServices
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 EFI_STATUS
74 OutputBeep (
75 IN CONST EFI_PEI_SERVICES **PeiServices,
76 IN UINTN NumberOfBeep,
77 IN UINTN BeepDuration,
78 IN UINTN TimeInterval
79 )
80 {
81 UINTN Num;
82 EFI_PEI_STALL_PPI* StallPpi;
83
84 (**PeiServices).LocatePpi (PeiServices, &gEfiPeiStallPpiGuid, 0, NULL, (void **)&StallPpi);
85
86 for (Num=0; Num < NumberOfBeep; Num++) {
87 TurnOnSpeaker (PeiServices);
88 StallPpi->Stall(PeiServices, StallPpi, BeepDuration);
89 TurnOffSpeaker(PeiServices);
90 StallPpi->Stall(PeiServices, StallPpi, 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 Frequency - A value which should be 16 bit only.
101
102 EFI_SUCESS
103
104 **/
105 EFI_STATUS
106 EFIAPI
107 ProgramToneFrequency (
108 IN CONST EFI_PEI_SERVICES **PeiServices,
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 PeiServices PeiServices to locate various PPIs
128 @param NumberOfBeeps Number of beeps which user want to produce
129 @param BeepDuration Duration for speaker gate need to be enabled
130 @param TimeInterval Interval between each beep
131
132 @retval EFI_STATUS
133
134 **/
135 EFI_STATUS
136 EFIAPI
137 GenerateBeepTone (
138 IN CONST EFI_PEI_SERVICES **PeiServices,
139 IN UINTN NumberOfBeeps,
140 IN UINTN BeepDuration,
141 IN UINTN TimeInterval
142 )
143 {
144
145 if ((NumberOfBeeps == 1) && (BeepDuration == 0) && (TimeInterval == 0)) {
146 TurnOnSpeaker (PeiServices);
147 return EFI_SUCCESS;
148 }
149
150 if ((NumberOfBeeps == 0) && (BeepDuration == 0) && (TimeInterval == 0)) {
151 TurnOffSpeaker (PeiServices);
152 return EFI_SUCCESS;
153 }
154
155 if (BeepDuration == 0) {
156 BeepDuration = EFI_DEFAULT_SHORT_BEEP_DURATION;
157 }
158
159 if (TimeInterval == 0) {
160 TimeInterval = EFI_DEFAULT_BEEP_TIME_INTERVAL;
161 }
162
163 OutputBeep (PeiServices, NumberOfBeeps, BeepDuration, TimeInterval);
164 return EFI_SUCCESS;
165
166
167 }
168