]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/ioctl.c
Update of Makefiles to support "Standalone" compilation.
[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 CONF_FILTER: {
67                     #if 0
68                         if (!strcmp(chip->chip_type,"i82527")) {
69                         
70                                 unsigned char id1, id0;
71                                 id1 = (unsigned char) (arg << 5);
72                                 id0 = (unsigned char) (arg >> 3);
73
74                                 DEBUGMSG("configuring ID=%lx in message object:"
75                                         " %02x, %02x\n", arg, id0, id1);
76                                 can_write_reg(chip,id1,MSG_OFFSET(obj->object) +
77                                                                 iMSGID1);
78                                 can_write_reg(chip,id0,MSG_OFFSET(obj->object) +
79                                                                 iMSGID0);
80                         }
81                     #endif
82
83                         /* In- and output buffer re-initialization */
84                         
85                         if(canuser->rx_edge0){
86                                 canque_set_filt(canuser->rx_edge0, arg, ~0);
87                                 canque_flush(canuser->rx_edge0);
88                         }
89
90                         break;
91                 }
92                 
93                 case CONF_FILTER_QUE0: {
94                         struct canfilt_t canfilt;
95                         copy_from_user(&canfilt, (void*)arg, sizeof(struct canfilt_t));
96                         if(canuser->rx_edge0){
97                                 canque_set_filt(canuser->rx_edge0, canfilt.id, canfilt.mask);
98                                 canque_flush(canuser->rx_edge0);
99                         }
100                         break;
101                 }
102
103                 case CONF_BAUD: {
104                         channel = arg & 0xff;
105                         btr0 = (arg >> 8) & 0xff;
106                         btr1 = (arg >> 16) & 0xff;
107
108                         if (chip->chipspecops->set_btregs(chip, btr0, btr1)) {
109                                 CANMSG("Error setting bit timing registers\n");
110                                 return -1;
111                         }
112                         break;
113                 }
114                 default: {
115                         CANMSG("Not a valid ioctl command\n");
116                         return -EINVAL;
117                 }
118                 
119         }
120
121         return 0;
122 }