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/version.h>
22 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
23 #include <linux/malloc.h>
25 #include <linux/slab.h>
27 #include <linux/version.h>
29 #include "../include/main.h"
30 #include "../include/open.h"
31 #include "../include/i82527.h"
32 #include "../include/setup.h"
34 int can_open(struct inode *inode, struct file *file)
38 struct canfifo_t *fifo;
40 if ( ((obj=objects_p[MINOR_NR]) == NULL) ||
41 ((chip=objects_p[MINOR_NR]->hostchip) == NULL) ) {
42 CANMSG("There is no hardware support for the device file with minor nr.: %d\n",MINOR_NR);
46 if (objects_p[MINOR_NR]->flags & OPENED) {
47 CANMSG("Sorry, only single open per device file.\n");
51 objects_p[MINOR_NR]->flags |= OPENED;
53 if (chip->flags & CONFIGURED)
54 DEBUGMSG("Device is already configured.\n");
56 if (chip->chipspecops->chip_config(chip))
57 CANMSG("Error configuring chip.\n");
59 chip->flags |= CONFIGURED;
60 } /* End of chip configuration */
62 /* Allocate output buffer memory for the opened device */
63 fifo = objects_p[MINOR_NR]->fifo;
64 fifo->buf_tx_entry=(struct canmsg_t *)kmalloc(MAX_BUF_LENGTH * sizeof(struct canmsg_t), GFP_KERNEL);
65 if (fifo->buf_tx_entry == NULL)
68 if ( add_mem_to_list(fifo->buf_tx_entry) )
70 /* Allocate input buffer memory for the opened device */
71 fifo->buf_rx_entry=(struct canmsg_t *)kmalloc(MAX_BUF_LENGTH * sizeof(struct canmsg_t), GFP_KERNEL);
72 if (fifo->buf_rx_entry == NULL)
75 if ( add_mem_to_list(fifo->buf_rx_entry) )
78 /* In- and output buffer initialization */
79 fifo->tx_readp = fifo->buf_tx_entry;
80 fifo->tx_writep = fifo->buf_tx_entry;
81 fifo->rx_readp = fifo->buf_rx_entry;
82 fifo->rx_writep = fifo->buf_rx_entry;
83 fifo->rx_size = MAX_BUF_LENGTH * sizeof(struct canmsg_t);
84 fifo->tx_size = fifo->rx_size;
86 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,0))
87 init_waitqueue(&fifo->readq);
88 init_waitqueue(&fifo->writeq);
90 init_waitqueue_head(&fifo->readq);
91 init_waitqueue_head(&fifo->writeq);
94 fifo->rx_in_progress = 0;
95 fifo->tx_in_progress = 0;
97 chip->flags |= BUFFERS_ALLOCATED;
99 if (chip->chipspecops->pre_read_config(chip,obj)<0)
100 CANMSG("Error initializing chip for receiving\n");
102 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,50))