]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/ioctl.c
08b3aa0aa2646cfbf6fec0e9bf9664e7556bdfda
[lincan.git] / lincan / src / ioctl.c
1 /* ioctl.c
2  * Linux CAN-bus device driver.
3  * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
4  * Rewritten for new CAN queues by Pavel Pisa - OCERA team member
5  * email:pisa@cmp.felk.cvut.cz
6  * This software is released under the GPL-License.
7  * Version lincan-0.2  9 Jul 2003
8  */
9
10 #include <linux/autoconf.h>
11
12 #include <linux/fs.h>
13 #include <linux/version.h>
14 #include <linux/string.h>
15 #include <asm/uaccess.h>
16
17 #include "../include/main.h"
18 #include "../include/ioctl.h"
19 #include "../include/i82527.h"
20
21 int can_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
22 {
23         int i=0;
24         unsigned short channel=0;
25         unsigned btr0=0, btr1=0;
26         struct canuser_t *canuser = (struct canuser_t*)(file->private_data);
27         struct msgobj_t *obj;
28         struct chip_t *chip;
29         struct canque_ends_t *qends;
30         
31         if(!canuser || (canuser->magic != CAN_USER_MAGIC)){
32                 CANMSG("can_close: bad canuser magic\n");
33                 return -ENODEV;
34         }
35         
36         obj = canuser->msgobj;
37         if (obj == NULL) {
38                 CANMSG("Could not assign buffer structure\n");
39                 return -1;
40         }
41
42         qends = canuser->qends;
43         chip = obj->hostchip;
44         if (chip == NULL) {
45                 CANMSG("Device is not correctly configured.\n");
46                 CANMSG("Please reload the driver.\n");
47                 return -1;
48         }
49
50         switch (cmd) {
51                 case STAT: {
52                         for (i=0x0; i<0x100; i++)
53                                 CANMSG("0x%x is 0x%x\n",i,can_read_reg(chip,i));
54                         break;
55                 }
56                 case CMD_START: {
57                         if (chip->chipspecops->start_chip(chip))
58                                 return -1;
59                         break;
60                 }
61                 case CMD_STOP: {
62                         if (chip->chipspecops->stop_chip(chip))
63                                 return -1;
64                         break;
65                 }
66                 case CANQUE_FLUSH: {
67                         canque_flush(canuser->rx_edge0);
68                         break;
69                 }
70                 case CONF_FILTER: {
71                     #if 0
72                         if (!strcmp(chip->chip_type,"i82527")) {
73                         
74                                 unsigned char id1, id0;
75                                 id1 = (unsigned char) (arg << 5);
76                                 id0 = (unsigned char) (arg >> 3);
77
78                                 DEBUGMSG("configuring ID=%lx in message object:"
79                                         " %02x, %02x\n", arg, id0, id1);
80                                 can_write_reg(chip,id1,MSG_OFFSET(obj->object) +
81                                                                 iMSGID1);
82                                 can_write_reg(chip,id0,MSG_OFFSET(obj->object) +
83                                                                 iMSGID0);
84                         }
85                     #endif
86
87                         /* In- and output buffer re-initialization */
88                         
89                         if(canuser->rx_edge0){
90                                 canque_set_filt(canuser->rx_edge0, arg, ~0, 0);
91                         }
92
93                         break;
94                 }
95                 
96                 case CANQUE_FILTER: {
97                         struct canfilt_t canfilt;
98                         copy_from_user(&canfilt, (void*)arg, sizeof(struct canfilt_t));
99                         if(canuser->rx_edge0){
100                                 canque_set_filt(canuser->rx_edge0, canfilt.id, canfilt.mask, canfilt.flags);
101                         }
102                         break;
103                 }
104
105                 case CONF_BAUD: {
106                         channel = arg & 0xff;
107                         btr0 = (arg >> 8) & 0xff;
108                         btr1 = (arg >> 16) & 0xff;
109
110                         if (chip->chipspecops->set_btregs(chip, btr0, btr1)) {
111                                 CANMSG("Error setting bit timing registers\n");
112                                 return -1;
113                         }
114                         break;
115                 }
116                 default: {
117                         CANMSG("Not a valid ioctl command\n");
118                         return -EINVAL;
119                 }
120                 
121         }
122
123         return 0;
124 }