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
10 /* This file is intended as a bfadcan file for currently unsupported hardware.
11 * Once you've changed/added the functions specific to your hardware it is
12 * possible to load the driver with the hardware option hw=bfadcan.
16 #define WINDOWED_ACCESS
18 #include "../include/can.h"
19 #include "../include/can_sysdep.h"
20 #include "../include/main.h"
21 #include "../include/i82527.h"
22 #include "../include/sja1000p.h"
24 #define __NO_VERSION__
25 #include <linux/module.h>
28 MODULE_PARM(clock_freq,"i");
30 /* cli and sti are not allowed in 2.5.5x SMP kernels */
31 #ifdef WINDOWED_ACCESS
32 static can_spinlock_t bfadcan_win_lock=SPIN_LOCK_UNLOCKED;
36 * IO_RANGE is the io-memory range that gets reserved, please adjust according
37 * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
38 * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
40 #ifdef WINDOWED_ACCESS
43 #define IO_RANGE 0x100
46 unsigned bfadcan_read_register(unsigned long address);
47 void bfadcan_write_register(unsigned data, unsigned long address);
51 * bfadcan_request_io: - reserve io or memory range for can board
52 * @candev: pointer to candevice/board which asks for io. Field @io_addr
53 * of @candev is used in most cases to define start of the range
55 * The function bfadcan_request_io() is used to reserve the io-memory. If your
56 * hardware uses a dedicated memory range as hardware control registers you
57 * will have to add the code to reserve this memory as well.
58 * %IO_RANGE is the io-memory range that gets reserved, please adjust according
59 * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
60 * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
61 * Return Value: The function returns zero on success or %-ENODEV on failure
64 int bfadcan_request_io(struct candevice_t *candev)
66 if (!can_request_io_region(candev->io_addr,IO_RANGE,DEVICE_NAME)) {
67 CANMSG("Unable to open port: 0x%lx\n",candev->io_addr);
70 DEBUGMSG("Registered IO-memory: 0x%lx - 0x%lx\n", candev->io_addr, candev->io_addr + IO_RANGE - 1);
76 * bfadcan_elease_io - free reserved io memory range
77 * @candev: pointer to candevice/board which releases io
79 * The function bfadcan_release_io() is used to free reserved io-memory.
80 * In case you have reserved more io memory, don't forget to free it here.
81 * IO_RANGE is the io-memory range that gets released, please adjust according
82 * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
83 * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
84 * Return Value: The function always returns zero
87 int bfadcan_release_io(struct candevice_t *candev)
89 can_release_io_region(candev->io_addr,IO_RANGE);
95 * bfadcan_reset - hardware reset routine
96 * @candev: Pointer to candevice/board structure
98 * The function bfadcan_reset() is used to give a hardware reset. This is
99 * rather hardware specific so I haven't included example code. Don't forget to
100 * check the reset status of the chip before returning.
101 * Return Value: The function returns zero on success or %-ENODEV on failure
102 * File: src/bfadcan.c
104 int bfadcan_reset(struct candevice_t *candev)
108 struct canchip_t *chip=candev->chip[0];
111 bfadcan_write_register(sjaMOD_RM, chip->chip_base_addr+SJAMOD);
114 cdr=bfadcan_read_register(chip->chip_base_addr+SJACDR);
115 bfadcan_write_register(cdr|sjaCDR_PELICAN, chip->chip_base_addr+SJACDR);
117 bfadcan_write_register(0, chip->chip_base_addr+SJAIER);
120 bfadcan_write_register(0, chip->chip_base_addr+SJAMOD);
121 while (bfadcan_read_register(chip->chip_base_addr+SJAMOD)&sjaMOD_RM){
122 if(!i--) return -ENODEV;
124 bfadcan_write_register(0, chip->chip_base_addr+SJAMOD);
127 cdr=bfadcan_read_register(chip->chip_base_addr+SJACDR);
128 bfadcan_write_register(cdr|sjaCDR_PELICAN, chip->chip_base_addr+SJACDR);
130 bfadcan_write_register(0, chip->chip_base_addr+SJAIER);
135 #define RESET_ADDR 0x202
140 * bfadcan_init_hw_data - Initialize hardware cards
141 * @candev: Pointer to candevice/board structure
143 * The function bfadcan_init_hw_data() is used to initialize the hardware
144 * structure containing information about the installed CAN-board.
145 * %RESET_ADDR represents the io-address of the hardware reset register.
146 * %NR_82527 represents the number of intel 82527 chips on the board.
147 * %NR_SJA1000 represents the number of philips sja1000 chips on the board.
148 * The flags entry can currently only be %CANDEV_PROGRAMMABLE_IRQ to indicate that
149 * the hardware uses programmable interrupts.
150 * Return Value: The function always returns zero
151 * File: src/bfadcan.c
153 int bfadcan_init_hw_data(struct candevice_t *candev)
155 candev->res_addr=RESET_ADDR;
156 candev->nr_82527_chips=NR_82527;
157 candev->nr_sja1000_chips=NR_SJA1000;
158 candev->nr_all_chips=NR_82527+NR_SJA1000;
159 candev->flags |= 0 /* CANDEV_PROGRAMMABLE_IRQ */ ;
165 * bfadcan_init_chip_data - Initialize chips
166 * @candev: Pointer to candevice/board structure
167 * @chipnr: Number of the CAN chip on the hardware card
169 * The function bfadcan_init_chip_data() is used to initialize the hardware
170 * structure containing information about the CAN chips.
171 * %CHIP_TYPE represents the type of CAN chip. %CHIP_TYPE can be "i82527" or
173 * The @chip_base_addr entry represents the start of the 'official' memory map
174 * of the installed chip. It's likely that this is the same as the @io_addr
175 * argument supplied at module loading time.
176 * The @clock entry holds the chip clock value in Hz.
177 * The entry @sja_cdr_reg holds hardware specific options for the Clock Divider
178 * register. Options defined in the %sja1000.h file:
179 * %sjaCDR_CLKOUT_MASK, %sjaCDR_CLK_OFF, %sjaCDR_RXINPEN, %sjaCDR_CBP, %sjaCDR_PELICAN
180 * The entry @sja_ocr_reg holds hardware specific options for the Output Control
181 * register. Options defined in the %sja1000.h file:
182 * %sjaOCR_MODE_BIPHASE, %sjaOCR_MODE_TEST, %sjaOCR_MODE_NORMAL, %sjaOCR_MODE_CLOCK,
183 * %sjaOCR_TX0_LH, %sjaOCR_TX1_ZZ.
184 * The entry @int_clk_reg holds hardware specific options for the Clock Out
185 * register. Options defined in the %i82527.h file:
186 * %iCLK_CD0, %iCLK_CD1, %iCLK_CD2, %iCLK_CD3, %iCLK_SL0, %iCLK_SL1.
187 * The entry @int_bus_reg holds hardware specific options for the Bus
188 * Configuration register. Options defined in the %i82527.h file:
189 * %iBUS_DR0, %iBUS_DR1, %iBUS_DT1, %iBUS_POL, %iBUS_CBY.
190 * The entry @int_cpu_reg holds hardware specific options for the cpu interface
191 * register. Options defined in the %i82527.h file:
192 * %iCPU_CEN, %iCPU_MUX, %iCPU_SLP, %iCPU_PWD, %iCPU_DMC, %iCPU_DSC, %iCPU_RST.
193 * Return Value: The function always returns zero
194 * File: src/bfadcan.c
196 int bfadcan_init_chip_data(struct candevice_t *candev, int chipnr)
198 unsigned int id1, id2;
199 sja1000p_fill_chipspecops(candev->chip[chipnr]);
200 candev->chip[chipnr]->chip_base_addr=candev->io_addr;
201 candev->chip[chipnr]->clock = clock_freq;
202 candev->chip[chipnr]->int_cpu_reg = iCPU_DSC;
203 candev->chip[chipnr]->int_clk_reg = iCLK_SL1;
204 candev->chip[chipnr]->int_bus_reg = iBUS_CBY;
205 candev->chip[chipnr]->sja_cdr_reg = sjaCDR_CBP | sjaCDR_CLK_OFF;
206 candev->chip[chipnr]->sja_ocr_reg = sjaOCR_MODE_NORMAL |
212 CANMSG("can driver ver lincan-0.3, at %04lx, CPLD v%d.%d.%d.%d\n",
213 candev->chip[chipnr]->chip_base_addr,
214 id1>>4, id1&0x0f, id2>>4, id2&0x0f);
221 * bfadcan_init_obj_data - Initialize message buffers
222 * @chip: Pointer to chip specific structure
223 * @objnr: Number of the message buffer
225 * The function bfadcan_init_obj_data() is used to initialize the hardware
226 * structure containing information about the different message objects on the
227 * CAN chip. In case of the sja1000 there's only one message object but on the
228 * i82527 chip there are 15.
229 * The code below is for a i82527 chip and initializes the object base addresses
230 * The entry @obj_base_addr represents the first memory address of the message
231 * object. In case of the sja1000 @obj_base_addr is taken the same as the chips
233 * Unless the hardware uses a segmented memory map, flags can be set zero.
234 * Return Value: The function always returns zero
235 * File: src/bfadcan.c
237 int bfadcan_init_obj_data(struct canchip_t *chip, int objnr)
239 chip->msgobj[objnr]->obj_base_addr=chip->chip_base_addr+(objnr+1)*0x10;
245 * bfadcan_program_irq - program interrupts
246 * @candev: Pointer to candevice/board structure
248 * The function bfadcan_program_irq() is used for hardware that uses
249 * programmable interrupts. If your hardware doesn't use programmable interrupts
250 * you should not set the @candevices_t->flags entry to %CANDEV_PROGRAMMABLE_IRQ and
251 * leave this function unedited. Again this function is hardware specific so
252 * there's no example code.
253 * Return value: The function returns zero on success or %-ENODEV on failure
254 * File: src/bfadcan.c
256 int bfadcan_program_irq(struct candevice_t *candev)
262 * bfadcan_write_register - Low level write register routine
263 * @data: data to be written
264 * @address: memory address to write to
266 * The function bfadcan_write_register() is used to write to hardware registers
267 * on the CAN chip. You should only have to edit this function if your hardware
268 * uses some specific write process.
269 * Return Value: The function does not return a value
270 * File: src/bfadcan.c
272 void bfadcan_write_register(unsigned data, unsigned long address)
274 #ifdef WINDOWED_ACCESS
275 can_spin_irqflags_t flags;
276 can_spin_lock_irqsave(&bfadcan_win_lock,flags);
277 outb(address&0x00ff,0x200);
279 can_spin_unlock_irqrestore(&bfadcan_win_lock,flags);
286 * bfadcan_read_register - Low level read register routine
287 * @address: memory address to read from
289 * The function bfadcan_read_register() is used to read from hardware registers
290 * on the CAN chip. You should only have to edit this function if your hardware
291 * uses some specific read process.
292 * Return Value: The function returns the value stored in @address
293 * File: src/bfadcan.c
295 unsigned bfadcan_read_register(unsigned long address)
297 #ifdef WINDOWED_ACCESS
298 can_spin_irqflags_t flags;
300 can_spin_lock_irqsave(&bfadcan_win_lock,flags);
301 outb(address&0x00ff,0x200);
303 can_spin_unlock_irqrestore(&bfadcan_win_lock,flags);
310 /* !!! Don't change this function !!! */
311 int bfadcan_register(struct hwspecops_t *hwspecops)
313 hwspecops->request_io = bfadcan_request_io;
314 hwspecops->release_io = bfadcan_release_io;
315 hwspecops->reset = bfadcan_reset;
316 hwspecops->init_hw_data = bfadcan_init_hw_data;
317 hwspecops->init_chip_data = bfadcan_init_chip_data;
318 hwspecops->init_obj_data = bfadcan_init_obj_data;
319 hwspecops->write_register = bfadcan_write_register;
320 hwspecops->read_register = bfadcan_read_register;
321 hwspecops->program_irq = bfadcan_program_irq;