From: Pavel Pisa Date: Sat, 25 Jul 2015 21:14:55 +0000 (+0200) Subject: Merge branch 'master' into can-usb1 X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/commitdiff_plain/3c47a7cd435662f7e2daa006596722271f5dd090?hp=-c Merge branch 'master' into can-usb1 --- 3c47a7cd435662f7e2daa006596722271f5dd090 diff --combined lincan/include/can_sysdep.h index 60c76de,165d4a1..b2c8d83 --- a/lincan/include/can_sysdep.h +++ b/lincan/include/can_sysdep.h @@@ -56,9 -56,6 +56,9 @@@ #include #include #include +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)) + #include +#endif #include #include @@@ -136,13 -133,13 +136,13 @@@ #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 + #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 f7a302c,663f81f..aad913d --- a/lincan/include/main.h +++ b/lincan/include/main.h @@@ -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 942225a,219aab9..266aed4 --- a/lincan/src/open.c +++ b/lincan/src/open.c @@@ -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); @@@ -82,10 -88,6 +88,10 @@@ 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;