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