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