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