WIP FPC-III support
[linux/fpc-iii.git] / drivers / video / backlight / kb3886_bl.c
blob55794b239cff0fcd32011d455820ecdcf9ae0d0d
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Backlight Driver for the KB3886 Backlight
5 * Copyright (c) 2007-2008 Claudio Nieder
7 * Based on corgi_bl.c by Richard Purdie and kb3886 driver by Robert Woerle
8 */
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/mutex.h>
15 #include <linux/fb.h>
16 #include <linux/backlight.h>
17 #include <linux/delay.h>
18 #include <linux/dmi.h>
20 #define KB3886_PARENT 0x64
21 #define KB3886_IO 0x60
22 #define KB3886_ADC_DAC_PWM 0xC4
23 #define KB3886_PWM0_WRITE 0x81
24 #define KB3886_PWM0_READ 0x41
26 static DEFINE_MUTEX(bl_mutex);
28 static void kb3886_bl_set_intensity(int intensity)
30 mutex_lock(&bl_mutex);
31 intensity = intensity&0xff;
32 outb(KB3886_ADC_DAC_PWM, KB3886_PARENT);
33 usleep_range(10000, 11000);
34 outb(KB3886_PWM0_WRITE, KB3886_IO);
35 usleep_range(10000, 11000);
36 outb(intensity, KB3886_IO);
37 mutex_unlock(&bl_mutex);
40 struct kb3886bl_machinfo {
41 int max_intensity;
42 int default_intensity;
43 int limit_mask;
44 void (*set_bl_intensity)(int intensity);
47 static struct kb3886bl_machinfo kb3886_bl_machinfo = {
48 .max_intensity = 0xff,
49 .default_intensity = 0xa0,
50 .limit_mask = 0x7f,
51 .set_bl_intensity = kb3886_bl_set_intensity,
54 static struct platform_device kb3886bl_device = {
55 .name = "kb3886-bl",
56 .dev = {
57 .platform_data = &kb3886_bl_machinfo,
59 .id = -1,
62 static struct platform_device *devices[] __initdata = {
63 &kb3886bl_device,
67 * Back to driver
70 static int kb3886bl_intensity;
71 static struct backlight_device *kb3886_backlight_device;
72 static struct kb3886bl_machinfo *bl_machinfo;
74 static unsigned long kb3886bl_flags;
75 #define KB3886BL_SUSPENDED 0x01
77 static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
79 .ident = "Sahara Touch-iT",
80 .matches = {
81 DMI_MATCH(DMI_SYS_VENDOR, "SDV"),
82 DMI_MATCH(DMI_PRODUCT_NAME, "iTouch T201"),
85 { }
88 static int kb3886bl_send_intensity(struct backlight_device *bd)
90 int intensity = backlight_get_brightness(bd);
92 if (kb3886bl_flags & KB3886BL_SUSPENDED)
93 intensity = 0;
95 bl_machinfo->set_bl_intensity(intensity);
97 kb3886bl_intensity = intensity;
98 return 0;
101 #ifdef CONFIG_PM_SLEEP
102 static int kb3886bl_suspend(struct device *dev)
104 struct backlight_device *bd = dev_get_drvdata(dev);
106 kb3886bl_flags |= KB3886BL_SUSPENDED;
107 backlight_update_status(bd);
108 return 0;
111 static int kb3886bl_resume(struct device *dev)
113 struct backlight_device *bd = dev_get_drvdata(dev);
115 kb3886bl_flags &= ~KB3886BL_SUSPENDED;
116 backlight_update_status(bd);
117 return 0;
119 #endif
121 static SIMPLE_DEV_PM_OPS(kb3886bl_pm_ops, kb3886bl_suspend, kb3886bl_resume);
123 static int kb3886bl_get_intensity(struct backlight_device *bd)
125 return kb3886bl_intensity;
128 static const struct backlight_ops kb3886bl_ops = {
129 .get_brightness = kb3886bl_get_intensity,
130 .update_status = kb3886bl_send_intensity,
133 static int kb3886bl_probe(struct platform_device *pdev)
135 struct backlight_properties props;
136 struct kb3886bl_machinfo *machinfo = dev_get_platdata(&pdev->dev);
138 bl_machinfo = machinfo;
139 if (!machinfo->limit_mask)
140 machinfo->limit_mask = -1;
142 memset(&props, 0, sizeof(struct backlight_properties));
143 props.type = BACKLIGHT_RAW;
144 props.max_brightness = machinfo->max_intensity;
145 kb3886_backlight_device = devm_backlight_device_register(&pdev->dev,
146 "kb3886-bl", &pdev->dev,
147 NULL, &kb3886bl_ops,
148 &props);
149 if (IS_ERR(kb3886_backlight_device))
150 return PTR_ERR(kb3886_backlight_device);
152 platform_set_drvdata(pdev, kb3886_backlight_device);
154 kb3886_backlight_device->props.power = FB_BLANK_UNBLANK;
155 kb3886_backlight_device->props.brightness = machinfo->default_intensity;
156 backlight_update_status(kb3886_backlight_device);
158 return 0;
161 static struct platform_driver kb3886bl_driver = {
162 .probe = kb3886bl_probe,
163 .driver = {
164 .name = "kb3886-bl",
165 .pm = &kb3886bl_pm_ops,
169 static int __init kb3886_init(void)
171 if (!dmi_check_system(kb3886bl_device_table))
172 return -ENODEV;
174 platform_add_devices(devices, ARRAY_SIZE(devices));
175 return platform_driver_register(&kb3886bl_driver);
178 static void __exit kb3886_exit(void)
180 platform_driver_unregister(&kb3886bl_driver);
183 module_init(kb3886_init);
184 module_exit(kb3886_exit);
186 MODULE_AUTHOR("Claudio Nieder <private@claudio.ch>");
187 MODULE_DESCRIPTION("Tabletkiosk Sahara Touch-iT Backlight Driver");
188 MODULE_LICENSE("GPL");
189 MODULE_ALIAS("dmi:*:svnSDV:pniTouchT201:*");