tty/module.c
author Florian Pose <fp@igh-essen.com>
Tue, 18 Oct 2016 10:20:47 +0200
branchstable-1.5
changeset 2662 a1079c6242a5
parent 2661 39280d5a3321
permissions -rw-r--r--
Support changed sock_create_kern() interface from Linux 4.2.
1565
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  published by the Free Software Foundation.
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  Public License for more details.
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *  ---
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *****************************************************************************/
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
/** \file
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
 * EtherCAT tty driver module.
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 */
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
/*****************************************************************************/
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#include <linux/module.h>
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include <linux/err.h>
1568
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
    38
#include <linux/tty.h>
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
    39
#include <linux/tty_driver.h>
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
    40
#include <linux/tty_flip.h>
1568
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
    41
#include <linux/termios.h>
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
    42
#include <linux/timer.h>
1595
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
    43
#include <linux/version.h>
1778
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
    44
#include <linux/serial.h>
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
    45
#include <linux/uaccess.h>
1975
8e173dddd183 Improved compiling on 2.6.34 (thanks to Malcolm Lewis).
Florian Pose <fp@igh-essen.com>
parents: 1908
diff changeset
    46
#include <linux/slab.h>
1565
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
#include "../master/globals.h"
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
    49
#include "../include/ectty.h"
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
    50
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
    51
/*****************************************************************************/
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
    52
1570
7a2a58107dd8 Use own PFX for printk.
Florian Pose <fp@igh-essen.com>
parents: 1569
diff changeset
    53
#define PFX "ec_tty: "
7a2a58107dd8 Use own PFX for printk.
Florian Pose <fp@igh-essen.com>
parents: 1569
diff changeset
    54
1789
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
    55
#define EC_TTY_MAX_DEVICES 32
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
    56
#define EC_TTY_TX_BUFFER_SIZE 100
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
    57
#define EC_TTY_RX_BUFFER_SIZE 100
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
    58
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
    59
#define EC_TTY_DEBUG 0
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
    60
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
    61
/*****************************************************************************/
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
    62
1565
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
char *ec_master_version_str = EC_MASTER_VERSION; /**< Version string. */
1570
7a2a58107dd8 Use own PFX for printk.
Florian Pose <fp@igh-essen.com>
parents: 1569
diff changeset
    64
unsigned int debug_level = 0;
1565
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
    66
static struct tty_driver *tty_driver = NULL;
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
    67
ec_tty_t *ttys[EC_TTY_MAX_DEVICES];
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
    68
struct semaphore tty_sem;
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
    69
1786
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
    70
void ec_tty_wakeup(unsigned long);
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
    71
1565
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
/*****************************************************************************/
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
/** \cond */
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
MODULE_DESCRIPTION("EtherCAT TTY driver module");
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
MODULE_LICENSE("GPL");
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
MODULE_VERSION(EC_MASTER_VERSION);
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
module_param_named(debug_level, debug_level, uint, S_IRUGO);
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
MODULE_PARM_DESC(debug_level, "Debug level");
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
    84
/** \endcond */
1568
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
    85
1778
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
    86
/** Standard termios for ec_tty devices.
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
    87
 *
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
    88
 * Simplest possible configuration, as you would expect.
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
    89
 */
1568
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
    90
static struct ktermios ec_tty_std_termios = {
1778
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
    91
    .c_iflag = 0,
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
    92
    .c_oflag = 0,
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
    93
    .c_cflag = B9600 | CS8 | CREAD,
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
    94
    .c_lflag = 0,
1568
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
    95
    .c_cc = INIT_C_CC,
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
    96
};
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
    97
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
    98
