129 lines
3.6 KiB
C
129 lines
3.6 KiB
C
/*
|
|
* VAS_EBOOT -- GRand Unified Bootloader
|
|
* Copyright (C) 2008, 2009 Free Software Foundation, Inc.
|
|
*
|
|
* VAS_EBOOT is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* VAS_EBOOT is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with VAS_EBOOT. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef VAS_EBOOT_CMOS_H
|
|
#define VAS_EBOOT_CMOS_H 1
|
|
|
|
#include <VasEBoot/types.h>
|
|
#if !defined (__powerpc__) && !defined (__sparc__)
|
|
#include <VasEBoot/cpu/io.h>
|
|
#include <VasEBoot/cpu/cmos.h>
|
|
#endif
|
|
|
|
#define VAS_EBOOT_CMOS_INDEX_SECOND 0
|
|
#define VAS_EBOOT_CMOS_INDEX_SECOND_ALARM 1
|
|
#define VAS_EBOOT_CMOS_INDEX_MINUTE 2
|
|
#define VAS_EBOOT_CMOS_INDEX_MINUTE_ALARM 3
|
|
#define VAS_EBOOT_CMOS_INDEX_HOUR 4
|
|
#define VAS_EBOOT_CMOS_INDEX_HOUR_ALARM 5
|
|
#define VAS_EBOOT_CMOS_INDEX_DAY_OF_WEEK 6
|
|
#define VAS_EBOOT_CMOS_INDEX_DAY_OF_MONTH 7
|
|
#define VAS_EBOOT_CMOS_INDEX_MONTH 8
|
|
#define VAS_EBOOT_CMOS_INDEX_YEAR 9
|
|
|
|
#define VAS_EBOOT_CMOS_INDEX_STATUS_A 0xA
|
|
#define VAS_EBOOT_CMOS_INDEX_STATUS_B 0xB
|
|
#define VAS_EBOOT_CMOS_INDEX_STATUS_C 0xC
|
|
#define VAS_EBOOT_CMOS_INDEX_STATUS_D 0xD
|
|
|
|
#define VAS_EBOOT_CMOS_STATUS_B_DAYLIGHT 1
|
|
#define VAS_EBOOT_CMOS_STATUS_B_24HOUR 2
|
|
#define VAS_EBOOT_CMOS_STATUS_B_BINARY 4
|
|
|
|
static inline VasEBoot_uint8_t
|
|
VasEBoot_bcd_to_num (VasEBoot_uint8_t a)
|
|
{
|
|
return ((a >> 4) * 10 + (a & 0xF));
|
|
}
|
|
|
|
static inline VasEBoot_uint8_t
|
|
VasEBoot_num_to_bcd (VasEBoot_uint8_t a)
|
|
{
|
|
return (((a / 10) << 4) + (a % 10));
|
|
}
|
|
|
|
#if !defined (__powerpc__) && !defined (__sparc__)
|
|
static inline VasEBoot_err_t
|
|
VasEBoot_cmos_read (VasEBoot_uint8_t index, VasEBoot_uint8_t *val)
|
|
{
|
|
if (index & 0x80)
|
|
{
|
|
VasEBoot_outb (index & 0x7f, VAS_EBOOT_CMOS_ADDR_REG_HI);
|
|
*val = VasEBoot_inb (VAS_EBOOT_CMOS_DATA_REG_HI);
|
|
}
|
|
else
|
|
{
|
|
VasEBoot_outb (index & 0x7f, VAS_EBOOT_CMOS_ADDR_REG);
|
|
*val = VasEBoot_inb (VAS_EBOOT_CMOS_DATA_REG);
|
|
}
|
|
return VAS_EBOOT_ERR_NONE;
|
|
}
|
|
|
|
static inline VasEBoot_err_t
|
|
VasEBoot_cmos_write (VasEBoot_uint8_t index, VasEBoot_uint8_t value)
|
|
{
|
|
if (index & 0x80)
|
|
{
|
|
VasEBoot_outb (index & 0x7f, VAS_EBOOT_CMOS_ADDR_REG_HI);
|
|
VasEBoot_outb (value, VAS_EBOOT_CMOS_DATA_REG_HI);
|
|
}
|
|
else
|
|
{
|
|
VasEBoot_outb (index & 0x7f, VAS_EBOOT_CMOS_ADDR_REG);
|
|
VasEBoot_outb (value, VAS_EBOOT_CMOS_DATA_REG);
|
|
}
|
|
return VAS_EBOOT_ERR_NONE;
|
|
}
|
|
#else
|
|
VasEBoot_err_t VasEBoot_cmos_find_port (void);
|
|
extern volatile VasEBoot_uint8_t *VasEBoot_cmos_port;
|
|
|
|
static inline VasEBoot_err_t
|
|
VasEBoot_cmos_read (VasEBoot_uint8_t index, VasEBoot_uint8_t *val)
|
|
{
|
|
if (!VasEBoot_cmos_port)
|
|
{
|
|
VasEBoot_err_t err;
|
|
err = VasEBoot_cmos_find_port ();
|
|
if (err)
|
|
return err;
|
|
}
|
|
VasEBoot_cmos_port[((index & 0x80) >> 6) | 0] = index & 0x7f;
|
|
*val = VasEBoot_cmos_port[((index & 0x80) >> 6) | 1];
|
|
return VAS_EBOOT_ERR_NONE;
|
|
}
|
|
|
|
static inline VasEBoot_err_t
|
|
VasEBoot_cmos_write (VasEBoot_uint8_t index, VasEBoot_uint8_t val)
|
|
{
|
|
if (!VasEBoot_cmos_port)
|
|
{
|
|
VasEBoot_err_t err;
|
|
err = VasEBoot_cmos_find_port ();
|
|
if (err)
|
|
return err;
|
|
}
|
|
VasEBoot_cmos_port[((index & 0x80) >> 6) | 0] = index;
|
|
VasEBoot_cmos_port[((index & 0x80) >> 6) | 1] = val;
|
|
return VAS_EBOOT_ERR_NONE;
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* VAS_EBOOT_CMOS_H */
|