]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/oscar.c
00f3616ac747ae365ccd87edca4bcccc26d8633c
[lincan.git] / lincan / src / oscar.c
1 /* oscar.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  NOTE: Please see the template.c file for the comments relating to this code.
10        Herein is the modified copy of the functions
11
12  */ 
13 #include "../include/can.h"
14 #include "../include/can_sysdep.h"
15 #include "../include/main.h"
16 #include "../include/oscar.h"
17 #include "../include/i82527.h"
18 #include "../include/sja1000.h"
19
20 #define IO_RANGE 0x80 // allow both basic CAN and PeliCAN modes for sja1000
21
22 int oscar_request_io(struct candevice_t *candev)
23 {
24         if (!can_request_io_region(candev->io_addr,IO_RANGE,DEVICE_NAME)) {
25                 CANMSG("Unable to open port: 0x%lx\n",candev->io_addr);
26                 return -ENODEV;
27         }else {
28                 DEBUGMSG("Registered IO-memory: 0x%lx - 0x%lx\n", candev->io_addr, candev->io_addr + IO_RANGE - 1);
29         }
30         return 0;
31 }
32
33 int oscar_release_io(struct candevice_t *candev)
34 {
35         can_release_io_region(candev->io_addr,IO_RANGE);
36
37         return 0;
38 }
39
40 int oscar_reset(struct candevice_t *candev)
41 {
42     DEBUGMSG("Cannot issue a hardware reset to the CAN chip.");
43     return -ENODEV;
44 }
45
46 int oscar_init_hw_data(struct candevice_t *candev) 
47 {
48     candev->res_addr = 0x0; // RESET address?
49     candev->nr_82527_chips = 0;
50     candev->nr_sja1000_chips = 1; // We've got a SJA1000 variant
51     candev->nr_all_chips= 1;
52     candev->flags |= CANDEV_PROGRAMMABLE_IRQ;
53
54     return 0;
55 }
56
57 int oscar_init_chip_data(struct candevice_t *candev, int chipnr)
58 {
59     // i82527_fill_chipspecops(candev->chip[chipnr]);
60     sja1000_fill_chipspecops(candev->chip[chipnr]);
61     // sja1000p_fill_chipspecops(candev->chip[chipnr]);
62         
63     candev->chip[chipnr]->chip_base_addr = candev->io_addr;
64     candev->chip[chipnr]->clock = 12000000;
65     candev->chip[chipnr]->sja_cdr_reg = sjaCDR_CBP;  // we use an external tranceiver
66     candev->chip[chipnr]->sja_ocr_reg = sjaOCR_MODE_NORMAL | sjaOCR_TX0_LH;
67     // these three int_ registers are unused (we don't have this chip)
68     candev->chip[chipnr]->int_cpu_reg = 0;
69     candev->chip[chipnr]->int_clk_reg = 0;
70     candev->chip[chipnr]->int_bus_reg = 0;
71     
72     return 0;
73 }
74
75 int oscar_init_obj_data(struct canchip_t *chip, int objnr)
76 {
77     chip->msgobj[objnr]->obj_base_addr = chip->chip_base_addr;
78     
79     return 0;
80 }
81
82 int oscar_program_irq(struct candevice_t *candev)
83 {
84     // CAN_IRQ_L (active low) interrupt: PF2 / INT2 on our LH7A400 SoC
85     // This IRQ is set up already by the kernel.    
86
87     return 0;
88 }
89
90 void oscar_write_register(unsigned data, unsigned long address)
91 {
92         outb(data,address);
93 }
94
95 unsigned oscar_read_register(unsigned long address)
96 {
97         return inb(address);
98 }
99
100 /* !!! Don't change this function !!! */
101 int oscar_register(struct hwspecops_t *hwspecops)
102 {
103         hwspecops->request_io = oscar_request_io;
104         hwspecops->release_io = oscar_release_io;
105         hwspecops->reset = oscar_reset;
106         hwspecops->init_hw_data = oscar_init_hw_data;
107         hwspecops->init_chip_data = oscar_init_chip_data;
108         hwspecops->init_obj_data = oscar_init_obj_data;
109         hwspecops->write_register = oscar_write_register;
110         hwspecops->read_register = oscar_read_register;
111         hwspecops->program_irq = oscar_program_irq;
112         return 0;
113 }