struct ec_tty {
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
    99
    int minor;
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   100
    struct device *dev;
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   101
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   102
    uint8_t tx_buffer[EC_TTY_TX_BUFFER_SIZE];
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   103
    unsigned int tx_read_idx;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   104
    unsigned int tx_write_idx;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   105
    unsigned int wakeup;
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   106
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   107
    uint8_t rx_buffer[EC_TTY_RX_BUFFER_SIZE];
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   108
    unsigned int rx_read_idx;
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   109
    unsigned int rx_write_idx;
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   110
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   111
    struct timer_list timer;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   112
    struct tty_struct *tty;
1797
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   113
    unsigned int open_count;
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   114
    struct semaphore sem;
1779
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   115
1787
439f186185be Callback set via own structure.
Florian Pose <fp@igh-essen.com>
parents: 1786
diff changeset
   116
    ec_tty_operations_t ops;
1779
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   117
    void *cb_data;
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   118
};
1565
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   120
static const struct tty_operations ec_tty_ops; // see below
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   121
1565
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
/*****************************************************************************/
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
/** Module initialization.
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
 *
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
 * \return 0 on success, else < 0
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
 */
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
int __init ec_tty_init_module(void)
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
{
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   130
    int i, ret = 0;
1565
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
1570
7a2a58107dd8 Use own PFX for printk.
Florian Pose <fp@igh-essen.com>
parents: 1569
diff changeset
   132
    printk(KERN_INFO PFX "TTY driver %s\n", EC_MASTER_VERSION);
1565
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
1808
96adb3e6db74 Replaced deprecated init_MUTEX in tty code.
Florian Pose <fp@igh-essen.com>
parents: 1797
diff changeset
   134
    sema_init(&tty_sem, 1);
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   135
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   136
    for (i = 0; i < EC_TTY_MAX_DEVICES; i++) {
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   137
        ttys[i] = NULL;
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   138
    }
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   139
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   140
    tty_driver = alloc_tty_driver(EC_TTY_MAX_DEVICES);
1568
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   141
    if (!tty_driver) {
1570
7a2a58107dd8 Use own PFX for printk.
Florian Pose <fp@igh-essen.com>
parents: 1569
diff changeset
   142
        printk(KERN_ERR PFX "Failed to allocate tty driver.\n");
1568
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   143
        ret = -ENOMEM;
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   144
        goto out_return;
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   145
    }
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   146
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   147
    tty_driver->owner = THIS_MODULE;
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   148
    tty_driver->driver_name = "EtherCAT TTY";
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   149
    tty_driver->name = "ttyEC";
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   150
    tty_driver->major = 0;
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   151
    tty_driver->minor_start = 0;
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   152
    tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   153
    tty_driver->subtype = SERIAL_TYPE_NORMAL;
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   154
    tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   155
    tty_driver->init_termios = ec_tty_std_termios;
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   156
    tty_set_operations(tty_driver, &ec_tty_ops);
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   157
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   158
    ret = tty_register_driver(tty_driver);
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   159
    if (ret) {
1570
7a2a58107dd8 Use own PFX for printk.
Florian Pose <fp@igh-essen.com>
parents: 1569
diff changeset
   160
        printk(KERN_ERR PFX "Failed to register tty driver.\n");
1568
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   161
        goto out_put;
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   162
    }
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   163
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   164
    return ret;
2384
b068951506d9 Removed whitespace.
Florian Pose <fp@igh-essen.com>
parents: 1975
diff changeset
   165
1568
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   166
out_put:
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   167
    put_tty_driver(tty_driver);
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   168
out_return:
1565
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
    return ret;
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
}
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
/*****************************************************************************/
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
/** Module cleanup.
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
 *
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
 * Clears all master instances.
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
 */
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
void __exit ec_tty_cleanup_module(void)
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
{
1568
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   180
    tty_unregister_driver(tty_driver);
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   181
    put_tty_driver(tty_driver);
1570
7a2a58107dd8 Use own PFX for printk.
Florian Pose <fp@igh-essen.com>
parents: 1569
diff changeset
   182
    printk(KERN_INFO PFX "Module unloading.\n");
1565
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
}
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
1786
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   185
/******************************************************************************
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   186
 * ec_tty_t methods.
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   187
 *****************************************************************************/
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   188
1789
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   189
int ec_tty_init(ec_tty_t *t, int minor,
1787
439f186185be Callback set via own structure.
Florian Pose <fp@igh-essen.com>
parents: 1786
diff changeset
   190
        const ec_tty_operations_t *ops, void *cb_data)
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   191
{
1789
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   192
    int ret;
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   193
    tcflag_t cflag;
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   194
    struct tty_struct *tty;
2518
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   195
    struct ktermios *termios;
1789
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   196
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   197
    t->minor = minor;
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   198
    t->tx_read_idx = 0;
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   199
    t->tx_write_idx = 0;
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   200
    t->wakeup = 0;
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   201
    t->rx_read_idx = 0;
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   202
    t->rx_write_idx = 0;
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   203
    init_timer(&t->timer);
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   204
    t->tty = NULL;
1797
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   205
    t->open_count = 0;
1808
96adb3e6db74 Replaced deprecated init_MUTEX in tty code.
Florian Pose <fp@igh-essen.com>
parents: 1797
diff changeset
   206
    sema_init(&t->sem, 1);
1789
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   207
    t->ops = *ops;
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   208
    t->cb_data = cb_data;
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   209
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   210
    t->dev = tty_register_device(tty_driver, t->minor, NULL);
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   211
    if (IS_ERR(t->dev)) {
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   212
        printk(KERN_ERR PFX "Failed to register tty device.\n");
1789
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   213
        return PTR_ERR(t->dev);
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   214
    }
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   215
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   216
    // Tell the device-specific implementation about the initial cflags
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   217
    tty = tty_driver->ttys[minor];
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   218
2518
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   219
    termios =
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   220
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   221
        &tty->termios
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   222
#else
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   223
        tty->termios
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   224
#endif
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   225
        ;
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   226
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   227
    if (tty && termios) { // already opened before
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   228
        cflag = termios->c_cflag;
1789
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   229
    } else {
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   230
        cflag = tty_driver->init_termios.c_cflag;
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   231
    }
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   232
    ret = t->ops.cflag_changed(t->cb_data, cflag);
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   233
    if (ret) {
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   234
        printk(KERN_ERR PFX "ERROR: Initial cflag 0x%x not accepted.\n",
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   235
                cflag);
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   236
        tty_unregister_device(tty_driver, t->minor);
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   237
        return ret;
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   238
    }
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   239
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   240
    t->timer.function = ec_tty_wakeup;
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   241
    t->timer.data = (unsigned long) t;
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   242
    t->timer.expires = jiffies + 10;
058248c47ba0 Pass initial cflag to device-specific implementation in constructor.
Florian Pose <fp@igh-essen.com>
parents: 1787
diff changeset
   243
    add_timer(&t->timer);
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   244
    return 0;
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   245
}
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   246
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   247
/*****************************************************************************/
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   248
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   249
void ec_tty_clear(ec_tty_t *tty)
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   250
{
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   251
    del_timer_sync(&tty->timer);
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   252
    tty_unregister_device(tty_driver, tty->minor);
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   253
}
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   254
1778
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   255
/*****************************************************************************/
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   256
1786
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   257
unsigned int ec_tty_tx_size(ec_tty_t *tty)
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   258
{
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   259
    unsigned int ret;
2384
b068951506d9 Removed whitespace.
Florian Pose <fp@igh-essen.com>
parents: 1975
diff changeset
   260
1786
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   261
    if (tty->tx_write_idx >= tty->tx_read_idx) {
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   262
        ret = tty->tx_write_idx - tty->tx_read_idx;
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   263
    } else {
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   264
        ret = EC_TTY_TX_BUFFER_SIZE + tty->tx_write_idx - tty->tx_read_idx;
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   265
    }
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   266
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   267
    return ret;
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   268
}
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   269
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   270
/*****************************************************************************/
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   271
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   272
unsigned int ec_tty_tx_space(ec_tty_t *tty)
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   273
{
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   274
    return EC_TTY_TX_BUFFER_SIZE - 1 - ec_tty_tx_size(tty);
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   275
}
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   276
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   277
/*****************************************************************************/
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   278
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   279
unsigned int ec_tty_rx_size(ec_tty_t *tty)
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   280
{
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   281
    unsigned int ret;
2384
b068951506d9 Removed whitespace.
Florian Pose <fp@igh-essen.com>
parents: 1975
diff changeset
   282
1786
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   283
    if (tty->rx_write_idx >= tty->rx_read_idx) {
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   284
        ret = tty->rx_write_idx - tty->rx_read_idx;
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   285
    } else {
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   286
        ret = EC_TTY_RX_BUFFER_SIZE + tty->rx_write_idx - tty->rx_read_idx;
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   287
    }
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   288
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   289
    return ret;
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   290
}
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   291
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   292
/*****************************************************************************/
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   293
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   294
unsigned int ec_tty_rx_space(ec_tty_t *tty)
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   295
{
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   296
    return EC_TTY_RX_BUFFER_SIZE - 1 - ec_tty_rx_size(tty);
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   297
}
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   298
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   299
/*****************************************************************************/
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   300
1778
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   301
int ec_tty_get_serial_info(ec_tty_t *tty, struct serial_struct *data)
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   302
{
1779
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   303
    struct serial_struct tmp;
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   304
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   305
    if (!data)
1778
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   306
        return -EFAULT;
1779
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   307
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   308
    memset(&tmp, 0, sizeof(tmp));
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   309
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   310
    if (copy_to_user(data, &tmp, sizeof(*data))) {
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   311
        return -EFAULT;
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   312
    }
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   313
    return 0;
1778
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   314
}
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   315
1786
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   316
/*****************************************************************************/
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   317
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   318
/** Timer function.
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   319
 */
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   320
void ec_tty_wakeup(unsigned long data)
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   321
{
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   322
    ec_tty_t *tty = (ec_tty_t *) data;
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   323
    size_t to_recv;
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   324
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   325
    /* Wake up any process waiting to send data */
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   326
    if (tty->wakeup) {
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   327
        if (tty->tty) {
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   328
#if EC_TTY_DEBUG >= 1
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   329
            printk(KERN_INFO PFX "Waking up.\n");
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   330
#endif
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   331
            tty_wakeup(tty->tty);
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   332
        }
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   333
        tty->wakeup = 0;
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   334
    }
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   335
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   336
    /* Push received data into TTY core. */
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   337
    to_recv = ec_tty_rx_size(tty);
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   338
    if (to_recv && tty->tty) {
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   339
        unsigned char *cbuf;
2661
39280d5a3321 Support changed tty_prepare_flip_string() interface from kernel 3.9.
Florian Pose <fp@igh-essen.com>
parents: 2518
diff changeset
   340
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
39280d5a3321 Support changed tty_prepare_flip_string() interface from kernel 3.9.
Florian Pose <fp@igh-essen.com>
parents: 2518
diff changeset
   341
        int space = tty_prepare_flip_string(tty->tty->port, &cbuf, to_recv);
39280d5a3321 Support changed tty_prepare_flip_string() interface from kernel 3.9.
Florian Pose <fp@igh-essen.com>
parents: 2518
diff changeset
   342
#else
1786
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   343
        int space = tty_prepare_flip_string(tty->tty, &cbuf, to_recv);
2661
39280d5a3321 Support changed tty_prepare_flip_string() interface from kernel 3.9.
Florian Pose <fp@igh-essen.com>
parents: 2518
diff changeset
   344
#endif
1786
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   345
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   346
        if (space < to_recv) {
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   347
            printk(KERN_WARNING PFX "Insufficient space to_recv=%d space=%d\n",
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   348
                    to_recv, space);
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   349
        }
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   350
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   351
        if (space < 0) {
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   352
            to_recv = 0;
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   353
        } else {
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   354
            to_recv = space;
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   355
        }
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   356
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   357
        if (to_recv) {
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   358
            unsigned int i;
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   359
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   360
#if EC_TTY_DEBUG >= 1
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   361
            printk(KERN_INFO PFX "Pushing %u bytes to TTY core.\n", to_recv);
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   362
#endif
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   363
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   364
            for (i = 0; i < to_recv; i++) {
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   365
                cbuf[i] = tty->rx_buffer[tty->rx_read_idx];
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   366
                tty->rx_read_idx =
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   367
                    (tty->rx_read_idx + 1) % EC_TTY_RX_BUFFER_SIZE;
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   368
            }
2661
39280d5a3321 Support changed tty_prepare_flip_string() interface from kernel 3.9.
Florian Pose <fp@igh-essen.com>
parents: 2518
diff changeset
   369
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
39280d5a3321 Support changed tty_prepare_flip_string() interface from kernel 3.9.
Florian Pose <fp@igh-essen.com>
parents: 2518
diff changeset
   370
            tty_flip_buffer_push(tty->tty->port);
39280d5a3321 Support changed tty_prepare_flip_string() interface from kernel 3.9.
Florian Pose <fp@igh-essen.com>
parents: 2518
diff changeset
   371
#else
1786
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   372
            tty_flip_buffer_push(tty->tty);
2661
39280d5a3321 Support changed tty_prepare_flip_string() interface from kernel 3.9.
Florian Pose <fp@igh-essen.com>
parents: 2518
diff changeset
   373
#endif
1786
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   374
        }
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   375
    }
2384
b068951506d9 Removed whitespace.
Florian Pose <fp@igh-essen.com>
parents: 1975
diff changeset
   376
1786
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   377
    tty->timer.expires += 1;
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   378
    add_timer(&tty->timer);
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   379
}
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   380
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   381
/******************************************************************************
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   382
 * Device callbacks
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   383
 *****************************************************************************/
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   384
1568
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   385
static int ec_tty_open(struct tty_struct *tty, struct file *file)
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   386
{
1571
88167b8589ef TTY open and close.
Florian Pose <fp@igh-essen.com>
parents: 1570
diff changeset
   387
    ec_tty_t *t;
1787
439f186185be Callback set via own structure.
Florian Pose <fp@igh-essen.com>
parents: 1786
diff changeset
   388
    int line = tty->index;
1571
88167b8589ef TTY open and close.
Florian Pose <fp@igh-essen.com>
parents: 1570
diff changeset
   389
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   390
#if EC_TTY_DEBUG >= 1
1797
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   391
    printk(KERN_INFO PFX "%s(tty=%p, file=%p): Opening line %i.\n",
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   392
            __func__, tty, file, line);
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   393
#endif
1571
88167b8589ef TTY open and close.
Florian Pose <fp@igh-essen.com>
parents: 1570
diff changeset
   394
1779
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   395
    if (line < 0 || line >= EC_TTY_MAX_DEVICES) {
1797
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   396
        tty->driver_data = NULL;
1779
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   397
        return -ENXIO;
1571
88167b8589ef TTY open and close.
Florian Pose <fp@igh-essen.com>
parents: 1570
diff changeset
   398
    }
88167b8589ef TTY open and close.
Florian Pose <fp@igh-essen.com>
parents: 1570
diff changeset
   399
88167b8589ef TTY open and close.
Florian Pose <fp@igh-essen.com>
parents: 1570
diff changeset
   400
    t = ttys[line];
88167b8589ef TTY open and close.
Florian Pose <fp@igh-essen.com>
parents: 1570
diff changeset
   401
    if (!t) {
1797
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   402
        tty->driver_data = NULL;
1571
88167b8589ef TTY open and close.
Florian Pose <fp@igh-essen.com>
parents: 1570
diff changeset
   403
        return -ENXIO;
88167b8589ef TTY open and close.
Florian Pose <fp@igh-essen.com>
parents: 1570
diff changeset
   404
    }
88167b8589ef TTY open and close.
Florian Pose <fp@igh-essen.com>
parents: 1570
diff changeset
   405
1797
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   406
    if (!t->tty) {
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   407
        t->tty = tty;
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   408
        tty->driver_data = t;
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   409
    }
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   410
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   411
    down(&t->sem);
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   412
    t->open_count++;
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   413
    up(&t->sem);
1571
88167b8589ef TTY open and close.
Florian Pose <fp@igh-essen.com>
parents: 1570
diff changeset
   414
    return 0;
1568
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   415
}
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   416
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   417
/*****************************************************************************/
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   418
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   419
static void ec_tty_close(struct tty_struct *tty, struct file *file)
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   420
{
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   421
    ec_tty_t *t = (ec_tty_t *) tty->driver_data;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   422
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   423
#if EC_TTY_DEBUG >= 1
1797
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   424
    printk(KERN_INFO PFX "%s(tty=%p, file=%p): Closing line %i.\n",
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   425
            __func__, tty, file, tty->index);
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   426
#endif
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   427
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   428
    if (t) {
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   429
        down(&t->sem);
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   430
        if (--t->open_count == 0) {
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   431
            t->tty = NULL;
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   432
        }
5bf740cd1599 Allow multiple open() calls to tty devices.
Florian Pose <fp@igh-essen.com>
parents: 1796
diff changeset
   433
        up(&t->sem);
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   434
    }
1568
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   435
}
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   436
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   437
/*****************************************************************************/
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   438
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   439
static int ec_tty_write(
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   440
        struct tty_struct *tty,
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   441
        const unsigned char *buffer,
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   442
        int count
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   443
        )
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   444
{
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   445
    ec_tty_t *t = (ec_tty_t *) tty->driver_data;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   446
    unsigned int data_size, i;
2384
b068951506d9 Removed whitespace.
Florian Pose <fp@igh-essen.com>
parents: 1975
diff changeset
   447
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   448
#if EC_TTY_DEBUG >= 1
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   449
    printk(KERN_INFO PFX "%s(count=%i)\n", __func__, count);
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   450
#endif
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   451
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   452
    if (count <= 0) {
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   453
        return 0;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   454
    }
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   455
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   456
    data_size = min(ec_tty_tx_space(t), (unsigned int) count);
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   457
    for (i = 0; i < data_size; i++) {
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   458
        t->tx_buffer[t->tx_write_idx] = buffer[i];
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   459
        t->tx_write_idx = (t->tx_write_idx + 1) % EC_TTY_TX_BUFFER_SIZE;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   460
    }
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   461
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   462
#if EC_TTY_DEBUG >= 1
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   463
    printk(KERN_INFO PFX "%s(): %u bytes written.\n", __func__, data_size);
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   464
#endif
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   465
    return data_size;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   466
}
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   467
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   468
/*****************************************************************************/
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   469
1595
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   470
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   471
static int ec_tty_put_char(struct tty_struct *tty, unsigned char ch)
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   472
#else
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   473
static void ec_tty_put_char(struct tty_struct *tty, unsigned char ch)
1595
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   474
#endif
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   475
{
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   476
    ec_tty_t *t = (ec_tty_t *) tty->driver_data;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   477
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   478
#if EC_TTY_DEBUG >= 1
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   479
    printk(KERN_INFO PFX "%s(): c=%02x.\n", __func__, (unsigned int) ch);
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   480
#endif
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   481
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   482
    if (ec_tty_tx_space(t)) {
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   483
        t->tx_buffer[t->tx_write_idx] = ch;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   484
        t->tx_write_idx = (t->tx_write_idx + 1) % EC_TTY_TX_BUFFER_SIZE;
1595
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   485
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   486
        return 1;
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   487
#endif
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   488
    } else {
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   489
        printk(KERN_WARNING PFX "%s(): Dropped a byte!\n", __func__);
1595
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   490
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   491
        return 0;
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   492
#endif
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   493
    }
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   494
}
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   495
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   496
/*****************************************************************************/
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   497
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   498
static int ec_tty_write_room(struct tty_struct *tty)
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   499
{
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   500
    ec_tty_t *t = (ec_tty_t *) tty->driver_data;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   501
    int ret = ec_tty_tx_space(t);
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2384
diff changeset
   502
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   503
#if EC_TTY_DEBUG >= 2
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   504
    printk(KERN_INFO PFX "%s() = %i.\n", __func__, ret);
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   505
#endif
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   506
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   507
    return ret;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   508
}
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   509
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   510
/*****************************************************************************/
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   511
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   512
static int ec_tty_chars_in_buffer(struct tty_struct *tty)
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   513
{
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   514
    ec_tty_t *t = (ec_tty_t *) tty->driver_data;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   515
    int ret;
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2384
diff changeset
   516
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   517
#if EC_TTY_DEBUG >= 2
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   518
    printk(KERN_INFO PFX "%s().\n", __func__);
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   519
#endif
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   520
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   521
    ret = ec_tty_tx_size(t);
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   522
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   523
#if EC_TTY_DEBUG >= 2
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   524
    printk(KERN_INFO PFX "%s() = %i.\n", __func__, ret);
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   525
#endif
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2384
diff changeset
   526
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   527
    return ret;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   528
}
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   529
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   530
/*****************************************************************************/
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   531
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   532
static void ec_tty_flush_buffer(struct tty_struct *tty)
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   533
{
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   534
#if EC_TTY_DEBUG >= 2
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   535
    printk(KERN_INFO PFX "%s().\n", __func__);
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   536
#endif
1796
3bb9ca8b58f2 Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1789
diff changeset
   537
3bb9ca8b58f2 Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1789
diff changeset
   538
    // FIXME empty ring buffer
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   539
}
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   540
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   541
/*****************************************************************************/
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   542
2517
b5214d8e48d1 TTY ioctl() file parameter was dropped in kernel 2.6.39.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   543
static int ec_tty_ioctl(struct tty_struct *tty,
b5214d8e48d1 TTY ioctl() file parameter was dropped in kernel 2.6.39.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   544
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39)
b5214d8e48d1 TTY ioctl() file parameter was dropped in kernel 2.6.39.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   545
        struct file *file,
