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/cc_can104.h"
24 #include "../include/i82527.h"
25 #include "../include/sja1000.h"
28 * IO_RANGE is the io-memory range that gets reserved, please adjust according
29 * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
30 * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
35 * template_request_io: - reserve io memory
36 * @io_addr: The reserved memory starts at @io_addr, wich is the module
39 * The function template_request_io() is used to reserve the io-memory. If your
40 * hardware uses a dedicated memory range as hardware control registers you
41 * will have to add the code to reserve this memory as well.
42 * %IO_RANGE is the io-memory range that gets reserved, please adjust according
43 * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
44 * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
45 * Return Value: The function returns zero on success or %-ENODEV on failure
46 * File: src/template.c
48 int cc104_request_io(unsigned long io_addr)
50 if (check_region(io_addr,IO_RANGE)) {
51 CANMSG("Unable to open port: 0x%lx\n",io_addr);
55 request_region(io_addr,IO_RANGE,DEVICE_NAME);
56 DEBUGMSG("Registered IO-memory: 0x%lx - 0x%lx\n", io_addr, io_addr + IO_RANGE - 1);
62 * template_release_io - free reserved io-memory
63 * @io_addr: Start of the memory range to be released.
65 * The function template_release_io() is used to free reserved io-memory.
66 * In case you have reserved more io memory, don't forget to free it here.
67 * IO_RANGE is the io-memory range that gets released, please adjust according
68 * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
69 * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
70 * Return Value: The function always returns zero
71 * File: src/template.c
73 int cc104_release_io(unsigned long io_addr)
75 release_region(io_addr,IO_RANGE);
81 * template_reset - hardware reset routine
82 * @card: Number of the hardware card.
84 * The function template_reset() is used to give a hardware reset. This is
85 * rather hardware specific so I haven't included example code. Don't forget to
86 * check the reset status of the chip before returning.
87 * Return Value: The function returns zero on success or %-ENODEV on failure
88 * File: src/template.c
90 int cc104_reset(int card)
95 #define RESET_ADDR 0x0
100 * template_init_hw_data - Initialze hardware cards
101 * @card: Number of the hardware card.
103 * The function template_init_hw_data() is used to initialize the hardware
104 * structure containing information about the installed CAN-board.
105 * %RESET_ADDR represents the io-address of the hardware reset register.
106 * %NR_82527 represents the number of intel 82527 chips on the board.
107 * %NR_SJA1000 represents the number of philips sja1000 chips on the board.
108 * The flags entry can currently only be %PROGRAMMABLE_IRQ to indicate that
109 * the hardware uses programmable interrupts.
110 * Return Value: The function always returns zero
111 * File: src/template.c
113 int cc104_init_hw_data(int card)
115 candevices_p[card]->res_addr=RESET_ADDR;
116 candevices_p[card]->nr_82527_chips=0;
117 candevices_p[card]->nr_sja1000_chips=1;
118 candevices_p[card]->flags |= ~PROGRAMMABLE_IRQ;
123 #define CHIP_TYPE "sja1000"
125 * template_init_chip_data - Initialize chips
126 * @card: Number of the hardware card
127 * @chipnr: Number of the CAN chip on the hardware card
129 * The function template_init_chip_data() is used to initialize the hardware
130 * structure containing information about the CAN chips.
131 * %CHIP_TYPE represents the type of CAN chip. %CHIP_TYPE can be "i82527" or
133 * The @chip_base_addr entry represents the start of the 'official' memory map
134 * of the installed chip. It's likely that this is the same as the @io_addr
135 * argument supplied at module loading time.
136 * The @clock entry holds the chip clock value in Hz.
137 * The entry @sja_cdr_reg holds hardware specific options for the Clock Divider
138 * register. Options defined in the %sja1000.h file:
139 * %CDR_CLKOUT_MASK, %CDR_CLK_OFF, %CDR_RXINPEN, %CDR_CBP, %CDR_PELICAN
140 * The entry @sja_ocr_reg holds hardware specific options for the Output Control
141 * register. Options defined in the %sja1000.h file:
142 * %OCR_MODE_BIPHASE, %OCR_MODE_TEST, %OCR_MODE_NORMAL, %OCR_MODE_CLOCK,
143 * %OCR_TX0_LH, %OCR_TX1_ZZ.
144 * The entry @int_clk_reg holds hardware specific options for the Clock Out
145 * register. Options defined in the %i82527.h file:
146 * %iCLK_CD0, %iCLK_CD1, %iCLK_CD2, %iCLK_CD3, %iCLK_SL0, %iCLK_SL1.
147 * The entry @int_bus_reg holds hardware specific options for the Bus
148 * Configuration register. Options defined in the %i82527.h file:
149 * %iBUS_DR0, %iBUS_DR1, %iBUS_DT1, %iBUS_POL, %iBUS_CBY.
150 * Return Value: The function always returns zero
151 * File: src/template.c
153 int cc104_init_chip_data(int card, int chipnr)
155 candevices_p[card]->chip[chipnr]->chip_type=CHIP_TYPE;
156 candevices_p[card]->chip[chipnr]->chip_base_addr=candevices_p[card]->io_addr;
157 candevices_p[card]->chip[chipnr]->clock = 16000000;
158 candevices_p[card]->chip[chipnr]->flags = 0;
159 candevices_p[card]->chip[chipnr]->sja_cdr_reg = CDR_CBP | CDR_CLK_OFF;
160 candevices_p[card]->chip[chipnr]->sja_ocr_reg = OCR_MODE_NORMAL |
167 * template_init_obj_data - Initialize message buffers
168 * @chipnr: Number of the CAN chip
169 * @objnr: Number of the message buffer
171 * The function template_init_obj_data() is used to initialize the hardware
172 * structure containing information about the different message objects on the
173 * CAN chip. In case of the sja1000 there's only one message object but on the
174 * i82527 chip there are 15.
175 * The code below is for a i82527 chip and initializes the object base addresses
176 * The entry @obj_base_addr represents the first memory address of the message
177 * object. In case of the sja1000 @obj_base_addr is taken the same as the chips
179 * Unless the hardware uses a segmented memory map, flags can be set zero.
180 * Return Value: The function always returns zero
181 * File: src/template.c
183 int cc104_init_obj_data(int chipnr, int objnr)
185 chips_p[chipnr]->msgobj[objnr]->obj_base_addr=chips_p[chipnr]->chip_base_addr;
186 chips_p[chipnr]->msgobj[objnr]->flags=0;
192 * template_program_irq - program interrupts
193 * @card: Number of the hardware card.
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 %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
203 int cc104_program_irq(int card)
209 * template_write_register - Low level write register routine
210 * @data: data to be written
211 * @address: memory address to write to
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
219 void cc104_write_register(unsigned char data, unsigned long address)
225 * template_read_register - Low level read register routine
226 * @address: memory address to read from
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
234 unsigned cc104_read_register(unsigned long address)
239 /* !!! Don't change this function !!! */
240 int cc104_register(struct hwspecops_t *hwspecops)
242 hwspecops->request_io = cc104_request_io;
243 hwspecops->release_io = cc104_release_io;
244 hwspecops->reset = cc104_reset;
245 hwspecops->init_hw_data = cc104_init_hw_data;
246 hwspecops->init_chip_data = cc104_init_chip_data;
247 hwspecops->init_obj_data = cc104_init_obj_data;
248 hwspecops->write_register = cc104_write_register;
249 hwspecops->read_register = cc104_read_register;
250 hwspecops->program_irq = cc104_program_irq;