Merge branch 'master' into can-usb1
authorppisa <pisa@cmp.felk.cvut.cz>
Sat, 1 Nov 2008 12:40:35 +0000 (13:40 +0100)
committerppisa <pisa@cmp.felk.cvut.cz>
Sat, 1 Nov 2008 12:40:35 +0000 (13:40 +0100)
The changes between LinCAN 0.3.3 version and current master head are propagated
into "can-usb1" branch.

Conflicts:

lincan/include/kthread.h
lincan/include/main.h
lincan/src/Makefile.omk
lincan/src/bfadcan.c
lincan/src/boardlist.c
lincan/src/finish.c
lincan/src/kthread.c
lincan/src/main.c
lincan/src/modparms.c
lincan/src/proc.c
lincan/src/setup.c

1  2 
lincan/include/can_sysdep.h
lincan/include/main.h
lincan/src/Makefile.omk
lincan/src/boardlist.c
lincan/src/main.c
lincan/src/modparms.c
lincan/src/proc.c
lincan/src/setup.c

Simple merge
Simple merge
@@@ -1,8 -1,8 +1,8 @@@
  lincan_cards_NAMES = pip pccan smartcan nsi cc_can104 ems_cpcpci \
-               pc_i03 pcm3680 aim104 m437 pcccan ssv bfadcan pikronisa eb8245 \
-               kv_pcican msmcan oscar adlink7841 unican virtual template usbcan
+               pc_i03 pcm3680 aim104 m437 pcccan ssv bfadcan gensja1000io pikronisa eb8245 \
 -              kv_pcican msmcan oscar adlink7841 pcan_pci esdpci200 unican virtual template
++              kv_pcican msmcan oscar adlink7841 pcan_pci esdpci200 unican usbcan virtual template
  
- lincan_morecards_NAMES = hms30c7202_can ns_dev_can ipci165 pimx1 tscan1 nsi_canpci
+ lincan_morecards_NAMES = hms30c7202_can ns_dev_can ipci165 pimx1 tscan1 nsi_canpci sh7760
  
  default_CONFIG = CONFIG_OC_LINCAN=y CONFIG_OC_LINCANRTL=n CONFIG_OC_LINCANVME=n
  default_CONFIG += CONFIG_OC_LINCAN_PORTIO_ONLY=n CONFIG_OC_LINCAN_MEMIO_ONLY=n
