2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2008 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#include <grub/types.h>
2N/A#include <grub/i386/io.h>
2N/A#include <grub/i386/pit.h>
2N/A
2N/A#define TIMER2_REG_CONTROL 0x42
2N/A#define TIMER_REG_COMMAND 0x43
2N/A#define TIMER2_REG_LATCH 0x61
2N/A
2N/A#define TIMER2_SELECT 0x80
2N/A#define TIMER_ENABLE_LSB 0x20
2N/A#define TIMER_ENABLE_MSB 0x10
2N/A#define TIMER2_LATCH 0x20
2N/A#define TIMER2_SPEAKER 0x02
2N/A#define TIMER2_GATE 0x01
2N/A
2N/Avoid
2N/Agrub_pit_wait (grub_uint16_t tics)
2N/A{
2N/A /* Disable timer2 gate and speaker. */
2N/A grub_outb (grub_inb (TIMER2_REG_LATCH) & ~ (TIMER2_SPEAKER | TIMER2_GATE),
2N/A TIMER2_REG_LATCH);
2N/A
2N/A /* Set tics. */
2N/A grub_outb (TIMER2_SELECT | TIMER_ENABLE_LSB | TIMER_ENABLE_MSB, TIMER_REG_COMMAND);
2N/A grub_outb (tics & 0xff, TIMER2_REG_CONTROL);
2N/A grub_outb (tics >> 8, TIMER2_REG_CONTROL);
2N/A
2N/A /* Enable timer2 gate, keep speaker disabled. */
2N/A grub_outb ((grub_inb (TIMER2_REG_LATCH) & ~ TIMER2_SPEAKER) | TIMER2_GATE,
2N/A TIMER2_REG_LATCH);
2N/A
2N/A /* Wait. */
2N/A while ((grub_inb (TIMER2_REG_LATCH) & TIMER2_LATCH) == 0x00);
2N/A
2N/A /* Disable timer2 gate and speaker. */
2N/A grub_outb (grub_inb (TIMER2_REG_LATCH) & ~ (TIMER2_SPEAKER | TIMER2_GATE),
2N/A TIMER2_REG_LATCH);
2N/A}