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>
This commit is contained in:
Ulrich Hecht 2018-01-22 18:56:32 +01:00 committed by Marcel Holtmann
parent 8c6b8eda72
commit 3a19cfcce1
3 changed files with 46 additions and 0 deletions

View File

@ -225,6 +225,18 @@ void serdev_device_set_flow_control(struct serdev_device *serdev, bool enable)
} }
EXPORT_SYMBOL_GPL(serdev_device_set_flow_control); EXPORT_SYMBOL_GPL(serdev_device_set_flow_control);
int serdev_device_set_parity(struct serdev_device *serdev,
enum serdev_parity parity)
{
struct serdev_controller *ctrl = serdev->ctrl;
if (!ctrl || !ctrl->ops->set_parity)
return -ENOTSUPP;
return ctrl->ops->set_parity(ctrl, parity);
}
EXPORT_SYMBOL_GPL(serdev_device_set_parity);
void serdev_device_wait_until_sent(struct serdev_device *serdev, long timeout) void serdev_device_wait_until_sent(struct serdev_device *serdev, long timeout)
{ {
struct serdev_controller *ctrl = serdev->ctrl; struct serdev_controller *ctrl = serdev->ctrl;

View File

@ -190,6 +190,29 @@ static void ttyport_set_flow_control(struct serdev_controller *ctrl, bool enable
tty_set_termios(tty, &ktermios); tty_set_termios(tty, &ktermios);
} }
static int ttyport_set_parity(struct serdev_controller *ctrl,
enum serdev_parity parity)
{
struct serport *serport = serdev_controller_get_drvdata(ctrl);
struct tty_struct *tty = serport->tty;
struct ktermios ktermios = tty->termios;
ktermios.c_cflag &= ~(PARENB | PARODD | CMSPAR);
if (parity != SERDEV_PARITY_NONE) {
ktermios.c_cflag |= PARENB;
if (parity == SERDEV_PARITY_ODD)
ktermios.c_cflag |= PARODD;
}
tty_set_termios(tty, &ktermios);
if ((tty->termios.c_cflag & (PARENB | PARODD | CMSPAR)) !=
(ktermios.c_cflag & (PARENB | PARODD | CMSPAR)))
return -EINVAL;
return 0;
}
static void ttyport_wait_until_sent(struct serdev_controller *ctrl, long timeout) static void ttyport_wait_until_sent(struct serdev_controller *ctrl, long timeout)
{ {
struct serport *serport = serdev_controller_get_drvdata(ctrl); struct serport *serport = serdev_controller_get_drvdata(ctrl);
@ -227,6 +250,7 @@ static const struct serdev_controller_ops ctrl_ops = {
.open = ttyport_open, .open = ttyport_open,
.close = ttyport_close, .close = ttyport_close,
.set_flow_control = ttyport_set_flow_control, .set_flow_control = ttyport_set_flow_control,
.set_parity = ttyport_set_parity,
.set_baudrate = ttyport_set_baudrate, .set_baudrate = ttyport_set_baudrate,
.wait_until_sent = ttyport_wait_until_sent, .wait_until_sent = ttyport_wait_until_sent,
.get_tiocm = ttyport_get_tiocm, .get_tiocm = ttyport_get_tiocm,

View File

@ -76,6 +76,12 @@ static inline struct serdev_device_driver *to_serdev_device_driver(struct device
return container_of(d, struct serdev_device_driver, driver); return container_of(d, struct serdev_device_driver, driver);
} }
enum serdev_parity {
SERDEV_PARITY_NONE,
SERDEV_PARITY_EVEN,
SERDEV_PARITY_ODD,
};
/* /*
* serdev controller structures * serdev controller structures
*/ */
@ -86,6 +92,7 @@ struct serdev_controller_ops {
int (*open)(struct serdev_controller *); int (*open)(struct serdev_controller *);
void (*close)(struct serdev_controller *); void (*close)(struct serdev_controller *);
void (*set_flow_control)(struct serdev_controller *, bool); void (*set_flow_control)(struct serdev_controller *, bool);
int (*set_parity)(struct serdev_controller *, enum serdev_parity);
unsigned int (*set_baudrate)(struct serdev_controller *, unsigned int); unsigned int (*set_baudrate)(struct serdev_controller *, unsigned int);
void (*wait_until_sent)(struct serdev_controller *, long); void (*wait_until_sent)(struct serdev_controller *, long);
int (*get_tiocm)(struct serdev_controller *); int (*get_tiocm)(struct serdev_controller *);
@ -298,6 +305,9 @@ static inline int serdev_device_set_rts(struct serdev_device *serdev, bool enabl
return serdev_device_set_tiocm(serdev, 0, TIOCM_RTS); return serdev_device_set_tiocm(serdev, 0, TIOCM_RTS);
} }
int serdev_device_set_parity(struct serdev_device *serdev,
enum serdev_parity parity);
/* /*
* serdev hooks into TTY core * serdev hooks into TTY core
*/ */