Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / video / backlight / cr_bllcd.c
blob4ad0a72531fe2de2ac67895dd4ff52194febca2d
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) Intel Corp. 2007.
4 * All Rights Reserved.
6 * Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
7 * develop this driver.
9 * This file is part of the Carillo Ranch video subsystem driver.
11 * Authors:
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>
23 #include <linux/fb.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;
53 static u32 gpio_bar;
55 struct cr_panel {
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;
63 u32 cur = inl(addr);
65 if (backlight_get_brightness(bd) == 0) {
66 /* OFF */
67 cur |= CRVML_BACKLIGHT_OFF;
68 outl(cur, addr);
69 } else {
70 /* FULL ON */
71 cur &= ~CRVML_BACKLIGHT_OFF;
72 outl(cur, addr);
75 return 0;
78 static int cr_backlight_get_intensity(struct backlight_device *bd)
80 u32 addr = gpio_bar + CRVML_PANEL_PORT;
81 u32 cur = inl(addr);
82 u8 intensity;
84 if (cur & CRVML_BACKLIGHT_OFF)
85 intensity = 0;
86 else
87 intensity = 1;
89 return intensity;
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;
100 u32 cur = inl(addr);
102 if (!(cur & CRVML_PANEL_ON)) {
103 /* Make sure LVDS controller is down. */
104 if (cur & 0x00000001) {
105 cur &= ~CRVML_LVDS_ON;
106 outl(cur, addr);
108 /* Power up Panel */
109 schedule_timeout(HZ / 10);
110 cur |= CRVML_PANEL_ON;
111 outl(cur, addr);
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;
125 u32 cur = inl(addr);
127 /* Power down LVDS controller first to avoid high currents */
128 if (cur & CRVML_LVDS_ON) {
129 cur &= ~CRVML_LVDS_ON;
130 outl(cur, addr);
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)
141 cr_panel_on();
142 if (power == FB_BLANK_POWERDOWN)
143 cr_panel_off();
145 return 0;
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;
158 u8 dev_en;
160 lpc_dev = pci_get_device(PCI_VENDOR_ID_INTEL,
161 CRVML_DEVICE_LPC, NULL);
162 if (!lpc_dev) {
163 pr_err("INTEL CARILLO RANCH LPC not found.\n");
164 return -ENODEV;
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);
171 return -ENODEV;
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,
178 &props);
179 if (IS_ERR(bdp)) {
180 pci_dev_put(lpc_dev);
181 return PTR_ERR(bdp);
184 ldp = devm_lcd_device_register(&pdev->dev, "cr-lcd", &pdev->dev, NULL,
185 &cr_lcd_ops);
186 if (IS_ERR(ldp)) {
187 pci_dev_put(lpc_dev);
188 return PTR_ERR(ldp);
191 pci_read_config_dword(lpc_dev, CRVML_REG_GPIOBAR,
192 &gpio_bar);
193 gpio_bar &= ~0x3F;
195 crp = devm_kzalloc(&pdev->dev, sizeof(*crp), GFP_KERNEL);
196 if (!crp) {
197 pci_dev_put(lpc_dev);
198 return -ENOMEM;
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);
210 return 0;
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);
224 return 0;
227 static struct platform_driver cr_backlight_driver = {
228 .probe = cr_backlight_probe,
229 .remove = cr_backlight_remove,
230 .driver = {
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);
241 if (ret)
242 return ret;
244 crp = platform_device_register_simple("cr_backlight", -1, NULL, 0);
245 if (IS_ERR(crp)) {
246 platform_driver_unregister(&cr_backlight_driver);
247 return PTR_ERR(crp);
250 pr_info("Carillo Ranch Backlight Driver Initialized.\n");
252 return 0;
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");