49 |
49 |
50 /*****************************************************************************/ |
50 /*****************************************************************************/ |
51 |
51 |
52 #define PFX "ec_tty: " |
52 #define PFX "ec_tty: " |
53 |
53 |
54 #define EC_TTY_MAX_DEVICES 10 |
54 #define EC_TTY_MAX_DEVICES 32 |
55 #define EC_TTY_TX_BUFFER_SIZE 100 |
55 #define EC_TTY_TX_BUFFER_SIZE 100 |
56 #define EC_TTY_RX_BUFFER_SIZE 100 |
56 #define EC_TTY_RX_BUFFER_SIZE 100 |
57 |
57 |
58 #define EC_TTY_DEBUG 0 |
58 #define EC_TTY_DEBUG 0 |
59 |
59 |
181 |
181 |
182 /****************************************************************************** |
182 /****************************************************************************** |
183 * ec_tty_t methods. |
183 * ec_tty_t methods. |
184 *****************************************************************************/ |
184 *****************************************************************************/ |
185 |
185 |
186 int ec_tty_init(ec_tty_t *tty, int minor, |
186 int ec_tty_init(ec_tty_t *t, int minor, |
187 const ec_tty_operations_t *ops, void *cb_data) |
187 const ec_tty_operations_t *ops, void *cb_data) |
188 { |
188 { |
189 tty->minor = minor; |
189 int ret; |
190 tty->tx_read_idx = 0; |
190 tcflag_t cflag; |
191 tty->tx_write_idx = 0; |
191 struct tty_struct *tty; |
192 tty->wakeup = 0; |
192 |
193 tty->rx_read_idx = 0; |
193 t->minor = minor; |
194 tty->rx_write_idx = 0; |
194 t->tx_read_idx = 0; |
195 init_timer(&tty->timer); |
195 t->tx_write_idx = 0; |
196 tty->tty = NULL; |
196 t->wakeup = 0; |
197 tty->ops = *ops; |
197 t->rx_read_idx = 0; |
198 tty->cb_data = cb_data; |
198 t->rx_write_idx = 0; |
199 |
199 init_timer(&t->timer); |
200 tty->dev = tty_register_device(tty_driver, tty->minor, NULL); |
200 t->tty = NULL; |
201 if (IS_ERR(tty->dev)) { |
201 t->ops = *ops; |
|
202 t->cb_data = cb_data; |
|
203 |
|
204 t->dev = tty_register_device(tty_driver, t->minor, NULL); |
|
205 if (IS_ERR(t->dev)) { |
202 printk(KERN_ERR PFX "Failed to register tty device.\n"); |
206 printk(KERN_ERR PFX "Failed to register tty device.\n"); |
203 return PTR_ERR(tty->dev); |
207 return PTR_ERR(t->dev); |
204 } |
208 } |
205 |
209 |
206 tty->timer.function = ec_tty_wakeup; |
210 // Tell the device-specific implementation about the initial cflags |
207 tty->timer.data = (unsigned long) tty; |
211 tty = tty_driver->ttys[minor]; |
208 tty->timer.expires = jiffies + 10; |
212 |
209 add_timer(&tty->timer); |
213 if (tty && tty->termios) { // already opened before |
|
214 cflag = tty->termios->c_cflag; |
|
215 } else { |
|
216 cflag = tty_driver->init_termios.c_cflag; |
|
217 } |
|
218 ret = t->ops.cflag_changed(t->cb_data, cflag); |
|
219 if (ret) { |
|
220 printk(KERN_ERR PFX "ERROR: Initial cflag 0x%x not accepted.\n", |
|
221 cflag); |
|
222 tty_unregister_device(tty_driver, t->minor); |
|
223 return ret; |
|
224 } |
|
225 |
|
226 t->timer.function = ec_tty_wakeup; |
|
227 t->timer.data = (unsigned long) t; |
|
228 t->timer.expires = jiffies + 10; |
|
229 add_timer(&t->timer); |
210 return 0; |
230 return 0; |
211 } |
231 } |
212 |
232 |
213 /*****************************************************************************/ |
233 /*****************************************************************************/ |
214 |
234 |