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>
22 #include "../include/main.h"
23 #include "../include/pcm3680.h"
24 #include "../include/i82527.h"
25 #include "../include/sja1000p.h"
27 /* Basic hardware io address. This is also stored in the hardware structure but
28 * we need it global, else we have to change many internal functions.
29 * pcm3680_base_addr is initialized in pcm3680_init_chip_data().
31 unsigned int pcm3680_base_addr;
34 * IO_RANGE is the io-memory range that gets reserved, please adjust according
35 * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
36 * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
38 #define IO_RANGE 0x200
41 * template_request_io: - reserve io memory
42 * @io_addr: The reserved memory starts at @io_addr, wich is the module
45 * The function template_request_io() is used to reserve the io-memory. If your
46 * hardware uses a dedicated memory range as hardware control registers you
47 * will have to add the code to reserve this memory as well.
48 * %IO_RANGE is the io-memory range that gets reserved, please adjust according
49 * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
50 * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
51 * Return Value: The function returns zero on success or %-ENODEV on failure
52 * File: src/template.c
54 int pcm3680_request_io(unsigned long io_addr)
56 if (check_region(io_addr,IO_RANGE)) {
57 CANMSG("Unable to open port: 0x%lx\n",io_addr);
61 request_region(io_addr,IO_RANGE,DEVICE_NAME);
62 DEBUGMSG("Registered IO-memory: 0x%lx - 0x%lx\n", io_addr, io_addr + IO_RANGE - 1);
68 * template_release_io - free reserved io-memory
69 * @io_addr: Start of the memory range to be released.
71 * The function template_release_io() is used to free reserved io-memory.
72 * In case you have reserved more io memory, don't forget to free it here.
73 * IO_RANGE is the io-memory range that gets released, please adjust according
74 * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
75 * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
76 * Return Value: The function always returns zero
77 * File: src/template.c
79 int pcm3680_release_io(unsigned long io_addr)
81 release_region(io_addr,IO_RANGE);
87 * template_reset - hardware reset routine
88 * @card: Number of the hardware card.
90 * The function template_reset() is used to give a hardware reset. This is
91 * rather hardware specific so I haven't included example code. Don't forget to
92 * check the reset status of the chip before returning.
93 * Return Value: The function returns zero on success or %-ENODEV on failure
94 * File: src/template.c
96 int pcm3680_reset(int card)
100 // DEBUGMSG("Resetting pcm3680 hardware ...\n");
101 // pcm3680_write_register(0x01, candevices_p[card]->io_addr +
102 // 0x100); // Write arbitrary data to reset mem
103 // pcm3680_write_register(0x01, candevices_p[card]->io_addr +
104 // 0x300); // Write arbitrary data to reset mem
107 // pcm3680_write_register(0x00, candevices_p[card]->io_addr + SJACR);
108 // pcm3680_write_register(0x00, candevices_p[card]->io_addr + SJACR+0x200);
110 /* Check hardware reset status chip 0 */
112 while ( (pcm3680_read_register(candevices_p[card]->io_addr + SJACR)
113 & CR_RR) && (i<=15) ) {
118 CANMSG("Reset status timeout!\n");
119 CANMSG("Please check your hardware.\n");
123 DEBUGMSG("Chip[0] reset status ok.\n");
125 /* Check hardware reset status chip 1 */
127 while ( (pcm3680_read_register( candevices_p[card]->io_addr + SJACR +
128 0x200) & CR_RR) && (i<=15) ) {
133 CANMSG("Reset status timeout!\n");
134 CANMSG("Please check your hardware.\n");
138 DEBUGMSG("Chip[1] reset status ok.\n");
143 #define RESET_ADDR 0x100
148 * template_init_hw_data - Initialze hardware cards
149 * @card: Number of the hardware card.
151 * The function template_init_hw_data() is used to initialize the hardware
152 * structure containing information about the installed CAN-board.
153 * %RESET_ADDR represents the io-address of the hardware reset register.
154 * %NR_82527 represents the number of intel 82527 chips on the board.
155 * %NR_SJA1000 represents the number of philips sja1000 chips on the board.
156 * The flags entry can currently only be %PROGRAMMABLE_IRQ to indicate that
157 * the hardware uses programmable interrupts.
158 * Return Value: The function always returns zero
159 * File: src/template.c
161 int pcm3680_init_hw_data(int card)
163 candevices_p[card]->res_addr=RESET_ADDR;
164 candevices_p[card]->nr_82527_chips=NR_82527;
165 candevices_p[card]->nr_sja1000_chips=NR_SJA1000;
166 candevices_p[card]->flags &= ~PROGRAMMABLE_IRQ;
171 #define CHIP_TYPE "sja1000p"
173 * template_init_chip_data - Initialize chips
174 * @card: Number of the hardware card
175 * @chipnr: Number of the CAN chip on the hardware card
177 * The function template_init_chip_data() is used to initialize the hardware
178 * structure containing information about the CAN chips.
179 * %CHIP_TYPE represents the type of CAN chip. %CHIP_TYPE can be "i82527" or
181 * The @chip_base_addr entry represents the start of the 'official' memory map
182 * of the installed chip. It's likely that this is the same as the @io_addr
183 * argument supplied at module loading time.
184 * The @clock entry holds the chip clock value in Hz.
185 * The entry @sja_cdr_reg holds hardware specific options for the Clock Divider
186 * register. Options defined in the %sja1000.h file:
187 * %CDR_CLKOUT_MASK, %CDR_CLK_OFF, %CDR_RXINPEN, %CDR_CBP, %CDR_PELICAN
188 * The entry @sja_ocr_reg holds hardware specific options for the Output Control
189 * register. Options defined in the %sja1000.h file:
190 * %OCR_MODE_BIPHASE, %OCR_MODE_TEST, %OCR_MODE_NORMAL, %OCR_MODE_CLOCK,
191 * %OCR_TX0_LH, %OCR_TX1_ZZ.
192 * The entry @int_clk_reg holds hardware specific options for the Clock Out
193 * register. Options defined in the %i82527.h file:
194 * %iCLK_CD0, %iCLK_CD1, %iCLK_CD2, %iCLK_CD3, %iCLK_SL0, %iCLK_SL1.
195 * The entry @int_bus_reg holds hardware specific options for the Bus
196 * Configuration register. Options defined in the %i82527.h file:
197 * %iBUS_DR0, %iBUS_DR1, %iBUS_DT1, %iBUS_POL, %iBUS_CBY.
198 * Return Value: The function always returns zero
199 * File: src/template.c
201 int pcm3680_init_chip_data(int card, int chipnr)
203 pcm3680_base_addr = candevices_p[card]->io_addr;
204 candevices_p[card]->chip[chipnr]->chip_type=CHIP_TYPE;
205 candevices_p[card]->chip[chipnr]->chip_base_addr=candevices_p[card]->io_addr;
206 candevices_p[card]->chip[chipnr]->clock = 16000000;
207 candevices_p[card]->chip[chipnr]->int_clk_reg = 0x0;
208 candevices_p[card]->chip[chipnr]->int_bus_reg = 0x0;
209 candevices_p[card]->chip[chipnr]->sja_cdr_reg = CDR_CBP | CDR_CLK_OFF;
210 candevices_p[card]->chip[chipnr]->sja_ocr_reg = OCR_MODE_NORMAL |
217 * template_init_obj_data - Initialize message buffers
218 * @chipnr: Number of the CAN chip
219 * @objnr: Number of the message buffer
221 * The function template_init_obj_data() is used to initialize the hardware
222 * structure containing information about the different message objects on the
223 * CAN chip. In case of the sja1000 there's only one message object but on the
224 * i82527 chip there are 15.
225 * The code below is for a i82527 chip and initializes the object base addresses
226 * The entry @obj_base_addr represents the first memory address of the message
227 * object. In case of the sja1000 @obj_base_addr is taken the same as the chips
229 * Unless the hardware uses a segmented memory map, flags can be set zero.
230 * Return Value: The function always returns zero
231 * File: src/template.c
233 int pcm3680_init_obj_data(int chipnr, int objnr)
235 chips_p[chipnr]->msgobj[objnr]->obj_base_addr=chips_p[chipnr]->chip_base_addr;
236 chips_p[chipnr]->msgobj[objnr]->flags=0;
242 * template_program_irq - program interrupts
243 * @card: Number of the hardware card.
245 * The function template_program_irq() is used for hardware that uses
246 * programmable interrupts. If your hardware doesn't use programmable interrupts
247 * you should not set the @candevices_t->flags entry to %PROGRAMMABLE_IRQ and
248 * leave this function unedited. Again this function is hardware specific so
249 * there's no example code.
250 * Return value: The function returns zero on success or %-ENODEV on failure
251 * File: src/template.c
253 int pcm3680_program_irq(int card)
259 * template_write_register - Low level write register routine
260 * @data: data to be written
261 * @address: memory address to write to
263 * The function template_write_register() is used to write to hardware registers
264 * on the CAN chip. You should only have to edit this function if your hardware
265 * uses some specific write process.
266 * Return Value: The function does not return a value
267 * File: src/template.c
269 void pcm3680_write_register(unsigned char data, unsigned long address)
271 writeb(data,address);
275 * template_read_register - Low level read register routine
276 * @address: memory address to read from
278 * The function template_read_register() is used to read from hardware registers
279 * on the CAN chip. You should only have to edit this function if your hardware
280 * uses some specific read process.
281 * Return Value: The function returns the value stored in @address
282 * File: src/template.c
284 unsigned pcm3680_read_register(unsigned long address)
286 return readb(address);
289 /* !!! Don't change this function !!! */
290 int pcm3680_register(struct hwspecops_t *hwspecops)
292 hwspecops->request_io = pcm3680_request_io;
293 hwspecops->release_io = pcm3680_release_io;
294 hwspecops->reset = pcm3680_reset;
295 hwspecops->init_hw_data = pcm3680_init_hw_data;
296 hwspecops->init_chip_data = pcm3680_init_chip_data;
297 hwspecops->init_obj_data = pcm3680_init_obj_data;
298 hwspecops->write_register = pcm3680_write_register;
299 hwspecops->read_register = pcm3680_read_register;
300 hwspecops->program_irq = pcm3680_program_irq;