]> rtime.felk.cvut.cz Git - lincan.git/commitdiff
Merge branch 'master' into can-usb1
authorPavel Pisa <pisa@cmp.felk.cvut.cz>
Sat, 25 Jul 2015 21:14:55 +0000 (23:14 +0200)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Sat, 25 Jul 2015 21:14:55 +0000 (23:14 +0200)
1  2 
lincan/include/can_sysdep.h
lincan/include/main.h
lincan/src/open.c

index 60c76de28b8d551ba900621c9650937656e41383,165d4a12e1fb37dc3cbb82a61b3e7ce000ca9844..b2c8d83e3d5ce0ff54c2d1ad7d58dca944038c01
@@@ -56,9 -56,6 +56,9 @@@
  #include <linux/sched.h>
  #include <linux/interrupt.h>
  #include <linux/time.h>
 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10))
 +      #include <linux/kref.h>
 +#endif
  #include <asm/errno.h>
  
  #include <asm/io.h>
  
  #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,7)) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
  
- #define MINOR_NR \
-       (MINOR(file->f_dentry->d_inode->i_rdev))
+ #define INODE2MINOR_NR(inode) \
+       (MINOR(inode->i_rdev))
  
  #else /* Linux kernel < 2.5.7 or >= 2.6.0 */
  
- #define MINOR_NR \
-       (minor(file->f_dentry->d_inode->i_rdev))
+ #define INODE2MINOR_NR(inode) \
+       (minor(inode->i_rdev))
  
  #endif /* Linux kernel < 2.5.7 or >= 2.6.0 */
  
@@@ -307,20 -304,4 +307,20 @@@ extern can_spinlock_t can_irq_manipulat
  
  #endif /*CAN_WITH_RTL*/
  
 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4))
 +      #include <linux/kthread.h>
 +      #define can_kthread_create      kthread_create
 +      #define can_kthread_run kthread_run
 +      #define can_kthread_bind        kthread_bind
 +      #define can_kthread_stop        kthread_stop
 +      #define can_kthread_should_stop kthread_should_stop
 +#else
 +      #define can_kthread_create
 +      #define can_kthread_run
 +      #define can_kthread_bind
 +      #define can_kthread_stop
 +      #define can_kthread_should_stop
 +#endif
 +
 +
  #endif /*_CAN_SYSDEP_H*/
diff --combined lincan/include/main.h
index f7a302c53d25ad219ad709cda402044578c2b9bc,663f81f8bb64f2e86e8540438dd6e9fa34457b49..aad913dfcd979b7beae0e832b5dee002818aed0c
@@@ -113,10 -113,6 +113,10 @@@ struct candevice_t 
  
        struct canhardware_t *hosthardware_p;
  
 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10))
 +      struct kref refcount;
 +#endif
 +
        union {
                void *anydev;
            #ifdef CAN_ENABLE_PCI_SUPPORT
@@@ -185,7 -181,7 +185,7 @@@ struct canchip_t 
        int chip_idx;   /* chip index in candevice_t.chip[] */
        int chip_irq;
        can_ioptr_t chip_base_addr;
 -      unsigned int flags;
 +      uint16_t flags;
        long clock; /* Chip clock in Hz */
        long baudrate;
  
@@@ -331,11 -327,6 +331,11 @@@ struct hwspecops_t 
        int (*program_irq)(struct candevice_t *candev);
        void (*write_register)(unsigned data, can_ioptr_t address);
        unsigned (*read_register)(can_ioptr_t address);
 +
 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10))
 +      void (*release_device)(struct kref *refcount);
 +#endif
 +
  };
  
  /**
@@@ -406,6 -397,7 +406,7 @@@ struct mem_addr 
  /* Structure for the RTR queue */
  struct rtr_id {
        unsigned long id;
+       int ready_fl;
        struct canmsg_t *rtr_message;
        wait_queue_head_t rtr_wq;
        struct rtr_id *next;
@@@ -429,7 -421,7 +430,7 @@@ extern struct mem_addr *mem_head
  
  
  #if defined(CONFIG_OC_LINCAN_PORTIO_ONLY)
 -extern inline void can_write_reg(const struct canchip_t *chip, unsigned char data, unsigned reg_offs)
 +extern inline void can_write_reg(const struct canchip_t *chip, unsigned data, unsigned reg_offs)
  {
        can_outb(data, chip->chip_base_addr+reg_offs);
  }
@@@ -438,7 -430,7 +439,7 @@@ extern inline unsigned can_read_reg(con
        return can_inb(chip->chip_base_addr+reg_offs);
  }
  extern inline void canobj_write_reg(const struct canchip_t *chip, const struct msgobj_t *obj,
 -                              unsigned char data, unsigned reg_offs)
 +                              unsigned data, unsigned reg_offs)
  {
        can_outb(data, obj->obj_base_addr+reg_offs);
  }
