static int platform_probe(struct platform_device *dev) { struct backlight_properties props; int ret; mutex_init(&dev_priv.mutex); INIT_DELAYED_WORK(&dev_priv.work, brightness_work); ret = lp8550_probe(); if (ret) return ret; ret = lp8550_save(); if (ret) return ret; memset(&props, 0, sizeof(struct backlight_properties)); props.max_brightness = 255; props.type = BACKLIGHT_FIRMWARE; props.power = 0; /* Power is on */ backlight_device = backlight_device_register("mba6x_backlight", NULL, NULL, &backlight_ops, &props); if (IS_ERR(backlight_device)) { pr_err("mba6x_bl: Failed to register backlight device\n"); return PTR_ERR(backlight_device); } backlight_device->props.brightness = INIT_BRIGHTNESS; backlight_update_status(backlight_device); #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) acpi_video_set_dmi_backlight_type(acpi_backlight_vendor); #else acpi_video_dmi_promote_vendor(); #endif acpi_video_unregister(); return 0; }
static int __devinit gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) { struct apple_gmux_data *gmux_data; struct resource *res; struct backlight_properties props; struct backlight_device *bdev; u8 ver_major, ver_minor, ver_release; int ret = -ENXIO; gmux_data = kzalloc(sizeof(*gmux_data), GFP_KERNEL); if (!gmux_data) return -ENOMEM; pnp_set_drvdata(pnp, gmux_data); res = pnp_get_resource(pnp, IORESOURCE_IO, 0); if (!res) { pr_err("Failed to find gmux I/O resource\n"); goto err_free; } gmux_data->iostart = res->start; gmux_data->iolen = res->end - res->start; if (gmux_data->iolen < GMUX_MIN_IO_LEN) { pr_err("gmux I/O region too small (%lu < %u)\n", gmux_data->iolen, GMUX_MIN_IO_LEN); goto err_free; } if (!request_region(gmux_data->iostart, gmux_data->iolen, "Apple gmux")) { pr_err("gmux I/O already in use\n"); goto err_free; } /* * On some machines the gmux is in ACPI even thought the machine * doesn't really have a gmux. Check for invalid version information * to detect this. */ ver_major = gmux_read8(gmux_data, GMUX_PORT_VERSION_MAJOR); ver_minor = gmux_read8(gmux_data, GMUX_PORT_VERSION_MINOR); ver_release = gmux_read8(gmux_data, GMUX_PORT_VERSION_RELEASE); if (ver_major == 0xff && ver_minor == 0xff && ver_release == 0xff) { pr_info("gmux device not present\n"); ret = -ENODEV; goto err_release; } pr_info("Found gmux version %d.%d.%d\n", ver_major, ver_minor, ver_release); memset(&props, 0, sizeof(props)); props.type = BACKLIGHT_PLATFORM; props.max_brightness = gmux_read32(gmux_data, GMUX_PORT_MAX_BRIGHTNESS); /* * Currently it's assumed that the maximum brightness is less than * 2^24 for compatibility with old gmux versions. Cap the max * brightness at this value, but print a warning if the hardware * reports something higher so that it can be fixed. */ if (WARN_ON(props.max_brightness > GMUX_MAX_BRIGHTNESS)) props.max_brightness = GMUX_MAX_BRIGHTNESS; bdev = backlight_device_register("gmux_backlight", &pnp->dev, gmux_data, &gmux_bl_ops, &props); if (IS_ERR(bdev)) { ret = PTR_ERR(bdev); goto err_release; } gmux_data->bdev = bdev; bdev->props.brightness = gmux_get_brightness(bdev); backlight_update_status(bdev); /* * The backlight situation on Macs is complicated. If the gmux is * present it's the best choice, because it always works for * backlight control and supports more levels than other options. * Disable the other backlight choices. */ acpi_video_dmi_promote_vendor(); #ifdef CONFIG_ACPI_VIDEO acpi_video_unregister(); #endif apple_bl_unregister(); return 0; err_release: release_region(gmux_data->iostart, gmux_data->iolen); err_free: kfree(gmux_data); return ret; }