]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/hms30c7202_can.c
changed usb vendor and product id.
[lincan.git] / lincan / src / hms30c7202_can.c
index fc130439e58c0a3c4413eebaf9a72194664334a6..1a18904a1cf1192f8ba542fd8b31243f3f6ebf46 100644 (file)
@@ -6,7 +6,7 @@
  * 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.2  9 Jul 2003
+ * Version lincan-0.3  17 Jun 2004
  */
 
 #include <linux/delay.h>
@@ -40,7 +40,7 @@
  */
 int hms30c7202_request_io(struct candevice_t *candev)
 {
-       DEBUGMSG("(c%d)calling hms30c7202_request_io(...)\n", pchip->chip_nr);
+       DEBUGMSG("(c%d)calling hms30c7202_request_io(...)\n", candev->chip[0]->chip_idx);
 
        if(!can_request_mem_region(candev->io_addr, IO_RANGE, DEVICE_NAME )) {
                CANMSG("hmsc30c7202_can failed to request mem region %lx.\n",
@@ -143,7 +143,7 @@ int hms30c7202_reset(  struct candevice_t *candev)
 {
        int i=0;
        int enableTest=0, disableTest=0;
-       struct chip_t *pchip = candev->chip[0];
+       struct canchip_t *pchip = candev->chip[0];
        
        enableTest = pchip->chipspecops->enable_configuration(pchip);
        disableTest = pchip->chipspecops->disable_configuration(pchip);
@@ -190,7 +190,7 @@ int hms30c7202_reset(  struct candevice_t *candev)
  * File: src/template.c
  */
 int hms30c7202_init_hw_data(struct candevice_t *candev) 
-/*( struct chip_t *pchip, u16 chip_nr, u16 startminor, u32 baseaddr, u8 irq )*/
+/*( struct canchip_t *pchip, u16 chip_nr, u16 startminor, u32 baseaddr, u8 irq )*/
 {
        //      u32 intCntrVAddr = 0;
        u32 gpioVAddr = 0;
@@ -294,20 +294,20 @@ int hms30c7202_init_hw_data(struct candevice_t *candev)
  */
 int hms30c7202_init_chip_data(struct candevice_t *candev, int chipnr)
 {
-       candev->chip[chipnr]->chip_type=CHIP_TYPE;
+       // Register chip operations
+       c_can_fill_chipspecops(candev->chip[chipnr]);
+       /* override chip provided default value */
+       candev->chip[chipnr]->max_objects = NR_MSGOBJ;
+
        candev->chip[chipnr]->chip_base_addr=candev->io_addr;
        
-       candev->chip[chipnr]->clock = 16000000;
-       
-       candev->chip[chipnr]->max_objects = NR_MSGOBJ;
+       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;*/
        
-       // Register chip operations
-       c_can_register(candev->chip[chipnr]->chipspecops);
 
        return 0;
 }
@@ -327,10 +327,10 @@ int hms30c7202_init_chip_data(struct candevice_t *candev, int chipnr)
  * Return Value: The function always returns zero
  * File: src/template.c
  */
-int hms30c7202_init_obj_data(struct chip_t *chip, int objnr)
+int hms30c7202_init_obj_data(struct canchip_t *chip, int objnr)
 {
 
-       DEBUGMSG("(c%d)calling hms30c7202_init_obj_data( ...)\n", pchip->chip_nr);
+       DEBUGMSG("(c%d)calling hms30c7202_init_obj_data( ...)\n", chip->chip_idx);
 
        /* It seems, that there is no purpose to setup object base address */
        chip->msgobj[objnr]->obj_base_addr=0;
@@ -345,8 +345,9 @@ int hms30c7202_init_obj_data(struct chip_t *chip, int objnr)
  * @address: memory address to write to
  *
  * The function hms30c7202_write_register() is used to write to hardware registers
- * on the CAN chip. You should only have to edit this function if your hardware
- * uses some specific write process.
+ * on the CAN chip. The registers are mapped on 32 bit bus on hms30c7202
+ * and thus registers span is twice as one defined by C_CAN manual and defines.
+ * This function compensates this difference.
  * Return Value: The function does not return a value
  * File: src/template.c
  */
@@ -355,6 +356,9 @@ void hms30c7202_write_register(unsigned data, unsigned long address)
 {
        int i;
        //unsigned long usecs = 1;
+
+       address = ((address & C_CAN_REGOFFS_MASK) << 1) |
+                 (address & ~C_CAN_REGOFFS_MASK);
        
        //DEBUGMSG("Trying to write 0x%u16x to address 0x%lx\n",data,address);
        
@@ -368,8 +372,9 @@ void hms30c7202_write_register(unsigned data, unsigned long address)
  * @address: memory address to read from
  *
  * The function hms30c7202_read_register() is used to read from hardware registers
- * on the CAN chip. You should only have to edit this function if your hardware
- * uses some specific read process.
+ * on the CAN chip. The registers are mapped on 32 bit bus on hms30c7202
+ * and thus registers span is twice as one defined by C_CAN manual and defines.
+ * This function compensates this difference.
  * Return Value: The function returns the value stored in @address
  * File: src/template.c
  */
@@ -377,6 +382,9 @@ unsigned hms30c7202_read_register(unsigned long address)
 {
        u16 value, i;
        
+       address = ((address & C_CAN_REGOFFS_MASK) << 1) |
+                 (address & ~C_CAN_REGOFFS_MASK);
+
        //DEBUGMSG("Trying to read from address 0x%lx :",address);
        
        value = readw(address);