Skip to content

Commit

Permalink
serdev: Add method to assert break signal over tty UART port
Browse files Browse the repository at this point in the history
Adds serdev_device_break_ctl() and an implementation for ttyport.
This function simply calls the break_ctl in tty layer, which can
assert a break signal over UART-TX line, if the tty and the
underlying platform and UART peripheral supports this operation.

Signed-off-by: Neeraj Sanjay Kale <neeraj.sanjaykale@nxp.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
  • Loading branch information
Neeraj Sanjay Kale authored and Luiz Augusto von Dentz committed Mar 17, 2023
1 parent d227f28 commit 5ea260d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions drivers/tty/serdev/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,17 @@ int serdev_device_set_tiocm(struct serdev_device *serdev, int set, int clear)
}
EXPORT_SYMBOL_GPL(serdev_device_set_tiocm);

int serdev_device_break_ctl(struct serdev_device *serdev, int break_state)
{
struct serdev_controller *ctrl = serdev->ctrl;

if (!ctrl || !ctrl->ops->break_ctl)
return -EOPNOTSUPP;

return ctrl->ops->break_ctl(ctrl, break_state);
}
EXPORT_SYMBOL_GPL(serdev_device_break_ctl);

static int serdev_drv_probe(struct device *dev)
{
const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver);
Expand Down
12 changes: 12 additions & 0 deletions drivers/tty/serdev/serdev-ttyport.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,17 @@ static int ttyport_set_tiocm(struct serdev_controller *ctrl, unsigned int set, u
return tty->ops->tiocmset(tty, set, clear);
}

static int ttyport_break_ctl(struct serdev_controller *ctrl, unsigned int break_state)
{
struct serport *serport = serdev_controller_get_drvdata(ctrl);
struct tty_struct *tty = serport->tty;

if (!tty->ops->break_ctl)
return -EOPNOTSUPP;

return tty->ops->break_ctl(tty, break_state);
}

static const struct serdev_controller_ops ctrl_ops = {
.write_buf = ttyport_write_buf,
.write_flush = ttyport_write_flush,
Expand All @@ -259,6 +270,7 @@ static const struct serdev_controller_ops ctrl_ops = {
.wait_until_sent = ttyport_wait_until_sent,
.get_tiocm = ttyport_get_tiocm,
.set_tiocm = ttyport_set_tiocm,
.break_ctl = ttyport_break_ctl,
};

struct device *serdev_tty_port_register(struct tty_port *port,
Expand Down
6 changes: 6 additions & 0 deletions include/linux/serdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ struct serdev_controller_ops {
void (*wait_until_sent)(struct serdev_controller *, long);
int (*get_tiocm)(struct serdev_controller *);
int (*set_tiocm)(struct serdev_controller *, unsigned int, unsigned int);
int (*break_ctl)(struct serdev_controller *ctrl, unsigned int break_state);
};

/**
Expand Down Expand Up @@ -203,6 +204,7 @@ int serdev_device_write_buf(struct serdev_device *, const unsigned char *, size_
void serdev_device_wait_until_sent(struct serdev_device *, long);
int serdev_device_get_tiocm(struct serdev_device *);
int serdev_device_set_tiocm(struct serdev_device *, int, int);
int serdev_device_break_ctl(struct serdev_device *serdev, int break_state);
void serdev_device_write_wakeup(struct serdev_device *);
int serdev_device_write(struct serdev_device *, const unsigned char *, size_t, long);
void serdev_device_write_flush(struct serdev_device *);
Expand Down Expand Up @@ -256,6 +258,10 @@ static inline int serdev_device_set_tiocm(struct serdev_device *serdev, int set,
{
return -EOPNOTSUPP;
}
static inline int serdev_device_break_ctl(struct serdev_device *serdev, int break_state)
{
return -EOPNOTSUPP;
}
static inline int serdev_device_write(struct serdev_device *sdev, const unsigned char *buf,
size_t count, unsigned long timeout)
{
Expand Down

0 comments on commit 5ea260d

Please sign in to comment.