Andrzej Zaborowski | ec072b0 | 2008-01-13 23:15:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Backlight driver for OMAP based boards. |
| 3 | * |
| 4 | * Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org> |
| 5 | * |
| 6 | * This package is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This package is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this package; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
Jingoo Han | 95e9313 | 2012-05-29 15:07:19 -0700 | [diff] [blame] | 21 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 22 | |
Andrzej Zaborowski | ec072b0 | 2008-01-13 23:15:43 +0000 | [diff] [blame] | 23 | #include <linux/module.h> |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/platform_device.h> |
| 27 | #include <linux/fb.h> |
| 28 | #include <linux/backlight.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Igor Grinberg | cc01272 | 2012-08-29 02:18:54 +0300 | [diff] [blame^] | 30 | #include <linux/platform_data/omap1_bl.h> |
Andrzej Zaborowski | ec072b0 | 2008-01-13 23:15:43 +0000 | [diff] [blame] | 31 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 32 | #include <mach/hardware.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 33 | #include <plat/mux.h> |
Andrzej Zaborowski | ec072b0 | 2008-01-13 23:15:43 +0000 | [diff] [blame] | 34 | |
| 35 | #define OMAPBL_MAX_INTENSITY 0xff |
| 36 | |
| 37 | struct omap_backlight { |
| 38 | int powermode; |
| 39 | int current_intensity; |
| 40 | |
| 41 | struct device *dev; |
| 42 | struct omap_backlight_config *pdata; |
| 43 | }; |
| 44 | |
| 45 | static void inline omapbl_send_intensity(int intensity) |
| 46 | { |
| 47 | omap_writeb(intensity, OMAP_PWL_ENABLE); |
| 48 | } |
| 49 | |
| 50 | static void inline omapbl_send_enable(int enable) |
| 51 | { |
| 52 | omap_writeb(enable, OMAP_PWL_CLK_ENABLE); |
| 53 | } |
| 54 | |
| 55 | static void omapbl_blank(struct omap_backlight *bl, int mode) |
| 56 | { |
| 57 | if (bl->pdata->set_power) |
| 58 | bl->pdata->set_power(bl->dev, mode); |
| 59 | |
| 60 | switch (mode) { |
| 61 | case FB_BLANK_NORMAL: |
| 62 | case FB_BLANK_VSYNC_SUSPEND: |
| 63 | case FB_BLANK_HSYNC_SUSPEND: |
| 64 | case FB_BLANK_POWERDOWN: |
| 65 | omapbl_send_intensity(0); |
| 66 | omapbl_send_enable(0); |
| 67 | break; |
| 68 | |
| 69 | case FB_BLANK_UNBLANK: |
| 70 | omapbl_send_intensity(bl->current_intensity); |
| 71 | omapbl_send_enable(1); |
| 72 | break; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | #ifdef CONFIG_PM |
| 77 | static int omapbl_suspend(struct platform_device *pdev, pm_message_t state) |
| 78 | { |
| 79 | struct backlight_device *dev = platform_get_drvdata(pdev); |
| 80 | struct omap_backlight *bl = dev_get_drvdata(&dev->dev); |
| 81 | |
| 82 | omapbl_blank(bl, FB_BLANK_POWERDOWN); |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | static int omapbl_resume(struct platform_device *pdev) |
| 87 | { |
| 88 | struct backlight_device *dev = platform_get_drvdata(pdev); |
| 89 | struct omap_backlight *bl = dev_get_drvdata(&dev->dev); |
| 90 | |
| 91 | omapbl_blank(bl, bl->powermode); |
| 92 | return 0; |
| 93 | } |
| 94 | #else |
| 95 | #define omapbl_suspend NULL |
| 96 | #define omapbl_resume NULL |
| 97 | #endif |
| 98 | |
| 99 | static int omapbl_set_power(struct backlight_device *dev, int state) |
| 100 | { |
| 101 | struct omap_backlight *bl = dev_get_drvdata(&dev->dev); |
| 102 | |
| 103 | omapbl_blank(bl, state); |
| 104 | bl->powermode = state; |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | static int omapbl_update_status(struct backlight_device *dev) |
| 110 | { |
| 111 | struct omap_backlight *bl = dev_get_drvdata(&dev->dev); |
| 112 | |
| 113 | if (bl->current_intensity != dev->props.brightness) { |
| 114 | if (bl->powermode == FB_BLANK_UNBLANK) |
| 115 | omapbl_send_intensity(dev->props.brightness); |
| 116 | bl->current_intensity = dev->props.brightness; |
| 117 | } |
| 118 | |
| 119 | if (dev->props.fb_blank != bl->powermode) |
| 120 | omapbl_set_power(dev, dev->props.fb_blank); |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | static int omapbl_get_intensity(struct backlight_device *dev) |
| 126 | { |
| 127 | struct omap_backlight *bl = dev_get_drvdata(&dev->dev); |
| 128 | return bl->current_intensity; |
| 129 | } |
| 130 | |
Emese Revfy | 9905a43 | 2009-12-14 00:58:57 +0100 | [diff] [blame] | 131 | static const struct backlight_ops omapbl_ops = { |
Andrzej Zaborowski | ec072b0 | 2008-01-13 23:15:43 +0000 | [diff] [blame] | 132 | .get_brightness = omapbl_get_intensity, |
| 133 | .update_status = omapbl_update_status, |
| 134 | }; |
| 135 | |
| 136 | static int omapbl_probe(struct platform_device *pdev) |
| 137 | { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 138 | struct backlight_properties props; |
Andrzej Zaborowski | ec072b0 | 2008-01-13 23:15:43 +0000 | [diff] [blame] | 139 | struct backlight_device *dev; |
| 140 | struct omap_backlight *bl; |
| 141 | struct omap_backlight_config *pdata = pdev->dev.platform_data; |
| 142 | |
| 143 | if (!pdata) |
| 144 | return -ENXIO; |
| 145 | |
Julia Lawall | ce96922 | 2012-03-23 15:02:00 -0700 | [diff] [blame] | 146 | bl = devm_kzalloc(&pdev->dev, sizeof(struct omap_backlight), |
| 147 | GFP_KERNEL); |
Andrzej Zaborowski | ec072b0 | 2008-01-13 23:15:43 +0000 | [diff] [blame] | 148 | if (unlikely(!bl)) |
| 149 | return -ENOMEM; |
| 150 | |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 151 | memset(&props, 0, sizeof(struct backlight_properties)); |
Matthew Garrett | bb7ca74 | 2011-03-22 16:30:21 -0700 | [diff] [blame] | 152 | props.type = BACKLIGHT_RAW; |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 153 | props.max_brightness = OMAPBL_MAX_INTENSITY; |
| 154 | dev = backlight_device_register("omap-bl", &pdev->dev, bl, &omapbl_ops, |
| 155 | &props); |
Julia Lawall | ce96922 | 2012-03-23 15:02:00 -0700 | [diff] [blame] | 156 | if (IS_ERR(dev)) |
Andrzej Zaborowski | ec072b0 | 2008-01-13 23:15:43 +0000 | [diff] [blame] | 157 | return PTR_ERR(dev); |
Andrzej Zaborowski | ec072b0 | 2008-01-13 23:15:43 +0000 | [diff] [blame] | 158 | |
| 159 | bl->powermode = FB_BLANK_POWERDOWN; |
| 160 | bl->current_intensity = 0; |
| 161 | |
| 162 | bl->pdata = pdata; |
| 163 | bl->dev = &pdev->dev; |
| 164 | |
| 165 | platform_set_drvdata(pdev, dev); |
| 166 | |
| 167 | omap_cfg_reg(PWL); /* Conflicts with UART3 */ |
| 168 | |
| 169 | dev->props.fb_blank = FB_BLANK_UNBLANK; |
Andrzej Zaborowski | ec072b0 | 2008-01-13 23:15:43 +0000 | [diff] [blame] | 170 | dev->props.brightness = pdata->default_intensity; |
| 171 | omapbl_update_status(dev); |
| 172 | |
Jingoo Han | 95e9313 | 2012-05-29 15:07:19 -0700 | [diff] [blame] | 173 | pr_info("OMAP LCD backlight initialised\n"); |
Andrzej Zaborowski | ec072b0 | 2008-01-13 23:15:43 +0000 | [diff] [blame] | 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | static int omapbl_remove(struct platform_device *pdev) |
| 179 | { |
| 180 | struct backlight_device *dev = platform_get_drvdata(pdev); |
Andrzej Zaborowski | ec072b0 | 2008-01-13 23:15:43 +0000 | [diff] [blame] | 181 | |
| 182 | backlight_device_unregister(dev); |
Andrzej Zaborowski | ec072b0 | 2008-01-13 23:15:43 +0000 | [diff] [blame] | 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | static struct platform_driver omapbl_driver = { |
| 188 | .probe = omapbl_probe, |
| 189 | .remove = omapbl_remove, |
| 190 | .suspend = omapbl_suspend, |
| 191 | .resume = omapbl_resume, |
| 192 | .driver = { |
| 193 | .name = "omap-bl", |
| 194 | }, |
| 195 | }; |
| 196 | |
Axel Lin | 81178e0 | 2012-01-10 15:09:11 -0800 | [diff] [blame] | 197 | module_platform_driver(omapbl_driver); |
Andrzej Zaborowski | ec072b0 | 2008-01-13 23:15:43 +0000 | [diff] [blame] | 198 | |
| 199 | MODULE_AUTHOR("Andrzej Zaborowski <balrog@zabor.org>"); |
| 200 | MODULE_DESCRIPTION("OMAP LCD Backlight driver"); |
| 201 | MODULE_LICENSE("GPL"); |