/* * gpio_backlight.c - Simple GPIO-controlled backlight * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include #include #include #include #include #include #include #include #include #include #include #include struct gpio_backlight { struct device *dev; struct device *fbdev; int gpio; int active; int def_value; }; static int gpio_backlight_update_status(struct backlight_device *bl) { struct gpio_backlight *gbl = bl_get_data(bl); int brightness = bl->props.brightness; if (bl->props.power != FB_BLANK_UNBLANK || bl->props.fb_blank != FB_BLANK_UNBLANK || bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK)) brightness = 0; gpio_set_value_cansleep(gbl->gpio, brightness ? gbl->active : !gbl->active); return 0; } static int gpio_backlight_check_fb(struct backlight_device *bl, struct fb_info *info) { struct gpio_backlight *gbl = bl_get_data(bl); return gbl->fbdev == NULL || gbl->fbdev == info->dev; } static const struct backlight_ops gpio_backlight_ops = { .options = BL_CORE_SUSPENDRESUME, .update_status = gpio_backlight_update_status, .check_fb = gpio_backlight_check_fb, }; static int gpio_backlight_probe_dt(struct platform_device *pdev, struct gpio_backlight *gbl) { struct device_node *np = pdev->dev.of_node; enum of_gpio_flags gpio_flags; gbl->gpio = of_get_gpio_flags(np, 0, &gpio_flags); if (!gpio_is_valid(gbl->gpio)) { if (gbl->gpio != -EPROBE_DEFER) { dev_err(&pdev->dev, "Error: The gpios parameter is missing or invalid.\n"); } return gbl->gpio; } gbl->active = (gpio_flags & OF_GPIO_ACTIVE_LOW) ? 0 : 1; gbl->def_value = of_property_read_bool(np, "default-on"); return 0; } static int gpio_backlight_probe(struct platform_device *pdev) { struct gpio_backlight_platform_data *pdata = dev_get_platdata(&pdev->dev); struct backlight_properties props; struct backlight_device *bl; struct gpio_backlight *gbl; struct device_node *np = pdev->dev.of_node; unsigned long flags = GPIOF_DIR_OUT; int ret; if (!pdata && !np) { dev_err(&pdev->dev, "failed to find platform data or device tree node.\n"); return -ENODEV; } gbl = devm_kzalloc(&pdev->dev, sizeof(*gbl), GFP_KERNEL); if (gbl == NULL) return -ENOMEM; gbl->dev = &pdev->dev; if (np) { ret = gpio_backlight_probe_dt(pdev, gbl); if (ret) return ret; } else { gbl->fbdev = pdata->fbdev; gbl->gpio = pdata->gpio; gbl->active = pdata->active_low ? 0 : 1; gbl->def_value = pdata->def_value; } if (gbl->active) flags |= gbl->def_value ? GPIOF_INIT_HIGH : GPIOF_INIT_LOW; else flags |= gbl->def_value ? GPIOF_INIT_LOW : GPIOF_INIT_HIGH; ret = devm_gpio_request_one(gbl->dev, gbl->gpio, flags, pdata ? pdata->name : "backlight"); if (ret < 0) { dev_err(&pdev->dev, "unable to request GPIO\n"); return ret; } memset(&props, 0, sizeof(props)); props.type = BACKLIGHT_RAW; props.max_brightness = 1; bl = devm_backlight_device_register(&pdev->dev, dev_name(&pdev->dev), &pdev->dev, gbl, &gpio_backlight_ops, &props); if (IS_ERR(bl)) { dev_err(&pdev->dev, "failed to register backlight\n"); return PTR_ERR(bl); } bl->props.brightness = gbl->def_value; backlight_update_status(bl); platform_set_drvdata(pdev, bl); return 0; } #ifdef CONFIG_OF static struct of_device_id gpio_backlight_of_match[] = { { .compatible = "gpio-backlight" }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, gpio_backlight_of_match); #endif static struct platform_driver gpio_backlight_driver = { .driver = { .name = "gpio-backlight", .of_match_table = of_match_ptr(gpio_backlight_of_match), }, .probe = gpio_backlight_probe, }; module_platform_driver(gpio_backlight_driver); MODULE_AUTHOR("Laurent Pinchart "); MODULE_DESCRIPTION("GPIO-based Backlight Driver"); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:gpio-backlight"); iff
authorThomas Gleixner <tglx@linutronix.de>2017-01-31 19:03:21 +0100
committerThomas Gleixner <tglx@linutronix.de>2017-01-31 20:22:18 +0100
commitaaaec6fc755447a1d056765b11b24d8ff2b81366 (patch)
treea7f4167960ee1df86739905b6ccdeb95465bfe5f /net/atm/protocols.h
parent08d85f3ea99f1eeafc4e8507936190e86a16ee8c (diff)
x86/irq: Make irq activate operations symmetric
The recent commit which prevents double activation of interrupts unearthed interesting code in x86. The code (ab)uses irq_domain_activate_irq() to reconfigure an already activated interrupt. That trips over the prevention code now. Fix it by deactivating the interrupt before activating the new configuration. Fixes: 08d85f3ea99f1 "irqdomain: Avoid activating interrupts more than once" Reported-and-tested-by: Mike Galbraith <efault@gmx.de> Reported-and-tested-by: Borislav Petkov <bp@alien8.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: Marc Zyngier <marc.zyngier@arm.com> Cc: stable@vger.kernel.org Link: http://lkml.kernel.org/r/alpine.DEB.2.20.1701311901580.3457@nanos
Diffstat (limited to 'net/atm/protocols.h')