xorg-x11-drv-wacom/0004-tools-rearrange-serial-settings.patch
2014-03-19 19:14:03 +10:00

122 lines
2.9 KiB
Diff

From 7f188409d95bc98498d9770974b156c348da40d2 Mon Sep 17 00:00:00 2001
From: Peter Hutterer <peter.hutterer@who-t.net>
Date: Mon, 17 Mar 2014 09:46:21 +1000
Subject: [PATCH 04/14] tools: rearrange serial settings
If the device was't properly closed/reset after a crash, tcgetattr() will
fail. Ignore that error and apply the settings we want nonetheless, in most
cases the device will just come back normally.
And to do so, merge setting the baud rate together with the rest so we only
have one call. Otherwise we can't apply the baud rate settings without
potentially submitting garbage to the driver.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
---
tools/isdv4-serial-debugger.c | 49 +++++++++++++++----------------------------
1 file changed, 17 insertions(+), 32 deletions(-)
diff --git a/tools/isdv4-serial-debugger.c b/tools/isdv4-serial-debugger.c
index 8a64f43..47c6896 100644
--- a/tools/isdv4-serial-debugger.c
+++ b/tools/isdv4-serial-debugger.c
@@ -68,17 +68,16 @@ static void version(void)
PACKAGE_VERSION_PATCHLEVEL);
}
-static int open_device(char *path)
+int open_device(const char *path)
{
- int fd, rc;
+ int fd;
struct serial_struct ser;
- struct termios t;
TRACE("Opening device '%s'.\n", path);
fd = open(path, O_RDWR);
if (fd < 1)
- perror("Failed to open device file.");
+ perror("Failed to open device file");
if (ioctl(fd, TIOCGSERIAL, &ser) == -1)
{
@@ -88,14 +87,16 @@ static int open_device(char *path)
goto out;
}
- rc = tcgetattr(fd, &t);
- if (rc == -1)
- {
- perror("Failed to get serial attributes.");
- close(fd);
- fd = -1;
- goto out;
- }
+out:
+ return fd;
+}
+
+int set_serial_attr(int fd, unsigned int baud)
+{
+ struct termios t;
+
+ if (tcgetattr(fd, &t) == -1)
+ memset(&t, 0, sizeof(t));
/* defaults from xf86OpenSerial */
t.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
@@ -110,21 +111,9 @@ static int open_device(char *path)
t.c_cflag &= ~(CSIZE); /* databits 8 */
t.c_cflag |= (CS8); /* databits 8 */
t.c_cflag &= ~(PARENB); /* parity none */
- t.c_cc[VMIN] = 1; /* vmin 1 */
+ t.c_cc[VMIN] = 1; /* vmin 1 */
t.c_cc[VTIME] = 10; /* vtime 10 */
- t.c_iflag |= IXOFF; /* flow controll xoff */
-
-
- tcsetattr(fd, TCSANOW, &t);
-
-out:
- return fd;
-}
-
-static int set_baud_rate(int fd, int baud)
-{
- struct termios t;
- int rc;
+ t.c_iflag |= IXOFF; /* flow controll xoff */
TRACE("Baud rate is %d\n", baud);
@@ -137,15 +126,11 @@ static int set_baud_rate(int fd, int baud)
return -1;
}
- rc = tcgetattr(fd, &t);
-
- if (rc)
- return rc;
-
cfsetispeed(&t, baud);
cfsetospeed(&t, baud);
return tcsetattr(fd, TCSANOW, &t);
+
}
static int write_to_tablet(int fd, char *command)
@@ -567,7 +552,7 @@ int main (int argc, char **argv)
if (fd < 0)
return 1;
- rc = set_baud_rate(fd, baudrate);
+ rc = set_serial_attr(fd, baudrate);
if (rc < 0)
return 1;
--
1.8.5.3