examples/tty/serial.c
author Martin Troxler <ch1010277@ch10lt194>
Tue, 19 Jan 2010 19:33:47 +0100
changeset 1777 a93fc03eeb06
parent 1615 020ad9ad3afb
child 1779 9fab229d6ca9
permissions -rw-r--r--
Merged
1613
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  published by the Free Software Foundation.
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  Public License for more details.
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *  ---
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *****************************************************************************/
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#include <linux/module.h>
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#include <linux/err.h>
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include "../../include/ecrt.h" // EtherCAT realtime interface
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include "../../include/ectty.h" // EtherCAT TTY interface
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
/*****************************************************************************/
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
// Optional features
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#define PFX "ec_tty_example: "
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
/*****************************************************************************/
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#define VendorIdBeckhoff 0x00000002
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#define ProductCodeBeckhoffEL6002 0x17723052
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
#define Beckhoff_EL6002 VendorIdBeckhoff, ProductCodeBeckhoffEL6002
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
typedef enum {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
    SER_REQUEST_INIT,
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
    SER_WAIT_FOR_INIT_RESPONSE,
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
    SER_READY
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
} serial_state_t;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
typedef struct {
1615
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
    54
    struct list_head list;
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
    55
1613
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
    ec_tty_t *tty;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
    ec_slave_config_t *sc;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
    size_t max_tx_data_size;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
    size_t max_rx_data_size;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
    u8 *tx_data;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
    u8 tx_data_size;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
    serial_state_t state;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    u8 tx_request_toggle;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    u8 tx_accepted_toggle;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    u8 rx_request_toggle;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
    u8 rx_accepted_toggle;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
    u16 control;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
    u32 off_ctrl;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
    u32 off_tx;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
    u32 off_status;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
    u32 off_rx;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
} el6002_t;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
1615
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
    81