@@@ -33,10 -33,10 +33,14 @@@ ifeq ($(CONFIG_OC_LINCAN_CARD_ipci165),
  lincan_cards_SOURCES += ipci165_fw.c kthread.c
  endif
  
+ ifeq ($(CONFIG_OC_LINCAN_CARD_sh7760),y)
+ lincan_cards_SOURCES += sh7760.c
+ endif
 +ifeq ($(CONFIG_OC_LINCAN_CARD_usbcan),y)
 +lincan_cards_SOURCES += kthread.c
 +endif
 +
  ifneq ($(filter hms30c7202_can ns_dev_can,$(lincan_cards_SELECTED)),)
  $(warning Not finished C_CAN support requested)
  lincan_cards_SOURCES += c_can.c c_can_irq.c
@@@ -44,7 -45,9 +45,10 @@@ extern int ts7kv_register(struct hwspec
  extern int ns_dev_register(struct hwspecops_t *hwspecops);
  extern int hms30c7202_register(struct hwspecops_t *hwspecops);
  extern int nsi_canpci_register(struct hwspecops_t *hwspecops);
 +extern int usbcan_register(struct hwspecops_t *hwspecops);
+ extern int pcan_pci_register(struct hwspecops_t *hwspecops);
+ extern int esdpci200_register(struct hwspecops_t *hwspecops);
+ extern int sh7760_register(struct hwspecops_t *hwspecops);
  
  const struct boardtype_t can_boardtypes[]={
      #ifdef CONFIG_OC_LINCAN_CARD_template
      #if defined(CONFIG_OC_LINCAN_CARD_nsi_canpci)&&defined(CAN_ENABLE_PCI_SUPPORT)
        {"nsicanpci", nsi_canpci_register, 1},
      #endif
+     #if defined(CONFIG_OC_LINCAN_CARD_pcan_pci)&&defined(CAN_ENABLE_PCI_SUPPORT)
+       {"pcan_pci", pcan_pci_register, 0},
++    #endif
 +    #if defined(CONFIG_OC_LINCAN_CARD_usbcan)
 +      {"usbcan", usbcan_register, 0},
      #endif
        {NULL}
  };
@@@ -409,215 -400,12 +413,225 @@@ int init_module(void
                return -ENODEV;
  }
  
-                       #else /* >= 2.6.15 */
 +
 +
 +
 +
 +struct candevice_t* register_usbdev(const char *hwname,void *devdata,void (*chipdataregfnc)(struct canchip_t *ch,void *data)){
 +      int i=0, j, board=0;
 +      struct candevice_t *candev;
 +      struct canchip_t *chip;
 +      struct boardtype_t *brp;
 +
 +      while ( (hw[board] != NULL) && (board < MAX_HW_CARDS) )
 +              board++;
 +      if (board>=MAX_HW_CARDS){
 +              CANMSG("Maximum number of devices has been reached, no space for new device");
 +              return NULL;
 +      }
 +      brp = boardtype_find(hwname);
 +      if(!brp) {
 +              CANMSG("Sorry, hardware \"%s\" is currently not supported.\n",hw[board]);
 +              return NULL;
 +      }
 +      if (board==MAX_HW_CARDS){
 +                      CANMSG("Device \"%s\" could not be registered due to internal limits.\n",hw[board]);
 +                      return NULL;
 +      }
 +      hw[board]=brp->boardtype;
 +
 +      if (init_new_hw_struct(board))
 +              return NULL;
 +
 +      #ifdef CAN_DEBUG
 +              list_hw();
 +      #endif
 +
 +      candev=hardware_p->candevice[board];
 +
 +      /* Adding link to usb device structure into can device */
 +      candev->sysdevptr.anydev=devdata;
 +
 +      if (candev->hwspecops->request_io(candev))
 +              goto request_io_error;
 +      candev->flags|=CANDEV_IO_RESERVED;
 +
 +      if (candev->hwspecops->reset(candev))
 +              goto reset_error;
 +
 +      for(j=0; j<candev->nr_all_chips; j++) {
 +              if((chip=candev->chip[j])==NULL)
 +                      continue;
 +
 +              chipdataregfnc(chip,devdata);
 +
 +              if(chip->chipspecops->attach_to_chip(chip)<0) {
 +                      CANMSG("Initial attach to the chip HW failed\n");
 +                      goto interrupt_error;
 +              }
 +
 +              chip->flags |= CHIP_ATTACHED;
 +
 +              if(can_chip_setup_irq(chip)<0) {
 +                      CANMSG("Error to setup chip IRQ\n");
 +                      goto interrupt_error;
 +              }
 +      }
 +
 +      if (candev->flags & CANDEV_PROGRAMMABLE_IRQ)
 +              if (candev->hwspecops->program_irq(candev)){
 +                      CANMSG("Error to program board interrupt\n");
 +                      goto interrupt_error;
 +              }
 +
 +#ifdef CONFIG_PROC_FS
 +      if (can_init_procentry(board))
 +              goto proc_error;
 +#endif
 +
 +#if defined(CONFIG_DEVFS_FS) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
 +      {
 +              #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0))
 +              char dev_name[32];
 +              #else
 +              struct class_device *this_dev;
 +              #endif
 +              int dev_minor;
 +              for(i=0;i<MAX_TOT_MSGOBJS;i++) {
 +                      if(!objects_p[i]) continue;
 +                      if(objects_p[i]->hostchip->hostdevice != candev) continue;
 +
 +                      dev_minor=objects_p[i]->minor;
 +                      #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0))
 +                      sprintf (dev_name, "can%d", dev_minor);
 +                      devfs_handles[i]=devfs_register(NULL, dev_name,
 +                      DEVFS_FL_DEFAULT, major, dev_minor,
 +                      S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
 +                      &can_fops, (void*)objects_p[i]);
 +                      #else
 +                      #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,14))
 +                      this_dev=class_device_create(can_class, MKDEV(major, dev_minor), NULL,  "can%d", dev_minor);
-                       #endif /* >= 2.6.15 */
++                      #elif  LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,25) /* >= 2.6.15 */
 +                      this_dev=class_device_create(can_class, NULL, MKDEV(major, dev_minor), NULL,  "can%d", dev_minor);
++                      #else /* >= 2.6.26 */
++                      this_dev=device_create_drvdata(can_class, NULL, MKDEV(major, dev_minor), objects_p[i],  "can%d", dev_minor);
++                      #endif /* >= 2.6.26 */
 +                      if(IS_ERR(this_dev)){
 +                              CANMSG("problem to create device \"can%d\" in the class \"can\"\n", dev_minor);
++                    #if  LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,25)
 +                      }else{
 +                              /*this_dev->class_data=objects_p[i];*/
 +                              class_set_devdata(this_dev,objects_p[i]);
++                    #endif /* <= 2.6.25 */
 +                      }
 +                      #ifdef CONFIG_DEVFS_FS
 +                      devfs_mk_cdev(MKDEV(major, dev_minor), S_IFCHR | S_IRUGO | S_IWUGO, "can%d", dev_minor);
 +                      #endif
 +                      #endif
 +              }
 +      }
 +#endif
 +      return candev;
 +
 +#ifdef CONFIG_PROC_FS
 +      proc_error: ;
 +              CANMSG("Error registering /proc entry.\n");
 +              goto memory_error;
 +#endif
 +
 +      interrupt_error: ;
 +              goto memory_error;
 +
 +      reset_error: ;
 +              CANMSG("Error resetting device.\n");
 +              goto memory_error;
 +
 +      request_io_error: ;
 +              CANMSG("Error to request IO resources for device.\n");
 +              goto memory_error;
 +
 +      memory_error: ;
 +
 +              #ifdef CAN_WITH_RTL
 +      rtldev_error:
 +              #endif /*CAN_WITH_RTL*/
 +
 +//    register_error:
 +              if ( can_del_mem_list() )
 +                      CANMSG("Error deallocating memory\n");
 +
 +              return NULL;
 +}
 +
 +
 +
 +
 +
 +
 +
 +void cleanup_usbdev(struct candevice_t *dev)
 +{
 +      int i=0;
 +      int dev_minor;
 +
 +      if (!dev)
 +              return;
 +
 +#ifdef CONFIG_PROC_FS
 +      if (can_delete_procentry(dev))
 +              CANMSG("Error unregistering /proc/can entry.\n");
 +#endif
 +
 +#if defined(CONFIG_DEVFS_FS) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
 +      for(i=0;i<MAX_TOT_MSGOBJS;i++) {
 +              if(!objects_p[i]) continue;
 +              if(objects_p[i]->hostchip->hostdevice != dev) continue;
 +              #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0))
 +              if(devfs_handles[i])
 +                      devfs_unregister(devfs_handles[i]);
 +              #else
 +              dev_minor=objects_p[i]->minor;
 +              if(dev_minor>=0){
 +                      #ifdef CONFIG_DEVFS_FS
 +                      devfs_remove("can%d", dev_minor);
 +                      #endif
++                      #if  LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,25)
 +                      class_device_destroy(can_class, MKDEV(major, dev_minor));
++                      #else /* >= 2.6.26 */
++                      device_destroy(can_class, MKDEV(major, dev_minor));
++                      #endif /* >= 2.6.26 */
 +              }
 +              #endif
 +      }
 +#endif
 +
 +      for(i=0;i<MAX_TOT_CHIPS;i++){
 +              if(!chips_p[i]) continue;
 +              if(chips_p[i]->hostdevice != dev) continue;
 +              chips_p[i]=NULL;
 +      }
 +
 +      hardware_p->candevice[dev->candev_idx]=NULL;
 +      hardware_p->nr_boards--;
 +      hw[dev->candev_idx]=NULL;
 +
 +      candevice_done(dev);
 +      can_checked_free(dev);
 +}
 +
 +
 +
 +
  void cleanup_module(void)
  {
-       int res=0,i=0;
+ #if defined(CONFIG_DEVFS_FS) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
+       int i=0;
+ #endif
  
 +#if defined(CONFIG_OC_LINCAN_CARD_usbcan)
 +      usbcan_exit();
 +#endif
 +
  #ifdef CONFIG_PROC_FS
        if (can_delete_procdir())
                CANMSG("Error unregistering /proc/can entry.\n");
@@@ -19,10 -19,9 +19,10 @@@ int parse_mod_parms(void
        const struct boardtype_t *brp;
  
        if ( (hw[0] == NULL) | (io[0] == -1) ) {
 -              CANMSG("You must supply your type of hardware, interrupt numbers and io address.\n");
 +              //CANMSG("You must supply your type of hardware, interrupt numbers and io address.\n");
 +              CANMSG("Autodetection works only for USB devices, supply your type of hardware for PCI devices \n");
-               CANMSG("Example: # insmod can.o hw=pip5 irq=4 io=0x8000\n");
+               CANMSG("Example: # insmod lincan.ko hw=pip5 irq=4 io=0x8000\n");
 -              return -ENODEV;
 +              //return -ENODEV;
        }
  
        while ( (hw[i] != NULL) && (i < MAX_HW_CARDS) ) {
@@@ -152,11 -155,8 +158,11 @@@ int can_init_procdir(void
  {
        int board;
        struct candevice_t *candev;
 +
 +      mutex_init(&proc_mutex);
 +
        base->can_proc_entry = can_create_proc_entry("can", S_IFDIR | S_IRUGO |
-                                       S_IXUGO, &proc_root);
+                                       S_IXUGO, CAN_PROC_ROOT);
        if (base->can_proc_entry == NULL)
                return -ENODEV;
  
@@@ -183,19 -171,10 +189,19 @@@ int can_init_procentry(int board
  /* can_delete_procdir removes the entire CAN tree from the proc system */
  int can_delete_procdir(void)
  {
 -      if (remove_channel_from_procdir()) 
 +      if (remove_channels_from_procdir())
                return -ENODEV;
        /* name: "can" */
-       if (can_remove_proc_entry(base->can_proc_entry, &proc_root))
 -      if (can_remove_proc_entry(base->can_proc_entry, CAN_PROC_ROOT)) 
++      if (can_remove_proc_entry(base->can_proc_entry, CAN_PROC_ROOT))
 +              return -ENODEV;
 +
 +      return 0;
 +}
 +
 +/* can_delete_procentry removes device entries from CAN tree in the proc system */
 +int can_delete_procentry(struct candevice_t *candev)
 +{
 +      if (remove_channel_from_procdir(candev))
                return -ENODEV;
  
        return 0;
  
  int init_hwspecops(struct candevice_t *candev, int *irqnum_p);
  int init_device_struct(int card, int *chan_param_idx_p, int *irq_param_idx_p);
- int init_chip_struct(struct candevice_t *candev, int chipnr, int irq, long baudrate);
+ int init_chip_struct(struct candevice_t *candev, int chipnr, int irq, long baudrate, long clock);
  int init_obj_struct(struct candevice_t *candev, struct canchip_t *hostchip, int objnr);
  
 +int next_minor=0;
 +
  /**
   * can_base_addr_fixup - relocates board physical memory addresses to the CPU accessible ones
   * @candev: pointer to the previously filled device/board, chips and message objects structures