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/cc_can104.h"
14 #include "../include/sja1000.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 * template_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 template_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/template.c
37 int cc104_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 * template_elease_io - free reserved io memory range
50 * @candev: pointer to candevice/board which releases io
52 * The function template_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/template.c
60 int cc104_release_io(struct candevice_t *candev)
62 can_release_io_region(candev->io_addr,IO_RANGE);
68 * template_reset - hardware reset routine
69 * @candev: Pointer to candevice/board structure
71 * The function template_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/template.c
77 int cc104_reset(struct candevice_t *candev)
82 #define RESET_ADDR 0x0
87 * template_init_hw_data - Initialize hardware cards
88 * @candev: Pointer to candevice/board structure
90 * The function template_init_hw_data() is used to initialize the hardware
91 * structure containing information about the installed CAN-board.
92 * %RESET_ADDR represents the io-address of the hardware reset register.
93 * %NR_82527 represents the number of intel 82527 chips on the board.
94 * %NR_SJA1000 represents the number of philips sja1000 chips on the board.
95 * The flags entry can currently only be %CANDEV_PROGRAMMABLE_IRQ to indicate that
96 * the hardware uses programmable interrupts.
97 * Return Value: The function always returns zero
98 * File: src/template.c
100 int cc104_init_hw_data(struct candevice_t *candev)
102 candev->res_addr=RESET_ADDR;
103 candev->nr_82527_chips=0;
104 candev->nr_sja1000_chips=1;
105 candev->nr_all_chips=1;
106 candev->flags &= ~CANDEV_PROGRAMMABLE_IRQ;
112 * template_init_chip_data - Initialize chips
113 * @candev: Pointer to candevice/board structure
114 * @chipnr: Number of the CAN chip on the hardware card
116 * The function template_init_chip_data() is used to initialize the hardware
117 * structure containing information about the CAN chips.
118 * %CHIP_TYPE represents the type of CAN chip. %CHIP_TYPE can be "i82527" or
120 * The @chip_base_addr entry represents the start of the 'official' memory map
121 * of the installed chip. It's likely that this is the same as the @io_addr
122 * argument supplied at module loading time.
123 * The @clock entry holds the chip clock value in Hz.
124 * The entry @sja_cdr_reg holds hardware specific options for the Clock Divider
125 * register. Options defined in the %sja1000.h file:
126 * %sjaCDR_CLKOUT_MASK, %sjaCDR_CLK_OFF, %sjaCDR_RXINPEN, %sjaCDR_CBP, %sjaCDR_PELICAN
127 * The entry @sja_ocr_reg holds hardware specific options for the Output Control
128 * register. Options defined in the %sja1000.h file:
129 * %sjaOCR_MODE_BIPHASE, %sjaOCR_MODE_TEST, %sjaOCR_MODE_NORMAL, %sjaOCR_MODE_CLOCK,
130 * %sjaOCR_TX0_LH, %sjaOCR_TX1_ZZ.
131 * The entry @int_clk_reg holds hardware specific options for the Clock Out
132 * register. Options defined in the %i82527.h file:
133 * %iCLK_CD0, %iCLK_CD1, %iCLK_CD2, %iCLK_CD3, %iCLK_SL0, %iCLK_SL1.
134 * The entry @int_bus_reg holds hardware specific options for the Bus
135 * Configuration register. Options defined in the %i82527.h file:
136 * %iBUS_DR0, %iBUS_DR1, %iBUS_DT1, %iBUS_POL, %iBUS_CBY.
137 * Return Value: The function always returns zero
138 * File: src/template.c
140 int cc104_init_chip_data(struct candevice_t *candev, int chipnr)
142 sja1000_fill_chipspecops(candev->chip[chipnr]);
143 candev->chip[chipnr]->chip_base_addr=candev->io_addr;
144 candev->chip[chipnr]->clock = 16000000;
145 candev->chip[chipnr]->flags = 0;
146 candev->chip[chipnr]->sja_cdr_reg = sjaCDR_CBP | sjaCDR_CLK_OFF;
147 candev->chip[chipnr]->sja_ocr_reg = sjaOCR_MODE_NORMAL |
154 * template_init_obj_data - Initialize message buffers
155 * @chip: Pointer to chip specific structure
156 * @objnr: Number of the message buffer
158 * The function template_init_obj_data() is used to initialize the hardware
159 * structure containing information about the different message objects on the
160 * CAN chip. In case of the sja1000 there's only one message object but on the
161 * i82527 chip there are 15.
162 * The code below is for a i82527 chip and initializes the object base addresses
163 * The entry @obj_base_addr represents the first memory address of the message
164 * object. In case of the sja1000 @obj_base_addr is taken the same as the chips
166 * Unless the hardware uses a segmented memory map, flags can be set zero.
167 * Return Value: The function always returns zero
168 * File: src/template.c
170 int cc104_init_obj_data(struct canchip_t *chip, int objnr)
172 chip->msgobj[objnr]->obj_base_addr=chip->chip_base_addr;
178 * template_program_irq - program interrupts
179 * @candev: Pointer to candevice/board structure
181 * The function template_program_irq() is used for hardware that uses
182 * programmable interrupts. If your hardware doesn't use programmable interrupts
183 * you should not set the @candevices_t->flags entry to %CANDEV_PROGRAMMABLE_IRQ and
184 * leave this function unedited. Again this function is hardware specific so
185 * there's no example code.
186 * Return value: The function returns zero on success or %-ENODEV on failure
187 * File: src/template.c
189 int cc104_program_irq(struct candevice_t *candev)
195 * template_write_register - Low level write register routine
196 * @data: data to be written
197 * @address: memory address to write to
199 * The function template_write_register() is used to write to hardware registers
200 * on the CAN chip. You should only have to edit this function if your hardware
201 * uses some specific write process.
202 * Return Value: The function does not return a value
203 * File: src/template.c
205 void cc104_write_register(unsigned data, unsigned long address)
211 * template_read_register - Low level read register routine
212 * @address: memory address to read from
214 * The function template_read_register() is used to read from hardware registers
215 * on the CAN chip. You should only have to edit this function if your hardware
216 * uses some specific read process.
217 * Return Value: The function returns the value stored in @address
218 * File: src/template.c
220 unsigned cc104_read_register(unsigned long address)
225 /* !!! Don't change this function !!! */
226 int cc104_register(struct hwspecops_t *hwspecops)
228 hwspecops->request_io = cc104_request_io;
229 hwspecops->release_io = cc104_release_io;
230 hwspecops->reset = cc104_reset;
231 hwspecops->init_hw_data = cc104_init_hw_data;
232 hwspecops->init_chip_data = cc104_init_chip_data;
233 hwspecops->init_obj_data = cc104_init_obj_data;
234 hwspecops->write_register = cc104_write_register;
235 hwspecops->read_register = cc104_read_register;
236 hwspecops->program_irq = cc104_program_irq;