b5214d8e48d1 TTY ioctl() file parameter was dropped in kernel 2.6.39.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   546
#endif
1779
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   547
        unsigned int cmd, unsigned long arg)
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   548
{
1778
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   549
    ec_tty_t *t = (ec_tty_t *) tty->driver_data;
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   550
    int ret = -ENOTTY;
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2384
diff changeset
   551
1778
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   552
#if EC_TTY_DEBUG >= 2
2517
b5214d8e48d1 TTY ioctl() file parameter was dropped in kernel 2.6.39.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   553
    printk(KERN_INFO PFX "%s(tty=%p, "
b5214d8e48d1 TTY ioctl() file parameter was dropped in kernel 2.6.39.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   554
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39)
b5214d8e48d1 TTY ioctl() file parameter was dropped in kernel 2.6.39.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   555
            "file=%p, "
b5214d8e48d1 TTY ioctl() file parameter was dropped in kernel 2.6.39.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   556
#endif
b5214d8e48d1 TTY ioctl() file parameter was dropped in kernel 2.6.39.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   557
            "cmd=%08x, arg=%08lx).\n",
b5214d8e48d1 TTY ioctl() file parameter was dropped in kernel 2.6.39.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   558
            __func__, tty,
b5214d8e48d1 TTY ioctl() file parameter was dropped in kernel 2.6.39.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   559
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39)
b5214d8e48d1 TTY ioctl() file parameter was dropped in kernel 2.6.39.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   560
            file,
