Пример #1
0
static int dm_init(void)
{
	int result;
	int devno;
	struct drvr_mem * memDev;

	dev_t dev = 0;
	result = alloc_chrdev_region(&dev, 0, 1, DEVICE_NAME);
	gDrvrMajor = MAJOR(dev);

	if (result < 0) {
		DBG_LOG("Registering char device failed with %d\n", gDrvrMajor);

		return result;
	}

	drvr_devices = kmalloc(sizeof(struct drvr_device), GFP_KERNEL);

	if (!drvr_devices) {
		dm_exit();

		return -ENOMEM;
	}

	drvr_class = class_create(THIS_MODULE, DEVICE_NAME);
	memset(drvr_devices, 0, sizeof(struct drvr_device));

	//printk(KERN_INFO "'mknod /dev/%s c %d %d'.\n", DEVICE_NAME, gDrvrMajor, 0);
	/* Initialize each device. */
	devno = MKDEV(gDrvrMajor, 0);
	memDev = &(drvr_devices[0].data);
	memDev->base_addr = (unsigned short *) (FPGA_BASE_ADDR);
	device_create(drvr_class, prog_device, devno, NULL, DEVICE_NAME_MEM);
	cdev_init(&(drvr_devices[0].cdev), &dm_ops);
	(drvr_devices[0].cdev).owner = THIS_MODULE;
	(drvr_devices[0].cdev).ops = &dm_ops;
	cdev_add(&(drvr_devices[0].cdev), devno, 1);
	drvr_devices[0].opened = 0;
	logi_dma_init();

	return ioctl_init();
}
Пример #2
0
static int dm_init(void)
{
	int result;
	int devno;
	struct drvr_mem * memDev;
	struct drvr_prog * progDev;
	struct i2c_adapter *i2c_adap;

	dev_t dev = 0;
	result = alloc_chrdev_region(&dev, 0, 2, DEVICE_NAME);
	gDrvrMajor = MAJOR(dev);

	if (result < 0) {
		DBG_LOG("Registering char device failed with %d\n", gDrvrMajor);

		return result;
	}

	drvr_devices = kmalloc(2 * sizeof(struct drvr_device), GFP_KERNEL);

	if (!drvr_devices) {
		dm_exit();

		return -ENOMEM;
	}

	drvr_class = class_create(THIS_MODULE, DEVICE_NAME);
	memset(drvr_devices, 0, 2 * sizeof(struct drvr_device));

	/*Initializing main mdevice for prog*/
	devno = MKDEV(gDrvrMajor, 0);
	drvr_devices[0].type = prog;
	progDev = &(drvr_devices[0].data.prog);
	prog_device = device_create(drvr_class, NULL, devno, NULL, DEVICE_NAME);//should create /dev entry for main node
	drvr_devices[0].opened = 0;

	/*Do the i2c stuff*/
	i2c_adap = i2c_get_adapter(I2C_ADAPTER);

	if (i2c_adap == NULL) {
		DBG_LOG("Cannot get I2C adapter %i\n", I2C_ADAPTER);
		dm_exit();

		return -ENODEV;
	}

	progDev->i2c_io = i2c_new_device(i2c_adap, &io_exp_info);

	if (prog_device == NULL) {
		class_destroy(drvr_class);
		drvr_devices[0].opened = 0;
		dm_exit();

		return -ENOMEM;
	}

	cdev_init(&(drvr_devices[0].cdev), &dm_ops);
	drvr_devices[0].cdev.owner = THIS_MODULE;
	drvr_devices[0].cdev.ops = &dm_ops;
	cdev_add(&(drvr_devices[0].cdev), devno, 1);
	//printk(KERN_INFO "'mknod /dev/%s c %d %d'.\n", DEVICE_NAME, gDrvrMajor, 0);
	/* Initialize each device. */
	devno = MKDEV(gDrvrMajor, 1);
	drvr_devices[1].type = mem;
	memDev = &(drvr_devices[1].data.mem);
	memDev->base_addr = (unsigned short *) (FPGA_BASE_ADDR);
	device_create(drvr_class, prog_device, devno, NULL, DEVICE_NAME_MEM);
	cdev_init(&(drvr_devices[1].cdev), &dm_ops);
	(drvr_devices[1].cdev).owner = THIS_MODULE;
	(drvr_devices[1].cdev).ops = &dm_ops;
	cdev_add(&(drvr_devices[1].cdev), devno, 1);
	drvr_devices[1].opened = 0;
	logi_dma_init();

	return ioctl_init();
}