2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2013 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #include <grub/serial.h>
20 #include <grub/types.h>
22 #include <grub/misc.h>
24 #include <grub/time.h>
25 #include <grub/i18n.h>
26 #include <grub/arc/arc.h>
30 do_real_config (struct grub_serial_port
*port
)
36 name
= grub_arc_alt_name_to_norm (port
->name
, "");
38 if (GRUB_ARC_FIRMWARE_VECTOR
->open (name
,GRUB_ARC_FILE_ACCESS_OPEN_RW
,
40 port
->handle_valid
= 0;
42 port
->handle_valid
= 1;
49 serial_hw_fetch (struct grub_serial_port
*port
)
54 do_real_config (port
);
56 if (!port
->handle_valid
)
58 if (GRUB_ARC_FIRMWARE_VECTOR
->read (port
->handle
, &c
,
59 1, &actual
) || actual
<= 0)
64 /* Put a character. */
66 serial_hw_put (struct grub_serial_port
*port
, const int c
)
71 do_real_config (port
);
73 if (!port
->handle_valid
)
76 GRUB_ARC_FIRMWARE_VECTOR
->write (port
->handle
, &c0
,
80 /* Initialize a serial device. PORT is the port number for a serial device.
81 SPEED is a DTE-DTE speed which must be one of these: 2400, 4800, 9600,
82 19200, 38400, 57600 and 115200. WORD_LEN is the word length to be used
83 for the device. Likewise, PARITY is the type of the parity and
84 STOP_BIT_LEN is the length of the stop bit. The possible values for
85 WORD_LEN, PARITY and STOP_BIT_LEN are defined in the header file as
88 serial_hw_configure (struct grub_serial_port
*port
__attribute__ ((unused
)),
89 struct grub_serial_config
*config
__attribute__ ((unused
)))
91 /* FIXME: no ARC serial config available. */
96 struct grub_serial_driver grub_arcserial_driver
=
98 .configure
= serial_hw_configure
,
99 .fetch
= serial_hw_fetch
,
104 grub_arcserial_add_port (const char *path
)
106 struct grub_serial_port
*port
;
109 port
= grub_zalloc (sizeof (*port
));
112 port
->name
= grub_strdup (path
);
116 port
->driver
= &grub_arcserial_driver
;
117 err
= grub_serial_config_defaults (port
);
121 grub_serial_register (port
);
127 dev_iterate (const char *name
,
128 const struct grub_arc_component
*comp
__attribute__ ((unused
)),
129 void *data
__attribute__ ((unused
)))
131 /* We should check consolein/consoleout flags as
132 well but some implementations are buggy. */
133 if ((comp
->flags
& (GRUB_ARC_COMPONENT_FLAG_IN
| GRUB_ARC_COMPONENT_FLAG_OUT
))
134 != (GRUB_ARC_COMPONENT_FLAG_IN
| GRUB_ARC_COMPONENT_FLAG_OUT
))
136 if (!grub_arc_is_device_serial (name
, 1))
138 grub_arcserial_add_port (name
);
143 grub_arcserial_init (void)
145 grub_arc_iterate_devs (dev_iterate
, 0, 1);