]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/template.c
Changed filling of the chip specific operations.
[lincan.git] / lincan / src / template.c
1 /* template.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
10 /* This file is intended as a template 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=template.
13  */
14
15 #include "../include/can.h"
16 #include "../include/can_sysdep.h"
17 #include "../include/main.h"
18 #include "../include/template.h"
19 #include "../include/i82527.h"
20 #include "../include/sja1000.h"
21
22 /*
23  * IO_RANGE is the io-memory range that gets reserved, please adjust according
24  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
25  * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
26  */
27 #define IO_RANGE 0x100
28
29 /**
30  * template_request_io: - reserve io or memory range for can board
31  * @candev: pointer to candevice/board which asks for io. Field @io_addr
32  *      of @candev is used in most cases to define start of the range
33  *
34  * The function template_request_io() is used to reserve the io-memory. If your
35  * hardware uses a dedicated memory range as hardware control registers you
36  * will have to add the code to reserve this memory as well. 
37  * %IO_RANGE is the io-memory range that gets reserved, please adjust according
38  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
39  * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
40  * Return Value: The function returns zero on success or %-ENODEV on failure
41  * File: src/template.c
42  */
43 int template_request_io(struct candevice_t *candev)
44 {
45         if (!can_request_io_region(candev->io_addr,IO_RANGE,DEVICE_NAME)) {
46                 CANMSG("Unable to open port: 0x%lx\n",candev->io_addr);
47                 return -ENODEV;
48         }else {
49                 DEBUGMSG("Registered IO-memory: 0x%lx - 0x%lx\n", candev->io_addr, candev->io_addr + IO_RANGE - 1);
50         }
51         return 0;
52 }
53
54 /**
55  * template_release_io - free reserved io memory range
56  * @candev: pointer to candevice/board which releases io
57  *
58  * The function template_release_io() is used to free reserved io-memory.
59  * In case you have reserved more io memory, don't forget to free it here.
60  * IO_RANGE is the io-memory range that gets released, please adjust according
61  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
62  * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
63  * Return Value: The function always returns zero
64  * File: src/template.c
65  */
66 int template_release_io(struct candevice_t *candev)
67 {
68         can_release_io_region(candev->io_addr,IO_RANGE);
69
70         return 0;
71 }
72
73 /**
74  * template_reset - hardware reset routine
75  * @candev: Pointer to candevice/board structure
76  *
77  * The function template_reset() is used to give a hardware reset. This is 
78  * rather hardware specific so I haven't included example code. Don't forget to 
79  * check the reset status of the chip before returning.
80  * Return Value: The function returns zero on success or %-ENODEV on failure
81  * File: src/template.c
82  */
83 int template_reset(struct candevice_t *candev)
84 {
85         return 0;
86 }
87
88 #define RESET_ADDR 0x0
89 #define NR_82527 1
90 #define NR_SJA1000 0
91
92 /**
93  * template_init_hw_data - Initialize hardware cards
94  * @candev: Pointer to candevice/board structure
95  *
96  * The function template_init_hw_data() is used to initialize the hardware
97  * structure containing information about the installed CAN-board.
98  * %RESET_ADDR represents the io-address of the hardware reset register.
99  * %NR_82527 represents the number of Intel 82527 chips on the board.
100  * %NR_SJA1000 represents the number of Philips sja1000 chips on the board.
101  * The flags entry can currently only be %CANDEV_PROGRAMMABLE_IRQ to indicate that
102  * the hardware uses programmable interrupts.
103  * Return Value: The function always returns zero
104  * File: src/template.c
105  */
106 int template_init_hw_data(struct candevice_t *candev) 
107 {
108         candev->res_addr=RESET_ADDR;
109         candev->nr_82527_chips=NR_82527;
110         candev->nr_sja1000_chips=NR_SJA1000;
111         candev->nr_all_chips=NR_82527+NR_SJA1000;
112         candev->flags |= CANDEV_PROGRAMMABLE_IRQ;
113
114         return 0;
115 }
116
117 /**
118  * template_init_chip_data - Initialize chips
119  * @candev: Pointer to candevice/board structure
120  * @chipnr: Number of the CAN chip on the hardware card
121  *
122  * The function template_init_chip_data() is used to initialize the hardware
123  * structure containing information about the CAN chips.
124  * %CHIP_TYPE represents the type of CAN chip. %CHIP_TYPE can be "i82527" or
125  * "sja1000".
126  * The @chip_base_addr entry represents the start of the 'official' memory map
127  * of the installed chip. It's likely that this is the same as the @io_addr
128  * argument supplied at module loading time.
129  * The @clock entry holds the chip clock value in Hz.
130  * The entry @sja_cdr_reg holds hardware specific options for the Clock Divider
131  * register. Options defined in the %sja1000.h file:
132  * %sjaCDR_CLKOUT_MASK, %sjaCDR_CLK_OFF, %sjaCDR_RXINPEN, %sjaCDR_CBP, %sjaCDR_PELICAN
133  * The entry @sja_ocr_reg holds hardware specific options for the Output Control
134  * register. Options defined in the %sja1000.h file:
135  * %sjaOCR_MODE_BIPHASE, %sjaOCR_MODE_TEST, %sjaOCR_MODE_NORMAL, %sjaOCR_MODE_CLOCK,
136  * %sjaOCR_TX0_LH, %sjaOCR_TX1_ZZ.
137  * The entry @int_clk_reg holds hardware specific options for the Clock Out
138  * register. Options defined in the %i82527.h file:
139  * %iCLK_CD0, %iCLK_CD1, %iCLK_CD2, %iCLK_CD3, %iCLK_SL0, %iCLK_SL1.
140  * The entry @int_bus_reg holds hardware specific options for the Bus 
141  * Configuration register. Options defined in the %i82527.h file:
142  * %iBUS_DR0, %iBUS_DR1, %iBUS_DT1, %iBUS_POL, %iBUS_CBY.
143  * The entry @int_cpu_reg holds hardware specific options for the cpu interface
144  * register. Options defined in the %i82527.h file:
145  * %iCPU_CEN, %iCPU_MUX, %iCPU_SLP, %iCPU_PWD, %iCPU_DMC, %iCPU_DSC, %iCPU_RST.
146  * Return Value: The function always returns zero
147  * File: src/template.c
148  */
149 int template_init_chip_data(struct candevice_t *candev, int chipnr)
150 {
151         i82527_fill_chipspecops(candev->chip[chipnr]);
152         /*sja1000_fill_chipspecops(candev->chip[chipnr]);*/
153         /*sja1000p_fill_chipspecops(candev->chip[chipnr]);*/
154         
155         candev->chip[chipnr]->chip_base_addr=candev->io_addr;
156         candev->chip[chipnr]->clock = 16000000;
157         candev->chip[chipnr]->int_cpu_reg = iCPU_DSC;
158         candev->chip[chipnr]->int_clk_reg = iCLK_SL1;
159         candev->chip[chipnr]->int_bus_reg = iBUS_CBY;
160         candev->chip[chipnr]->sja_cdr_reg = sjaCDR_CBP | sjaCDR_CLK_OFF;
161         candev->chip[chipnr]->sja_ocr_reg = sjaOCR_MODE_NORMAL |
162                                                                 sjaOCR_TX0_LH;
163
164         return 0;
165 }
166
167 /**
168  * template_init_obj_data - Initialize message buffers
169  * @chip: Pointer to chip specific structure
170  * @objnr: Number of the message buffer
171  *
172  * The function template_init_obj_data() is used to initialize the hardware
173  * structure containing information about the different message objects on the
174  * CAN chip. In case of the sja1000 there's only one message object but on the
175  * i82527 chip there are 15.
176  * The code below is for a i82527 chip and initializes the object base addresses
177  * The entry @obj_base_addr represents the first memory address of the message 
178  * object. In case of the sja1000 @obj_base_addr is taken the same as the chips
179  * base address.
180  * Unless the hardware uses a segmented memory map, flags can be set zero.
181  * Return Value: The function always returns zero
182  * File: src/template.c
183  */
184 int template_init_obj_data(struct chip_t *chip, int objnr)
185 {
186         chip->msgobj[objnr]->obj_base_addr=chip->chip_base_addr+(objnr+1)*0x10;
187         
188         return 0;
189 }
190
191 /**
192  * template_program_irq - program interrupts
193  * @candev: Pointer to candevice/board structure
194  *
195  * The function template_program_irq() is used for hardware that uses 
196  * programmable interrupts. If your hardware doesn't use programmable interrupts
197  * you should not set the @candevices_t->flags entry to %CANDEV_PROGRAMMABLE_IRQ and 
198  * leave this function unedited. Again this function is hardware specific so 
199  * there's no example code.
200  * Return value: The function returns zero on success or %-ENODEV on failure
201  * File: src/template.c
202  */
203 int template_program_irq(struct candevice_t *candev)
204 {
205         return 0;
206 }
207
208 /**
209  * template_write_register - Low level write register routine
210  * @data: data to be written
211  * @address: memory address to write to
212  *
213  * The function template_write_register() is used to write to hardware registers
214  * on the CAN chip. You should only have to edit this function if your hardware
215  * uses some specific write process.
216  * Return Value: The function does not return a value
217  * File: src/template.c
218  */
219 void template_write_register(unsigned data, unsigned long address)
220 {
221         outb(data,address);
222 }
223
224 /**
225  * template_read_register - Low level read register routine
226  * @address: memory address to read from
227  *
228  * The function template_read_register() is used to read from hardware registers
229  * on the CAN chip. You should only have to edit this function if your hardware
230  * uses some specific read process.
231  * Return Value: The function returns the value stored in @address
232  * File: src/template.c
233  */
234 unsigned template_read_register(unsigned long address)
235 {
236         return inb(address);
237 }
238
239 /* !!! Don't change this function !!! */
240 int template_register(struct hwspecops_t *hwspecops)
241 {
242         hwspecops->request_io = template_request_io;
243         hwspecops->release_io = template_release_io;
244         hwspecops->reset = template_reset;
245         hwspecops->init_hw_data = template_init_hw_data;
246         hwspecops->init_chip_data = template_init_chip_data;
247         hwspecops->init_obj_data = template_init_obj_data;
248         hwspecops->write_register = template_write_register;
249         hwspecops->read_register = template_read_register;
250         hwspecops->program_irq = template_program_irq;
251         return 0;
252 }