]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/virtual.c
LinCAN driver major structured comments and documentation update
[lincan.git] / lincan / src / virtual.c
1 /* virtual.c
2  * Linux CAN-bus device driver.
3  * Written for new CAN driver version by Pavel Pisa - OCERA team member
4  * email:pisa@cmp.felk.cvut.cz
5  * This software is released under the GPL-License.
6  * Version lincan-0.2  9 Jul 2003
7  */ 
8
9 #include <linux/autoconf.h>
10
11 #include <linux/delay.h>
12 #include <asm/errno.h>
13 #include "../include/main.h"
14
15 /* * * Virtual Chip Functionality * * */
16
17 int virtual_enable_configuration(struct chip_t *chip)
18 {
19         return 0;
20 }
21
22 int virtual_disable_configuration(struct chip_t *chip)
23 {
24         return 0;
25 }
26
27 /**
28  * virtual_chip_config: - can chip configuration
29  * @chip: pointer to chip state structure
30  *
31  * Return Value: negative value reports error.
32  * File: src/virtual.c
33  */
34 int virtual_chip_config(struct chip_t *chip)
35 {
36         return 0;
37 }
38
39 /**
40  * virtual_extended_mask: - setup of extended mask for message filtering
41  * @chip: pointer to chip state structure
42  * @code: can message acceptance code
43  * @mask: can message acceptance mask
44  *
45  * Return Value: negative value reports error.
46  * File: src/virtual.c
47  */
48 int virtual_extended_mask(struct chip_t *chip, unsigned long code, unsigned  long mask)
49 {
50         return 0;
51 }
52
53 /**
54  * virtual_baud_rate: - set communication parameters.
55  * @chip: pointer to chip state structure
56  * @rate: baud rate in Hz
57  * @clock: frequency of sja1000 clock in Hz (ISA osc is 14318000)
58  * @sjw: synchronization jump width (0-3) prescaled clock cycles
59  * @sampl_pt: sample point in % (0-100) sets (TSEG1+1)/(TSEG1+TSEG2+2) ratio
60  * @flags: fields %BTR1_SAM, %OCMODE, %OCPOL, %OCTP, %OCTN, %CLK_OFF, %CBP
61  *
62  * Return Value: negative value reports error.
63  * File: src/virtual.c
64  */
65 int virtual_baud_rate(struct chip_t *chip, int rate, int clock, int sjw,
66                                                         int sampl_pt, int flags)
67 {
68         return 0;
69 }
70
71 /**
72  * virtual_read: - reads and distributes one or more received messages
73  * @chip: pointer to chip state structure
74  * @obj: pinter to CAN message queue information
75  *
76  * File: src/virtual.c
77  */
78 void virtual_read(struct chip_t *chip, struct msgobj_t *obj) {
79
80 }
81
82 /**
83  * virtual_pre_read_config: - prepares message object for message reception
84  * @chip: pointer to chip state structure
85  * @obj: pointer to message object state structure
86  *
87  * Return Value: negative value reports error.
88  *      Positive value indicates immediate reception of message.
89  * File: src/virtual.c
90  */
91 int virtual_pre_read_config(struct chip_t *chip, struct msgobj_t *obj)
92 {
93         return 0;
94 }
95
96 #define MAX_TRANSMIT_WAIT_LOOPS 10
97 /**
98  * virtual_pre_write_config: - prepares message object for message transmission
99  * @chip: pointer to chip state structure
100  * @obj: pointer to message object state structure
101  * @msg: pointer to CAN message
102  *
103  * Return Value: negative value reports error.
104  * File: src/virtual.c
105  */
106 int virtual_pre_write_config(struct chip_t *chip, struct msgobj_t *obj, 
107                                                         struct canmsg_t *msg)
108 {
109         return 0;
110 }
111
112 /**
113  * virtual_send_msg: - initiate message transmission
114  * @chip: pointer to chip state structure
115  * @obj: pointer to message object state structure
116  * @msg: pointer to CAN message
117  *
118  * This function is called after virtual_pre_write_config() function,
119  * which prepares data in chip buffer.
120  * Return Value: negative value reports error.
121  * File: src/virtual.c
122  */
123 int virtual_send_msg(struct chip_t *chip, struct msgobj_t *obj, 
124                                                         struct canmsg_t *msg)
125 {
126         return 0;
127 }
128
129 /**
130  * virtual_check_tx_stat: - checks state of transmission engine
131  * @chip: pointer to chip state structure
132  *
133  * Return Value: negative value reports error.
134  *      Positive return value indicates transmission under way status.
135  *      Zero value indicates finishing of all issued transmission requests.
136  * File: src/virtual.c
137  */
138 int virtual_check_tx_stat(struct chip_t *chip)
139 {
140         return 0;
141 }
142
143 /**
144  * virtual_set_btregs: -  configures bitrate registers
145  * @chip: pointer to chip state structure
146  * @btr0: bitrate register 0
147  * @btr1: bitrate register 1
148  *
149  * Return Value: negative value reports error.
150  * File: src/virtual.c
151  */
152 int virtual_set_btregs(struct chip_t *chip, unsigned short btr0, 
153                                                         unsigned short btr1)
154 {
155         return 0;
156 }
157
158 /**
159  * virtual_stop_chip: -  starts chip message processing
160  * @chip: pointer to chip state structure
161  *
162  * Return Value: negative value reports error.
163  * File: src/virtual.c
164  */
165 int virtual_start_chip(struct chip_t *chip)
166 {
167         return 0;
168 }
169
170 /**
171  * virtual_stop_chip: -  stops chip message processing
172  * @chip: pointer to chip state structure
173  *
174  * Return Value: negative value reports error.
175  * File: src/virtual.c
176  */
177 int virtual_stop_chip(struct chip_t *chip)
178 {
179         return 0;
180 }
181
182
183 /**
184  * virtual_remote_request: - configures message object and asks for RTR message
185  * @chip: pointer to chip state structure
186  * @obj: pointer to message object structure
187  *
188  * Return Value: negative value reports error.
189  * File: src/virtual.c
190  */
191 int virtual_remote_request(struct chip_t *chip, struct msgobj_t *obj)
192 {
193         CANMSG("virtual_remote_request not implemented\n");
194         return -ENOSYS;
195 }
196
197 /**
198  * virtual_standard_mask: - setup of mask for message filtering
199  * @chip: pointer to chip state structure
200  * @code: can message acceptance code
201  * @mask: can message acceptance mask
202  *
203  * Return Value: negative value reports error.
204  * File: src/virtual.c
205  */
206 int virtual_standard_mask(struct chip_t *chip, unsigned short code,
207                 unsigned short mask)
208 {
209         CANMSG("virtual_standard_mask not implemented\n");
210         return -ENOSYS;
211 }
212
213 /**
214  * virtual_clear_objects: - clears state of all message object residing in chip
215  * @chip: pointer to chip state structure
216  *
217  * Return Value: negative value reports error.
218  * File: src/virtual.c
219  */
220 int virtual_clear_objects(struct chip_t *chip)
221 {
222         CANMSG("virtual_clear_objects not implemented\n");
223         return -ENOSYS;
224 }
225
226 /**
227  * virtual_config_irqs: - tunes chip hardware interrupt delivery
228  * @chip: pointer to chip state structure
229  * @irqs: requested chip IRQ configuration
230  *
231  * Return Value: negative value reports error.
232  * File: src/virtual.c
233  */
234 int virtual_config_irqs(struct chip_t *chip, short irqs)
235 {
236         CANMSG("virtual_config_irqs not implemented\n");
237         return -ENOSYS;
238 }
239
240 /**
241  * virtual_irq_write_handler: - part of ISR code responsible for transmit events
242  * @chip: pointer to chip state structure
243  * @obj: pointer to attached queue description
244  *
245  * The main purpose of this function is to read message from attached queues
246  * and transfer message contents into CAN controller chip.
247  * This subroutine is called by
248  * virtual_irq_write_handler() for transmit events.
249  * File: src/virtual.c
250  */
251 void virtual_irq_write_handler(struct chip_t *chip, struct msgobj_t *obj)
252 {
253
254 }
255
256 #define MAX_RETR 10
257
258 /**
259  * virtual_irq_handler: - interrupt service routine
260  * @irq: interrupt vector number, this value is system specific
261  * @dev_id: driver private pointer registered at time of request_irq() call.
262  *      The CAN driver uses this pointer to store relationship of interrupt
263  *      to chip state structure - @struct chip_t
264  * @regs: system dependent value pointing to registers stored in exception frame
265  * 
266  * Interrupt handler is activated when state of CAN controller chip changes,
267  * there is message to be read or there is more space for new messages or
268  * error occurs. The receive events results in reading of the message from
269  * CAN controller chip and distribution of message through attached
270  * message queues.
271  * File: src/virtual.c
272  */
273 irqreturn_t virtual_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
274 {
275         return IRQ_HANDLED;
276 }
277
278 /**
279  * virtual_wakeup_tx: - wakeups TX processing
280  * @chip: pointer to chip state structure
281  * @obj: pointer to message object structure
282  *
283  * Return Value: negative value reports error.
284  * File: src/virtual.c
285  */
286 int virtual_wakeup_tx(struct chip_t *chip, struct msgobj_t *obj)
287 {
288         /* set_bit(OBJ_TX_REQUEST,&obj->flags); */
289         
290         struct canque_edge_t *qedge;
291         struct canque_slot_t *slot;
292         int cmd;
293         
294         /* Ensure delivery of all ready slots */
295         
296         while((cmd=canque_test_outslot(obj->qends, &qedge, &slot)) >= 0){
297                 if(cmd==0) {
298                         canque_filter_msg2edges(obj->qends, &slot->msg);
299                 }
300                 canque_free_outslot(obj->qends, qedge, slot);
301         }
302
303         return 0;
304 }
305
306
307 /* * * Virtual Board Functionality * * */
308
309 /**
310  * virtual_request_io: - reserve io or memory range for can board
311  * @candev: pointer to candevice/board which asks for io. Field @io_addr
312  *      of @candev is used in most cases to define start of the range
313  *
314  * Return Value: The function returns zero on success or %-ENODEV on failure
315  * File: src/virtual.c
316  */
317 int virtual_request_io(struct candevice_t *candev)
318 {
319         return 0;
320 }
321
322 /**
323  * virtual_elease_io - free reserved io memory range
324  * @candev: pointer to candevice/board which releases io
325  *
326  * Return Value: The function always returns zero
327  * File: src/virtual.c
328  */
329 int virtual_release_io(struct candevice_t *candev)
330 {
331         return 0;
332 }
333
334 /**
335  * virtual_reset - hardware reset routine
336  * @candev: Pointer to candevice/board structure
337  *
338  * Return Value: The function returns zero on success or %-ENODEV on failure
339  * File: src/virtual.c
340  */
341 int virtual_reset(struct candevice_t *candev)
342 {
343         return 0;
344 }
345
346 /**
347  * virtual_init_hw_data - Initialize hardware cards
348  * @candev: Pointer to candevice/board structure
349  *
350  * Return Value: The function always returns zero
351  * File: src/virtual.c
352  */
353 int virtual_init_hw_data(struct candevice_t *candev) 
354 {
355         candev->res_addr=0;
356         candev->nr_82527_chips=0;
357         candev->nr_sja1000_chips=0;
358         candev->nr_all_chips=1;
359         candev->flags |= PROGRAMMABLE_IRQ*0;
360
361         return 0;
362 }
363
364 #define CHIP_TYPE "virtual"
365
366 /**
367  * virtual_init_chip_data - Initialize chips
368  * @candev: Pointer to candevice/board structure
369  * @chipnr: Number of the CAN chip on the hardware card
370  *
371  * Return Value: The function always returns zero
372  * File: src/virtual.c
373  */
374 int virtual_init_chip_data(struct candevice_t *candev, int chipnr)
375 {
376         struct chip_t *chip = candev->chip[chipnr];
377         chip->chip_type = CHIP_TYPE;
378         chip->chip_base_addr = 0;
379         chip->clock = 10000000;
380         chip->int_clk_reg = 0x0;
381         chip->int_bus_reg = 0x0;
382         chip->max_objects = 1;
383
384         CANMSG("initializing virtual chip operations\n");
385         chip->chipspecops->chip_config=virtual_chip_config;
386         chip->chipspecops->baud_rate=virtual_baud_rate;
387         chip->chipspecops->standard_mask=virtual_standard_mask;
388         chip->chipspecops->extended_mask=virtual_extended_mask;
389         chip->chipspecops->message15_mask=virtual_extended_mask;
390         chip->chipspecops->clear_objects=virtual_clear_objects;
391         chip->chipspecops->config_irqs=virtual_config_irqs;
392         chip->chipspecops->pre_read_config=virtual_pre_read_config;
393         chip->chipspecops->pre_write_config=virtual_pre_write_config;
394         chip->chipspecops->send_msg=virtual_send_msg;
395         chip->chipspecops->check_tx_stat=virtual_check_tx_stat;
396         chip->chipspecops->wakeup_tx=virtual_wakeup_tx;
397         chip->chipspecops->remote_request=virtual_remote_request;
398         chip->chipspecops->enable_configuration=virtual_enable_configuration;
399         chip->chipspecops->disable_configuration=virtual_disable_configuration;
400         chip->chipspecops->set_btregs=virtual_set_btregs;
401         chip->chipspecops->start_chip=virtual_start_chip;
402         chip->chipspecops->stop_chip=virtual_stop_chip;
403         chip->chipspecops->irq_handler=NULL;
404
405         return 0;
406 }
407
408 /**
409  * virtual_init_obj_data - Initialize message buffers
410  * @chip: Pointer to chip specific structure
411  * @objnr: Number of the message buffer
412  *
413  * Return Value: The function always returns zero
414  * File: src/virtual.c
415  */
416 int virtual_init_obj_data(struct chip_t *chip, int objnr)
417 {
418         chip->msgobj[objnr]->obj_base_addr=chip->chip_base_addr;
419         chip->msgobj[objnr]->flags=0;
420         return 0;
421 }
422
423 /**
424  * virtual_program_irq - program interrupts
425  * @candev: Pointer to candevice/board structure
426  *
427  * Return value: The function returns zero on success or %-ENODEV on failure
428  * File: src/virtual.c
429  */
430 int virtual_program_irq(struct candevice_t *candev)
431 {
432         return 0;
433 }
434
435 int virtual_register(struct hwspecops_t *hwspecops)
436 {
437         hwspecops->request_io = virtual_request_io;
438         hwspecops->release_io = virtual_release_io;
439         hwspecops->reset = virtual_reset;
440         hwspecops->init_hw_data = virtual_init_hw_data;
441         hwspecops->init_chip_data = virtual_init_chip_data;
442         hwspecops->init_obj_data = virtual_init_obj_data;
443         hwspecops->write_register = NULL;
444         hwspecops->read_register = NULL;
445         hwspecops->program_irq = virtual_program_irq;
446         return 0;
447 }