rapidio: fix use of non-compatible registers
[linux-2.6-block.git] / drivers / video / backlight / ep93xx_bl.c
CommitLineData
08b3924b
HS
1/*
2 * Driver for the Cirrus EP93xx lcd backlight
3 *
4 * Copyright (c) 2010 H Hartley Sweeten <hsweeten@visionengravers.com>
5 *
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.
9 *
10 * This driver controls the pulse width modulated brightness control output,
11 * BRIGHT, on the Cirrus EP9307, EP9312, and EP9315 processors.
12 */
13
14
15#include <linux/platform_device.h>
16#include <linux/io.h>
17#include <linux/fb.h>
18#include <linux/backlight.h>
19
20#include <mach/hardware.h>
21
22#define EP93XX_RASTER_REG(x) (EP93XX_RASTER_BASE + (x))
23#define EP93XX_RASTER_BRIGHTNESS EP93XX_RASTER_REG(0x20)
24
25#define EP93XX_MAX_COUNT 255
26#define EP93XX_MAX_BRIGHT 255
27#define EP93XX_DEF_BRIGHT 128
28
29struct ep93xxbl {
30 void __iomem *mmio;
31 int brightness;
32};
33
34static int ep93xxbl_set(struct backlight_device *bl, int brightness)
35{
36 struct ep93xxbl *ep93xxbl = bl_get_data(bl);
37
38 __raw_writel((brightness << 8) | EP93XX_MAX_COUNT, ep93xxbl->mmio);
39
40 ep93xxbl->brightness = brightness;
41
42 return 0;
43}
44
45static int ep93xxbl_update_status(struct backlight_device *bl)
46{
47 int brightness = bl->props.brightness;
48
49 if (bl->props.power != FB_BLANK_UNBLANK ||
50 bl->props.fb_blank != FB_BLANK_UNBLANK)
51 brightness = 0;
52
53 return ep93xxbl_set(bl, brightness);
54}
55
56static int ep93xxbl_get_brightness(struct backlight_device *bl)
57{
58 struct ep93xxbl *ep93xxbl = bl_get_data(bl);
59
60 return ep93xxbl->brightness;
61}
62
63static const struct backlight_ops ep93xxbl_ops = {
64 .update_status = ep93xxbl_update_status,
65 .get_brightness = ep93xxbl_get_brightness,
66};
67
68static int __init ep93xxbl_probe(struct platform_device *dev)
69{
70 struct ep93xxbl *ep93xxbl;
71 struct backlight_device *bl;
72 struct backlight_properties props;
73
74 ep93xxbl = devm_kzalloc(&dev->dev, sizeof(*ep93xxbl), GFP_KERNEL);
75 if (!ep93xxbl)
76 return -ENOMEM;
77
78 /*
79 * This register is located in the range already ioremap'ed by
80 * the framebuffer driver. A MFD driver seems a bit of overkill
81 * to handle this so use the static I/O mapping; this address
82 * is already virtual.
83 *
84 * NOTE: No locking is required; the framebuffer does not touch
85 * this register.
86 */
87 ep93xxbl->mmio = EP93XX_RASTER_BRIGHTNESS;
88
89 memset(&props, 0, sizeof(struct backlight_properties));
bb7ca747 90 props.type = BACKLIGHT_RAW;
08b3924b
HS
91 props.max_brightness = EP93XX_MAX_BRIGHT;
92 bl = backlight_device_register(dev->name, &dev->dev, ep93xxbl,
93 &ep93xxbl_ops, &props);
94 if (IS_ERR(bl))
95 return PTR_ERR(bl);
96
97 bl->props.brightness = EP93XX_DEF_BRIGHT;
98
99 platform_set_drvdata(dev, bl);
100
101 ep93xxbl_update_status(bl);
102
103 return 0;
104}
105
106static int ep93xxbl_remove(struct platform_device *dev)
107{
108 struct backlight_device *bl = platform_get_drvdata(dev);
109
110 backlight_device_unregister(bl);
111 platform_set_drvdata(dev, NULL);
112 return 0;
113}
114
115#ifdef CONFIG_PM
116static int ep93xxbl_suspend(struct platform_device *dev, pm_message_t state)
117{
118 struct backlight_device *bl = platform_get_drvdata(dev);
119
120 return ep93xxbl_set(bl, 0);
121}
122
123static int ep93xxbl_resume(struct platform_device *dev)
124{
125 struct backlight_device *bl = platform_get_drvdata(dev);
126
127 backlight_update_status(bl);
128 return 0;
129}
130#else
131#define ep93xxbl_suspend NULL
132#define ep93xxbl_resume NULL
133#endif
134
135static struct platform_driver ep93xxbl_driver = {
136 .driver = {
137 .name = "ep93xx-bl",
138 .owner = THIS_MODULE,
139 },
140 .probe = ep93xxbl_probe,
141 .remove = __devexit_p(ep93xxbl_remove),
142 .suspend = ep93xxbl_suspend,
143 .resume = ep93xxbl_resume,
144};
145
146static int __init ep93xxbl_init(void)
147{
148 return platform_driver_register(&ep93xxbl_driver);
149}
150module_init(ep93xxbl_init);
151
152static void __exit ep93xxbl_exit(void)
153{
154 platform_driver_unregister(&ep93xxbl_driver);
155}
156module_exit(ep93xxbl_exit);
157
158MODULE_DESCRIPTION("EP93xx Backlight Driver");
159MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
160MODULE_LICENSE("GPL");
161MODULE_ALIAS("platform:ep93xx-bl");