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>
15 #include <linux/gfp.h>
17 #include <linux/module.h>
18 #include <linux/platform_device.h>
20 /* register definitions */
21 #define ADX_BACKLIGHT_CONTROL 0x00
22 #define ADX_BACKLIGHT_CONTROL_ENABLE (1 << 0)
23 #define ADX_BACKLIGHT_BRIGHTNESS 0x08
24 #define ADX_BACKLIGHT_STATUS 0x10
25 #define ADX_BACKLIGHT_ERROR 0x18
31 static int adx_backlight_update_status(struct backlight_device
*bldev
)
33 struct adxbl
*bl
= bl_get_data(bldev
);
36 value
= bldev
->props
.brightness
;
37 writel(value
, bl
->base
+ ADX_BACKLIGHT_BRIGHTNESS
);
39 value
= readl(bl
->base
+ ADX_BACKLIGHT_CONTROL
);
41 if (bldev
->props
.state
& BL_CORE_FBBLANK
)
42 value
&= ~ADX_BACKLIGHT_CONTROL_ENABLE
;
44 value
|= ADX_BACKLIGHT_CONTROL_ENABLE
;
46 writel(value
, bl
->base
+ ADX_BACKLIGHT_CONTROL
);
51 static int adx_backlight_get_brightness(struct backlight_device
*bldev
)
53 struct adxbl
*bl
= bl_get_data(bldev
);
56 brightness
= readl(bl
->base
+ ADX_BACKLIGHT_BRIGHTNESS
);
57 return brightness
& 0xff;
60 static int adx_backlight_check_fb(struct backlight_device
*bldev
, struct fb_info
*fb
)
65 static const struct backlight_ops adx_backlight_ops
= {
67 .update_status
= adx_backlight_update_status
,
68 .get_brightness
= adx_backlight_get_brightness
,
69 .check_fb
= adx_backlight_check_fb
,
72 static int __devinit
adx_backlight_probe(struct platform_device
*pdev
)
74 struct backlight_properties props
;
75 struct backlight_device
*bldev
;
80 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
86 res
= devm_request_mem_region(&pdev
->dev
, res
->start
,
87 resource_size(res
), res
->name
);
93 bl
= devm_kzalloc(&pdev
->dev
, sizeof(*bl
), GFP_KERNEL
);
99 bl
->base
= devm_ioremap_nocache(&pdev
->dev
, res
->start
,
106 memset(&props
, 0, sizeof(struct backlight_properties
));
107 props
.type
= BACKLIGHT_RAW
;
108 props
.max_brightness
= 0xff;
109 bldev
= backlight_device_register(dev_name(&pdev
->dev
), &pdev
->dev
,
110 bl
, &adx_backlight_ops
, &props
);
112 ret
= PTR_ERR(bldev
);
116 bldev
->props
.brightness
= 0xff;
117 bldev
->props
.power
= FB_BLANK_UNBLANK
;
119 platform_set_drvdata(pdev
, bldev
);
125 static int __devexit
adx_backlight_remove(struct platform_device
*pdev
)
127 struct backlight_device
*bldev
;
130 bldev
= platform_get_drvdata(pdev
);
131 bldev
->props
.power
= FB_BLANK_UNBLANK
;
132 bldev
->props
.brightness
= 0xff;
133 backlight_update_status(bldev
);
134 backlight_device_unregister(bldev
);
135 platform_set_drvdata(pdev
, NULL
);
141 static int adx_backlight_suspend(struct platform_device
*pdev
,
147 static int adx_backlight_resume(struct platform_device
*pdev
)
152 #define adx_backlight_suspend NULL
153 #define adx_backlight_resume NULL
156 static struct platform_driver adx_backlight_driver
= {
157 .probe
= adx_backlight_probe
,
158 .remove
= __devexit_p(adx_backlight_remove
),
159 .suspend
= adx_backlight_suspend
,
160 .resume
= adx_backlight_resume
,
162 .name
= "adx-backlight",
163 .owner
= THIS_MODULE
,
167 static int __init
adx_backlight_init(void)
169 return platform_driver_register(&adx_backlight_driver
);
172 static void __exit
adx_backlight_exit(void)
174 platform_driver_unregister(&adx_backlight_driver
);
177 module_init(adx_backlight_init
);
178 module_exit(adx_backlight_exit
);
180 MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>");
181 MODULE_DESCRIPTION("Avionic Design Xanthos Backlight Driver");
182 MODULE_LICENSE("GPL v2");