]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/cc_can104.c
9df4b71ea6d2c94a7d5a87e306c4b5cd02fd1665
[lincan.git] / lincan / src / cc_can104.c
1 /* cc_can104.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.3  17 Jun 2004
8  */ 
9
10 #include "../include/can.h"
11 #include "../include/can_sysdep.h"
12 #include "../include/main.h"
13 #include "../include/cc_can104.h"
14 #include "../include/i82527.h"
15 #include "../include/sja1000.h"
16
17 /*
18  * IO_RANGE is the io-memory range that gets reserved, please adjust according
19  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
20  * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
21  */
22 #define IO_RANGE 0x80
23
24 /**
25  * template_request_io: - reserve io or memory range for can board
26  * @candev: pointer to candevice/board which asks for io. Field @io_addr
27  *      of @candev is used in most cases to define start of the range
28  *
29  * The function template_request_io() is used to reserve the io-memory. If your
30  * hardware uses a dedicated memory range as hardware control registers you
31  * will have to add the code to reserve this memory as well. 
32  * %IO_RANGE is the io-memory range that gets reserved, please adjust according
33  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
34  * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
35  * Return Value: The function returns zero on success or %-ENODEV on failure
36  * File: src/template.c
37  */
38 int cc104_request_io(struct candevice_t *candev)
39 {
40         if (!can_request_io_region(candev->io_addr,IO_RANGE,DEVICE_NAME)) {
41                 CANMSG("Unable to open port: 0x%lx\n",candev->io_addr);
42                 return -ENODEV;
43         }else {
44                 DEBUGMSG("Registered IO-memory: 0x%lx - 0x%lx\n", candev->io_addr, candev->io_addr + IO_RANGE - 1);
45         }
46         return 0;
47 }
48
49 /**
50  * template_elease_io - free reserved io memory range
51  * @candev: pointer to candevice/board which releases io
52  *
53  * The function template_release_io() is used to free reserved io-memory.
54  * In case you have reserved more io memory, don't forget to free it here.
55  * IO_RANGE is the io-memory range that gets released, please adjust according
56  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
57  * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
58  * Return Value: The function always returns zero
59  * File: src/template.c
60  */
61 int cc104_release_io(struct candevice_t *candev)
62 {
63         can_release_io_region(candev->io_addr,IO_RANGE);
64
65         return 0;
66 }
67
68 /**
69  * template_reset - hardware reset routine
70  * @candev: Pointer to candevice/board structure
71  *
72  * The function template_reset() is used to give a hardware reset. This is 
73  * rather hardware specific so I haven't included example code. Don't forget to 
74  * check the reset status of the chip before returning.
75  * Return Value: The function returns zero on success or %-ENODEV on failure
76  * File: src/template.c
77  */
78 int cc104_reset(struct candevice_t *candev)
79 {
80         return 0;
81 }
82
83 #define RESET_ADDR 0x0
84 #define NR_82527 0
85 #define NR_SJA1000 1
86
87 /**
88  * template_init_hw_data - Initialize hardware cards
89  * @candev: Pointer to candevice/board structure
90  *
91  * The function template_init_hw_data() is used to initialize the hardware
92  * structure containing information about the installed CAN-board.
93  * %RESET_ADDR represents the io-address of the hardware reset register.
94  * %NR_82527 represents the number of intel 82527 chips on the board.
95  * %NR_SJA1000 represents the number of philips sja1000 chips on the board.
96  * The flags entry can currently only be %CANDEV_PROGRAMMABLE_IRQ to indicate that
97  * the hardware uses programmable interrupts.
98  * Return Value: The function always returns zero
99  * File: src/template.c
100  */
101 int cc104_init_hw_data(struct candevice_t *candev) 
102 {
103         candev->res_addr=RESET_ADDR;
104         candev->nr_82527_chips=0;
105         candev->nr_sja1000_chips=1;
106         candev->nr_all_chips=1;
107         candev->flags &= ~CANDEV_PROGRAMMABLE_IRQ;
108
109         return 0;
110 }
111
112 #define CHIP_TYPE "sja1000"
113 /**
114  * template_init_chip_data - Initialize chips
115  * @candev: Pointer to candevice/board structure
116  * @chipnr: Number of the CAN chip on the hardware card
117  *
118  * The function template_init_chip_data() is used to initialize the hardware
119  * structure containing information about the CAN chips.
120  * %CHIP_TYPE represents the type of CAN chip. %CHIP_TYPE can be "i82527" or
121  * "sja1000".
122  * The @chip_base_addr entry represents the start of the 'official' memory map
123  * of the installed chip. It's likely that this is the same as the @io_addr
124  * argument supplied at module loading time.
125  * The @clock entry holds the chip clock value in Hz.
126  * The entry @sja_cdr_reg holds hardware specific options for the Clock Divider
127  * register. Options defined in the %sja1000.h file:
128  * %sjaCDR_CLKOUT_MASK, %sjaCDR_CLK_OFF, %sjaCDR_RXINPEN, %sjaCDR_CBP, %sjaCDR_PELICAN
129  * The entry @sja_ocr_reg holds hardware specific options for the Output Control
130  * register. Options defined in the %sja1000.h file:
131  * %sjaOCR_MODE_BIPHASE, %sjaOCR_MODE_TEST, %sjaOCR_MODE_NORMAL, %sjaOCR_MODE_CLOCK,
132  * %sjaOCR_TX0_LH, %sjaOCR_TX1_ZZ.
133  * The entry @int_clk_reg holds hardware specific options for the Clock Out
134  * register. Options defined in the %i82527.h file:
135  * %iCLK_CD0, %iCLK_CD1, %iCLK_CD2, %iCLK_CD3, %iCLK_SL0, %iCLK_SL1.
136  * The entry @int_bus_reg holds hardware specific options for the Bus 
137  * Configuration register. Options defined in the %i82527.h file:
138  * %iBUS_DR0, %iBUS_DR1, %iBUS_DT1, %iBUS_POL, %iBUS_CBY.
139  * Return Value: The function always returns zero
140  * File: src/template.c
141  */
142 int cc104_init_chip_data(struct candevice_t *candev, int chipnr)
143 {
144         candev->chip[chipnr]->chip_type=CHIP_TYPE;
145         candev->chip[chipnr]->chip_base_addr=candev->io_addr;
146         candev->chip[chipnr]->clock = 16000000;
147         candev->chip[chipnr]->flags = 0;
148         candev->chip[chipnr]->sja_cdr_reg = sjaCDR_CBP | sjaCDR_CLK_OFF;
149         candev->chip[chipnr]->sja_ocr_reg = sjaOCR_MODE_NORMAL |
150                                                                 sjaOCR_TX0_LH;
151
152         return 0;
153 }
154
155 /**
156  * template_init_obj_data - Initialize message buffers
157  * @chip: Pointer to chip specific structure
158  * @objnr: Number of the message buffer
159  *
160  * The function template_init_obj_data() is used to initialize the hardware
161  * structure containing information about the different message objects on the
162  * CAN chip. In case of the sja1000 there's only one message object but on the
163  * i82527 chip there are 15.
164  * The code below is for a i82527 chip and initializes the object base addresses
165  * The entry @obj_base_addr represents the first memory address of the message 
166  * object. In case of the sja1000 @obj_base_addr is taken the same as the chips
167  * base address.
168  * Unless the hardware uses a segmented memory map, flags can be set zero.
169  * Return Value: The function always returns zero
170  * File: src/template.c
171  */
172 int cc104_init_obj_data(struct chip_t *chip, int objnr)
173 {
174         chip->msgobj[objnr]->obj_base_addr=chip->chip_base_addr;
175         
176         return 0;
177 }
178
179 /**
180  * template_program_irq - program interrupts
181  * @candev: Pointer to candevice/board structure
182  *
183  * The function template_program_irq() is used for hardware that uses 
184  * programmable interrupts. If your hardware doesn't use programmable interrupts
185  * you should not set the @candevices_t->flags entry to %CANDEV_PROGRAMMABLE_IRQ and 
186  * leave this function unedited. Again this function is hardware specific so 
187  * there's no example code.
188  * Return value: The function returns zero on success or %-ENODEV on failure
189  * File: src/template.c
190  */
191 int cc104_program_irq(struct candevice_t *candev)
192 {
193         return 0;
194 }
195
196 /**
197  * template_write_register - Low level write register routine
198  * @data: data to be written
199  * @address: memory address to write to
200  *
201  * The function template_write_register() is used to write to hardware registers
202  * on the CAN chip. You should only have to edit this function if your hardware
203  * uses some specific write process.
204  * Return Value: The function does not return a value
205  * File: src/template.c
206  */
207 void cc104_write_register(unsigned data, unsigned long address)
208 {
209         outb(data,address);
210 }
211
212 /**
213  * template_read_register - Low level read register routine
214  * @address: memory address to read from
215  *
216  * The function template_read_register() is used to read from hardware registers
217  * on the CAN chip. You should only have to edit this function if your hardware
218  * uses some specific read process.
219  * Return Value: The function returns the value stored in @address
220  * File: src/template.c
221  */
222 unsigned cc104_read_register(unsigned long address)
223 {
224         return inb(address);
225 }
226
227 /* !!! Don't change this function !!! */
228 int cc104_register(struct hwspecops_t *hwspecops)
229 {
230         hwspecops->request_io = cc104_request_io;
231         hwspecops->release_io = cc104_release_io;
232         hwspecops->reset = cc104_reset;
233         hwspecops->init_hw_data = cc104_init_hw_data;
234         hwspecops->init_chip_data = cc104_init_chip_data;
235         hwspecops->init_obj_data = cc104_init_obj_data;
236         hwspecops->write_register = cc104_write_register;
237         hwspecops->read_register = cc104_read_register;
238         hwspecops->program_irq = cc104_program_irq;
239         return 0;
240 }