backlight: Allow properties to be passed at registration
[linux-2.6/x86.git] / drivers / video / backlight / adx_bl.c
blobb0624b983889273c72219d4b94ade29b7c0ce603
1 /*
2 * linux/drivers/video/backlight/adx.c
4 * Copyright (C) 2009 Avionic Design GmbH
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Written by Thierry Reding <thierry.reding@avionic-design.de>
13 #include <linux/backlight.h>
14 #include <linux/fb.h>
15 #include <linux/io.h>
16 #include <linux/module.h>
17 #include <linux/platform_device.h>
19 /* register definitions */
20 #define ADX_BACKLIGHT_CONTROL 0x00
21 #define ADX_BACKLIGHT_CONTROL_ENABLE (1 << 0)
22 #define ADX_BACKLIGHT_BRIGHTNESS 0x08
23 #define ADX_BACKLIGHT_STATUS 0x10
24 #define ADX_BACKLIGHT_ERROR 0x18
26 struct adxbl {
27 void __iomem *base;
30 static int adx_backlight_update_status(struct backlight_device *bldev)
32 struct adxbl *bl = bl_get_data(bldev);
33 u32 value;
35 value = bldev->props.brightness;
36 writel(value, bl->base + ADX_BACKLIGHT_BRIGHTNESS);
38 value = readl(bl->base + ADX_BACKLIGHT_CONTROL);
40 if (bldev->props.state & BL_CORE_FBBLANK)
41 value &= ~ADX_BACKLIGHT_CONTROL_ENABLE;
42 else
43 value |= ADX_BACKLIGHT_CONTROL_ENABLE;
45 writel(value, bl->base + ADX_BACKLIGHT_CONTROL);
47 return 0;
50 static int adx_backlight_get_brightness(struct backlight_device *bldev)
52 struct adxbl *bl = bl_get_data(bldev);
53 u32 brightness;
55 brightness = readl(bl->base + ADX_BACKLIGHT_BRIGHTNESS);
56 return brightness & 0xff;
59 static int adx_backlight_check_fb(struct backlight_device *bldev, struct fb_info *fb)
61 return 1;
64 static const struct backlight_ops adx_backlight_ops = {
65 .options = 0,
66 .update_status = adx_backlight_update_status,
67 .get_brightness = adx_backlight_get_brightness,
68 .check_fb = adx_backlight_check_fb,
71 static int __devinit adx_backlight_probe(struct platform_device *pdev)
73 struct backlight_properties props;
74 struct backlight_device *bldev;
75 struct resource *res;
76 struct adxbl *bl;
77 int ret = 0;
79 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
80 if (!res) {
81 ret = -ENXIO;
82 goto out;
85 res = devm_request_mem_region(&pdev->dev, res->start,
86 resource_size(res), res->name);
87 if (!res) {
88 ret = -ENXIO;
89 goto out;
92 bl = devm_kzalloc(&pdev->dev, sizeof(*bl), GFP_KERNEL);
93 if (!bl) {
94 ret = -ENOMEM;
95 goto out;
98 bl->base = devm_ioremap_nocache(&pdev->dev, res->start,
99 resource_size(res));
100 if (!bl->base) {
101 ret = -ENXIO;
102 goto out;
105 memset(&props, 0, sizeof(struct backlight_properties));
106 props.max_brightness = 0xff;
107 bldev = backlight_device_register(dev_name(&pdev->dev), &pdev->dev,
108 bl, &adx_backlight_ops, &props);
109 if (!bldev) {
110 ret = -ENOMEM;
111 goto out;
114 bldev->props.brightness = 0xff;
115 bldev->props.power = FB_BLANK_UNBLANK;
117 platform_set_drvdata(pdev, bldev);
119 out:
120 return ret;
123 static int __devexit adx_backlight_remove(struct platform_device *pdev)
125 struct backlight_device *bldev;
126 int ret = 0;
128 bldev = platform_get_drvdata(pdev);
129 bldev->props.power = FB_BLANK_UNBLANK;
130 bldev->props.brightness = 0xff;
131 backlight_update_status(bldev);
132 backlight_device_unregister(bldev);
133 platform_set_drvdata(pdev, NULL);
135 return ret;
138 #ifdef CONFIG_PM
139 static int adx_backlight_suspend(struct platform_device *pdev,
140 pm_message_t state)
142 return 0;
145 static int adx_backlight_resume(struct platform_device *pdev)
147 return 0;
149 #else
150 #define adx_backlight_suspend NULL
151 #define adx_backlight_resume NULL
152 #endif
154 static struct platform_driver adx_backlight_driver = {
155 .probe = adx_backlight_probe,
156 .remove = __devexit_p(adx_backlight_remove),
157 .suspend = adx_backlight_suspend,
158 .resume = adx_backlight_resume,
159 .driver = {
160 .name = "adx-backlight",
161 .owner = THIS_MODULE,
165 static int __init adx_backlight_init(void)
167 return platform_driver_register(&adx_backlight_driver);
170 static void __exit adx_backlight_exit(void)
172 platform_driver_unregister(&adx_backlight_driver);
175 module_init(adx_backlight_init);
176 module_exit(adx_backlight_exit);
178 MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>");
179 MODULE_DESCRIPTION("Avionic Design Xanthos Backlight Driver");
180 MODULE_LICENSE("GPL v2");