2 * Linux CAN-bus device driver.
3 * Written by Arnaud Westenberg email:arnaud@casema.net
4 * This software is released under the GPL-License.
5 * Version 0.6 18 Sept 2000
8 #include <linux/autoconf.h>
9 #if defined (CONFIG_MODVERSIONS) && !defined (MODVERSIONS)
14 #include <linux/modversions.h>
17 #include <linux/ioport.h>
18 #include <linux/delay.h>
19 #include <asm/errno.h>
23 #include "../include/main.h"
24 #include "../include/ssv.h"
25 #include "../include/i82527.h"
27 int ssvcan_irq[2]={-1,-1};
28 unsigned long ssvcan_base=0x0;
30 /* IO_RANGE is the io-memory range that gets reserved, please adjust according
31 * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
32 * #define IO_RANGE 0x20 for sja1000 chips.
36 /* The function template_request_io is used to reserve the io-memory. If your
37 * hardware uses a dedicated memory range as hardware control registers you
38 * will have to add the code to reserve this memory as well.
39 * The reserved memory starts at io_addr, wich is the module parameter io.
41 int ssv_request_io(unsigned long io_addr)
44 if (check_region(io_addr,IO_RANGE)) {
45 CANMSG("Unable to open port: 0x%lx\n",io_addr);
49 request_region(io_addr,IO_RANGE,DEVICE_NAME);
50 DEBUGMSG("Registered IO-memory: 0x%lx - 0x%lx\n", io_addr,
51 io_addr + IO_RANGE - 1);
56 /* The function template_release_io is used to free the previously reserved
57 * io-memory. In case you reserved more memory, don't forget to free it here.
59 int ssv_release_io(unsigned long io_addr)
62 release_region(io_addr,IO_RANGE);
67 /* The function template_reset is used to give a hardware reset. This is rather
68 * hardware specific so I haven't included example code. Don't forget to check
69 * the reset status of the chip before returning.
71 int ssv_reset(int card)
75 DEBUGMSG("Resetting ssv hardware ...\n");
76 ssv_write_register(1,ssvcan_base+iCPU);
77 ssv_write_register(0,ssvcan_base+iCPU);
78 ssv_write_register(1,ssvcan_base+0x100+iCPU);
79 ssv_write_register(0,ssvcan_base+0x100+iCPU);
81 for (i = 1; i < 1000; i++)
84 /* Check hardware reset status */
86 while ( (ssv_read_register(ssvcan_base+iCPU) & iCPU_RST) && (i<=15)) {
91 CANMSG("Reset status timeout!\n");
92 CANMSG("Please check your hardware.\n");
96 DEBUGMSG("Chip0 reset status ok.\n");
98 /* Check hardware reset status */
100 while ( (ssv_read_register(ssvcan_base+0x100+iCPU) & iCPU_RST) && (i<=15)) {
105 CANMSG("Reset status timeout!\n");
106 CANMSG("Please check your hardware.\n");
110 DEBUGMSG("Chip1 reset status ok.\n");
117 /* The function template_init_hw_data is used to initialize the hardware
118 * structure containing information about the installed CAN-board.
119 * RESET_ADDR represents the io-address of the hardware reset register.
120 * NR_82527 represents the number of intel 82527 chips on the board.
121 * NR_SJA1000 represents the number of philips sja1000 chips on the board.
122 * The flags entry can currently only be PROGRAMMABLE_IRQ to indicate that
123 * the hardware uses programmable interrupts.
125 #define RESET_ADDR 0x02
129 int ssv_init_hw_data(int card)
131 candevices_p[card]->res_addr=RESET_ADDR;
132 candevices_p[card]->nr_82527_chips=NR_82527;
133 candevices_p[card]->nr_sja1000_chips=0;
134 candevices_p[card]->flags |= PROGRAMMABLE_IRQ;
139 /* The function template_init_chip_data is used to initialize the hardware
140 * structure containing information about the CAN chips.
141 * CHIP_TYPE represents the type of CAN chip. CHIP_TYPE can be "i82527" or
143 * The chip_base_addr entry represents the start of the 'official' memory map
144 * of the installed chip. It's likely that this is the same as the io_addr
145 * argument supplied at module loading time.
146 * The clock argument holds the chip clock value in Hz.
148 #define CHIP_TYPE "i82527"
150 int ssv_init_chip_data(int card, int chipnr)
152 candevices_p[card]->chip[chipnr]->chip_type=CHIP_TYPE;
153 candevices_p[card]->chip[chipnr]->chip_base_addr=
154 candevices_p[card]->io_addr+0x100*chipnr;
155 candevices_p[card]->chip[chipnr]->clock = 16000000;
156 ssvcan_irq[chipnr]=candevices_p[card]->chip[chipnr]->chip_irq;
158 ssvcan_base=candevices_p[card]->io_addr;
160 candevices_p[card]->chip[chipnr]->int_cpu_reg = iCPU_DSC;
161 candevices_p[card]->chip[chipnr]->int_clk_reg = iCLK_SL1;
162 candevices_p[card]->chip[chipnr]->int_bus_reg = iBUS_CBY;
166 /* The function template_init_obj_data is used to initialize the hardware
167 * structure containing information about the different message objects on the
168 * CAN chip. In case of the sja1000 there's only one message object but on the
169 * i82527 chip there are 15.
170 * The code below is for a i82527 chip and initializes the object base addresses
171 * The entry obj_base_addr represents the first memory address of the message
172 * object. In case of the sja1000 obj_base_addr is taken the same as the chips
174 * Unless the hardware uses a segmented memory map, flags can be set zero.
176 int ssv_init_obj_data(int chipnr, int objnr)
179 chips_p[chipnr]->msgobj[objnr]->obj_base_addr=
180 chips_p[chipnr]->chip_base_addr+(objnr+1)*0x10;
181 chips_p[chipnr]->msgobj[objnr]->flags=0;
186 /* The function template_program_irq is used for hardware that uses programmable
187 * interrupts. If your hardware doesn't use programmable interrupts you should
188 * not set the candevices_t->flags entry to PROGRAMMABLE_IRQ and leave this
189 * function unedited. Again this function is hardware specific so there's no
192 int ssv_program_irq(int card)
197 /* The function template_write_register is used to write to hardware registers
198 * on the CAN chip. You should only have to edit this function if your hardware
199 * uses some specific write process.
201 void ssv_write_register(unsigned char data, unsigned long address)
203 /* address is an absolute address */
205 /* the ssv card has two registers, the address register at 0x0
206 and the data register at 0x01 */
208 /* write the relative address on the eight LSB bits
209 and the data on the eight MSB bits in one time */
210 if((address-ssvcan_base)<0x100)
211 outw(address-ssvcan_base + (256 * data), ssvcan_base);
213 outw(address-ssvcan_base-0x100 + (256 * data), ssvcan_base+0x02);
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.
220 unsigned ssv_read_register(unsigned long address)
222 /* this is the same thing that the function write_register.
223 We use the two register, we write the address where we
224 want to read in a first time. In a second time we read the
229 if((address-ssvcan_base)<0x100)
231 disable_irq(ssvcan_irq[0]);
232 outb(address-ssvcan_base, ssvcan_base);
233 ret=inb(ssvcan_base+1);
234 enable_irq(ssvcan_irq[0]);
238 disable_irq(ssvcan_irq[1]);
239 outb(address-ssvcan_base-0x100, ssvcan_base+0x02);
240 ret=inb(ssvcan_base+1+0x02);
241 enable_irq(ssvcan_irq[1]);
248 /* !!! Don't change this function !!! */
249 int ssv_register(struct hwspecops_t *hwspecops)
251 hwspecops->request_io = ssv_request_io;
252 hwspecops->release_io = ssv_release_io;
253 hwspecops->reset = ssv_reset;
254 hwspecops->init_hw_data = ssv_init_hw_data;
255 hwspecops->init_chip_data = ssv_init_chip_data;
256 hwspecops->init_obj_data = ssv_init_obj_data;
257 hwspecops->write_register = ssv_write_register;
258 hwspecops->read_register = ssv_read_register;
259 hwspecops->program_irq = ssv_program_irq;