Beispiel #1
0
static int adp5520_bl_probe(struct platform_device *pdev)
{
	struct backlight_properties props;
	struct backlight_device *bl;
	struct adp5520_bl *data;
	int ret = 0;

	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
	if (data == NULL)
		return -ENOMEM;

	data->master = pdev->dev.parent;
	data->pdata = dev_get_platdata(&pdev->dev);

	if (data->pdata  == NULL) {
		dev_err(&pdev->dev, "missing platform data\n");
		return -ENODEV;
	}

	data->id = pdev->id;
	data->current_brightness = 0;

	mutex_init(&data->lock);

	memset(&props, 0, sizeof(struct backlight_properties));
	props.type = BACKLIGHT_RAW;
	props.max_brightness = ADP5020_MAX_BRIGHTNESS;
	bl = devm_backlight_device_register(&pdev->dev, pdev->name,
					data->master, data, &adp5520_bl_ops,
					&props);
	if (IS_ERR(bl)) {
		dev_err(&pdev->dev, "failed to register backlight\n");
		return PTR_ERR(bl);
	}

	bl->props.brightness = ADP5020_MAX_BRIGHTNESS;
	if (data->pdata->en_ambl_sens)
		ret = sysfs_create_group(&bl->dev.kobj,
			&adp5520_bl_attr_group);

	if (ret) {
		dev_err(&pdev->dev, "failed to register sysfs\n");
		return ret;
	}

	platform_set_drvdata(pdev, bl);
	ret = adp5520_bl_setup(bl);
	if (ret) {
		dev_err(&pdev->dev, "failed to setup\n");
		if (data->pdata->en_ambl_sens)
			sysfs_remove_group(&bl->dev.kobj,
					&adp5520_bl_attr_group);
		return ret;
	}

	backlight_update_status(bl);

	return 0;
}
Beispiel #2
0
static int __devinit adp5520_bl_probe(struct platform_device *pdev)
{
	struct backlight_device *bl;
	struct adp5520_bl *data;
	int ret = 0;

	data = kzalloc(sizeof(*data), GFP_KERNEL);
	if (data == NULL)
		return -ENOMEM;

	data->master = pdev->dev.parent;
	data->pdata = pdev->dev.platform_data;

	if (data->pdata  == NULL) {
		dev_err(&pdev->dev, "missing platform data\n");
		kfree(data);
		return -ENODEV;
	}

	data->id = pdev->id;
	data->current_brightness = 0;

	mutex_init(&data->lock);

	bl = backlight_device_register(pdev->name, data->master,
			data, &adp5520_bl_ops);
	if (IS_ERR(bl)) {
		dev_err(&pdev->dev, "failed to register backlight\n");
		kfree(data);
		return PTR_ERR(bl);
	}

	bl->props.max_brightness =
		bl->props.brightness = ADP5020_MAX_BRIGHTNESS;

	if (data->pdata->en_ambl_sens)
		ret = sysfs_create_group(&bl->dev.kobj,
			&adp5520_bl_attr_group);

	if (ret) {
		dev_err(&pdev->dev, "failed to register sysfs\n");
		backlight_device_unregister(bl);
		kfree(data);
	}

	platform_set_drvdata(pdev, bl);
	ret |= adp5520_bl_setup(bl);
	backlight_update_status(bl);

	return ret;
}