Merge tag 'v3.3.7' into 3.3/master
[zen-stable.git] / drivers / video / backlight / kb3886_bl.c
blob72dd5556a35bdbe825f4fb86033f82828f206bc3
1 /*
2 * Backlight Driver for the KB3886 Backlight
4 * Copyright (c) 2007-2008 Claudio Nieder
6 * Based on corgi_bl.c by Richard Purdie and kb3886 driver by Robert Woerle
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/mutex.h>
19 #include <linux/fb.h>
20 #include <linux/backlight.h>
21 #include <linux/delay.h>
22 #include <linux/dmi.h>
24 #define KB3886_PARENT 0x64
25 #define KB3886_IO 0x60
26 #define KB3886_ADC_DAC_PWM 0xC4
27 #define KB3886_PWM0_WRITE 0x81
28 #define KB3886_PWM0_READ 0x41
30 static DEFINE_MUTEX(bl_mutex);
32 static void kb3886_bl_set_intensity(int intensity)
34 mutex_lock(&bl_mutex);
35 intensity = intensity&0xff;
36 outb(KB3886_ADC_DAC_PWM, KB3886_PARENT);
37 msleep(10);
38 outb(KB3886_PWM0_WRITE, KB3886_IO);
39 msleep(10);
40 outb(intensity, KB3886_IO);
41 mutex_unlock(&bl_mutex);
44 struct kb3886bl_machinfo {
45 int max_intensity;
46 int default_intensity;
47 int limit_mask;
48 void (*set_bl_intensity)(int intensity);
51 static struct kb3886bl_machinfo kb3886_bl_machinfo = {
52 .max_intensity = 0xff,
53 .default_intensity = 0xa0,
54 .limit_mask = 0x7f,
55 .set_bl_intensity = kb3886_bl_set_intensity,
58 static struct platform_device kb3886bl_device = {
59 .name = "kb3886-bl",
60 .dev = {
61 .platform_data = &kb3886_bl_machinfo,
63 .id = -1,
66 static struct platform_device *devices[] __initdata = {
67 &kb3886bl_device,
71 * Back to driver
74 static int kb3886bl_intensity;
75 static struct backlight_device *kb3886_backlight_device;
76 static struct kb3886bl_machinfo *bl_machinfo;
78 static unsigned long kb3886bl_flags;
79 #define KB3886BL_SUSPENDED 0x01
81 static struct dmi_system_id __initdata kb3886bl_device_table[] = {
83 .ident = "Sahara Touch-iT",
84 .matches = {
85 DMI_MATCH(DMI_SYS_VENDOR, "SDV"),
86 DMI_MATCH(DMI_PRODUCT_NAME, "iTouch T201"),
89 { }
92 static int kb3886bl_send_intensity(struct backlight_device *bd)
94 int intensity = bd->props.brightness;
96 if (bd->props.power != FB_BLANK_UNBLANK)
97 intensity = 0;
98 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
99 intensity = 0;
100 if (kb3886bl_flags & KB3886BL_SUSPENDED)
101 intensity = 0;
103 bl_machinfo->set_bl_intensity(intensity);
105 kb3886bl_intensity = intensity;
106 return 0;
109 #ifdef CONFIG_PM
110 static int kb3886bl_suspend(struct platform_device *pdev, pm_message_t state)
112 struct backlight_device *bd = platform_get_drvdata(pdev);
114 kb3886bl_flags |= KB3886BL_SUSPENDED;
115 backlight_update_status(bd);
116 return 0;
119 static int kb3886bl_resume(struct platform_device *pdev)
121 struct backlight_device *bd = platform_get_drvdata(pdev);
123 kb3886bl_flags &= ~KB3886BL_SUSPENDED;
124 backlight_update_status(bd);
125 return 0;
127 #else
128 #define kb3886bl_suspend NULL
129 #define kb3886bl_resume NULL
130 #endif
132 static int kb3886bl_get_intensity(struct backlight_device *bd)
134 return kb3886bl_intensity;
137 static const struct backlight_ops kb3886bl_ops = {
138 .get_brightness = kb3886bl_get_intensity,
139 .update_status = kb3886bl_send_intensity,
142 static int kb3886bl_probe(struct platform_device *pdev)
144 struct backlight_properties props;
145 struct kb3886bl_machinfo *machinfo = pdev->dev.platform_data;
147 bl_machinfo = machinfo;
148 if (!machinfo->limit_mask)
149 machinfo->limit_mask = -1;
151 memset(&props, 0, sizeof(struct backlight_properties));
152 props.type = BACKLIGHT_RAW;
153 props.max_brightness = machinfo->max_intensity;
154 kb3886_backlight_device = backlight_device_register("kb3886-bl",
155 &pdev->dev, NULL,
156 &kb3886bl_ops,
157 &props);
158 if (IS_ERR(kb3886_backlight_device))
159 return PTR_ERR(kb3886_backlight_device);
161 platform_set_drvdata(pdev, kb3886_backlight_device);
163 kb3886_backlight_device->props.power = FB_BLANK_UNBLANK;
164 kb3886_backlight_device->props.brightness = machinfo->default_intensity;
165 backlight_update_status(kb3886_backlight_device);
167 return 0;
170 static int kb3886bl_remove(struct platform_device *pdev)
172 struct backlight_device *bd = platform_get_drvdata(pdev);
174 backlight_device_unregister(bd);
176 return 0;
179 static struct platform_driver kb3886bl_driver = {
180 .probe = kb3886bl_probe,
181 .remove = kb3886bl_remove,
182 .suspend = kb3886bl_suspend,
183 .resume = kb3886bl_resume,
184 .driver = {
185 .name = "kb3886-bl",
189 static int __init kb3886_init(void)
191 if (!dmi_check_system(kb3886bl_device_table))
192 return -ENODEV;
194 platform_add_devices(devices, ARRAY_SIZE(devices));
195 return platform_driver_register(&kb3886bl_driver);
198 static void __exit kb3886_exit(void)
200 platform_driver_unregister(&kb3886bl_driver);
203 module_init(kb3886_init);
204 module_exit(kb3886_exit);
206 MODULE_AUTHOR("Claudio Nieder <private@claudio.ch>");
207 MODULE_DESCRIPTION("Tabletkiosk Sahara Touch-iT Backlight Driver");
208 MODULE_LICENSE("GPL");
209 MODULE_ALIAS("dmi:*:svnSDV:pniTouchT201:*");