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 u32 addr
= gpio_bar
+ CRVML_PANEL_PORT
;
65 if (backlight_get_brightness(bd
) == 0) {
67 cur
|= CRVML_BACKLIGHT_OFF
;
71 cur
&= ~CRVML_BACKLIGHT_OFF
;
78 static int cr_backlight_get_intensity(struct backlight_device
*bd
)
80 u32 addr
= gpio_bar
+ CRVML_PANEL_PORT
;
84 if (cur
& CRVML_BACKLIGHT_OFF
)
92 static const struct backlight_ops cr_backlight_ops
= {
93 .get_brightness
= cr_backlight_get_intensity
,
94 .update_status
= cr_backlight_set_intensity
,
97 static void cr_panel_on(void)
99 u32 addr
= gpio_bar
+ CRVML_PANEL_PORT
;
102 if (!(cur
& CRVML_PANEL_ON
)) {
103 /* Make sure LVDS controller is down. */
104 if (cur
& 0x00000001) {
105 cur
&= ~CRVML_LVDS_ON
;
109 schedule_timeout(HZ
/ 10);
110 cur
|= CRVML_PANEL_ON
;
114 /* Power up LVDS controller */
116 if (!(cur
& CRVML_LVDS_ON
)) {
117 schedule_timeout(HZ
/ 10);
118 outl(cur
| CRVML_LVDS_ON
, addr
);
122 static void cr_panel_off(void)
124 u32 addr
= gpio_bar
+ CRVML_PANEL_PORT
;
127 /* Power down LVDS controller first to avoid high currents */
128 if (cur
& CRVML_LVDS_ON
) {
129 cur
&= ~CRVML_LVDS_ON
;
132 if (cur
& CRVML_PANEL_ON
) {
133 schedule_timeout(HZ
/ 10);
134 outl(cur
& ~CRVML_PANEL_ON
, addr
);
138 static int cr_lcd_set_power(struct lcd_device
*ld
, int power
)
140 if (power
== FB_BLANK_UNBLANK
)
142 if (power
== FB_BLANK_POWERDOWN
)
148 static struct lcd_ops cr_lcd_ops
= {
149 .set_power
= cr_lcd_set_power
,
152 static int cr_backlight_probe(struct platform_device
*pdev
)
154 struct backlight_properties props
;
155 struct backlight_device
*bdp
;
156 struct lcd_device
*ldp
;
157 struct cr_panel
*crp
;
160 lpc_dev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
161 CRVML_DEVICE_LPC
, NULL
);
163 pr_err("INTEL CARILLO RANCH LPC not found.\n");
167 pci_read_config_byte(lpc_dev
, CRVML_REG_GPIOEN
, &dev_en
);
168 if (!(dev_en
& CRVML_GPIOEN_BIT
)) {
169 pr_err("Carillo Ranch GPIO device was not enabled.\n");
170 pci_dev_put(lpc_dev
);
174 memset(&props
, 0, sizeof(struct backlight_properties
));
175 props
.type
= BACKLIGHT_RAW
;
176 bdp
= devm_backlight_device_register(&pdev
->dev
, "cr-backlight",
177 &pdev
->dev
, NULL
, &cr_backlight_ops
,
180 pci_dev_put(lpc_dev
);
184 ldp
= devm_lcd_device_register(&pdev
->dev
, "cr-lcd", &pdev
->dev
, NULL
,
187 pci_dev_put(lpc_dev
);
191 pci_read_config_dword(lpc_dev
, CRVML_REG_GPIOBAR
,
195 crp
= devm_kzalloc(&pdev
->dev
, sizeof(*crp
), GFP_KERNEL
);
197 pci_dev_put(lpc_dev
);
201 crp
->cr_backlight_device
= bdp
;
202 crp
->cr_lcd_device
= ldp
;
203 crp
->cr_backlight_device
->props
.power
= FB_BLANK_UNBLANK
;
204 crp
->cr_backlight_device
->props
.brightness
= 0;
205 cr_backlight_set_intensity(crp
->cr_backlight_device
);
206 cr_lcd_set_power(crp
->cr_lcd_device
, FB_BLANK_UNBLANK
);
208 platform_set_drvdata(pdev
, crp
);
213 static int cr_backlight_remove(struct platform_device
*pdev
)
215 struct cr_panel
*crp
= platform_get_drvdata(pdev
);
217 crp
->cr_backlight_device
->props
.power
= FB_BLANK_POWERDOWN
;
218 crp
->cr_backlight_device
->props
.brightness
= 0;
219 crp
->cr_backlight_device
->props
.max_brightness
= 0;
220 cr_backlight_set_intensity(crp
->cr_backlight_device
);
221 cr_lcd_set_power(crp
->cr_lcd_device
, FB_BLANK_POWERDOWN
);
222 pci_dev_put(lpc_dev
);
227 static struct platform_driver cr_backlight_driver
= {
228 .probe
= cr_backlight_probe
,
229 .remove
= cr_backlight_remove
,
231 .name
= "cr_backlight",
235 static struct platform_device
*crp
;
237 static int __init
cr_backlight_init(void)
239 int ret
= platform_driver_register(&cr_backlight_driver
);
244 crp
= platform_device_register_simple("cr_backlight", -1, NULL
, 0);
246 platform_driver_unregister(&cr_backlight_driver
);
250 pr_info("Carillo Ranch Backlight Driver Initialized.\n");
255 static void __exit
cr_backlight_exit(void)
257 platform_device_unregister(crp
);
258 platform_driver_unregister(&cr_backlight_driver
);
261 module_init(cr_backlight_init
);
262 module_exit(cr_backlight_exit
);
264 MODULE_AUTHOR("Tungsten Graphics Inc.");
265 MODULE_DESCRIPTION("Carillo Ranch Backlight Driver");
266 MODULE_LICENSE("GPL");