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/pcm3680.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.
21 #define IO_RANGE 0x400
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 pcm3680_request_io(struct candevice_t *candev)
39 can_ioptr_t remap_addr;
40 if (!can_request_mem_region(candev->io_addr,IO_RANGE,DEVICE_NAME " - pcm3680")) {
41 CANMSG("Unable to request IO-memory: 0x%lx\n",candev->io_addr);
44 if ( !( remap_addr = ioremap( candev->io_addr, IO_RANGE ) ) ) {
45 CANMSG("Unable to access I/O memory at: 0x%lx\n", candev->io_addr);
46 can_release_mem_region(candev->io_addr,IO_RANGE);
50 can_base_addr_fixup(candev, remap_addr);
51 DEBUGMSG("Registered IO-memory: 0x%lx - 0x%lx\n", candev->io_addr, candev->io_addr + IO_RANGE - 1);
56 * template_release_io - free reserved io memory range
57 * @candev: pointer to candevice/board which releases io
59 * The function template_release_io() is used to free reserved io-memory.
60 * In case you have reserved more io memory, don't forget to free it here.
61 * IO_RANGE is the io-memory range that gets released, please adjust according
62 * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
63 * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
64 * Return Value: The function always returns zero
65 * File: src/template.c
67 int pcm3680_release_io(struct candevice_t *candev)
69 iounmap((void*)candev->dev_base_addr);
70 can_release_mem_region(candev->io_addr,IO_RANGE);
75 * template_reset - hardware reset routine
76 * @candev: Pointer to candevice/board structure
78 * The function template_reset() is used to give a hardware reset. This is
79 * rather hardware specific so I haven't included example code. Don't forget to
80 * check the reset status of the chip before returning.
81 * Return Value: The function returns zero on success or %-ENODEV on failure
82 * File: src/template.c
84 int pcm3680_reset(struct candevice_t *candev)
87 struct canchip_t *chip;
90 DEBUGMSG("Resetting pcm3680 hardware ...\n");
91 for(chipnr=0;chipnr<candev->nr_sja1000_chips;chipnr++) {
92 chip=candev->chip[chipnr];
93 pcm3680_write_register(sjaMOD_RM, chip->chip_base_addr+SJAMOD);
95 pcm3680_write_register(0x00, chip->chip_base_addr + SJAIER);
96 /* Write arbitrary data to reset chip */
97 pcm3680_write_register(0x01, chip->chip_base_addr + 0x100);
100 while (pcm3680_read_register(chip->chip_base_addr+SJAMOD)&sjaMOD_RM){
101 if(!i--) return -ENODEV;
103 pcm3680_write_register(0, chip->chip_base_addr+SJAMOD);
106 pcm3680_write_register(sjaCDR_PELICAN, chip->chip_base_addr+SJACDR);
107 pcm3680_write_register(0x00, chip->chip_base_addr + SJAIER);
113 #define RESET_ADDR 0x100
118 * template_init_hw_data - Initialize hardware cards
119 * @candev: Pointer to candevice/board structure
121 * The function template_init_hw_data() is used to initialize the hardware
122 * structure containing information about the installed CAN-board.
123 * %RESET_ADDR represents the io-address of the hardware reset register.
124 * %NR_82527 represents the number of intel 82527 chips on the board.
125 * %NR_SJA1000 represents the number of philips sja1000 chips on the board.
126 * The flags entry can currently only be %CANDEV_PROGRAMMABLE_IRQ to indicate that
127 * the hardware uses programmable interrupts.
128 * Return Value: The function always returns zero
129 * File: src/template.c
131 int pcm3680_init_hw_data(struct candevice_t *candev)
133 candev->res_addr=RESET_ADDR;
134 candev->nr_82527_chips=NR_82527;
135 candev->nr_sja1000_chips=NR_SJA1000;
136 candev->nr_all_chips=NR_82527+NR_SJA1000;
137 candev->flags &= ~CANDEV_PROGRAMMABLE_IRQ;
143 * template_init_chip_data - Initialize chips
144 * @candev: Pointer to candevice/board structure
145 * @chipnr: Number of the CAN chip on the hardware card
147 * The function template_init_chip_data() is used to initialize the hardware
148 * structure containing information about the CAN chips.
149 * %CHIP_TYPE represents the type of CAN chip. %CHIP_TYPE can be "i82527" or
151 * The @chip_base_addr entry represents the start of the 'official' memory map
152 * of the installed chip. It's likely that this is the same as the @io_addr
153 * argument supplied at module loading time.
154 * The @clock entry holds the chip clock value in Hz.
155 * The entry @sja_cdr_reg holds hardware specific options for the Clock Divider
156 * register. Options defined in the %sja1000.h file:
157 * %sjaCDR_CLKOUT_MASK, %sjaCDR_CLK_OFF, %sjaCDR_RXINPEN, %sjaCDR_CBP, %sjaCDR_PELICAN
158 * The entry @sja_ocr_reg holds hardware specific options for the Output Control
159 * register. Options defined in the %sja1000.h file:
160 * %sjaOCR_MODE_BIPHASE, %sjaOCR_MODE_TEST, %sjaOCR_MODE_NORMAL, %sjaOCR_MODE_CLOCK,
161 * %sjaOCR_TX0_LH, %sjaOCR_TX1_ZZ.
162 * The entry @int_clk_reg holds hardware specific options for the Clock Out
163 * register. Options defined in the %i82527.h file:
164 * %iCLK_CD0, %iCLK_CD1, %iCLK_CD2, %iCLK_CD3, %iCLK_SL0, %iCLK_SL1.
165 * The entry @int_bus_reg holds hardware specific options for the Bus
166 * Configuration register. Options defined in the %i82527.h file:
167 * %iBUS_DR0, %iBUS_DR1, %iBUS_DT1, %iBUS_POL, %iBUS_CBY.
168 * Return Value: The function always returns zero
169 * File: src/template.c
171 int pcm3680_init_chip_data(struct candevice_t *candev, int chipnr)
173 sja1000p_fill_chipspecops(candev->chip[chipnr]);
174 candev->chip[chipnr]->chip_base_addr=
175 candev->dev_base_addr + 0x200*chipnr;
176 candev->chip[chipnr]->clock = 16000000;
177 candev->chip[chipnr]->int_clk_reg = 0x0;
178 candev->chip[chipnr]->int_bus_reg = 0x0;
179 candev->chip[chipnr]->sja_cdr_reg = sjaCDR_CBP | sjaCDR_CLK_OFF;
180 candev->chip[chipnr]->sja_ocr_reg = sjaOCR_MODE_NORMAL |
187 * template_init_obj_data - Initialize message buffers
188 * @chip: Pointer to chip specific structure
189 * @objnr: Number of the message buffer
191 * The function template_init_obj_data() is used to initialize the hardware
192 * structure containing information about the different message objects on the
193 * CAN chip. In case of the sja1000 there's only one message object but on the
194 * i82527 chip there are 15.
195 * The code below is for a i82527 chip and initializes the object base addresses
196 * The entry @obj_base_addr represents the first memory address of the message
197 * object. In case of the sja1000 @obj_base_addr is taken the same as the chips
199 * Unless the hardware uses a segmented memory map, flags can be set zero.
200 * Return Value: The function always returns zero
201 * File: src/template.c
203 int pcm3680_init_obj_data(struct canchip_t *chip, int objnr)
205 chip->msgobj[objnr]->obj_base_addr=chip->chip_base_addr;
211 * template_program_irq - program interrupts
212 * @candev: Pointer to candevice/board structure
214 * The function template_program_irq() is used for hardware that uses
215 * programmable interrupts. If your hardware doesn't use programmable interrupts
216 * you should not set the @candevices_t->flags entry to %CANDEV_PROGRAMMABLE_IRQ and
217 * leave this function unedited. Again this function is hardware specific so
218 * there's no example code.
219 * Return value: The function returns zero on success or %-ENODEV on failure
220 * File: src/template.c
222 int pcm3680_program_irq(struct candevice_t *candev)
228 * template_write_register - Low level write register routine
229 * @data: data to be written
230 * @address: memory address to write to
232 * The function template_write_register() is used to write to hardware registers
233 * on the CAN chip. You should only have to edit this function if your hardware
234 * uses some specific write process.
235 * Return Value: The function does not return a value
236 * File: src/template.c
238 void pcm3680_write_register(unsigned data, can_ioptr_t address)
240 can_writeb(data,address);
244 * template_read_register - Low level read register routine
245 * @address: memory address to read from
247 * The function template_read_register() is used to read from hardware registers
248 * on the CAN chip. You should only have to edit this function if your hardware
249 * uses some specific read process.
250 * Return Value: The function returns the value stored in @address
251 * File: src/template.c
253 unsigned pcm3680_read_register(can_ioptr_t address)
255 return can_readb(address);
258 /* !!! Don't change this function !!! */
259 int pcm3680_register(struct hwspecops_t *hwspecops)
261 hwspecops->request_io = pcm3680_request_io;
262 hwspecops->release_io = pcm3680_release_io;
263 hwspecops->reset = pcm3680_reset;
264 hwspecops->init_hw_data = pcm3680_init_hw_data;
265 hwspecops->init_chip_data = pcm3680_init_chip_data;
266 hwspecops->init_obj_data = pcm3680_init_obj_data;
267 hwspecops->write_register = pcm3680_write_register;
268 hwspecops->read_register = pcm3680_read_register;
269 hwspecops->program_irq = pcm3680_program_irq;