2 * Driver for the Cirrus EP93xx lcd backlight
4 * Copyright (c) 2010 H Hartley Sweeten <hsweeten@visionengravers.com>
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 * This driver controls the pulse width modulated brightness control output,
11 * BRIGHT, on the Cirrus EP9307, EP9312, and EP9315 processors.
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
18 #include <linux/backlight.h>
20 #define EP93XX_MAX_COUNT 255
21 #define EP93XX_MAX_BRIGHT 255
22 #define EP93XX_DEF_BRIGHT 128
29 static int ep93xxbl_set(struct backlight_device
*bl
, int brightness
)
31 struct ep93xxbl
*ep93xxbl
= bl_get_data(bl
);
33 writel((brightness
<< 8) | EP93XX_MAX_COUNT
, ep93xxbl
->mmio
);
35 ep93xxbl
->brightness
= brightness
;
40 static int ep93xxbl_update_status(struct backlight_device
*bl
)
42 int brightness
= bl
->props
.brightness
;
44 if (bl
->props
.power
!= FB_BLANK_UNBLANK
||
45 bl
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
48 return ep93xxbl_set(bl
, brightness
);
51 static int ep93xxbl_get_brightness(struct backlight_device
*bl
)
53 struct ep93xxbl
*ep93xxbl
= bl_get_data(bl
);
55 return ep93xxbl
->brightness
;
58 static const struct backlight_ops ep93xxbl_ops
= {
59 .update_status
= ep93xxbl_update_status
,
60 .get_brightness
= ep93xxbl_get_brightness
,
63 static int ep93xxbl_probe(struct platform_device
*dev
)
65 struct ep93xxbl
*ep93xxbl
;
66 struct backlight_device
*bl
;
67 struct backlight_properties props
;
70 ep93xxbl
= devm_kzalloc(&dev
->dev
, sizeof(*ep93xxbl
), GFP_KERNEL
);
74 res
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
79 * FIXME - We don't do a request_mem_region here because we are
80 * sharing the register space with the framebuffer driver (see
81 * drivers/video/ep93xx-fb.c) and doing so will cause the second
82 * loaded driver to return -EBUSY.
84 * NOTE: No locking is required; the framebuffer does not touch
87 ep93xxbl
->mmio
= devm_ioremap(&dev
->dev
, res
->start
,
92 memset(&props
, 0, sizeof(struct backlight_properties
));
93 props
.type
= BACKLIGHT_RAW
;
94 props
.max_brightness
= EP93XX_MAX_BRIGHT
;
95 bl
= devm_backlight_device_register(&dev
->dev
, dev
->name
, &dev
->dev
,
96 ep93xxbl
, &ep93xxbl_ops
, &props
);
100 bl
->props
.brightness
= EP93XX_DEF_BRIGHT
;
102 platform_set_drvdata(dev
, bl
);
104 ep93xxbl_update_status(bl
);
109 #ifdef CONFIG_PM_SLEEP
110 static int ep93xxbl_suspend(struct device
*dev
)
112 struct backlight_device
*bl
= dev_get_drvdata(dev
);
114 return ep93xxbl_set(bl
, 0);
117 static int ep93xxbl_resume(struct device
*dev
)
119 struct backlight_device
*bl
= dev_get_drvdata(dev
);
121 backlight_update_status(bl
);
126 static SIMPLE_DEV_PM_OPS(ep93xxbl_pm_ops
, ep93xxbl_suspend
, ep93xxbl_resume
);
128 static struct platform_driver ep93xxbl_driver
= {
131 .owner
= THIS_MODULE
,
132 .pm
= &ep93xxbl_pm_ops
,
134 .probe
= ep93xxbl_probe
,
137 module_platform_driver(ep93xxbl_driver
);
139 MODULE_DESCRIPTION("EP93xx Backlight Driver");
140 MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
141 MODULE_LICENSE("GPL");
142 MODULE_ALIAS("platform:ep93xx-bl");