Exemple #1
0
/**
 * platform driver
 *
 */
static int __devinit dsps_probe(struct platform_device *pdev)
{
	int ret;

	pr_debug("%s.\n", __func__);

	if (pdev->dev.platform_data == NULL) {
		pr_err("%s: platform data is NULL.\n", __func__);
		return -ENODEV;
	}

	drv = kzalloc(sizeof(*drv), GFP_KERNEL);
	if (drv == NULL) {
		pr_err("%s: kzalloc fail.\n", __func__);
		goto alloc_err;
	}
	drv->pdata = pdev->dev.platform_data;

	drv->dev_class = class_create(THIS_MODULE, DRV_NAME);
	if (drv->dev_class == NULL) {
		pr_err("%s: class_create fail.\n", __func__);
		goto res_err;
	}

	ret = alloc_chrdev_region(&drv->dev_num, 0, 1, DRV_NAME);
	if (ret) {
		pr_err("%s: alloc_chrdev_region fail.\n", __func__);
		goto alloc_chrdev_region_err;
	}

	drv->dev = device_create(drv->dev_class, NULL,
				     drv->dev_num,
				     drv, DRV_NAME);
	if (IS_ERR(drv->dev)) {
		pr_err("%s: device_create fail.\n", __func__);
		goto device_create_err;
	}

	drv->cdev = cdev_alloc();
	if (drv->cdev == NULL) {
		pr_err("%s: cdev_alloc fail.\n", __func__);
		goto cdev_alloc_err;
	}
	cdev_init(drv->cdev, &dsps_fops);
	drv->cdev->owner = THIS_MODULE;

	ret = cdev_add(drv->cdev, drv->dev_num, 1);
	if (ret) {
		pr_err("%s: cdev_add fail.\n", __func__);
		goto cdev_add_err;
	}

	ret = dsps_alloc_resources(pdev);
	if (ret) {
		pr_err("%s: failed to allocate dsps resources.\n", __func__);
		goto cdev_add_err;
	}

	ret =
	    smsm_state_cb_register(SMSM_DSPS_STATE, SMSM_RESET,
				   dsps_smsm_state_cb, 0);
	if (ret) {
		pr_err("%s: smsm_state_cb_register fail %d\n", __func__,
		       ret);
		goto smsm_register_err;
	}

	ret = ssr_register_subsystem(&dsps_ssrops);
	if (ret) {
		pr_err("%s: ssr_register_subsystem fail %d\n", __func__,
		       ret);
		goto ssr_register_err;
	}

	return 0;

ssr_register_err:
	smsm_state_cb_deregister(SMSM_DSPS_STATE, SMSM_RESET,
				 dsps_smsm_state_cb,
				 0);
smsm_register_err:
	cdev_del(drv->cdev);
cdev_add_err:
	kfree(drv->cdev);
cdev_alloc_err:
	device_destroy(drv->dev_class, drv->dev_num);
device_create_err:
	unregister_chrdev_region(drv->dev_num, 1);
alloc_chrdev_region_err:
	class_destroy(drv->dev_class);
res_err:
	kfree(drv);
	drv = NULL;
alloc_err:
	return -ENODEV;
}
/**
 * platform driver
 *
 */
static int __devinit dsps_probe(struct platform_device *pdev)
{
    int ret;

    pr_debug("%s.\n", __func__);

    if (pdev->dev.platform_data == NULL) {
        pr_err("%s: platform data is NULL.\n", __func__);
        return -ENODEV;
    }

    drv = kzalloc(sizeof(*drv), GFP_KERNEL);
    if (drv == NULL) {
        pr_err("%s: kzalloc fail.\n", __func__);
        goto alloc_err;
    }
    drv->pdata = pdev->dev.platform_data;

    ret = dsps_alloc_resources(pdev);
    if (ret) {
        pr_err("%s: failed to allocate dsps resources.\n", __func__);
        goto res_err;
    }

    drv->dev_class = class_create(THIS_MODULE, DRV_NAME);
    if (drv->dev_class == NULL) {
        pr_err("%s: class_create fail.\n", __func__);
        goto res_err;
    }

    ret = alloc_chrdev_region(&drv->dev_num, 0, 1, DRV_NAME);
    if (ret) {
        pr_err("%s: alloc_chrdev_region fail.\n", __func__);
        goto alloc_chrdev_region_err;
    }

    drv->dev = device_create(drv->dev_class, NULL,
                             drv->dev_num,
                             drv, DRV_NAME);
    if (IS_ERR(drv->dev)) {
        pr_err("%s: device_create fail.\n", __func__);
        goto device_create_err;
    }

    drv->cdev = cdev_alloc();
    if (drv->cdev == NULL) {
        pr_err("%s: cdev_alloc fail.\n", __func__);
        goto cdev_alloc_err;
    }
    cdev_init(drv->cdev, &dsps_fops);
    drv->cdev->owner = THIS_MODULE;

    ret = cdev_add(drv->cdev, drv->dev_num, 1);
    if (ret) {
        pr_err("%s: cdev_add fail.\n", __func__);
        goto cdev_add_err;
    }

    /*Default disabled*/
    msm_dsps_power(false);

    return 0;

cdev_add_err:
    kfree(drv->cdev);
cdev_alloc_err:
    device_destroy(drv->dev_class, drv->dev_num);
device_create_err:
    unregister_chrdev_region(drv->dev_num, 1);
alloc_chrdev_region_err:
    class_destroy(drv->dev_class);
res_err:
    kfree(drv);
    drv = NULL;
alloc_err:
    return -ENODEV;
}