1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Backlight driver for OMAP based boards.
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/platform_device.h>
12 #include <linux/backlight.h>
13 #include <linux/slab.h>
14 #include <linux/platform_data/omap1_bl.h>
16 #include <linux/soc/ti/omap1-io.h>
17 #include <linux/soc/ti/omap1-mux.h>
19 #define OMAPBL_MAX_INTENSITY 0xff
21 struct omap_backlight {
23 int current_intensity;
26 struct omap_backlight_config *pdata;
29 static inline void omapbl_send_intensity(int intensity)
31 omap_writeb(intensity, OMAP_PWL_ENABLE);
34 static inline void omapbl_send_enable(int enable)
36 omap_writeb(enable, OMAP_PWL_CLK_ENABLE);
39 static void omapbl_enable(struct omap_backlight *bl, bool enable)
42 omapbl_send_intensity(bl->current_intensity);
43 omapbl_send_enable(1);
45 omapbl_send_intensity(0);
46 omapbl_send_enable(0);
50 #ifdef CONFIG_PM_SLEEP
51 static int omapbl_suspend(struct device *dev)
53 struct backlight_device *bl_dev = dev_get_drvdata(dev);
54 struct omap_backlight *bl = bl_get_data(bl_dev);
56 omapbl_enable(bl, false);
60 static int omapbl_resume(struct device *dev)
62 struct backlight_device *bl_dev = dev_get_drvdata(dev);
63 struct omap_backlight *bl = bl_get_data(bl_dev);
65 omapbl_enable(bl, bl->enabled);
70 static void omapbl_set_enabled(struct backlight_device *dev, bool enable)
72 struct omap_backlight *bl = bl_get_data(dev);
74 omapbl_enable(bl, enable);
78 static int omapbl_update_status(struct backlight_device *dev)
80 struct omap_backlight *bl = bl_get_data(dev);
83 if (bl->current_intensity != dev->props.brightness) {
85 omapbl_send_intensity(dev->props.brightness);
86 bl->current_intensity = dev->props.brightness;
89 enable = !backlight_is_blank(dev);
91 if (enable != bl->enabled)
92 omapbl_set_enabled(dev, enable);
97 static int omapbl_get_intensity(struct backlight_device *dev)
99 struct omap_backlight *bl = bl_get_data(dev);
101 return bl->current_intensity;
104 static const struct backlight_ops omapbl_ops = {
105 .get_brightness = omapbl_get_intensity,
106 .update_status = omapbl_update_status,
109 static int omapbl_probe(struct platform_device *pdev)
111 struct backlight_properties props;
112 struct backlight_device *dev;
113 struct omap_backlight *bl;
114 struct omap_backlight_config *pdata = dev_get_platdata(&pdev->dev);
119 bl = devm_kzalloc(&pdev->dev, sizeof(struct omap_backlight),
124 memset(&props, 0, sizeof(struct backlight_properties));
125 props.type = BACKLIGHT_RAW;
126 props.max_brightness = OMAPBL_MAX_INTENSITY;
127 dev = devm_backlight_device_register(&pdev->dev, "omap-bl", &pdev->dev,
128 bl, &omapbl_ops, &props);
133 bl->current_intensity = 0;
136 bl->dev = &pdev->dev;
138 platform_set_drvdata(pdev, dev);
140 omap_cfg_reg(PWL); /* Conflicts with UART3 */
142 dev->props.brightness = pdata->default_intensity;
143 omapbl_update_status(dev);
145 dev_info(&pdev->dev, "OMAP LCD backlight initialised\n");
150 static SIMPLE_DEV_PM_OPS(omapbl_pm_ops, omapbl_suspend, omapbl_resume);
152 static struct platform_driver omapbl_driver = {
153 .probe = omapbl_probe,
156 .pm = &omapbl_pm_ops,
160 module_platform_driver(omapbl_driver);
163 MODULE_DESCRIPTION("OMAP LCD Backlight driver");
164 MODULE_LICENSE("GPL");