1 /* console.c -- Open Firmware console for GRUB. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/term.h>
21 #include <grub/types.h>
22 #include <grub/misc.h>
24 #include <grub/time.h>
25 #include <grub/terminfo.h>
27 #include <grub/speaker.h>
29 GRUB_MOD_LICENSE ("GPLv3+");
31 extern struct grub_terminfo_output_state grub_spkmodem_terminfo_output
;
34 make_tone (grub_uint16_t freq_count
, unsigned int duration
)
36 /* Program timer 2. */
37 grub_outb (GRUB_PIT_CTRL_SELECT_2
38 | GRUB_PIT_CTRL_READLOAD_WORD
39 | GRUB_PIT_CTRL_SQUAREWAVE_GEN
40 | GRUB_PIT_CTRL_COUNT_BINARY
, GRUB_PIT_CTRL
);
41 grub_outb (freq_count
& 0xff, GRUB_PIT_COUNTER_2
); /* LSB */
42 grub_outb ((freq_count
>> 8) & 0xff, GRUB_PIT_COUNTER_2
); /* MSB */
45 grub_outb (grub_inb (GRUB_PIT_SPEAKER_PORT
)
46 | GRUB_PIT_SPK_TMR2
| GRUB_PIT_SPK_DATA
,
47 GRUB_PIT_SPEAKER_PORT
);
49 for (; duration
; duration
--)
51 unsigned short counter
, previous_counter
= 0xffff;
54 counter
= grub_inb (GRUB_PIT_COUNTER_2
);
55 counter
|= ((grub_uint16_t
) grub_inb (GRUB_PIT_COUNTER_2
)) << 8;
56 if (counter
> previous_counter
)
58 previous_counter
= counter
;
61 previous_counter
= counter
;
69 put (struct grub_term_output
*term
__attribute__ ((unused
)), const int c
)
73 make_tone (GRUB_SPEAKER_PIT_FREQUENCY
/ 200, 4);
74 for (i
= 7; i
>= 0; i
--)
77 make_tone (GRUB_SPEAKER_PIT_FREQUENCY
/ 2000, 20);
79 make_tone (GRUB_SPEAKER_PIT_FREQUENCY
/ 4000, 40);
80 make_tone (GRUB_SPEAKER_PIT_FREQUENCY
/ 1000, 10);
82 make_tone (GRUB_SPEAKER_PIT_FREQUENCY
/ 200, 0);
86 grub_spkmodem_init_output (struct grub_term_output
*term
)
88 /* Some models shutdown sound when not in use and it takes for it
89 around 30 ms to come back on which loses 3 bits. So generate a base
90 200 Hz continously. */
92 make_tone (GRUB_SPEAKER_PIT_FREQUENCY
/ 200, 0);
93 grub_terminfo_output_init (term
);
99 grub_spkmodem_fini_output (struct grub_term_output
*term
__attribute__ ((unused
)))
101 grub_speaker_beep_off ();
109 struct grub_terminfo_output_state grub_spkmodem_terminfo_output
=
115 static struct grub_term_output grub_spkmodem_term_output
=
118 .init
= grub_spkmodem_init_output
,
119 .fini
= grub_spkmodem_fini_output
,
120 .putchar
= grub_terminfo_putchar
,
121 .getxy
= grub_terminfo_getxy
,
122 .getwh
= grub_terminfo_getwh
,
123 .gotoxy
= grub_terminfo_gotoxy
,
124 .cls
= grub_terminfo_cls
,
125 .setcolorstate
= grub_terminfo_setcolorstate
,
126 .setcursor
= grub_terminfo_setcursor
,
127 .flags
= GRUB_TERM_CODE_TYPE_ASCII
,
128 .data
= &grub_spkmodem_terminfo_output
,
129 .progress_update_divisor
= GRUB_PROGRESS_NO_UPDATE
132 GRUB_MOD_INIT (spkmodem
)
134 grub_term_register_output ("spkmodem", &grub_spkmodem_term_output
);
138 GRUB_MOD_FINI (spkmodem
)
140 grub_term_unregister_output (&grub_spkmodem_term_output
);