Add support up to 2.6.31
[bcu1driver.git] / eib-common.h
blob2fc6f4a0e6819d14f0b31822c210f373e407b082
1 /*
2 EIB driver core
4 Copyright (C) 2005-2008 Martin Koegler <mkoegler@auto.tuwien.ac.at>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 enum eib_reason
23 EIB_INT_DATA,
24 EIB_INT_MSR,
25 EIB_TIME_RESET,
26 EIB_TIME_SEND,
27 EIB_TIME_WRITE,
28 EIB_OTHER,
29 EIB_NONE
32 typedef void (*eib_handler_t) (void *data, enum eib_reason reason);
34 struct eib_lowlevel;
35 typedef struct eib_lowlevel eib_lowlevel;
37 typedef struct _eib_port
39 void (*setRTS) (eib_lowlevel * dev);
40 void (*clrRTS) (eib_lowlevel * dev);
41 int (*getCTS) (eib_lowlevel * dev);
42 void (*send) (eib_lowlevel * dev, uint8_t val);
43 int (*recv) (eib_lowlevel * dev);
44 void (*open_port) (eib_lowlevel * dev);
45 void (*close_port) (eib_lowlevel * dev);
46 enum eib_reason (*getserialint) (eib_lowlevel * dev);
47 int (*send_finished) (eib_lowlevel * dev);
48 int (*overrun) (eib_lowlevel * dev);
49 void (*free_serial) (eib_lowlevel * dev);
50 struct module *owner;
51 } eib_port;
53 typedef eib_lowlevel *(*eib_create_serial_t) (struct device * dev,
54 const char *name,
55 eib_handler_t handler,
56 void *data);
59 int eib_port_register (struct device *dev, eib_create_serial_t create,
60 eib_port * ops);
61 void eib_port_unregister (struct device *dev);
62 void eib_port_free (struct device *dev);
64 eib_lowlevel *eib_port_create (int minor, const char *name,
65 eib_handler_t handler, void *data,
66 eib_port ** ops);
68 #define EIB_MAX_READ_BUFFER 20
69 #define EIB_MAX_WRITE_BUFFER 5
71 typedef unsigned char eib_buffer[64];
73 struct eib_protocol_data;
74 struct eib_chardev;
75 typedef struct eib_protocol_data eib_protocol_data;
76 typedef struct eib_chardev eib_chardev;
77 typedef struct
79 int (*write_prepare) (eib_protocol_data * proto, eib_buffer buf, int len);
80 void (*write_start) (eib_protocol_data * proto);
81 int (*ioctl) (eib_protocol_data * proto, unsigned int cmd,
82 unsigned long arg);
83 void (*shutdown) (eib_protocol_data *);
84 void (*free) (eib_protocol_data *);
85 eib_protocol_data *(*create) (int minor, eib_chardev * cdev);
86 struct module *owner;
87 } eib_protocol_ops;
89 struct eib_chardev
91 wait_queue_head_t read_queue;
92 int read_head, read_free, read_next;
93 eib_buffer read_buffer[EIB_MAX_READ_BUFFER];
94 spinlock_t read_lock;
96 wait_queue_head_t write_queue;
97 int write_head, write_free, write_next;
98 eib_buffer write_buffer[EIB_MAX_WRITE_BUFFER];
99 signed char write_result[EIB_MAX_WRITE_BUFFER];
100 spinlock_t write_lock;
102 struct fasync_struct *async;
104 eib_protocol_data *data;
105 eib_protocol_ops *ops;
108 static inline int
109 eib_readbuffer_full (eib_chardev * cdev)
111 if ((cdev->read_free + 1) % EIB_MAX_READ_BUFFER == cdev->read_head)
112 return 1;
113 else
114 return 0;
117 static inline int
118 eib_writebuffer_empty (eib_chardev * cdev)
120 if (cdev->write_head == cdev->write_next)
121 return 1;
122 else
123 return 0;
126 static inline unsigned char *
127 eib_readbuffer (eib_chardev * cdev)
129 return cdev->read_buffer[cdev->read_free];
132 static inline unsigned char *
133 eib_writebuffer (eib_chardev * cdev)
135 return cdev->write_buffer[cdev->write_head];
138 static inline void
139 eib_writebuffer_clear (eib_chardev * cdev)
141 spin_lock (&cdev->write_lock);
143 cdev->write_head = cdev->write_free;
144 spin_unlock (&cdev->write_lock);
146 wake_up_interruptible_all (&cdev->write_queue);
149 static inline void
150 eib_readbuffer_clear (eib_chardev * cdev)
152 spin_lock (&cdev->read_lock);
154 cdev->read_free = cdev->read_next;
155 spin_unlock (&cdev->read_lock);
157 wake_up_interruptible_all (&cdev->read_queue);
160 static inline void
161 eib_read_notify (eib_chardev * cdev)
163 cdev->read_free = (cdev->read_free + 1) % EIB_MAX_READ_BUFFER;
164 wake_up_interruptible_all (&cdev->read_queue);
165 if (cdev->async)
166 kill_fasync (&cdev->async, SIGIO, POLL_IN);
169 static inline void
170 eib_write_finish (eib_chardev * cdev, signed char result)
172 cdev->write_result[cdev->write_head] = result;
173 cdev->write_head = (cdev->write_head + 1) % EIB_MAX_WRITE_BUFFER;
174 wake_up_interruptible_all (&cdev->write_queue);
177 int eib_driver_register (const char *name, int major,
178 eib_protocol_ops * fops);
179 void eib_driver_unregister (const char *name);