LIST_HEAD(handlers);
1613
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
        
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
/*****************************************************************************/
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
/* Beckhoff EL6002
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
 * Vendor ID:       0x00000002
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
 * Product code:    0x17723052
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
 * Revision number: 0x00100000
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
ec_pdo_entry_info_t el6002_pdo_entries[] = {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
   {0x7001, 0x01, 16}, /* Ctrl */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
   {0x7000, 0x11, 8}, /* Data Out 0 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
   {0x7000, 0x12, 8}, /* Data Out 1 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
   {0x7000, 0x13, 8}, /* Data Out 2 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
   {0x7000, 0x14, 8}, /* Data Out 3 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
   {0x7000, 0x15, 8}, /* Data Out 4 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
   {0x7000, 0x16, 8}, /* Data Out 5 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
   {0x7000, 0x17, 8}, /* Data Out 6 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
   {0x7000, 0x18, 8}, /* Data Out 7 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
   {0x7000, 0x19, 8}, /* Data Out 8 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
   {0x7000, 0x1a, 8}, /* Data Out 9 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
   {0x7000, 0x1b, 8}, /* Data Out 10 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
   {0x7000, 0x1c, 8}, /* Data Out 11 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
   {0x7000, 0x1d, 8}, /* Data Out 12 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
   {0x7000, 0x1e, 8}, /* Data Out 13 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
   {0x7000, 0x1f, 8}, /* Data Out 14 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
   {0x7000, 0x20, 8}, /* Data Out 15 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
   {0x7000, 0x21, 8}, /* Data Out 16 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
   {0x7000, 0x22, 8}, /* Data Out 17 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
   {0x7000, 0x23, 8}, /* Data Out 18 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
   {0x7000, 0x24, 8}, /* Data Out 19 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
   {0x7000, 0x25, 8}, /* Data Out 20 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
   {0x7000, 0x26, 8}, /* Data Out 21 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
   {0x7011, 0x01, 16}, /* Ctrl */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
   {0x7010, 0x11, 8}, /* Data Out 0 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
   {0x7010, 0x12, 8}, /* Data Out 1 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
   {0x7010, 0x13, 8}, /* Data Out 2 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
   {0x7010, 0x14, 8}, /* Data Out 3 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
   {0x7010, 0x15, 8}, /* Data Out 4 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
   {0x7010, 0x16, 8}, /* Data Out 5 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
   {0x7010, 0x17, 8}, /* Data Out 6 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
   {0x7010, 0x18, 8}, /* Data Out 7 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
   {0x7010, 0x19, 8}, /* Data Out 8 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
   {0x7010, 0x1a, 8}, /* Data Out 9 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
   {0x7010, 0x1b, 8}, /* Data Out 10 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
   {0x7010, 0x1c, 8}, /* Data Out 11 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
   {0x7010, 0x1d, 8}, /* Data Out 12 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
   {0x7010, 0x1e, 8}, /* Data Out 13 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
   {0x7010, 0x1f, 8}, /* Data Out 14 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
   {0x7010, 0x20, 8}, /* Data Out 15 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
   {0x7010, 0x21, 8}, /* Data Out 16 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
   {0x7010, 0x22, 8}, /* Data Out 17 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
   {0x7010, 0x23, 8}, /* Data Out 18 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
   {0x7010, 0x24, 8}, /* Data Out 19 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
   {0x7010, 0x25, 8}, /* Data Out 20 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
   {0x7010, 0x26, 8}, /* Data Out 21 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
   {0x6001, 0x01, 16}, /* Status */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
   {0x6000, 0x11, 8}, /* Data In 0 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
   {0x6000, 0x12, 8}, /* Data In 1 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
   {0x6000, 0x13, 8}, /* Data In 2 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
   {0x6000, 0x14, 8}, /* Data In 3 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
   {0x6000, 0x15, 8}, /* Data In 4 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
   {0x6000, 0x16, 8}, /* Data In 5 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
   {0x6000, 0x17, 8}, /* Data In 6 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
   {0x6000, 0x18, 8}, /* Data In 7 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
   {0x6000, 0x19, 8}, /* Data In 8 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
   {0x6000, 0x1a, 8}, /* Data In 9 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
   {0x6000, 0x1b, 8}, /* Data In 10 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
   {0x6000, 0x1c, 8}, /* Data In 11 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
   {0x6000, 0x1d, 8}, /* Data In 12 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
   {0x6000, 0x1e, 8}, /* Data In 13 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
   {0x6000, 0x1f, 8}, /* Data In 14 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
   {0x6000, 0x20, 8}, /* Data In 15 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
   {0x6000, 0x21, 8}, /* Data In 16 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
   {0x6000, 0x22, 8}, /* Data In 17 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
   {0x6000, 0x23, 8}, /* Data In 18 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
   {0x6000, 0x24, 8}, /* Data In 19 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
   {0x6000, 0x25, 8}, /* Data In 20 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
   {0x6000, 0x26, 8}, /* Data In 21 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
   {0x6011, 0x01, 16}, /* Status */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
   {0x6010, 0x11, 8}, /* Data In 0 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
   {0x6010, 0x12, 8}, /* Data In 1 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
   {0x6010, 0x13, 8}, /* Data In 2 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
   {0x6010, 0x14, 8}, /* Data In 3 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
   {0x6010, 0x15, 8}, /* Data In 4 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
   {0x6010, 0x16, 8}, /* Data In 5 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
   {0x6010, 0x17, 8}, /* Data In 6 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
   {0x6010, 0x18, 8}, /* Data In 7 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
   {0x6010, 0x19, 8}, /* Data In 8 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
   {0x6010, 0x1a, 8}, /* Data In 9 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
   {0x6010, 0x1b, 8}, /* Data In 10 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
   {0x6010, 0x1c, 8}, /* Data In 11 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
   {0x6010, 0x1d, 8}, /* Data In 12 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
   {0x6010, 0x1e, 8}, /* Data In 13 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
   {0x6010, 0x1f, 8}, /* Data In 14 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
   {0x6010, 0x20, 8}, /* Data In 15 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
   {0x6010, 0x21, 8}, /* Data In 16 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
   {0x6010, 0x22, 8}, /* Data In 17 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
   {0x6010, 0x23, 8}, /* Data In 18 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
   {0x6010, 0x24, 8}, /* Data In 19 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
   {0x6010, 0x25, 8}, /* Data In 20 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
   {0x6010, 0x26, 8}, /* Data In 21 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
};
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
ec_pdo_info_t el6002_pdos[] = {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
   {0x1604, 23, el6002_pdo_entries + 0}, /* COM RxPDO-Map Outputs Ch.1 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
   {0x1605, 23, el6002_pdo_entries + 23}, /* COM RxPDO-Map Outputs Ch.2 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
   {0x1a04, 23, el6002_pdo_entries + 46}, /* COM TxPDO-Map Inputs Ch.1 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
   {0x1a05, 23, el6002_pdo_entries + 69}, /* COM TxPDO-Map Inputs Ch.2 */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
};
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
ec_sync_info_t el6002_syncs[] = {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
   {0, EC_DIR_OUTPUT, 0, NULL, EC_WD_DISABLE},
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
   {1, EC_DIR_INPUT, 0, NULL, EC_WD_DISABLE},
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
   {2, EC_DIR_OUTPUT, 2, el6002_pdos + 0, EC_WD_DISABLE},
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
   {3, EC_DIR_INPUT, 2, el6002_pdos + 2, EC_WD_DISABLE},
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
   {0xff}
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
};
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
/****************************************************************************/
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
int el6002_init(el6002_t *ser, ec_master_t *master, u16 position,
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
        ec_domain_t *domain)
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
{
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
    int ret = 0;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
    ser->tty = ectty_create();
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
    if (IS_ERR(ser->tty)) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
        printk(KERN_ERR PFX "Failed to create tty.\n");
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
        ret = PTR_ERR(ser->tty);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
        goto out_return;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
    }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
    ser->sc = NULL;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
    ser->max_tx_data_size = 22;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
    ser->max_rx_data_size = 22;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
    ser->tx_data = NULL;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
    ser->tx_data_size = 0;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
    ser->state = SER_REQUEST_INIT;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
    ser->tx_request_toggle = 0;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
    ser->rx_accepted_toggle = 0;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
    ser->control = 0x0000;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
    ser->off_ctrl = 0;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
    ser->off_tx = 0;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
    ser->off_status = 0;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
    ser->off_rx = 0;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
    if (!(ser->sc = ecrt_master_slave_config(
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
                    master, 0, position, Beckhoff_EL6002))) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
        printk(KERN_ERR PFX "Failed to create slave configuration.\n");
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
        ret = -EBUSY;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
        goto out_free_tty;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
    }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
    if (ecrt_slave_config_pdos(ser->sc, EC_END, el6002_syncs)) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
        printk(KERN_ERR PFX "Failed to configure PDOs.\n");
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
        ret = -ENOMEM;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
        goto out_free_tty;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
    }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
    
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
    ret = ecrt_slave_config_reg_pdo_entry(
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
            ser->sc, 0x7001, 0x01, domain, NULL);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
    if (ret < 0) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
        printk(KERN_ERR PFX "Failed to register PDO entry.\n");
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
        goto out_free_tty;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
    }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
    ser->off_ctrl = ret;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
    ret = ecrt_slave_config_reg_pdo_entry(
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
            ser->sc, 0x7000, 0x11, domain, NULL);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
    if (ret < 0) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
        printk(KERN_ERR PFX "Failed to register PDO entry.\n");
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
        goto out_free_tty;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
    }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
    ser->off_tx = ret;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
    ret = ecrt_slave_config_reg_pdo_entry(
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
            ser->sc, 0x6001, 0x01, domain, NULL);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
    if (ret < 0) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
        printk(KERN_ERR PFX "Failed to register PDO entry.\n");
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
        goto out_free_tty;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
    }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
    ser->off_status = ret;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
    ret = ecrt_slave_config_reg_pdo_entry(
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
            ser->sc, 0x6000, 0x11, domain, NULL);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
    if (ret < 0) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
        printk(KERN_ERR PFX "Failed to register PDO entry.\n");
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
        goto out_free_tty;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
    }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
    ser->off_rx = ret;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
    if (ser->max_tx_data_size > 0) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
        ser->tx_data = kmalloc(ser->max_tx_data_size, GFP_KERNEL);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
        if (ser->tx_data == NULL) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
            ret = -ENOMEM;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
            goto out_free_tty;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
        }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
    }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
    return 0;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
