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
9 #include <linux/autoconf.h>
11 #include <linux/delay.h>
12 #include <asm/errno.h>
13 #include "../include/main.h"
15 /* * * Virtual Chip Functionality * * */
17 int virtual_enable_configuration(struct chip_t *chip)
22 int virtual_disable_configuration(struct chip_t *chip)
28 * virtual_chip_config: - can chip configuration
29 * @chip: pointer to chip state structure
31 * Return Value: negative value reports error.
34 int virtual_chip_config(struct chip_t *chip)
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
45 * Return Value: negative value reports error.
48 int virtual_extended_mask(struct chip_t *chip, unsigned long code, unsigned long mask)
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
62 * Return Value: negative value reports error.
65 int virtual_baud_rate(struct chip_t *chip, int rate, int clock, int sjw,
66 int sampl_pt, int flags)
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
78 void virtual_read(struct chip_t *chip, struct msgobj_t *obj) {
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
87 * Return Value: negative value reports error.
88 * Positive value indicates immediate reception of message.
91 int virtual_pre_read_config(struct chip_t *chip, struct msgobj_t *obj)
96 #define MAX_TRANSMIT_WAIT_LOOPS 10
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
103 * Return Value: negative value reports error.
104 * File: src/virtual.c
106 int virtual_pre_write_config(struct chip_t *chip, struct msgobj_t *obj,
107 struct canmsg_t *msg)
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
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
123 int virtual_send_msg(struct chip_t *chip, struct msgobj_t *obj,
124 struct canmsg_t *msg)
130 * virtual_check_tx_stat: - checks state of transmission engine
131 * @chip: pointer to chip state structure
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
138 int virtual_check_tx_stat(struct chip_t *chip)
144 * virtual_set_btregs: - configures bitrate registers
145 * @chip: pointer to chip state structure
146 * @btr0: bitrate register 0
147 * @btr1: bitrate register 1
149 * Return Value: negative value reports error.
150 * File: src/virtual.c
152 int virtual_set_btregs(struct chip_t *chip, unsigned short btr0,
159 * virtual_stop_chip: - starts chip message processing
160 * @chip: pointer to chip state structure
162 * Return Value: negative value reports error.
163 * File: src/virtual.c
165 int virtual_start_chip(struct chip_t *chip)
171 * virtual_stop_chip: - stops chip message processing
172 * @chip: pointer to chip state structure
174 * Return Value: negative value reports error.
175 * File: src/virtual.c
177 int virtual_stop_chip(struct chip_t *chip)
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
188 * Return Value: negative value reports error.
189 * File: src/virtual.c
191 int virtual_remote_request(struct chip_t *chip, struct msgobj_t *obj)
193 CANMSG("virtual_remote_request not implemented\n");
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
203 * Return Value: negative value reports error.
204 * File: src/virtual.c
206 int virtual_standard_mask(struct chip_t *chip, unsigned short code,
209 CANMSG("virtual_standard_mask not implemented\n");
214 * virtual_clear_objects: - clears state of all message object residing in chip
215 * @chip: pointer to chip state structure
217 * Return Value: negative value reports error.
218 * File: src/virtual.c
220 int virtual_clear_objects(struct chip_t *chip)
222 CANMSG("virtual_clear_objects not implemented\n");
227 * virtual_config_irqs: - tunes chip hardware interrupt delivery
228 * @chip: pointer to chip state structure
229 * @irqs: requested chip IRQ configuration
231 * Return Value: negative value reports error.
232 * File: src/virtual.c
234 int virtual_config_irqs(struct chip_t *chip, short irqs)
236 CANMSG("virtual_config_irqs not implemented\n");
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
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
251 void virtual_irq_write_handler(struct chip_t *chip, struct msgobj_t *obj)
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
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
271 * File: src/virtual.c
273 irqreturn_t virtual_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
279 * virtual_wakeup_tx: - wakeups TX processing
280 * @chip: pointer to chip state structure
281 * @obj: pointer to message object structure
283 * Return Value: negative value reports error.
284 * File: src/virtual.c
286 int virtual_wakeup_tx(struct chip_t *chip, struct msgobj_t *obj)
288 /* set_bit(OBJ_TX_REQUEST,&obj->flags); */
290 struct canque_edge_t *qedge;
291 struct canque_slot_t *slot;
294 /* Ensure delivery of all ready slots */
296 while((cmd=canque_test_outslot(obj->qends, &qedge, &slot)) >= 0){
298 canque_filter_msg2edges(obj->qends, &slot->msg);
300 canque_free_outslot(obj->qends, qedge, slot);
307 /* * * Virtual Board Functionality * * */
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
314 * Return Value: The function returns zero on success or %-ENODEV on failure
315 * File: src/virtual.c
317 int virtual_request_io(struct candevice_t *candev)
323 * virtual_elease_io - free reserved io memory range
324 * @candev: pointer to candevice/board which releases io
326 * Return Value: The function always returns zero
327 * File: src/virtual.c
329 int virtual_release_io(struct candevice_t *candev)
335 * virtual_reset - hardware reset routine
336 * @candev: Pointer to candevice/board structure
338 * Return Value: The function returns zero on success or %-ENODEV on failure
339 * File: src/virtual.c
341 int virtual_reset(struct candevice_t *candev)
347 * virtual_init_hw_data - Initialize hardware cards
348 * @candev: Pointer to candevice/board structure
350 * Return Value: The function always returns zero
351 * File: src/virtual.c
353 int virtual_init_hw_data(struct candevice_t *candev)
356 candev->nr_82527_chips=0;
357 candev->nr_sja1000_chips=0;
358 candev->nr_all_chips=1;
359 candev->flags |= PROGRAMMABLE_IRQ*0;
364 #define CHIP_TYPE "virtual"
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
371 * Return Value: The function always returns zero
372 * File: src/virtual.c
374 int virtual_init_chip_data(struct candevice_t *candev, int chipnr)
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;
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;
409 * virtual_init_obj_data - Initialize message buffers
410 * @chip: Pointer to chip specific structure
411 * @objnr: Number of the message buffer
413 * Return Value: The function always returns zero
414 * File: src/virtual.c
416 int virtual_init_obj_data(struct chip_t *chip, int objnr)
418 chip->msgobj[objnr]->obj_base_addr=chip->chip_base_addr;
419 chip->msgobj[objnr]->flags=0;
424 * virtual_program_irq - program interrupts
425 * @candev: Pointer to candevice/board structure
427 * Return value: The function returns zero on success or %-ENODEV on failure
428 * File: src/virtual.c
430 int virtual_program_irq(struct candevice_t *candev)
435 int virtual_register(struct hwspecops_t *hwspecops)
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;