Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
08b3924b HS |
2 | /* |
3 | * Driver for the Cirrus EP93xx lcd backlight | |
4 | * | |
5 | * Copyright (c) 2010 H Hartley Sweeten <hsweeten@visionengravers.com> | |
6 | * | |
08b3924b HS |
7 | * This driver controls the pulse width modulated brightness control output, |
8 | * BRIGHT, on the Cirrus EP9307, EP9312, and EP9315 processors. | |
9 | */ | |
10 | ||
15b1a8f2 | 11 | #include <linux/module.h> |
08b3924b HS |
12 | #include <linux/platform_device.h> |
13 | #include <linux/io.h> | |
14 | #include <linux/fb.h> | |
15 | #include <linux/backlight.h> | |
16 | ||
08b3924b HS |
17 | #define EP93XX_MAX_COUNT 255 |
18 | #define EP93XX_MAX_BRIGHT 255 | |
19 | #define EP93XX_DEF_BRIGHT 128 | |
20 | ||
21 | struct ep93xxbl { | |
22 | void __iomem *mmio; | |
23 | int brightness; | |
24 | }; | |
25 | ||
26 | static int ep93xxbl_set(struct backlight_device *bl, int brightness) | |
27 | { | |
28 | struct ep93xxbl *ep93xxbl = bl_get_data(bl); | |
29 | ||
0fd19580 | 30 | writel((brightness << 8) | EP93XX_MAX_COUNT, ep93xxbl->mmio); |
08b3924b HS |
31 | |
32 | ep93xxbl->brightness = brightness; | |
33 | ||
34 | return 0; | |
35 | } | |
36 | ||
37 | static int ep93xxbl_update_status(struct backlight_device *bl) | |
38 | { | |
51d53e5b | 39 | return ep93xxbl_set(bl, backlight_get_brightness(bl)); |
08b3924b HS |
40 | } |
41 | ||
42 | static int ep93xxbl_get_brightness(struct backlight_device *bl) | |
43 | { | |
44 | struct ep93xxbl *ep93xxbl = bl_get_data(bl); | |
45 | ||
46 | return ep93xxbl->brightness; | |
47 | } | |
48 | ||
49 | static const struct backlight_ops ep93xxbl_ops = { | |
50 | .update_status = ep93xxbl_update_status, | |
51 | .get_brightness = ep93xxbl_get_brightness, | |
52 | }; | |
53 | ||
cb1fbb88 | 54 | static int ep93xxbl_probe(struct platform_device *dev) |
08b3924b HS |
55 | { |
56 | struct ep93xxbl *ep93xxbl; | |
57 | struct backlight_device *bl; | |
58 | struct backlight_properties props; | |
0fd19580 | 59 | struct resource *res; |
08b3924b HS |
60 | |
61 | ep93xxbl = devm_kzalloc(&dev->dev, sizeof(*ep93xxbl), GFP_KERNEL); | |
62 | if (!ep93xxbl) | |
63 | return -ENOMEM; | |
64 | ||
0fd19580 RM |
65 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); |
66 | if (!res) | |
67 | return -ENXIO; | |
68 | ||
08b3924b | 69 | /* |
0fd19580 RM |
70 | * FIXME - We don't do a request_mem_region here because we are |
71 | * sharing the register space with the framebuffer driver (see | |
72 | * drivers/video/ep93xx-fb.c) and doing so will cause the second | |
73 | * loaded driver to return -EBUSY. | |
08b3924b HS |
74 | * |
75 | * NOTE: No locking is required; the framebuffer does not touch | |
76 | * this register. | |
77 | */ | |
0fd19580 RM |
78 | ep93xxbl->mmio = devm_ioremap(&dev->dev, res->start, |
79 | resource_size(res)); | |
80 | if (!ep93xxbl->mmio) | |
81 | return -ENXIO; | |
08b3924b HS |
82 | |
83 | memset(&props, 0, sizeof(struct backlight_properties)); | |
bb7ca747 | 84 | props.type = BACKLIGHT_RAW; |
08b3924b | 85 | props.max_brightness = EP93XX_MAX_BRIGHT; |
23741ada JH |
86 | bl = devm_backlight_device_register(&dev->dev, dev->name, &dev->dev, |
87 | ep93xxbl, &ep93xxbl_ops, &props); | |
08b3924b HS |
88 | if (IS_ERR(bl)) |
89 | return PTR_ERR(bl); | |
90 | ||
91 | bl->props.brightness = EP93XX_DEF_BRIGHT; | |
92 | ||
93 | platform_set_drvdata(dev, bl); | |
94 | ||
95 | ep93xxbl_update_status(bl); | |
96 | ||
97 | return 0; | |
98 | } | |
99 | ||
d7696aad JH |
100 | #ifdef CONFIG_PM_SLEEP |
101 | static int ep93xxbl_suspend(struct device *dev) | |
08b3924b | 102 | { |
d7696aad | 103 | struct backlight_device *bl = dev_get_drvdata(dev); |
08b3924b HS |
104 | |
105 | return ep93xxbl_set(bl, 0); | |
106 | } | |
107 | ||
d7696aad | 108 | static int ep93xxbl_resume(struct device *dev) |
08b3924b | 109 | { |
d7696aad | 110 | struct backlight_device *bl = dev_get_drvdata(dev); |
08b3924b HS |
111 | |
112 | backlight_update_status(bl); | |
113 | return 0; | |
114 | } | |
08b3924b HS |
115 | #endif |
116 | ||
d7696aad JH |
117 | static SIMPLE_DEV_PM_OPS(ep93xxbl_pm_ops, ep93xxbl_suspend, ep93xxbl_resume); |
118 | ||
08b3924b HS |
119 | static struct platform_driver ep93xxbl_driver = { |
120 | .driver = { | |
121 | .name = "ep93xx-bl", | |
d7696aad | 122 | .pm = &ep93xxbl_pm_ops, |
08b3924b HS |
123 | }, |
124 | .probe = ep93xxbl_probe, | |
08b3924b HS |
125 | }; |
126 | ||
81178e02 | 127 | module_platform_driver(ep93xxbl_driver); |
08b3924b HS |
128 | |
129 | MODULE_DESCRIPTION("EP93xx Backlight Driver"); | |
130 | MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>"); | |
131 | MODULE_LICENSE("GPL"); | |
132 | MODULE_ALIAS("platform:ep93xx-bl"); |