@@@ -449,7 -441,7 +450,7 @@@ extern inline unsigned canobj_read_reg(
  }
  
  #elif defined(CONFIG_OC_LINCAN_MEMIO_ONLY)
 -extern inline void can_write_reg(const struct canchip_t *chip, unsigned char data, unsigned reg_offs)
 +extern inline void can_write_reg(const struct canchip_t *chip, unsigned data, unsigned reg_offs)
  {
        can_writeb(data, chip->chip_base_addr+reg_offs);
  }
@@@ -458,7 -450,7 +459,7 @@@ extern inline unsigned can_read_reg(con
        return can_readb(chip->chip_base_addr+reg_offs);
  }
  extern inline void canobj_write_reg(const struct canchip_t *chip, const struct msgobj_t *obj,
 -                              unsigned char data, unsigned reg_offs)
 +                              unsigned data, unsigned reg_offs)
  {
        can_writeb(data, obj->obj_base_addr+reg_offs);
  }
@@@ -476,7 -468,7 +477,7 @@@ extern inline unsigned canobj_read_reg(
  /* Inline function to write to the hardware registers. The argument reg_offs is
   * relative to the memory map of the chip and not the absolute memory reg_offs.
   */
 -extern inline void can_write_reg(const struct canchip_t *chip, unsigned char data, unsigned reg_offs)
 +extern inline void can_write_reg(const struct canchip_t *chip, unsigned data, unsigned reg_offs)
  {
        can_ioptr_t address_to_write;
        address_to_write = chip->chip_base_addr+reg_offs;
@@@ -491,7 -483,7 +492,7 @@@ extern inline unsigned can_read_reg(con
  }
  
  extern inline void canobj_write_reg(const struct canchip_t *chip, const struct msgobj_t *obj,
 -                              unsigned char data, unsigned reg_offs)
 +                              unsigned data, unsigned reg_offs)
  {
        can_ioptr_t address_to_write;
        address_to_write = obj->obj_base_addr+reg_offs;
@@@ -553,7 -545,3 +554,7 @@@ void can_filltimestamp(canmsg_tstamp_t 
  #ifdef CAN_WITH_RTL
  extern int can_rtl_priority;
  #endif /*CAN_WITH_RTL*/
 +
 +extern struct candevice_t* register_hotplug_dev(const char *hwname,int (*chipdataregfnc)(struct canchip_t *chip,void *data),void *devdata);
 +extern void deregister_hotplug_dev(struct candevice_t *dev);
 +extern void cleanup_hotplug_dev(struct candevice_t *dev);
diff --combined lincan/src/open.c
index 942225a8fbaa4c726340e98a5fc6753d6b311a59,219aab96787bb618e0febb8cc0578ee321266b1f..266aed414743109592a41cfade17c54f15332bd4
@@@ -50,15 -50,21 +50,21 @@@ int can_open(struct inode *inode, struc
        struct canque_edge_t *edge;
        can_spin_irqflags_t iflags;
        char openflag;          // Martin Petera: Object already opened
+       int minor_nr = INODE2MINOR_NR(inode);
  
-       if ( ((obj=objects_p[MINOR_NR]) == NULL) ||
-                       ((chip=objects_p[MINOR_NR]->hostchip) == NULL) ) {
-               CANMSG("There is no hardware support for the device file with minor nr.: %d\n",MINOR_NR);
+       if ((minor_nr < 0) || (minor_nr >= MAX_TOT_MSGOBJS)) {
+               CANMSG("can_open: bad minor %d\n", minor_nr);
+               return -ENODEV;
+       }
+       if ( ((obj=objects_p[minor_nr]) == NULL) ||
+           ((chip=objects_p[minor_nr]->hostchip) == NULL) ) {
+               CANMSG("There is no hardware support for the device file with minor nr.: %d\n", minor_nr);
                return -ENODEV;
        }
  
        atomic_inc(&obj->obj_used);
-       DEBUGMSG("Device %d opened %d times.\n", MINOR_NR, atomic_read(&obj->obj_used));
+       DEBUGMSG("Device %d opened %d times.\n", minor_nr, atomic_read(&obj->obj_used));
        openflag = can_msgobj_test_fl(obj,OPENED);      // Martin Petera: store previous status
        can_msgobj_set_fl(obj,OPENED);
  
                        CANMSG("Error initializing chip for receiving\n");
        }
  
 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10))
 +      if (chip->hostdevice->hwspecops->release_device)
 +              kref_get(&chip->hostdevice->refcount);
 +#endif
  
        canuser = (struct canuser_t *)kmalloc(sizeof(struct canuser_t), GFP_KERNEL);
        if(canuser == NULL) goto no_canuser;