/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2000,2001,2002,2003,2004,2005,2007,2008,2009,2010 Free Software Foundation, Inc.
*
* 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.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef GRUB_MACHINE_PCBIOS
static const unsigned short *serial_hw_io_addr = (const unsigned short *) GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR;
#else
#endif
/* Convert speed to divisor. */
static unsigned short
const struct grub_serial_config *config)
{
unsigned int i;
/* The structure for speed vs. divisor. */
struct divisor
{
unsigned int speed;
unsigned short div;
};
/* The table which lists common configurations. */
/* 1843200 / (speed * 16) */
{
{ 2400, 0x0030 },
{ 4800, 0x0018 },
{ 9600, 0x000C },
{ 19200, 0x0006 },
{ 38400, 0x0003 },
{ 57600, 0x0002 },
{ 115200, 0x0001 }
};
/* Set the baud rate. */
for (i = 0; i < ARRAY_SIZE (divisor_tab); i++)
{
/* internal Loongson UART runs twice the usual rate. */
#ifdef GRUB_MACHINE_MIPS_LOONGSON
else
#endif
return divisor_tab[i].div;
}
return 0;
}
static void
{
int divisor;
unsigned char status = 0;
const unsigned char parities[] = {
};
const unsigned char stop_bits[] = {
};
if (port->configured)
return;
/* Turn off the interrupt. */
/* Set DLAB. */
/* Set the baud rate. */
/* Set the line status. */
/* On Loongson machines serial port has only 3 wires. */
#ifndef GRUB_MACHINE_MIPS_LOONGSON
/* Enable the FIFO. */
/* Turn on DTR and RTS. */
#else
/* Enable the FIFO. */
/* Turn on DTR, RTS, and OUT2. */
#endif
/* Drain the input buffer. */
}
/* Fetch a key. */
static int
{
return -1;
}
/* Put a character. */
static void
{
endtime = grub_get_time_ms ();
else
/* Wait until the transmitter holding register is empty. */
{
if (grub_get_time_ms () > endtime)
{
/* There is something wrong. But what can I do? */
return;
}
}
}
/* Initialize a serial device. PORT is the port number for a serial device.
SPEED is a DTE-DTE speed which must be one of these: 2400, 4800, 9600,
19200, 38400, 57600 and 115200. WORD_LEN is the word length to be used
for the device. Likewise, PARITY is the type of the parity and
STOP_BIT_LEN is the length of the stop bit. The possible values for
WORD_LEN, PARITY and STOP_BIT_LEN are defined in the header file as
macros. */
static grub_err_t
struct grub_serial_config *config)
{
unsigned short divisor;
if (divisor == 0)
port->configured = 0;
/* FIXME: should check if the serial terminal was found. */
return GRUB_ERR_NONE;
}
{
.fetch = serial_hw_fetch,
.put = serial_hw_put
};
void
grub_ns8250_init (void)
{
unsigned i;
for (i = 0; i < GRUB_SERIAL_PORT_NUM; i++)
if (serial_hw_io_addr[i])
{
if (err)
grub_print_error ();
grub_serial_register (&com_ports[i]);
}
}
/* Return the port number for the UNITth serial device. */
{
if (unit < GRUB_SERIAL_PORT_NUM)
return serial_hw_io_addr[unit];
else
return 0;
}
char *
{
struct grub_serial_port *p;
unsigned i;
for (i = 0; i < GRUB_SERIAL_PORT_NUM; i++)
return com_names[i];
p = grub_malloc (sizeof (*p));
if (!p)
return NULL;
if (!p->name)
{
grub_free (p);
return NULL;
}
p->driver = &grub_ns8250_driver;
grub_serial_register (p);
return p->name;
}