blob: 32b91677cd57ee3f3750a10918b2395d9b77a3f6 [file] [log] [blame]
H Hartley Sweeten08b39242010-05-05 12:13:23 -05001/*
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
Axel Lin15b1a8f2011-08-25 15:59:14 -070014#include <linux/module.h>
H Hartley Sweeten08b39242010-05-05 12:13:23 -050015#include <linux/platform_device.h>
Paul Gortmaker355b2002011-07-03 16:17:28 -040016#include <linux/module.h>
H Hartley Sweeten08b39242010-05-05 12:13:23 -050017#include <linux/io.h>
18#include <linux/fb.h>
19#include <linux/backlight.h>
20
21#include <mach/hardware.h>
22
23#define EP93XX_RASTER_REG(x) (EP93XX_RASTER_BASE + (x))
24#define EP93XX_RASTER_BRIGHTNESS EP93XX_RASTER_REG(0x20)
25
26#define EP93XX_MAX_COUNT 255
27#define EP93XX_MAX_BRIGHT 255
28#define EP93XX_DEF_BRIGHT 128
29
30struct ep93xxbl {
31 void __iomem *mmio;
32 int brightness;
33};
34
35static int ep93xxbl_set(struct backlight_device *bl, int brightness)
36{
37 struct ep93xxbl *ep93xxbl = bl_get_data(bl);
38
39 __raw_writel((brightness << 8) | EP93XX_MAX_COUNT, ep93xxbl->mmio);
40
41 ep93xxbl->brightness = brightness;
42
43 return 0;
44}
45
46static int ep93xxbl_update_status(struct backlight_device *bl)
47{
48 int brightness = bl->props.brightness;
49
50 if (bl->props.power != FB_BLANK_UNBLANK ||
51 bl->props.fb_blank != FB_BLANK_UNBLANK)
52 brightness = 0;
53
54 return ep93xxbl_set(bl, brightness);
55}
56
57static int ep93xxbl_get_brightness(struct backlight_device *bl)
58{
59 struct ep93xxbl *ep93xxbl = bl_get_data(bl);
60
61 return ep93xxbl->brightness;
62}
63
64static const struct backlight_ops ep93xxbl_ops = {
65 .update_status = ep93xxbl_update_status,
66 .get_brightness = ep93xxbl_get_brightness,
67};
68
69static int __init ep93xxbl_probe(struct platform_device *dev)
70{
71 struct ep93xxbl *ep93xxbl;
72 struct backlight_device *bl;
73 struct backlight_properties props;
74
75 ep93xxbl = devm_kzalloc(&dev->dev, sizeof(*ep93xxbl), GFP_KERNEL);
76 if (!ep93xxbl)
77 return -ENOMEM;
78
79 /*
80 * This register is located in the range already ioremap'ed by
81 * the framebuffer driver. A MFD driver seems a bit of overkill
82 * to handle this so use the static I/O mapping; this address
83 * is already virtual.
84 *
85 * NOTE: No locking is required; the framebuffer does not touch
86 * this register.
87 */
88 ep93xxbl->mmio = EP93XX_RASTER_BRIGHTNESS;
89
90 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -070091 props.type = BACKLIGHT_RAW;
H Hartley Sweeten08b39242010-05-05 12:13:23 -050092 props.max_brightness = EP93XX_MAX_BRIGHT;
93 bl = backlight_device_register(dev->name, &dev->dev, ep93xxbl,
94 &ep93xxbl_ops, &props);
95 if (IS_ERR(bl))
96 return PTR_ERR(bl);
97
98 bl->props.brightness = EP93XX_DEF_BRIGHT;
99
100 platform_set_drvdata(dev, bl);
101
102 ep93xxbl_update_status(bl);
103
104 return 0;
105}
106
107static int ep93xxbl_remove(struct platform_device *dev)
108{
109 struct backlight_device *bl = platform_get_drvdata(dev);
110
111 backlight_device_unregister(bl);
112 platform_set_drvdata(dev, NULL);
113 return 0;
114}
115
116#ifdef CONFIG_PM
117static int ep93xxbl_suspend(struct platform_device *dev, pm_message_t state)
118{
119 struct backlight_device *bl = platform_get_drvdata(dev);
120
121 return ep93xxbl_set(bl, 0);
122}
123
124static int ep93xxbl_resume(struct platform_device *dev)
125{
126 struct backlight_device *bl = platform_get_drvdata(dev);
127
128 backlight_update_status(bl);
129 return 0;
130}
131#else
132#define ep93xxbl_suspend NULL
133#define ep93xxbl_resume NULL
134#endif
135
136static struct platform_driver ep93xxbl_driver = {
137 .driver = {
138 .name = "ep93xx-bl",
139 .owner = THIS_MODULE,
140 },
141 .probe = ep93xxbl_probe,
142 .remove = __devexit_p(ep93xxbl_remove),
143 .suspend = ep93xxbl_suspend,
144 .resume = ep93xxbl_resume,
145};
146
Axel Lin81178e02012-01-10 15:09:11 -0800147module_platform_driver(ep93xxbl_driver);
H Hartley Sweeten08b39242010-05-05 12:13:23 -0500148
149MODULE_DESCRIPTION("EP93xx Backlight Driver");
150MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
151MODULE_LICENSE("GPL");
152MODULE_ALIAS("platform:ep93xx-bl");