6 #include <linux/termios.h>
12 * HACK: declare the ioctl function by hand...
14 * We cannot include <sys/ioctl.h> as it will eventually include
15 * <termios.h>, which will conflict with <linux/temios.h>. As we
16 * really need the latter one AND the ioctl, just declare it by hand
17 * here so that we get to use it...
19 int ioctl(int d, int request, ...);
22 * Open a serial device and adjust the baud rate to give (arbitrary)
23 * baud rate. The actual baud rate is stored back to the @baud
24 * variable. This might differ from the requested one as the
25 * underlying hardware may not support all possible baud
28 * Returns the file descriptor that was opened.
30 int open_at_baud(const char *device, int *baud)
35 fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
38 pr_err("error opening %s: %m\n", device);
42 if (ioctl(fd, TCGETS2, &tios)) {
43 pr_err("TCGETS2: %m\n");
47 tios.c_cflag &= ~CBAUD;
48 tios.c_cflag |= BOTHER;
49 tios.c_ispeed = *baud;
50 tios.c_ospeed = *baud;
52 if (ioctl(fd, TCSETS2, &tios)) {
53 pr_err("TCSETS2: %m");
57 if (ioctl(fd, TCGETS2, &tios)) {
58 pr_err("TCGETS2: %m");
62 *baud = tios.c_ospeed;