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
10 #include "../include/can.h"
11 #include "../include/can_sysdep.h"
12 #include "../include/main.h"
13 #include "../include/gensja1000io.h"
14 #include "../include/sja1000p.h"
17 * IO_RANGE is the io-memory range that gets reserved, please adjust according
18 * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
19 * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
24 * gensja1000io_request_io: - reserve io or memory range for can board
25 * @candev: pointer to candevice/board which asks for io. Field @io_addr
26 * of @candev is used in most cases to define start of the range
28 * The function gensja1000io_request_io() is used to reserve the io-memory. If your
29 * hardware uses a dedicated memory range as hardware control registers you
30 * will have to add the code to reserve this memory as well.
31 * %IO_RANGE is the io-memory range that gets reserved, please adjust according
32 * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
33 * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
34 * Return Value: The function returns zero on success or %-ENODEV on failure
35 * File: src/gensja1000io.c
37 int gensja1000io_request_io(struct candevice_t *candev)
39 if (!can_request_io_region(candev->io_addr,IO_RANGE,DEVICE_NAME)) {
40 CANMSG("Unable to open port: 0x%lx\n",candev->io_addr);
43 DEBUGMSG("Registered IO-memory: 0x%lx - 0x%lx\n", candev->io_addr, candev->io_addr + IO_RANGE - 1);
49 * gensja1000io_elease_io - free reserved io memory range
50 * @candev: pointer to candevice/board which releases io
52 * The function gensja1000io_release_io() is used to free reserved io-memory.
53 * In case you have reserved more io memory, don't forget to free it here.
54 * IO_RANGE is the io-memory range that gets released, please adjust according
55 * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
56 * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
57 * Return Value: The function always returns zero
58 * File: src/gensja1000io.c
60 int gensja1000io_release_io(struct candevice_t *candev)
62 can_release_io_region(candev->io_addr,IO_RANGE);
68 * gensja1000io_reset - hardware reset routine
69 * @candev: Pointer to candevice/board structure
71 * The function gensja1000io_reset() is used to give a hardware reset. This is
72 * rather hardware specific so I haven't included example code. Don't forget to
73 * check the reset status of the chip before returning.
74 * Return Value: The function returns zero on success or %-ENODEV on failure
75 * File: src/gensja1000io.c
77 int gensja1000io_reset(struct candevice_t *candev)
80 struct canchip_t *chip=candev->chip[0];
83 gensja1000io_write_register(sjaMOD_RM, chip->chip_base_addr+SJAMOD);
86 cdr=gensja1000io_read_register(chip->chip_base_addr+SJACDR);
87 gensja1000io_write_register(cdr|sjaCDR_PELICAN, chip->chip_base_addr+SJACDR);
89 gensja1000io_write_register(0, chip->chip_base_addr+SJAIER);
92 gensja1000io_write_register(0, chip->chip_base_addr+SJAMOD);
93 while (gensja1000io_read_register(chip->chip_base_addr+SJAMOD)&sjaMOD_RM){
94 if(!i--) return -ENODEV;
96 gensja1000io_write_register(0, chip->chip_base_addr+SJAMOD);
99 cdr=gensja1000io_read_register(chip->chip_base_addr+SJACDR);
100 gensja1000io_write_register(cdr|sjaCDR_PELICAN, chip->chip_base_addr+SJACDR);
102 gensja1000io_write_register(0, chip->chip_base_addr+SJAIER);
107 #define RESET_ADDR 0x0
112 * gensja1000io_init_hw_data - Initialize hardware cards
113 * @candev: Pointer to candevice/board structure
115 * The function gensja1000io_init_hw_data() is used to initialize the hardware
116 * structure containing information about the installed CAN-board.
117 * %RESET_ADDR represents the io-address of the hardware reset register.
118 * %NR_82527 represents the number of intel 82527 chips on the board.
119 * %NR_SJA1000 represents the number of philips sja1000 chips on the board.
120 * The flags entry can currently only be %CANDEV_PROGRAMMABLE_IRQ to indicate that
121 * the hardware uses programmable interrupts.
122 * Return Value: The function always returns zero
123 * File: src/gensja1000io.c
125 int gensja1000io_init_hw_data(struct candevice_t *candev)
127 candev->res_addr=RESET_ADDR;
128 candev->nr_82527_chips=0;
129 candev->nr_sja1000_chips=1;
130 candev->nr_all_chips=1;
131 candev->flags |= CANDEV_PROGRAMMABLE_IRQ*0;
137 * gensja1000io_init_chip_data - Initialize chips
138 * @candev: Pointer to candevice/board structure
139 * @chipnr: Number of the CAN chip on the hardware card
141 * The function gensja1000io_init_chip_data() is used to initialize the hardware
142 * structure containing information about the CAN chips.
143 * %CHIP_TYPE represents the type of CAN chip. %CHIP_TYPE can be "i82527" or
145 * The @chip_base_addr entry represents the start of the 'official' memory map
146 * of the installed chip. It's likely that this is the same as the @io_addr
147 * argument supplied at module loading time.
148 * The @clock entry holds the chip clock value in Hz.
149 * The entry @sja_cdr_reg holds hardware specific options for the Clock Divider
150 * register. Options defined in the %sja1000.h file:
151 * %sjaCDR_CLKOUT_MASK, %sjaCDR_CLK_OFF, %sjaCDR_RXINPEN, %sjaCDR_CBP, %sjaCDR_PELICAN
152 * The entry @sja_ocr_reg holds hardware specific options for the Output Control
153 * register. Options defined in the %sja1000.h file:
154 * %sjaOCR_MODE_BIPHASE, %sjaOCR_MODE_TEST, %sjaOCR_MODE_NORMAL, %sjaOCR_MODE_CLOCK,
155 * %sjaOCR_TX0_LH, %sjaOCR_TX1_ZZ.
156 * The entry @int_clk_reg holds hardware specific options for the Clock Out
157 * register. Options defined in the %i82527.h file:
158 * %iCLK_CD0, %iCLK_CD1, %iCLK_CD2, %iCLK_CD3, %iCLK_SL0, %iCLK_SL1.
159 * The entry @int_bus_reg holds hardware specific options for the Bus
160 * Configuration register. Options defined in the %i82527.h file:
161 * %iBUS_DR0, %iBUS_DR1, %iBUS_DT1, %iBUS_POL, %iBUS_CBY.
162 * The entry @int_cpu_reg holds hardware specific options for the cpu interface
163 * register. Options defined in the %i82527.h file:
164 * %iCPU_CEN, %iCPU_MUX, %iCPU_SLP, %iCPU_PWD, %iCPU_DMC, %iCPU_DSC, %iCPU_RST.
165 * Return Value: The function always returns zero
166 * File: src/gensja1000io.c
168 int gensja1000io_init_chip_data(struct candevice_t *candev, int chipnr)
170 /*sja1000_fill_chipspecops(candev->chip[chipnr]);*/
171 sja1000p_fill_chipspecops(candev->chip[chipnr]);
173 candev->chip[chipnr]->chip_base_addr=can_ioport2ioptr(candev->io_addr);
174 if(candev->chip[chipnr]->clock<=0)
175 candev->chip[chipnr]->clock = 16000000;
176 candev->chip[chipnr]->int_clk_reg = 0x0;
177 candev->chip[chipnr]->int_bus_reg = 0x0;
178 candev->chip[chipnr]->sja_cdr_reg = sjaCDR_CBP | sjaCDR_CLK_OFF;
179 candev->chip[chipnr]->sja_ocr_reg = sjaOCR_MODE_NORMAL | sjaOCR_TX0_LH;
185 * gensja1000io_init_obj_data - Initialize message buffers
186 * @chip: Pointer to chip specific structure
187 * @objnr: Number of the message buffer
189 * The function gensja1000io_init_obj_data() is used to initialize the hardware
190 * structure containing information about the different message objects on the
191 * CAN chip. In case of the sja1000 there's only one message object but on the
192 * i82527 chip there are 15.
193 * The code below is for a i82527 chip and initializes the object base addresses
194 * The entry @obj_base_addr represents the first memory address of the message
195 * object. In case of the sja1000 @obj_base_addr is taken the same as the chips
197 * Unless the hardware uses a segmented memory map, flags can be set zero.
198 * Return Value: The function always returns zero
199 * File: src/gensja1000io.c
201 int gensja1000io_init_obj_data(struct canchip_t *chip, int objnr)
203 chip->msgobj[objnr]->obj_base_addr=chip->chip_base_addr;
208 * gensja1000io_program_irq - program interrupts
209 * @candev: Pointer to candevice/board structure
211 * The function gensja1000io_program_irq() is used for hardware that uses
212 * programmable interrupts. If your hardware doesn't use programmable interrupts
213 * you should not set the @candevices_t->flags entry to %CANDEV_PROGRAMMABLE_IRQ and
214 * leave this function unedited. Again this function is hardware specific so
215 * there's no example code.
216 * Return value: The function returns zero on success or %-ENODEV on failure
217 * File: src/gensja1000io.c
219 int gensja1000io_program_irq(struct candevice_t *candev)
225 * gensja1000io_write_register - Low level write register routine
226 * @data: data to be written
227 * @address: memory address to write to
229 * The function gensja1000io_write_register() is used to write to hardware registers
230 * on the CAN chip. You should only have to edit this function if your hardware
231 * uses some specific write process.
232 * Return Value: The function does not return a value
233 * File: src/gensja1000io.c
235 void gensja1000io_write_register(unsigned data, can_ioptr_t address)
237 /*DEBUGMSG("gensja1000io_write_register: addr=0x%lx data=0x%x",
239 can_outb(data,address);
243 * gensja1000io_read_register - Low level read register routine
244 * @address: memory address to read from
246 * The function gensja1000io_read_register() is used to read from hardware registers
247 * on the CAN chip. You should only have to edit this function if your hardware
248 * uses some specific read process.
249 * Return Value: The function returns the value stored in @address
250 * File: src/gensja1000io.c
252 unsigned gensja1000io_read_register(can_ioptr_t address)
254 return can_inb(address);
257 /* !!! Don't change this function !!! */
258 int gensja1000io_register(struct hwspecops_t *hwspecops)
260 hwspecops->request_io = gensja1000io_request_io;
261 hwspecops->release_io = gensja1000io_release_io;
262 hwspecops->reset = gensja1000io_reset;
263 hwspecops->init_hw_data = gensja1000io_init_hw_data;
264 hwspecops->init_chip_data = gensja1000io_init_chip_data;
265 hwspecops->init_obj_data = gensja1000io_init_obj_data;
266 hwspecops->write_register = gensja1000io_write_register;
267 hwspecops->read_register = gensja1000io_read_register;
268 hwspecops->program_irq = gensja1000io_program_irq;