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
8 #include <linux/autoconf.h>
9 #if defined (CONFIG_MODVERSIONS) && !defined (MODVERSIONS)
13 #if defined (MODVERSIONS)
14 #include <linux/modversions.h>
18 #include <linux/version.h>
20 #include "../include/main.h"
21 #include "../include/ioctl.h"
22 #include "../include/i82527.h"
24 int can_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
27 unsigned short channel=0;
28 unsigned btr0=0, btr1=0;
30 struct chip_t *chip = objects_p[MINOR_NR]->hostchip;
31 struct canfifo_t *fifo = objects_p[MINOR_NR]->fifo;
33 /* Initialize hardware pointers */
34 if ( (obj = objects_p[MINOR_NR]) == NULL) {
35 CANMSG("Could not assign buffer structure\n");
38 if ( (chip = obj->hostchip) == NULL) {
39 CANMSG("Device is not correctly configured.\n");
40 CANMSG("Please reload the driver.\n");
46 for (i=0x0; i<0x100; i++)
47 CANMSG("0x%x is 0x%x\n",i,can_read_reg(chip,i));
51 if (chips_p[arg]->chipspecops->start_chip(chip))
56 if (chips_p[arg]->chipspecops->stop_chip(chip))
61 if (!strcmp(chip->chip_type,"i82527")) {
63 unsigned char id1, id0;
64 id1 = (unsigned char) (arg << 5);
65 id0 = (unsigned char) (arg >> 3);
67 DEBUGMSG("configuring ID=%lx in message object:
68 %02x, %02x\n", arg, id0, id1);
69 can_write_reg(chip,id1,MSG_OFFSET(obj->object) +
71 can_write_reg(chip,id0,MSG_OFFSET(obj->object) +
75 /* In- and output buffer re-initialization */
77 fifo->tx_readp = fifo->buf_tx_entry;
78 fifo->tx_writep = fifo->buf_tx_entry;
79 fifo->rx_readp = fifo->buf_rx_entry;
80 fifo->rx_writep = fifo->buf_rx_entry;
81 fifo->rx_size= MAX_BUF_LENGTH * sizeof(struct canmsg_t);
82 fifo->tx_size = fifo->rx_size;
84 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,2,19))
85 init_waitqueue(&fifo->readq);
86 init_waitqueue(&fifo->writeq);
88 init_waitqueue_head(&fifo->readq);
89 init_waitqueue_head(&fifo->writeq);
92 fifo->rx_in_progress = 0;
93 fifo->tx_in_progress = 0;
95 fifo->head = fifo->tail = 0; //TEMP!!
101 channel = arg & 0xff;
102 btr0 = (arg >> 8) & 0xff;
103 btr1 = (arg >> 16) & 0xff;
105 if (chips_p[channel]->chipspecops->set_btregs(chip,
107 CANMSG("Error setting bit timing registers\n");
113 CANMSG("Not a valid ioctl command\n");