2 * Linux CAN-bus device driver.
3 * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
4 * This software is released under the GPL-License.
5 * Version 0.7 6 Aug 2001
9 #include <linux/module.h>
11 #include <linux/autoconf.h>
12 #if defined (CONFIG_MODVERSIONS) && !defined (MODVERSIONS)
16 #if defined (MODVERSIONS)
17 #include <linux/modversions.h>
21 #include <linux/malloc.h>
22 #include <linux/version.h>
24 #include "../include/main.h"
25 #include "../include/open.h"
26 #include "../include/i82527.h"
27 #include "../include/setup.h"
29 int can_open(struct inode *inode, struct file *file)
33 struct canfifo_t *fifo;
35 if ( ((obj=objects_p[MINOR_NR]) == NULL) ||
36 ((chip=objects_p[MINOR_NR]->hostchip) == NULL) ) {
37 CANMSG("There is no hardware support for the device file with minor nr.: %d\n",MINOR_NR);
41 if (objects_p[MINOR_NR]->flags & OPENED) {
42 CANMSG("Sorry, only single open per device file.\n");
46 objects_p[MINOR_NR]->flags |= OPENED;
48 if (chip->flags & CONFIGURED)
49 DEBUGMSG("Device is already configured.\n");
51 if (chip->chipspecops->chip_config(chip))
52 CANMSG("Error configuring chip.\n");
54 chip->flags |= CONFIGURED;
55 } /* End of chip configuration */
57 /* Allocate output buffer memory for the opened device */
58 fifo = objects_p[MINOR_NR]->fifo;
59 fifo->buf_tx_entry=(struct canmsg_t *)kmalloc(MAX_BUF_LENGTH * sizeof(struct canmsg_t), GFP_KERNEL);
60 if (fifo->buf_tx_entry == NULL)
63 if ( add_mem_to_list(fifo->buf_tx_entry) )
65 /* Allocate input buffer memory for the opened device */
66 fifo->buf_rx_entry=(struct canmsg_t *)kmalloc(MAX_BUF_LENGTH * sizeof(struct canmsg_t), GFP_KERNEL);
67 if (fifo->buf_rx_entry == NULL)
70 if ( add_mem_to_list(fifo->buf_rx_entry) )
73 /* In- and output buffer initialization */
74 fifo->tx_readp = fifo->buf_tx_entry;
75 fifo->tx_writep = fifo->buf_tx_entry;
76 fifo->rx_readp = fifo->buf_rx_entry;
77 fifo->rx_writep = fifo->buf_rx_entry;
78 fifo->rx_size = MAX_BUF_LENGTH * sizeof(struct canmsg_t);
79 fifo->tx_size = fifo->rx_size;
81 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,2,19))
82 init_waitqueue(&fifo->readq);
83 init_waitqueue(&fifo->writeq);
85 init_waitqueue_head(&fifo->readq);
86 init_waitqueue_head(&fifo->writeq);
89 fifo->rx_in_progress = 0;
90 fifo->tx_in_progress = 0;
92 fifo->head = fifo->tail = 0; //TEMP!!
94 if (chip->chipspecops->pre_read_config(chip,obj)<0)
95 CANMSG("Error initializing chip for receiving\n");