X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/blobdiff_plain/6234a9dc385e5a9258a84227b2eab09bbb099c27..50e9e47fc21191ea9ea758fea1e7f2bd5a275e98:/lincan/src/hms30c7202_can.c diff --git a/lincan/src/hms30c7202_can.c b/lincan/src/hms30c7202_can.c index ff12573..0bc5045 100644 --- a/lincan/src/hms30c7202_can.c +++ b/lincan/src/hms30c7202_can.c @@ -1,13 +1,38 @@ -/* hms30c7202_can.c - Hynix HMS30c7202 ARM device specific code - * Linux CAN-bus device driver. - * Written by Sebastian Stolzenberg email:stolzi@sebastian-stolzenberg.de - * Based on code from Arnaud Westenberg email:arnaud@wanadoo.nl - * and Ake Hedman, eurosource, akhe@eurosource.se - * Rewritten for new CAN queues by Pavel Pisa - OCERA team member - * email:pisa@cmp.felk.cvut.cz - * This software is released under the GPL-License. - * Version lincan-0.3 17 Jun 2004 - */ +/**************************************************************************/ +/* File: hms30c7202_can.c - Hynix HMS30c7202 ARM integrated C_CAN handling*/ +/* */ +/* LinCAN - (Not only) Linux CAN bus driver */ +/* Copyright (C) 2002-2009 DCE FEE CTU Prague */ +/* Copyright (C) 2002-2009 Pavel Pisa */ +/* Copyright (C) 2004 Sebastian Stolzenberg */ +/* Funded by OCERA and FRESCOR IST projects */ +/* Based on CAN driver code by Arnaud Westenberg */ +/* and Ake Hedman, eurosource */ +/* */ +/* LinCAN is free software; you can redistribute it and/or modify it */ +/* under terms of the GNU General Public License as published by the */ +/* Free Software Foundation; either version 2, or (at your option) any */ +/* later version. LinCAN is distributed in the hope that it will be */ +/* useful, but WITHOUT ANY WARRANTY; without even the implied warranty */ +/* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ +/* General Public License for more details. You should have received a */ +/* copy of the GNU General Public License along with LinCAN; see file */ +/* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, */ +/* Cambridge, MA 02139, USA. */ +/* */ +/* To allow use of LinCAN in the compact embedded systems firmware */ +/* and RT-executives (RTEMS for example), main authors agree with next */ +/* special exception: */ +/* */ +/* Including LinCAN header files in a file, instantiating LinCAN generics */ +/* or templates, or linking other files with LinCAN objects to produce */ +/* an application image/executable, does not by itself cause the */ +/* resulting application image/executable to be covered by */ +/* the GNU General Public License. */ +/* This exception does not however invalidate any other reasons */ +/* why the executable file might be covered by the GNU Public License. */ +/* Publication of enhanced or derived LinCAN files is required although. */ +/**************************************************************************/ #include @@ -31,7 +56,7 @@ * * The function hms30c7202_request_io() is used to reserve the io-memory. If your * hardware uses a dedicated memory range as hardware control registers you - * will have to add the code to reserve this memory as well. + * will have to add the code to reserve this memory as well. * %IO_RANGE is the io-memory range that gets reserved, please adjust according * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode. @@ -46,7 +71,7 @@ int hms30c7202_request_io(struct candevice_t *candev) CANMSG("hmsc30c7202_can failed to request mem region %lx.\n", (unsigned long)candev->io_addr ); } - + if (!( candev->dev_base_addr = ioremap( candev->io_addr, IO_RANGE ))) { DEBUGMSG( "Failed to map IO-memory: 0x%lx - 0x%lx, mapped to 0x%lx\n", (unsigned long)candev->io_addr, @@ -55,23 +80,23 @@ int hms30c7202_request_io(struct candevice_t *candev) can_release_mem_region(candev->io_addr, IO_RANGE); return -ENODEV; } else { - + DEBUGMSG( "Mapped IO-memory: 0x%lx - 0x%lx, mapped to 0x%lx\n", (unsigned long)candev->io_addr, (unsigned long)candev->io_addr + IO_RANGE - 1, (unsigned long)candev->dev_base_addr); - + } - + candev->chip[0]->chip_base_addr=candev->dev_base_addr; - + //pchip->write_register(0, pchip->vbase_addr + CCCR); //DEBUGMSG("C-CAN Control Register : 0x%.4lx\n", // (unsigned long)(c_can_read_reg_w( pchip->vbase_addr + CCCR))); candev->chip[0]->chipspecops->start_chip(candev->chip[0]); //DEBUGMSG("C-CAN Control Register : 0x%.4lx\n", // (unsigned long)(c_can_read_reg_w( pchip->vbase_addr + CCCR))); - + //DEBUGMSG("hms30c7202_can request i/o, leaving.\n"); return 0; } @@ -92,12 +117,12 @@ int hms30c7202_request_io(struct candevice_t *candev) int hms30c7202_release_io(struct candevice_t *candev) { u16 tempReg; - + //disable IRQ generation tempReg = c_can_read_reg_w(candev->chip[0], CCCR); c_can_config_irqs(candev->chip[0], 0); - + /* // clear all message objects for (i=1; i<=15; i++) { ccscan_write_register( @@ -119,13 +144,13 @@ int hms30c7202_release_io(struct candevice_t *candev) */ // power down HMS30c7202 - C_CAN candev->chip[0]->chipspecops->stop_chip(candev->chip[0]); - + // release I/O memory mapping iounmap(candev->dev_base_addr); - + // Release the memory region can_release_mem_region(candev->io_addr, IO_RANGE); - + return 0; } @@ -144,7 +169,7 @@ int hms30c7202_reset( struct candevice_t *candev) int i=0; int enableTest=0, disableTest=0; struct canchip_t *pchip = candev->chip[0]; - + enableTest = pchip->chipspecops->enable_configuration(pchip); disableTest = pchip->chipspecops->disable_configuration(pchip); if( enableTest || disableTest) { @@ -152,9 +177,9 @@ int hms30c7202_reset( struct candevice_t *candev) CANMSG("Please check your hardware.\n"); return -ENODEV; } - + /* Check busoff status */ - + while ( (c_can_read_reg_w(pchip, CCSR) & SR_BOFF) && (i<=15)) { udelay(20000); i++; @@ -166,7 +191,7 @@ int hms30c7202_reset( struct candevice_t *candev) } else DEBUGMSG("Chip0 reset status ok.\n"); - + //pchip->config_irqs(pchip, CR_MIE | CR_SIE | CR_EIE); return 0; } @@ -189,14 +214,14 @@ int hms30c7202_reset( struct candevice_t *candev) * Return Value: The function always returns zero * File: src/template.c */ -int hms30c7202_init_hw_data(struct candevice_t *candev) +int hms30c7202_init_hw_data(struct candevice_t *candev) /*( struct canchip_t *pchip, u16 chip_nr, u16 startminor, u32 baseaddr, u8 irq )*/ { // u32 intCntrVAddr = 0; can_ioptr_t gpioVAddr = 0; u32 tempReg = 0; u32 baseaddr=candev->io_addr; - + // if ( (!( intCntrVAddr = ioremap( 0x80024000, 0xCD ) )) // & (! ( gpioVAddr = ioremap( 0x80023000, 0xAD ) ))) { // DEBUGMSG("Failed to map Int and GPIO memory\n"); @@ -206,7 +231,7 @@ int hms30c7202_init_hw_data(struct candevice_t *candev) DEBUGMSG("Failed to map GPIO memory\n"); return -EIO; } else { - + // DEBUGMSG( "Mapped Interrupt Controller IO-memory: 0x%lx - 0x%lx to 0x%lx\n", // (unsigned long)0X80024000, // (unsigned long)0X800240CC, @@ -216,7 +241,7 @@ int hms30c7202_init_hw_data(struct candevice_t *candev) (unsigned long)0X800240AC, (unsigned long)gpioVAddr); } - + if (baseaddr == 0x8002f000) { // tempReg = can_readl(intCntrVAddr); // DEBUGMSG("Read Interrupt Enable Register : 0x%.4lx\n",(long)tempReg); @@ -268,7 +293,7 @@ int hms30c7202_init_hw_data(struct candevice_t *candev) // Initialize chip data ( only one chip ) // pcandev->pchip[ 0 ]->powner = pcandev; /*pchip->ntype = CAN_CHIPTYPE_C_CAN;*/ - + candev->nr_82527_chips=0; candev->nr_sja1000_chips=0; candev->nr_all_chips=NR_C_CAN; @@ -300,14 +325,14 @@ int hms30c7202_init_chip_data(struct candevice_t *candev, int chipnr) candev->chip[chipnr]->max_objects = NR_MSGOBJ; candev->chip[chipnr]->chip_base_addr=candev->io_addr; - + candev->chip[chipnr]->clock = 16000000/2; - + /*candev->chip[chipnr]->int_clk_reg = 0x0; candev->chip[chipnr]->int_bus_reg = 0x0; candev->chip[chipnr]->sja_cdr_reg = 0x0; candev->chip[chipnr]->sja_ocr_reg = 0x0;*/ - + return 0; } @@ -320,9 +345,9 @@ int hms30c7202_init_chip_data(struct candevice_t *candev, int chipnr) * * The function hms30c7202_init_obj_data() is used to initialize the hardware * structure containing information about the different message objects on the - * CAN chip. - * The entry @obj_base_addr represents the first memory address of the message - * object. + * CAN chip. + * The entry @obj_base_addr represents the first memory address of the message + * object. * Unless the hardware uses a segmented memory map, flags can be set zero. * Return Value: The function always returns zero * File: src/template.c @@ -334,7 +359,7 @@ int hms30c7202_init_obj_data(struct canchip_t *chip, int objnr) /* It seems, that there is no purpose to setup object base address */ chip->msgobj[objnr]->obj_base_addr=0; - + /*can_msgobj_test_fl(pmsgobj,RX_MODE_EXT);*/ return 0; } @@ -360,9 +385,9 @@ void hms30c7202_write_register(unsigned data, can_ioptr_t address) address = can_ulong2ioptr(((addr & C_CAN_REGOFFS_MASK) << 1) | (addr & ~C_CAN_REGOFFS_MASK)); - + //DEBUGMSG("Trying to write 0x%u16x to address 0x%lx\n",data,address); - + can_writew(data,address); //udelay( usecs ); for (i=0; i<5; i++); @@ -383,19 +408,19 @@ unsigned hms30c7202_read_register(can_ioptr_t address) { unsigned long addr=can_ioptr2ulong(address); u16 value, i; - + address = can_ulong2ioptr(((addr & C_CAN_REGOFFS_MASK) << 1) | (addr & ~C_CAN_REGOFFS_MASK)); //DEBUGMSG("Trying to read from address 0x%lx :",address); - + value = can_readw(address); //udelay( usecs ); for (i=0;i<5;i++); value = can_readw(address); //udelay( usecs ); for (i=0;i<5;i++); - + //DEBUGMSG("0x%u16x\n",value); return value; @@ -405,10 +430,10 @@ unsigned hms30c7202_read_register(can_ioptr_t address) * hms30c7202_program_irq - program interrupts * @candev: Pointer to candevice/board structure * - * The function hms30c7202_program_irq() is used for hardware that uses + * The function hms30c7202_program_irq() is used for hardware that uses * programmable interrupts. If your hardware doesn't use programmable interrupts - * you should not set the @candevices_t->flags entry to %CANDEV_PROGRAMMABLE_IRQ and - * leave this function unedited. Again this function is hardware specific so + * you should not set the @candevices_t->flags entry to %CANDEV_PROGRAMMABLE_IRQ and + * leave this function unedited. Again this function is hardware specific so * there's no example code. * Return value: The function returns zero on success or %-ENODEV on failure * File: src/template.c