b5214d8e48d1 TTY ioctl() file parameter was dropped in kernel 2.6.39.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   561
#endif
b5214d8e48d1 TTY ioctl() file parameter was dropped in kernel 2.6.39.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   562
            cmd, arg);
1778
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   563
    printk(KERN_INFO PFX "decoded: type=%02x nr=%u\n",
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   564
            _IOC_TYPE(cmd), _IOC_NR(cmd));
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   565
#endif
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   566
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   567
    switch (cmd) {
1779
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   568
        case TIOCGSERIAL:
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   569
            if (access_ok(VERIFY_WRITE,
1778
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   570
                        (void *) arg, sizeof(struct serial_struct))) {
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   571
                ret = ec_tty_get_serial_info(t, (struct serial_struct *) arg);
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   572
            } else {
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   573
                ret = -EFAULT;
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   574
            }
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   575
            break;
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   576
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   577
        default:
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   578
#if EC_TTY_DEBUG >= 2
1796
3bb9ca8b58f2 Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1789
diff changeset
   579
            printk(KERN_INFO PFX "no ioctl() -> handled by tty core!\n");
1778
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   580
#endif
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   581
            ret = -ENOIOCTLCMD;
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   582
            break;
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   583
    }
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   584
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   585
    return ret;
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   586
}
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   587
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   588
/*****************************************************************************/
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   589
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   590
static void ec_tty_set_termios(struct tty_struct *tty,
1779
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   591
        struct ktermios *old_termios)
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   592
{
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   593
    ec_tty_t *t = (ec_tty_t *) tty->driver_data;
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   594
    int ret;
2518
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   595
    struct ktermios *termios;
1778
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   596
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   597
#if EC_TTY_DEBUG >= 2
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   598
    printk(KERN_INFO PFX "%s().\n", __func__);
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   599
#endif
1778
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   600
2518
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   601
    termios =
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   602
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   603
        &tty->termios
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   604
#else
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   605
        tty->termios
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   606
#endif
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   607
        ;
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   608
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   609
    if (termios->c_cflag == old_termios->c_cflag)
1778
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   610
        return;
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   611
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   612
#if EC_TTY_DEBUG >= 2
94dbb44884ec Basic configuration for tty.
Florian Pose <fp@igh-essen.com>
parents: 1595
diff changeset
   613
    printk(KERN_INFO "cflag changed from %x to %x.\n",
2518
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   614
            old_termios->c_cflag, termios->c_cflag);
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   615
#endif
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   616
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   617
    ret = t->ops.cflag_changed(t->cb_data, termios->c_cflag);
1779
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   618
    if (ret) {
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   619
        printk(KERN_ERR PFX "ERROR: cflag 0x%x not accepted.\n",
2518
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   620
                termios->c_cflag);
e5640f5e10a2 TTY: termios structure was included in 'struct tty' with kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents: 2517
diff changeset
   621
        termios->c_cflag = old_termios->c_cflag;
1779
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   622
    }
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   623
}
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   624
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   625
/*****************************************************************************/
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   626
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   627
static void ec_tty_stop(struct tty_struct *tty)
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   628
{
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   629
#if EC_TTY_DEBUG >= 2
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   630
    printk(KERN_INFO PFX "%s().\n", __func__);
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   631
#endif
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   632
}
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   633
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   634
/*****************************************************************************/
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   635
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   636
static void ec_tty_start(struct tty_struct *tty)
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   637
{
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   638
#if EC_TTY_DEBUG >= 2
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   639
    printk(KERN_INFO PFX "%s().\n", __func__);
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   640
#endif
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   641
}
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   642
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   643
/*****************************************************************************/
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   644
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   645
static void ec_tty_hangup(struct tty_struct *tty)
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   646
{
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   647
#if EC_TTY_DEBUG >= 2
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   648
    printk(KERN_INFO PFX "%s().\n", __func__);
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   649
#endif
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   650
}
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   651
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   652
/*****************************************************************************/
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   653
1595
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   654
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   655
static int ec_tty_break(struct tty_struct *tty, int break_state)
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   656
#else
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   657
static void ec_tty_break(struct tty_struct *tty, int break_state)
1595
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   658
#endif
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   659
{
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   660
#if EC_TTY_DEBUG >= 2
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   661
    printk(KERN_INFO PFX "%s(break_state = %i).\n", __func__, break_state);
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   662
#endif
1595
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   663
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   664
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   665
    return -EIO; // not implemented
8d8657654921 Implemented tty put_char and break_ctl callbacks for kernels newer than 2.6.26
Florian Pose <fp@igh-essen.com>
parents: 1577
diff changeset
   666
#endif
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   667
}
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   668
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   669
/*****************************************************************************/
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   670
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   671
static void ec_tty_send_xchar(struct tty_struct *tty, char ch)
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   672
{
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   673
#if EC_TTY_DEBUG >= 2
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   674
    printk(KERN_INFO PFX "%s(ch=%02x).\n", __func__, (unsigned int) ch);
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   675
#endif
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   676
}
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   677
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   678
/*****************************************************************************/
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   679
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   680
static void ec_tty_wait_until_sent(struct tty_struct *tty, int timeout)
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   681
{
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   682
#if EC_TTY_DEBUG >= 2
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   683
    printk(KERN_INFO PFX "%s(timeout=%i).\n", __func__, timeout);
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   684
#endif
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   685
}
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   686
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   687
/*****************************************************************************/
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   688
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   689
static const struct tty_operations ec_tty_ops = {
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   690
    .open = ec_tty_open,
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   691
    .close = ec_tty_close,
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   692
    .write = ec_tty_write,
1779
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   693
    .put_char = ec_tty_put_char,
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   694
    .write_room = ec_tty_write_room,
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   695
    .chars_in_buffer = ec_tty_chars_in_buffer,
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   696
    .flush_buffer = ec_tty_flush_buffer,
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   697
    .ioctl = ec_tty_ioctl,
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   698
    .set_termios = ec_tty_set_termios,
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   699
    .stop = ec_tty_stop,
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   700
    .start = ec_tty_start,
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   701
    .hangup = ec_tty_hangup,
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   702
    .break_ctl = ec_tty_break,
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   703
    .send_xchar = ec_tty_send_xchar,
9fab229d6ca9 Passing tty cflag to serial implementation.
Florian Pose <fp@igh-essen.com>
parents: 1778
diff changeset
   704
    .wait_until_sent = ec_tty_wait_until_sent,
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   705
};
1568
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   706
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   707
/******************************************************************************
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   708
 * Public functions and methods
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   709
 *****************************************************************************/
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   710
1787
439f186185be Callback set via own structure.
Florian Pose <fp@igh-essen.com>
parents: 1786
diff changeset
   711
