2 * Linux CAN-bus device driver.
3 * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
4 * This software is released under the GPL-License.
5 * Version 0.7 6 Aug 2001
8 #include <linux/autoconf.h>
9 #if defined (CONFIG_MODVERSIONS) && !defined (MODVERSIONS)
13 #if 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/nsi.h"
25 #include "../include/i82527.h"
28 unsigned long nsican_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 nsi_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 nsi_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 nsi_reset(int card)
75 DEBUGMSG("Resetting nsi hardware ...\n");
76 /* we don't use template_write_register because we don't use the two first
77 register of the card but the third in order to make a hard reset */
78 outb (1, nsican_base + candevices_p[card]->res_addr);
79 outb (0, nsican_base + candevices_p[card]->res_addr);
80 for (i = 1; i < 1000; i++)
84 /* Check hardware reset status */
86 while ( (nsi_read_register(nsican_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");
101 /* The function template_init_hw_data is used to initialize the hardware
102 * structure containing information about the installed CAN-board.
103 * RESET_ADDR represents the io-address of the hardware reset register.
104 * NR_82527 represents the number of intel 82527 chips on the board.
105 * NR_SJA1000 represents the number of philips sja1000 chips on the board.
106 * The flags entry can currently only be PROGRAMMABLE_IRQ to indicate that
107 * the hardware uses programmable interrupts.
109 #define RESET_ADDR 0x02
113 int nsi_init_hw_data(int card)
115 candevices_p[card]->res_addr=RESET_ADDR;
116 candevices_p[card]->nr_82527_chips=1;
117 candevices_p[card]->nr_sja1000_chips=0;
118 candevices_p[card]->flags |= PROGRAMMABLE_IRQ;
123 /* The function template_init_chip_data is used to initialize the hardware
124 * structure containing information about the CAN chips.
125 * CHIP_TYPE represents the type of CAN chip. CHIP_TYPE can be "i82527" or
127 * The chip_base_addr entry represents the start of the 'official' memory map
128 * of the installed chip. It's likely that this is the same as the io_addr
129 * argument supplied at module loading time.
130 * The clock argument holds the chip clock value in Hz.
132 #define CHIP_TYPE "i82527"
134 int nsi_init_chip_data(int card, int chipnr)
136 candevices_p[card]->chip[chipnr]->chip_type=CHIP_TYPE;
137 candevices_p[card]->chip[chipnr]->chip_base_addr=
138 candevices_p[card]->io_addr;
139 candevices_p[card]->chip[chipnr]->clock = 16000000;
140 nsican_irq=candevices_p[card]->chip[chipnr]->chip_irq;
141 nsican_base=candevices_p[card]->chip[chipnr]->chip_base_addr;
142 candevices_p[card]->chip[chipnr]->int_cpu_reg = iCPU_DSC;
143 candevices_p[card]->chip[chipnr]->int_clk_reg = iCLK_SL1;
144 candevices_p[card]->chip[chipnr]->int_bus_reg = iBUS_CBY;
149 /* The function template_init_obj_data is used to initialize the hardware
150 * structure containing information about the different message objects on the
151 * CAN chip. In case of the sja1000 there's only one message object but on the
152 * i82527 chip there are 15.
153 * The code below is for a i82527 chip and initializes the object base addresses
154 * The entry obj_base_addr represents the first memory address of the message
155 * object. In case of the sja1000 obj_base_addr is taken the same as the chips
157 * Unless the hardware uses a segmented memory map, flags can be set zero.
159 int nsi_init_obj_data(int chipnr, int objnr)
162 chips_p[chipnr]->msgobj[objnr]->obj_base_addr=
163 chips_p[chipnr]->chip_base_addr+(objnr+1)*0x10;
164 chips_p[chipnr]->msgobj[objnr]->flags=0;
169 /* The function template_program_irq is used for hardware that uses programmable
170 * interrupts. If your hardware doesn't use programmable interrupts you should
171 * not set the candevices_t->flags entry to PROGRAMMABLE_IRQ and leave this
172 * function unedited. Again this function is hardware specific so there's no
175 int nsi_program_irq(int card)
180 /* The function template_write_register is used to write to hardware registers
181 * on the CAN chip. You should only have to edit this function if your hardware
182 * uses some specific write process.
184 void nsi_write_register(unsigned char data, unsigned long address)
186 /* address is an absolute address */
188 /* the nsi card has two registers, the address register at 0x0
189 and the data register at 0x01 */
191 /* write the relative address on the eight LSB bits
192 and the data on the eight MSB bits in one time */
193 outw(address-nsican_base + (256 * data), nsican_base);
196 /* The function template_read_register is used to read from hardware registers
197 * on the CAN chip. You should only have to edit this function if your hardware
198 * uses some specific read process.
200 unsigned nsi_read_register(unsigned long address)
202 /* this is the same thing that the function write_register.
203 We use the two register, we write the address where we
204 want to read in a first time. In a second time we read the
208 disable_irq(nsican_irq);
209 outb(address-nsican_base, nsican_base);
210 ret=inb(nsican_base+1);
211 enable_irq(nsican_irq);
216 /* !!! Don't change this function !!! */
217 int nsi_register(struct hwspecops_t *hwspecops)
219 hwspecops->request_io = nsi_request_io;
220 hwspecops->release_io = nsi_release_io;
221 hwspecops->reset = nsi_reset;
222 hwspecops->init_hw_data = nsi_init_hw_data;
223 hwspecops->init_chip_data = nsi_init_chip_data;
224 hwspecops->init_obj_data = nsi_init_obj_data;
225 hwspecops->write_register = nsi_write_register;
226 hwspecops->read_register = nsi_read_register;
227 hwspecops->program_irq = nsi_program_irq;