void bbd_sensor_init_vars(struct bbd_device *dev, int* result)
{
        struct bbd_sensor_device *p = 0;

        if (*result)
                return;

	p = bbd_alloc(sizeof(struct bbd_sensor_device));
        if (!p) {
		*result = -ENOMEM;
		return;
        }

        bbd_base_init_vars(dev, &p->base, result);
        if (*result) {
                bbd_free(p);
                return;
        }
        p->priv_data = 0;
        p->callbacks = 0;
        dev->bbd_ptr[BBD_MINOR_SENSOR] = p;
        p->base.name = "sensor";
}
static int __init bbd_device_init(void)
{
	int ret   = -ENOMEM;
	int index =  0;
	dev_t devno[BBD_DEVICE_INDEX] = {0,};
	struct device *dev = NULL;
	struct class *bbd_class;	

	const char *dev_name[BBD_DEVICE_INDEX] = {
		"bbd_sensor",
		"bbd_control",
		"bbd_packet",
		"bbd_reliable",
		"bbd_patch",
		"bbd_ssi_spi_debug" };

	gpbbd_dev = bbd_alloc(sizeof(struct bbd_device));
	if (gpbbd_dev == NULL)
		return ret;

	ret = bbd_init_vars(gpbbd_dev);
	if (ret < 0)
		return ret;

	bbd_class = class_create(THIS_MODULE, "bbd");
	if (IS_ERR(bbd_class)) {
		printk(KERN_ERR "BBD:%s() failed to create class (ret=%d)\n",
					__func__, ret);
		return ret;
	}

	for (index = 0; index < BBD_DEVICE_INDEX; index++) {
		printk(KERN_INFO "BBD:%s(%d,%d)##### 204024 /dev/%s\n",
                            __func__, BBD_DEVICE_MAJOR,index, dev_name[index]);

		devno[index] = MKDEV(BBD_DEVICE_MAJOR, index);
                if (dev_name[index])
                    ret = register_chrdev_region(devno[index], 1, dev_name[index]);
                else
                    ret = -EFAULT;
		if (ret < 0) {
			printk(KERN_ERR "BBD:%s() failed to register char dev(%d) (ret=%d)\n",
						__func__, index, ret);
			return ret;
		}

		dev = device_create(bbd_class, NULL, MKDEV(BBD_DEVICE_MAJOR, index), NULL, 
					"%s", dev_name[index]);
		if (IS_ERR_OR_NULL(dev)) {
			printk(KERN_ERR "BBD:%s() failed to create device %s (ret=%d)\n",
						__func__, dev_name[index], ret);
			return ret;
		}

		cdev_init(&gpbbd_dev->dev[index], &bbd_fops[index]);

		gpbbd_dev->dev[index].owner = THIS_MODULE;
		gpbbd_dev->dev[index].ops   = &bbd_fops[index];
		ret = cdev_add(&gpbbd_dev->dev[index], devno[index], 1);
		if (ret) {
			printk(KERN_ERR "failed to add bbd_device device(ret=%d).\n",
						ret);
			return ret;
		}
	}

	ret = platform_device_register(&bbd_platform_dev);
	if (ret) {
		printk(KERN_ERR "%s(): failed to register platfrom device(bbd_device)\n",
		__func__);
		goto err;
	}
	dev = &bbd_platform_dev.dev;
	dev_set_drvdata(dev, (void *)gpbbd_dev);

	ret = bbd_sysfs_init(&dev->kobj);
	if (ret < 0) {
		goto err;
	}

        bbd_ssi_spi_open();

	return 0;

err:
	for (index = 0; index < BBD_DEVICE_INDEX; index++) {
		cdev_del(&gpbbd_dev->dev[index]);
		unregister_chrdev_region(MKDEV(bbd_dev_major, index), 1);
	}
        if (gpbbd_dev) {
            bbd_free(gpbbd_dev);
            gpbbd_dev = 0;
        }
	return ret;
}