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>
19 #include <linux/string.h>
21 #include "../include/main.h"
22 #include "../include/ioctl.h"
23 #include "../include/i82527.h"
25 int can_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
28 unsigned short channel=0;
29 unsigned btr0=0, btr1=0;
31 struct chip_t *chip = objects_p[MINOR_NR]->hostchip;
32 struct canfifo_t *fifo = objects_p[MINOR_NR]->fifo;
34 /* Initialize hardware pointers */
35 if ( (obj = objects_p[MINOR_NR]) == NULL) {
36 CANMSG("Could not assign buffer structure\n");
39 if ( (chip = obj->hostchip) == NULL) {
40 CANMSG("Device is not correctly configured.\n");
41 CANMSG("Please reload the driver.\n");
47 for (i=0x0; i<0x100; i++)
48 CANMSG("0x%x is 0x%x\n",i,can_read_reg(chip,i));
52 if (chips_p[arg]->chipspecops->start_chip(chip))
57 if (chips_p[arg]->chipspecops->stop_chip(chip))
62 if (!strcmp(chip->chip_type,"i82527")) {
64 unsigned char id1, id0;
65 id1 = (unsigned char) (arg << 5);
66 id0 = (unsigned char) (arg >> 3);
68 DEBUGMSG("configuring ID=%lx in message object:
69 %02x, %02x\n", arg, id0, id1);
70 can_write_reg(chip,id1,MSG_OFFSET(obj->object) +
72 can_write_reg(chip,id0,MSG_OFFSET(obj->object) +
76 /* In- and output buffer re-initialization */
78 fifo->tx_readp = fifo->buf_tx_entry;
79 fifo->tx_writep = fifo->buf_tx_entry;
80 fifo->rx_readp = fifo->buf_rx_entry;
81 fifo->rx_writep = fifo->buf_rx_entry;
82 fifo->rx_size= MAX_BUF_LENGTH * sizeof(struct canmsg_t);
83 fifo->tx_size = fifo->rx_size;
85 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,0))
86 init_waitqueue(&fifo->readq);
87 init_waitqueue(&fifo->writeq);
89 init_waitqueue_head(&fifo->readq);
90 init_waitqueue_head(&fifo->writeq);
93 fifo->rx_in_progress = 0;
94 fifo->tx_in_progress = 0;
100 channel = arg & 0xff;
101 btr0 = (arg >> 8) & 0xff;
102 btr1 = (arg >> 16) & 0xff;
104 if (chips_p[channel]->chipspecops->set_btregs(chip,
106 CANMSG("Error setting bit timing registers\n");
112 CANMSG("Not a valid ioctl command\n");