Indentation fix, cleanup.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / term / arc / serial.c
blob87d1ce8218db807045bdd64fb06c5af9d5746416
1 /*
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>
21 #include <grub/dl.h>
22 #include <grub/misc.h>
23 #include <grub/mm.h>
24 #include <grub/time.h>
25 #include <grub/i18n.h>
26 #include <grub/arc/arc.h>
29 static void
30 do_real_config (struct grub_serial_port *port)
32 char *name;
33 if (port->configured)
34 return;
36 name = grub_arc_alt_name_to_norm (port->name, "");
38 if (GRUB_ARC_FIRMWARE_VECTOR->open (name,GRUB_ARC_FILE_ACCESS_OPEN_RW,
39 &port->handle))
40 port->handle_valid = 0;
41 else
42 port->handle_valid = 1;
44 port->configured = 1;
47 /* Fetch a key. */
48 static int
49 serial_hw_fetch (struct grub_serial_port *port)
51 unsigned long actual;
52 char c;
54 do_real_config (port);
56 if (!port->handle_valid)
57 return -1;
58 if (GRUB_ARC_FIRMWARE_VECTOR->read (port->handle, &c,
59 1, &actual) || actual <= 0)
60 return -1;
61 return c;
64 /* Put a character. */
65 static void
66 serial_hw_put (struct grub_serial_port *port, const int c)
68 unsigned long actual;
69 char c0 = c;
71 do_real_config (port);
73 if (!port->handle_valid)
74 return;
76 GRUB_ARC_FIRMWARE_VECTOR->write (port->handle, &c0,
77 1, &actual);
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
86 macros. */
87 static grub_err_t
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. */
93 return GRUB_ERR_NONE;
96 struct grub_serial_driver grub_arcserial_driver =
98 .configure = serial_hw_configure,
99 .fetch = serial_hw_fetch,
100 .put = serial_hw_put
103 const char *
104 grub_arcserial_add_port (const char *path)
106 struct grub_serial_port *port;
107 grub_err_t err;
109 port = grub_zalloc (sizeof (*port));
110 if (!port)
111 return NULL;
112 port->name = grub_strdup (path);
113 if (!port->name)
114 return NULL;
116 port->driver = &grub_arcserial_driver;
117 err = grub_serial_config_defaults (port);
118 if (err)
119 grub_print_error ();
121 grub_serial_register (port);
123 return port->name;
126 static int
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))
135 return 0;
136 if (!grub_arc_is_device_serial (name, 1))
137 return 0;
138 grub_arcserial_add_port (name);
139 return 0;
142 void
143 grub_arcserial_init (void)
145 grub_arc_iterate_devs (dev_iterate, 0, 1);