ec_tty_t *ectty_create(const ec_tty_operations_t *ops, void *cb_data)
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   712
{
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   713
    ec_tty_t *tty;
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   714
    int minor, ret;
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   715
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   716
    if (down_interruptible(&tty_sem)) {
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   717
        return ERR_PTR(-EINTR);
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   718
    }
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   719
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   720
    for (minor = 0; minor < EC_TTY_MAX_DEVICES; minor++) {
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   721
        if (!ttys[minor]) {
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   722
            printk(KERN_INFO PFX "Creating TTY interface %i.\n", minor);
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   723
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   724
            tty = kmalloc(sizeof(ec_tty_t), GFP_KERNEL);
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   725
            if (!tty) {
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   726
                up(&tty_sem);
1570
7a2a58107dd8 Use own PFX for printk.
Florian Pose <fp@igh-essen.com>
parents: 1569
diff changeset
   727
                printk(KERN_ERR PFX "Failed to allocate memory.\n");
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   728
                return ERR_PTR(-ENOMEM);
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   729
            }
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   730
1787
439f186185be Callback set via own structure.
Florian Pose <fp@igh-essen.com>
parents: 1786
diff changeset
   731
            ret = ec_tty_init(tty, minor, ops, cb_data);
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   732
            if (ret) {
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   733
                up(&tty_sem);
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   734
                kfree(tty);
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   735
                return ERR_PTR(ret);
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   736
            }
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   737
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   738
            ttys[minor] = tty;
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   739
            up(&tty_sem);
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   740
            return tty;
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   741
        }
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   742
    }
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   743
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   744
    up(&tty_sem);
1570
7a2a58107dd8 Use own PFX for printk.
Florian Pose <fp@igh-essen.com>
parents: 1569
diff changeset
   745
    printk(KERN_ERR PFX "No free interfaces avaliable.\n");
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   746
    return ERR_PTR(-EBUSY);
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   747
}
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   748
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   749
/*****************************************************************************/
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   750
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   751
void ectty_free(ec_tty_t *tty)
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   752
{
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   753
    printk(KERN_INFO PFX "Freeing TTY interface %i.\n", tty->minor);
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   754
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   755
    ec_tty_clear(tty);
1570
7a2a58107dd8 Use own PFX for printk.
Florian Pose <fp@igh-essen.com>
parents: 1569
diff changeset
   756
    ttys[tty->minor] = NULL;
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   757
    kfree(tty);
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   758
}
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   759
1568
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   760
/*****************************************************************************/
d9bbbe1883ab Register a TTY driver with one device.
Florian Pose <fp@igh-essen.com>
parents: 1565
diff changeset
   761
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   762
unsigned int ectty_tx_data(ec_tty_t *tty, uint8_t *buffer, size_t size)
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   763
{
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   764
    unsigned int data_size = min(ec_tty_tx_size(tty), size), i;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   765
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   766
    if (data_size)  {
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   767
#if EC_TTY_DEBUG >= 1
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   768
        printk(KERN_INFO PFX "Fetching %u bytes to send.\n", data_size);
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   769
#endif
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   770
    }
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   771
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   772
    for (i = 0; i < data_size; i++) {
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   773
        buffer[i] = tty->tx_buffer[tty->tx_read_idx];
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   774
        tty->tx_read_idx = (tty->tx_read_idx + 1) % EC_TTY_TX_BUFFER_SIZE;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   775
    }
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   776
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   777
    if (data_size) {
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   778
        tty->wakeup = 1;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   779
    }
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   780
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   781
    return data_size;
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   782
}
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   783
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   784
/*****************************************************************************/
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   785
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   786
void ectty_rx_data(ec_tty_t *tty, const uint8_t *buffer, size_t size)
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   787
{
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   788
    size_t to_recv;
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   789
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   790
    if (size)  {
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   791
        unsigned int i;
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   792
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   793
#if EC_TTY_DEBUG >= 1
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   794
        printk(KERN_INFO PFX "Received %u bytes.\n", size);
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   795
#endif
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   796
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   797
        to_recv = min(ec_tty_rx_space(tty), size);
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   798
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   799
        if (to_recv < size) {
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   800
            printk(KERN_WARNING PFX "Dropping %u bytes.\n", size - to_recv);
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   801
        }
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   802
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   803
        for (i = 0; i < size; i++) {
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   804
            tty->rx_buffer[tty->rx_write_idx] = buffer[i];
1786
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   805
            tty->rx_write_idx =
7198caede741 Sorted methods.
Florian Pose <fp@igh-essen.com>
parents: 1782
diff changeset
   806
                (tty->rx_write_idx + 1) % EC_TTY_RX_BUFFER_SIZE;
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   807
        }
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   808
    }
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   809
}
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   810
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   811
/*****************************************************************************/
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   812
1565
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   813
/** \cond */
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   814
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   815
module_init(ec_tty_init_module);
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   816
module_exit(ec_tty_cleanup_module);
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   817
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   818
EXPORT_SYMBOL(ectty_create);
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   819
EXPORT_SYMBOL(ectty_free);
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1572
diff changeset
   820
EXPORT_SYMBOL(ectty_tx_data);
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   821
EXPORT_SYMBOL(ectty_rx_data);
1569
61f5f4c35883 Interface management.
Florian Pose <fp@igh-essen.com>
parents: 1568
diff changeset
   822
1565
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   823
/** \endcond */
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   824
8c526cfe1399 Base files for new TTY driver.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   825
/*****************************************************************************/