Beispiel #1
0
static int tps65217_bl_probe(struct platform_device *pdev)
{
	int rc;
	struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
	struct tps65217 *tps = i2c_get_clientdata(i2c_client);
	struct tps65217_bl *tps65217_bl;
	struct tps65217_bl_pdata *pdata;
	struct backlight_properties bl_props;

	tps65217_bl = devm_kzalloc(&pdev->dev, sizeof(*tps65217_bl),
				GFP_KERNEL);
	if (tps65217_bl == NULL) {
		dev_err(&pdev->dev, "allocation of struct tps65217_bl failed\n");
		return -ENOMEM;
	}

	tps65217_bl->tps = tps;
	tps65217_bl->dev = &pdev->dev;
	tps65217_bl->on = 0;

	if (tps65217_bl->dev->of_node)
		pdata = tps65217_bl_parse_dt(tps65217_bl);
	else
		pdata = pdev->dev.platform_data;

	if (IS_ERR(pdata))
		return PTR_ERR(pdata);

	rc = tps65217_bl_hw_init(tps65217_bl, pdata);
	if (rc)
		goto err_bl_hw_init;

	memset(&bl_props, 0, sizeof(struct backlight_properties));
	bl_props.type = BACKLIGHT_RAW;
	bl_props.max_brightness = 100;

	tps65217_bl->bl = backlight_device_register(pdev->name,
						tps65217_bl->dev, tps65217_bl,
						&tps65217_bl_ops, &bl_props);
	if (IS_ERR(tps65217_bl->bl)) {
		rc = PTR_ERR(tps65217_bl->bl);
		dev_err(tps65217_bl->dev,
			"registration of backlight device failed: %d\n", rc);
		goto err_reg_bl;
	}

	// Set the default brightness to 90%
	tps65217_bl->bl->props.brightness = 90;

	return 0;

err_reg_bl:
err_bl_hw_init:
	return rc;
}
Beispiel #2
0
static int tps65217_bl_probe(struct platform_device *pdev)
{
	int rc;
	struct tps65217 *tps = dev_get_drvdata(pdev->dev.parent);
	struct tps65217_bl *tps65217_bl;
	struct tps65217_bl_pdata *pdata;
	struct backlight_properties bl_props;

	if (tps->dev->of_node) {
		pdata = tps65217_bl_parse_dt(pdev);
		if (IS_ERR(pdata))
			return PTR_ERR(pdata);
	} else {
		pdata = dev_get_platdata(&pdev->dev);
		if (!pdata) {
			dev_err(&pdev->dev, "no platform data provided\n");
			return -EINVAL;
		}
	}

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

	tps65217_bl->tps = tps;
	tps65217_bl->dev = &pdev->dev;
	tps65217_bl->is_enabled = false;

	rc = tps65217_bl_hw_init(tps65217_bl, pdata);
	if (rc)
		return rc;

	memset(&bl_props, 0, sizeof(struct backlight_properties));
	bl_props.type = BACKLIGHT_RAW;
	bl_props.max_brightness = 100;

	tps65217_bl->bl = devm_backlight_device_register(&pdev->dev, pdev->name,
						tps65217_bl->dev, tps65217_bl,
						&tps65217_bl_ops, &bl_props);
	if (IS_ERR(tps65217_bl->bl)) {
		dev_err(tps65217_bl->dev,
			"registration of backlight device failed: %d\n", rc);
		return PTR_ERR(tps65217_bl->bl);
	}

	tps65217_bl->bl->props.brightness = pdata->dft_brightness;
	backlight_update_status(tps65217_bl->bl);
	platform_set_drvdata(pdev, tps65217_bl);

	return 0;
}