1 /**************************************************************************/
2 /* File: sysdep_sysless.c - System-less support routines */
4 /* LinCAN - (Not only) Linux CAN bus driver */
5 /* Copyright (C) 2002-2009 DCE FEE CTU Prague <http://dce.felk.cvut.cz> */
6 /* Copyright (C) 2002-2009 Pavel Pisa <pisa@cmp.felk.cvut.cz> */
7 /* Funded by OCERA and FRESCOR IST projects */
8 /* Based on CAN driver code by Arnaud Westenberg <arnaud@wanadoo.nl> */
10 /* LinCAN is free software; you can redistribute it and/or modify it */
11 /* under terms of the GNU General Public License as published by the */
12 /* Free Software Foundation; either version 2, or (at your option) any */
13 /* later version. LinCAN is distributed in the hope that it will be */
14 /* useful, but WITHOUT ANY WARRANTY; without even the implied warranty */
15 /* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
16 /* General Public License for more details. You should have received a */
17 /* copy of the GNU General Public License along with LinCAN; see file */
18 /* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, */
19 /* Cambridge, MA 02139, USA. */
21 /* To allow use of LinCAN in the compact embedded systems firmware */
22 /* and RT-executives (RTEMS for example), main authors agree with next */
23 /* special exception: */
25 /* Including LinCAN header files in a file, instantiating LinCAN generics */
26 /* or templates, or linking other files with LinCAN objects to produce */
27 /* an application image/executable, does not by itself cause the */
28 /* resulting application image/executable to be covered by */
29 /* the GNU General Public License. */
30 /* This exception does not however invalidate any other reasons */
31 /* why the executable file might be covered by the GNU Public License. */
32 /* Publication of enhanced or derived LinCAN files is required although. */
33 /**************************************************************************/
36 #include <system_def.h>
37 #include "./can/can.h"
38 #include "./can/can_sysdep.h"
39 #include "./can/main.h"
40 #include "./can/devcommon.h"
41 #include "./can/setup.h"
42 #include "./can/finish.h"
46 #endif /*IRQF_SHARED*/
48 IRQ_HANDLER_FNC(can_default_irq_dispatch);
51 * can_request_io_region - request IO space region
52 * @start: the first IO port address
53 * @n: number of the consecutive IO port addresses
54 * @name: name/label for the requested region
56 * The function hides system specific implementation of the feature.
58 * Return Value: returns positive value (1) in the case, that region could
59 * be reserved for the driver. Returns zero (0) if there is collision with
60 * other driver or region cannot be taken for some other reason.
62 int can_request_io_region(unsigned long start, unsigned long n, const char *name)
68 * can_release_io_region - release IO space region
69 * @start: the first IO port address
70 * @n: number of the consecutive IO port addresses
72 void can_release_io_region(unsigned long start, unsigned long n)
77 * can_request_mem_region - request memory space region
78 * @start: the first memory port physical address
79 * @n: number of the consecutive memory port addresses
80 * @name: name/label for the requested region
82 * The function hides system specific implementation of the feature.
84 * Return Value: returns positive value (1) in the case, that region could
85 * be reserved for the driver. Returns zero (0) if there is collision with
86 * other driver or region cannot be taken for some other reason.
88 int can_request_mem_region(unsigned long start, unsigned long n, const char *name)
94 * can_release_mem_region - release memory space region
95 * @start: the first memory port physical address
96 * @n: number of the consecutive memory port addresses
98 void can_release_mem_region(unsigned long start, unsigned long n)
105 * can_default_irq_dispatch - the first level interrupt dispatch handler
106 * @irq: interrupt vector number, this value is system specific
107 * @dev_id: driver private pointer registered at time of request_irq() call.
108 * The CAN driver uses this pointer to store relationship of interrupt
109 * to chip state structure - @struct canchip_t
110 * @regs: system dependent value pointing to registers stored in exception frame
114 IRQ_HANDLER_FNC(can_default_irq_dispatch)
117 struct canchip_t *chip;
119 chip = (struct canchip_t*)irq_handler_get_context();
121 retval=chip->chipspecops->irq_handler(0, chip);
122 return CAN_IRQ_RETVAL(retval);
126 * can_chip_setup_irq - attaches chip to the system interrupt processing
127 * @chip: pointer to CAN chip structure
129 * Return Value: returns negative number in the case of fail
131 int can_chip_setup_irq(struct canchip_t *chip)
135 if(!chip->chipspecops->irq_handler)
137 if(chip->flags & CHIP_IRQ_CUSTOM)
140 if (request_irq(chip->chip_irq,can_default_irq_dispatch,IRQF_SHARED,DEVICE_NAME,chip))
143 DEBUGMSG("Registered interrupt %d\n",chip->chip_irq);
144 chip->flags |= CHIP_IRQ_SETUP;
151 * can_chip_free_irq - unregisters chip interrupt handler from the system
152 * @chip: pointer to CAN chip structure
154 void can_chip_free_irq(struct canchip_t *chip)
156 if((chip->flags & CHIP_IRQ_SETUP) && (chip->chip_irq>=0)) {
157 if(chip->flags & CHIP_IRQ_CUSTOM)
160 free_irq(chip->chip_irq, chip);
161 chip->flags &= ~CHIP_IRQ_SETUP;