blob: 84a110a719cbd73256c326b13fe19619b6cfde74 [file] [log] [blame]
Claudio Niederd03ebb12008-10-20 23:35:40 +01001/*
2 * Backlight Driver for the KB3886 Backlight
3 *
4 * Copyright (c) 2007-2008 Claudio Nieder
5 *
6 * Based on corgi_bl.c by Richard Purdie and kb3886 driver by Robert Woerle
7 *
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.
11 *
12 */
13
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>
23
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
29
30static DEFINE_MUTEX(bl_mutex);
31
32static void kb3886_bl_set_intensity(int intensity)
33{
34 mutex_lock(&bl_mutex);
35 intensity = intensity&0xff;
36 outb(KB3886_ADC_DAC_PWM, KB3886_PARENT);
Jingoo Han7c9332d2012-10-04 17:12:47 -070037 usleep_range(10000, 11000);
Claudio Niederd03ebb12008-10-20 23:35:40 +010038 outb(KB3886_PWM0_WRITE, KB3886_IO);
Jingoo Han7c9332d2012-10-04 17:12:47 -070039 usleep_range(10000, 11000);
Claudio Niederd03ebb12008-10-20 23:35:40 +010040 outb(intensity, KB3886_IO);
41 mutex_unlock(&bl_mutex);
42}
43
44struct kb3886bl_machinfo {
45 int max_intensity;
46 int default_intensity;
47 int limit_mask;
48 void (*set_bl_intensity)(int intensity);
49};
50
51static 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,
56};
57
58static struct platform_device kb3886bl_device = {
59 .name = "kb3886-bl",
60 .dev = {
61 .platform_data = &kb3886_bl_machinfo,
62 },
63 .id = -1,
64};
65
66static struct platform_device *devices[] __initdata = {
67 &kb3886bl_device,
68};
69
70/*
71 * Back to driver
72 */
73
74static int kb3886bl_intensity;
75static struct backlight_device *kb3886_backlight_device;
76static struct kb3886bl_machinfo *bl_machinfo;
77
78static unsigned long kb3886bl_flags;
79#define KB3886BL_SUSPENDED 0x01
80
Jingoo Han81f5cdc2014-01-23 15:54:31 -080081static struct dmi_system_id kb3886bl_device_table[] __initdata = {
Claudio Niederd03ebb12008-10-20 23:35:40 +010082 {
83 .ident = "Sahara Touch-iT",
84 .matches = {
85 DMI_MATCH(DMI_SYS_VENDOR, "SDV"),
86 DMI_MATCH(DMI_PRODUCT_NAME, "iTouch T201"),
87 },
88 },
89 { }
90};
91
92static int kb3886bl_send_intensity(struct backlight_device *bd)
93{
94 int intensity = bd->props.brightness;
95
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;
102
103 bl_machinfo->set_bl_intensity(intensity);
104
105 kb3886bl_intensity = intensity;
106 return 0;
107}
108
Jingoo Hanf10a46c2013-04-29 16:17:43 -0700109#ifdef CONFIG_PM_SLEEP
110static int kb3886bl_suspend(struct device *dev)
Claudio Niederd03ebb12008-10-20 23:35:40 +0100111{
Jingoo Hanf10a46c2013-04-29 16:17:43 -0700112 struct backlight_device *bd = dev_get_drvdata(dev);
Claudio Niederd03ebb12008-10-20 23:35:40 +0100113
114 kb3886bl_flags |= KB3886BL_SUSPENDED;
115 backlight_update_status(bd);
116 return 0;
117}
118
Jingoo Hanf10a46c2013-04-29 16:17:43 -0700119static int kb3886bl_resume(struct device *dev)
Claudio Niederd03ebb12008-10-20 23:35:40 +0100120{
Jingoo Hanf10a46c2013-04-29 16:17:43 -0700121 struct backlight_device *bd = dev_get_drvdata(dev);
Claudio Niederd03ebb12008-10-20 23:35:40 +0100122
123 kb3886bl_flags &= ~KB3886BL_SUSPENDED;
124 backlight_update_status(bd);
125 return 0;
126}
Claudio Niederd03ebb12008-10-20 23:35:40 +0100127#endif
128
Jingoo Hanf10a46c2013-04-29 16:17:43 -0700129static SIMPLE_DEV_PM_OPS(kb3886bl_pm_ops, kb3886bl_suspend, kb3886bl_resume);
130
Claudio Niederd03ebb12008-10-20 23:35:40 +0100131static int kb3886bl_get_intensity(struct backlight_device *bd)
132{
133 return kb3886bl_intensity;
134}
135
Emese Revfy9905a432009-12-14 00:58:57 +0100136static const struct backlight_ops kb3886bl_ops = {
Claudio Niederd03ebb12008-10-20 23:35:40 +0100137 .get_brightness = kb3886bl_get_intensity,
138 .update_status = kb3886bl_send_intensity,
139};
140
141static int kb3886bl_probe(struct platform_device *pdev)
142{
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500143 struct backlight_properties props;
Jingoo Hanc512794c2013-11-12 15:09:04 -0800144 struct kb3886bl_machinfo *machinfo = dev_get_platdata(&pdev->dev);
Claudio Niederd03ebb12008-10-20 23:35:40 +0100145
146 bl_machinfo = machinfo;
147 if (!machinfo->limit_mask)
148 machinfo->limit_mask = -1;
149
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500150 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -0700151 props.type = BACKLIGHT_RAW;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500152 props.max_brightness = machinfo->max_intensity;
Jingoo Handa653782013-11-12 15:09:17 -0800153 kb3886_backlight_device = devm_backlight_device_register(&pdev->dev,
154 "kb3886-bl", &pdev->dev,
155 NULL, &kb3886bl_ops,
156 &props);
Claudio Niederd03ebb12008-10-20 23:35:40 +0100157 if (IS_ERR(kb3886_backlight_device))
158 return PTR_ERR(kb3886_backlight_device);
159
160 platform_set_drvdata(pdev, kb3886_backlight_device);
161
Claudio Niederd03ebb12008-10-20 23:35:40 +0100162 kb3886_backlight_device->props.power = FB_BLANK_UNBLANK;
163 kb3886_backlight_device->props.brightness = machinfo->default_intensity;
164 backlight_update_status(kb3886_backlight_device);
165
166 return 0;
167}
168
Claudio Niederd03ebb12008-10-20 23:35:40 +0100169static struct platform_driver kb3886bl_driver = {
170 .probe = kb3886bl_probe,
Claudio Niederd03ebb12008-10-20 23:35:40 +0100171 .driver = {
172 .name = "kb3886-bl",
Jingoo Hanf10a46c2013-04-29 16:17:43 -0700173 .pm = &kb3886bl_pm_ops,
Claudio Niederd03ebb12008-10-20 23:35:40 +0100174 },
175};
176
177static int __init kb3886_init(void)
178{
179 if (!dmi_check_system(kb3886bl_device_table))
180 return -ENODEV;
181
182 platform_add_devices(devices, ARRAY_SIZE(devices));
183 return platform_driver_register(&kb3886bl_driver);
184}
185
186static void __exit kb3886_exit(void)
187{
188 platform_driver_unregister(&kb3886bl_driver);
189}
190
191module_init(kb3886_init);
192module_exit(kb3886_exit);
193
194MODULE_AUTHOR("Claudio Nieder <private@claudio.ch>");
195MODULE_DESCRIPTION("Tabletkiosk Sahara Touch-iT Backlight Driver");
196MODULE_LICENSE("GPL");
197MODULE_ALIAS("dmi:*:svnSDV:pniTouchT201:*");