Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) Intel Corp. 2007. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to |
| 6 | * develop this driver. |
| 7 | * |
| 8 | * This file is part of the Carillo Ranch video subsystem driver. |
| 9 | * The Carillo Ranch video subsystem driver is free software; |
| 10 | * you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * The Carillo Ranch video subsystem driver is distributed |
| 16 | * in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this driver; if not, write to the Free Software |
| 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 24 | * |
| 25 | * Authors: |
| 26 | * Thomas Hellstrom <thomas-at-tungstengraphics-dot-com> |
| 27 | * Alan Hourihane <alanh-at-tungstengraphics-dot-com> |
| 28 | */ |
| 29 | |
Jingoo Han | 31e6432 | 2012-05-29 15:07:17 -0700 | [diff] [blame] | 30 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 31 | |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 32 | #include <linux/module.h> |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/init.h> |
| 35 | #include <linux/platform_device.h> |
| 36 | #include <linux/mutex.h> |
| 37 | #include <linux/fb.h> |
| 38 | #include <linux/backlight.h> |
| 39 | #include <linux/lcd.h> |
| 40 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 41 | #include <linux/slab.h> |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 42 | |
| 43 | /* The LVDS- and panel power controls sits on the |
| 44 | * GPIO port of the ISA bridge. |
| 45 | */ |
| 46 | |
| 47 | #define CRVML_DEVICE_LPC 0x27B8 |
| 48 | #define CRVML_REG_GPIOBAR 0x48 |
| 49 | #define CRVML_REG_GPIOEN 0x4C |
| 50 | #define CRVML_GPIOEN_BIT (1 << 4) |
| 51 | #define CRVML_PANEL_PORT 0x38 |
| 52 | #define CRVML_LVDS_ON 0x00000001 |
| 53 | #define CRVML_PANEL_ON 0x00000002 |
| 54 | #define CRVML_BACKLIGHT_OFF 0x00000004 |
| 55 | |
| 56 | /* The PLL Clock register sits on Host bridge */ |
| 57 | #define CRVML_DEVICE_MCH 0x5001 |
| 58 | #define CRVML_REG_MCHBAR 0x44 |
| 59 | #define CRVML_REG_MCHEN 0x54 |
| 60 | #define CRVML_MCHEN_BIT (1 << 28) |
| 61 | #define CRVML_MCHMAP_SIZE 4096 |
| 62 | #define CRVML_REG_CLOCK 0xc3c |
| 63 | #define CRVML_CLOCK_SHIFT 8 |
| 64 | #define CRVML_CLOCK_MASK 0x00000f00 |
| 65 | |
| 66 | static struct pci_dev *lpc_dev; |
| 67 | static u32 gpio_bar; |
| 68 | |
| 69 | struct cr_panel { |
| 70 | struct backlight_device *cr_backlight_device; |
| 71 | struct lcd_device *cr_lcd_device; |
| 72 | }; |
| 73 | |
| 74 | static int cr_backlight_set_intensity(struct backlight_device *bd) |
| 75 | { |
| 76 | int intensity = bd->props.brightness; |
| 77 | u32 addr = gpio_bar + CRVML_PANEL_PORT; |
| 78 | u32 cur = inl(addr); |
| 79 | |
| 80 | if (bd->props.power == FB_BLANK_UNBLANK) |
| 81 | intensity = FB_BLANK_UNBLANK; |
| 82 | if (bd->props.fb_blank == FB_BLANK_UNBLANK) |
| 83 | intensity = FB_BLANK_UNBLANK; |
| 84 | if (bd->props.power == FB_BLANK_POWERDOWN) |
| 85 | intensity = FB_BLANK_POWERDOWN; |
| 86 | if (bd->props.fb_blank == FB_BLANK_POWERDOWN) |
| 87 | intensity = FB_BLANK_POWERDOWN; |
| 88 | |
| 89 | if (intensity == FB_BLANK_UNBLANK) { /* FULL ON */ |
| 90 | cur &= ~CRVML_BACKLIGHT_OFF; |
| 91 | outl(cur, addr); |
| 92 | } else if (intensity == FB_BLANK_POWERDOWN) { /* OFF */ |
| 93 | cur |= CRVML_BACKLIGHT_OFF; |
| 94 | outl(cur, addr); |
| 95 | } /* anything else, don't bother */ |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | static int cr_backlight_get_intensity(struct backlight_device *bd) |
| 101 | { |
| 102 | u32 addr = gpio_bar + CRVML_PANEL_PORT; |
| 103 | u32 cur = inl(addr); |
| 104 | u8 intensity; |
| 105 | |
| 106 | if (cur & CRVML_BACKLIGHT_OFF) |
| 107 | intensity = FB_BLANK_POWERDOWN; |
| 108 | else |
| 109 | intensity = FB_BLANK_UNBLANK; |
| 110 | |
| 111 | return intensity; |
| 112 | } |
| 113 | |
Emese Revfy | 9905a43 | 2009-12-14 00:58:57 +0100 | [diff] [blame] | 114 | static const struct backlight_ops cr_backlight_ops = { |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 115 | .get_brightness = cr_backlight_get_intensity, |
| 116 | .update_status = cr_backlight_set_intensity, |
| 117 | }; |
| 118 | |
| 119 | static void cr_panel_on(void) |
| 120 | { |
| 121 | u32 addr = gpio_bar + CRVML_PANEL_PORT; |
| 122 | u32 cur = inl(addr); |
| 123 | |
| 124 | if (!(cur & CRVML_PANEL_ON)) { |
| 125 | /* Make sure LVDS controller is down. */ |
| 126 | if (cur & 0x00000001) { |
| 127 | cur &= ~CRVML_LVDS_ON; |
| 128 | outl(cur, addr); |
| 129 | } |
| 130 | /* Power up Panel */ |
| 131 | schedule_timeout(HZ / 10); |
| 132 | cur |= CRVML_PANEL_ON; |
| 133 | outl(cur, addr); |
| 134 | } |
| 135 | |
| 136 | /* Power up LVDS controller */ |
| 137 | |
| 138 | if (!(cur & CRVML_LVDS_ON)) { |
| 139 | schedule_timeout(HZ / 10); |
| 140 | outl(cur | CRVML_LVDS_ON, addr); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | static void cr_panel_off(void) |
| 145 | { |
| 146 | u32 addr = gpio_bar + CRVML_PANEL_PORT; |
| 147 | u32 cur = inl(addr); |
| 148 | |
| 149 | /* Power down LVDS controller first to avoid high currents */ |
| 150 | if (cur & CRVML_LVDS_ON) { |
| 151 | cur &= ~CRVML_LVDS_ON; |
| 152 | outl(cur, addr); |
| 153 | } |
| 154 | if (cur & CRVML_PANEL_ON) { |
| 155 | schedule_timeout(HZ / 10); |
| 156 | outl(cur & ~CRVML_PANEL_ON, addr); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | static int cr_lcd_set_power(struct lcd_device *ld, int power) |
| 161 | { |
| 162 | if (power == FB_BLANK_UNBLANK) |
| 163 | cr_panel_on(); |
| 164 | if (power == FB_BLANK_POWERDOWN) |
| 165 | cr_panel_off(); |
| 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | static struct lcd_ops cr_lcd_ops = { |
| 171 | .set_power = cr_lcd_set_power, |
| 172 | }; |
| 173 | |
| 174 | static int cr_backlight_probe(struct platform_device *pdev) |
| 175 | { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 176 | struct backlight_properties props; |
Jesper Juhl | 0b75f2d | 2007-08-11 10:29:59 +0100 | [diff] [blame] | 177 | struct backlight_device *bdp; |
| 178 | struct lcd_device *ldp; |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 179 | struct cr_panel *crp; |
| 180 | u8 dev_en; |
| 181 | |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 182 | lpc_dev = pci_get_device(PCI_VENDOR_ID_INTEL, |
| 183 | CRVML_DEVICE_LPC, NULL); |
| 184 | if (!lpc_dev) { |
Jingoo Han | 31e6432 | 2012-05-29 15:07:17 -0700 | [diff] [blame] | 185 | pr_err("INTEL CARILLO RANCH LPC not found.\n"); |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 186 | return -ENODEV; |
| 187 | } |
| 188 | |
| 189 | pci_read_config_byte(lpc_dev, CRVML_REG_GPIOEN, &dev_en); |
| 190 | if (!(dev_en & CRVML_GPIOEN_BIT)) { |
Jingoo Han | 31e6432 | 2012-05-29 15:07:17 -0700 | [diff] [blame] | 191 | pr_err("Carillo Ranch GPIO device was not enabled.\n"); |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 192 | pci_dev_put(lpc_dev); |
| 193 | return -ENODEV; |
| 194 | } |
| 195 | |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 196 | memset(&props, 0, sizeof(struct backlight_properties)); |
Matthew Garrett | bb7ca74 | 2011-03-22 16:30:21 -0700 | [diff] [blame] | 197 | props.type = BACKLIGHT_RAW; |
Jingoo Han | 289a65e | 2013-11-12 15:09:35 -0800 | [diff] [blame] | 198 | bdp = devm_backlight_device_register(&pdev->dev, "cr-backlight", |
| 199 | &pdev->dev, NULL, &cr_backlight_ops, |
| 200 | &props); |
Jesper Juhl | 0b75f2d | 2007-08-11 10:29:59 +0100 | [diff] [blame] | 201 | if (IS_ERR(bdp)) { |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 202 | pci_dev_put(lpc_dev); |
Jesper Juhl | 0b75f2d | 2007-08-11 10:29:59 +0100 | [diff] [blame] | 203 | return PTR_ERR(bdp); |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Jingoo Han | 289a65e | 2013-11-12 15:09:35 -0800 | [diff] [blame] | 206 | ldp = devm_lcd_device_register(&pdev->dev, "cr-lcd", &pdev->dev, NULL, |
| 207 | &cr_lcd_ops); |
Jesper Juhl | 0b75f2d | 2007-08-11 10:29:59 +0100 | [diff] [blame] | 208 | if (IS_ERR(ldp)) { |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 209 | pci_dev_put(lpc_dev); |
Roel Kluin | 5b0582e | 2009-12-07 14:35:32 +0100 | [diff] [blame] | 210 | return PTR_ERR(ldp); |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | pci_read_config_dword(lpc_dev, CRVML_REG_GPIOBAR, |
| 214 | &gpio_bar); |
| 215 | gpio_bar &= ~0x3F; |
| 216 | |
Julia Lawall | ce96922 | 2012-03-23 15:02:00 -0700 | [diff] [blame] | 217 | crp = devm_kzalloc(&pdev->dev, sizeof(*crp), GFP_KERNEL); |
Jesper Juhl | 0b75f2d | 2007-08-11 10:29:59 +0100 | [diff] [blame] | 218 | if (!crp) { |
Jesper Juhl | 0b75f2d | 2007-08-11 10:29:59 +0100 | [diff] [blame] | 219 | pci_dev_put(lpc_dev); |
| 220 | return -ENOMEM; |
| 221 | } |
| 222 | |
| 223 | crp->cr_backlight_device = bdp; |
| 224 | crp->cr_lcd_device = ldp; |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 225 | crp->cr_backlight_device->props.power = FB_BLANK_UNBLANK; |
| 226 | crp->cr_backlight_device->props.brightness = 0; |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 227 | cr_backlight_set_intensity(crp->cr_backlight_device); |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 228 | cr_lcd_set_power(crp->cr_lcd_device, FB_BLANK_UNBLANK); |
| 229 | |
| 230 | platform_set_drvdata(pdev, crp); |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | static int cr_backlight_remove(struct platform_device *pdev) |
| 236 | { |
| 237 | struct cr_panel *crp = platform_get_drvdata(pdev); |
Jingoo Han | 7beeee4 | 2014-08-27 10:11:14 +0900 | [diff] [blame] | 238 | |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 239 | crp->cr_backlight_device->props.power = FB_BLANK_POWERDOWN; |
| 240 | crp->cr_backlight_device->props.brightness = 0; |
| 241 | crp->cr_backlight_device->props.max_brightness = 0; |
| 242 | cr_backlight_set_intensity(crp->cr_backlight_device); |
| 243 | cr_lcd_set_power(crp->cr_lcd_device, FB_BLANK_POWERDOWN); |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 244 | pci_dev_put(lpc_dev); |
| 245 | |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | static struct platform_driver cr_backlight_driver = { |
| 250 | .probe = cr_backlight_probe, |
| 251 | .remove = cr_backlight_remove, |
| 252 | .driver = { |
| 253 | .name = "cr_backlight", |
| 254 | }, |
| 255 | }; |
| 256 | |
| 257 | static struct platform_device *crp; |
| 258 | |
| 259 | static int __init cr_backlight_init(void) |
| 260 | { |
| 261 | int ret = platform_driver_register(&cr_backlight_driver); |
| 262 | |
Akinobu Mita | b4a11d3 | 2008-11-17 15:21:32 +0000 | [diff] [blame] | 263 | if (ret) |
| 264 | return ret; |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 265 | |
Akinobu Mita | b4a11d3 | 2008-11-17 15:21:32 +0000 | [diff] [blame] | 266 | crp = platform_device_register_simple("cr_backlight", -1, NULL, 0); |
| 267 | if (IS_ERR(crp)) { |
| 268 | platform_driver_unregister(&cr_backlight_driver); |
| 269 | return PTR_ERR(crp); |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Jingoo Han | 31e6432 | 2012-05-29 15:07:17 -0700 | [diff] [blame] | 272 | pr_info("Carillo Ranch Backlight Driver Initialized.\n"); |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 273 | |
Akinobu Mita | b4a11d3 | 2008-11-17 15:21:32 +0000 | [diff] [blame] | 274 | return 0; |
Alan Hourihane | dbe7e42 | 2007-05-08 00:39:25 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | static void __exit cr_backlight_exit(void) |
| 278 | { |
| 279 | platform_device_unregister(crp); |
| 280 | platform_driver_unregister(&cr_backlight_driver); |
| 281 | } |
| 282 | |
| 283 | module_init(cr_backlight_init); |
| 284 | module_exit(cr_backlight_exit); |
| 285 | |
| 286 | MODULE_AUTHOR("Tungsten Graphics Inc."); |
| 287 | MODULE_DESCRIPTION("Carillo Ranch Backlight Driver"); |
| 288 | MODULE_LICENSE("GPL"); |