]> rtime.felk.cvut.cz Git - lincan.git/blob - embedded/app/usbcan/sysdep_sysless.c
embedded: reintroduce missing emulated bus initialization for UL_USB1 board.
[lincan.git] / embedded / app / usbcan / sysdep_sysless.c
1 /**************************************************************************/
2 /* File: sysdep_sysless.c - System-less support routines                  */
3 /*                                                                        */
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>      */
9 /*                                                                        */
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.                                              */
20 /*                                                                        */
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:                                                     */
24 /*                                                                        */
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 /**************************************************************************/
34
35 #include <cpu_def.h>
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"
43
44 #ifndef IRQF_SHARED
45 #define IRQF_SHARED 0
46 #endif  /*IRQF_SHARED*/
47
48 IRQ_HANDLER_FNC(can_default_irq_dispatch);
49
50 /**
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
55  *
56  * The function hides system specific implementation of the feature.
57  *
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.
61  */
62 int can_request_io_region(unsigned long start, unsigned long n, const char *name)
63 {
64         return 1;
65 }
66
67 /**
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
71  */
72 void can_release_io_region(unsigned long start, unsigned long n)
73 {
74 }
75
76 /**
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
81  *
82  * The function hides system specific implementation of the feature.
83  *
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.
87  */
88 int can_request_mem_region(unsigned long start, unsigned long n, const char *name)
89 {
90         return 1;
91 }
92
93 /**
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
97  */
98 void can_release_mem_region(unsigned long start, unsigned long n)
99 {
100         return;
101 }
102
103
104 /**
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
111  *
112  * File: src/setup.c
113  */
114 IRQ_HANDLER_FNC(can_default_irq_dispatch)
115 {
116         int retval;
117         struct canchip_t *chip;
118
119         chip = (struct canchip_t*)irq_handler_get_context();
120
121         retval=chip->chipspecops->irq_handler(0, chip);
122         return CAN_IRQ_RETVAL(retval);
123 }
124
125 /**
126  * can_chip_setup_irq - attaches chip to the system interrupt processing
127  * @chip: pointer to CAN chip structure
128  *
129  * Return Value: returns negative number in the case of fail
130  */
131 int can_chip_setup_irq(struct canchip_t *chip)
132 {
133         if(chip==NULL)
134                 return -1;
135         if(!chip->chipspecops->irq_handler)
136                 return 0;
137         if(chip->flags & CHIP_IRQ_CUSTOM)
138                 return 1;
139
140         if (request_irq(chip->chip_irq,can_default_irq_dispatch,IRQF_SHARED,DEVICE_NAME,chip))
141                 return -1;
142         else {
143                 DEBUGMSG("Registered interrupt %d\n",chip->chip_irq);
144                 chip->flags |= CHIP_IRQ_SETUP;
145         }
146         return 1;
147 }
148
149
150 /**
151  * can_chip_free_irq - unregisters chip interrupt handler from the system
152  * @chip: pointer to CAN chip structure
153  */
154 void can_chip_free_irq(struct canchip_t *chip)
155 {
156         if((chip->flags & CHIP_IRQ_SETUP) && (chip->chip_irq>=0)) {
157                 if(chip->flags & CHIP_IRQ_CUSTOM)
158                         return;
159
160                 free_irq(chip->chip_irq, chip);
161                 chip->flags &= ~CHIP_IRQ_SETUP;
162         }
163 }
164