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 <linux/string.h>
20 #include <asm/errno.h>
23 #include "../include/main.h"
24 #include "../include/pip.h"
25 #include "../include/i82527.h"
27 int pip5_request_io(unsigned long io_addr)
29 if (io_addr != 0x8000) {
30 CANMSG("Invalid base io address\n");
31 CANMSG("The PIP5 uses a fixed base address of 0x8000,\n");
32 CANMSG("please consult your user manual.\n");
35 if (check_region(io_addr,0x100)) {
36 CANMSG("Unable to open port: 0x%lx\n",io_addr);
39 else if(check_region(io_addr+0x102,0x01)) {
40 CANMSG("Unable to open port: 0x%lx\n",io_addr+0x102);
44 request_region(io_addr,0x100,DEVICE_NAME);
45 DEBUGMSG("Registered IO-memory: 0x%lx - 0x%lx\n", io_addr, io_addr + 0x100 - 1);
46 request_region(io_addr+0x102,0x01,DEVICE_NAME);
47 DEBUGMSG("Registered IO-memory: 0x%lx\n", io_addr+0x102);
52 int pip6_request_io(unsigned long io_addr)
54 if ( (io_addr != 0x1000)&&(io_addr != 0x8000)&&(io_addr != 0xe000)) {
55 CANMSG("Invalid base io address\n");
56 CANMSG("Valid values for the PIP6 are: 0x1000, 0x8000 or 0xe000\n");
57 CANMSG("Please consult your user manual.\n");
60 if (check_region(io_addr,0x100)) {
61 CANMSG("Unable to open port: 0x%lx\n",io_addr);
64 else if (check_region(0x804, 0x02)) {
65 CANMSG("Unable to open port: 0x%x\n", 0x804);
69 request_region(io_addr,0x100, DEVICE_NAME);
70 DEBUGMSG("Registered IO-memory: 0x%lx - 0x%lx\n", io_addr, io_addr + 0x100 -1);
71 request_region(0x804,0x02,DEVICE_NAME);
72 DEBUGMSG("Registered IO-memory : 0x%x - 0x%x\n",0x804,0x805);
77 int pip5_release_io(unsigned long io_addr)
79 release_region(io_addr,0x100);
80 release_region(io_addr+0x102,0x01);
85 int pip6_release_io(unsigned long io_addr)
87 release_region(io_addr,0x100);
88 release_region(0x804,0x02);
93 int pip_reset(int card)
97 DEBUGMSG("Resetting %s hardware ...\n", candevices_p[card]->hwname);
98 if (!strcmp(candevices_p[card]->hwname,"pip5"))
102 while (i < 1000000) {
104 outb(res_value,candevices_p[card]->res_addr);
106 outb(0x0,candevices_p[card]->res_addr);
108 /* Check hardware reset status */
110 while ( (inb(candevices_p[card]->io_addr+iCPU) & iCPU_RST) && (i<=15)) {
115 CANMSG("Reset status timeout!\n");
116 CANMSG("Please check your hardware.\n");
120 DEBUGMSG("Chip0 reset status ok.\n");
126 int pip_init_hw_data(int card)
128 if (!strcmp(candevices_p[card]->hwname,"pip5"))
129 candevices_p[card]->res_addr=candevices_p[card]->io_addr+0x102;
131 candevices_p[card]->res_addr=0x805;
132 candevices_p[card]->nr_82527_chips=1;
133 candevices_p[card]->nr_sja1000_chips=0;
134 candevices_p[card]->flags |= PROGRAMMABLE_IRQ;
139 int pip_init_chip_data(int card, int chipnr)
141 candevices_p[card]->chip[chipnr]->chip_type="i82527";
142 candevices_p[card]->chip[chipnr]->chip_base_addr=candevices_p[card]->io_addr;
143 candevices_p[card]->chip[chipnr]->clock = 16000000;
144 if (!strcmp(candevices_p[card]->hwname,"pip5"))
145 candevices_p[card]->chip[chipnr]->int_cpu_reg = iCPU_DSC;
147 candevices_p[card]->chip[chipnr]->int_cpu_reg = 0x0;
148 candevices_p[card]->chip[chipnr]->int_clk_reg = iCLK_SL1;
149 candevices_p[card]->chip[chipnr]->int_bus_reg = iBUS_CBY;
150 candevices_p[card]->chip[chipnr]->sja_cdr_reg = 0;
151 candevices_p[card]->chip[chipnr]->sja_ocr_reg = 0;
156 int pip_init_obj_data(int chipnr, int objnr)
158 chips_p[chipnr]->msgobj[objnr]->obj_base_addr=chips_p[chipnr]->chip_base_addr+(objnr+1)*0x10;
159 chips_p[chipnr]->msgobj[objnr]->flags=0;
164 int pip5_program_irq(int card)
166 outb(0x01, candevices_p[card]->res_addr);
167 switch (candevices_p[card]->chip[0]->chip_irq) {
168 case 3: { outb(0x03, candevices_p[card]->res_addr); break; }
169 case 4: { outb(0x05, candevices_p[card]->res_addr); break; }
170 case 5: { outb(0x07, candevices_p[card]->res_addr); break; }
171 case 10: { outb(0x09, candevices_p[card]->res_addr); break; }
172 case 11: { outb(0x0c, candevices_p[card]->res_addr); break; }
173 case 15: { outb(0x0d, candevices_p[card]->res_addr); break; }
175 CANMSG("Supplied interrupt is not supported by the hardware\n");
176 CANMSG("Please consult your user manual.\n");
180 outb(0x00, candevices_p[card]->res_addr);
185 int pip6_program_irq(int card)
187 unsigned char can_int = 0, can_addr = 0;
189 can_int = candevices_p[card]->chip[0]->chip_irq;
190 if ((can_int != 3) && (can_int != 4) && (can_int != 5) && (can_int != 6)
191 && (can_int != 7) && (can_int != 9) && (can_int != 10) &&
192 (can_int != 11) && (can_int != 12) && (can_int != 14) &&
194 CANMSG("Invalid interrupt number\n");
195 CANMSG("Valid interrupt numbers for the PIP6: 3,4,5,6,7,9,10,11,12,14 or 15\n");
196 CANMSG("Please consult your user manual.\n");
199 switch (candevices_p[card]->io_addr) {
200 case 0x1000: { can_addr = 0x01; break; }
201 case 0x8000: { can_addr = 0x02; break; }
202 case 0xe000: { can_addr = 0x03; break; }
204 CANMSG("Supplied io address is not valid, please check your manual\n");
208 outb( (can_int<<4)|can_addr, 0x804);
213 void pip_write_register(unsigned char data, unsigned long address)
218 unsigned pip_read_register(unsigned long address)
223 /* !!! Don't change these functions !!! */
224 int pip5_register(struct hwspecops_t *hwspecops)
226 hwspecops->request_io = pip5_request_io;
227 hwspecops->release_io = pip5_release_io;
228 hwspecops->reset = pip_reset;
229 hwspecops->init_hw_data = pip_init_hw_data;
230 hwspecops->init_chip_data = pip_init_chip_data;
231 hwspecops->init_obj_data = pip_init_obj_data;
232 hwspecops->write_register = pip_write_register;
233 hwspecops->read_register = pip_read_register;
234 hwspecops->program_irq = pip5_program_irq;
238 int pip6_register(struct hwspecops_t *hwspecops)
240 hwspecops->request_io = pip6_request_io;
241 hwspecops->release_io = pip6_release_io;
242 hwspecops->reset = pip_reset;
243 hwspecops->init_hw_data = pip_init_hw_data;
244 hwspecops->init_chip_data = pip_init_chip_data;
245 hwspecops->init_obj_data = pip_init_obj_data;
246 hwspecops->write_register = pip_write_register;
247 hwspecops->read_register = pip_read_register;
248 hwspecops->program_irq = pip6_program_irq;