out_free_tty:
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
    ectty_free(ser->tty);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   286
out_return:
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   287
    return ret;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
}
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
/****************************************************************************/
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   291
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
void el6002_clear(el6002_t *ser)
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
{
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   294
    ectty_free(ser->tty);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   295
    if (ser->tx_data) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
        kfree(ser->tx_data);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   297
    }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
}
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
/****************************************************************************/
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   301
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   302
void el6002_run(el6002_t *ser, u8 *pd)
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   303
{
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   304
    u16 status = EC_READ_U16(pd + ser->off_status);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   305
    u8 *rx_data = pd + ser->off_rx;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   306
    uint8_t tx_accepted_toggle, rx_request_toggle;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   307
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
    switch (ser->state) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   309
        case SER_READY:
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   310
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
            /* Send data */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
            
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   313
            tx_accepted_toggle = status & 0x0001;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   314
            if (tx_accepted_toggle != ser->tx_accepted_toggle) { // ready
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   315
                ser->tx_data_size =
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   316
                    ectty_tx_data(ser->tty, ser->tx_data, ser->max_tx_data_size);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
                if (ser->tx_data_size) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
                    printk(KERN_INFO PFX "Sending %u bytes.\n", ser->tx_data_size);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
                    ser->tx_request_toggle = !ser->tx_request_toggle;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   320
                    ser->tx_accepted_toggle = tx_accepted_toggle;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   321
                }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   322
            }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   323
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   324
            /* Receive data */
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   326
            rx_request_toggle = status & 0x0002;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   327
            if (rx_request_toggle != ser->rx_request_toggle) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   328
                uint8_t rx_data_size = status >> 8;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   329
                ser->rx_request_toggle = rx_request_toggle;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   330
                printk(KERN_INFO PFX "Received %u bytes.\n", rx_data_size);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   331
                ectty_rx_data(ser->tty, rx_data, rx_data_size);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   332
                ser->rx_accepted_toggle = !ser->rx_accepted_toggle;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   333
            }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   334
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   335
            ser->control =
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   336
                ser->tx_request_toggle |
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   337
                ser->rx_accepted_toggle << 1 |
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   338
                ser->tx_data_size << 8;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   339
            break;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   340
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   341
        case SER_REQUEST_INIT:
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   342
            if (status & (1 << 2)) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   343
                ser->control = 0x0000;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   344
                ser->state = SER_WAIT_FOR_INIT_RESPONSE;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   345
            } else {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   346
                ser->control = 1 << 2; // CW.2, request initialization
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   347
            }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   348
            break;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   349
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   350
        case SER_WAIT_FOR_INIT_RESPONSE:
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   351
            if (!(status & (1 << 2))) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   352
                printk(KERN_INFO PFX "Init successful.\n");
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   353
                ser->tx_accepted_toggle = 1;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   354
                ser->control = 0x0000;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   355
                ser->state = SER_READY;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   356
            }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   357
            break;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   358
    }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   359
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   360
    EC_WRITE_U16(pd + ser->off_ctrl, ser->control);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   361
    memcpy(pd + ser->off_tx, ser->tx_data, ser->tx_data_size);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   362
}
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   363
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   364
/*****************************************************************************/
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   365
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   366
void run_serial_devices(u8 *pd)
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   367
{
1615
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   368
    el6002_t *ser;
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   369
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   370
    list_for_each_entry(ser, &handlers, list) {
1613
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   371
        el6002_run(ser, pd);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   372
    }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   373
}
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   374
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   375
/*****************************************************************************/
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   376
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   377
int create_serial_devices(ec_master_t *master, ec_domain_t *domain)
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   378
{
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   379
    int i, ret;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   380
    ec_master_info_t master_info;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   381
    ec_slave_info_t slave_info;
1615
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   382
    el6002_t *ser, *next;
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   383
1613
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   384
    printk(KERN_INFO PFX "Registering serial devices...\n");
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   385
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   386
    ret = ecrt_master(master, &master_info);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   387
    if (ret) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   388
        printk(KERN_ERR PFX "Failed to obtain master information.\n");
1615
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   389
        goto out_return;
1613
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   390
    }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   391
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   392
    for (i = 0; i < master_info.slave_count; i++) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   393
        ret = ecrt_master_get_slave(master, i, &slave_info);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   394
        if (ret) {
1615
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   395
            printk(KERN_ERR PFX "Failed to obtain slave information.\n");
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   396
            goto out_free_handlers;
1613
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   397
        }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   398
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   399
        if (slave_info.vendor_id != VendorIdBeckhoff
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   400
                || slave_info.product_code != ProductCodeBeckhoffEL6002) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   401
            continue;
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   402
        }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   403
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   404
        printk(KERN_INFO PFX "Creating handler for serial device"
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   405
                " at position %i\n", i);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   406
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   407
        ser = kmalloc(sizeof(*ser), GFP_KERNEL);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   408
        if (!ser) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   409
            printk(KERN_ERR PFX "Failed to allocate serial device object.\n");
