Callback set via own structure.
--- a/examples/tty/serial.c Mon Jan 25 16:15:56 2010 +0100
+++ b/examples/tty/serial.c Mon Jan 25 17:42:07 2010 +0100
@@ -376,6 +376,12 @@
/****************************************************************************/
+static ec_tty_operations_t el60xx_tty_ops = {
+ .cflag_changed = el60xx_cflag_changed,
+};
+
+/****************************************************************************/
+
int el60xx_port_init(el60xx_port_t *port, ec_slave_config_t *sc,
ec_domain_t *domain, unsigned int slot_offset, const char *name)
{
@@ -383,7 +389,7 @@
strncpy(port->name, name, EL6002_PORT_NAME_SIZE);
- port->tty = ectty_create(el60xx_cflag_changed, port);
+ port->tty = ectty_create(&el60xx_tty_ops, port);
if (IS_ERR(port->tty)) {
printk(KERN_ERR PFX "Failed to create tty for %s.\n",
port->name);
--- a/include/ectty.h Mon Jan 25 16:15:56 2010 +0100
+++ b/include/ectty.h Mon Jan 25 17:42:07 2010 +0100
@@ -49,22 +49,27 @@
struct ec_tty;
typedef struct ec_tty ec_tty_t; /**< \see ec_tty */
+/**
+ * \param cflag_changed This callback function is called when the serial
+ * settings shall be changed. The \a cflag argument contains the new settings.
+ */
+typedef struct {
+ int (*cflag_changed)(void *, tcflag_t);
+} ec_tty_operations_t;
+
/******************************************************************************
* Global functions
*****************************************************************************/
/** Create a virtual TTY interface.
*
- * \param cflag_cb This callback function is called when the serial settings
- * shall be changed. The \a cb_data argument is the same as the \a cb_data
- * given on device creation, while the \a cflag argument contains the new
- * settings.
- * \param cb_data Arbitrary data to pass to callbacks.
+ * \param ops Set of callbacks.
+ * \param cb_data Arbitrary data, that is passed to any callback.
*
* \return Pointer to the interface object, otherwise an ERR_PTR value.
*/
ec_tty_t *ectty_create(
- int (*cflag_cb)(void *cb_data, tcflag_t cflag),
+ const ec_tty_operations_t *ops,
void *cb_data
);
--- a/tty/module.c Mon Jan 25 16:15:56 2010 +0100
+++ b/tty/module.c Mon Jan 25 17:42:07 2010 +0100
@@ -110,7 +110,7 @@
struct timer_list timer;
struct tty_struct *tty;
- int (*cflag_cb)(void *, tcflag_t);
+ ec_tty_operations_t ops;
void *cb_data;
};
@@ -184,7 +184,7 @@
*****************************************************************************/
int ec_tty_init(ec_tty_t *tty, int minor,
- int (*cflag_cb)(void *, tcflag_t), void *cb_data)
+ const ec_tty_operations_t *ops, void *cb_data)
{
tty->minor = minor;
tty->tx_read_idx = 0;
@@ -194,7 +194,7 @@
tty->rx_write_idx = 0;
init_timer(&tty->timer);
tty->tty = NULL;
- tty->cflag_cb = cflag_cb;
+ tty->ops = *ops;
tty->cb_data = cb_data;
tty->dev = tty_register_device(tty_driver, tty->minor, NULL);
@@ -343,7 +343,7 @@
static int ec_tty_open(struct tty_struct *tty, struct file *file)
{
ec_tty_t *t;
- int line = tty->index, ret;
+ int line = tty->index;
#if EC_TTY_DEBUG >= 1
printk(KERN_INFO PFX "Opening line %i.\n", line);
@@ -364,15 +364,6 @@
t->tty = tty;
tty->driver_data = t;
-
- // request initial settings
- ret = t->cflag_cb(t->cb_data, t->tty->termios->c_cflag);
- if (ret) {
- printk(KERN_ERR PFX "Error: Device does not accept"
- " initial configuration!\n");
- return ret;
- }
-
return 0;
}
@@ -552,7 +543,7 @@
old_termios->c_cflag, tty->termios->c_cflag);
#endif
- ret = t->cflag_cb(t->cb_data, tty->termios->c_cflag);
+ ret = t->ops.cflag_changed(t->cb_data, tty->termios->c_cflag);
if (ret) {
printk(KERN_ERR PFX "ERROR: cflag 0x%x not accepted.\n",
tty->termios->c_cflag);
@@ -646,7 +637,7 @@
* Public functions and methods
*****************************************************************************/
-ec_tty_t *ectty_create(int (*cflag_cb)(void *, tcflag_t), void *cb_data)
+ec_tty_t *ectty_create(const ec_tty_operations_t *ops, void *cb_data)
{
ec_tty_t *tty;
int minor, ret;
@@ -666,7 +657,7 @@
return ERR_PTR(-ENOMEM);
}
- ret = ec_tty_init(tty, minor, cflag_cb, cb_data);
+ ret = ec_tty_init(tty, minor, ops, cb_data);
if (ret) {
up(&tty_sem);
kfree(tty);