Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serdev: add method to set parity

Adds serdev_device_set_parity() and an implementation for ttyport.
The interface uses an enum with the values SERIAL_PARITY_NONE,
SERIAL_PARITY_EVEN and SERIAL_PARITY_ODD.

Signed-off-by: Ulrich Hecht <ulrich.hecht+renesas@gmail.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Reviewed-by: Johan Hovold <johan@kernel.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>

authored by

Ulrich Hecht and committed by
Marcel Holtmann
3a19cfcc 8c6b8eda

+46
+12
drivers/tty/serdev/core.c
··· 225 225 } 226 226 EXPORT_SYMBOL_GPL(serdev_device_set_flow_control); 227 227 228 + int serdev_device_set_parity(struct serdev_device *serdev, 229 + enum serdev_parity parity) 230 + { 231 + struct serdev_controller *ctrl = serdev->ctrl; 232 + 233 + if (!ctrl || !ctrl->ops->set_parity) 234 + return -ENOTSUPP; 235 + 236 + return ctrl->ops->set_parity(ctrl, parity); 237 + } 238 + EXPORT_SYMBOL_GPL(serdev_device_set_parity); 239 + 228 240 void serdev_device_wait_until_sent(struct serdev_device *serdev, long timeout) 229 241 { 230 242 struct serdev_controller *ctrl = serdev->ctrl;
+24
drivers/tty/serdev/serdev-ttyport.c
··· 190 190 tty_set_termios(tty, &ktermios); 191 191 } 192 192 193 + static int ttyport_set_parity(struct serdev_controller *ctrl, 194 + enum serdev_parity parity) 195 + { 196 + struct serport *serport = serdev_controller_get_drvdata(ctrl); 197 + struct tty_struct *tty = serport->tty; 198 + struct ktermios ktermios = tty->termios; 199 + 200 + ktermios.c_cflag &= ~(PARENB | PARODD | CMSPAR); 201 + if (parity != SERDEV_PARITY_NONE) { 202 + ktermios.c_cflag |= PARENB; 203 + if (parity == SERDEV_PARITY_ODD) 204 + ktermios.c_cflag |= PARODD; 205 + } 206 + 207 + tty_set_termios(tty, &ktermios); 208 + 209 + if ((tty->termios.c_cflag & (PARENB | PARODD | CMSPAR)) != 210 + (ktermios.c_cflag & (PARENB | PARODD | CMSPAR))) 211 + return -EINVAL; 212 + 213 + return 0; 214 + } 215 + 193 216 static void ttyport_wait_until_sent(struct serdev_controller *ctrl, long timeout) 194 217 { 195 218 struct serport *serport = serdev_controller_get_drvdata(ctrl); ··· 250 227 .open = ttyport_open, 251 228 .close = ttyport_close, 252 229 .set_flow_control = ttyport_set_flow_control, 230 + .set_parity = ttyport_set_parity, 253 231 .set_baudrate = ttyport_set_baudrate, 254 232 .wait_until_sent = ttyport_wait_until_sent, 255 233 .get_tiocm = ttyport_get_tiocm,
+10
include/linux/serdev.h
··· 76 76 return container_of(d, struct serdev_device_driver, driver); 77 77 } 78 78 79 + enum serdev_parity { 80 + SERDEV_PARITY_NONE, 81 + SERDEV_PARITY_EVEN, 82 + SERDEV_PARITY_ODD, 83 + }; 84 + 79 85 /* 80 86 * serdev controller structures 81 87 */ ··· 92 86 int (*open)(struct serdev_controller *); 93 87 void (*close)(struct serdev_controller *); 94 88 void (*set_flow_control)(struct serdev_controller *, bool); 89 + int (*set_parity)(struct serdev_controller *, enum serdev_parity); 95 90 unsigned int (*set_baudrate)(struct serdev_controller *, unsigned int); 96 91 void (*wait_until_sent)(struct serdev_controller *, long); 97 92 int (*get_tiocm)(struct serdev_controller *); ··· 304 297 else 305 298 return serdev_device_set_tiocm(serdev, 0, TIOCM_RTS); 306 299 } 300 + 301 + int serdev_device_set_parity(struct serdev_device *serdev, 302 + enum serdev_parity parity); 307 303 308 304 /* 309 305 * serdev hooks into TTY core