Commit e3b5fde7 authored by Haim Daniel's avatar Haim Daniel Committed by Greg Kroah-Hartman

drivers/staging: refactor dgnc tty registration.

-remove duplicate tty allocation code for serial and printer drivers.
-add missing tty c_ispeed and c_ospeed initialization to 9600.
-fix sparse warning: too long initializer-string for array of char.

This patch was only unit tested due to lack of the actual hardware.
Signed-off-by: default avatarHaim Daniel <haimdaniel@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 052181bb
...@@ -52,19 +52,6 @@ ...@@ -52,19 +52,6 @@
#define dgnc_jiffies_from_ms(a) (((a) * HZ) / 1000) #define dgnc_jiffies_from_ms(a) (((a) * HZ) / 1000)
/*
* Define a local default termios struct. All ports will be created
* with this termios initially. This is the same structure that is defined
* as the default in tty_io.c with the same settings overridden as in serial.c
*
* In short, this should match the internal serial ports' defaults.
*/
#define DEFAULT_IFLAGS (ICRNL | IXON)
#define DEFAULT_OFLAGS (OPOST | ONLCR)
#define DEFAULT_CFLAGS (B9600 | CS8 | CREAD | HUPCL | CLOCAL)
#define DEFAULT_LFLAGS (ISIG | ICANON | ECHO | ECHOE | ECHOK | \
ECHOCTL | ECHOKE | IEXTEN)
#ifndef _POSIX_VDISABLE #ifndef _POSIX_VDISABLE
#define _POSIX_VDISABLE '\0' #define _POSIX_VDISABLE '\0'
#endif #endif
......
...@@ -51,22 +51,6 @@ static const struct digi_t dgnc_digi_init = { ...@@ -51,22 +51,6 @@ static const struct digi_t dgnc_digi_init = {
.digi_term = "ansi" /* default terminal type */ .digi_term = "ansi" /* default terminal type */
}; };
/*
* Define a local default termios struct. All ports will be created
* with this termios initially.
*
* This defines a raw port at 9600 baud, 8 data bits, no parity,
* 1 stop bit.
*/
static const struct ktermios default_termios = {
.c_iflag = (DEFAULT_IFLAGS),
.c_oflag = (DEFAULT_OFLAGS),
.c_cflag = (DEFAULT_CFLAGS),
.c_lflag = (DEFAULT_LFLAGS),
.c_cc = INIT_C_CC,
.c_line = 0,
};
static int dgnc_tty_open(struct tty_struct *tty, struct file *file); static int dgnc_tty_open(struct tty_struct *tty, struct file *file);
static void dgnc_tty_close(struct tty_struct *tty, struct file *file); static void dgnc_tty_close(struct tty_struct *tty, struct file *file);
static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file,
...@@ -129,102 +113,86 @@ static const struct tty_operations dgnc_tty_ops = { ...@@ -129,102 +113,86 @@ static const struct tty_operations dgnc_tty_ops = {
/* TTY Initialization/Cleanup Functions */ /* TTY Initialization/Cleanup Functions */
/** static struct tty_driver *dgnc_tty_create(char *serial_name, uint maxports,
* dgnc_tty_register() - Init the tty subsystem for this board. int major, int minor)
*/
int dgnc_tty_register(struct dgnc_board *brd)
{ {
int rc; int rc;
struct tty_driver *drv;
brd->serial_driver = tty_alloc_driver(brd->maxports, drv = tty_alloc_driver(maxports,
TTY_DRIVER_REAL_RAW | TTY_DRIVER_REAL_RAW |
TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DYNAMIC_DEV |
TTY_DRIVER_HARDWARE_BREAK); TTY_DRIVER_HARDWARE_BREAK);
if (IS_ERR(brd->serial_driver)) if (IS_ERR(drv))
return PTR_ERR(brd->serial_driver); return drv;
snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgnc_%d_", drv->name = serial_name;
brd->boardnum); drv->name_base = 0;
drv->major = major;
brd->serial_driver->name = brd->serial_name; drv->minor_start = minor;
brd->serial_driver->name_base = 0; drv->type = TTY_DRIVER_TYPE_SERIAL;
brd->serial_driver->major = 0; drv->subtype = SERIAL_TYPE_NORMAL;
brd->serial_driver->minor_start = 0; drv->init_termios = tty_std_termios;
brd->serial_driver->type = TTY_DRIVER_TYPE_SERIAL; drv->init_termios.c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL);
brd->serial_driver->subtype = SERIAL_TYPE_NORMAL; drv->init_termios.c_ispeed = 9600;
brd->serial_driver->init_termios = default_termios; drv->init_termios.c_ospeed = 9600;
brd->serial_driver->driver_name = DRVSTR; drv->driver_name = DRVSTR;
/* /*
* Entry points for driver. Called by the kernel from * Entry points for driver. Called by the kernel from
* tty_io.c and n_tty.c. * tty_io.c and n_tty.c.
*/ */
tty_set_operations(brd->serial_driver, &dgnc_tty_ops); tty_set_operations(drv, &dgnc_tty_ops);
rc = tty_register_driver(drv);
rc = tty_register_driver(brd->serial_driver);
if (rc < 0) { if (rc < 0) {
dev_dbg(&brd->pdev->dev, put_tty_driver(drv);
"Can't register tty device (%d)\n", rc); return ERR_PTR(rc);
goto free_serial_driver;
} }
return drv;
}
/* static void dgnc_tty_free(struct tty_driver *drv)
* If we're doing transparent print, we have to do all of the above {
* again, separately so we don't get the LD confused about what major tty_unregister_driver(drv);
* we are when we get into the dgnc_tty_open() routine. put_tty_driver(drv);
*/ }
brd->print_driver = tty_alloc_driver(brd->maxports,
TTY_DRIVER_REAL_RAW |
TTY_DRIVER_DYNAMIC_DEV |
TTY_DRIVER_HARDWARE_BREAK);
if (IS_ERR(brd->print_driver)) {
rc = PTR_ERR(brd->print_driver);
goto unregister_serial_driver;
}
snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgnc_%d_", brd->boardnum);
brd->print_driver->name = brd->print_name;
brd->print_driver->name_base = 0;
brd->print_driver->major = brd->serial_driver->major;
brd->print_driver->minor_start = 0x80;
brd->print_driver->type = TTY_DRIVER_TYPE_SERIAL;
brd->print_driver->subtype = SERIAL_TYPE_NORMAL;
brd->print_driver->init_termios = default_termios;
brd->print_driver->driver_name = DRVSTR;
/* /**
* Entry points for driver. Called by the kernel from * dgnc_tty_register() - Init the tty subsystem for this board.
* tty_io.c and n_tty.c.
*/ */
tty_set_operations(brd->print_driver, &dgnc_tty_ops); int dgnc_tty_register(struct dgnc_board *brd)
{
int rc;
rc = tty_register_driver(brd->print_driver); snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgnc_%d_",
if (rc < 0) { brd->boardnum);
dev_dbg(&brd->pdev->dev,
"Can't register Transparent Print device(%d)\n", brd->serial_driver = dgnc_tty_create(brd->serial_name,
brd->maxports, 0, 0);
if (IS_ERR(brd->serial_driver)) {
rc = PTR_ERR(brd->serial_driver);
dev_dbg(&brd->pdev->dev, "Can't register tty device (%d)\n",
rc); rc);
goto free_print_driver; return rc;
} }
return 0; snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgnc_%d_", brd->boardnum);
brd->print_driver = dgnc_tty_create(brd->print_name, brd->maxports,
free_print_driver: 0x80,
put_tty_driver(brd->print_driver); brd->serial_driver->major);
unregister_serial_driver: if (IS_ERR(brd->print_driver)) {
tty_unregister_driver(brd->serial_driver); rc = PTR_ERR(brd->print_driver);
free_serial_driver: dev_dbg(&brd->pdev->dev,
put_tty_driver(brd->serial_driver); "Can't register Transparent Print device(%d)\n", rc);
dgnc_tty_free(brd->serial_driver);
return rc; return rc;
}
return 0;
} }
void dgnc_tty_unregister(struct dgnc_board *brd) void dgnc_tty_unregister(struct dgnc_board *brd)
{ {
tty_unregister_driver(brd->print_driver); dgnc_tty_free(brd->print_driver);
tty_unregister_driver(brd->serial_driver); dgnc_tty_free(brd->serial_driver);
put_tty_driver(brd->print_driver);
put_tty_driver(brd->serial_driver);
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment