Ejemplo n.º 1
0
//----------------------------------------------------------------------------
// create all declared isa devices
int pcan_create_isa_devices(char* type, u32 io, u16 irq)
{
  int    result = 0;
  struct pcandev *dev = NULL;

  // create isa devices
  DPRINTK(KERN_DEBUG "%s: pcan_create_isa_devices(0x%x, %d)\n", DEVICE_NAME, io, irq);
  
  if ((dev = (struct pcandev *)kmalloc(sizeof(struct pcandev), GFP_KERNEL)) == NULL)
  {
    result = -ENOMEM;
    goto fail;
  }

  pcan_soft_init(dev, type, HW_ISA_SJA);
  
  dev->device_open    = sja1000_open;
  dev->device_write   = sja1000_write;
  dev->device_release = sja1000_release;

  result = pcan_isa_init(dev, io, irq);
  if (!result)
    result = sja1000_probe(dev);

  if (result)
  {
    dev->cleanup(dev);
    kfree(dev);
    goto fail;
  }
  else
  {
    dev->ucPhysicallyInstalled = 1;
    list_add_tail(&dev->list, &pcan_drv.devices);  // add this device to the list
    pcan_drv.wDeviceCount++;
  }        
  
  fail:
  if (result)
    DPRINTK(KERN_DEBUG "%s: pcan_create_isa_devices() failed!\n", DEVICE_NAME);
  else
    DPRINTK(KERN_DEBUG "%s: pcan_create_isa_devices() is OK\n", DEVICE_NAME);

  return result;
}
Ejemplo n.º 2
0
//----------------------------------------------------------------------------
// is called by pcan_open() and pcan_netdev_open()
int pcan_open_path(PCAN_OPEN_PATH_ARGS)
{
	int err = 0;

	DPRINTK(KERN_DEBUG "%s: pcan_open_path, minor = %d, path = %d.\n",
		DEVICE_NAME, dev->nMinor, dev->nOpenPaths);

	// only the 1st open to this device makes a default init on this device
	if (!dev->nOpenPaths) {
		// empty all FIFOs
		err = pcan_fifo_reset(&dev->writeFifo);
		if (err)
			return err;
		err = pcan_fifo_reset(&dev->readFifo);
		if (err)
			return err;

		// open the interface special parts
		err = dev->open(dev);
		if (err) {
			DPRINTK(KERN_DEBUG
				"%s: can't open interface special parts!\n",
				DEVICE_NAME);
			return err;
		}

		/*
		 * special handling: probe here only for dongle devices,
		 * connect after init is possible
		 */
		if ((dev->wType == HW_DONGLE_SJA) ||
				(dev->wType == HW_DONGLE_SJA_EPP)) {
			err = sja1000_probe(dev); // no usb here, generic sja1000 call for dongle
			if (err) {
				DPRINTK(KERN_ERR
					"%s: %s-dongle device minor %d not found (io=0x%04x,irq=%d)\n",
					DEVICE_NAME, dev->type, dev->nMinor,
					dev->port.dng.dwPort,
					dev->port.dng.wIrq);
				dev->release(dev);
				return err;
			}
		}

		// install irq
		err = dev->req_irq(REQ_IRQ_ARG);

		if (err) {
			DPRINTK(KERN_DEBUG
				"%s: can't request irq from device!\n",
				DEVICE_NAME);
			return err;
		}

		// open the device itself
		err = dev->device_open(dev, dev->wBTR0BTR1, dev->ucCANMsgType,
				       dev->ucListenOnly);
		if (err) {
			DPRINTK(KERN_DEBUG
				"%s: can't open device hardware itself!\n",
				DEVICE_NAME);
			return err;
		}
	}

	dev->nOpenPaths++;

	DPRINTK(KERN_DEBUG "%s: pcan_open_path() is OK\n", DEVICE_NAME);

	return 0;
}