1615
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   410
            ret = -ENOMEM;
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   411
            goto out_free_handlers;
1613
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   412
        }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   413
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   414
        ret = el6002_init(ser, master, i, domain);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   415
        if (ret) {
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   416
            printk(KERN_ERR PFX "Failed to init serial device object.\n");
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   417
            kfree(ser);
1615
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   418
            goto out_free_handlers;
1613
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   419
        }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   420
1615
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   421
        list_add_tail(&ser->list, &handlers);
1613
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   422
    }
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   423
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   424
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   425
    printk(KERN_INFO PFX "Finished.\n");
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   426
    return 0;
1615
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   427
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   428
out_free_handlers:
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   429
    list_for_each_entry_safe(ser, next, &handlers, list) {
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   430
        list_del(&ser->list);
1613
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   431
        el6002_clear(ser);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   432
        kfree(ser);
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   433
    }
1615
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   434
out_return:
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   435
    return ret;
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   436
}
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   437
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   438
/*****************************************************************************/
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   439
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   440
void free_serial_devices(void)
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   441
{
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   442
    el6002_t *ser, *next;
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   443
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   444
    printk(KERN_INFO PFX "Cleaning up serial devices...\n");
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   445
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   446
    list_for_each_entry_safe(ser, next, &handlers, list) {
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   447
        list_del(&ser->list);
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   448
        el6002_clear(ser);
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   449
        kfree(ser);
020ad9ad3afb TTY example: Auto-create multiple handlers.
Florian Pose <fp@igh-essen.com>
parents: 1614
diff changeset
   450
    }
1613
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   451
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   452
    printk(KERN_INFO PFX "Finished cleaning up serial devices.\n");
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   453
}
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   454
070b4b420ab1 TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   455
/*****************************************************************************/