1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) Intel Corp. 2007.
6 * Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
9 * This file is part of the Carillo Ranch video subsystem driver.
12 * Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
13 * Alan Hourihane <alanh-at-tungstengraphics-dot-com>
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/platform_device.h>
22 #include <linux/mutex.h>
24 #include <linux/backlight.h>
25 #include <linux/lcd.h>
26 #include <linux/pci.h>
27 #include <linux/slab.h>
29 /* The LVDS- and panel power controls sits on the
30 * GPIO port of the ISA bridge.
33 #define CRVML_DEVICE_LPC 0x27B8
34 #define CRVML_REG_GPIOBAR 0x48
35 #define CRVML_REG_GPIOEN 0x4C
36 #define CRVML_GPIOEN_BIT (1 << 4)
37 #define CRVML_PANEL_PORT 0x38
38 #define CRVML_LVDS_ON 0x00000001
39 #define CRVML_PANEL_ON 0x00000002
40 #define CRVML_BACKLIGHT_OFF 0x00000004
42 /* The PLL Clock register sits on Host bridge */
43 #define CRVML_DEVICE_MCH 0x5001
44 #define CRVML_REG_MCHBAR 0x44
45 #define CRVML_REG_MCHEN 0x54
46 #define CRVML_MCHEN_BIT (1 << 28)
47 #define CRVML_MCHMAP_SIZE 4096
48 #define CRVML_REG_CLOCK 0xc3c
49 #define CRVML_CLOCK_SHIFT 8
50 #define CRVML_CLOCK_MASK 0x00000f00
52 static struct pci_dev
*lpc_dev
;
56 struct backlight_device
*cr_backlight_device
;
57 struct lcd_device
*cr_lcd_device
;
60 static int cr_backlight_set_intensity(struct backlight_device
*bd
)
62 int intensity
= bd
->props
.brightness
;
63 u32 addr
= gpio_bar
+ CRVML_PANEL_PORT
;
66 if (bd
->props
.power
== FB_BLANK_UNBLANK
)
67 intensity
= FB_BLANK_UNBLANK
;
68 if (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
)
69 intensity
= FB_BLANK_UNBLANK
;
70 if (bd
->props
.power
== FB_BLANK_POWERDOWN
)
71 intensity
= FB_BLANK_POWERDOWN
;
72 if (bd
->props
.fb_blank
== FB_BLANK_POWERDOWN
)
73 intensity
= FB_BLANK_POWERDOWN
;
75 if (intensity
== FB_BLANK_UNBLANK
) { /* FULL ON */
76 cur
&= ~CRVML_BACKLIGHT_OFF
;
78 } else if (intensity
== FB_BLANK_POWERDOWN
) { /* OFF */
79 cur
|= CRVML_BACKLIGHT_OFF
;
81 } /* anything else, don't bother */
86 static int cr_backlight_get_intensity(struct backlight_device
*bd
)
88 u32 addr
= gpio_bar
+ CRVML_PANEL_PORT
;
92 if (cur
& CRVML_BACKLIGHT_OFF
)
93 intensity
= FB_BLANK_POWERDOWN
;
95 intensity
= FB_BLANK_UNBLANK
;
100 static const struct backlight_ops cr_backlight_ops
= {
101 .get_brightness
= cr_backlight_get_intensity
,
102 .update_status
= cr_backlight_set_intensity
,
105 static void cr_panel_on(void)
107 u32 addr
= gpio_bar
+ CRVML_PANEL_PORT
;
110 if (!(cur
& CRVML_PANEL_ON
)) {
111 /* Make sure LVDS controller is down. */
112 if (cur
& 0x00000001) {
113 cur
&= ~CRVML_LVDS_ON
;
117 schedule_timeout(HZ
/ 10);
118 cur
|= CRVML_PANEL_ON
;
122 /* Power up LVDS controller */
124 if (!(cur
& CRVML_LVDS_ON
)) {
125 schedule_timeout(HZ
/ 10);
126 outl(cur
| CRVML_LVDS_ON
, addr
);
130 static void cr_panel_off(void)
132 u32 addr
= gpio_bar
+ CRVML_PANEL_PORT
;
135 /* Power down LVDS controller first to avoid high currents */
136 if (cur
& CRVML_LVDS_ON
) {
137 cur
&= ~CRVML_LVDS_ON
;
140 if (cur
& CRVML_PANEL_ON
) {
141 schedule_timeout(HZ
/ 10);
142 outl(cur
& ~CRVML_PANEL_ON
, addr
);
146 static int cr_lcd_set_power(struct lcd_device
*ld
, int power
)
148 if (power
== FB_BLANK_UNBLANK
)
150 if (power
== FB_BLANK_POWERDOWN
)
156 static struct lcd_ops cr_lcd_ops
= {
157 .set_power
= cr_lcd_set_power
,
160 static int cr_backlight_probe(struct platform_device
*pdev
)
162 struct backlight_properties props
;
163 struct backlight_device
*bdp
;
164 struct lcd_device
*ldp
;
165 struct cr_panel
*crp
;
168 lpc_dev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
169 CRVML_DEVICE_LPC
, NULL
);
171 pr_err("INTEL CARILLO RANCH LPC not found.\n");
175 pci_read_config_byte(lpc_dev
, CRVML_REG_GPIOEN
, &dev_en
);
176 if (!(dev_en
& CRVML_GPIOEN_BIT
)) {
177 pr_err("Carillo Ranch GPIO device was not enabled.\n");
178 pci_dev_put(lpc_dev
);
182 memset(&props
, 0, sizeof(struct backlight_properties
));
183 props
.type
= BACKLIGHT_RAW
;
184 bdp
= devm_backlight_device_register(&pdev
->dev
, "cr-backlight",
185 &pdev
->dev
, NULL
, &cr_backlight_ops
,
188 pci_dev_put(lpc_dev
);
192 ldp
= devm_lcd_device_register(&pdev
->dev
, "cr-lcd", &pdev
->dev
, NULL
,
195 pci_dev_put(lpc_dev
);
199 pci_read_config_dword(lpc_dev
, CRVML_REG_GPIOBAR
,
203 crp
= devm_kzalloc(&pdev
->dev
, sizeof(*crp
), GFP_KERNEL
);
205 pci_dev_put(lpc_dev
);
209 crp
->cr_backlight_device
= bdp
;
210 crp
->cr_lcd_device
= ldp
;
211 crp
->cr_backlight_device
->props
.power
= FB_BLANK_UNBLANK
;
212 crp
->cr_backlight_device
->props
.brightness
= 0;
213 cr_backlight_set_intensity(crp
->cr_backlight_device
);
214 cr_lcd_set_power(crp
->cr_lcd_device
, FB_BLANK_UNBLANK
);
216 platform_set_drvdata(pdev
, crp
);
221 static int cr_backlight_remove(struct platform_device
*pdev
)
223 struct cr_panel
*crp
= platform_get_drvdata(pdev
);
225 crp
->cr_backlight_device
->props
.power
= FB_BLANK_POWERDOWN
;
226 crp
->cr_backlight_device
->props
.brightness
= 0;
227 crp
->cr_backlight_device
->props
.max_brightness
= 0;
228 cr_backlight_set_intensity(crp
->cr_backlight_device
);
229 cr_lcd_set_power(crp
->cr_lcd_device
, FB_BLANK_POWERDOWN
);
230 pci_dev_put(lpc_dev
);
235 static struct platform_driver cr_backlight_driver
= {
236 .probe
= cr_backlight_probe
,
237 .remove
= cr_backlight_remove
,
239 .name
= "cr_backlight",
243 static struct platform_device
*crp
;
245 static int __init
cr_backlight_init(void)
247 int ret
= platform_driver_register(&cr_backlight_driver
);
252 crp
= platform_device_register_simple("cr_backlight", -1, NULL
, 0);
254 platform_driver_unregister(&cr_backlight_driver
);
258 pr_info("Carillo Ranch Backlight Driver Initialized.\n");
263 static void __exit
cr_backlight_exit(void)
265 platform_device_unregister(crp
);
266 platform_driver_unregister(&cr_backlight_driver
);
269 module_init(cr_backlight_init
);
270 module_exit(cr_backlight_exit
);
272 MODULE_AUTHOR("Tungsten Graphics Inc.");
273 MODULE_DESCRIPTION("Carillo Ranch Backlight Driver");
274 MODULE_LICENSE("GPL");